Search in sources :

Example 41 with Drug

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

the class DrugsByNameComparatorTest method compareDrugNamesIgnoringNumericals_shouldReturnPositiveIfNameForDrug1ComesBeforeThatOfDrug2IgnoringDashes.

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

Example 42 with Drug

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

the class HibernateConceptDAO method getDrugByMapping.

/**
 * @see org.openmrs.api.db.ConceptDAO#getDrugs
 */
@Override
public Drug getDrugByMapping(String code, ConceptSource conceptSource, Collection<ConceptMapType> withAnyOfTheseTypesOrOrderOfPreference) throws DAOException {
    Criteria criteria = createSearchDrugByMappingCriteria(code, conceptSource, true);
    // match with any of the supplied collection or order of preference of conceptMapTypes
    if (!withAnyOfTheseTypesOrOrderOfPreference.isEmpty()) {
        for (ConceptMapType conceptMapType : withAnyOfTheseTypesOrOrderOfPreference) {
            criteria.add(Restrictions.eq("map.conceptMapType", conceptMapType));
            List<Drug> drugs = criteria.list();
            if (drugs.size() > 1) {
                throw new DAOException("There are multiple matches for the highest-priority ConceptMapType");
            } else if (drugs.size() == 1) {
                return drugs.get(0);
            }
            // reset for the next execution to avoid unwanted AND clauses on every found map type
            criteria = createSearchDrugByMappingCriteria(code, conceptSource, true);
        }
    } else {
        List<Drug> drugs = criteria.list();
        if (drugs.size() > 1) {
            throw new DAOException("There are multiple matches for the highest-priority ConceptMapType");
        } else if (drugs.size() == 1) {
            return drugs.get(0);
        }
    }
    return null;
}
Also used : Drug(org.openmrs.Drug) DAOException(org.openmrs.api.db.DAOException) ConceptMapType(org.openmrs.ConceptMapType) Criteria(org.hibernate.Criteria)

Example 43 with Drug

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

the class ConceptServiceTest method getDrugsByMapping_shouldGetAListOfAllDrugsThatMatchOnAllTheParameterValues.

/**
 * @see ConceptService#getDrugsByMapping(String, org.openmrs.ConceptSource,
 *      java.util.Collection, boolean)
 */
@Test
public void getDrugsByMapping_shouldGetAListOfAllDrugsThatMatchOnAllTheParameterValues() {
    executeDataSet(GET_DRUG_MAPPINGS);
    List<ConceptMapType> conceptMapTypeList = new ArrayList<>();
    conceptMapTypeList.add(conceptService.getConceptMapType(1));
    ConceptSource source = conceptService.getConceptSource(1);
    List<Drug> drugs = conceptService.getDrugsByMapping("WGT234", source, conceptMapTypeList, false);
    assertEquals(1, drugs.size());
    assertTrue(containsId(drugs, 2));
}
Also used : Drug(org.openmrs.Drug) ConceptMapType(org.openmrs.ConceptMapType) ArrayList(java.util.ArrayList) ConceptSource(org.openmrs.ConceptSource) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 44 with Drug

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

the class ConceptServiceTest method getDrugsByMapping_shouldExcludeDuplicateMatches.

/**
 * @see ConceptService#getDrugsByMapping(String, org.openmrs.ConceptSource,
 *      java.util.Collection, boolean)
 */
@Test
public void getDrugsByMapping_shouldExcludeDuplicateMatches() {
    executeDataSet(GET_DRUG_MAPPINGS);
    List<ConceptMapType> conceptMapTypeList = conceptService.getConceptMapTypes(false, true);
    // the expected matching drug has two mappings to different concept sources but same code
    // so this test also ensure that we can never get back duplicates
    ConceptSource source = conceptService.getConceptSource(1);
    List<Drug> drugs = conceptService.getDrugsByMapping("WGT234", source, conceptMapTypeList, false);
    assertEquals(1, drugs.size());
    assertTrue(containsId(drugs, 2));
}
Also used : Drug(org.openmrs.Drug) ConceptMapType(org.openmrs.ConceptMapType) ConceptSource(org.openmrs.ConceptSource) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 45 with Drug

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

the class ConceptServiceTest method getDrugsByMapping_shouldMatchOnTheMapTypes.

/**
 * @see ConceptService#getDrugsByMapping(String, ConceptSource, Collection, boolean)
 */
@Test
public void getDrugsByMapping_shouldMatchOnTheMapTypes() {
    executeDataSet(GET_DRUG_MAPPINGS);
    List<ConceptMapType> conceptMapTypeList = conceptService.getConceptMapTypes(false, true);
    ConceptSource source = conceptService.getConceptSource(1);
    List<Drug> drugs = conceptService.getDrugsByMapping(null, source, conceptMapTypeList, false);
    assertEquals(2, drugs.size());
    assertTrue(containsId(drugs, 2));
    assertTrue(containsId(drugs, 3));
    drugs = conceptService.getDrugsByMapping(null, source, conceptMapTypeList, true);
    assertEquals(3, drugs.size());
    assertTrue(containsId(drugs, 2));
    assertTrue(containsId(drugs, 3));
    assertTrue(containsId(drugs, 11));
}
Also used : Drug(org.openmrs.Drug) ConceptMapType(org.openmrs.ConceptMapType) ConceptSource(org.openmrs.ConceptSource) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) 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