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));
}
}
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());
}
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());
}
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());
}
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));
}
Aggregations