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