Search in sources :

Example 31 with Drug

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

the class ConceptServiceImplTest method getDrugs_shouldReturnListOfMatchingDrugs.

/**
 * @see ConceptServiceImpl#getDrugs(String, Concept, boolean, boolean, boolean, Integer,
 *      Integer)
 */
@Test
public void getDrugs_shouldReturnListOfMatchingDrugs() {
    String drugName = "ASPIRIN";
    String drugUuid = "05ec820a-d297-44e3-be6e-698531d9dd3f";
    Concept concept = conceptService.getConceptByUuid(drugUuid);
    List<Drug> drugs = conceptService.getDrugs(drugName, concept, true, true, true, 0, 100);
    assertTrue(drugs.contains(conceptService.getDrug(drugName)));
}
Also used : Concept(org.openmrs.Concept) Drug(org.openmrs.Drug) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 32 with Drug

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

the class ConceptServiceImplTest method unretireDrug_shouldNotChangeAttributesOfDrugThatIsAlreadyNotRetired.

/**
 * @see ConcepTServiceImpl#unretireDrug(Drug)
 */
@Test
public void unretireDrug_shouldNotChangeAttributesOfDrugThatIsAlreadyNotRetired() {
    String uuidOfDrugToCheck = "3cfcf118-931c-46f7-8ff6-7b876f0d4202";
    Drug drug = conceptService.getDrugByUuid(uuidOfDrugToCheck);
    assertFalse(drug.getRetired());
    conceptService.unretireDrug(drug);
    assertFalse(drug.getRetired());
}
Also used : Drug(org.openmrs.Drug) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 33 with Drug

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

the class ConceptDrugValidatorTest method validate_shouldFailIfAConceptIsNotSpecified.

/**
 * @see ConceptDrugValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfAConceptIsNotSpecified() {
    Drug drug = new Drug();
    Errors errors = new BindException(drug, "drug");
    new ConceptDrugValidator().validate(drug, errors);
    Assert.assertTrue(errors.hasErrors());
}
Also used : Drug(org.openmrs.Drug) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Test(org.junit.Test)

Example 34 with Drug

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

the class DrugValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * @see DrugValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    Drug drug = new Drug();
    drug.addDrugReferenceMap(new DrugReferenceMap(conceptService.getConceptReferenceTerm(1), conceptService.getConceptMapType(1)));
    drug.setName("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    drug.setStrength("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    drug.setRetireReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    Errors errors = new BindException(drug, "drug");
    new DrugValidator().validate(drug, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
    Assert.assertTrue(errors.hasFieldErrors("strength"));
    Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
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 35 with Drug

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

the class DrugValidatorTest method validate_shouldRejectDrugMultipleMappingsToTheSameTerm.

/**
 * @see DrugValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldRejectDrugMultipleMappingsToTheSameTerm() {
    Drug drug = new Drug();
    DrugReferenceMap term1 = new DrugReferenceMap(conceptService.getConceptReferenceTerm(1), conceptService.getConceptMapType(1));
    DrugReferenceMap term2 = new DrugReferenceMap(conceptService.getConceptReferenceTerm(1), conceptService.getConceptMapType(2));
    drug.addDrugReferenceMap(term1);
    drug.addDrugReferenceMap(term2);
    Assert.assertEquals(2, drug.getDrugReferenceMaps().size());
    Errors errors = new BindException(drug, "drug");
    new DrugValidator().validate(drug, errors);
    Assert.assertTrue(errors.hasFieldErrors("drugReferenceMaps[1].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