use of org.openmrs.Encounter in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method saveOrder_shouldFailDrugOrderWithNeitherDrugNonCodedNorDrugAreSetForDrugOrderWhenDrugRequiredSet.
@Test
public void saveOrder_shouldFailDrugOrderWithNeitherDrugNonCodedNorDrugAreSetForDrugOrderWhenDrugRequiredSet() {
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.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.drugIsRequired", errors.getFieldError("drug").getCode());
}
use of org.openmrs.Encounter in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method saveOrder_shouldPassDrugOrderWithoutADrugWhenDrugOrderRequireDrugGBIsFalse.
/**
* @see org.openmrs.api.OrderService#saveOrder(org.openmrs.Order, org.openmrs.api.OrderContext)
*/
@Test
public void saveOrder_shouldPassDrugOrderWithoutADrugWhenDrugOrderRequireDrugGBIsFalse() {
GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG, "false");
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.assertFalse(errors.hasFieldErrors());
}
use of org.openmrs.Encounter 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.Encounter in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
/**
* @see DrugOrderValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
DrugOrder order = new DrugOrder();
Encounter encounter = new Encounter();
Patient patient = Context.getPatientService().getPatient(2);
order.setConcept(Context.getConceptService().getConcept(88));
order.setOrderer(Context.getProviderService().getProvider(1));
order.setDosingType(FreeTextDosingInstructions.class);
order.setInstructions("Instructions");
order.setDosingInstructions("Test Instruction");
order.setPatient(patient);
encounter.setPatient(patient);
order.setEncounter(encounter);
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.setOrderType(Context.getOrderService().getOrderTypeByName("Drug order"));
order.setDrug(Context.getConceptService().getDrug(3));
order.setCareSetting(Context.getOrderService().getCareSetting(1));
order.setQuantity(2.00);
order.setQuantityUnits(Context.getConceptService().getConcept(51));
order.setNumRefills(10);
order.setAsNeededCondition("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.setBrandName("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 DrugOrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors("asNeededCondition"));
Assert.assertTrue(errors.hasFieldErrors("brandName"));
}
use of org.openmrs.Encounter in project openmrs-core by openmrs.
the class EncounterValidatorTest method validate_shouldFailIfEncounterDateTimeIsAfterCurrentDateTime.
/**
* @see EncounterValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfEncounterDateTimeIsAfterCurrentDateTime() {
Encounter encounter = Context.getEncounterService().getEncounter(3);
// Set encounter dateTime after the current dateTime.
Calendar calendar = new GregorianCalendar();
calendar.add(Calendar.DAY_OF_YEAR, 1);
Date tomorrowDate = calendar.getTime();
encounter.setEncounterDatetime(tomorrowDate);
errors = new BindException(encounter, "encounter");
encounterValidator.validate(encounter, errors);
Assert.assertEquals(true, errors.hasFieldErrors("encounterDatetime"));
}
Aggregations