Search in sources :

Example 6 with ConceptService

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"));
}
Also used : Errors(org.springframework.validation.Errors) ConceptReferenceTermMap(org.openmrs.ConceptReferenceTermMap) BindException(org.springframework.validation.BindException) ConceptService(org.openmrs.api.ConceptService) ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 7 with ConceptService

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());
}
Also used : Concept(org.openmrs.Concept) ConceptSearchResult(org.openmrs.ConceptSearchResult) ConceptService(org.openmrs.api.ConceptService) Ignore(org.junit.Ignore) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 8 with ConceptService

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;
}
Also used : Concept(org.openmrs.Concept) StringTokenizer(java.util.StringTokenizer) ConceptService(org.openmrs.api.ConceptService) ApplicationContextException(org.springframework.context.ApplicationContextException) TransformerException(javax.xml.transform.TransformerException) InvalidCharactersPasswordException(org.openmrs.api.InvalidCharactersPasswordException) IOException(java.io.IOException) NoSuchMessageException(org.springframework.context.NoSuchMessageException) ModuleException(org.openmrs.module.ModuleException) PatternSyntaxException(java.util.regex.PatternSyntaxException) FileNotFoundException(java.io.FileNotFoundException) PasswordException(org.openmrs.api.PasswordException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) WeakPasswordException(org.openmrs.api.WeakPasswordException) APIException(org.openmrs.api.APIException) ShortPasswordException(org.openmrs.api.ShortPasswordException) MalformedURLException(java.net.MalformedURLException) HashSet(java.util.HashSet)

Example 9 with ConceptService

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());
}
Also used : Concept(org.openmrs.Concept) Errors(org.springframework.validation.Errors) TestOrder(org.openmrs.TestOrder) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) OrderService(org.openmrs.api.OrderService) ConceptService(org.openmrs.api.ConceptService) Date(java.util.Date) Provider(org.openmrs.Provider) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 10 with ConceptService

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());
}
Also used : Concept(org.openmrs.Concept) Errors(org.springframework.validation.Errors) TestOrder(org.openmrs.TestOrder) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) OrderService(org.openmrs.api.OrderService) ConceptService(org.openmrs.api.ConceptService) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

ConceptService (org.openmrs.api.ConceptService)21 Test (org.junit.Test)11 Concept (org.openmrs.Concept)11 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)11 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)7 ArrayList (java.util.ArrayList)4 ConceptName (org.openmrs.ConceptName)4 Encounter (org.openmrs.Encounter)4 Patient (org.openmrs.Patient)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 CareSetting (org.openmrs.CareSetting)3 ConceptDescription (org.openmrs.ConceptDescription)3 OrderFrequency (org.openmrs.OrderFrequency)3 FileNotFoundException (java.io.FileNotFoundException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 Date (java.util.Date)2 StringTokenizer (java.util.StringTokenizer)2