use of org.openmrs.TestOrder in project openmrs-core by openmrs.
the class OrderValidatorTest method validate_shouldNotAllowAFutureDateActivated.
/**
* @see OrderValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldNotAllowAFutureDateActivated() {
Patient patient = Context.getPatientService().getPatient(7);
TestOrder order = new TestOrder();
order.setPatient(patient);
order.setOrderType(orderService.getOrderTypeByName("Test order"));
order.setEncounter(Context.getEncounterService().getEncounter(3));
order.setConcept(Context.getConceptService().getConcept(5497));
order.setOrderer(Context.getProviderService().getProvider(1));
order.setCareSetting(orderService.getCareSetting(1));
Calendar cal = Calendar.getInstance();
cal.add(Calendar.HOUR_OF_DAY, 1);
order.setDateActivated(cal.getTime());
Errors errors = new BindException(order, "order");
new OrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors("dateActivated"));
Assert.assertEquals("Order.error.dateActivatedInFuture", errors.getFieldError("dateActivated").getCode());
}
use of org.openmrs.TestOrder in project openmrs-core by openmrs.
the class OrderServiceImpl method ensureOrderTypeIsSet.
private void ensureOrderTypeIsSet(Order order, OrderContext orderContext) {
if (order.getOrderType() != null) {
return;
}
OrderType orderType = null;
if (orderContext != null) {
orderType = orderContext.getOrderType();
}
if (orderType == null) {
orderType = getOrderTypeByConcept(order.getConcept());
}
if (orderType == null && order instanceof DrugOrder) {
orderType = Context.getOrderService().getOrderTypeByUuid(OrderType.DRUG_ORDER_TYPE_UUID);
}
if (orderType == null && order instanceof TestOrder) {
orderType = Context.getOrderService().getOrderTypeByUuid(OrderType.TEST_ORDER_TYPE_UUID);
}
if (orderType == null) {
throw new OrderEntryException("Order.type.cannot.determine");
}
Order previousOrder = order.getPreviousOrder();
if (previousOrder != null && !orderType.equals(previousOrder.getOrderType())) {
throw new OrderEntryException("Order.type.does.not.match");
}
order.setOrderType(orderType);
}
use of org.openmrs.TestOrder in project openmrs-core by openmrs.
the class EncounterServiceTest method saveEncounter_shouldNotCascadeToExistingOrder.
/**
* @see EncounterService#unvoidEncounter(Encounter)
*/
@Test
public void saveEncounter_shouldNotCascadeToExistingOrder() {
EncounterService es = Context.getEncounterService();
TestOrder order = (TestOrder) Context.getOrderService().getOrder(7);
order.setVoided(true);
Encounter encounter = es.getEncounter(6);
es.saveEncounter(encounter);
String sql = "SELECT voided FROM orders WHERE order_id=7";
Boolean voided = (Boolean) Context.getAdministrationService().executeSQL(sql, true).get(0).get(0);
Assert.assertFalse(voided);
}
use of org.openmrs.TestOrder in project openmrs-core by openmrs.
the class EncounterServiceTest method saveEncounter_shouldSetDateStoppedOnTheOriginalAfterAddingReviseOrder.
/**
* @see EncounterService#unvoidEncounter(Encounter)
*/
@Test
public void saveEncounter_shouldSetDateStoppedOnTheOriginalAfterAddingReviseOrder() {
EncounterService es = Context.getEncounterService();
TestOrder order = (TestOrder) Context.getOrderService().getOrder(7);
Assert.assertNull(order.getDateStopped());
Encounter encounter = es.getEncounter(6);
TestOrder reviseOrder = order.cloneForRevision();
reviseOrder.setOrderer(Context.getProviderService().getProvider(1));
encounter.addOrder(reviseOrder);
es.saveEncounter(encounter);
Context.flushSession();
Context.clearSession();
Date dateStopped = Context.getOrderService().getOrder(7).getDateStopped();
Assert.assertNotNull(dateStopped);
}
use of org.openmrs.TestOrder in project openmrs-core by openmrs.
the class TestOrderValidatorTest method validate_shouldFailValidationIfTheSpecimenSourceIsInvalid.
/**
* @see TestOrderValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailValidationIfTheSpecimenSourceIsInvalid() {
ConceptService conceptService = Context.getConceptService();
Concept specimenSource = conceptService.getConcept(3);
OrderService orderService = Context.getOrderService();
assertThat(specimenSource, not(isIn(orderService.getDrugRoutes())));
TestOrder order = new TestOrder();
Patient patient = new Patient(8);
order.setPatient(patient);
order.setOrderType(orderService.getOrderTypeByName("Test order"));
order.setConcept(conceptService.getConcept(5497));
order.setOrderer(new Provider());
order.setCareSetting(new CareSetting());
Encounter encounter = new Encounter();
encounter.setPatient(patient);
order.setEncounter(encounter);
order.setDateActivated(new Date());
order.setSpecimenSource(specimenSource);
Errors errors = new BindException(order, "order");
new TestOrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors("specimenSource"));
Assert.assertEquals("TestOrder.error.specimenSourceNotAmongAllowedConcepts", errors.getFieldError("specimenSource").getCode());
}
Aggregations