Search in sources :

Example 1 with ConceptSet

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

the class ConceptSetsEditor method setAsText.

/**
 * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
 */
@Override
public void setAsText(String text) throws IllegalArgumentException {
    log.debug("setting conceptSets with text: " + text);
    if (StringUtils.hasText(text)) {
        ConceptService cs = Context.getConceptService();
        String[] conceptIds = text.split(" ");
        List<Integer> requestConceptIds = new ArrayList<>();
        // and removal of duplicates
        for (String id : conceptIds) {
            id = id.trim();
            if (!("".equals(id)) && !requestConceptIds.contains(Integer.valueOf(id))) {
                // remove whitespace, blank lines, and duplicate entries
                requestConceptIds.add(Integer.valueOf(id));
            }
        }
        // used when adding in concept sets
        List<Integer> originalConceptSetIds = new ArrayList<>(originalConceptSets.size());
        // remove all sets that aren't in the request (aka, that have been deleted by the user)
        Collection<ConceptSet> copyOfOriginalConceptSets = new ArrayList<>(originalConceptSets);
        for (ConceptSet origConceptSet : copyOfOriginalConceptSets) {
            if (!requestConceptIds.contains(origConceptSet.getConcept().getConceptId())) {
                originalConceptSets.remove(origConceptSet);
            }
            // add to quick list used when adding later
            originalConceptSetIds.add(origConceptSet.getConcept().getConceptId());
        }
        // Also normalize all weight attributes
        for (int x = 0; x < requestConceptIds.size(); x++) {
            Integer requestConceptId = requestConceptIds.get(x);
            if (!originalConceptSetIds.contains(requestConceptId)) {
                // the null weight will be reset in the next step of normalization
                originalConceptSets.add(new ConceptSet(cs.getConcept(requestConceptId), (double) x));
            } else {
                // find this conceptId in the original set and set its weight
                for (ConceptSet conceptSet : originalConceptSets) {
                    if (conceptSet.getConcept().getConceptId().equals(requestConceptId)) {
                        conceptSet.setSortWeight((double) x);
                    }
                }
            }
        }
    } else {
        originalConceptSets.clear();
    }
    setValue(originalConceptSets);
}
Also used : ConceptSet(org.openmrs.ConceptSet) ArrayList(java.util.ArrayList) ConceptService(org.openmrs.api.ConceptService)

Example 2 with ConceptSet

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

the class ConceptServiceTest method getConceptSetByUuid_shouldFindObjectGivenValidUuid.

/**
 * @see ConceptService#getConceptSetByUuid(String)
 */
@Test
public void getConceptSetByUuid_shouldFindObjectGivenValidUuid() {
    String uuid = "1a111827-639f-4cb4-961f-1e025bf88d90";
    ConceptSet conceptSet = Context.getConceptService().getConceptSetByUuid(uuid);
    Assert.assertEquals(1, (int) conceptSet.getConceptSetId());
}
Also used : ConceptSet(org.openmrs.ConceptSet) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 3 with ConceptSet

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

the class ConceptServiceImpl method explodeConceptSetHelper.

/**
 * Utility method used by getConceptsInSet(Concept concept)
 *
 * @param concept
 * @param ret
 * @param alreadySeen
 */
private void explodeConceptSetHelper(Concept concept, Collection<Concept> ret, Collection<Integer> alreadySeen) {
    if (alreadySeen.contains(concept.getConceptId())) {
        return;
    }
    alreadySeen.add(concept.getConceptId());
    List<ConceptSet> cs = getConceptSetsByConcept(concept);
    for (ConceptSet set : cs) {
        Concept c = set.getConcept();
        if (c.getSet()) {
            ret.add(c);
            explodeConceptSetHelper(c, ret, alreadySeen);
        } else {
            ret.add(c);
        }
    }
}
Also used : Concept(org.openmrs.Concept) ConceptSet(org.openmrs.ConceptSet)

Example 4 with ConceptSet

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

the class ConceptServiceImplTest method getSetsContainingConcept_shouldGiveAnEmptyListIfNoMatchingConceptSetIsFound.

/**
 * @see ConceptServiceImpl#getSetsContainingConcept(Concept)
 */
@Test
public void getSetsContainingConcept_shouldGiveAnEmptyListIfNoMatchingConceptSetIsFound() {
    String uuid = "0cbe2ed3-cd5f-4f46-9459-26127c9265ab";
    Concept concept = conceptService.getConceptByUuid(uuid);
    List<ConceptSet> conceptSets = conceptService.getSetsContainingConcept(concept);
    assertEquals(conceptSets, Collections.emptyList());
}
Also used : Concept(org.openmrs.Concept) ConceptSet(org.openmrs.ConceptSet) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 5 with ConceptSet

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

the class ConceptServiceImplTest method getSetsContainingConcept_shouldGiveAnEmptyListIfConceptIdIsNull.

/**
 * @see ConceptServiceImpl#getSetsContainingConcept(Concept)
 */
@Test
public void getSetsContainingConcept_shouldGiveAnEmptyListIfConceptIdIsNull() {
    List<ConceptSet> conceptSets = conceptService.getSetsContainingConcept(new Concept());
    assertEquals(conceptSets, Collections.emptyList());
}
Also used : Concept(org.openmrs.Concept) ConceptSet(org.openmrs.ConceptSet) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

ConceptSet (org.openmrs.ConceptSet)6 Test (org.junit.Test)4 Concept (org.openmrs.Concept)4 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)4 ArrayList (java.util.ArrayList)1 ConceptService (org.openmrs.api.ConceptService)1