Skip to content

Commit 51b05f7

Browse files
icrc-jofranciscoJose Franciscoparthfloyd
authored andcommitted
FM2-126: Fix handling of concepts in PersonAttributes (#567)
Co-authored-by: Jose Francisco <josecarlos.francisco@merkle.com> Co-authored-by: Parth Panchal <parth6606@gmail.com>
1 parent f0f3b91 commit 51b05f7

File tree

8 files changed

+37
-8
lines changed

8 files changed

+37
-8
lines changed

api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/PersonAttributeTranslatorImpl.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public class PersonAttributeTranslatorImpl implements PersonAttributeTranslator
7575

7676
@Override
7777
public Extension toFhirResource(@Nonnull PersonAttribute personAttribute) {
78-
if (personAttribute == null || personAttribute.getAttributeType() == null) {
78+
if (personAttribute == null || personAttribute.getVoided() || personAttribute.getAttributeType() == null) {
7979
return null;
8080
}
8181

@@ -204,7 +204,14 @@ protected CodeableConcept buildCodeableConcept(String conceptId) {
204204
return null;
205205
}
206206

207-
Concept concept = conceptService.get(conceptId);
207+
Concept concept;
208+
try {
209+
concept = conceptService.get(Integer.parseInt(conceptId));
210+
}
211+
catch (NumberFormatException e) {
212+
return null;
213+
}
214+
208215
if (concept != null) {
209216
return conceptTranslator.toFhirResource(concept);
210217
}

api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/PersonAttributeTranslatorImplTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public void shouldTranslateConceptPersonAttributeToFhirExtension() {
185185

186186
Concept concept = new Concept();
187187
concept.setConceptId(Integer.parseInt(CONCEPT_ATTRIBUTE_VALUE));
188-
when(conceptService.get(CONCEPT_ATTRIBUTE_VALUE)).thenReturn(concept);
188+
when(conceptService.get(Integer.parseInt(CONCEPT_ATTRIBUTE_VALUE))).thenReturn(concept);
189189

190190
CodeableConcept codeableConcept = new CodeableConcept();
191191
codeableConcept.setText("ConceptText");
@@ -380,4 +380,17 @@ public void shouldTranslateCodeableConceptTypeExtensionToPersonAttribute() {
380380
assertThat(result.getValue(), equalTo(CONCEPT_ATTRIBUTE_VALUE));
381381
}
382382

383+
@Test
384+
public void shouldReturnNullWhenPersonAttributeIsVoided() {
385+
personAttribute.setVoided(true);
386+
Extension result = personAttributeTranslator.toFhirResource(personAttribute);
387+
assertThat(result, equalTo(null));
388+
}
389+
390+
@Test
391+
public void shouldReturnNullWhenConceptIdIsNotAnInteger() {
392+
CodeableConcept result = personAttributeTranslator.buildCodeableConcept("notAnInt");
393+
assertThat(result, equalTo(null));
394+
}
395+
383396
}

integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/PatientFhirResourceProviderIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public void shouldReturnPersonAttributesAsExtensions() throws Exception {
197197
.filter(ext -> ext.getUrl().equals(FhirConstants.OPENMRS_FHIR_EXT_PERSON_ATTRIBUTE))
198198
.collect(Collectors.toList());
199199

200-
assertThat(personAttributeExtensions, hasSize(3));
200+
assertThat(personAttributeExtensions, hasSize(4));
201201
}
202202

203203
@Test

integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r3/PersonFhirResourceProviderIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public void shouldReturnPersonAttributesAsExtensions() throws Exception {
148148
.filter(ext -> ext.getUrl().equals(FhirConstants.OPENMRS_FHIR_EXT_PERSON_ATTRIBUTE))
149149
.collect(Collectors.toList());
150150

151-
assertThat(personAttributeExtensions, hasSize(2));
151+
assertThat(personAttributeExtensions, hasSize(4));
152152
}
153153

154154
@Test

integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/PatientFhirResourceProviderIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public void shouldReturnPersonAttributesAsExtensions() throws Exception {
205205
.filter(ext -> ext.getUrl().equals(FhirConstants.OPENMRS_FHIR_EXT_PERSON_ATTRIBUTE))
206206
.collect(Collectors.toList());
207207

208-
assertThat(personAttributeExtensions, hasSize(3));
208+
assertThat(personAttributeExtensions, hasSize(4));
209209
}
210210

211211
@Test

integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/PersonFhirResourceProviderIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public void shouldReturnPersonAttributesAsExtensions() throws Exception {
154154
.filter(ext -> ext.getUrl().equals(FhirConstants.OPENMRS_FHIR_EXT_PERSON_ATTRIBUTE))
155155
.collect(Collectors.toList());
156156

157-
assertThat(personAttributeExtensions, hasSize(2));
157+
assertThat(personAttributeExtensions, hasSize(4));
158158
}
159159

160160
@Test

test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirPatientDaoImplTest_initial_data.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
<dataset>
1212
<global_property property="patient.identifierRegex" property_value="^0*@SEARCH@([A-Z]+-[0-9])?$" uuid="c92cce6d-7e7d-4c53-a3c9-faaac17f8f8b"/>
1313
<location location_id="1" name="Test Location" creator="1" date_created="2005-01-01 00:00:00.0" retired="false" uuid="92ab9667-4686-49af-8be8-65a4b58fc49c"/>
14+
<concept concept_id="1" retired="false" class_id="1" is_set="false" creator="1" date_created="2005-01-01 00:00:00.0" version="" uuid="4bfea75e-2b8d-4048-9551-b363d72018b1"/>
15+
<concept_name concept_id="1" name="Test Concept" locale="en_GB" creator="1" date_created="2005-01-01 00:00:00.0" concept_name_id="1" concept_name_type="FULLY_SPECIFIED" locale_preferred="1" voided="false" uuid="17b09f4e-37c6-46cd-8c3a-89214dd5fe25"/>
1416
<patient_identifier_type patient_identifier_type_id="1" name="Test Identifier Type" description="Test description" creator="1" date_created="2005-01-01 00:00:00.0" required="false" retired="false" uuid="c5576187-9a67-43a7-9b7c-04db22851211"/>
1517
<person person_id="2" gender="M" dead="false" creator="1" date_created="2005-01-01 00:00:00.0" voided="false" uuid="61b38324-e2fd-4feb-95b7-9e9a2a4400df"/>
1618
<person person_id="3" gender="M" dead="true" creator="1" date_created="2005-01-01 00:00:00.0" voided="false" uuid="5c521595-4e12-46b0-8248-b8f2d3697766"/>
@@ -51,7 +53,9 @@
5153
<person_attribute_type person_attribute_type_id="4" name="test string" format="java.lang.String" searchable="false" creator="1" date_created="2008-08-15 15:53:36.0" retired="false" uuid="3b4a243d-4508-4ecf-aa05-d1260a78e196" sort_weight="2"/>
5254
<person_attribute_type person_attribute_type_id="5" name="test boolean" format="java.lang.Boolean" searchable="false" creator="1" date_created="2008-08-15 15:53:36.0" retired="false" uuid="4973eeee-f193-4504-a67e-b8132a39c42a" sort_weight="2"/>
5355
<person_attribute_type person_attribute_type_id="6" name="test location" format="org.openmrs.Location" searchable="false" creator="1" date_created="2008-08-15 15:53:36.0" retired="false" uuid="560683ca-1261-441d-89e2-d11faeacd8c9" sort_weight="2"/>
56+
<person_attribute_type person_attribute_type_id="7" name="test concept" format="org.openmrs.Concept" searchable="false" creator="1" date_created="2008-08-15 15:53:36.0" retired="false" uuid="9da03a0b-c208-44d3-acd9-425151c8f8e1" sort_weight="2"/>
5457
<person_attribute person_attribute_id="4" person_id="5" value="test@openmrs.org" person_attribute_type_id="4" creator="1" date_created="2008-08-18 12:25:57.0" voided="false" uuid="fbd82a27-56ec-46b4-8660-6442e832dc3e"/>
5558
<person_attribute person_attribute_id="5" person_id="5" value="true" person_attribute_type_id="5" creator="1" date_created="2008-08-18 12:25:57.0" voided="false" uuid="a55f316e-29dd-4ad5-b954-62ef93723658"/>
5659
<person_attribute person_attribute_id="6" person_id="5" value="1" person_attribute_type_id="6" creator="1" date_created="2008-08-18 12:25:57.0" voided="false" uuid="ad0f530d-aebf-4284-b7c1-c103986b1c2b"/>
60+
<person_attribute person_attribute_id="7" person_id="5" value="1" person_attribute_type_id="7" creator="1" date_created="2008-08-18 12:25:57.0" voided="false" uuid="704f5723-ed90-4d03-ad69-5d626dfb18ee"/>
5761
</dataset>

test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirPersonDaoImplTest_initial_data.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
graphic logo is a trademark of OpenMRS Inc.
1010
-->
1111
<dataset>
12+
<concept concept_id="1" retired="false" class_id="1" is_set="false" creator="1" date_created="2005-01-01 00:00:00.0" version="" uuid="790e6c1e-1e89-43a7-92d7-4aa22b1f961a"/>
13+
<concept_name concept_id="1" name="Test Concept" locale="en_GB" creator="1" date_created="2005-01-01 00:00:00.0" concept_name_id="1" concept_name_type="FULLY_SPECIFIED" locale_preferred="1" voided="false" uuid="80dc810e-68fe-4bef-80d3-786722c53766"/>
1214
<person person_id="2" gender="M" birthdate="1999-12-20" dead="false" creator="1" date_created="2005-01-01 00:00:00.0" voided="false" uuid="61b38324-e2fd-4feb-95b7-9e9a2a4400df"/>
1315
<person person_id="3" gender="M" birthdate="2000-11-18" dead="false" creator="1" date_created="2005-01-01 00:00:00.0" voided="false" void_reason="there is no reason" uuid="5c521595-4e12-46b0-8248-b8f2d3697766"/>
1416
<person person_id="4" gender="M" birthdate="1993-04-02" dead="false" creator="1" date_created="2005-01-01 00:00:00.0" voided="false" uuid="256ccf6d-6b41-455c-9be2-51ff4386ae76"/>
@@ -22,7 +24,10 @@
2224
<person_address person_address_id="7" preferred="true" person_id="7" city_village="Peabody" state_province="MA" postal_code="01960" country="FakeAB" creator="1" date_created="2005-01-01 00:00:00.0" voided="false" uuid="da593572-67b7-11ea-bc55-0242ac130003"/>
2325
<person_attribute_type person_attribute_type_id="2" name="email" format="java.lang.String" searchable="false" creator="1" date_created="2008-08-15 15:53:36.0" retired="false" uuid="5a8c170b-178a-4b8f-908e-279b67854d84" sort_weight="2"/>
2426
<person_attribute_type person_attribute_type_id="3" name="test patient" format="java.lang.Boolean" searchable="false" creator="1" date_created="2008-08-15 15:53:36.0" retired="false" uuid="e34d1404-5633-4e5b-9db3-930f31086557" sort_weight="2"/>
27+
<person_attribute_type person_attribute_type_id="8" name="test location" format="org.openmrs.Location" searchable="false" creator="1" date_created="2008-08-15 15:53:36.0" retired="false" uuid="95a7a38f-9bea-4f7a-9428-775762ee13e4" sort_weight="2"/>
28+
<person_attribute_type person_attribute_type_id="9" name="test concept" format="org.openmrs.Concept" searchable="false" creator="1" date_created="2008-08-15 15:53:36.0" retired="false" uuid="1a39a18b-184d-4a5c-9641-e1f7a4a717e5" sort_weight="2"/>
2529
<person_attribute person_attribute_id="2" person_id="3" value="test@openmrs.org" person_attribute_type_id="2" creator="1" date_created="2008-08-18 12:25:57.0" voided="false" uuid="9cc62c8d-5817-4c21-8205-266c5ff344db"/>
2630
<person_attribute person_attribute_id="3" person_id="3" value="true" person_attribute_type_id="3" creator="1" date_created="2008-08-18 12:25:57.0" voided="false" uuid="bcced38f-dad5-4c71-a436-8a486e4288d9"/>
27-
31+
<person_attribute person_attribute_id="8" person_id="3" value="1" person_attribute_type_id="8" creator="1" date_created="2008-08-18 12:25:57.0" voided="false" uuid="4b2f7474-29e7-4205-ae48-0b5f67bf7895"/>
32+
<person_attribute person_attribute_id="9" person_id="3" value="1" person_attribute_type_id="9" creator="1" date_created="2008-08-18 12:25:57.0" voided="false" uuid="f830bf48-af63-495a-897e-a779e229d503"/>
2833
</dataset>

0 commit comments

Comments
 (0)