Search in sources :

Example 11 with Drug

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

the class DrugOrderValidatorTest method validate_shouldFailIfConceptIsNullAndCannotInferItFromDrug.

/**
 * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailIfConceptIsNullAndCannotInferItFromDrug() {
    DrugOrder order = new DrugOrder();
    Drug drug = Context.getConceptService().getDrug(3);
    drug.setConcept(null);
    order.setDrug(drug);
    Errors errors = new BindException(order, "order");
    adminService.validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("concept"));
}
Also used : DrugOrder(org.openmrs.DrugOrder) Drug(org.openmrs.Drug) 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 12 with Drug

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

the class ConceptServiceImpl method getDrugs.

/**
 * @see org.openmrs.api.ConceptService#getDrugs(java.lang.String)
 */
@Override
@Transactional(readOnly = true)
public List<Drug> getDrugs(String phrase) {
    List<Drug> drugs = new ArrayList<>();
    // trying to treat search phrase as drug id
    try {
        Integer drugId = Integer.parseInt(phrase);
        Drug targetDrug = Context.getConceptService().getDrug(drugId);
        // if drug was found add it to result
        if (targetDrug != null) {
            drugs.add(targetDrug);
        }
    } catch (NumberFormatException e) {
    // do nothing
    }
    // also try to treat search phrase as drug concept id
    try {
        Integer conceptId = Integer.parseInt(phrase);
        Concept targetConcept = Context.getConceptService().getConcept(conceptId);
        if (targetConcept != null) {
            drugs.addAll(Context.getConceptService().getDrugsByConcept(targetConcept));
        }
    } catch (NumberFormatException e) {
    // do nothing
    }
    drugs.addAll(dao.getDrugs(phrase));
    return drugs;
}
Also used : Drug(org.openmrs.Drug) Concept(org.openmrs.Concept) ArrayList(java.util.ArrayList) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with Drug

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

the class DrugValidatorTest method validate_shouldInvokeConceptReferenceTermValidatorIfTermOnDrugReferenceMapIsNew.

/**
 * @see DrugValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldInvokeConceptReferenceTermValidatorIfTermOnDrugReferenceMapIsNew() {
    Drug drug = new Drug();
    drug.addDrugReferenceMap(new DrugReferenceMap(new ConceptReferenceTerm(), null));
    Errors errors = new BindException(drug, "drug");
    new DrugValidator().validate(drug, errors);
    // reference term validator should have been called which should reject a null code
    Assert.assertTrue(errors.hasFieldErrors("drugReferenceMaps[0].conceptReferenceTerm.code"));
}
Also used : Drug(org.openmrs.Drug) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) DrugReferenceMap(org.openmrs.DrugReferenceMap) ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 14 with Drug

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

the class DrugValidatorTest method validate_shouldFailIfTheDrugObjectIsNull.

/**
 * @see DrugValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailIfTheDrugObjectIsNull() {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("The parameter obj should not be null and must be of type" + Drug.class);
    new DrugValidator().validate(null, new BindException(new Drug(), "drug"));
}
Also used : Drug(org.openmrs.Drug) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 15 with Drug

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

the class DrugValidatorTest method validate_shouldFailIfConceptReferenceTermOnDrugReferenceMapIsNull.

/**
 * @see DrugValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailIfConceptReferenceTermOnDrugReferenceMapIsNull() {
    Drug drug = new Drug();
    drug.addDrugReferenceMap(new DrugReferenceMap());
    Errors errors = new BindException(drug, "drug");
    new DrugValidator().validate(drug, errors);
    Assert.assertTrue(errors.hasFieldErrors("drugReferenceMaps[0].conceptReferenceTerm"));
}
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)

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