Search in sources :

Example 71 with Concept

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"));
}
Also used : Concept(org.openmrs.Concept) DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 72 with Concept

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"));
}
Also used : Concept(org.openmrs.Concept) DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 73 with Concept

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());
}
Also used : Concept(org.openmrs.Concept) Allergy(org.openmrs.Allergy) Errors(org.springframework.validation.Errors) Patient(org.openmrs.Patient) BindException(org.springframework.validation.BindException) Allergies(org.openmrs.Allergies) Allergen(org.openmrs.Allergen) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 74 with Concept

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;
}
Also used : Concept(org.openmrs.Concept) ConceptName(org.openmrs.ConceptName)

Example 75 with 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"));
}
Also used : Concept(org.openmrs.Concept) Allergen(org.openmrs.Allergen) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Concept (org.openmrs.Concept)294 Test (org.junit.Test)210 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)176 ConceptName (org.openmrs.ConceptName)62 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)62 Obs (org.openmrs.Obs)49 Date (java.util.Date)48 Patient (org.openmrs.Patient)42 ConceptDescription (org.openmrs.ConceptDescription)33 Locale (java.util.Locale)32 ConceptDatatype (org.openmrs.ConceptDatatype)32 OrderUtilTest (org.openmrs.order.OrderUtilTest)29 ConceptClass (org.openmrs.ConceptClass)27 ArrayList (java.util.ArrayList)26 BindException (org.springframework.validation.BindException)26 DrugOrder (org.openmrs.DrugOrder)25 Encounter (org.openmrs.Encounter)25 Errors (org.springframework.validation.Errors)25 ConceptMapBuilder (org.openmrs.module.metadatadeploy.builder.ConceptMapBuilder)21 Location (org.openmrs.Location)19