use of org.openmrs.CareSetting in project openmrs-core by openmrs.
the class OrderValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
/**
* @see OrderValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
Order order = new Order();
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.setOrderReasonNonCoded("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
order.setAccessionNumber("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
order.setCommentToFulfiller("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
order.setVoidReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
Errors errors = new BindException(order, "order");
new OrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors("accessionNumber"));
Assert.assertTrue(errors.hasFieldErrors("orderReasonNonCoded"));
Assert.assertTrue(errors.hasFieldErrors("commentToFulfiller"));
Assert.assertTrue(errors.hasFieldErrors("voidReason"));
}
use of org.openmrs.CareSetting in project openmrs-core by openmrs.
the class OrderValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* @see OrderValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
Order order = new Order();
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.setOrderReasonNonCoded("orderReasonNonCoded");
order.setAccessionNumber("accessionNumber");
order.setCommentToFulfiller("commentToFulfiller");
order.setVoidReason("voidReason");
Errors errors = new BindException(order, "order");
new OrderValidator().validate(order, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.CareSetting in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method saveOrder_shouldFailDrugOrderWithBothDrugNonCodedAndDrugAreSetForDrugOrder.
@Test
public void saveOrder_shouldFailDrugOrderWithBothDrugNonCodedAndDrugAreSetForDrugOrder() {
Patient patient = Context.getPatientService().getPatient(7);
CareSetting careSetting = Context.getOrderService().getCareSetting(2);
OrderType orderType = Context.getOrderService().getOrderTypeByName("Drug order");
GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG, "true");
Context.getAdministrationService().saveGlobalProperty(gp);
// place drug order
DrugOrder order = new DrugOrder();
Encounter encounter = Context.getEncounterService().getEncounter(3);
order.setEncounter(encounter);
order.setDrug(Context.getConceptService().getDrug(3));
order.setDrugNonCoded("paracetemol drug non coded");
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());
assertEquals("DrugOrder.error.onlyOneOfDrugOrNonCodedShouldBeSet", errors.getFieldError("concept").getCode());
}
use of org.openmrs.CareSetting in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method saveOrder_shouldPassDrugOrderWithoutADrugWhenDrugOrderRequireDrugGBIsNotSet.
/**
* @throws SQLException
* @see org.openmrs.api.OrderService#saveOrder(org.openmrs.Order, org.openmrs.api.OrderContext)
*/
@Test
public void saveOrder_shouldPassDrugOrderWithoutADrugWhenDrugOrderRequireDrugGBIsNotSet() throws SQLException {
deleteAllData();
baseSetupWithStandardDataAndAuthentication();
Patient patient = Context.getPatientService().getPatient(7);
CareSetting careSetting = Context.getOrderService().getCareSetting(2);
OrderType orderType = Context.getOrderService().getOrderTypeByName("Drug order");
assertNull(Context.getAdministrationService().getGlobalPropertyObject(OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG));
// 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.assertFalse(errors.hasFieldErrors());
}
use of org.openmrs.CareSetting in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method saveOrder_shouldFailDrugOrderWithoutADrugNonCodedWhenDrugOrderIsNonCoded.
@Test
public void saveOrder_shouldFailDrugOrderWithoutADrugNonCodedWhenDrugOrderIsNonCoded() {
executeDataSet("org/openmrs/api/include/OrderServiceTest-nonCodedDrugs.xml");
Patient patient = Context.getPatientService().getPatient(7);
CareSetting careSetting = Context.getOrderService().getCareSetting(2);
OrderType orderType = Context.getOrderService().getOrderTypeByName("Drug order");
GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG, "true");
Context.getAdministrationService().saveGlobalProperty(gp);
// place drug order
DrugOrder order = new DrugOrder();
Encounter encounter = Context.getEncounterService().getEncounter(3);
order.setEncounter(encounter);
order.setConcept(Context.getOrderService().getNonCodedDrugConcept());
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());
assertEquals("DrugOrder.error.drugNonCodedIsRequired", errors.getFieldError("drugNonCoded").getCode());
}
Aggregations