use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method validate_shouldFailIfDurationUnitsHasNoMappingToSNOMEDCTSource.
/**
* @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailIfDurationUnitsHasNoMappingToSNOMEDCTSource() {
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);
ConceptService cs = Context.getConceptService();
order.setConcept(cs.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");
order.setDuration(20);
order.setDurationUnits(cs.getConcept(28));
Errors errors = new BindException(order, "order");
new DrugOrderValidator().validate(order, errors);
assertEquals("DrugOrder.error.durationUnitsNotMappedToSnomedCtDurationCode", errors.getFieldError("durationUnits").getCode());
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method validate_shouldFailValidationIfQuantityIsNullForOutpatientCareSetting.
/**
* @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailValidationIfQuantityIsNullForOutpatientCareSetting() {
DrugOrder OutpatientOrder = new DrugOrder();
OutpatientOrder.setCareSetting(Context.getOrderService().getCareSetting(1));
OutpatientOrder.setQuantity(null);
Errors OutpatientOrderErrors = new BindException(OutpatientOrder, "order");
new DrugOrderValidator().validate(OutpatientOrder, OutpatientOrderErrors);
Assert.assertTrue(OutpatientOrderErrors.hasFieldErrors("quantity"));
DrugOrder inPatientOrder = new DrugOrder();
inPatientOrder.setCareSetting(Context.getOrderService().getCareSetting(2));
inPatientOrder.setQuantity(null);
Errors InpatientOrderErrors = new BindException(inPatientOrder, "order");
new DrugOrderValidator().validate(inPatientOrder, InpatientOrderErrors);
Assert.assertFalse(InpatientOrderErrors.hasFieldErrors("quantity"));
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method validate_shouldPassValidationIfAllFieldsAreCorrect.
/**
* @see DrugOrderValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfAllFieldsAreCorrect() {
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);
Errors errors = new BindException(order, "order");
new DrugOrderValidator().validate(order, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method validate_shouldFailValidationIfDosingTypeIsNull.
/**
* @see DrugOrderValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfDosingTypeIsNull() {
DrugOrder order = new DrugOrder();
order.setDosingType(null);
order.setDrug(Context.getConceptService().getDrug(3));
Errors errors = new BindException(order, "order");
new DrugOrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors("dosingType"));
}
use of org.openmrs.DrugOrder in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method validate_shouldFailValidationIfDosingInstructionsIsNullForFreeTextDosingInstructionsDosingType.
/**
* @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailValidationIfDosingInstructionsIsNullForFreeTextDosingInstructionsDosingType() {
DrugOrder order = new DrugOrder();
order.setDosingType(FreeTextDosingInstructions.class);
order.setDosingInstructions(null);
Errors errors = new BindException(order, "order");
new DrugOrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors("dosingInstructions"));
}
Aggregations