From 6a7435787f4c1c1b2434209fb60955f40fe7c9b9 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Wed, 5 May 2021 08:28:03 +1000 Subject: [PATCH 1/5] tidy up and document version conversion advisors --- .../convertors/VersionConvertorAdvisor30.java | 48 +++++++++++++++-- .../convertors/VersionConvertorAdvisor40.java | 51 ++++++++++++++++--- .../convertors/VersionConvertorAdvisor50.java | 39 +++++++++++--- .../convertors/conv10_30/Bundle10_30.java | 4 +- .../convertors/conv10_40/Bundle10_40.java | 4 +- .../convertors/conv10_50/Bundle10_50.java | 4 +- .../loaders/R2016MayToR4Loader.java | 15 ------ .../loaders/R2016MayToR5Loader.java | 21 -------- .../fhir/convertors/loaders/R2ToR3Loader.java | 4 -- .../fhir/convertors/loaders/R2ToR4Loader.java | 14 ----- .../fhir/convertors/loaders/R2ToR5Loader.java | 19 ------- .../fhir/convertors/loaders/R3ToR4Loader.java | 14 ----- .../fhir/convertors/loaders/R3ToR5Loader.java | 20 -------- .../fhir/convertors/loaders/R4ToR5Loader.java | 20 -------- .../fhir/convertors/loaders/R5ToR5Loader.java | 20 -------- .../convertors/misc/IGPackConverter102.java | 4 -- .../convertors/misc/IGR2ConvertorAdvisor.java | 13 ----- .../misc/IGR2ConvertorAdvisor5.java | 20 -------- .../misc/NpmPackageVersionConverter.java | 14 ----- .../fhir/validation/NativeHostServices.java | 21 -------- 20 files changed, 124 insertions(+), 245 deletions(-) diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertorAdvisor30.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertorAdvisor30.java index d43a785f1..cc7eb0da6 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertorAdvisor30.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertorAdvisor30.java @@ -33,14 +33,54 @@ package org.hl7.fhir.convertors; import org.hl7.fhir.exceptions.FHIRException; +/** + * This interface is passed into the version conversion routines when on of the + * converters is producing or converting R3 resources. + * + * The interface allows users of the code to + * 1. manage the life cycle of new resources created (or needed) during the conversion process + * 2. manage how unknown content etc is handled + * + * @author grahame + * + */ public interface VersionConvertorAdvisor30 { + + /** + * when processing a bundle, and converting from R3 to R2 whether to ignore an entry in the bundle. + * typically, return true when it's a resource that isn't handled, and you don't care. + * + * by default, always return false unless you know why not do this + * + * todo: why only R2? generalise this to all targets + * + * @param src + * @return + */ boolean ignoreEntry(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent src); - // called ? - org.hl7.fhir.dstu2.model.Resource convert(org.hl7.fhir.dstu3.model.Resource resource) throws FHIRException; - - // called when an r2 value set has a codeSystem in it + /** + * In R2, code systems are internal to value sets, but in subsequent versions, they + * exist as separate resources. The convertor will create the code system, and then + * call this routine for the host to decide what to do with it + * + * It can make it a contained resource, or it can put it somewhere else + * + * @param tgtcs + * @param source + * @throws FHIRException + */ void handleCodeSystem(org.hl7.fhir.dstu3.model.CodeSystem tgtcs, org.hl7.fhir.dstu3.model.ValueSet source) throws FHIRException; + /** + * when converting from R3 to R2, and converting a value set, the convertor will need + * to find the code system a value set is referring to, so it can include it inline. + * + * This routine should find the actual resource + * + * @param src + * @return + * @throws FHIRException + */ org.hl7.fhir.dstu3.model.CodeSystem getCodeSystem(org.hl7.fhir.dstu3.model.ValueSet src) throws FHIRException; } \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertorAdvisor40.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertorAdvisor40.java index 0f6e2cae4..7a5774be8 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertorAdvisor40.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertorAdvisor40.java @@ -33,16 +33,55 @@ package org.hl7.fhir.convertors; import org.hl7.fhir.exceptions.FHIRException; + +/** + * This interface is passed into the version conversion routines when on of the + * converters is producing or converting R4 resources. + * + * The interface allows users of the code to + * 1. manage the life cycle of new resources created (or needed) during the conversion process + * 2. manage how unknown content etc is handled + * + * @author grahame + * + */ public interface VersionConvertorAdvisor40 { + + /** + * when processing a bundle, and converting from R4 to R2 whether to ignore an entry in the bundle. + * typically, return true when it's a resource that isn't handled, and you don't care. + * + * by default, always return false unless you know why not do this + * + * todo: why only R2? generalise this to all targets + * + * @param src + * @return + */ boolean ignoreEntry(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent src); - // called ? - org.hl7.fhir.dstu2.model.Resource convertR2(org.hl7.fhir.r4.model.Resource resource) throws FHIRException; - org.hl7.fhir.dstu2016may.model.Resource convertR2016May(org.hl7.fhir.r4.model.Resource resource) throws FHIRException; - org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r4.model.Resource resource) throws FHIRException; - - // called when an r2 value set has a codeSystem in it + /** + * In R2, code systems are internal to value sets, but in subsequent versions, they + * exist as separate resources. The convertor will create the code system, and then + * call this routine for the host to decide what to do with it + * + * It can make it a contained resource, or it can put it somewhere else + * + * @param tgtcs + * @param source + * @throws FHIRException + */ void handleCodeSystem(org.hl7.fhir.r4.model.CodeSystem tgtcs, org.hl7.fhir.r4.model.ValueSet source) throws FHIRException; + /** + * when converting from R4 to R2, and converting a value set, the convertor will need + * to find the code system a value set is referring to, so it can include it inline. + * + * This routine should find the actual resource + * + * @param src + * @return + * @throws FHIRException + */ org.hl7.fhir.r4.model.CodeSystem getCodeSystem(org.hl7.fhir.r4.model.ValueSet src) throws FHIRException; } \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertorAdvisor50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertorAdvisor50.java index 0c697173a..25072549d 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertorAdvisor50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertorAdvisor50.java @@ -34,16 +34,41 @@ package org.hl7.fhir.convertors; import org.hl7.fhir.exceptions.FHIRException; public interface VersionConvertorAdvisor50 { + /** + * when processing a bundle, and converting from R5 to R2 whether to ignore an entry in the bundle. + * typically, return true when it's a resource that isn't handled, and you don't care. + * + * by default, always return false unless you know why not do this + * + * todo: why only R2? generalise this to all targets + * + * @param src + * @return + */ boolean ignoreEntry(org.hl7.fhir.r5.model.Bundle.BundleEntryComponent src); - // called ? - org.hl7.fhir.dstu2.model.Resource convertR2(org.hl7.fhir.r5.model.Resource resource) throws FHIRException; - org.hl7.fhir.dstu2016may.model.Resource convertR2016May(org.hl7.fhir.r5.model.Resource resource) throws FHIRException; - org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r5.model.Resource resource) throws FHIRException; - org.hl7.fhir.r4.model.Resource convertR4(org.hl7.fhir.r5.model.Resource resource) throws FHIRException; - - // called when an r2 value set has a codeSystem in it + /** + * In R2, code systems are internal to value sets, but in subsequent versions, they + * exist as separate resources. The convertor will create the code system, and then + * call this routine for the host to decide what to do with it + * + * It can make it a contained resource, or it can put it somewhere else + * + * @param tgtcs + * @param source + * @throws FHIRException + */ void handleCodeSystem(org.hl7.fhir.r5.model.CodeSystem tgtcs, org.hl7.fhir.r5.model.ValueSet source) throws FHIRException; + /** + * when converting from R5 to R2, and converting a value set, the convertor will need + * to find the code system a value set is referring to, so it can include it inline. + * + * This routine should find the actual resource + * + * @param src + * @return + * @throws FHIRException + */ org.hl7.fhir.r5.model.CodeSystem getCodeSystem(org.hl7.fhir.r5.model.ValueSet src) throws FHIRException; } \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_30/Bundle10_30.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_30/Bundle10_30.java index 6ad1c12a9..23fb51626 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_30/Bundle10_30.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_30/Bundle10_30.java @@ -52,9 +52,7 @@ public class Bundle10_30 { for (org.hl7.fhir.dstu3.model.Bundle.BundleLinkComponent t : src.getLink()) tgt.addLink(convertBundleLinkComponent(t)); if (src.hasFullUrlElement()) tgt.setFullUrlElement(VersionConvertor_10_30.convertUri(src.getFullUrlElement())); - org.hl7.fhir.dstu2.model.Resource res = advisor.convert(src.getResource()); - if (res == null) - res = VersionConvertor_10_30.convertResource(src.getResource()); + org.hl7.fhir.dstu2.model.Resource res = VersionConvertor_10_30.convertResource(src.getResource()); tgt.setResource(res); if (src.hasSearch()) tgt.setSearch(convertBundleEntrySearchComponent(src.getSearch())); diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_40/Bundle10_40.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_40/Bundle10_40.java index 35b7a9d56..4e413e43d 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_40/Bundle10_40.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_40/Bundle10_40.java @@ -71,9 +71,7 @@ public class Bundle10_40 { for (org.hl7.fhir.r4.model.Bundle.BundleLinkComponent t : src.getLink()) tgt.addLink(convertBundleLinkComponent(t)); if (src.hasFullUrlElement()) tgt.setFullUrlElement(VersionConvertor_10_40.convertUri(src.getFullUrlElement())); - org.hl7.fhir.dstu2.model.Resource res = advisor.convertR2(src.getResource()); - if (res == null) - res = VersionConvertor_10_40.convertResource(src.getResource()); + org.hl7.fhir.dstu2.model.Resource res = VersionConvertor_10_40.convertResource(src.getResource()); tgt.setResource(res); if (src.hasSearch()) tgt.setSearch(convertBundleEntrySearchComponent(src.getSearch())); diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_50/Bundle10_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_50/Bundle10_50.java index 13a80b9d2..df8de9f2c 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_50/Bundle10_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_50/Bundle10_50.java @@ -71,9 +71,7 @@ public class Bundle10_50 { for (org.hl7.fhir.r5.model.Bundle.BundleLinkComponent t : src.getLink()) tgt.addLink(convertBundleLinkComponent(t)); if (src.hasFullUrlElement()) tgt.setFullUrlElement(VersionConvertor_10_50.convertUri(src.getFullUrlElement())); - org.hl7.fhir.dstu2.model.Resource res = advisor.convertR2(src.getResource()); - if (res == null) - res = VersionConvertor_10_50.convertResource(src.getResource()); + org.hl7.fhir.dstu2.model.Resource res = VersionConvertor_10_50.convertResource(src.getResource()); tgt.setResource(res); if (src.hasSearch()) tgt.setSearch(convertBundleEntrySearchComponent(src.getSearch())); diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R2016MayToR4Loader.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R2016MayToR4Loader.java index 94249ead4..0e8eac879 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R2016MayToR4Loader.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R2016MayToR4Loader.java @@ -116,21 +116,6 @@ public class R2016MayToR4Loader extends BaseLoaderR4 implements IContextResource return false; } - @Override - public org.hl7.fhir.dstu2.model.Resource convertR2(org.hl7.fhir.r4.model.Resource resource) throws FHIRException { - return null; - } - - @Override - public Resource convertR2016May(org.hl7.fhir.r4.model.Resource resource) throws FHIRException { - return null; - } - - @Override - public org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r4.model.Resource resource) throws FHIRException { - return null; - } - @Override public void handleCodeSystem(CodeSystem cs, ValueSet vs) { cs.setId(vs.getId()); diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R2016MayToR5Loader.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R2016MayToR5Loader.java index 4aa7b132a..90ef54953 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R2016MayToR5Loader.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R2016MayToR5Loader.java @@ -163,21 +163,6 @@ public class R2016MayToR5Loader extends BaseLoaderR5 implements VersionConvertor return false; } - @Override - public org.hl7.fhir.dstu2.model.Resource convertR2(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - - @Override - public Resource convertR2016May(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - - @Override - public org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - @Override public void handleCodeSystem(CodeSystem cs, ValueSet vs) { cs.setId(vs.getId()); @@ -191,11 +176,5 @@ public class R2016MayToR5Loader extends BaseLoaderR5 implements VersionConvertor return null; } - @Override - public org.hl7.fhir.r4.model.Resource convertR4(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - - } \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R2ToR3Loader.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R2ToR3Loader.java index 1bed6644a..33ef1d454 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R2ToR3Loader.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R2ToR3Loader.java @@ -113,10 +113,6 @@ public class R2ToR3Loader extends BaseLoaderR3 implements VersionConvertorAdviso return false; } - @Override - public Resource convert(org.hl7.fhir.dstu3.model.Resource resource) throws FHIRException { - return null; - } @Override public void handleCodeSystem(CodeSystem cs, ValueSet vs) { diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R2ToR4Loader.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R2ToR4Loader.java index 941acbd4b..40ec42877 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R2ToR4Loader.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R2ToR4Loader.java @@ -115,20 +115,6 @@ public class R2ToR4Loader extends BaseLoaderR4 implements VersionConvertorAdviso return false; } - @Override - public Resource convertR2(org.hl7.fhir.r4.model.Resource resource) throws FHIRException { - return null; - } - - @Override - public org.hl7.fhir.dstu2016may.model.Resource convertR2016May(org.hl7.fhir.r4.model.Resource resource) throws FHIRException { - return null; - } - - public org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r4.model.Resource resource) throws FHIRException { - return null; - } - @Override public void handleCodeSystem(CodeSystem cs, ValueSet vs) { cs.setId(vs.getId()); diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R2ToR5Loader.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R2ToR5Loader.java index 07f64c869..91f69b4e2 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R2ToR5Loader.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R2ToR5Loader.java @@ -163,20 +163,6 @@ public class R2ToR5Loader extends BaseLoaderR5 implements IContextResourceLoader return false; } - @Override - public Resource convertR2(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - - @Override - public org.hl7.fhir.dstu2016may.model.Resource convertR2016May(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - - public org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - @Override public void handleCodeSystem(CodeSystem cs, ValueSet vs) { cs.setId(vs.getId()); @@ -190,10 +176,5 @@ public class R2ToR5Loader extends BaseLoaderR5 implements IContextResourceLoader return null; } - @Override - public org.hl7.fhir.r4.model.Resource convertR4(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - } \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R3ToR4Loader.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R3ToR4Loader.java index 0691b1fe6..46ae2d6da 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R3ToR4Loader.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R3ToR4Loader.java @@ -125,20 +125,6 @@ public class R3ToR4Loader extends BaseLoaderR4 implements IContextResourceLoader return false; } - @Override - public org.hl7.fhir.dstu2.model.Resource convertR2(org.hl7.fhir.r4.model.Resource resource) throws FHIRException { - return null; - } - - @Override - public org.hl7.fhir.dstu2016may.model.Resource convertR2016May(org.hl7.fhir.r4.model.Resource resource) throws FHIRException { - return null; - } - - @Override - public Resource convertR3(org.hl7.fhir.r4.model.Resource resource) throws FHIRException { - return null; - } @Override public void handleCodeSystem(CodeSystem cs, ValueSet vs) { diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R3ToR5Loader.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R3ToR5Loader.java index 07feac9ab..e08f45a33 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R3ToR5Loader.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R3ToR5Loader.java @@ -166,21 +166,6 @@ public class R3ToR5Loader extends BaseLoaderR5 implements IContextResourceLoader return false; } - @Override - public org.hl7.fhir.dstu2.model.Resource convertR2(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - - @Override - public org.hl7.fhir.dstu2016may.model.Resource convertR2016May(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - - @Override - public Resource convertR3(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - @Override public void handleCodeSystem(CodeSystem cs, ValueSet vs) { cs.setId(vs.getId()); @@ -194,9 +179,4 @@ public class R3ToR5Loader extends BaseLoaderR5 implements IContextResourceLoader return null; } - @Override - public org.hl7.fhir.r4.model.Resource convertR4(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - } \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R4ToR5Loader.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R4ToR5Loader.java index fa8af1b5f..3f9001daf 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R4ToR5Loader.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R4ToR5Loader.java @@ -166,21 +166,6 @@ public class R4ToR5Loader extends BaseLoaderR5 implements IContextResourceLoader return false; } - @Override - public org.hl7.fhir.dstu2.model.Resource convertR2(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - - @Override - public org.hl7.fhir.dstu2016may.model.Resource convertR2016May(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - - @Override - public Resource convertR4(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - @Override public void handleCodeSystem(CodeSystem cs, ValueSet vs) { cs.setId(vs.getId()); @@ -194,9 +179,4 @@ public class R4ToR5Loader extends BaseLoaderR5 implements IContextResourceLoader return null; } - @Override - public org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - } \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R5ToR5Loader.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R5ToR5Loader.java index a71cb3705..1046b11e4 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R5ToR5Loader.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/R5ToR5Loader.java @@ -163,21 +163,6 @@ public class R5ToR5Loader extends BaseLoaderR5 implements VersionConvertorAdviso return false; } - @Override - public org.hl7.fhir.dstu2.model.Resource convertR2(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - - @Override - public org.hl7.fhir.dstu2016may.model.Resource convertR2016May(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - - @Override - public org.hl7.fhir.r4.model.Resource convertR4(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - @Override public void handleCodeSystem(CodeSystem cs, ValueSet vs) { cs.setId(vs.getId()); @@ -191,9 +176,4 @@ public class R5ToR5Loader extends BaseLoaderR5 implements VersionConvertorAdviso return null; } - @Override - public org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - } \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/IGPackConverter102.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/IGPackConverter102.java index 32cedac2d..385545f4b 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/IGPackConverter102.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/IGPackConverter102.java @@ -89,10 +89,6 @@ public class IGPackConverter102 implements VersionConvertorAdvisor30 { return false; } - @Override - public Resource convert(org.hl7.fhir.dstu3.model.Resource resource) throws FHIRException { - return null; - } @Override public void handleCodeSystem(CodeSystem tgtcs, ValueSet vs) { diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/IGR2ConvertorAdvisor.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/IGR2ConvertorAdvisor.java index ceac2feae..b2fe5bfa9 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/IGR2ConvertorAdvisor.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/IGR2ConvertorAdvisor.java @@ -46,20 +46,7 @@ public class IGR2ConvertorAdvisor implements VersionConvertorAdvisor40 { return false; } - @Override - public Resource convertR2(org.hl7.fhir.r4.model.Resource resource) throws FHIRException { - return null; - } - @Override - public org.hl7.fhir.dstu2016may.model.Resource convertR2016May(org.hl7.fhir.r4.model.Resource resource) throws FHIRException { - return null; - } - - @Override - public org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r4.model.Resource resource) throws FHIRException { - return null; - } @Override public void handleCodeSystem(CodeSystem cs, ValueSet vs) { diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/IGR2ConvertorAdvisor5.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/IGR2ConvertorAdvisor5.java index 132c2bcbe..20ae18af3 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/IGR2ConvertorAdvisor5.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/IGR2ConvertorAdvisor5.java @@ -46,21 +46,6 @@ public class IGR2ConvertorAdvisor5 implements VersionConvertorAdvisor50 { return false; } - @Override - public Resource convertR2(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - - @Override - public org.hl7.fhir.dstu2016may.model.Resource convertR2016May(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - - @Override - public org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - @Override public void handleCodeSystem(CodeSystem cs, ValueSet vs) { cs.setId(vs.getId()); @@ -71,9 +56,4 @@ public class IGR2ConvertorAdvisor5 implements VersionConvertorAdvisor50 { return null; } - @Override - public org.hl7.fhir.r4.model.Resource convertR4(org.hl7.fhir.r5.model.Resource resource) throws FHIRException { - return null; - } - } \ No newline at end of file diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/NpmPackageVersionConverter.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/NpmPackageVersionConverter.java index 4f63e27fa..72282bd65 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/NpmPackageVersionConverter.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/NpmPackageVersionConverter.java @@ -50,20 +50,6 @@ public class NpmPackageVersionConverter { return false; } - @Override - public Resource convertR2(org.hl7.fhir.r4.model.Resource resource) throws FHIRException { - throw new Error("Not done yet"); - } - - @Override - public org.hl7.fhir.dstu2016may.model.Resource convertR2016May(org.hl7.fhir.r4.model.Resource resource) throws FHIRException { - throw new Error("Not done yet"); - } - - @Override - public org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r4.model.Resource resource) throws FHIRException { - throw new Error("Not done yet"); - } @Override public void handleCodeSystem(CodeSystem tgtcs, ValueSet source) throws FHIRException { diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/NativeHostServices.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/NativeHostServices.java index 00b5cb9db..f54d8d2a7 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/NativeHostServices.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/NativeHostServices.java @@ -108,21 +108,6 @@ public class NativeHostServices { return false; } - @Override - public org.hl7.fhir.dstu2016may.model.Resource convertR2016May(Resource resource) throws FHIRException { - return null; - } - - @Override - public org.hl7.fhir.dstu2.model.Resource convertR2(Resource resource) throws FHIRException { - return null; - } - - @Override - public org.hl7.fhir.dstu3.model.Resource convertR3(Resource resource) throws FHIRException { - return null; - } - @Override public void handleCodeSystem(CodeSystem tgtcs, ValueSet source) throws FHIRException { } @@ -132,12 +117,6 @@ public class NativeHostServices { throw new FHIRException("Code systems cannot be handled at this time"); // what to do? need thread local storage? } - @Override - public org.hl7.fhir.r4.model.Resource convertR4(Resource resource) throws FHIRException { - // still to do - return null; - } - } private ValidationEngine validator; From 9ae04aed0350f89fa9500d98b971184fcf227aaf Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Wed, 5 May 2021 08:51:36 +1000 Subject: [PATCH 2/5] Fix compartment definitions of ListResource.source and subject for R3 and R4 --- RELEASE_NOTES.md | 1 + .../java/org/hl7/fhir/dstu3/model/ListResource.java | 10 ++++++++-- .../main/java/org/hl7/fhir/r4/model/ListResource.java | 10 ++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 0349c382b..fd5721d20 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1 +1,2 @@ * Update core R5 code to v4.6.0 (breaking changes to questionnaire, concept map, and other resources that are less important to core) +* Fix compartment definitions of ListResource.source and subject for R3 and R4 diff --git a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/ListResource.java b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/ListResource.java index 3a48c081a..ed04b1bc3 100644 --- a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/ListResource.java +++ b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/ListResource.java @@ -38,6 +38,12 @@ import java.util.List; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.instance.model.api.IBaseBackboneElement; +import org.hl7.fhir.r5.model.Device; +import org.hl7.fhir.r5.model.Group; +import org.hl7.fhir.r5.model.Location; +import org.hl7.fhir.r5.model.Patient; +import org.hl7.fhir.r5.model.Practitioner; +import org.hl7.fhir.r5.model.PractitionerRole; import org.hl7.fhir.utilities.Utilities; import ca.uhn.fhir.model.api.annotation.Block; @@ -1755,7 +1761,7 @@ public class ListResource extends DomainResource { * Path: List.subject
*

*/ - @SearchParamDefinition(name="subject", path="List.subject", description="If all resources have the same subject", type="reference", target={Device.class, Group.class, Location.class, Patient.class } ) + @SearchParamDefinition(name="subject", path="List.subject", description="If all resources have the same subject", type="reference", providesMembershipIn={ @ca.uhn.fhir.model.api.annotation.Compartment(name="Base FHIR compartment definition for Device"), @ca.uhn.fhir.model.api.annotation.Compartment(name="Base FHIR compartment definition for Patient") }, target={Device.class, Group.class, Location.class, Patient.class } ) public static final String SP_SUBJECT = "subject"; /** * Fluent Client search parameter constant for subject @@ -1807,7 +1813,7 @@ public class ListResource extends DomainResource { * Path: List.source
*

*/ - @SearchParamDefinition(name="source", path="List.source", description="Who and/or what defined the list contents (aka Author)", type="reference", target={Device.class, Patient.class, Practitioner.class } ) + @SearchParamDefinition(name="source", path="List.source", description="Who and/or what defined the list contents (aka Author)", type="reference", providesMembershipIn={ @ca.uhn.fhir.model.api.annotation.Compartment(name="Base FHIR compartment definition for Device"), @ca.uhn.fhir.model.api.annotation.Compartment(name="Base FHIR compartment definition for Patient"), @ca.uhn.fhir.model.api.annotation.Compartment(name="Base FHIR compartment definition for Practitioner") }, target={Device.class, Patient.class, Practitioner.class } ) public static final String SP_SOURCE = "source"; /** * Fluent Client search parameter constant for source diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ListResource.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ListResource.java index 120414399..b9169c401 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ListResource.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ListResource.java @@ -44,6 +44,12 @@ import ca.uhn.fhir.model.api.annotation.ChildOrder; import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.model.api.annotation.Block; import org.hl7.fhir.instance.model.api.*; +import org.hl7.fhir.r5.model.Device; +import org.hl7.fhir.r5.model.Group; +import org.hl7.fhir.r5.model.Location; +import org.hl7.fhir.r5.model.Patient; +import org.hl7.fhir.r5.model.Practitioner; +import org.hl7.fhir.r5.model.PractitionerRole; import org.hl7.fhir.exceptions.FHIRException; /** * A list is a curated collection of resources. @@ -1763,7 +1769,7 @@ public class ListResource extends DomainResource { * Path: List.subject
*

*/ - @SearchParamDefinition(name="subject", path="List.subject", description="If all resources have the same subject", type="reference", target={Device.class, Group.class, Location.class, Patient.class } ) + @SearchParamDefinition(name="subject", path="List.subject", description="If all resources have the same subject", type="reference", providesMembershipIn={ @ca.uhn.fhir.model.api.annotation.Compartment(name="Base FHIR compartment definition for Device"), @ca.uhn.fhir.model.api.annotation.Compartment(name="Base FHIR compartment definition for Patient") }, target={Device.class, Group.class, Location.class, Patient.class } ) public static final String SP_SUBJECT = "subject"; /** * Fluent Client search parameter constant for subject @@ -1815,7 +1821,7 @@ public class ListResource extends DomainResource { * Path: List.source
*

*/ - @SearchParamDefinition(name="source", path="List.source", description="Who and/or what defined the list contents (aka Author)", type="reference", target={Device.class, Patient.class, Practitioner.class, PractitionerRole.class } ) + @SearchParamDefinition(name="source", path="List.source", description="Who and/or what defined the list contents (aka Author)", type="reference", providesMembershipIn={ @ca.uhn.fhir.model.api.annotation.Compartment(name="Base FHIR compartment definition for Device"), @ca.uhn.fhir.model.api.annotation.Compartment(name="Base FHIR compartment definition for Patient"), @ca.uhn.fhir.model.api.annotation.Compartment(name="Base FHIR compartment definition for Practitioner") }, target={Device.class, Patient.class, Practitioner.class, PractitionerRole.class } ) public static final String SP_SOURCE = "source"; /** * Fluent Client search parameter constant for source From c6f392b7e03d2d54cbec83c81814ada6b6e42237 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Wed, 5 May 2021 09:54:22 +1000 Subject: [PATCH 3/5] #466: fix problem checking types on logical models --- .../hl7/fhir/dstu3/model/ListResource.java | 6 ---- .../org/hl7/fhir/r4/model/ListResource.java | 6 ---- .../fhir/r5/conformance/ProfileUtilities.java | 28 +++++++++++++++++-- .../hl7/fhir/validation/ValidationEngine.java | 4 +-- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/ListResource.java b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/ListResource.java index ed04b1bc3..4203569c2 100644 --- a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/ListResource.java +++ b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/ListResource.java @@ -38,12 +38,6 @@ import java.util.List; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.instance.model.api.IBaseBackboneElement; -import org.hl7.fhir.r5.model.Device; -import org.hl7.fhir.r5.model.Group; -import org.hl7.fhir.r5.model.Location; -import org.hl7.fhir.r5.model.Patient; -import org.hl7.fhir.r5.model.Practitioner; -import org.hl7.fhir.r5.model.PractitionerRole; import org.hl7.fhir.utilities.Utilities; import ca.uhn.fhir.model.api.annotation.Block; diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ListResource.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ListResource.java index b9169c401..190a18c59 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ListResource.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ListResource.java @@ -44,12 +44,6 @@ import ca.uhn.fhir.model.api.annotation.ChildOrder; import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.model.api.annotation.Block; import org.hl7.fhir.instance.model.api.*; -import org.hl7.fhir.r5.model.Device; -import org.hl7.fhir.r5.model.Group; -import org.hl7.fhir.r5.model.Location; -import org.hl7.fhir.r5.model.Patient; -import org.hl7.fhir.r5.model.Practitioner; -import org.hl7.fhir.r5.model.PractitionerRole; import org.hl7.fhir.exceptions.FHIRException; /** * A list is a curated collection of resources. diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java index 88489aa6c..51d763a71 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java @@ -609,7 +609,8 @@ public class ProfileUtilities extends TranslatingUtilities { derived.setSnapshot(new StructureDefinitionSnapshotComponent()); try { - checkDifferential(derived.getDifferential().getElement(), derived.getType(), derived.getUrl()); + checkDifferential(derived.getDifferential().getElement(), typeName(derived.getType()), derived.getUrl()); + checkDifferentialBaseType(derived); // so we have two lists - the base list, and the differential list // the differential list is only allowed to include things that are in the base list, but @@ -620,8 +621,6 @@ public class ProfileUtilities extends TranslatingUtilities { int baseCursor = 0; int diffCursor = 0; // we need a diff cursor because we can only look ahead, in the bound scoped by longer paths - if (derived.hasDifferential() && !derived.getDifferential().getElementFirstRep().getPath().contains(".") && !derived.getDifferential().getElementFirstRep().getType().isEmpty()) - throw new Error(context.formatMessage(I18nConstants.TYPE_ON_FIRST_DIFFERENTIAL_ELEMENT)); for (ElementDefinition e : derived.getDifferential().getElement()) e.clearUserData(GENERATED_IN_SNAPSHOT); @@ -771,6 +770,29 @@ public class ProfileUtilities extends TranslatingUtilities { derived.clearUserData("profileutils.snapshot.generating"); } + public void checkDifferentialBaseType(StructureDefinition derived) throws Error { + if (derived.hasDifferential() && !derived.getDifferential().getElementFirstRep().getPath().contains(".") && !derived.getDifferential().getElementFirstRep().getType().isEmpty()) { + if (typeMatchesAncestor(derived.getDifferential().getElementFirstRep().getType(), derived.getBaseDefinition())) { + derived.getDifferential().getElementFirstRep().getType().clear(); + } else { + throw new Error(context.formatMessage(I18nConstants.TYPE_ON_FIRST_DIFFERENTIAL_ELEMENT)); + } + } + } + + private boolean typeMatchesAncestor(List type, String baseDefinition) { + StructureDefinition sd = context.fetchResource(StructureDefinition.class, baseDefinition); + return sd != null && type.size() == 1 && sd.getType().equals(type.get(0).getCode()); + } + + private String typeName(String type) { + if (Utilities.isAbsoluteUrl(type)) { + return type.substring(type.lastIndexOf("/")+1); + } else { + return type; + } + } + private void checkGroupConstraints(StructureDefinition derived) { List toRemove = new ArrayList<>(); // List processed = new ArrayList<>(); diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java index 7e71fa3d6..ae3bc199c 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java @@ -485,9 +485,9 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst makeSnapshot(sd); } catch (Exception e) { System.out.println("Process Note: Unable to generate snapshot for " + sd.present() + ": " + e.getMessage()); - if (debug) { +// if (debug) { e.printStackTrace(); - } +// } } } } From 6da83fa41e92ef8c2016cab6ed8a73a381cdb490 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Wed, 5 May 2021 10:17:08 +1000 Subject: [PATCH 4/5] Do not flag internal references as suspicious --- RELEASE_NOTES.md | 2 ++ .../org/hl7/fhir/validation/instance/InstanceValidator.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index fd5721d20..879cbc5bd 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,2 +1,4 @@ * Update core R5 code to v4.6.0 (breaking changes to questionnaire, concept map, and other resources that are less important to core) * Fix compartment definitions of ListResource.source and subject for R3 and R4 +* Snapshot generator: fix problem checking types on logical models +* Do not flag internal references as suspicious diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java index 7fb09409f..a20839f05 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java @@ -2757,7 +2757,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat } private boolean isSuspiciousReference(String url) { - if (!assumeValidRestReferences || url == null || Utilities.isAbsoluteUrl(url)) { + if (!assumeValidRestReferences || url == null || Utilities.isAbsoluteUrl(url) || url.startsWith("#")) { return false; } String[] parts = url.split("\\/"); From b13b4932f92de66e67134ae653871586d76ec0dd Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Wed, 5 May 2021 12:17:02 +1000 Subject: [PATCH 5/5] XMLParser allows passing a schema location --- RELEASE_NOTES.md | 1 + .../fhir/r5/conformance/ProfileUtilities.java | 13 +++++++-- .../hl7/fhir/r5/elementmodel/XmlParser.java | 13 +++++++++ .../hl7/fhir/r5/formats/XmlParserBase.java | 16 +++++++++-- .../org/hl7/fhir/r5/test/ResourceTests.java | 28 +++++++++++++++++++ .../hl7/fhir/utilities/xml/IXMLWriter.java | 1 + .../org/hl7/fhir/utilities/xml/XMLWriter.java | 6 ++++ 7 files changed, 73 insertions(+), 5 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 879cbc5bd..b47a784c6 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -2,3 +2,4 @@ * Fix compartment definitions of ListResource.source and subject for R3 and R4 * Snapshot generator: fix problem checking types on logical models * Do not flag internal references as suspicious +* XMLParser allows passing a schema location \ No newline at end of file diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java index 51d763a71..6aefc6650 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java @@ -329,6 +329,7 @@ public class ProfileUtilities extends TranslatingUtilities { private String defWebRoot; private boolean autoFixSliceNames; private XVerExtensionManager xver; + private boolean wantFixDifferentialFirstElementType; public ProfileUtilities(IWorkerContext context, List messages, ProfileKnowledgeProvider pkp, FHIRPathEngine fpe) { super(); @@ -363,9 +364,15 @@ public class ProfileUtilities extends TranslatingUtilities { public void setIgmode(boolean igmode) { this.igmode = igmode; } + + public boolean isWantFixDifferentialFirstElementType() { + return wantFixDifferentialFirstElementType; + } + + public void setWantFixDifferentialFirstElementType(boolean wantFixDifferentialFirstElementType) { + this.wantFixDifferentialFirstElementType = wantFixDifferentialFirstElementType; + } - - public boolean isAutoFixSliceNames() { return autoFixSliceNames; } @@ -772,7 +779,7 @@ public class ProfileUtilities extends TranslatingUtilities { public void checkDifferentialBaseType(StructureDefinition derived) throws Error { if (derived.hasDifferential() && !derived.getDifferential().getElementFirstRep().getPath().contains(".") && !derived.getDifferential().getElementFirstRep().getType().isEmpty()) { - if (typeMatchesAncestor(derived.getDifferential().getElementFirstRep().getType(), derived.getBaseDefinition())) { + if (wantFixDifferentialFirstElementType && typeMatchesAncestor(derived.getDifferential().getElementFirstRep().getType(), derived.getBaseDefinition())) { derived.getDifferential().getElementFirstRep().getType().clear(); } else { throw new Error(context.formatMessage(I18nConstants.TYPE_ON_FIRST_DIFFERENTIAL_ELEMENT)); diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java index 3b01a0ab3..4fbe39b18 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java @@ -86,6 +86,16 @@ public class XmlParser extends ParserBase { public XmlParser(IWorkerContext context) { super(context); } + + private String schemaPath; + + public String getSchemaPath() { + return schemaPath; + } + public void setSchemaPath(String schemaPath) { + this.schemaPath = schemaPath; + } + public boolean isAllowXsiLocation() { @@ -597,6 +607,9 @@ public class XmlParser extends ParserBase { public void compose(Element e, IXMLWriter xml) throws Exception { xml.start(); xml.setDefaultNamespace(e.getProperty().getXmlNamespace()); + if (schemaPath != null) { + xml.setSchemaLocation(FormatUtilities.FHIR_NS, Utilities.pathURL(schemaPath, e.fhirType()+".xsd")); + } composeElement(xml, e, e.getType(), true); xml.end(); } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/formats/XmlParserBase.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/formats/XmlParserBase.java index b9643e3aa..ce36fe83e 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/formats/XmlParserBase.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/formats/XmlParserBase.java @@ -99,10 +99,11 @@ public abstract class XmlParserBase extends ParserBase implements IParser { public ParserType getType() { return ParserType.XML; } - + + // -- in descendent generated code -------------------------------------- - abstract protected Resource parseResource(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError ; + abstract protected Resource parseResource(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError ; abstract protected DataType parseType(XmlPullParser xml, String type) throws XmlPullParserException, IOException, FHIRFormatError ; abstract protected DataType parseAnyType(XmlPullParser xml, String type) throws XmlPullParserException, IOException, FHIRFormatError ; abstract protected void composeType(String prefix, DataType type) throws IOException ; @@ -268,6 +269,14 @@ public abstract class XmlParserBase extends ParserBase implements IParser { protected IXMLWriter xml; protected boolean htmlPretty; + private String schemaPath; + + public String getSchemaPath() { + return schemaPath; + } + public void setSchemaPath(String schemaPath) { + this.schemaPath = schemaPath; + } @@ -382,6 +391,9 @@ public abstract class XmlParserBase extends ParserBase implements IParser { this.htmlPretty = htmlPretty; xml = writer; xml.setDefaultNamespace(FHIR_NS); + if (schemaPath != null) { + xml.setSchemaLocation(FHIR_NS, Utilities.pathURL(schemaPath, resource.fhirType()+".xsd")); + } composeResource(resource); } diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ResourceTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ResourceTests.java index d1ec769f1..1bdd2815f 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ResourceTests.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ResourceTests.java @@ -2,6 +2,10 @@ package org.hl7.fhir.r5.test; import static org.junit.jupiter.api.Assertions.*; +import java.io.IOException; + +import org.hl7.fhir.r5.formats.IParser.OutputStyle; +import org.hl7.fhir.r5.formats.XmlParser; import org.hl7.fhir.r5.model.CapabilityStatement; import org.hl7.fhir.r5.model.CodeSystem; import org.hl7.fhir.r5.model.CompartmentDefinition; @@ -12,6 +16,7 @@ import org.hl7.fhir.r5.model.ImplementationGuide; import org.hl7.fhir.r5.model.MessageDefinition; import org.hl7.fhir.r5.model.NamingSystem; import org.hl7.fhir.r5.model.OperationDefinition; +import org.hl7.fhir.r5.model.Resource; import org.hl7.fhir.r5.model.SearchParameter; import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.r5.model.StructureMap; @@ -40,4 +45,27 @@ class ResourceTests { assertFalse(new GraphDefinition().supportsCopyright()); } + private String SRC = "\r\n\r\n"+ + "\r\n"+ + " \r\n"+ + " \r\n"+ + " \r\n"+ + "\r\n"; + + private String TGT = ""+ + ""+ + ""+ + ""+ + ""+ + ""; + + @Test + void testSchemaLocation() throws IOException { + XmlParser xml = new XmlParser(); + xml.setSchemaPath("http://test.org"); + xml.setOutputStyle(OutputStyle.NORMAL); + Resource res = xml.parse(SRC); + String output = xml.composeString(res); + assertEquals(TGT, output); + } } diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/IXMLWriter.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/IXMLWriter.java index 87b5773ca..2be6e0e6e 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/IXMLWriter.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/IXMLWriter.java @@ -60,6 +60,7 @@ public interface IXMLWriter { public abstract void comment(String comment, boolean doPretty) throws IOException; public abstract void decorate(ElementDecoration decoration) throws IOException; + public abstract void setSchemaLocation(String ns, String loc) throws IOException; public abstract void enter(String name) throws IOException; public abstract void enter(String namespace, String name) throws IOException; diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XMLWriter.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XMLWriter.java index 3854919cf..65753df7f 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XMLWriter.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XMLWriter.java @@ -900,6 +900,12 @@ public class XMLWriter extends OutputStreamWriter implements IXMLWriter { public void decorate(ElementDecoration element) throws IOException { // nothing... } + @Override + public void setSchemaLocation(String ns, String loc) throws IOException { + namespace("http://www.w3.org/2001/XMLSchema-instance", "xsi"); + attribute("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation", ns+" "+loc); + + } } \ No newline at end of file