Search in sources :

Example 41 with ConceptDescription

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

the class ConceptServiceTest method mapConceptProposalToConcept_shouldSetValueCodedNameWhenAddSynonymIsSelected.

/**
 * @see ConceptService#mapConceptProposalToConcept(ConceptProposal,Concept,Locale)
 */
@Test
public void mapConceptProposalToConcept_shouldSetValueCodedNameWhenAddSynonymIsSelected() {
    ConceptProposal cp = conceptService.getConceptProposal(2);
    Assert.assertEquals(OpenmrsConstants.CONCEPT_PROPOSAL_UNMAPPED, cp.getState());
    final Concept civilStatusConcept = conceptService.getConcept(4);
    final int mappedConceptId = 6;
    final String finalText = "Weight synonym";
    Assert.assertTrue(Context.getObsService().getObservationsByPersonAndConcept(cp.getEncounter().getPatient(), civilStatusConcept).isEmpty());
    Concept mappedConcept = conceptService.getConcept(mappedConceptId);
    mappedConcept.addDescription(new ConceptDescription("some description", Context.getLocale()));
    cp.setFinalText(finalText);
    cp.setObsConcept(civilStatusConcept);
    cp.setState(OpenmrsConstants.CONCEPT_PROPOSAL_SYNONYM);
    conceptService.mapConceptProposalToConcept(cp, mappedConcept, null);
    mappedConcept = conceptService.getConcept(mappedConceptId);
    List<Obs> observations = Context.getObsService().getObservationsByPersonAndConcept(cp.getEncounter().getPatient(), civilStatusConcept);
    Assert.assertEquals(1, observations.size());
    Obs obs = observations.get(0);
    Assert.assertNotNull(obs.getValueCodedName());
    Assert.assertEquals(finalText, obs.getValueCodedName().getName());
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) ConceptProposal(org.openmrs.ConceptProposal) ConceptDescription(org.openmrs.ConceptDescription) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 42 with ConceptDescription

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

the class ConceptServiceTest method saveConcept_shouldSetAuditInfoIfAnyItemInTheChildCollectionsIsEdited.

/**
 * @see ConceptService#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldSetAuditInfoIfAnyItemInTheChildCollectionsIsEdited() {
    Concept concept = conceptService.getConcept(3);
    Assert.assertNull(concept.getDateChanged());
    Assert.assertNull(concept.getChangedBy());
    ConceptDescription description = concept.getDescription();
    Assert.assertNotNull(description);
    description.setDescription("changed to something else");
    conceptService.saveConcept(concept);
    Assert.assertNotNull(concept.getDateChanged());
    Assert.assertNotNull(concept.getChangedBy());
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) ConceptDescription(org.openmrs.ConceptDescription) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 43 with ConceptDescription

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

the class ConceptServiceTest method saveConcept_shouldKeepIdForNewConceptIfOneIsSpecified.

/**
 * @see ConceptService#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldKeepIdForNewConceptIfOneIsSpecified() {
    // a nonexistent concept id;
    Integer conceptId = 343434;
    // sanity check
    Assert.assertNull(conceptService.getConcept(conceptId));
    Concept concept = new Concept();
    ConceptName cn = new ConceptName("Weight", Context.getLocale());
    concept.addName(cn);
    concept.addDescription(new ConceptDescription("some description", null));
    concept.setConceptId(conceptId);
    concept.setDatatype(Context.getConceptService().getConceptDatatypeByName("Numeric"));
    concept.setConceptClass(Context.getConceptService().getConceptClassByName("Finding"));
    concept = Context.getConceptService().saveConcept(concept);
    assertTrue(concept.getConceptId().equals(conceptId));
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 44 with ConceptDescription

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

the class ConceptServiceTest method saveConcept_shouldSaveNonConceptComplexObjectAsConceptComplex.

/**
 * @see ConceptService#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldSaveNonConceptComplexObjectAsConceptComplex() {
    executeDataSet(INITIAL_CONCEPTS_XML);
    // this tests saving a current concept as a newly changed conceptComplex
    // assumes there is already a concept in the database
    // with a concept id of #1
    ConceptComplex cn = new ConceptComplex(1);
    cn.setDatatype(new ConceptDatatype(13));
    cn.setConceptClass(new ConceptClass(1));
    cn.addName(new ConceptName("a new conceptComplex", Locale.US));
    cn.addDescription(new ConceptDescription("some description", null));
    cn.setHandler("SomeHandler");
    conceptService.saveConcept(cn);
    Concept firstConcept = conceptService.getConceptComplex(1);
    assertEquals("a new conceptComplex", firstConcept.getName(Locale.US).getName());
    assertTrue(firstConcept instanceof ConceptComplex);
    ConceptComplex firstConceptComplex = (ConceptComplex) firstConcept;
    assertEquals("SomeHandler", firstConceptComplex.getHandler());
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) ConceptClass(org.openmrs.ConceptClass) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptComplex(org.openmrs.ConceptComplex) ConceptDatatype(org.openmrs.ConceptDatatype) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 45 with ConceptDescription

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

the class ConceptServiceTest method saveConcept_shouldSetAPreferredNameForEachLocaleIfNoneIsMarked.

/**
 * @see ConceptService#saveConcept(Concept)
 */
@Test
public void saveConcept_shouldSetAPreferredNameForEachLocaleIfNoneIsMarked() {
    // add some other locales to locale.allowed.list for testing purposes
    GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST);
    gp.setPropertyValue(gp.getPropertyValue().concat(",fr,ja,en_GB"));
    Context.getAdministrationService().saveGlobalProperty(gp);
    Concept concept = new Concept();
    concept.addName(new ConceptName("name1", Locale.ENGLISH));
    concept.addName(new ConceptName("name2", Locale.ENGLISH));
    concept.addName(new ConceptName("name3", Locale.FRENCH));
    concept.addName(new ConceptName("name4", Locale.FRENCH));
    concept.addName(new ConceptName("name5", Locale.JAPANESE));
    concept.addName(new ConceptName("name6", Locale.JAPANESE));
    concept.addDescription(new ConceptDescription("some description", null));
    concept.setDatatype(new ConceptDatatype(1));
    concept.setConceptClass(new ConceptClass(1));
    concept = Context.getConceptService().saveConcept(concept);
    Assert.assertNotNull(concept.getPreferredName(Locale.ENGLISH));
    Assert.assertNotNull(concept.getPreferredName(Locale.FRENCH));
    Assert.assertNotNull(concept.getPreferredName(Locale.JAPANESE));
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) ConceptClass(org.openmrs.ConceptClass) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptDatatype(org.openmrs.ConceptDatatype) GlobalProperty(org.openmrs.GlobalProperty) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)48 ConceptDescription (org.openmrs.ConceptDescription)48 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)47 ConceptName (org.openmrs.ConceptName)42 Concept (org.openmrs.Concept)33 ConceptDatatype (org.openmrs.ConceptDatatype)32 ConceptClass (org.openmrs.ConceptClass)31 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)20 Locale (java.util.Locale)14 OrderFrequency (org.openmrs.OrderFrequency)5 ConceptMap (org.openmrs.ConceptMap)4 ConceptNumeric (org.openmrs.ConceptNumeric)4 ConceptComplex (org.openmrs.ConceptComplex)3 ConceptService (org.openmrs.api.ConceptService)3 BindException (org.springframework.validation.BindException)3 Errors (org.springframework.validation.Errors)3 ConceptProposal (org.openmrs.ConceptProposal)2 OrderUtilTest (org.openmrs.order.OrderUtilTest)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1