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);
}
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;
}
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));
}
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));
}
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));
}
Aggregations