Skip to content

Commit

Permalink
TRUNK-4389 Added orderType check
Browse files Browse the repository at this point in the history
  • Loading branch information
rkorytkowski committed Jul 7, 2014
1 parent ebd30d3 commit 08e0bc1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
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 @@ -142,6 +142,11 @@ public synchronized Order saveOrder(Order order, OrderContext orderContext) thro
discontinueExistingOrdersIfNecessary(order);
}

if (!order.getOrderType().getJavaClass().isAssignableFrom(order.getClass())) {
throw new APIException("Order type class " + order.getOrderType().getJavaClass()
+ " does not match the order class " + order.getClass().getName());
}

if (previousOrder != null) {
//Check that patient, careSetting, concept and drug if is drug order have not changed
//we need to use a SQL query to by pass the hibernate cache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public void shouldAllowEditingADiscontinuationOrder() throws Exception {

@Test
public void shouldAllowRetrospectiveDataEntryOfOrders() throws Exception {
Order order = new Order();
Order order = new TestOrder();
order.setPatient(patientService.getPatient(2));
order.setCareSetting(orderService.getCareSetting(2));
order.setConcept(conceptService.getConcept(5089));
Expand Down
3 changes: 2 additions & 1 deletion api/src/test/java/org/openmrs/OrderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ protected static void assertThatAllFieldsAreCopied(Order original, String method
} else {
try {
fieldValue = field.getType().newInstance();
} catch (InstantiationException e) {
}
catch (InstantiationException e) {
fieldValue = null;
}
}
Expand Down
12 changes: 6 additions & 6 deletions api/src/test/java/org/openmrs/api/OrderServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ public void saveOrder_shouldPassIfAnActiveOrderForTheSameConceptExistsInADiffere
assertEquals(cd4Count, duplicateOrder.getConcept());
int initialActiveOrderCount = orderService.getActiveOrders(patient, null, null, null).size();

Order order = new Order();
TestOrder order = new TestOrder();
order.setPatient(patient);
order.setCareSetting(orderService.getCareSetting(2));
order.setConcept(cd4Count);
Expand Down Expand Up @@ -1635,14 +1635,14 @@ public void getAllOrdersByPatient_shouldGetAllTheOrdersForTheSpecifiedPatient()
*/
@Test
public void saveOrder_shouldSetOrderTypeIfNullButMappedToTheConceptClass() throws Exception {
Order order = new Order();
TestOrder order = new TestOrder();
order.setPatient(patientService.getPatient(7));
order.setConcept(conceptService.getConcept(5497));
order.setOrderer(providerService.getProvider(1));
order.setCareSetting(orderService.getCareSetting(1));
order.setEncounter(encounterService.getEncounter(3));
order.setStartDate(new Date());
order = orderService.saveOrder(order, null);
orderService.saveOrder(order, null);
assertEquals(2, order.getOrderType().getOrderTypeId().intValue());
}

Expand Down Expand Up @@ -1791,14 +1791,14 @@ public void getOrderSubTypes_shouldGetAllSubOrderTypesWithoutRetiredOrderTypes()
*/
@Test
public void saveOrder_shouldDefaultToCareSettingAndOrderTypeDefinedInTheOrderContextIfNull() throws Exception {
Order order = new Order();
Order order = new TestOrder();
order.setPatient(patientService.getPatient(7));
Concept trimune30 = conceptService.getConcept(792);
order.setConcept(trimune30);
order.setOrderer(providerService.getProvider(1));
order.setEncounter(encounterService.getEncounter(3));
order.setStartDate(new Date());
OrderType expectedOrderType = orderService.getOrderType(3);
OrderType expectedOrderType = orderService.getOrderType(2);
CareSetting expectedCareSetting = orderService.getCareSetting(1);
OrderContext orderContext = new OrderContext();
orderContext.setOrderType(expectedOrderType);
Expand Down Expand Up @@ -2386,7 +2386,7 @@ public void getRevisionOrder_shouldNotReturnAVoidedRevisionOrder() throws Except
*/
@Test
public void saveOrder_shouldPassForADiscontinuationOrderWithNoPreviousOrder() throws Exception {
Order dcOrder = new Order();
TestOrder dcOrder = new TestOrder();
dcOrder.setAction(Action.DISCONTINUE);
dcOrder.setPatient(patientService.getPatient(2));
dcOrder.setCareSetting(orderService.getCareSetting(2));
Expand Down

0 comments on commit 08e0bc1

Please sign in to comment.