diff --git a/bahmni-test-commons/src/test/java/org/bahmni/test/builder/PersonBuilder.java b/bahmni-test-commons/src/test/java/org/bahmni/test/builder/PersonBuilder.java index 48b87bcb77..73fa5348f3 100644 --- a/bahmni-test-commons/src/test/java/org/bahmni/test/builder/PersonBuilder.java +++ b/bahmni-test-commons/src/test/java/org/bahmni/test/builder/PersonBuilder.java @@ -1,6 +1,10 @@ package org.bahmni.test.builder; import org.openmrs.Person; +import org.openmrs.PersonName; + +import java.util.HashSet; +import java.util.Set; public class PersonBuilder { @@ -15,6 +19,16 @@ public PersonBuilder withUUID(String patientUuid) { return this; } + public PersonBuilder withPersonName(String personNameValue) { + PersonName personName = new PersonName(); + personName.setGivenName(personNameValue); + personName.setId(2); + Set personNames = new HashSet<>(); + personNames.add(personName); + person.setNames(personNames); + return this; + } + public Person build() { return person; } diff --git a/bahmnicore-api/pom.xml b/bahmnicore-api/pom.xml index 83f5ff206d..fdcc273bd3 100644 --- a/bahmnicore-api/pom.xml +++ b/bahmnicore-api/pom.xml @@ -205,6 +205,12 @@ org.openmrs.module emrapi-api-1.12 + + org.apache.httpcomponents + httpclient + 4.5.14 + provided + diff --git a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/contract/SMS/PrescriptionSMS.java b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/contract/SMS/PrescriptionSMS.java new file mode 100644 index 0000000000..9d9ded49a3 --- /dev/null +++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/contract/SMS/PrescriptionSMS.java @@ -0,0 +1,22 @@ +package org.bahmni.module.bahmnicore.contract.SMS; + +public class PrescriptionSMS { + private String visitUuid; + private String locale = "en"; + + public String getVisitUuid() { + return visitUuid; + } + + public void setVisitUuid(String visitUuid) { + this.visitUuid = visitUuid; + } + + public String getLocale() { + return locale; + } + + public void setLocale(String locale) { + this.locale = locale; + } +} \ No newline at end of file diff --git a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/contract/SMS/SMSRequest.java b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/contract/SMS/SMSRequest.java new file mode 100644 index 0000000000..4a37ad4288 --- /dev/null +++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/contract/SMS/SMSRequest.java @@ -0,0 +1,26 @@ +package org.bahmni.module.bahmnicore.contract.SMS; + +import org.codehaus.jackson.annotate.JsonProperty; + +public class SMSRequest { + private String phoneNumber; + private String message; + + @JsonProperty + public String getPhoneNumber() { + return phoneNumber; + } + + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + @JsonProperty + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} \ No newline at end of file diff --git a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/BahmniDrugOrderService.java b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/BahmniDrugOrderService.java index 6d57f6a571..4166221ede 100644 --- a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/BahmniDrugOrderService.java +++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/BahmniDrugOrderService.java @@ -38,4 +38,6 @@ List getInactiveDrugOrders(String patientUuid, Set concepts, List getDrugOrders(String patientUuid, Boolean isActive, Set conceptsToFilter, Set conceptsToExclude, String patientProgramUuid) throws ParseException; + + List getBahmniDrugOrdersForVisit(String patientUuid, String visitUuid); } diff --git a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/SMSService.java b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/SMSService.java new file mode 100644 index 0000000000..33f58f3c57 --- /dev/null +++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/SMSService.java @@ -0,0 +1,15 @@ +package org.bahmni.module.bahmnicore.service; + +import org.openmrs.Location; +import org.openmrs.Patient; + +import java.util.Date; +import java.util.List; +import java.util.Locale; + +public interface SMSService { + + String getPrescriptionMessage(Locale locale, Date visitDate, Patient patient, Location location, List providerList, String prescriptionDetail); + + Object sendSMS(String phoneNumber, String message); +} diff --git a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/SharePrescriptionService.java b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/SharePrescriptionService.java new file mode 100644 index 0000000000..cd4801a1b2 --- /dev/null +++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/SharePrescriptionService.java @@ -0,0 +1,11 @@ +package org.bahmni.module.bahmnicore.service; + +import org.bahmni.module.bahmnicore.contract.SMS.PrescriptionSMS; +import org.openmrs.annotation.Authorized; +import org.springframework.transaction.annotation.Transactional; + +public interface SharePrescriptionService { + @Transactional(readOnly = true) + @Authorized({"Send Prescription SMS"}) + Object sendPresciptionSMS(PrescriptionSMS prescription); +} diff --git a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/impl/BahmniDrugOrderServiceImpl.java b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/impl/BahmniDrugOrderServiceImpl.java index 5f54ca0c5b..298c094a37 100644 --- a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/impl/BahmniDrugOrderServiceImpl.java +++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/impl/BahmniDrugOrderServiceImpl.java @@ -8,6 +8,7 @@ import org.bahmni.module.bahmnicore.contract.drugorder.OrderFrequencyData; import org.bahmni.module.bahmnicore.dao.OrderDao; import org.bahmni.module.bahmnicore.service.BahmniDrugOrderService; +import org.bahmni.module.bahmnicore.service.BahmniObsService; import org.bahmni.module.bahmnicore.service.BahmniProgramWorkflowService; import org.openmrs.CareSetting; import org.openmrs.Concept; @@ -25,6 +26,7 @@ import org.openmrs.module.bahmniemrapi.drugorder.contract.BahmniDrugOrder; import org.openmrs.module.bahmniemrapi.drugorder.contract.BahmniOrderAttribute; import org.openmrs.module.bahmniemrapi.drugorder.mapper.BahmniDrugOrderMapper; +import org.openmrs.module.bahmniemrapi.encountertransaction.contract.BahmniObservation; import org.openmrs.module.emrapi.encounter.ConceptMapper; import org.openmrs.module.emrapi.encounter.domain.EncounterTransaction; import org.openmrs.module.emrapi.utils.HibernateLazyLoader; @@ -41,6 +43,8 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import java.util.Arrays; +import java.util.Comparator; @Service public class BahmniDrugOrderServiceImpl implements BahmniDrugOrderService { @@ -51,21 +55,21 @@ public class BahmniDrugOrderServiceImpl implements BahmniDrugOrderService { private ConceptMapper conceptMapper = new ConceptMapper(); private BahmniProgramWorkflowService bahmniProgramWorkflowService; private BahmniDrugOrderMapper bahmniDrugOrderMapper; - + private BahmniObsService bahmniObsService; private static final String GP_DOSING_INSTRUCTIONS_CONCEPT_UUID = "order.dosingInstructionsConceptUuid"; private static Logger logger = LogManager.getLogger(BahmniDrugOrderService.class); - @Autowired - public BahmniDrugOrderServiceImpl(ConceptService conceptService, OrderService orderService, - PatientService patientService, OrderDao orderDao, BahmniProgramWorkflowService bahmniProgramWorkflowService) { + public BahmniDrugOrderServiceImpl(ConceptService conceptService, OrderService orderService, PatientService patientService, OrderDao orderDao, + BahmniProgramWorkflowService bahmniProgramWorkflowService, BahmniObsService bahmniObsService) { this.conceptService = conceptService; this.orderService = orderService; this.openmrsPatientService = patientService; this.orderDao = orderDao; this.bahmniProgramWorkflowService = bahmniProgramWorkflowService; this.bahmniDrugOrderMapper = new BahmniDrugOrderMapper(); + this.bahmniObsService = bahmniObsService; } @@ -167,6 +171,31 @@ public List getAllDrugOrders(String patientUuid, String patientProgramUui return orderDao.getAllOrders(patientByUuid, orderTypeByUuid, conceptsForDrugs, drugConceptsToBeExcluded, encounters); } + @Override + public List getBahmniDrugOrdersForVisit(String patientUuid, String visitUuid) { + try { + List drugOrderList = getPrescribedDrugOrders(Arrays.asList(visitUuid), patientUuid, null,null, null, null, null); + Map drugOrderMap = getDiscontinuedDrugOrders(drugOrderList); + Collection orderAttributeObs = bahmniObsService.observationsFor(patientUuid, getOrderAttributeConcepts(), null, null, false, null, null, null); + List bahmniDrugOrderList = bahmniDrugOrderMapper.mapToResponse(drugOrderList, orderAttributeObs, drugOrderMap , null); + Collections.sort(bahmniDrugOrderList, new Comparator() { + @Override + public int compare(BahmniDrugOrder o1, BahmniDrugOrder o2) { + return o1.getEffectiveStartDate().compareTo(o2.getEffectiveStartDate()); + } + }); + return bahmniDrugOrderList; + } catch (IOException e) { + logger.error("Could not parse drug order", e); + throw new RuntimeException("Could not parse drug order", e); + } + } + + private Collection getOrderAttributeConcepts() { + Concept orderAttribute = conceptService.getConceptByName(BahmniOrderAttribute.ORDER_ATTRIBUTES_CONCEPT_SET_NAME); + return orderAttribute == null ? Collections.EMPTY_LIST : orderAttribute.getSetMembers(); + } + private List fetchOrderAttributeConcepts() { Concept orderAttributesConceptSet = conceptService.getConceptByName(BahmniOrderAttribute.ORDER_ATTRIBUTES_CONCEPT_SET_NAME); if(orderAttributesConceptSet != null){ @@ -200,7 +229,6 @@ private List getFrequencies() { .collect(Collectors.toList()); } - private List getActiveDrugOrders(String patientUuid, Date asOfDate, Set conceptsToFilter, Set conceptsToExclude, Date startDate, Date endDate, Collection encounters) { Patient patient = openmrsPatientService.getPatientByUuid(patientUuid); @@ -221,5 +249,4 @@ private List mapOrderToDrugOrder(List orders){ } return drugOrders; } - } diff --git a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/impl/BahmniVisitServiceImpl.java b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/impl/BahmniVisitServiceImpl.java index 0b5cc86631..10ce41fca5 100644 --- a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/impl/BahmniVisitServiceImpl.java +++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/impl/BahmniVisitServiceImpl.java @@ -33,4 +33,5 @@ public Visit getVisitSummary(String visitUuid) { public List getAdmitAndDischargeEncounters(Integer visitId) { return visitDao.getAdmitAndDischargeEncounters(visitId); } + } diff --git a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/impl/SMSServiceImpl.java b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/impl/SMSServiceImpl.java new file mode 100644 index 0000000000..ffa56726ca --- /dev/null +++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/impl/SMSServiceImpl.java @@ -0,0 +1,79 @@ +package org.bahmni.module.bahmnicore.service.impl; + +import org.apache.commons.lang.StringUtils; +import org.apache.http.HttpResponse; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import org.bahmni.module.bahmnicore.contract.SMS.SMSRequest; +import org.bahmni.module.bahmnicore.service.BahmniDrugOrderService; +import org.bahmni.module.bahmnicore.service.SMSService; +import org.openmrs.Location; +import org.openmrs.Patient; + +import org.openmrs.api.context.Context; +import org.springframework.stereotype.Service; + +import java.text.MessageFormat; +import java.util.Date; +import java.util.List; +import java.util.Locale; + +import static org.bahmni.module.bahmnicore.util.BahmniDateUtil.convertUTCToGivenFormat; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; + +@Service +public class SMSServiceImpl implements SMSService { + private static Logger logger = LogManager.getLogger(BahmniDrugOrderService.class); + private final static String PRESCRIPTION_SMS_TEMPLATE = "bahmni.prescriptionSMSTemplate"; + private final static String SMS_TIMEZONE = "bahmni.sms.timezone"; + private final static String SMS_DATEFORMAT = "bahmni.sms.dateformat"; + private final static String SMS_URL = "bahmni.sms.url"; + + public SMSServiceImpl() {} + + @Override + public Object sendSMS(String phoneNumber, String message) { + try { + SMSRequest smsRequest = new SMSRequest(); + smsRequest.setPhoneNumber(phoneNumber); + smsRequest.setMessage(message); + + ObjectMapper Obj = new ObjectMapper(); + String jsonObject = Obj.writeValueAsString(smsRequest); + StringEntity params = new StringEntity(jsonObject); + + HttpPost request = new HttpPost(Context.getMessageSourceService().getMessage(SMS_URL, null, new Locale("en"))); + request.addHeader("content-type", "application/json"); + request.setEntity(params); + CloseableHttpClient httpClient = HttpClients.createDefault(); + HttpResponse response = httpClient.execute(request); + httpClient.close(); + return response.getStatusLine(); + } catch (Exception e) { + logger.error("Exception occured in sending sms ", e); + throw new RuntimeException("Exception occured in sending sms ", e); + } + } + + @Override + public String getPrescriptionMessage(Locale locale, Date visitDate, Patient patient, Location location, List providerList, String prescriptionDetail) { + String smsTimeZone = Context.getMessageSourceService().getMessage(SMS_TIMEZONE, null, locale); + String smsDateFormat = Context.getMessageSourceService().getMessage(SMS_DATEFORMAT, null, locale); + String smsTemplate = Context.getAdministrationService().getGlobalProperty(PRESCRIPTION_SMS_TEMPLATE); + Object[] arguments = {convertUTCToGivenFormat(visitDate, smsDateFormat, smsTimeZone), + patient.getGivenName() + " " + patient.getFamilyName(), patient.getGender(), patient.getAge().toString(), + org.springframework.util.StringUtils.collectionToCommaDelimitedString(providerList), location.getName(), prescriptionDetail}; + if (StringUtils.isBlank(smsTemplate)) { + return Context.getMessageSourceService().getMessage(PRESCRIPTION_SMS_TEMPLATE, arguments, locale).replace("\\n", System.lineSeparator()); + } else { + return new MessageFormat(smsTemplate).format(arguments).replace("\\n", System.lineSeparator()); + } + } + +} diff --git a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/impl/SharePrescriptionServiceImpl.java b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/impl/SharePrescriptionServiceImpl.java new file mode 100644 index 0000000000..82ee776c23 --- /dev/null +++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/impl/SharePrescriptionServiceImpl.java @@ -0,0 +1,159 @@ +package org.bahmni.module.bahmnicore.service.impl; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.bahmni.module.bahmnicore.contract.SMS.PrescriptionSMS; +import org.bahmni.module.bahmnicore.service.BahmniDrugOrderService; +import org.bahmni.module.bahmnicore.service.BahmniVisitService; +import org.bahmni.module.bahmnicore.service.SMSService; +import org.bahmni.module.bahmnicore.service.SharePrescriptionService; +import org.openmrs.Location; +import org.openmrs.Visit; +import org.openmrs.annotation.Authorized; +import org.openmrs.api.context.Context; +import org.openmrs.module.bahmniemrapi.drugorder.contract.BahmniDrugOrder; +import org.openmrs.module.emrapi.encounter.domain.EncounterTransaction; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.ArrayList; +import java.util.Set; +import java.util.Map; +import java.util.Date; +import java.util.Locale; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.concurrent.TimeUnit; + +import static org.bahmni.module.bahmnicore.util.BahmniDateUtil.convertUTCToGivenFormat; + +@Service +public class SharePrescriptionServiceImpl implements SharePrescriptionService { + private static Logger logger = LogManager.getLogger(BahmniDrugOrderService.class); + private BahmniVisitService bahmniVisitService; + private BahmniDrugOrderService drugOrderService; + private SMSService smsService; + + private final static String SMS_TIMEZONE = "bahmni.sms.timezone"; + private final static String SMS_DATEFORMAT = "bahmni.sms.dateformat"; + + @Autowired + public SharePrescriptionServiceImpl(BahmniVisitService bahmniVisitService, BahmniDrugOrderService drugOrderService, SMSService smsService) { + this.bahmniVisitService = bahmniVisitService; + this.drugOrderService = drugOrderService; + this.smsService = smsService; + } + + @Override + @Transactional(readOnly = true) + @Authorized({"Send Prescription"}) + public Object sendPresciptionSMS(PrescriptionSMS prescription) { + Visit visit = bahmniVisitService.getVisitSummary(prescription.getVisitUuid()); + Location location = getParentLocationForVisit(visit.getLocation()); + List drugOrderList = drugOrderService.getBahmniDrugOrdersForVisit(visit.getPatient().getUuid(), visit.getUuid()); + List uniqueProviderList = getUniqueProviderNames(drugOrderList); + String prescriptionString = getPrescriptionAsString(drugOrderList, new Locale(prescription.getLocale())); + String prescriptionSMSContent = smsService.getPrescriptionMessage(new Locale(prescription.getLocale()), visit.getStartDatetime(), visit.getPatient(), + location, uniqueProviderList, prescriptionString); + return smsService.sendSMS(visit.getPatient().getAttribute("phoneNumber").getValue(), prescriptionSMSContent); + } + + private Location getParentLocationForVisit(Location location) { + if (location.getParentLocation() != null && isVisitLocation(location.getParentLocation())) { + return getParentLocationForVisit(location.getParentLocation()); + } else { + return location; + } + } + + private Boolean isVisitLocation(Location location) { + return (location.getTags().stream().filter(tag -> tag.getName().equalsIgnoreCase("Visit Location")) != null); + } + + private Map getMergedDrugOrderMap(List drugOrderList) { + Map mergedDrugOrderMap = new LinkedHashMap<>(); + for(BahmniDrugOrder drugOrder : drugOrderList) { + BahmniDrugOrder foundDrugOrder = mergedDrugOrderMap.entrySet().stream() + .map(x -> x.getKey()) + .filter( existingOrder -> + compareDrugOrders(existingOrder, drugOrder) ) + .findFirst() + .orElse(null); + if (foundDrugOrder!=null) { + String durationWithUnits = mergedDrugOrderMap.get(foundDrugOrder); + if(drugOrder.getDurationUnits() == foundDrugOrder.getDurationUnits()) + durationWithUnits = (foundDrugOrder.getDuration()+drugOrder.getDuration()) + " " + drugOrder.getDurationUnits(); + else + durationWithUnits += " + " + drugOrder.getDuration() + " " + drugOrder.getDurationUnits(); + mergedDrugOrderMap.put(foundDrugOrder, durationWithUnits); + } else { + mergedDrugOrderMap.put(drugOrder, drugOrder.getDuration()+" "+drugOrder.getDurationUnits()); + } + } + return mergedDrugOrderMap; + } + + private boolean compareDrugOrders(BahmniDrugOrder existingOrder, BahmniDrugOrder newDrugOrder) { + return (existingOrder.getDrug()!=null && newDrugOrder.getDrug()!=null && + areValuesEqual(existingOrder.getDrug().getUuid(), newDrugOrder.getDrug().getUuid())) && + areValuesEqual(existingOrder.getDrugNonCoded(), newDrugOrder.getDrugNonCoded()) && + areValuesEqual(existingOrder.getInstructions(), newDrugOrder.getInstructions()) && + compareDosingInstruction(existingOrder.getDosingInstructions(), newDrugOrder.getDosingInstructions()) && + areValuesEqual(existingOrder.getDosingInstructions().getRoute(), newDrugOrder.getDosingInstructions().getRoute()) && + areValuesEqual(existingOrder.getDosingInstructions().getAdministrationInstructions(), newDrugOrder.getDosingInstructions().getAdministrationInstructions()) && + areValuesEqual(existingOrder.getDosingInstructions().getAsNeeded(), newDrugOrder.getDosingInstructions().getAsNeeded()) && + areValuesEqual(existingOrder.getDateStopped(), newDrugOrder.getDateStopped()) && + getDateDifferenceInDays(existingOrder.getEffectiveStopDate(), newDrugOrder.getEffectiveStartDate()) <= 1.0 ; + } + + private Boolean areValuesEqual(Object value1, Object value2) { + if(value1 != null && value2 != null) { + return value1.equals(value2); + } + return (value1 == null && value2 == null); + }; + + private Boolean compareDosingInstruction(EncounterTransaction.DosingInstructions value1, EncounterTransaction.DosingInstructions value2) { + String doseAndFrequency1 = value1.getDose() + " " + value1.getDoseUnits() + ", " + value1.getFrequency(); + String doseAndFrequency2 = value2.getDose() + " " + value2.getDoseUnits() + ", " + value2.getFrequency(); + return doseAndFrequency1.equals(doseAndFrequency2); + }; + + private double getDateDifferenceInDays(Date date1, Date date2){ + long diff = date2.getTime() - date1.getTime(); + return TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS); + } + + public String getPrescriptionAsString(List drugOrders, Locale locale) { + Map drugOrderDurationMap = getMergedDrugOrderMap(drugOrders); + String prescriptionString = ""; + int counter = 1; + for (Map.Entry entry : drugOrderDurationMap.entrySet()) { + prescriptionString += counter++ + ". " + getDrugOrderAsString(entry.getKey(), drugOrderDurationMap.get(entry.getKey()), locale) + "\n"; + } + return prescriptionString; + } + + public List getUniqueProviderNames(List drugOrders) { + Set providerSet = new LinkedHashSet(); + for (BahmniDrugOrder drugOrder : drugOrders) { + providerSet.add("Dr " + drugOrder.getProvider().getName()); + } + return new ArrayList<>(providerSet); + } + + private String getDrugOrderAsString(BahmniDrugOrder drugOrder, String duration, Locale locale) { + String drugOrderString = drugOrder.getDrug().getName(); + drugOrderString += ", " + (drugOrder.getDosingInstructions().getDose().intValue()) + " " + drugOrder.getDosingInstructions().getDoseUnits(); + drugOrderString += ", " + drugOrder.getDosingInstructions().getFrequency() + "-" + duration; + drugOrderString += ", start from " + convertUTCToGivenFormat(drugOrder.getEffectiveStartDate(), + Context.getMessageSourceService().getMessage(SMS_DATEFORMAT, null, locale), Context.getMessageSourceService().getMessage(SMS_TIMEZONE, null, locale)); + if(drugOrder.getDateStopped() != null) + drugOrderString += ", stopped on " + convertUTCToGivenFormat(drugOrder.getDateStopped(), + Context.getMessageSourceService().getMessage(SMS_DATEFORMAT, null, locale), Context.getMessageSourceService().getMessage(SMS_TIMEZONE, null, locale)); + return drugOrderString; + } + +} diff --git a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/util/BahmniDateUtil.java b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/util/BahmniDateUtil.java index f157433edb..4c329a6907 100644 --- a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/util/BahmniDateUtil.java +++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/util/BahmniDateUtil.java @@ -2,6 +2,7 @@ import org.apache.commons.lang3.StringUtils; +import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; @@ -47,4 +48,14 @@ public static Date convertToLocalDateFromUTC(String dateString) throws ParseExce simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); return simpleDateFormat.parse(dateString); } + + public static String convertUTCToGivenFormat(Date dateTime, String format, String timeZone) { + if (dateTime == null || StringUtils.isEmpty(format) || StringUtils.isEmpty(timeZone)) { + return null; + } + DateFormat givenFormat = new SimpleDateFormat(format); + TimeZone givenTimeZone = TimeZone.getTimeZone(timeZone); + givenFormat.setTimeZone(givenTimeZone); + return givenFormat.format(dateTime); + } } diff --git a/bahmnicore-api/src/test/java/org/bahmni/module/bahmnicore/service/impl/BahmniDrugOrderServiceImplTest.java b/bahmnicore-api/src/test/java/org/bahmni/module/bahmnicore/service/impl/BahmniDrugOrderServiceImplTest.java index db08d279f4..bbfd6ff5c1 100644 --- a/bahmnicore-api/src/test/java/org/bahmni/module/bahmnicore/service/impl/BahmniDrugOrderServiceImplTest.java +++ b/bahmnicore-api/src/test/java/org/bahmni/module/bahmnicore/service/impl/BahmniDrugOrderServiceImplTest.java @@ -82,7 +82,7 @@ public void shouldGetActiveDrugOrdersOfAPatientProgram() throws ParseException { when(orderDao.getActiveOrders(any(Patient.class), any(OrderType.class), any(CareSetting.class), dateArgumentCaptor.capture(), anySet(), eq(null), eq(null), eq(null), anyCollection())).thenReturn(new ArrayList()); - bahmniDrugOrderService.getDrugOrders(PATIENT_UUID, true, conceptsToFilter, null, PATIENT_PROGRAM_UUID); + bahmniDrugOrderService.getDrugOrders(PATIENT_UUID, true, conceptsToFilter, null, PATIENT_PROGRAM_UUID); final Date value = dateArgumentCaptor.getValue(); verify(orderDao).getActiveOrders(mockPatient, mockOrderType, mockCareSetting, value, conceptsToFilter, null, null, null, encounters); @@ -113,4 +113,4 @@ public void shouldNotConsiderEncountersToFetchDrugOrdersIfPatientProgramUuidIsNu verify(orderDao).getAllOrders(mockPatient, mockOrderType,conceptsToFilter, null, encounters); verifyNoMoreInteractions(bahmniProgramWorkflowService); } -} +} \ No newline at end of file diff --git a/bahmnicore-api/src/test/java/org/bahmni/module/bahmnicore/service/impl/SMSServiceImplIT.java b/bahmnicore-api/src/test/java/org/bahmni/module/bahmnicore/service/impl/SMSServiceImplIT.java new file mode 100644 index 0000000000..ea5b6edd6f --- /dev/null +++ b/bahmnicore-api/src/test/java/org/bahmni/module/bahmnicore/service/impl/SMSServiceImplIT.java @@ -0,0 +1,121 @@ +package org.bahmni.module.bahmnicore.service.impl; + +import org.bahmni.test.builder.PersonBuilder; +import org.bahmni.test.builder.VisitBuilder; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.openmrs.Location; +import org.openmrs.Visit; +import org.openmrs.Person; +import org.openmrs.api.AdministrationService; +import org.openmrs.api.context.Context; +import org.openmrs.messagesource.MessageSourceService; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Date; +import java.util.Locale; + +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.not; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.*; +import static org.mockito.MockitoAnnotations.initMocks; +import static org.powermock.api.mockito.PowerMockito.mockStatic; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Context.class}) +@PowerMockIgnore("javax.management.*") +public class SMSServiceImplIT { + + private SMSServiceImpl smsService; + @Mock + AdministrationService administrationService; + @Mock + MessageSourceService messageSourceService; + @Rule + public ExpectedException expectedEx = ExpectedException.none(); + + @Before + public void setUp() throws Exception { + smsService = new SMSServiceImpl(); + initMocks(this); + mockStatic(Context.class); + when(Context.getAdministrationService()).thenReturn(administrationService); + when(Context.getMessageSourceService()).thenReturn(messageSourceService); + } + + @Test + public void shouldReturnPrescriptionSMSWithGlobalPropertyTemplate() throws ParseException { + when(administrationService.getGlobalProperty("bahmni.prescriptionSMSTemplate")).thenReturn("Date: {0}\nPrescription For Patient: {1}, {2}, {3} years.\nDoctor: {4} ({5})\n{6}"); + when(messageSourceService.getMessage("bahmni.sms.timezone", null, new Locale("en"))).thenReturn("IST"); + when(messageSourceService.getMessage("bahmni.sms.dateformat", null, new Locale("en"))).thenReturn("dd-MM-yyyy"); + Date visitDate = new SimpleDateFormat("MMMM d, yyyy", new Locale("en")).parse("January 30, 2023"); + Date birthDate = new SimpleDateFormat("MMMM d, yyyy", new Locale("en")).parse("January 30, 2010"); + Person person = new PersonBuilder().withUUID("puuid").withPersonName("testPersonName").build(); + person.setGender("M"); + person.setBirthdate(birthDate); + Visit visit = new VisitBuilder().withPerson(person).withUUID("vuuid").withStartDatetime(visitDate).build(); + Location location = new Location(); + location.setName("Bahmni"); + + String prescriptionContent = smsService.getPrescriptionMessage(new Locale("en"), visit.getStartDatetime(), visit.getPatient(), location, Arrays.asList("Superman"), "1. Paracetamol 150 mg/ml, 50 ml, Immediately-1 Days, start from 31-01-2023"); + String expectedPrescriptionContent = "Date: 30-01-2023\n" + + "Prescription For Patient: testPersonName null, M, 13 years.\n" + + "Doctor: Superman (Bahmni)\n" + + "1. Paracetamol 150 mg/ml, 50 ml, Immediately-1 Days, start from 31-01-2023"; + assertEquals(expectedPrescriptionContent, prescriptionContent); + } + + @Test + public void shouldReturnPrescriptionSMSWithDefaultTemplate() throws ParseException { + Object[] args = {"30-01-2023", "testPersonName null", "M", "13", "Superman", "Bahmni", "1. Paracetamol 150 mg/ml, 50 ml, Immediately-1 Days, start from 31-01-2023"}; + when(administrationService.getGlobalProperty("bahmni.prescriptionSMSTemplate")).thenReturn(null); + when(messageSourceService.getMessage("bahmni.prescriptionSMSTemplate", args, new Locale("en"))).thenReturn("Date: 30-01-2023\nPrescription For Patient: testPersonName null, M, 13 years.\nDoctor: Superman (Bahmni)\n1. Paracetamol 150 mg/ml, 50 ml, Immediately-1 Days, start from 31-01-2023"); + when(messageSourceService.getMessage("bahmni.sms.timezone", null, new Locale("en"))).thenReturn("IST"); + when(messageSourceService.getMessage("bahmni.sms.dateformat", null, new Locale("en"))).thenReturn("dd-MM-yyyy"); + Date visitDate = new SimpleDateFormat("MMMM d, yyyy", new Locale("en")).parse("January 30, 2023"); + Date birthDate = new SimpleDateFormat("MMMM d, yyyy", new Locale("en")).parse("January 30, 2010"); + Person person = new PersonBuilder().withUUID("puuid").withPersonName("testPersonName").build(); + person.setGender("M"); + person.setBirthdate(birthDate); + Visit visit = new VisitBuilder().withPerson(person).withUUID("vuuid").withStartDatetime(visitDate).build(); + Location location = new Location(); + location.setName("Bahmni"); + + String prescriptionContent = smsService.getPrescriptionMessage(new Locale("en"), visit.getStartDatetime(), visit.getPatient(), location, Arrays.asList("Superman"), "1. Paracetamol 150 mg/ml, 50 ml, Immediately-1 Days, start from 31-01-2023"); + String expectedPrescriptionContent = "Date: 30-01-2023\n" + + "Prescription For Patient: testPersonName null, M, 13 years.\n" + + "Doctor: Superman (Bahmni)\n" + + "1. Paracetamol 150 mg/ml, 50 ml, Immediately-1 Days, start from 31-01-2023"; + assertEquals(expectedPrescriptionContent, prescriptionContent); + } + + @Test + public void shouldThrowNullPointerExceptionOnNullUrl() throws Exception { + when(messageSourceService.getMessage("bahmni.sms.url", null, new Locale("en"))).thenReturn(null); + expectedEx.expect(RuntimeException.class); + expectedEx.expectMessage("Exception occured in sending sms"); + expectedEx.expectCause(instanceOf(java.lang.NullPointerException.class)); + smsService.sendSMS("+919999999999", "Welcome"); + } + + @Test + public void shouldNotThrowNullPointerExceptionOnValidUrl() throws Exception { + when(messageSourceService.getMessage("bahmni.sms.url", null, new Locale("en"))).thenReturn("http://google.com"); + expectedEx.expect(RuntimeException.class); + expectedEx.expectMessage("Exception occured in sending sms"); + expectedEx.isAnyExceptionExpected(); + expectedEx.expectCause(not(instanceOf(java.lang.NullPointerException.class))); + smsService.sendSMS("+919999999999", "Welcome"); + } + +} diff --git a/bahmnicore-api/src/test/java/org/bahmni/module/bahmnicore/service/impl/SharePrescriptionServiceImplIT.java b/bahmnicore-api/src/test/java/org/bahmni/module/bahmnicore/service/impl/SharePrescriptionServiceImplIT.java new file mode 100644 index 0000000000..6292b73e09 --- /dev/null +++ b/bahmnicore-api/src/test/java/org/bahmni/module/bahmnicore/service/impl/SharePrescriptionServiceImplIT.java @@ -0,0 +1,172 @@ +package org.bahmni.module.bahmnicore.service.impl; + +import org.apache.commons.lang3.time.DateUtils; +import org.bahmni.module.bahmnicore.contract.SMS.PrescriptionSMS; +import org.bahmni.module.bahmnicore.service.BahmniDrugOrderService; +import org.bahmni.module.bahmnicore.service.BahmniVisitService; +import org.bahmni.module.bahmnicore.service.SMSService; +import org.bahmni.test.builder.PersonBuilder; +import org.bahmni.test.builder.VisitBuilder; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.openmrs.Visit; +import org.openmrs.Location; +import org.openmrs.Person; +import org.openmrs.PersonAttribute; +import org.openmrs.PersonAttributeType; + +import org.openmrs.api.AdministrationService; +import org.openmrs.api.context.Context; +import org.openmrs.messagesource.MessageSourceService; +import org.openmrs.module.bahmniemrapi.drugorder.contract.BahmniDrugOrder; +import org.openmrs.module.emrapi.encounter.domain.EncounterTransaction; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.Locale; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import java.util.Arrays; +import java.util.List; + +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.times; +import static org.mockito.MockitoAnnotations.initMocks; +import static org.powermock.api.mockito.PowerMockito.mockStatic; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Context.class}) +@PowerMockIgnore("javax.management.*") +public class SharePrescriptionServiceImplIT { + + @Mock + BahmniDrugOrderService bahmniDrugOrderService; + @Mock + BahmniVisitService bahmniVisitService; + @Mock + SMSService smsService; + @InjectMocks + SharePrescriptionServiceImpl sharePrescriptionService; + @Mock + AdministrationService administrationService; + @Mock + MessageSourceService messageSourceService; + + @Before + public void setUp() throws Exception { + initMocks(this); + mockStatic(Context.class); + when(Context.getAdministrationService()).thenReturn(administrationService); + when(Context.getMessageSourceService()).thenReturn(messageSourceService); + } + + @Test + public void shouldCallSendSMSForSendingPrescriptionSMS() throws Exception { + PrescriptionSMS prescriptionSMS = new PrescriptionSMS(); + prescriptionSMS.setVisitUuid("visit-uuid"); + prescriptionSMS.setLocale("en"); + Visit visit = createVisitForTest(); + String sampleSMSContent = "Date: 30-01-2023\n" + + "Prescription For Patient: testPersonName null, M, 13 years.\n" + + "Doctor: Dr Harry (Bahmni)\n" + + "1. Paracetamol, 2 tab (s), Once a day-5 Days, start from 30-01-2023\n"; + + when(administrationService.getGlobalProperty("bahmni.prescriptionSMSTemplate")).thenReturn("Date: {0}\nPrescription For Patient: {1}, {2}, {3} years.\nDoctor: {4} ({5})\n{6}"); + when(messageSourceService.getMessage("bahmni.sms.timezone", null, new Locale("en"))).thenReturn("IST"); + when(messageSourceService.getMessage("bahmni.sms.dateformat", null, new Locale("en"))).thenReturn("dd-MM-yyyy"); + when(messageSourceService.getMessage("bahmni.sms.url", null, new Locale("en"))).thenReturn(null); + when(bahmniVisitService.getVisitSummary(prescriptionSMS.getVisitUuid())).thenReturn(visit); + when(bahmniDrugOrderService.getBahmniDrugOrdersForVisit(visit.getPatient().getUuid(), visit.getUuid())).thenReturn(buildBahmniDrugOrderList()); + when(smsService.getPrescriptionMessage(new Locale(prescriptionSMS.getLocale()), visit.getStartDatetime(), visit.getPatient(), + visit.getLocation(), Arrays.asList("Dr Harry"), "1. Paracetamol, 2 tab (s), Once a day-5 Days, start from 30-01-2023\n")) + .thenReturn(sampleSMSContent); + sharePrescriptionService.sendPresciptionSMS(prescriptionSMS); + verify(smsService, times(1)).sendSMS("+919999999999", sampleSMSContent); + } + + private Visit createVisitForTest() throws Exception { + Date visitDate = new SimpleDateFormat("MMMM d, yyyy", new Locale("en")).parse("January 30, 2023"); + Date birthDate = new SimpleDateFormat("MMMM d, yyyy", new Locale("en")).parse("January 30, 2010"); + Person person = new PersonBuilder().withUUID("puuid").withPersonName("testPersonName").build(); + person.setGender("M"); + person.setBirthdate(birthDate); + PersonAttribute pa = new PersonAttribute(); + pa.setValue("+919999999999"); + PersonAttributeType pat = new PersonAttributeType(); + pat.setName("phoneNumber"); + pa.setAttributeType(pat); + person.setAttributes(Stream.of(pa).collect(Collectors.toSet())); + + Visit visit = new VisitBuilder().withPerson(person).withUUID("visit-uuid").withStartDatetime(visitDate).build(); + Location location = new Location(); + location.setName("Bahmni"); + visit.setLocation(location); + + return visit; + } + + private List buildBahmniDrugOrderList() { + List bahmniDrugOrderList = new ArrayList<>(); + try { + EncounterTransaction.Provider provider = createETProvider("1", "Harry"); + Date drugOrderStartDate = new SimpleDateFormat("MMMM d, yyyy", new Locale("en")).parse("January 30, 2023"); + EncounterTransaction.DrugOrder etDrugOrder = createETDrugOrder("1", "Paracetamol", 2.0, "Once a day", drugOrderStartDate, 5); + BahmniDrugOrder bahmniDrugOrder = createBahmniDrugOrder(provider, etDrugOrder); + bahmniDrugOrderList.add(bahmniDrugOrder); + } catch (ParseException e) { + e.printStackTrace(); + } + return bahmniDrugOrderList; + } + + private BahmniDrugOrder createBahmniDrugOrder(EncounterTransaction.Provider provider, EncounterTransaction.DrugOrder etDrugOrder) { + BahmniDrugOrder bahmniDrugOrder = new BahmniDrugOrder(); + bahmniDrugOrder.setDrugOrder(etDrugOrder); + bahmniDrugOrder.setProvider(provider); + return bahmniDrugOrder; + } + + private EncounterTransaction.Provider createETProvider(String uuid, String name) { + EncounterTransaction.Provider provider = new EncounterTransaction.Provider(); + provider.setUuid(uuid); + provider.setName(name); + return provider; + } + + private EncounterTransaction.DrugOrder createETDrugOrder(String drugUuid, String drugName, Double dose, String frequency, Date effectiveStartDate, Integer duration) { + EncounterTransaction.Drug encounterTransactionDrug = new EncounterTransaction.Drug(); + encounterTransactionDrug.setUuid(drugUuid); + encounterTransactionDrug.setName(drugName); + + EncounterTransaction.DosingInstructions dosingInstructions = new EncounterTransaction.DosingInstructions(); + dosingInstructions.setAdministrationInstructions("{\"instructions\":\"As directed\"}"); + dosingInstructions.setAsNeeded(false); + dosingInstructions.setDose(dose); + dosingInstructions.setDoseUnits("tab (s)"); + dosingInstructions.setFrequency(frequency); + dosingInstructions.setNumberOfRefills(0); + dosingInstructions.setRoute("UNKNOWN"); + + EncounterTransaction.DrugOrder drugOrder = new EncounterTransaction.DrugOrder(); + drugOrder.setOrderType("Drug Order"); + drugOrder.setDrug(encounterTransactionDrug); + drugOrder.setDosingInstructions(dosingInstructions); + drugOrder.setDuration(duration); + drugOrder.setDurationUnits("Days"); + drugOrder.setEffectiveStartDate(effectiveStartDate); + drugOrder.setEffectiveStopDate(DateUtils.addDays(effectiveStartDate, duration)); + drugOrder.setVoided(false); + + return drugOrder; + } + +} diff --git a/bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/controller/BahmniDrugOrderController.java b/bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/controller/BahmniDrugOrderController.java index afc0306678..def8ae4149 100644 --- a/bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/controller/BahmniDrugOrderController.java +++ b/bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/controller/BahmniDrugOrderController.java @@ -3,8 +3,10 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.bahmni.module.bahmnicore.contract.SMS.PrescriptionSMS; import org.bahmni.module.bahmnicore.service.BahmniDrugOrderService; import org.bahmni.module.bahmnicore.service.BahmniObsService; +import org.bahmni.module.bahmnicore.service.SharePrescriptionService; import org.bahmni.module.bahmnicore.util.BahmniDateUtil; import org.openmrs.Concept; import org.openmrs.DrugOrder; @@ -21,6 +23,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RequestBody; import java.io.IOException; import java.text.ParseException; @@ -49,13 +52,17 @@ public class BahmniDrugOrderController extends BaseRestController { @Autowired private ConceptService conceptService; + @Autowired + private SharePrescriptionService sharePrescriptionServiceService; + private static Logger logger = LogManager.getLogger(BahmniDrugOrderController.class); private BahmniDrugOrderMapper bahmniDrugOrderMapper; - public BahmniDrugOrderController(BahmniDrugOrderService drugOrderService) { + public BahmniDrugOrderController(BahmniDrugOrderService drugOrderService, SharePrescriptionService sharePrescriptionServiceService) { this.drugOrderService = drugOrderService; this.bahmniDrugOrderMapper = new BahmniDrugOrderMapper(); + this.sharePrescriptionServiceService = sharePrescriptionServiceService; } public BahmniDrugOrderController() { this.bahmniDrugOrderMapper = new BahmniDrugOrderMapper(); @@ -129,6 +136,12 @@ public List getDrugOrderDetails(@RequestParam(value = "patientU return drugOrderService.getDrugOrders(patientUuid, isActive, drugConceptsToBeFiltered, drugConceptsToBeExcluded, patientProgramUuid); } + @RequestMapping(value = baseUrl+ "/sendPrescriptionSMS", method = RequestMethod.POST) + @ResponseBody + public Object sendPrescriptionSMS(@RequestBody PrescriptionSMS prescription) throws Exception { + return sharePrescriptionServiceService.sendPresciptionSMS(prescription); + } + Set getDrugConcepts(String drugConceptSetName){ if(drugConceptSetName == null) return null; Set drugConcepts = new HashSet<>(); diff --git a/bahmnicore-omod/src/main/resources/config.xml b/bahmnicore-omod/src/main/resources/config.xml index 1a6d99757e..c05e2694ed 100644 --- a/bahmnicore-omod/src/main/resources/config.xml +++ b/bahmnicore-omod/src/main/resources/config.xml @@ -97,6 +97,10 @@ app:lab-lite Will give access to Lab Lite app + + Send Prescription + Will give access to send prescription via sms + org.openmrs.module.bahmniemrapi.encountertransaction.service.BahmniEncounterTransactionService @@ -165,5 +169,20 @@ A list of UUIDs indicating extra Patient Identifier Types that should be displayed + + bahmni.enableSMSPrescriptionOption + false + Boolean to enable sending sms with prescription details + + + bahmni.enableEmailPrescriptionOption + false + Boolean to enable sending email with prescription details + + + bahmni.prescriptionSMSTemplate + Date: {0}\nPrescription For Patient: {1}, {2}, {3} years.\nDoctor: {4} ({5})\n{6} + Template to use while sending prescription in sms for a visit. Format is define like in Java MessageFormat + diff --git a/bahmnicore-omod/src/main/resources/messages.properties b/bahmnicore-omod/src/main/resources/messages.properties index cd2616a57a..e4d5120a1a 100644 --- a/bahmnicore-omod/src/main/resources/messages.properties +++ b/bahmnicore-omod/src/main/resources/messages.properties @@ -1 +1,6 @@ -@MODULE_ID@.title=Bahmni Core \ No newline at end of file +@MODULE_ID@.title=Bahmni Core + +bahmni.prescriptionSMSTemplate=Date: {0}\nPrescription For Patient: {1}, {2}, {3} years.\nDoctor: {4} ({5})\n{6} +bahmni.sms.timezone=IST +bahmni.sms.url=http://otp/notification/sms +bahmni.sms.dateformat=dd-MM-yyyy \ No newline at end of file diff --git a/bahmnicore-omod/src/test/java/org/bahmni/module/bahmnicore/web/v1_0/controller/BahmniDrugOrderControllerTest.java b/bahmnicore-omod/src/test/java/org/bahmni/module/bahmnicore/web/v1_0/controller/BahmniDrugOrderControllerTest.java index 9ba211900f..8c60e1aaf1 100644 --- a/bahmnicore-omod/src/test/java/org/bahmni/module/bahmnicore/web/v1_0/controller/BahmniDrugOrderControllerTest.java +++ b/bahmnicore-omod/src/test/java/org/bahmni/module/bahmnicore/web/v1_0/controller/BahmniDrugOrderControllerTest.java @@ -1,6 +1,8 @@ package org.bahmni.module.bahmnicore.web.v1_0.controller; +import org.bahmni.module.bahmnicore.contract.SMS.PrescriptionSMS; import org.bahmni.module.bahmnicore.service.BahmniDrugOrderService; +import org.bahmni.module.bahmnicore.service.SharePrescriptionService; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -13,6 +15,8 @@ import static org.junit.Assert.assertNull; import static org.mockito.Mockito.when; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import static org.mockito.MockitoAnnotations.initMocks; @RunWith(MockitoJUnitRunner.class) @@ -22,6 +26,8 @@ public class BahmniDrugOrderControllerTest { ConceptService conceptService; @Mock BahmniDrugOrderService bahmniDrugOrderService; + @Mock + SharePrescriptionService sharePrescriptionService; @InjectMocks BahmniDrugOrderController bahmniDrugOrderController; @@ -44,4 +50,13 @@ public void shouldReturnNullIfDrugConceptNameIsNull() { Set drugConcepts = bahmniDrugOrderController.getDrugConcepts(null); assertNull(drugConcepts); } + + @Test + public void shouldCallSendPrescriptionSMSServiceMethod() throws Exception { + PrescriptionSMS prescriptionSMS = new PrescriptionSMS(); + prescriptionSMS.setVisitUuid("visit-uuid"); + prescriptionSMS.setLocale("en"); + bahmniDrugOrderController.sendPrescriptionSMS(prescriptionSMS); + verify(sharePrescriptionService, times(1)).sendPresciptionSMS(prescriptionSMS); + } } \ No newline at end of file