Search in sources :

Example 16 with ConceptReferenceTerm

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

the class ConceptServiceTest method getConceptReferenceTerms_shouldReturnUniqueTermsWithACodeOrNameContainingTheSearchPhrase.

/**
 * @see ConceptService#getConceptReferenceTerms(String,ConceptSource,Integer,Integer,null)
 */
@Test
public void getConceptReferenceTerms_shouldReturnUniqueTermsWithACodeOrNameContainingTheSearchPhrase() {
    List<ConceptReferenceTerm> matches = Context.getConceptService().getConceptReferenceTerms("cd4", null, null, null, true);
    Assert.assertEquals(3, matches.size());
    Set<ConceptReferenceTerm> uniqueTerms = new HashSet<>();
    // check that we have only unique terms
    for (ConceptReferenceTerm conceptReferenceTerm : matches) {
        Assert.assertTrue(uniqueTerms.add(conceptReferenceTerm));
    }
}
Also used : ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) HashSet(java.util.HashSet) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 17 with ConceptReferenceTerm

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

the class ConceptServiceTest method getConceptReferenceTermByName_shouldBeCaseInsensitive.

/**
 * @see ConceptService#getConceptReferenceTermByName(String,ConceptSource)
 */
@Test
public void getConceptReferenceTermByName_shouldBeCaseInsensitive() {
    String name = "WEIGHT term";
    ConceptReferenceTerm term = Context.getConceptService().getConceptReferenceTermByName(name, new ConceptSource(1));
    Assert.assertNotNull(term);
    Assert.assertNotSame(name, term.getName());
    Assert.assertEquals(1, term.getId().intValue());
}
Also used : ConceptSource(org.openmrs.ConceptSource) ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 18 with ConceptReferenceTerm

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

the class ConceptServiceTest method retireConceptReferenceTerm_shouldRetireTheSpecifiedConceptReferenceTermWithTheGivenRetireReason.

/**
 * @see ConceptService#retireConceptReferenceTerm(ConceptReferenceTerm,String)
 */
@Test
public void retireConceptReferenceTerm_shouldRetireTheSpecifiedConceptReferenceTermWithTheGivenRetireReason() {
    ConceptReferenceTerm term = Context.getConceptService().getConceptReferenceTerm(1);
    Assert.assertFalse(term.getRetired());
    Assert.assertNull(term.getRetireReason());
    Assert.assertNull(term.getRetiredBy());
    Assert.assertNull(term.getDateRetired());
    ConceptReferenceTerm retiredTerm = Context.getConceptService().retireConceptReferenceTerm(term, "test retire reason");
    Assert.assertTrue(retiredTerm.getRetired());
    Assert.assertEquals("test retire reason", retiredTerm.getRetireReason());
    Assert.assertNotNull(retiredTerm.getRetiredBy());
    Assert.assertNotNull(retiredTerm.getDateRetired());
}
Also used : ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 19 with ConceptReferenceTerm

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

the class ConceptServiceTest method saveConceptReferenceTerm_shouldUpdateChangesToTheConceptReferenceTermInTheDatabase.

/**
 * @see ConceptService#saveConceptReferenceTerm(ConceptReferenceTerm)
 */
@Test
public void saveConceptReferenceTerm_shouldUpdateChangesToTheConceptReferenceTermInTheDatabase() {
    ConceptReferenceTerm term = Context.getConceptService().getConceptReferenceTerm(1);
    // sanity checks
    Assert.assertEquals(Context.getConceptService().getConceptSource(1), term.getConceptSource());
    Assert.assertNull(term.getChangedBy());
    Assert.assertNull(term.getDateChanged());
    term.setName("new name");
    term.setCode("new code");
    term.setDescription("new descr");
    ConceptSource conceptSource2 = Context.getConceptService().getConceptSource(2);
    term.setConceptSource(conceptSource2);
    ConceptReferenceTerm editedTerm = Context.getConceptService().saveConceptReferenceTerm(term);
    Context.flushSession();
    Assert.assertEquals("new name", editedTerm.getName());
    Assert.assertEquals("new code", editedTerm.getCode());
    Assert.assertEquals("new descr", editedTerm.getDescription());
    Assert.assertEquals(conceptSource2, editedTerm.getConceptSource());
    // The auditable fields should have been set
    Assert.assertNotNull(term.getChangedBy());
    Assert.assertNotNull(term.getDateChanged());
}
Also used : ConceptSource(org.openmrs.ConceptSource) ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 20 with ConceptReferenceTerm

use of org.openmrs.ConceptReferenceTerm 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)

Aggregations

ConceptReferenceTerm (org.openmrs.ConceptReferenceTerm)37 Test (org.junit.Test)33 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)31 BindException (org.springframework.validation.BindException)19 Errors (org.springframework.validation.Errors)19 ConceptSource (org.openmrs.ConceptSource)7 ConceptReferenceTermMap (org.openmrs.ConceptReferenceTermMap)5 ArrayList (java.util.ArrayList)3 Ignore (org.junit.Ignore)3 Drug (org.openmrs.Drug)3 APIException (org.openmrs.api.APIException)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Criteria (org.hibernate.Criteria)2 ConceptMap (org.openmrs.ConceptMap)2 ConceptMapType (org.openmrs.ConceptMapType)2 ConceptName (org.openmrs.ConceptName)2 DrugReferenceMap (org.openmrs.DrugReferenceMap)2 OpenmrsObject (org.openmrs.OpenmrsObject)2 ConceptService (org.openmrs.api.ConceptService)2