Skip to content

Commit

Permalink
TRUNK-5234: API Should Set the Concept for Non Coded Drug Orders
Browse files Browse the repository at this point in the history
  • Loading branch information
IamMujuziMoses committed Feb 29, 2024
1 parent 11cbda0 commit 131ed70
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
5 changes: 5 additions & 0 deletions api/src/main/java/org/openmrs/api/impl/OrderServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ private void ensureConceptIsSet(Order order) {
if (drugOrder.getDrug() != null) {
concept = drugOrder.getDrug().getConcept();
drugOrder.setConcept(concept);
} else {
if (drugOrder.isNonCodedDrug()) {
concept = getNonCodedDrugConcept();
drugOrder.setConcept(concept);
}
}
}
if (concept == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void validate(Object obj, Errors errors) {
if (order.getAction() != Order.Action.DISCONTINUE) {
ValidationUtils.rejectIfEmpty(errors, "dosingType", "error.null");
}
if (order.getDrug() == null || order.getDrug().getConcept() == null) {
if (!order.isNonCodedDrug() && (order.getDrug() == null || order.getDrug().getConcept() == null)) {
ValidationUtils.rejectIfEmpty(errors, "concept", "error.null");
}

Expand Down
31 changes: 31 additions & 0 deletions api/src/test/java/org/openmrs/api/OrderServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3369,6 +3369,37 @@ public void saveOrder_shouldRevisePreviousNonCodedOrderIfItIsAlreadyExisting() {
assertNotNull(orderService.getOrder(saveOrder.getOrderId()));
}

/**
* @see org.openmrs.api.OrderService#saveOrder(Order, OrderContext)
*/
@Test
public void saveOrder_shouldSetNonCodedDrugOrderConcept() {
executeDataSet("org/openmrs/api/include/OrderServiceTest-nonCodedDrugs.xml");
final Encounter encounter = encounterService.getEncounter(3);

DrugOrder drugOrder = new DrugOrder();
drugOrder.setEncounter(encounter);

drugOrder.setDateActivated(encounter.getEncounterDatetime());
drugOrder.setDrugNonCoded("non coded paracetamol");
drugOrder.setPatient(patientService.getPatient(7));
drugOrder.setCareSetting(orderService.getCareSetting(1));
drugOrder.setOrderer(providerService.getProvider(1));
drugOrder.setDoseUnits(conceptService.getConcept(50));
drugOrder.setQuantityUnits(conceptService.getConcept(51));
drugOrder.setFrequency(orderService.getOrderFrequency(3));
drugOrder.setRoute(conceptService.getConcept(22));
drugOrder.setDosingType(SimpleDosingInstructions.class);
drugOrder.setNumRefills(10);
drugOrder.setDose(300.0);
drugOrder.setQuantity(20.0);
drugOrder.setOrderType(null);

orderService.saveOrder(drugOrder, null);
assertNotNull(drugOrder.getConcept());
}


@Test
public void saveRetrospectiveOrder_shouldDiscontinueOrderInRetrospectiveEntry() throws ParseException {
executeDataSet("org/openmrs/api/include/OrderServiceTest-ordersWithAutoExpireDate.xml");
Expand Down

0 comments on commit 131ed70

Please sign in to comment.