use of org.openmrs.api.ConceptService in project openmrs-core by openmrs.
the class ConceptReferenceTermValidatorTest method validate_shouldFailIfATermIsMappedMultipleTimesToTheSameTerm.
/**
* @see ConceptReferenceTermValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfATermIsMappedMultipleTimesToTheSameTerm() {
ConceptReferenceTerm term = new ConceptReferenceTerm();
ConceptService cs = Context.getConceptService();
term.setCode("unique code");
term.setConceptSource(Context.getConceptService().getConceptSource(1));
ConceptReferenceTermMap map1 = new ConceptReferenceTermMap(cs.getConceptReferenceTerm(1), cs.getConceptMapType(1));
term.addConceptReferenceTermMap(map1);
// test should fail if we change the term below
ConceptReferenceTermMap map2 = new ConceptReferenceTermMap(cs.getConceptReferenceTerm(1), cs.getConceptMapType(1));
term.addConceptReferenceTermMap(map2);
Errors errors = new BindException(term, "term");
new ConceptReferenceTermValidator().validate(term, errors);
System.err.println(errors.getAllErrors());
// the term for second mapping should be rejected
Assert.assertEquals(true, errors.hasFieldErrors("conceptReferenceTermMaps[1].termB"));
}
use of org.openmrs.api.ConceptService in project openmrs-core by openmrs.
the class ConceptDAOTest method getConcepts_shouldReturnCorrectResultsForConceptWithNamesThatContainsWordsWithMoreWeight.
/**
* @see {@link
* ConceptDAO#getConcepts(String,List<Locale>,null,List<ConceptClass>,List<ConceptClass
* >,List<ConceptDatatype>,List<ConceptDatatype>,Concept,Integer,Integer)}
*/
@SuppressWarnings("unchecked")
@Test
@Ignore
public void getConcepts_shouldReturnCorrectResultsForConceptWithNamesThatContainsWordsWithMoreWeight() {
executeDataSet("org/openmrs/api/include/ConceptServiceTest-words.xml");
Concept conceptWithMultipleMatchingNames = dao.getConcept(3000);
// recalculate the weights just in case the logic for calculating the weights is changed
ConceptService cs = Context.getConceptService();
cs.updateConceptIndex(conceptWithMultipleMatchingNames);
cs.updateConceptIndex(dao.getConcept(4000));
List<ConceptSearchResult> searchResults = dao.getConcepts("trust", Collections.singletonList(Locale.ENGLISH), false, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, null, null, null);
Assert.assertEquals(2, searchResults.size());
// the first concept is the one with a word with the highest weight
Assert.assertEquals(conceptWithMultipleMatchingNames, searchResults.get(0).getConcept());
// For conceptId=3000, its search result should ALWAYS match on 'TRUST ME' because it is shorter THAN 'TRUST ALWAYS'
Assert.assertEquals(9998, searchResults.get(0).getConceptName().getConceptNameId().intValue());
}
use of org.openmrs.api.ConceptService in project openmrs-core by openmrs.
the class OpenmrsUtil method conceptSetHelper.
public static Set<Concept> conceptSetHelper(String descriptor) {
Set<Concept> ret = new HashSet<>();
if (descriptor == null || descriptor.length() == 0) {
return ret;
}
ConceptService cs = Context.getConceptService();
for (StringTokenizer st = new StringTokenizer(descriptor, "|"); st.hasMoreTokens(); ) {
String s = st.nextToken().trim();
boolean isSet = s.startsWith("set:");
if (isSet) {
s = s.substring(4).trim();
}
Concept c = null;
if (s.startsWith("name:")) {
String name = s.substring(5).trim();
c = cs.getConceptByName(name);
} else {
try {
c = cs.getConcept(Integer.valueOf(s.trim()));
} catch (Exception ex) {
}
}
if (c != null) {
if (isSet) {
List<Concept> inSet = cs.getConceptsByConceptSet(c);
ret.addAll(inSet);
} else {
ret.add(c);
}
}
}
return ret;
}
use of org.openmrs.api.ConceptService in project openmrs-core by openmrs.
the class TestOrderValidatorTest method validate_shouldFailValidationIfTheSpecimenSourceIsInvalid.
/**
* @see TestOrderValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailValidationIfTheSpecimenSourceIsInvalid() {
ConceptService conceptService = Context.getConceptService();
Concept specimenSource = conceptService.getConcept(3);
OrderService orderService = Context.getOrderService();
assertThat(specimenSource, not(isIn(orderService.getDrugRoutes())));
TestOrder order = new TestOrder();
Patient patient = new Patient(8);
order.setPatient(patient);
order.setOrderType(orderService.getOrderTypeByName("Test order"));
order.setConcept(conceptService.getConcept(5497));
order.setOrderer(new Provider());
order.setCareSetting(new CareSetting());
Encounter encounter = new Encounter();
encounter.setPatient(patient);
order.setEncounter(encounter);
order.setDateActivated(new Date());
order.setSpecimenSource(specimenSource);
Errors errors = new BindException(order, "order");
new TestOrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors("specimenSource"));
Assert.assertEquals("TestOrder.error.specimenSourceNotAmongAllowedConcepts", errors.getFieldError("specimenSource").getCode());
}
use of org.openmrs.api.ConceptService in project openmrs-core by openmrs.
the class TestOrderValidatorTest method validate_shouldPassValidationIfTheSpecimenSourceIsValid.
/**
* @see TestOrderValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldPassValidationIfTheSpecimenSourceIsValid() {
ConceptService conceptService = Context.getConceptService();
Concept specimenSource = conceptService.getConcept(22);
OrderService orderService = Context.getOrderService();
assertThat(specimenSource, isIn(orderService.getDrugRoutes()));
TestOrder order = new TestOrder();
Patient patient = new Patient(8);
order.setPatient(patient);
order.setOrderType(orderService.getOrderTypeByName("Test order"));
order.setConcept(conceptService.getConcept(5497));
order.setOrderer(Context.getProviderService().getProvider(1));
order.setCareSetting(new CareSetting());
Encounter encounter = new Encounter();
encounter.setPatient(patient);
order.setEncounter(encounter);
order.setDateActivated(new Date());
order.setSpecimenSource(specimenSource);
Errors errors = new BindException(order, "order");
new TestOrderValidator().validate(order, errors);
Assert.assertFalse(errors.hasFieldErrors());
}
Aggregations