use of org.openmrs.CareSetting in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method saveOrder_shouldFailDrugOrderWithoutADrugWhenDrugOrderRequireDrugGBIsTrue.
/**
* @see org.openmrs.api.OrderService#saveOrder(org.openmrs.Order, org.openmrs.api.OrderContext)
*/
@Test
public void saveOrder_shouldFailDrugOrderWithoutADrugWhenDrugOrderRequireDrugGBIsTrue() {
GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG, "true");
Context.getAdministrationService().saveGlobalProperty(gp);
Patient patient = Context.getPatientService().getPatient(7);
CareSetting careSetting = Context.getOrderService().getCareSetting(2);
OrderType orderType = Context.getOrderService().getOrderTypeByName("Drug order");
// place drug order
DrugOrder order = new DrugOrder();
Encounter encounter = Context.getEncounterService().getEncounter(3);
order.setEncounter(encounter);
order.setConcept(Context.getConceptService().getConcept(5497));
order.setPatient(patient);
order.setCareSetting(careSetting);
order.setOrderer(Context.getProviderService().getProvider(1));
order.setDateActivated(encounter.getEncounterDatetime());
order.setOrderType(orderType);
order.setDosingType(FreeTextDosingInstructions.class);
order.setInstructions("None");
order.setDosingInstructions("Test Instruction");
Errors errors = new BindException(order, "order");
new DrugOrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors("drug"));
}
use of org.openmrs.CareSetting in project openmrs-core by openmrs.
the class OrderServiceImpl method ensureCareSettingIsSet.
private void ensureCareSettingIsSet(Order order, OrderContext orderContext) {
if (order.getCareSetting() != null) {
return;
}
CareSetting careSetting = null;
if (orderContext != null) {
careSetting = orderContext.getCareSetting();
}
Order previousOrder = order.getPreviousOrder();
if (careSetting == null || (previousOrder != null && !careSetting.equals(previousOrder.getCareSetting()))) {
throw new OrderEntryException("Order.care.cannot.determine");
}
order.setCareSetting(careSetting);
}
use of org.openmrs.CareSetting 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());
}
use of org.openmrs.CareSetting in project openmrs-core by openmrs.
the class TestOrderValidatorTest method validate_shouldPassValidationIfTheSpecimenSourceIsValid.
/**
* @see TestOrderValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldPassValidationIfTheSpecimenSourceIsValid() {
ConceptService conceptService = Context.getConceptService();
Concept specimenSource = conceptService.getConcept(22);
OrderService orderService = Context.getOrderService();
assertThat(specimenSource, 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(Context.getProviderService().getProvider(1));
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.assertFalse(errors.hasFieldErrors());
}
use of org.openmrs.CareSetting in project openmrs-core by openmrs.
the class OrderValidatorTest method validate_shouldPassValidationIfAllFieldsAreCorrect.
/**
* @see OrderValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfAllFieldsAreCorrect() {
Order order = new DrugOrder();
Encounter encounter = new Encounter();
order.setConcept(Context.getConceptService().getConcept(88));
order.setOrderer(Context.getProviderService().getProvider(1));
Patient patient = Context.getPatientService().getPatient(2);
encounter.setPatient(patient);
order.setPatient(patient);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) - 1);
order.setDateActivated(cal.getTime());
order.setAutoExpireDate(new Date());
order.setCareSetting(new CareSetting());
order.setEncounter(encounter);
order.setUrgency(Order.Urgency.ROUTINE);
order.setAction(Order.Action.NEW);
order.setOrderType(Context.getOrderService().getOrderTypeByName("Drug order"));
Errors errors = new BindException(order, "order");
new OrderValidator().validate(order, errors);
Assert.assertFalse(errors.hasErrors());
}
Aggregations