Search in sources :

Example 96 with ConceptName

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

the class ConceptDAOTest method getConcepts_shouldReturnCorrectResultsIfAConceptNameContainsSameWordMoreThanOnce.

/**
 * @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_shouldReturnCorrectResultsIfAConceptNameContainsSameWordMoreThanOnce() {
    ConceptService cs = Context.getConceptService();
    ConceptClass cc = cs.getConceptClass(1);
    Locale locale = Locale.ENGLISH;
    ConceptDatatype dt = cs.getConceptDatatype(4);
    Concept c1 = new Concept();
    ConceptName cn1a = new ConceptName("ONE TERM", locale);
    c1.addName(cn1a);
    c1.setConceptClass(cc);
    c1.setDatatype(dt);
    cs.saveConcept(c1);
    ConceptName cn1b = new ConceptName("ONE TO ONE", locale);
    cn1b.setConceptNameType(ConceptNameType.FULLY_SPECIFIED);
    cn1b.setLocalePreferred(true);
    c1.addName(cn1b);
    cs.saveConcept(c1);
    Assert.assertTrue(cn1a.isSynonym());
    Assert.assertTrue(cn1b.getConceptNameId() > cn1a.getConceptNameId());
    Concept c2 = new Concept();
    ConceptName cn2a = new ConceptName("ONE TO MANY", locale);
    c2.addName(cn2a);
    c2.setConceptClass(cc);
    c2.setDatatype(dt);
    cs.saveConcept(c2);
    updateSearchIndex();
    List<ConceptSearchResult> searchResults1 = dao.getConcepts("one", Collections.singletonList(locale), false, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, null, null, null);
    Assert.assertEquals(2, searchResults1.size());
    Assert.assertEquals(c1, searchResults1.get(0).getConcept());
    Assert.assertEquals(cn1b, searchResults1.get(0).getConceptName());
}
Also used : Locale(java.util.Locale) Concept(org.openmrs.Concept) ConceptClass(org.openmrs.ConceptClass) ConceptName(org.openmrs.ConceptName) ConceptSearchResult(org.openmrs.ConceptSearchResult) ConceptService(org.openmrs.api.ConceptService) ConceptDatatype(org.openmrs.ConceptDatatype) Ignore(org.junit.Ignore) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 97 with ConceptName

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

the class HibernateDiagnosisDAOTest method shouldSaveDiagnosis.

@Test
public void shouldSaveDiagnosis() {
    CodedOrFreeText codedOrFreeText = new CodedOrFreeText(new Concept(4), new ConceptName(5089), "non coded");
    int diagnosisId = 5;
    Diagnosis diagnosis = new Diagnosis();
    diagnosis.setEncounter(new Encounter(3));
    diagnosis.setRank(2);
    diagnosis.setId(diagnosisId);
    diagnosis.setCertainty(ConditionVerificationStatus.CONFIRMED);
    diagnosis.setPatient(new Patient(2));
    diagnosis.setCondition(new Condition());
    diagnosis.setDiagnosis(codedOrFreeText);
    diagnosis.setUuid("4e663d96-6b78-11e0-93c3-18a9b5e044dc");
    diagnosis.setCreator(new User(1));
    diagnosis.setVoided(false);
    diagnosis.setDateCreated(new Date());
    diagnosisDAO.saveDiagnosis(diagnosis);
    Diagnosis savedDiagnosis = diagnosisDAO.getDiagnosisById(diagnosisId);
    assertEquals(diagnosis.getUuid(), savedDiagnosis.getUuid());
    assertEquals(diagnosis.getVoided(), savedDiagnosis.getVoided());
    assertEquals(diagnosis.getRank(), savedDiagnosis.getRank());
    assertEquals(diagnosis.getCertainty(), savedDiagnosis.getCertainty());
    assertEquals(diagnosis.getCreator(), savedDiagnosis.getCreator());
    assertEquals(diagnosis.getCondition(), savedDiagnosis.getCondition());
    assertEquals(diagnosis.getPatient(), savedDiagnosis.getPatient());
    assertEquals(diagnosis.getEncounter(), savedDiagnosis.getEncounter());
}
Also used : Concept(org.openmrs.Concept) Condition(org.openmrs.Condition) User(org.openmrs.User) ConceptName(org.openmrs.ConceptName) Encounter(org.openmrs.Encounter) Patient(org.openmrs.Patient) Diagnosis(org.openmrs.Diagnosis) CodedOrFreeText(org.openmrs.CodedOrFreeText) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 98 with ConceptName

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

the class ConceptsFromMetadataSharing method baseConcept.

private Concept baseConcept(String name) {
    Concept concept = new Concept();
    concept.addName(new ConceptName(name, Locale.ENGLISH));
    concept.addConceptMapping(new ConceptMapBuilder(uuid()).type(sameAs).ensureTerm(pih, name).build());
    return concept;
}
Also used : Concept(org.openmrs.Concept) ConceptMapBuilder(org.openmrs.module.metadatadeploy.builder.ConceptMapBuilder) ConceptName(org.openmrs.ConceptName)

Example 99 with ConceptName

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

the class MockConcepts method baseConcept.

private Concept baseConcept(String name) {
    Concept concept = new Concept();
    concept.addName(new ConceptName(name, Locale.ENGLISH));
    concept.addConceptMapping(new ConceptMapBuilder(uuid()).type(sameAs).ensureTerm(pih, name).build());
    return concept;
}
Also used : Concept(org.openmrs.Concept) ConceptMapBuilder(org.openmrs.module.metadatadeploy.builder.ConceptMapBuilder) ConceptName(org.openmrs.ConceptName)

Example 100 with ConceptName

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

the class CauseOfDeathListTagHandlerComponentTest method testCreateAndEdit.

@Test
public void testCreateAndEdit() throws Exception {
    final ConceptName causeOne = conceptService.getConceptNameByUuid("2f7263e4-2a57-49b5-aef0-af9a259aac65");
    final Concept causeTwo = conceptService.getConcept(13);
    final Concept editedCauseTwo = conceptService.getConcept(11);
    final String causeThree = "Cause Three";
    final String editedCauseThree = "Edited Cause Three";
    final Concept causeFour = conceptService.getConcept(16);
    ArrayNode submission = jackson.createArrayNode();
    ObjectNode one = submission.addObject();
    one.put("ConceptName", causeOne.getUuid());
    ObjectNode two = submission.addObject();
    two.put("Concept", causeTwo.getUuid());
    ObjectNode three = submission.addObject();
    three.put("NonCodedValue", causeThree);
    ObjectNode four = submission.addObject();
    four.put("Concept", causeFour.getUuid());
    final String createJson = jackson.writeValueAsString(submission);
    two.put("Concept", editedCauseTwo.getUuid());
    three.put("NonCodedValue", editedCauseThree);
    // this removes 'four'
    submission.remove(3);
    final String editJson = jackson.writeValueAsString(submission);
    final Date date = new Date();
    new RegressionTestHelper() {

        @Override
        public String getXmlDatasetPath() {
            return "";
        }

        @Override
        public String getFormName() {
            return "causesOfDeathForm";
        }

        @Override
        public String[] widgetLabels() {
            return new String[] { "Date:", "Location:", "Provider:", "Causes:" };
        }

        @Override
        public void setupRequest(MockHttpServletRequest request, Map<String, String> widgets) {
            request.setParameter(widgets.get("Date:"), dateAsString(date));
            request.setParameter(widgets.get("Location:"), "2");
            request.setParameter(widgets.get("Provider:"), "1");
            request.setParameter(widgets.get("Causes:"), createJson);
        }

        @Override
        public void testResults(SubmissionResults results) {
            results.assertNoErrors();
            results.assertEncounterCreated();
            results.assertProvider(1);
            results.assertLocation(2);
            results.assertObsGroupCreatedCount(4);
            results.assertObsGroupCreated(groupingConcept.getConceptId(), codedCauseConcept.getId(), causeOne, sequenceConcept.getId(), 1);
            results.assertObsGroupCreated(groupingConcept.getConceptId(), codedCauseConcept.getId(), causeTwo, sequenceConcept.getId(), 2);
            results.assertObsGroupCreated(groupingConcept.getConceptId(), nonCodedCauseConcept.getId(), causeThree, sequenceConcept.getId(), 3);
            results.assertObsGroupCreated(groupingConcept.getConceptId(), codedCauseConcept.getId(), causeFour, sequenceConcept.getId(), 4);
            assertThat(results.getPatient().getCauseOfDeath(), is(causeFour));
        }

        @Override
        public boolean doEditEncounter() {
            return true;
        }

        @Override
        public String[] widgetLabelsForEdit() {
            return widgetLabels();
        }

        @Override
        public void setupEditRequest(MockHttpServletRequest request, Map<String, String> widgets) {
            request.setParameter(widgets.get("Date:"), dateAsString(date));
            request.setParameter(widgets.get("Location:"), "2");
            request.setParameter(widgets.get("Provider:"), "1");
            request.setParameter(widgets.get("Causes:"), editJson);
        }

        @Override
        public void testEditedResults(SubmissionResults results) {
            results.assertNoErrors();
            results.assertEncounterCreated();
            results.assertProvider(1);
            results.assertLocation(2);
            // there should be one voided member obs (causeTwo->causeTwoEdited), and one voided obs group (causeThree)
            // was causeThree
            results.assertObsVoided(groupingConcept.getConceptId(), null);
            assertVoidedObsInObsGroup(results.getEncounterCreated(), groupingConcept, codedCauseConcept, causeTwo);
            results.assertObsGroupCreatedCount(3);
            results.assertObsGroupCreated(groupingConcept.getConceptId(), codedCauseConcept.getId(), causeOne, sequenceConcept.getId(), 1);
            results.assertObsGroupCreated(groupingConcept.getConceptId(), codedCauseConcept.getId(), editedCauseTwo, sequenceConcept.getId(), 2);
            results.assertObsGroupCreated(groupingConcept.getConceptId(), nonCodedCauseConcept.getId(), editedCauseThree, sequenceConcept.getId(), 3);
            assertThat(results.getPatient().getCauseOfDeath(), is(unknownConcept));
        }

        private void assertVoidedObsInObsGroup(Encounter encounter, Concept groupingConcept, Concept concept, Concept value) {
            for (Obs candidate : encounter.getObsAtTopLevel(true)) {
                if (groupingConcept.equals(candidate.getConcept())) {
                    for (Obs member : candidate.getGroupMembers(true)) {
                        if (member.getVoided() && member.getConcept().equals(concept) && member.getValueCoded().equals(value)) {
                            return;
                        }
                    }
                }
            }
            Assert.fail("Did not find a voided obs of " + concept + "=" + value + " inside a group of " + groupingConcept);
        }
    }.run();
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) ObjectNode(org.codehaus.jackson.node.ObjectNode) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Date(java.util.Date) ConceptName(org.openmrs.ConceptName) Encounter(org.openmrs.Encounter) ArrayNode(org.codehaus.jackson.node.ArrayNode) RegressionTestHelper(org.openmrs.module.htmlformentry.RegressionTestHelper) PihCoreContextSensitiveTest(org.openmrs.module.pihcore.PihCoreContextSensitiveTest) 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