4444import org .hl7 .fhir .r4 .model .Procedure ;
4545import org .hl7 .fhir .r4 .model .Reference ;
4646import org .hl7 .fhir .r4 .model .Resource ;
47+ import org .hl7 .fhir .r4 .model .ResourceType ;
4748import org .hl7 .fhir .r4 .model .Task ;
4849import org .hl7 .fhir .r4 .model .Type ;
4950import org .slf4j .Logger ;
@@ -237,19 +238,33 @@ else if (resource instanceof Procedure)
237238
238239 protected String getConditionalUpdateUrl (String pseudonym , DomainResource resource )
239240 {
241+ String patientIdentifier = ConstantsDataTransfer .NAMING_SYSTEM_NUM_CODEX_DIC_PSEUDONYM + "|" + pseudonym ;
242+
240243 if (resource instanceof Patient )
241244 {
242- return "Patient?identifier=" + ConstantsDataTransfer .NAMING_SYSTEM_NUM_CODEX_DIC_PSEUDONYM + "|"
243- + pseudonym ;
245+ return "Patient?identifier=" + patientIdentifier ;
244246 }
245247 else if (resource instanceof Condition )
246248 {
247249 Condition c = (Condition ) resource ;
248250 String profileUrl = getProfileUrl (resource , v -> v .startsWith (NUM_CODEX_STRUCTURE_DEFINITION_PREFIX ));
249251
250- return "Condition?_profile=" + profileUrl + "&recorded-date="
251- + c .getRecordedDateElement ().getValueAsString () + "&patient:identifier="
252- + ConstantsDataTransfer .NAMING_SYSTEM_NUM_CODEX_DIC_PSEUDONYM + "|" + pseudonym ;
252+ String updateUrl = getBaseConditionalUpdateUrl (ResourceType .Condition .name (), profileUrl ,
253+ patientIdentifier );
254+
255+ if (c .hasRecordedDateElement () && c .getRecordedDateElement ().getValueAsString () != null )
256+ updateUrl = updateUrl + "&recorded-date=" + c .getRecordedDateElement ().getValueAsString ();
257+
258+ if (c .hasCategory () && c .getCategoryFirstRep ().hasCoding ())
259+ updateUrl = updateUrl + "&category=" + getCodingUpdateUrl (c .getCategoryFirstRep ().getCodingFirstRep ());
260+
261+ if (c .hasCode () && c .getCode ().hasCoding ())
262+ updateUrl = updateUrl + "&code=" + getCodingUpdateUrl (c .getCode ().getCodingFirstRep ());
263+
264+ if (c .hasBodySite () && c .getBodySiteFirstRep ().hasCoding ())
265+ updateUrl = updateUrl + "&body-site=" + getCodingUpdateUrl (c .getBodySiteFirstRep ().getCodingFirstRep ());
266+
267+ return updateUrl ;
253268 }
254269 else if (resource instanceof Consent )
255270 {
@@ -258,21 +273,20 @@ else if (resource instanceof Consent)
258273
259274 if (NUM_CODEX_DO_NOT_RESUSCITAT_ORDER .equals (profileUrl ))
260275 {
261- boolean scopePresent = c .getScope ().getCoding ().stream ().filter (co -> co . hasSystem () )
276+ boolean scopePresent = c .getScope ().getCoding ().stream ().filter (Coding :: hasSystem )
262277 .filter (co -> "http://terminology.hl7.org/CodeSystem/consentscope" .equals (co .getSystem ()))
263- .filter (co -> co . hasCode ()). filter (co -> "adr" .equals (co .getCode ())). findAny (). isPresent ( );
278+ .filter (Coding :: hasCode ). anyMatch (co -> "adr" .equals (co .getCode ()));
264279 boolean categoryPresent = c .getCategory ().stream ().flatMap (coc -> coc .getCoding ().stream ())
265- .filter (co -> co . hasSystem () )
280+ .filter (Coding :: hasSystem )
266281 .filter (co -> "http://terminology.hl7.org/CodeSystem/consentcategorycodes"
267282 .equals (co .getSystem ()))
268- .filter (co -> co . hasCode ()). filter (co -> "dnr" .equals (co .getCode ())). findAny (). isPresent ( );
283+ .filter (Coding :: hasCode ). anyMatch (co -> "dnr" .equals (co .getCode ()));
269284
270285 if (scopePresent && categoryPresent )
271- return " Consent?_profile=" + profileUrl
286+ return getBaseConditionalUpdateUrl ( ResourceType . Consent . name (), profileUrl , patientIdentifier )
272287 + "&scope=http://terminology.hl7.org/CodeSystem/consentscope|adr"
273- + "&category=http://terminology.hl7.org/CodeSystem/consentcategorycodes|dnr"
274- + "&patient:identifier=" + ConstantsDataTransfer .NAMING_SYSTEM_NUM_CODEX_DIC_PSEUDONYM + "|"
275- + pseudonym ;
288+ + "&category=http://terminology.hl7.org/CodeSystem/consentcategorycodes|dnr" ;
289+
276290 else
277291 throw new RuntimeException ("Resource of type Consent with profile " + profileUrl
278292 + " is missing scope: http://terminology.hl7.org/CodeSystem/consentscope|adr and/or category: http://terminology.hl7.org/CodeSystem/consentcategorycodes|dnr" );
@@ -285,61 +299,92 @@ else if (resource instanceof DiagnosticReport)
285299 DiagnosticReport dr = (DiagnosticReport ) resource ;
286300 String profileUrl = getProfileUrl (resource , v -> v .startsWith (NUM_CODEX_STRUCTURE_DEFINITION_PREFIX ));
287301
288- return "DiagnosticReport?_profile=" + profileUrl + "&date="
289- + dr .getEffectiveDateTimeType ().getValueAsString () + "&patient:identifier="
290- + ConstantsDataTransfer .NAMING_SYSTEM_NUM_CODEX_DIC_PSEUDONYM + "|" + pseudonym ;
302+ String updateUrl = getBaseConditionalUpdateUrl (ResourceType .DiagnosticReport .name (), profileUrl ,
303+ patientIdentifier );
304+
305+ if (dr .hasEffectiveDateTimeType () && dr .getEffectiveDateTimeType ().getValueAsString () != null )
306+ updateUrl = updateUrl + "&date=" + dr .getEffectiveDateTimeType ().getValueAsString ();
307+
308+ if (dr .hasCategory () && dr .getCategoryFirstRep ().hasCoding ())
309+ updateUrl = updateUrl + "&category=" + getCodingUpdateUrl (dr .getCategoryFirstRep ().getCodingFirstRep ());
310+
311+ if (dr .hasCode () && dr .getCode ().hasCoding ())
312+ updateUrl = updateUrl + "&code=" + getCodingUpdateUrl (dr .getCode ().getCodingFirstRep ());
313+
314+ return updateUrl ;
291315 }
292316 else if (resource instanceof Immunization )
293317 {
294318 Immunization i = (Immunization ) resource ;
295319 String profileUrl = getProfileUrl (resource , v -> v .startsWith (NUM_CODEX_STRUCTURE_DEFINITION_PREFIX ));
296320
297- return "Immunization?_profile=" + profileUrl + "&date=" + i .getOccurrenceDateTimeType ().getValueAsString ()
298- + "&patient:identifier=" + ConstantsDataTransfer .NAMING_SYSTEM_NUM_CODEX_DIC_PSEUDONYM + "|"
299- + pseudonym ;
321+ String updateUrl = getBaseConditionalUpdateUrl (ResourceType .Immunization .name (), profileUrl ,
322+ patientIdentifier );
323+
324+ if (i .hasOccurrenceDateTimeType () && i .getOccurrenceDateTimeType ().getValueAsString () != null )
325+ updateUrl = updateUrl + "&date=" + i .getOccurrenceDateTimeType ().getValueAsString ();
326+
327+ if (i .hasVaccineCode () && i .getVaccineCode ().hasCoding ())
328+ updateUrl = updateUrl + "&vaccine-code=" + i .getVaccineCode ().getCodingFirstRep ();
329+
330+ return updateUrl ;
300331 }
301332 else if (resource instanceof MedicationStatement )
302333 {
303334 MedicationStatement ms = (MedicationStatement ) resource ;
304335 String profileUrl = getProfileUrl (resource , v -> v .startsWith (NUM_CODEX_STRUCTURE_DEFINITION_PREFIX ));
305336
306- return "MedicationStatement?_profile=" + profileUrl + "&effective="
307- + ms .getEffectiveDateTimeType ().getValueAsString () + "&patient:identifier="
308- + ConstantsDataTransfer .NAMING_SYSTEM_NUM_CODEX_DIC_PSEUDONYM + "|" + pseudonym ;
309- }
337+ String updateUrl = getBaseConditionalUpdateUrl (ResourceType .MedicationStatement .name (), profileUrl ,
338+ patientIdentifier );
310339
340+ if (ms .hasEffectiveDateTimeType () && ms .getEffectiveDateTimeType ().getValueAsString () != null )
341+ updateUrl = updateUrl + "&effective=" + ms .getEffectiveDateTimeType ();
342+
343+ if (ms .hasMedicationCodeableConcept () && ms .getMedicationCodeableConcept ().hasCoding ())
344+ updateUrl = updateUrl + "&code="
345+ + getCodingUpdateUrl (ms .getMedicationCodeableConcept ().getCodingFirstRep ());
346+
347+ return updateUrl ;
348+ }
311349 else if (resource instanceof Observation )
312350 {
313351 Observation o = (Observation ) resource ;
314352 String profileUrl = getProfileUrl (resource , v -> v .startsWith (NUM_CODEX_STRUCTURE_DEFINITION_PREFIX )
315353 || MII_LAB_STRUCTURED_DEFINITION .equals (v ));
316354
317- if (MII_LAB_STRUCTURED_DEFINITION .equals (profileUrl ))
318- {
319- Coding loincCode = o .getCode ().getCoding ().stream ()
320- .filter (c -> "http://loinc.org" .equals (c .getSystem ())).findFirst ()
321- .orElseThrow (() -> new RuntimeException ("Observation (" + MII_LAB_STRUCTURED_DEFINITION
322- + ") not supported, missing LOINC code" ));
323-
324- return "Observation?_profile=" + profileUrl + "&date=" + o .getEffectiveDateTimeType ().getValueAsString ()
325- + "&code=" + loincCode .getSystem () + "|" + loincCode .getCode () + "&patient:identifier="
326- + ConstantsDataTransfer .NAMING_SYSTEM_NUM_CODEX_DIC_PSEUDONYM + "|" + pseudonym ;
327- }
328- else
329- {
330- return "Observation?_profile=" + profileUrl + "&date=" + o .getEffectiveDateTimeType ().getValueAsString ()
331- + "&patient:identifier=" + ConstantsDataTransfer .NAMING_SYSTEM_NUM_CODEX_DIC_PSEUDONYM + "|"
332- + pseudonym ;
333- }
355+ String updateUrl = getBaseConditionalUpdateUrl (ResourceType .Observation .name (), profileUrl ,
356+ patientIdentifier );
357+
358+ if (o .hasEffectiveDateTimeType () && o .getEffectiveDateTimeType ().getValueAsString () != null )
359+ updateUrl = updateUrl + "&date=" + o .getEffectiveDateTimeType ().getValueAsString ();
360+
361+ if (o .hasCategory () && o .getCategoryFirstRep ().hasCoding ())
362+ updateUrl = updateUrl + "&category=" + getCodingUpdateUrl (o .getCategoryFirstRep ().getCodingFirstRep ());
363+
364+ if (o .hasCode () && o .getCode ().hasCoding ())
365+ updateUrl = updateUrl + "&code=" + getCodingUpdateUrl (o .getCode ().getCodingFirstRep ());
366+
367+ return updateUrl ;
334368 }
335369 else if (resource instanceof Procedure )
336370 {
337371 Procedure p = (Procedure ) resource ;
338372 String profileUrl = getProfileUrl (resource , v -> v .startsWith (NUM_CODEX_STRUCTURE_DEFINITION_PREFIX ));
339373
340- return "Procedure?_profile=" + profileUrl + "&date=" + p .getPerformedDateTimeType ().getValueAsString ()
341- + "&patient:identifier=" + ConstantsDataTransfer .NAMING_SYSTEM_NUM_CODEX_DIC_PSEUDONYM + "|"
342- + pseudonym ;
374+ String updateUrl = getBaseConditionalUpdateUrl (ResourceType .Procedure .name (), profileUrl ,
375+ patientIdentifier );
376+
377+ if (p .hasPerformedDateTimeType () && p .getPerformedDateTimeType ().getValueAsString () != null )
378+ updateUrl = updateUrl + "&date=" + p .getPerformedDateTimeType ().getValueAsString ();
379+
380+ if (p .hasCategory () && p .getCategory ().hasCoding ())
381+ updateUrl = updateUrl + "&category=" + getCodingUpdateUrl (p .getCategory ().getCodingFirstRep ());
382+
383+ if (p .hasCode () && p .getCode ().hasCoding ())
384+ updateUrl = updateUrl + "&code=" + getCodingUpdateUrl (p .getCode ().getCodingFirstRep ());
385+
386+ return updateUrl ;
387+
343388 }
344389 else
345390 throw new RuntimeException ("Resource of type " + resource .getResourceType ().name () + " not supported" );
@@ -351,4 +396,14 @@ private String getProfileUrl(DomainResource resource, Predicate<String> filter)
351396 .orElseThrow (() -> new RuntimeException ("Resource of type " + resource .getResourceType ().name ()
352397 + " not supported, missing NUM or MII profile" ));
353398 }
399+
400+ private String getBaseConditionalUpdateUrl (String resourceName , String profileUrl , String patientIdentifier )
401+ {
402+ return resourceName + "?_profile=" + profileUrl + "&patient:identifier=" + patientIdentifier ;
403+ }
404+
405+ private String getCodingUpdateUrl (Coding coding )
406+ {
407+ return coding .getSystem () + "|" + coding .getCode ();
408+ }
354409}
0 commit comments