Skip to content

Commit 6d03753

Browse files
committed
Dubey | BDSHR-1275 | Saving a concept with answers as drug concept.
1 parent f5e2486 commit 6d03753

File tree

5 files changed

+141
-10
lines changed

5 files changed

+141
-10
lines changed

src/main/java/org/bahmni/module/terminology/application/mapping/ConceptMapper.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,30 @@ private void setConceptNames(Concept concept, ConceptRequest conceptRequest) {
7979
private void mapConceptAnswers(Concept concept, ConceptRequest conceptRequest) {
8080
if (null != conceptRequest.getConceptAnswers()) {
8181
for (String conceptAnswerUuid : conceptRequest.getConceptAnswers()) {
82-
ConceptAnswer answer = new ConceptAnswer();
8382
IdMapping idMap = idMappingsRepository.findByExternalId(conceptAnswerUuid);
8483
if (idMap == null) {
8584
throw new RuntimeException("Can not identify concept answer with external Id:" + conceptAnswerUuid);
8685
}
87-
answer.setAnswerConcept(conceptService.getConceptByUuid(idMap.getInternalId()));
86+
String internalId = idMap.getInternalId();
87+
ConceptAnswer answer = createConceptAnswer(internalId);
8888
concept.addAnswer(answer);
8989
}
9090
}
9191
}
9292

93+
private ConceptAnswer createConceptAnswer(String internalId) {
94+
ConceptAnswer conceptAnswer = new ConceptAnswer();
95+
Concept conceptByUuid = conceptService.getConceptByUuid(internalId);
96+
if (null != conceptByUuid) {
97+
conceptAnswer.setAnswerConcept(conceptByUuid);
98+
return conceptAnswer;
99+
}
100+
Drug drugByUuid = conceptService.getDrugByUuid(internalId);
101+
conceptAnswer.setAnswerConcept(drugByUuid.getConcept());
102+
conceptAnswer.setAnswerDrug(drugByUuid);
103+
return conceptAnswer;
104+
}
105+
93106
private void mapSetMembers(Concept concept, ConceptRequest conceptRequest) {
94107
if (null != conceptRequest.getSetMembers()) {
95108
for (String setMemberUuid : conceptRequest.getSetMembers()) {

src/main/java/org/bahmni/module/terminology/infrastructure/mapper/ConceptUpdate.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,17 @@ private void mergeConceptAnswers(Concept existingConcept, Concept newConcept) {
6969
private boolean foundAnswer(Concept newConcept, ConceptAnswer conceptAnswer) {
7070
if (null != newConcept.getAnswers()) {
7171
for (ConceptAnswer answer : newConcept.getAnswers()) {
72-
if (StringUtils.equals(answer.getAnswerConcept().getUuid(), conceptAnswer.getAnswerConcept().getUuid())) {
73-
return true;
72+
if (answer.getAnswerDrug() == null && conceptAnswer.getAnswerDrug() == null) {
73+
if (StringUtils.equals(answer.getAnswerConcept().getUuid(), conceptAnswer.getAnswerConcept().getUuid())) {
74+
return true;
75+
}
76+
}
77+
if (answer.getAnswerDrug() != null && conceptAnswer.getAnswerDrug() != null) {
78+
if (StringUtils.equals(answer.getAnswerDrug().getUuid(), conceptAnswer.getAnswerDrug().getUuid())) {
79+
if (StringUtils.equals(answer.getAnswerConcept().getUuid(), conceptAnswer.getAnswerConcept().getUuid())) {
80+
return true;
81+
}
82+
}
7483
}
7584
}
7685
}

src/test/java/org/bahmni/module/terminology/infrastructure/atomfeed/workers/ConceptEventWorkerIntegrationTest.java

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
@org.springframework.test.context.ContextConfiguration(locations = {"classpath:TestingApplicationContext.xml"}, inheritLocations = true)
3838
public class ConceptEventWorkerIntegrationTest extends BaseModuleWebContextSensitiveTest {
3939

40-
public static final String TR_CONCEPT_URL = "www.bdshr-tr.com/openmrs/ws/rest/v1/tr/concepts/";
41-
public static final String TR_REFTERM_URL = "www.bdshr-tr.com/openmrs/ws/rest/v1/tr/referenceterms/";
40+
private static final String TR_CONCEPT_URL = "www.bdshr-tr.com/openmrs/ws/rest/v1/tr/concepts/";
41+
private static final String TR_REFTERM_URL = "www.bdshr-tr.com/openmrs/ws/rest/v1/tr/referenceterms/";
4242
@Rule
4343
public WireMockRule wireMockRule = new WireMockRule(9997);
4444

@@ -57,9 +57,9 @@ public class ConceptEventWorkerIntegrationTest extends BaseModuleWebContextSensi
5757

5858
@Before
5959
public void setUp() {
60-
60+
6161
}
62-
62+
6363
@After
6464
public void tearDown() throws Exception {
6565
deleteAllData();
@@ -187,7 +187,6 @@ public void shouldUpdateConceptAnswersOfValueSet() {
187187

188188
@Test
189189
public void shouldSyncCodedConcept() {
190-
191190
syncConcept("666c8246-202c-4376-bfa8-3278d1049666", "concept_male.json");
192191
Concept maleSexConcept = conceptService.getConceptByName("Male Sex");
193192
assertNotNull("Male sex concept should have been created", maleSexConcept);
@@ -200,10 +199,39 @@ public void shouldSyncCodedConcept() {
200199

201200
Concept patientSexConcept = conceptService.getConceptByName("Patient Sex");
202201
assertNotNull("Patient Sex Concept should have been created", patientSexConcept);
202+
assertConceptAnswers(patientSexConcept, Arrays.asList(maleSexConcept, femaleSexConcept));
203+
}
203204

205+
@Test
206+
public void shouldSetDrugAsAnswerIfAnswerIsNotAConcept() throws Exception {
207+
executeDataSet("stubdata/datasets/concept_drugs.xml");
208+
String externalId = "2ff6a1bf-a27d-4364-9d80-5a42f3bb22ad";
209+
String concept_event_url = "/openmrs/ws/rest/v1/tr/concepts/" + externalId;
204210

205-
assertConceptAnswers(patientSexConcept, Arrays.asList(maleSexConcept, femaleSexConcept));
211+
givenThat(get(urlEqualTo(concept_event_url))
212+
.willReturn(aResponse()
213+
.withStatus(200)
214+
.withHeader("Content-Type", "application/json")
215+
.withBody(asString("stubdata/concept_with_answer_drugs.json"))));
216+
ConceptEventWorker worker = new ConceptEventWorker(httpClient, trFeedProperties, conceptSyncService, conceptMapper);
217+
218+
worker.process(new Event("eventId", concept_event_url, "title", "feedUri", null));
219+
220+
Concept concept = Context.getConceptService().getConceptByName("Medication TR");
221+
assertThat(concept, is(notNullValue()));
222+
assertThat(concept.getVersion(), is(ConceptMapper.TERMINOLOGY_SERVICES_VERSION_PREFIX + "1.1.1"));
223+
assertThat(concept.getName().getName(), is("Medication TR"));
224+
assertThat(concept.getDatatype().getName(), is("Coded"));
225+
assertThat(concept.getConceptClass().getName(), is("Finding"));
226+
assertThat(concept.isSet(), is(false));
227+
assertThat(concept.isRetired(), is(false));
206228

229+
Collection<ConceptAnswer> answers = concept.getAnswers();
230+
assertEquals(2, answers.size());
231+
for (ConceptAnswer answer : answers) {
232+
assertNotNull(answer.getAnswerConcept());
233+
assertNotNull(answer.getAnswerDrug());
234+
}
207235

208236
}
209237

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"uuid": "2ff6a1bf-a27d-4364-9d80-5a42f3bb22ad",
3+
"uri": "http://192.168.33.17:9080/openmrs/ws/rest/v1/tr/concepts/2ff6a1bf-a27d-4364-9d80-5a42f3bb22ad",
4+
"version": "1.1.1",
5+
"datatypeName": "Coded",
6+
"conceptClass": "Finding",
7+
"retireReason": null,
8+
"fullySpecifiedName": {
9+
"conceptName": "Medication TR",
10+
"conceptNameType": "FULLY_SPECIFIED",
11+
"locale": "en",
12+
"preferred": true
13+
},
14+
"names": [
15+
{
16+
"conceptName": "Medication",
17+
"conceptNameType": "SHORT",
18+
"locale": "en",
19+
"preferred": false
20+
},
21+
{
22+
"conceptName": "Medication TR",
23+
"conceptNameType": "FULLY_SPECIFIED",
24+
"locale": "en",
25+
"preferred": true
26+
}
27+
],
28+
"referenceTerms": [],
29+
"description": null,
30+
"setMembers": [],
31+
"properties": {},
32+
"conceptAnswers": [
33+
{
34+
"uuid": "cd89844d-8211-11e5-aa01-0050568276cf",
35+
"display": "Crocin 500mg",
36+
"uri": null
37+
},
38+
{
39+
"uuid": "d20a4cad-2349-4b5b-a6de-0665f51429cf",
40+
"display": "Benedryl",
41+
"uri": null
42+
}
43+
],
44+
"set": false,
45+
"retired": false
46+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<dataset>
3+
<concept concept_id="1200" retired="false" datatype_id="4" class_id="3" is_set="false" creator="1"
4+
date_created="2004-08-12 00:00:00.0" version="" changed_by="1" date_changed="2005-02-25 11:43:43.0"
5+
uuid="99110684-c97a-4a3b-9dad-5e5bf146867a"/>
6+
<concept_name concept_name_id="1035" concept_id="1200" name="Paracetamol" locale="en" creator="1"
7+
date_created="2004-08-12 00:00:00.0" concept_name_type="FULLY_SPECIFIED" locale_preferred="1"
8+
voided="false" uuid="3803d71e-adc6-41b9-a6c4-392a9593686c"/>
9+
10+
<concept concept_id="1201" retired="false" datatype_id="4" class_id="3" is_set="false" creator="1"
11+
date_created="2004-08-12 00:00:00.0" version="" changed_by="1" date_changed="2005-02-25 11:43:43.0"
12+
uuid="ddea03a4-c986-4bcd-b5d7-212b9fc52581"/>
13+
<concept_name concept_name_id="1036" concept_id="1201" name="diphenhydramine" locale="en" creator="1"
14+
date_created="2004-08-12 00:00:00.0" concept_name_type="FULLY_SPECIFIED" locale_preferred="1"
15+
voided="false" uuid="3031b038-2b77-4634-8614-35259e8d2e66"/>
16+
17+
<concept concept_id="1204" retired="false" datatype_id="4" class_id="4" is_set="false" creator="1"
18+
date_created="2004-08-12 00:00:00.0" version="" changed_by="1" date_changed="2005-02-25 11:43:43.0"
19+
uuid="ddea03a4-c986-4bcd-b5d7-212b9fc545dx"/>
20+
<concept_name concept_name_id="1038" concept_id="1204" name="Chew" locale="en" creator="1"
21+
date_created="2004-08-12 00:00:00.0" concept_name_type="FULLY_SPECIFIED" locale_preferred="1"
22+
voided="false" uuid="3xd0b038-2b77-4634-8614-35259e8d2e66"/>
23+
24+
<drug drug_id="1010" concept_id="1200" name="Crocin 500mg" dosage_form="1204" strength="500 mg" combination="0"
25+
creator="1" date_created="2004-08-12 00:00:00.0" retired="0" changed_by="1" date_changed="2005-02-25 11:43:43.0"
26+
uuid="ada47e63-5988-4f51-8282-e22fb66a7332"/>
27+
<drug drug_id="1011" concept_id="1201" name="Benedryl" dosage_form="1204" strength="20 mg" combination="0" creator="1"
28+
date_created="2004-08-12 00:00:00.0" retired="0" changed_by="1" date_changed="2005-02-25 11:43:43.0"
29+
uuid="04558a65-0e18-4fc4-bb8d-4f9a89fbec5c"/>
30+
31+
<shr_id_mapping id="100" internal_id="ada47e63-5988-4f51-8282-e22fb66a7332"
32+
external_id="cd89844d-8211-11e5-aa01-0050568276cf" type="Medication"/>
33+
<shr_id_mapping id="101" internal_id="04558a65-0e18-4fc4-bb8d-4f9a89fbec5c"
34+
external_id="d20a4cad-2349-4b5b-a6de-0665f51429cf" type="Medication"/>
35+
</dataset>

0 commit comments

Comments
 (0)