Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRUNK-5964: Hard-coded uuids for drug order type and test order type. #4585

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
TRUNK-5964: Hard-coded uuids for drug order type and test order type.
  • Loading branch information
IamMujuziMoses committed Mar 13, 2024
commit b201e6fb33960f2c0cdd118fe223a50df5520d9b
11 changes: 11 additions & 0 deletions api/src/main/java/org/openmrs/api/OrderService.java
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,17 @@ public Order discontinueOrder(Order orderToDiscontinue, String reasonNonCoded, D
*/
@Authorized(PrivilegeConstants.GET_ORDER_TYPES)
public OrderType getOrderTypeByConcept(Concept concept);

/**
* Get order types by java class name
*
* @param javaClassName the class name used to get the order types
* @since 2.7.0
* @return return the order types associated with given class name
* <strong>Should</strong> find order types with the specified class name
*/
@Authorized(PrivilegeConstants.GET_ORDER_TYPES)
public List<OrderType> getOrderTypesByClassName(String javaClassName) throws APIException;

/**
* Gets the possible drug routes, i.e the set members for the concept that matches the uuid
Expand Down
5 changes: 5 additions & 0 deletions api/src/main/java/org/openmrs/api/db/OrderDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ public List<OrderFrequency> getOrderFrequencies(String searchPhrase, Locale loca
* @see org.openmrs.api.OrderService#getOrderTypeByConceptClass(org.openmrs.ConceptClass)
*/
public OrderType getOrderTypeByConceptClass(ConceptClass conceptClass);

/**
* @see org.openmrs.api.OrderService#getOrderTypesByClassName(String)
*/
public List<OrderType> getOrderTypesByClassName(String javaClassName) throws DAOException;

/**
* @see org.openmrs.api.OrderService#saveOrderType(org.openmrs.OrderType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,26 @@ public OrderType getOrderTypeByConceptClass(ConceptClass conceptClass) {
"from OrderType where :conceptClass in elements(conceptClasses)").setParameter("conceptClass", conceptClass)
.uniqueResult();
}

/**
* @see org.openmrs.api.OrderService#getOrderTypesByClassName(String)
*/
@Override
public List<OrderType> getOrderTypesByClassName(String javaClassName) throws DAOException {
if (StringUtils.isBlank(javaClassName)) {
throw new APIException("javaClassName cannot be null");
}

Session session = sessionFactory.getCurrentSession();
CriteriaBuilder cb = session.getCriteriaBuilder();
CriteriaQuery<OrderType> cq = cb.createQuery(OrderType.class);
Root<OrderType> root = cq.from(OrderType.class);

cq.where(cb.equal(root.get("javaClassName"), javaClassName));

return session.createQuery(cq).getResultList();

}

/**
* @see org.openmrs.api.OrderService#saveOrderType(org.openmrs.OrderType)
Expand Down
15 changes: 12 additions & 3 deletions api/src/main/java/org/openmrs/api/impl/OrderServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ private void ensureOrderTypeIsSet(Order order, OrderContext orderContext) {
orderType = getOrderTypeByConcept(order.getConcept());
}
if (orderType == null && order instanceof DrugOrder) {
orderType = Context.getOrderService().getOrderTypeByUuid(OrderType.DRUG_ORDER_TYPE_UUID);
orderType = Context.getOrderService().getOrderTypeByName(OpenmrsConstants.DRUG_ORDER_TYPE_NAME);
}
if (orderType == null && order instanceof TestOrder) {
orderType = Context.getOrderService().getOrderTypeByUuid(OrderType.TEST_ORDER_TYPE_UUID);
orderType = Context.getOrderService().getOrderTypeByName(OpenmrsConstants.TEST_ORDER_TYPE_NAME);
}
if (orderType == null && order instanceof ReferralOrder) {
orderType = Context.getOrderService().getOrderTypeByUuid(OrderType.REFERRAL_ORDER_TYPE_UUID);
Expand Down Expand Up @@ -304,7 +304,7 @@ private boolean areDrugOrdersOfSameOrderableAndOverlappingSchedule(Order firstOr
&& !OpenmrsUtil.nullSafeEquals(firstOrder.getPreviousOrder(), secondOrder)
&& OrderUtil.checkScheduleOverlap(firstOrder, secondOrder)
&& firstOrder.getOrderType().equals(
Context.getOrderService().getOrderTypeByUuid(OrderType.DRUG_ORDER_TYPE_UUID));
Context.getOrderService().getOrderTypeByName(OpenmrsConstants.DRUG_ORDER_TYPE_NAME));
}

private boolean isDrugOrder(Order order) {
Expand Down Expand Up @@ -1027,6 +1027,15 @@ public OrderType getOrderTypeByConceptClass(ConceptClass conceptClass) {
public OrderType getOrderTypeByConcept(Concept concept) {
return Context.getOrderService().getOrderTypeByConceptClass(concept.getConceptClass());
}

/**
* @see org.openmrs.api.OrderService#getOrderTypesByClassName(String)
*/
@Override
@Transactional(readOnly = true)
public List<OrderType> getOrderTypesByClassName(String javaClassName) throws APIException {
return dao.getOrderTypesByClassName(javaClassName);
}

/**
* @see org.openmrs.api.OrderService#getDrugRoutes()
Expand Down
5 changes: 4 additions & 1 deletion api/src/main/java/org/openmrs/util/OpenmrsConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import org.apache.commons.io.IOUtils;
import org.openmrs.GlobalProperty;
import org.openmrs.api.context.Context;
import org.openmrs.api.handler.ExistingVisitAssignmentHandler;
import org.openmrs.customdatatype.datatype.BooleanDatatype;
import org.openmrs.customdatatype.datatype.FreeTextDatatype;
Expand Down Expand Up @@ -233,6 +232,10 @@ public static final Collection<String> AUTO_ROLES() {
return roles;
}

public static final String DRUG_ORDER_TYPE_NAME = "Drug order";

public static final String TEST_ORDER_TYPE_NAME = "Test order";

public static final String GLOBAL_PROPERTY_DRUG_FREQUENCIES = "dashboard.regimen.displayFrequencies";

public static final String GLOBAL_PROPERTY_CONCEPTS_LOCKED = "concepts.locked";
Expand Down
30 changes: 28 additions & 2 deletions api/src/test/java/org/openmrs/api/OrderServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2574,6 +2574,32 @@ public void getOrderTypeByConcept_shouldGetOrderTypeMappedToTheGivenConcept() {
assertEquals(2, orderType.getOrderTypeId().intValue());
}

/**
* @see org.openmrs.api.OrderService#getOrderTypesByClassName(String)
*/
@Test
public void getOrderTypesByClassName_shouldReturnOrderTypesForTheGivenJavaClassName() {
List<OrderType> drugOrderTypes = orderService.getOrderTypesByClassName(DrugOrder.class.getName());

assertNotNull(drugOrderTypes);
assertEquals(1, drugOrderTypes.size());
assertEquals(drugOrderTypes.get(0).getName(), OpenmrsConstants.DRUG_ORDER_TYPE_NAME);

List<OrderType> testOrderTypes = orderService.getOrderTypesByClassName(TestOrder.class.getName());

assertNotNull(testOrderTypes);
assertEquals(2, testOrderTypes.size());
assertEquals(testOrderTypes.get(0).getName(), OpenmrsConstants.TEST_ORDER_TYPE_NAME);
}

/**
* @see org.openmrs.api.OrderService#getOrderTypesByClassName(String)
*/
@Test
public void getOrderTypesByClassName_shouldThrowAPIExceptionForNullJavaClassName() {
assertThrows(APIException.class, () -> orderService.getOrderTypesByClassName(null));
}

/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
Expand Down Expand Up @@ -3101,7 +3127,7 @@ public void saveOrder_shouldSetOrderTypeOfDrugOrderToDrugOrderIfNotSetAndConcept

orderService.saveOrder(drugOrder, null);
assertNotNull(drugOrder.getOrderType());
assertEquals(orderService.getOrderTypeByUuid(OrderType.DRUG_ORDER_TYPE_UUID), drugOrder.getOrderType());
assertEquals(orderService.getOrderTypeByName(OpenmrsConstants.DRUG_ORDER_TYPE_NAME), drugOrder.getOrderType());
}

/**
Expand All @@ -3127,7 +3153,7 @@ public void saveOrder_shouldSetOrderTypeOfTestOrderToTestOrderIfNotSetAndConcept

orderService.saveOrder(testOrder, null);
assertNotNull(testOrder.getOrderType());
assertEquals(orderService.getOrderTypeByUuid(OrderType.TEST_ORDER_TYPE_UUID), testOrder.getOrderType());
assertEquals(orderService.getOrderTypeByName(OpenmrsConstants.TEST_ORDER_TYPE_NAME), testOrder.getOrderType());
}

@Test
Expand Down
Loading