use of org.openmrs.Concept in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method validate_shouldFailValidationIfDoseUnitsIsNotADoseUnitConcept.
/**
* @see DrugOrderValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfDoseUnitsIsNotADoseUnitConcept() {
Concept concept = Context.getConceptService().getConcept(3);
assertThat(concept, not(isIn(Context.getOrderService().getDrugDosingUnits())));
DrugOrder order = new DrugOrder();
order.setDosingType(FreeTextDosingInstructions.class);
order.setDuration(5);
order.setDurationUnits(concept);
order.setDose(1.0);
order.setDoseUnits(concept);
order.setQuantity(30.0);
order.setQuantityUnits(concept);
Errors errors = new BindException(order, "order");
new DrugOrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors("doseUnits"));
}
use of org.openmrs.Concept in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method validate_shouldFailValidationIfDurationUnitsIsNotADurationUnitConcept.
/**
* @see DrugOrderValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfDurationUnitsIsNotADurationUnitConcept() {
Concept concept = Context.getConceptService().getConcept(3);
assertThat(concept, not(isIn(Context.getOrderService().getDurationUnits())));
DrugOrder order = new DrugOrder();
order.setDosingType(FreeTextDosingInstructions.class);
order.setDuration(5);
order.setDurationUnits(concept);
order.setDose(1.0);
order.setDoseUnits(concept);
order.setQuantity(30.0);
order.setQuantityUnits(concept);
Errors errors = new BindException(order, "order");
new DrugOrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors("durationUnits"));
}
use of org.openmrs.Concept in project openmrs-core by openmrs.
the class AllergyValidatorTest method validate_shouldPassForAValidAllergy.
/**
* @see AllergyValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldPassForAValidAllergy() {
Allergies allergies = new Allergies();
Concept aspirin = new Concept();
Allergen allergen1 = new Allergen(AllergenType.DRUG, aspirin, null);
allergies.add(new Allergy(null, allergen1, null, null, null));
when(ps.getAllergies(any(Patient.class))).thenReturn(allergies);
Allergen anotherAllergen = new Allergen(AllergenType.DRUG, new Concept(), null);
Allergy allergy = new Allergy(mock(Patient.class), anotherAllergen, null, null, null);
Errors errors = new BindException(allergy, "allergy");
validator.validate(allergy, errors);
assertFalse(errors.hasErrors());
}
use of org.openmrs.Concept in project openmrs-core by openmrs.
the class AllergyValidatorTest method createMockConcept.
private Concept createMockConcept(String uuid) {
Concept concept = mock(Concept.class);
when(concept.getUuid()).thenReturn(uuid != null ? uuid : "some uuid");
when(concept.getName()).thenReturn(new ConceptName());
return concept;
}
use of org.openmrs.Concept in project openmrs-core by openmrs.
the class AllergyValidatorTest method validate_shouldFailIfNonCodedAllergenIsNullAndAllergenIsSetToOtherNonCoded.
/**
* @see AllergyValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailIfNonCodedAllergenIsNullAndAllergenIsSetToOtherNonCoded() {
Allergen allergen = mock(Allergen.class);
when(allergen.getAllergenType()).thenReturn(AllergenType.DRUG);
Concept concept = createMockConcept(getOtherNonCodedConceptUuid());
when(allergen.getCodedAllergen()).thenReturn(concept);
when(allergen.getNonCodedAllergen()).thenReturn("");
when(allergen.isCoded()).thenReturn(false);
allergy.setAllergen(allergen);
validator.validate(allergy, errors);
assertTrue(errors.hasFieldErrors("allergen"));
assertThat(errors.getFieldError("allergen").getCode(), is("allergyapi.allergen.nonCodedAllergen.required"));
}
Aggregations