Skip to content

Commit 3801ac7

Browse files
Get ICD10 from MIABIS on FHIR Observations
1 parent 675aab4 commit 3801ac7

3 files changed

Lines changed: 90 additions & 6 deletions

File tree

‎src/main/java/de/samply/directory_sync_service/fhir/FhirApi.java‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public class FhirApi {
6666
protected final IGenericClient fhirClient;
6767
protected final FhirContext ctx;
6868
protected String fhirStoreUrl;
69+
protected static final String ICD10_SYSTEM = "http://hl7.org/fhir/sid/icd-10";
6970

7071
public FhirApi(String fhirStoreUrl) {
7172
ctx = FhirContext.forR4();
@@ -926,7 +927,6 @@ protected List<Patient> extractPatientListFromSpecimenList(List<Specimen> specim
926927
private Map<Patient, List<String>> patientToConditionCodesMap = new HashMap<>();
927928
/**
928929
* Extracts a list of condition codes from a Patient resource using a FHIR client.
929-
* The condition codes are based on the system "http://hl7.org/fhir/sid/icd-10".
930930
*
931931
* Usess two types of caching to improve performance:
932932
* * If there are no conditions in the FHIR store, this is noted, and an empty list returned.
@@ -1005,8 +1005,8 @@ public List<String> extractConditionCodesFromPatient(Patient patient) {
10051005
List<Coding> codings = code.getCoding();
10061006
// Loop over the coding elements
10071007
for (Coding coding : codings) {
1008-
// Check if the coding element has the system "http://hl7.org/fhir/sid/icd-10"
1009-
if (coding.getSystem().equals("http://hl7.org/fhir/sid/icd-10")) {
1008+
// Check if the coding element has the ICD-10 system
1009+
if (coding.getSystem().equals(ICD10_SYSTEM)) {
10101010
// Get the code value and the display value from the coding element
10111011
String codeValue = coding.getCode();
10121012
//String displayValue = coding.getDisplay();
@@ -1024,14 +1024,13 @@ public List<String> extractConditionCodesFromPatient(Patient patient) {
10241024
}
10251025

10261026
/**
1027-
* Extracts and returns any diagnoses in the extension to the specimen with the
1028-
* URI SAMPLE_DIAGNOSIS_URI.
1027+
* Extracts and returns any diagnoses associated with the Specimen.
10291028
*
10301029
* @param specimen
10311030
* @return
10321031
*/
10331032
public List<String> extractDiagnosesFromSpecimen(Specimen specimen) {
1034-
return extractExtensionElementValuesFromSpecimen(specimen, getSampleDiagnosisUri());
1033+
return null;
10351034
}
10361035

10371036
/**

‎src/main/java/de/samply/directory_sync_service/fhir/FhirApiBbmriDe.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,14 @@ protected String extractLocalCollectionIdFromSpecimen(Specimen specimen) {
6262
protected List<String> extractStorageTemperaturesFromSpecimenList(List<Specimen> specimenList) {
6363
return extractExtensionElementValuesFromSpecimens(specimenList, STORAGE_TEMPERATURE_URI);
6464
}
65+
66+
/**
67+
* Extracts and returns any diagnoses associated with the Specimen.
68+
*
69+
* @param specimen
70+
* @return
71+
*/
72+
public List<String> extractDiagnosesFromSpecimen(Specimen specimen) {
73+
return extractExtensionElementValuesFromSpecimen(specimen, getSampleDiagnosisUri());
74+
}
6575
}

‎src/main/java/de/samply/directory_sync_service/fhir/FhirApiMiabisOnFhir.java‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package de.samply.directory_sync_service.fhir;
22

33
import de.samply.directory_sync_service.Util;
4+
import org.hl7.fhir.r4.model.Bundle;
45
import org.hl7.fhir.r4.model.CodeableConcept;
56
import org.hl7.fhir.r4.model.Coding;
67
import org.hl7.fhir.r4.model.Extension;
78
import org.hl7.fhir.r4.model.Identifier;
9+
import org.hl7.fhir.r4.model.Observation;
810
import org.hl7.fhir.r4.model.Specimen;
911
import org.slf4j.Logger;
1012
import org.slf4j.LoggerFactory;
@@ -152,4 +154,77 @@ protected List<String> extractStorageTemperaturesFromSpecimenList(List<Specimen>
152154

153155
return storageTemperatures;
154156
}
157+
158+
/**
159+
* Extracts and returns any diagnoses associated with the Specimen.
160+
*
161+
* @param specimen
162+
* @return
163+
*/
164+
// public List<String> extractDiagnosesFromSpecimen(Specimen specimen) {
165+
// return extractExtensionElementValuesFromSpecimen(specimen, getSampleDiagnosisUri());
166+
// }
167+
public List<String> extractDiagnosesFromSpecimen(Specimen specimen) {
168+
List<String> diagnoses = new ArrayList<>();
169+
170+
// Sample-diagnosis extension
171+
List<String> extensionDiagnoses =
172+
extractExtensionElementValuesFromSpecimen(
173+
specimen,
174+
getSampleDiagnosisUri());
175+
176+
if (extensionDiagnoses != null) {
177+
diagnoses.addAll(extensionDiagnoses);
178+
}
179+
180+
// Diagnoses represented as Observations referring to this Specimen
181+
diagnoses.addAll(extractDiagnosesFromObservations(specimen));
182+
183+
return diagnoses.stream()
184+
.filter(Objects::nonNull)
185+
.distinct()
186+
.toList();
187+
}
188+
189+
private List<String> extractDiagnosesFromObservations(Specimen specimen) {
190+
if (specimen == null || specimen.getIdElement().isEmpty()) {
191+
return List.of();
192+
}
193+
194+
String specimenReference =
195+
"Specimen/" + specimen.getIdElement().getIdPart();
196+
197+
try {
198+
Bundle bundle = fhirClient
199+
.search()
200+
.forResource(Observation.class)
201+
.where(Observation.SPECIMEN.hasId(specimenReference))
202+
.returnBundle(Bundle.class)
203+
.execute();
204+
205+
return bundle.getEntry().stream()
206+
.map(Bundle.BundleEntryComponent::getResource)
207+
.filter(Observation.class::isInstance)
208+
.map(Observation.class::cast)
209+
210+
// Optional, but useful if other kinds of Observations
211+
// also point to specimens:
212+
.filter(Observation::hasValueCodeableConcept)
213+
214+
.map(Observation::getValueCodeableConcept)
215+
.flatMap(cc -> cc.getCoding().stream())
216+
.filter(coding ->
217+
ICD10_SYSTEM.equals(coding.getSystem()))
218+
.map(Coding::getCode)
219+
.filter(Objects::nonNull)
220+
.distinct()
221+
.toList();
222+
223+
} catch (Exception e) {
224+
logger.warn(
225+
"extractDiagnosesFromObservations: exception: "
226+
+ Util.traceFromException(e));
227+
return List.of();
228+
}
229+
}
155230
}

0 commit comments

Comments
 (0)