Search in sources :

Example 36 with Drug

use of org.openmrs.Drug in project openmrs-core by openmrs.

the class DrugValidatorTest method validate_shouldInvokeConceptMapTypeValidatorIfConceptMapTypeOnDrugReferenceMapIsNew.

/**
 * @see DrugValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldInvokeConceptMapTypeValidatorIfConceptMapTypeOnDrugReferenceMapIsNew() {
    Drug drug = new Drug();
    drug.addDrugReferenceMap(new DrugReferenceMap(conceptService.getConceptReferenceTerm(1), new ConceptMapType()));
    Errors errors = new BindException(drug, "drug");
    new DrugValidator().validate(drug, errors);
    // concept map type validator should have been called which should reject a null name
    Assert.assertTrue(errors.hasFieldErrors("drugReferenceMaps[0].conceptMapType.name"));
}
Also used : Drug(org.openmrs.Drug) Errors(org.springframework.validation.Errors) ConceptMapType(org.openmrs.ConceptMapType) BindException(org.springframework.validation.BindException) DrugReferenceMap(org.openmrs.DrugReferenceMap) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 37 with Drug

use of org.openmrs.Drug in project openmrs-core by openmrs.

the class DrugValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.

/**
 * @see DrugValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
    Drug drug = new Drug();
    drug.addDrugReferenceMap(new DrugReferenceMap(conceptService.getConceptReferenceTerm(1), conceptService.getConceptMapType(1)));
    drug.setName("name");
    drug.setStrength("strength");
    drug.setRetireReason("retireReason");
    Errors errors = new BindException(drug, "drug");
    new DrugValidator().validate(drug, errors);
    Assert.assertFalse(errors.hasFieldErrors());
}
Also used : Drug(org.openmrs.Drug) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) DrugReferenceMap(org.openmrs.DrugReferenceMap) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 38 with Drug

use of org.openmrs.Drug in project openmrs-core by openmrs.

the class ObsValidatorTest method validate_shouldPassIfAnswerConceptAndConceptOfValueDrugMatch.

/**
 * @see ObsValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassIfAnswerConceptAndConceptOfValueDrugMatch() {
    Obs obs = new Obs();
    obs.setPerson(new Person(7));
    obs.setObsDatetime(new Date());
    Concept questionConcept = new Concept(100);
    ConceptDatatype dt = new ConceptDatatype(1);
    dt.setUuid(ConceptDatatype.CODED_UUID);
    questionConcept.setDatatype(dt);
    obs.setConcept(questionConcept);
    Concept answerConcept = new Concept(101);
    obs.setValueCoded(answerConcept);
    Drug drug = new Drug();
    drug.setConcept(answerConcept);
    obs.setValueDrug(drug);
    Errors errors = new BindException(obs, "obs");
    obsValidator.validate(obs, errors);
    assertFalse(errors.hasFieldErrors());
}
Also used : Concept(org.openmrs.Concept) Drug(org.openmrs.Drug) Obs(org.openmrs.Obs) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Person(org.openmrs.Person) ConceptDatatype(org.openmrs.ConceptDatatype) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 39 with Drug

use of org.openmrs.Drug in project openmrs-core by openmrs.

the class ObsValidatorTest method validate_shouldRejectAnInvalidConceptAndDrugCombination.

/**
 * @see ObsValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldRejectAnInvalidConceptAndDrugCombination() {
    Obs obs = new Obs();
    obs.setPerson(new Person(7));
    obs.setObsDatetime(new Date());
    Concept questionConcept = new Concept(100);
    ConceptDatatype dt = new ConceptDatatype(1);
    dt.setUuid(ConceptDatatype.CODED_UUID);
    questionConcept.setDatatype(dt);
    obs.setConcept(questionConcept);
    obs.setValueCoded(new Concept(101));
    Drug drug = new Drug();
    drug.setConcept(new Concept(102));
    obs.setValueDrug(drug);
    Errors errors = new BindException(obs, "obs");
    obsValidator.validate(obs, errors);
    assertTrue(errors.hasFieldErrors("valueDrug"));
}
Also used : Concept(org.openmrs.Concept) Drug(org.openmrs.Drug) Obs(org.openmrs.Obs) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Person(org.openmrs.Person) ConceptDatatype(org.openmrs.ConceptDatatype) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 40 with Drug

use of org.openmrs.Drug in project openmrs-core by openmrs.

the class DrugsByNameComparatorTest method compareDrugNamesIgnoringNumericals_shouldReturnNegativeIfNameForDrug1ComesBeforeThatOfDrug2.

/**
 * @see DrugsByNameComparator#compareDrugNamesIgnoringNumericals(Drug,Drug)
 */
@Test
public void compareDrugNamesIgnoringNumericals_shouldReturnNegativeIfNameForDrug1ComesBeforeThatOfDrug2() {
    Drug drug1 = new Drug();
    drug1.setName("ABCD");
    Drug drug2 = new Drug();
    drug2.setName("BCDE");
    DrugsByNameComparator dComparator = new DrugsByNameComparator();
    int actualValue = dComparator.compare(drug1, drug2);
    Assert.assertEquals(actualValue, -1);
}
Also used : Drug(org.openmrs.Drug) Test(org.junit.Test)

Aggregations

Drug (org.openmrs.Drug)51 Test (org.junit.Test)46 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)41 Concept (org.openmrs.Concept)15 BindException (org.springframework.validation.BindException)15 Errors (org.springframework.validation.Errors)14 DrugReferenceMap (org.openmrs.DrugReferenceMap)9 ConceptMapType (org.openmrs.ConceptMapType)8 DrugOrder (org.openmrs.DrugOrder)7 OrderUtilTest (org.openmrs.order.OrderUtilTest)7 Date (java.util.Date)5 ConceptSource (org.openmrs.ConceptSource)5 ArrayList (java.util.ArrayList)4 Obs (org.openmrs.Obs)3 HashSet (java.util.HashSet)2 ConceptAnswer (org.openmrs.ConceptAnswer)2 ConceptDatatype (org.openmrs.ConceptDatatype)2 ConceptReferenceTerm (org.openmrs.ConceptReferenceTerm)2 Encounter (org.openmrs.Encounter)2 Person (org.openmrs.Person)2