Search in sources :

Example 46 with ConceptName

use of org.openmrs.ConceptName in project openmrs-module-coreapps by openmrs.

the class CodedOrFreeTextAnswerListWidgetTest method testViewNonEmptyList.

@Test
public void testViewNonEmptyList() throws Exception {
    setUpView();
    ConceptName conceptName = new ConceptName();
    conceptName.setLocale(Context.getLocale());
    conceptName.setConceptNameType(ConceptNameType.FULLY_SPECIFIED);
    conceptName.setLocalePreferred(true);
    conceptName.setName("Coded");
    Concept concept = new Concept();
    concept.addName(conceptName);
    List<CodedOrFreeTextAnswer> list = new ArrayList<CodedOrFreeTextAnswer>();
    list.add(new CodedOrFreeTextAnswer("Free text"));
    list.add(new CodedOrFreeTextAnswer(concept));
    widget.setInitialValue(list);
    String html = widget.generateHtml(context);
    assertThat(html, matches("<div class=\"coded-or-free-text-list-widget\">\\s*" + "<span class=\"coded-or-free-text-title\">\\s*" + "Title\\s*" + "</span>\\s*" + "<br/>\\s*" + "<span class=\"value\">\\s*" + "\"Free text\"\\s*" + "</span>\\s*" + "<br/>\\s*" + "<span class=\"coded-or-free-text-between\">\\s*" + "\\(between\\)\\s*" + "</span>\\s*" + "<br/>\\s*" + "<span class=\"value\">\\s*" + "Coded\\s*" + "</span>\\s*" + "</div>"));
}
Also used : Concept(org.openmrs.Concept) ArrayList(java.util.ArrayList) ConceptName(org.openmrs.ConceptName) CodedOrFreeTextAnswer(org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer) Test(org.junit.Test)

Example 47 with ConceptName

use of org.openmrs.ConceptName in project openmrs-module-pihcore by PIH.

the class DrugListSetupTest method shouldInstallNewDrugList.

@Test
public void shouldInstallNewDrugList() throws Exception {
    ConceptService cs = Context.getConceptService();
    List<Drug> initialInstalledDrugs = Context.getConceptService().getAllDrugs();
    Concept testDrugConcept = new Concept();
    testDrugConcept.addName(new ConceptName("test drug concept", Locale.ENGLISH));
    // N/A
    testDrugConcept.setDatatype(cs.getConceptDatatype(4));
    // Drug
    testDrugConcept.setConceptClass(cs.getConceptClass(3));
    cs.saveConcept(testDrugConcept);
    ConceptReferenceTerm crt = new ConceptReferenceTerm();
    // SNOMED CT
    ConceptSource source = cs.getConceptSource(2);
    crt.setConceptSource(source);
    crt.setCode("9876");
    cs.saveConceptReferenceTerm(crt);
    ConceptMap map = new ConceptMap();
    map.setConcept(testDrugConcept);
    map.setConceptReferenceTerm(crt);
    testDrugConcept.addConceptMapping(map);
    cs.saveConcept(testDrugConcept);
    // prevents "Unexpected call to partialFlushEnd; expecting partialFlushStart"
    Context.flushSession();
    DrugListSetup.installDrugList();
    List<Drug> installedDrugs = Context.getConceptService().getAllDrugs();
    List<String> installedDrugNames = new ArrayList<String>();
    for (Drug drug : installedDrugs) {
        installedDrugNames.add(drug.getName());
    }
    assertThat("Test Drug", is(in(installedDrugNames)));
    assertThat(installedDrugs.size(), is(initialInstalledDrugs.size() + 1));
}
Also used : Drug(org.openmrs.Drug) Concept(org.openmrs.Concept) ArrayList(java.util.ArrayList) ConceptName(org.openmrs.ConceptName) ConceptSource(org.openmrs.ConceptSource) ConceptMap(org.openmrs.ConceptMap) ConceptService(org.openmrs.api.ConceptService) ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) Test(org.junit.Test) PihCoreContextSensitiveTest(org.openmrs.module.pihcore.PihCoreContextSensitiveTest)

Example 48 with ConceptName

use of org.openmrs.ConceptName in project openmrs-module-pihcore by PIH.

the class ConceptDictionaryExportTest method exportData.

/**
 * Intentional issues currently with this, in order to isolate away known issues.  These should be removed as appropriate:
 * - Normalizes concept source name, due to known issue needed in OCL to facilitate source matching
 * - Excludes voided concept names (which are really retired names that may have references), as these are not provided by ocl
 * - Converts answer sort weight from null -> 1.0 if only one answer exists for the concept
 */
@Test
public void exportData() throws Exception {
    // Only run this test if it is being run alone.  This ensures this test will not run in normal build.
    if (props == null) {
        return;
    }
    if (!Context.isSessionOpen()) {
        Context.openSession();
    }
    authenticate();
    List<Map<String, Object>> concepts = new ArrayList<>();
    System.out.println("Pulling concepts");
    int i = 0;
    List<Concept> conceptList = Context.getConceptService().getAllConcepts();
    conceptList.sort(Comparator.comparing(t -> t.getUuid().toUpperCase()));
    List<Concept> conceptsToIgnore = getConceptsToIgnore();
    conceptList.removeAll(conceptsToIgnore);
    for (Concept concept : conceptList) {
        System.out.println(i++ + ": Pulling concept: " + concept.getUuid());
        Map<String, Object> c = new LinkedHashMap<>();
        concepts.add(c);
        c.put("uuid", concept.getUuid());
        c.put("concept_class", concept.getConceptClass().getName());
        c.put("concept_datatype", concept.getDatatype().getName());
        c.put("is_set", BooleanUtils.isTrue(concept.getSet()) ? "true" : "false");
        c.put("version", concept.getVersion() == null ? "" : concept.getVersion());
        c.put("retired", BooleanUtils.isTrue(concept.getRetired()) ? "true" : "false");
        c.put("retireReason", concept.getRetireReason() == null ? "" : concept.getRetireReason());
        if (concept instanceof ConceptNumeric) {
            ConceptNumeric cn = (ConceptNumeric) concept;
            c.put("hi_absolute", cn.getHiAbsolute() == null ? "" : cn.getHiAbsolute().toString());
            c.put("hi_critical", cn.getLowAbsolute() == null ? "" : cn.getLowAbsolute().toString());
            c.put("hi_normal", cn.getHiNormal() == null ? "" : cn.getHiNormal().toString());
            c.put("low_absolute", cn.getLowAbsolute() == null ? "" : cn.getLowAbsolute().toString());
            c.put("low_critical", cn.getLowCritical() == null ? "" : cn.getLowCritical().toString());
            c.put("low_normal", cn.getLowNormal() == null ? "" : cn.getLowNormal().toString());
            c.put("units", cn.getUnits() == null ? "" : cn.getUnits());
            c.put("allow_decimal", BooleanUtils.isTrue(cn.getAllowDecimal()) ? "true" : "false");
            c.put("display_precision", cn.getHiAbsolute() == null ? "" : cn.getHiAbsolute().toString());
        }
        if (concept instanceof ConceptComplex) {
            ConceptComplex cc = (ConceptComplex) concept;
            c.put("handler", cc.getHandler());
        }
        List<ConceptName> names = new ArrayList<>(concept.getNames(true));
        names.sort(Comparator.comparing(ConceptName::getName).thenComparing(cn -> cn.getConceptNameType() == null ? "" : cn.getConceptNameType().name()).thenComparing(cn -> cn.getLocale().toString()).thenComparing(ConceptName::getLocalePreferred));
        List<Map<String, Object>> nameList = new ArrayList<>();
        for (ConceptName name : names) {
            if (BooleanUtils.isNotTrue(name.getVoided())) {
                Map<String, Object> n = new LinkedHashMap<>();
                n.put("name", name.getName());
                n.put("locale", name.getLocale().toString());
                n.put("locale_preferred", BooleanUtils.isTrue(name.getLocalePreferred()) ? "true" : "false");
                n.put("type", name.getConceptNameType() == null ? "" : name.getConceptNameType().name());
                n.put("voided", BooleanUtils.isTrue(name.getVoided()) ? "true" : "false");
                nameList.add(n);
            }
        }
        c.put("names", nameList);
        List<ConceptDescription> descriptions = new ArrayList<>(concept.getDescriptions());
        descriptions.sort(Comparator.comparing(ConceptDescription::getDescription));
        List<Map<String, Object>> descriptionList = new ArrayList<>();
        for (ConceptDescription description : descriptions) {
            Map<String, Object> n = new LinkedHashMap<>();
            n.put("description", description.getDescription());
            n.put("locale", description.getLocale().toString());
            descriptionList.add(n);
        }
        c.put("descriptions", descriptionList);
        List<ConceptAnswer> answers = new ArrayList<>(concept.getAnswers(true));
        answers.sort(Comparator.comparingDouble(ConceptAnswer::getSortWeight).thenComparing(ca -> ca.getAnswerConcept().getUuid()));
        List<Map<String, Object>> answerList = new ArrayList<>();
        for (ConceptAnswer ca : answers) {
            if (!conceptsToIgnore.contains(ca.getAnswerConcept())) {
                Map<String, Object> n = new LinkedHashMap<>();
                n.put("answerConcept", ca.getAnswerConcept().getUuid());
                n.put("sortWeight", ca.getSortWeight() == null ? (answers.size() == 1 ? "1.0" : "") : ca.getSortWeight().toString());
                answerList.add(n);
            }
        }
        c.put("answers", answerList);
        List<ConceptSet> setMembers = new ArrayList<>(concept.getConceptSets());
        setMembers.sort(Comparator.comparingDouble(ConceptSet::getSortWeight).thenComparing(cs -> cs.getConcept().getUuid()));
        List<Map<String, Object>> setMemberList = new ArrayList<>();
        for (ConceptSet cs : setMembers) {
            if (!conceptsToIgnore.contains(cs.getConcept())) {
                Map<String, Object> n = new LinkedHashMap<>();
                n.put("concept", cs.getConcept().getUuid());
                n.put("sortWeight", cs.getSortWeight() == null ? "" : cs.getSortWeight().toString());
                setMemberList.add(n);
            }
        }
        c.put("setMembers", setMemberList);
        List<ConceptMap> mappings = new ArrayList<>(concept.getConceptMappings());
        mappings.sort(Comparator.comparing((ConceptMap m) -> m.getConceptReferenceTerm().getConceptSource().getName()).thenComparing(m -> m.getConceptMapType().getName()).thenComparing(m -> m.getConceptReferenceTerm().getCode()));
        List<Map<String, Object>> mappingList = new ArrayList<>();
        for (ConceptMap cm : mappings) {
            Map<String, Object> n = new LinkedHashMap<>();
            n.put("source", normalizeSourceName(cm.getConceptReferenceTerm().getConceptSource().getName()));
            n.put("type", cm.getConceptMapType().getName());
            n.put("code", cm.getConceptReferenceTerm().getCode());
            mappingList.add(n);
        }
        c.put("mappings", mappingList);
    }
    File exportFile = new File(EXPORT_DIR, EXPORT_FILENAME);
    System.out.println("Writing concepts to: " + exportFile);
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.writerWithDefaultPrettyPrinter().writeValue(exportFile, concepts);
    System.out.println("Concepts exported successfully");
}
Also used : DbSessionFactory(org.openmrs.api.db.hibernate.DbSessionFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ConceptAnswer(org.openmrs.ConceptAnswer) ArrayList(java.util.ArrayList) BooleanUtils(org.apache.commons.lang.BooleanUtils) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ConceptMap(org.openmrs.ConceptMap) SkipBaseSetup(org.openmrs.test.SkipBaseSetup) ConceptSet(org.openmrs.ConceptSet) Properties(java.util.Properties) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test) ConceptName(org.openmrs.ConceptName) FileInputStream(java.io.FileInputStream) File(java.io.File) List(java.util.List) Concept(org.openmrs.Concept) Ignore(org.junit.Ignore) ConceptComplex(org.openmrs.ConceptComplex) ConceptDescription(org.openmrs.ConceptDescription) ConceptNumeric(org.openmrs.ConceptNumeric) Comparator(java.util.Comparator) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Context(org.openmrs.api.context.Context) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ConceptSet(org.openmrs.ConceptSet) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptMap(org.openmrs.ConceptMap) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Concept(org.openmrs.Concept) ConceptAnswer(org.openmrs.ConceptAnswer) ConceptNumeric(org.openmrs.ConceptNumeric) ConceptComplex(org.openmrs.ConceptComplex) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ConceptMap(org.openmrs.ConceptMap) File(java.io.File) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 49 with ConceptName

use of org.openmrs.ConceptName in project openmrs-module-coreapps by openmrs.

the class DiagnosesFragmentController method simplify.

/**
 * This is public so that it can be used by a fragment that needs to prepopulate a diagnoses widget that is normally
 * populated with AJAX results from the #search method.
 * @param result
 * @param ui
 * @param locale
 * @return
 * @throws Exception
 */
public SimpleObject simplify(ConceptSearchResult result, UiUtils ui, Locale locale) throws Exception {
    SimpleObject simple = SimpleObject.fromObject(result, ui, "word", "conceptName.id", "conceptName.uuid", "conceptName.conceptNameType", "conceptName.name", "concept.id", "concept.uuid", "concept.conceptMappings.conceptMapType", "concept.conceptMappings.conceptReferenceTerm.code", "concept.conceptMappings.conceptReferenceTerm.name", "concept.conceptMappings.conceptReferenceTerm.conceptSource.name");
    Concept concept = result.getConcept();
    ConceptName conceptName = result.getConceptName();
    ConceptName preferredName = getPreferredName(locale, concept);
    PropertyUtils.setProperty(simple, "concept.preferredName", preferredName.getName());
    return simple;
}
Also used : Concept(org.openmrs.Concept) SimpleObject(org.openmrs.ui.framework.SimpleObject) ConceptName(org.openmrs.ConceptName)

Example 50 with ConceptName

use of org.openmrs.ConceptName in project openmrs-module-coreapps by openmrs.

the class EncounterDiagnosesFragmentControllerTest method testController_createdProperExistingDiagnoses.

@Test
public void testController_createdProperExistingDiagnoses() throws Exception {
    EncounterDiagnosesFragmentController controller = new EncounterDiagnosesFragmentController();
    ConceptName specificName = new ConceptName("Specific Name", Context.getLocale());
    specificName.setId(1);
    specificName.setLocalePreferred(true);
    Concept conceptForSpecificName = new Concept();
    conceptForSpecificName.setId(2);
    conceptForSpecificName.addName(specificName);
    Concept nonSpecificConcept = new Concept();
    nonSpecificConcept.setId(3);
    ConceptName nonSpecificConceptName = new ConceptName("Non-specific concept", Context.getLocale());
    nonSpecificConceptName.setId(4);
    nonSpecificConceptName.setLocalePreferred(true);
    nonSpecificConcept.addName(nonSpecificConceptName);
    List<Diagnosis> diagnoses = new ArrayList<Diagnosis>();
    diagnoses.add(new Diagnosis(new CodedOrFreeTextAnswer(specificName), Diagnosis.Order.PRIMARY));
    diagnoses.add(new Diagnosis(new CodedOrFreeTextAnswer(nonSpecificConcept), Diagnosis.Order.SECONDARY));
    diagnoses.add(new Diagnosis(new CodedOrFreeTextAnswer("Unknown Disease"), Diagnosis.Order.SECONDARY));
    for (Diagnosis d : diagnoses) {
        d.setExistingObs(new Obs());
    }
    FragmentModel model = new FragmentModel();
    controller.controller(new TestUiUtils(), diagnoses, null, model);
    assertThat(((List<String>) model.getAttribute("jsForPrior")).size(), is(0));
    List<String> jsForExisting = (List<String>) model.getAttribute("jsForExisting");
    assertThat(jsForExisting.get(0), is("{ diagnosis: diagnoses.CodedOrFreeTextConceptAnswer({\"word\":null,\"conceptName\":{\"id\":1,\"uuid\":\"" + specificName.getUuid() + "\",\"conceptNameType\":\"FULLY_SPECIFIED\",\"name\":\"Specific Name\"},\"concept\":{\"id\":2,\"uuid\":\"" + conceptForSpecificName.getUuid() + "\",\"conceptMappings\":[],\"preferredName\":\"Specific Name\"}}), confirmed: false, primary: true, existingObs: null }"));
    assertThat(jsForExisting.get(1), is("{ diagnosis: diagnoses.CodedOrFreeTextConceptAnswer({\"word\":null,\"conceptName\":null,\"concept\":{\"id\":3,\"uuid\":\"" + nonSpecificConcept.getUuid() + "\",\"conceptMappings\":[],\"preferredName\":\"Non-specific concept\"}}), confirmed: false, primary: false, existingObs: null }"));
    assertThat(jsForExisting.get(2), is("{ diagnosis: diagnoses.CodedOrFreeTextConceptAnswer('Unknown Disease'), confirmed: false, primary: false, existingObs: null }"));
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) TestUiUtils(org.openmrs.module.appui.TestUiUtils) ArrayList(java.util.ArrayList) CodedOrFreeTextAnswer(org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer) FragmentModel(org.openmrs.ui.framework.fragment.FragmentModel) ConceptName(org.openmrs.ConceptName) ArrayList(java.util.ArrayList) List(java.util.List) Diagnosis(org.openmrs.module.emrapi.diagnosis.Diagnosis) Test(org.junit.Test)

Aggregations

ConceptName (org.openmrs.ConceptName)100 Test (org.junit.Test)78 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)71 Concept (org.openmrs.Concept)62 ConceptDescription (org.openmrs.ConceptDescription)42 ConceptDatatype (org.openmrs.ConceptDatatype)34 ConceptClass (org.openmrs.ConceptClass)33 Locale (java.util.Locale)32 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)22 ArrayList (java.util.ArrayList)11 Date (java.util.Date)9 Obs (org.openmrs.Obs)9 BindException (org.springframework.validation.BindException)8 ConceptMap (org.openmrs.ConceptMap)7 Errors (org.springframework.validation.Errors)7 LinkedList (java.util.LinkedList)6 List (java.util.List)6 Patient (org.openmrs.Patient)6 Encounter (org.openmrs.Encounter)5 OrderFrequency (org.openmrs.OrderFrequency)5