Search in sources :

Example 86 with Concept

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

the class EncounterServiceTest method saveEncounter_shouldCascadeSaveToContainedObs.

/**
 * You should be able to add an obs to an encounter, save the encounter, and have the obs
 * automatically persisted. Added to test bug reported in ticket #827
 *
 * @see EncounterService#saveEncounter(Encounter)
 */
@Test
public void saveEncounter_shouldCascadeSaveToContainedObs() {
    EncounterService es = Context.getEncounterService();
    // First, create a new Encounter
    Encounter enc = buildEncounter();
    // add an obs to the encounter
    Obs groupObs = new Obs();
    Concept c = Context.getConceptService().getConcept(1);
    groupObs.setConcept(c);
    // add an obs to the group
    Obs childObs = new Obs();
    childObs.setConcept(c);
    childObs.setValueNumeric(50d);
    groupObs.addGroupMember(childObs);
    enc.addObs(groupObs);
    // confirm that save and new enc id are cascaded to obs groupMembers
    // even though childObs aren't directly associated to enc
    assertNotNull("save succeeds without error", es.saveEncounter(enc));
    assertTrue("enc save succeeds", enc.getId() > 0);
    assertNotNull("obs save succeeds", groupObs.getObsId());
    assertEquals("encounter id propogated", groupObs.getEncounter().getId(), enc.getId());
    assertEquals("encounter time propogated", groupObs.getObsDatetime(), enc.getEncounterDatetime());
    assertNotNull("obs save succeeds", childObs.getObsId());
    assertEquals("encounter id propogated", childObs.getEncounter().getId(), enc.getId());
    assertEquals("encounter time propogated", childObs.getObsDatetime(), enc.getEncounterDatetime());
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 87 with Concept

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

the class ConceptServiceImplTest method saveConcept_shouldSetDefaultPreferredNameToFullySpecifiedFirst.

/**
 * @see ConceptServiceImpl#saveConcept(Concept)
 *           Concept.getPreferredName(locale) returns null, saveConcept chooses one. The default
 *           first choice is the fully specified name in the locale. The default second choice
 *           is a synonym in the locale.
 */
@Test
public void saveConcept_shouldSetDefaultPreferredNameToFullySpecifiedFirst() {
    Locale loc = new Locale("fr", "CA");
    ConceptName fullySpecifiedName = new ConceptName("fully specified", loc);
    // be explicit for test case
    fullySpecifiedName.setConceptNameType(ConceptNameType.FULLY_SPECIFIED);
    ConceptName shortName = new ConceptName("short name", loc);
    // be explicit for test case
    shortName.setConceptNameType(ConceptNameType.SHORT);
    ConceptName synonym = new ConceptName("synonym", loc);
    // synonyms are id'd by a null type
    synonym.setConceptNameType(null);
    ConceptName indexTerm = new ConceptName("indexTerm", loc);
    // synonyms are id'd by a null type
    indexTerm.setConceptNameType(ConceptNameType.INDEX_TERM);
    Concept c = new Concept();
    c.addName(fullySpecifiedName);
    c.addName(synonym);
    c.addName(indexTerm);
    c.addName(shortName);
    c.addDescription(new ConceptDescription("some description", null));
    c.setDatatype(new ConceptDatatype(1));
    c.setConceptClass(new ConceptClass(1));
    assertFalse("check test assumption - the API didn't automatically set preferred vlag", c.getFullySpecifiedName(loc).isPreferred());
    assertNotNull("Concept is legit, save succeeds", Context.getConceptService().saveConcept(c));
    Context.getConceptService().saveConcept(c);
    assertNotNull("there's a preferred name", c.getPreferredName(loc));
    assertTrue("name was explicitly marked preferred", c.getPreferredName(loc).isPreferred());
    assertEquals("name matches", c.getPreferredName(loc).getName(), fullySpecifiedName.getName());
}
Also used : Locale(java.util.Locale) Concept(org.openmrs.Concept) ConceptClass(org.openmrs.ConceptClass) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptDatatype(org.openmrs.ConceptDatatype) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 88 with Concept

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

the class ConceptServiceImplTest method saveConcept_shouldTrimWhitespacesInConceptName.

@Test
public void saveConcept_shouldTrimWhitespacesInConceptName() {
    // Given
    Concept concept = new Concept();
    String nameWithSpaces = "  jwm  ";
    concept.addName(new ConceptName(nameWithSpaces, new Locale("en", "US")));
    concept.addDescription(new ConceptDescription("some description", null));
    concept.setDatatype(new ConceptDatatype(1));
    concept.setConceptClass(new ConceptClass(1));
    // When
    Context.getConceptService().saveConcept(concept);
    // Then
    assertNotEquals(concept.getName().getName(), nameWithSpaces);
    assertEquals(concept.getName().getName(), "jwm");
}
Also used : Concept(org.openmrs.Concept) Locale(java.util.Locale) ConceptClass(org.openmrs.ConceptClass) ConceptName(org.openmrs.ConceptName) ConceptDescription(org.openmrs.ConceptDescription) ConceptDatatype(org.openmrs.ConceptDatatype) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 89 with Concept

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

the class ConceptServiceImplTest method getConceptsByAnswer_shouldReturnAnEmptyListIfConceptIdIsNull.

/**
 * @see ConceptService#getConceptsByAnswer(Concept)
 */
@Test
public void getConceptsByAnswer_shouldReturnAnEmptyListIfConceptIdIsNull() {
    List<Concept> concepts = conceptService.getConceptsByAnswer(new Concept());
    assertEquals(concepts, Collections.emptyList());
}
Also used : Concept(org.openmrs.Concept) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 90 with Concept

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

the class ConceptServiceImplTest method retireConcept_shouldFailIfNoReasonIsGiven.

/**
 * @see ConceptServiceImpl#retireConcept(Concept,String)
 */
@Test
public void retireConcept_shouldFailIfNoReasonIsGiven() {
    Concept concept = conceptService.getConcept(3);
    expectedException.expect(IllegalArgumentException.class);
    conceptService.retireConcept(concept, "");
}
Also used : Concept(org.openmrs.Concept) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Concept (org.openmrs.Concept)294 Test (org.junit.Test)210 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)176 ConceptName (org.openmrs.ConceptName)62 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)62 Obs (org.openmrs.Obs)49 Date (java.util.Date)48 Patient (org.openmrs.Patient)42 ConceptDescription (org.openmrs.ConceptDescription)33 Locale (java.util.Locale)32 ConceptDatatype (org.openmrs.ConceptDatatype)32 OrderUtilTest (org.openmrs.order.OrderUtilTest)29 ConceptClass (org.openmrs.ConceptClass)27 ArrayList (java.util.ArrayList)26 BindException (org.springframework.validation.BindException)26 DrugOrder (org.openmrs.DrugOrder)25 Encounter (org.openmrs.Encounter)25 Errors (org.springframework.validation.Errors)25 ConceptMapBuilder (org.openmrs.module.metadatadeploy.builder.ConceptMapBuilder)21 Location (org.openmrs.Location)19