Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.

Commit d448905

Browse files
committed
switching search-bundle from transaction to batch
1 parent 230d193 commit d448905

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

codex-process-data-transfer/src/main/java/de/netzwerk_universitaetsmedizin/codex/processes/data_transfer/client/fhir/AbstractFhirClient.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ public AbstractFhirClient(FhirContext fhirContext, HapiFhirClientFactory clientF
115115
public PatientReferenceList getPatientReferencesWithNewData(DateWithPrecision exportFrom, Date exportTo)
116116
{
117117
Bundle searchBundle = getSearchBundle(exportFrom, exportTo);
118+
BundleType expectedResponseType = BundleType.BATCH.equals(searchBundle.getType()) ? BundleType.BATCHRESPONSE
119+
: BundleType.TRANSACTIONRESPONSE;
118120

119121
if (logger.isDebugEnabled())
120122
logger.debug("Executing Search-Bundle: {}",
@@ -126,6 +128,29 @@ public PatientReferenceList getPatientReferencesWithNewData(DateWithPrecision ex
126128
if (logger.isDebugEnabled())
127129
logger.debug("Search-Bundle result: {}", fhirContext.newJsonParser().encodeResourceToString(resultBundle));
128130

131+
if (!resultBundle.hasType() || !expectedResponseType.equals(resultBundle.getType()) || !resultBundle.hasEntry())
132+
{
133+
logger.warn("Search-Bundle result not a {} or has no entries", expectedResponseType.toCode());
134+
throw new RuntimeException(
135+
"Search-Bundle result not a " + expectedResponseType.toCode() + " or has no entries");
136+
}
137+
138+
for (int i = 0; i < resultBundle.getEntry().size(); i++)
139+
{
140+
BundleEntryComponent entry = resultBundle.getEntry().get(i);
141+
142+
if (!entry.hasResource() || !(entry.getResource() instanceof Bundle) || !entry.hasResponse()
143+
|| !entry.getResponse().hasStatus() || !entry.getResponse().getStatus().startsWith("200"))
144+
{
145+
logger.warn(
146+
"Error in Search-Bundle at index {}: entry has no Bundle resource or response is not 200 OK",
147+
i);
148+
if (entry.hasResource() && !(entry.getResource() instanceof Bundle))
149+
logger.debug("Unexpected entry resource: {}",
150+
fhirContext.newJsonParser().encodeResourceToString(entry.getResource()));
151+
}
152+
}
153+
129154
Stream<Patient> patients = resultBundle.getEntry().stream()
130155
.filter(e -> e.hasResource() && e.getResource() instanceof Bundle).map(e -> (Bundle) e.getResource())
131156
.flatMap(this::getPatients);

codex-process-data-transfer/src/main/resources/fhir/Bundle/SearchBundle.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Bundle xmlns="http://hl7.org/fhir">
2-
<type value="transaction"/>
2+
<type value="batch"/>
33
<entry>
44
<request>
55
<method value="GET"/>

0 commit comments

Comments
 (0)