From ccfe10eb4d7b8e57795a1ff9f6c1b50885d32121 Mon Sep 17 00:00:00 2001 From: Lloyd McKenzie Date: Tue, 26 Mar 2019 16:51:06 -0600 Subject: [PATCH] Add support for both targetProfile and profile when converting to and from 2016May --- .../convertors/VersionConvertor_14_30.java | 26 +++++++++++++++---- .../convertors/VersionConvertor_14_40.java | 18 +++++++++++-- .../convertors/VersionConvertor_14_50.java | 18 +++++++++++-- 3 files changed, 53 insertions(+), 9 deletions(-) diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_14_30.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_14_30.java index a0bab4d06..888b1d4ab 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_14_30.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_14_30.java @@ -1422,8 +1422,14 @@ public class VersionConvertor_14_30 { copyElement(src, tgt); tgt.setCode(src.getCode()); for (org.hl7.fhir.dstu2016may.model.UriType t : src.getProfile()) { - if (src.hasTarget()) - tgt.setTargetProfile(t.getValueAsString()); + if (src.hasTarget()) { + // We don't have a good way to distinguish resources that have both 'profile' and 'targetProfile' when the type is reference, so the best we can do is by name. + String baseName = t.getValue().toLowerCase(); + if (baseName.contains("reference") && !baseName.contains("documentreference")) + tgt.setProfile(t.getValueAsString()); + else + tgt.setTargetProfile(t.getValueAsString()); + } else tgt.setProfile(t.getValueAsString()); } @@ -1439,9 +1445,19 @@ public class VersionConvertor_14_30 { org.hl7.fhir.dstu2016may.model.ElementDefinition.TypeRefComponent tgt = new org.hl7.fhir.dstu2016may.model.ElementDefinition.TypeRefComponent(); copyElement(src, tgt); tgt.setCode(src.getCode()); - if (src.hasTarget()) - tgt.addProfile(src.getTargetProfile()); - else + if (src.hasTarget()) { + if (src.hasTargetProfile()) { + tgt.addProfile(src.getTargetProfile()); + String baseName = src.getTargetProfile().toLowerCase(); + if (baseName.contains("reference") && !baseName.contains("documentreference")) + throw new Error("2016May Target profile contains the word 'reference':" + src.getTargetProfile()); + } + if (src.hasProfile()) { + tgt.addProfile(src.getProfile()); + if (!src.getProfile().toLowerCase().contains("reference")) + throw new Error("2016May profile doesn't contain the word 'reference':" + src.getTargetProfile()); + } + } else tgt.addProfile(src.getProfile()); for (org.hl7.fhir.dstu3.model.Enumeration t : src.getAggregation()) tgt.addAggregation(convertAggregationMode(t.getValue())); diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_14_40.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_14_40.java index 9def5bf09..a98211989 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_14_40.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_14_40.java @@ -1505,8 +1505,14 @@ public class VersionConvertor_14_40 { tgt.setCode(src.getCode()); } if (tgt.hasTarget()) { - for (org.hl7.fhir.dstu2016may.model.UriType u : src.getProfile()) - tgt.addTargetProfile(u.getValue()); + for (org.hl7.fhir.dstu2016may.model.UriType u : src.getProfile()) { + // We don't have a good way to distinguish resources that have both 'profile' and 'targetProfile' when the type is reference, so the best we can do is by name. + String baseName = u.getValue().toLowerCase(); + if (baseName.contains("reference") && !baseName.contains("documentreference")) + tgt.addProfile(u.getValue()); + else + tgt.addTargetProfile(u.getValue()); + } } else { for (org.hl7.fhir.dstu2016may.model.UriType u : src.getProfile()) tgt.addProfile(u.getValue()); @@ -1530,6 +1536,14 @@ public class VersionConvertor_14_40 { if (src.hasTarget()) { for (org.hl7.fhir.r4.model.UriType u : src.getTargetProfile()) { tgt.addProfile(u.getValue()); + String baseName = u.getValue().toLowerCase(); + if (baseName.contains("reference") && !baseName.contains("documentreference")) + throw new Error("2016May Target profile contains the word 'reference':" + u); + } + for (org.hl7.fhir.r4.model.UriType u : src.getProfile()) { + tgt.addProfile(u.getValue()); + if (!u.toString().toLowerCase().contains("reference")) + throw new Error("2016May profile doesn't contain the word 'reference':" + u); } } else { for (org.hl7.fhir.r4.model.UriType u : src.getProfile()) { diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_14_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_14_50.java index 27e699be4..68ed7d531 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_14_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_14_50.java @@ -1505,8 +1505,14 @@ public class VersionConvertor_14_50 { tgt.setCode(src.getCode()); } if (tgt.hasTarget()) { - for (org.hl7.fhir.dstu2016may.model.UriType u : src.getProfile()) - tgt.addTargetProfile(u.getValue()); + for (org.hl7.fhir.dstu2016may.model.UriType u : src.getProfile()) { + // We don't have a good way to distinguish resources that have both 'profile' and 'targetProfile' when the type is reference, so the best we can do is by name. + String baseName = u.getValue().toLowerCase(); + if (baseName.contains("reference") && !baseName.contains("documentreference")) + tgt.addProfile(u.getValue()); + else + tgt.addTargetProfile(u.getValue()); + } } else { for (org.hl7.fhir.dstu2016may.model.UriType u : src.getProfile()) tgt.addProfile(u.getValue()); @@ -1530,6 +1536,14 @@ public class VersionConvertor_14_50 { if (src.hasTarget()) { for (org.hl7.fhir.r5.model.UriType u : src.getTargetProfile()) { tgt.addProfile(u.getValue()); + String baseName = u.getValue().toLowerCase(); + if (baseName.contains("reference") && !baseName.contains("documentreference")) + throw new Error("2016May Target profile contains the word 'reference':" + u); + } + for (org.hl7.fhir.r5.model.UriType u : src.getProfile()) { + tgt.addProfile(u.getValue()); + if (!u.toString().toLowerCase().contains("reference")) + throw new Error("2016May profile doesn't contain the word 'reference':" + u); } } else { for (org.hl7.fhir.r5.model.UriType u : src.getProfile()) {