mirror of
https://github.com/hapifhir/org.hl7.fhir.core.git
synced 2025-02-07 21:38:15 +00:00
Merge pull request #280 from hapifhir/gg-lazy-loading
implement lazy loading - improve loading times and memory requirement
This commit is contained in:
commit
a5b8346711
@ -1,33 +1,33 @@
|
||||
package org.hl7.fhir.convertors;
|
||||
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@ -133,7 +133,8 @@ public class R2R3ConversionManager implements ITransformerServices {
|
||||
// set up ------------------------------------------------------------------
|
||||
public void setR2Definitions(InputStream stream) throws IOException, FHIRException {
|
||||
needPrepare = true;
|
||||
R2ToR3Loader ldr = new R2ToR3Loader().setPatchUrls(true).setKillPrimitives(true);
|
||||
R2ToR3Loader ldr = new R2ToR3Loader();
|
||||
ldr.setPatchUrls(true).setKillPrimitives(true);
|
||||
Map<String, InputStream> files = readInputStream(stream);
|
||||
contextR2 = new SimpleWorkerContext();
|
||||
contextR2.setAllowLoadingDuplicates(true);
|
||||
|
@ -1,7 +1,26 @@
|
||||
package org.hl7.fhir.convertors.loaders;
|
||||
|
||||
import org.hl7.fhir.r5.model.Bundle;
|
||||
import org.hl7.fhir.r5.model.CanonicalType;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition;
|
||||
import org.hl7.fhir.r5.model.StructureDefinition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BaseLoader {
|
||||
|
||||
protected final String URL_BASE = "http://hl7.org/fhir/";
|
||||
protected final String URL_DSTU2 = "http://hl7.org/fhir/1.0/";
|
||||
protected final String URL_DSTU2016MAY = "http://hl7.org/fhir/1.4/";
|
||||
protected final String URL_DSTU3 = "http://hl7.org/fhir/3.0/";
|
||||
protected final String URL_R4 = "http://hl7.org/fhir/4.0/";
|
||||
|
||||
protected final String URL_ELEMENT_DEF_NAMESPACE = "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace";
|
||||
|
||||
protected boolean patchUrls;
|
||||
protected boolean killPrimitives;;
|
||||
|
||||
private String[] types;
|
||||
|
||||
public BaseLoader(String[] types) {
|
||||
@ -13,6 +32,23 @@ public abstract class BaseLoader {
|
||||
return types;
|
||||
}
|
||||
|
||||
public boolean isPatchUrls() {
|
||||
return patchUrls;
|
||||
}
|
||||
|
||||
public BaseLoader setPatchUrls(boolean patchUrls) {
|
||||
this.patchUrls = patchUrls;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isKillPrimitives() {
|
||||
return killPrimitives;
|
||||
}
|
||||
|
||||
public BaseLoader setKillPrimitives(boolean killPrimitives) {
|
||||
this.killPrimitives = killPrimitives;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,33 +1,33 @@
|
||||
package org.hl7.fhir.convertors.loaders;
|
||||
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@ -55,12 +55,14 @@ import org.hl7.fhir.r4.model.StructureDefinition.StructureDefinitionKind;
|
||||
import org.hl7.fhir.r4.model.UriType;
|
||||
import org.hl7.fhir.r4.model.ValueSet;
|
||||
|
||||
public class R2016MayToR4Loader implements IContextResourceLoader, VersionConvertorAdvisor40 {
|
||||
public class R2016MayToR4Loader extends BaseLoader implements IContextResourceLoader, VersionConvertorAdvisor40 {
|
||||
|
||||
private List<CodeSystem> cslist = new ArrayList<>();
|
||||
private boolean patchUrls;
|
||||
private boolean killPrimitives;;
|
||||
|
||||
|
||||
public R2016MayToR4Loader() {
|
||||
super(new String[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
|
||||
Resource r2016may = null;
|
||||
@ -101,8 +103,8 @@ public class R2016MayToR4Loader implements IContextResourceLoader, VersionConver
|
||||
StructureDefinition sd = (StructureDefinition) be.getResource();
|
||||
new ProfileUtilities(null, null, null).setIds(sd, false);
|
||||
if (patchUrls) {
|
||||
sd.setUrl(sd.getUrl().replace("http://hl7.org/fhir/", "http://hl7.org/fhir/2016May/"));
|
||||
sd.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").setValue(new UriType("http://hl7.org/fhir"));
|
||||
sd.setUrl(sd.getUrl().replace(URL_BASE, "http://hl7.org/fhir/2016May/"));
|
||||
sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -142,22 +144,4 @@ public class R2016MayToR4Loader implements IContextResourceLoader, VersionConver
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isPatchUrls() {
|
||||
return patchUrls;
|
||||
}
|
||||
|
||||
public R2016MayToR4Loader setPatchUrls(boolean patchUrls) {
|
||||
this.patchUrls = patchUrls;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isKillPrimitives() {
|
||||
return killPrimitives;
|
||||
}
|
||||
|
||||
public R2016MayToR4Loader setKillPrimitives(boolean killPrimitives) {
|
||||
this.killPrimitives = killPrimitives;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +1,33 @@
|
||||
package org.hl7.fhir.convertors.loaders;
|
||||
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@ -48,8 +48,11 @@ import org.hl7.fhir.r5.context.IWorkerContext.IContextResourceLoader;
|
||||
import org.hl7.fhir.r5.model.Bundle;
|
||||
import org.hl7.fhir.r5.model.Bundle.BundleEntryComponent;
|
||||
import org.hl7.fhir.r5.model.Bundle.BundleType;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent;
|
||||
import org.hl7.fhir.r5.model.CanonicalResource;
|
||||
import org.hl7.fhir.r5.model.CanonicalType;
|
||||
import org.hl7.fhir.r5.model.CodeSystem;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition;
|
||||
import org.hl7.fhir.r5.model.StructureDefinition;
|
||||
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
|
||||
import org.hl7.fhir.r5.model.UriType;
|
||||
@ -62,9 +65,7 @@ public class R2016MayToR5Loader extends BaseLoader implements IContextResourceLo
|
||||
}
|
||||
|
||||
private List<CodeSystem> cslist = new ArrayList<>();
|
||||
private boolean patchUrls;
|
||||
private boolean killPrimitives;;
|
||||
|
||||
|
||||
@Override
|
||||
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
|
||||
Resource r2016may = null;
|
||||
@ -105,14 +106,53 @@ public class R2016MayToR5Loader extends BaseLoader implements IContextResourceLo
|
||||
StructureDefinition sd = (StructureDefinition) be.getResource();
|
||||
new ProfileUtilities(null, null, null).setIds(sd, false);
|
||||
if (patchUrls) {
|
||||
sd.setUrl(sd.getUrl().replace("http://hl7.org/fhir/", "http://hl7.org/fhir/2016May/"));
|
||||
sd.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").setValue(new UriType("http://hl7.org/fhir"));
|
||||
sd.setUrl(sd.getUrl().replace(URL_BASE, URL_DSTU2016MAY));
|
||||
sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
|
||||
}
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.hl7.fhir.r5.model.Resource loadResource(InputStream stream, boolean isJson) throws FHIRException, IOException {
|
||||
Resource r2016may = null;
|
||||
if (isJson)
|
||||
r2016may = new JsonParser().parse(stream);
|
||||
else
|
||||
r2016may = new XmlParser().parse(stream);
|
||||
org.hl7.fhir.r5.model.Resource r5 = VersionConvertor_14_50.convertResource(r2016may);
|
||||
if (!cslist.isEmpty()) {
|
||||
throw new FHIRException("Error: Cannot have included code systems");
|
||||
}
|
||||
if (killPrimitives) {
|
||||
throw new FHIRException("Cannot kill primitives when using deferred loading");
|
||||
}
|
||||
if (patchUrls) {
|
||||
if (r5 instanceof StructureDefinition) {
|
||||
StructureDefinition sd = (StructureDefinition) r5;
|
||||
sd.setUrl(sd.getUrl().replace(URL_BASE, URL_R4));
|
||||
sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
|
||||
for (ElementDefinition ed : sd.getSnapshot().getElement())
|
||||
patchUrl(ed);
|
||||
for (ElementDefinition ed : sd.getDifferential().getElement())
|
||||
patchUrl(ed);
|
||||
}
|
||||
}
|
||||
return r5;
|
||||
}
|
||||
|
||||
private void patchUrl(ElementDefinition ed) {
|
||||
for (TypeRefComponent tr : ed.getType()) {
|
||||
for (CanonicalType s : tr.getTargetProfile()) {
|
||||
s.setValue(s.getValue().replace(URL_BASE, URL_DSTU2016MAY));
|
||||
}
|
||||
for (CanonicalType s : tr.getProfile()) {
|
||||
s.setValue(s.getValue().replace(URL_BASE, URL_DSTU2016MAY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ignoreEntry(BundleEntryComponent src) {
|
||||
return false;
|
||||
@ -146,24 +186,6 @@ public class R2016MayToR5Loader extends BaseLoader implements IContextResourceLo
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isPatchUrls() {
|
||||
return patchUrls;
|
||||
}
|
||||
|
||||
public R2016MayToR5Loader setPatchUrls(boolean patchUrls) {
|
||||
this.patchUrls = patchUrls;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isKillPrimitives() {
|
||||
return killPrimitives;
|
||||
}
|
||||
|
||||
public R2016MayToR5Loader setKillPrimitives(boolean killPrimitives) {
|
||||
this.killPrimitives = killPrimitives;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.hl7.fhir.r4.model.Resource convertR4(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
|
||||
return null;
|
||||
|
@ -1,34 +1,33 @@
|
||||
package org.hl7.fhir.convertors.loaders;
|
||||
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
@ -54,12 +53,14 @@ import org.hl7.fhir.dstu3.model.UriType;
|
||||
import org.hl7.fhir.dstu3.model.ValueSet;
|
||||
import org.hl7.fhir.exceptions.FHIRException;
|
||||
|
||||
public class R2ToR3Loader implements IContextResourceLoader, VersionConvertorAdvisor30 {
|
||||
public class R2ToR3Loader extends BaseLoader implements IContextResourceLoader, VersionConvertorAdvisor30 {
|
||||
|
||||
private List<CodeSystem> cslist = new ArrayList<>();
|
||||
private boolean patchUrls;
|
||||
private boolean killPrimitives;;
|
||||
|
||||
|
||||
public R2ToR3Loader() {
|
||||
super(new String[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
|
||||
Resource r2 = null;
|
||||
@ -82,7 +83,7 @@ public class R2ToR3Loader implements IContextResourceLoader, VersionConvertorAdv
|
||||
be.setFullUrl(cs.getUrl());
|
||||
be.setResource(cs);
|
||||
}
|
||||
cslist.clear();
|
||||
cslist.clear();
|
||||
if (killPrimitives) {
|
||||
List<BundleEntryComponent> remove = new ArrayList<BundleEntryComponent>();
|
||||
for (BundleEntryComponent be : b.getEntry()) {
|
||||
@ -98,8 +99,8 @@ public class R2ToR3Loader implements IContextResourceLoader, VersionConvertorAdv
|
||||
for (BundleEntryComponent be : b.getEntry()) {
|
||||
if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
|
||||
StructureDefinition sd = (StructureDefinition) be.getResource();
|
||||
sd.setUrl(sd.getUrl().replace("http://hl7.org/fhir/", "http://hl7.org/fhir/DSTU2/"));
|
||||
sd.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").setValue(new UriType("http://hl7.org/fhir"));
|
||||
sd.setUrl(sd.getUrl().replace(URL_BASE, URL_DSTU2));
|
||||
sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -121,7 +122,6 @@ public class R2ToR3Loader implements IContextResourceLoader, VersionConvertorAdv
|
||||
cs.setId(vs.getId());
|
||||
cs.setValueSet(vs.getUrl());
|
||||
cslist.add(cs);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -129,22 +129,4 @@ public class R2ToR3Loader implements IContextResourceLoader, VersionConvertorAdv
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isPatchUrls() {
|
||||
return patchUrls;
|
||||
}
|
||||
|
||||
public R2ToR3Loader setPatchUrls(boolean patchUrls) {
|
||||
this.patchUrls = patchUrls;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isKillPrimitives() {
|
||||
return killPrimitives;
|
||||
}
|
||||
|
||||
public R2ToR3Loader setKillPrimitives(boolean killPrimitives) {
|
||||
this.killPrimitives = killPrimitives;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +1,33 @@
|
||||
package org.hl7.fhir.convertors.loaders;
|
||||
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@ -54,11 +54,13 @@ import org.hl7.fhir.r4.model.StructureDefinition.StructureDefinitionKind;
|
||||
import org.hl7.fhir.r4.model.UriType;
|
||||
import org.hl7.fhir.r4.model.ValueSet;
|
||||
|
||||
public class R2ToR4Loader implements IContextResourceLoader, VersionConvertorAdvisor40 {
|
||||
public class R2ToR4Loader extends BaseLoader implements IContextResourceLoader, VersionConvertorAdvisor40 {
|
||||
|
||||
private List<CodeSystem> cslist = new ArrayList<>();
|
||||
private boolean patchUrls;
|
||||
private boolean killPrimitives;;
|
||||
|
||||
public R2ToR4Loader() {
|
||||
super(new String[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
|
||||
@ -99,8 +101,8 @@ public class R2ToR4Loader implements IContextResourceLoader, VersionConvertorAdv
|
||||
for (BundleEntryComponent be : b.getEntry()) {
|
||||
if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
|
||||
StructureDefinition sd = (StructureDefinition) be.getResource();
|
||||
sd.setUrl(sd.getUrl().replace("http://hl7.org/fhir/", "http://hl7.org/fhir/DSTU2/"));
|
||||
sd.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").setValue(new UriType("http://hl7.org/fhir"));
|
||||
sd.setUrl(sd.getUrl().replace(URL_BASE, URL_DSTU2));
|
||||
sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -139,22 +141,4 @@ public class R2ToR4Loader implements IContextResourceLoader, VersionConvertorAdv
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isPatchUrls() {
|
||||
return patchUrls;
|
||||
}
|
||||
|
||||
public R2ToR4Loader setPatchUrls(boolean patchUrls) {
|
||||
this.patchUrls = patchUrls;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isKillPrimitives() {
|
||||
return killPrimitives;
|
||||
}
|
||||
|
||||
public R2ToR4Loader setKillPrimitives(boolean killPrimitives) {
|
||||
this.killPrimitives = killPrimitives;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +1,33 @@
|
||||
package org.hl7.fhir.convertors.loaders;
|
||||
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@ -47,8 +47,11 @@ import org.hl7.fhir.r5.context.IWorkerContext.IContextResourceLoader;
|
||||
import org.hl7.fhir.r5.model.Bundle;
|
||||
import org.hl7.fhir.r5.model.Bundle.BundleEntryComponent;
|
||||
import org.hl7.fhir.r5.model.Bundle.BundleType;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent;
|
||||
import org.hl7.fhir.r5.model.CanonicalResource;
|
||||
import org.hl7.fhir.r5.model.CanonicalType;
|
||||
import org.hl7.fhir.r5.model.CodeSystem;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition;
|
||||
import org.hl7.fhir.r5.model.StructureDefinition;
|
||||
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
|
||||
import org.hl7.fhir.r5.model.UriType;
|
||||
@ -56,15 +59,12 @@ import org.hl7.fhir.r5.model.ValueSet;
|
||||
|
||||
public class R2ToR5Loader extends BaseLoader implements IContextResourceLoader, VersionConvertorAdvisor50 {
|
||||
|
||||
|
||||
public R2ToR5Loader(String[] types) {
|
||||
super(types);
|
||||
}
|
||||
|
||||
private List<CodeSystem> cslist = new ArrayList<>();
|
||||
private boolean patchUrls;
|
||||
private boolean killPrimitives;;
|
||||
|
||||
|
||||
@Override
|
||||
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
|
||||
Resource r2 = null;
|
||||
@ -104,14 +104,54 @@ public class R2ToR5Loader extends BaseLoader implements IContextResourceLoader,
|
||||
for (BundleEntryComponent be : b.getEntry()) {
|
||||
if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
|
||||
StructureDefinition sd = (StructureDefinition) be.getResource();
|
||||
sd.setUrl(sd.getUrl().replace("http://hl7.org/fhir/", "http://hl7.org/fhir/DSTU2/"));
|
||||
sd.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").setValue(new UriType("http://hl7.org/fhir"));
|
||||
sd.setUrl(sd.getUrl().replace(URL_BASE, URL_DSTU2));
|
||||
sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
|
||||
}
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public org.hl7.fhir.r5.model.Resource loadResource(InputStream stream, boolean isJson) throws FHIRException, IOException {
|
||||
Resource r2 = null;
|
||||
if (isJson)
|
||||
r2 = new JsonParser().parse(stream);
|
||||
else
|
||||
r2 = new XmlParser().parse(stream);
|
||||
org.hl7.fhir.r5.model.Resource r5 = VersionConvertor_10_50.convertResource(r2, this);
|
||||
if (!cslist.isEmpty()) {
|
||||
throw new FHIRException("Error: Cannot have included code systems");
|
||||
}
|
||||
if (killPrimitives) {
|
||||
throw new FHIRException("Cannot kill primitives when using deferred loading");
|
||||
}
|
||||
if (patchUrls) {
|
||||
if (r5 instanceof StructureDefinition) {
|
||||
StructureDefinition sd = (StructureDefinition) r5;
|
||||
sd.setUrl(sd.getUrl().replace(URL_BASE, URL_R4));
|
||||
sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
|
||||
for (ElementDefinition ed : sd.getSnapshot().getElement())
|
||||
patchUrl(ed);
|
||||
for (ElementDefinition ed : sd.getDifferential().getElement())
|
||||
patchUrl(ed);
|
||||
}
|
||||
}
|
||||
return r5;
|
||||
}
|
||||
|
||||
private void patchUrl(ElementDefinition ed) {
|
||||
for (TypeRefComponent tr : ed.getType()) {
|
||||
for (CanonicalType s : tr.getTargetProfile()) {
|
||||
s.setValue(s.getValue().replace(URL_BASE, URL_DSTU2));
|
||||
}
|
||||
for (CanonicalType s : tr.getProfile()) {
|
||||
s.setValue(s.getValue().replace(URL_BASE, URL_DSTU2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ignoreEntry(BundleEntryComponent src) {
|
||||
return false;
|
||||
@ -144,24 +184,6 @@ public class R2ToR5Loader extends BaseLoader implements IContextResourceLoader,
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isPatchUrls() {
|
||||
return patchUrls;
|
||||
}
|
||||
|
||||
public R2ToR5Loader setPatchUrls(boolean patchUrls) {
|
||||
this.patchUrls = patchUrls;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isKillPrimitives() {
|
||||
return killPrimitives;
|
||||
}
|
||||
|
||||
public R2ToR5Loader setKillPrimitives(boolean killPrimitives) {
|
||||
this.killPrimitives = killPrimitives;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.hl7.fhir.r4.model.Resource convertR4(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
|
||||
return null;
|
||||
|
@ -1,33 +1,33 @@
|
||||
package org.hl7.fhir.convertors.loaders;
|
||||
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@ -44,25 +44,20 @@ import org.hl7.fhir.dstu3.formats.XmlParser;
|
||||
import org.hl7.fhir.dstu3.model.Resource;
|
||||
import org.hl7.fhir.exceptions.FHIRException;
|
||||
import org.hl7.fhir.r4.context.SimpleWorkerContext.IContextResourceLoader;
|
||||
import org.hl7.fhir.r4.model.Bundle;
|
||||
import org.hl7.fhir.r4.model.*;
|
||||
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
|
||||
import org.hl7.fhir.r4.model.Bundle.BundleType;
|
||||
import org.hl7.fhir.r4.model.CanonicalType;
|
||||
import org.hl7.fhir.r4.model.CodeSystem;
|
||||
import org.hl7.fhir.r4.model.ElementDefinition;
|
||||
import org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent;
|
||||
import org.hl7.fhir.r4.model.MetadataResource;
|
||||
import org.hl7.fhir.r4.model.StructureDefinition;
|
||||
import org.hl7.fhir.r4.model.StructureDefinition.StructureDefinitionKind;
|
||||
import org.hl7.fhir.r4.model.UriType;
|
||||
import org.hl7.fhir.r4.model.ValueSet;
|
||||
|
||||
public class R3ToR4Loader implements IContextResourceLoader, VersionConvertorAdvisor40 {
|
||||
public class R3ToR4Loader extends BaseLoader implements IContextResourceLoader, VersionConvertorAdvisor40 {
|
||||
|
||||
private List<CodeSystem> cslist = new ArrayList<>();
|
||||
private boolean patchUrls;
|
||||
private boolean killPrimitives;;
|
||||
|
||||
|
||||
public R3ToR4Loader() {
|
||||
super(new String[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
|
||||
Resource r3 = null;
|
||||
@ -101,8 +96,8 @@ public class R3ToR4Loader implements IContextResourceLoader, VersionConvertorAdv
|
||||
for (BundleEntryComponent be : b.getEntry()) {
|
||||
if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
|
||||
StructureDefinition sd = (StructureDefinition) be.getResource();
|
||||
sd.setUrl(sd.getUrl().replace("http://hl7.org/fhir/", "http://hl7.org/fhir/3.0/"));
|
||||
sd.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").setValue(new UriType("http://hl7.org/fhir"));
|
||||
sd.setUrl(sd.getUrl().replace(URL_BASE, URL_DSTU3));
|
||||
sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
|
||||
for (ElementDefinition ed : sd.getSnapshot().getElement())
|
||||
patchUrl(ed);
|
||||
for (ElementDefinition ed : sd.getDifferential().getElement())
|
||||
@ -116,10 +111,10 @@ public class R3ToR4Loader implements IContextResourceLoader, VersionConvertorAdv
|
||||
private void patchUrl(ElementDefinition ed) {
|
||||
for (TypeRefComponent tr : ed.getType()) {
|
||||
for (CanonicalType s : tr.getTargetProfile()) {
|
||||
s.setValue(s.getValue().replace("http://hl7.org/fhir/", "http://hl7.org/fhir/3.0/"));
|
||||
s.setValue(s.getValue().replace(URL_BASE, URL_DSTU3));
|
||||
}
|
||||
for (CanonicalType s : tr.getProfile()) {
|
||||
s.setValue(s.getValue().replace("http://hl7.org/fhir/", "http://hl7.org/fhir/3.0/"));
|
||||
s.setValue(s.getValue().replace(URL_BASE, URL_DSTU3));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -157,22 +152,4 @@ public class R3ToR4Loader implements IContextResourceLoader, VersionConvertorAdv
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isPatchUrls() {
|
||||
return patchUrls;
|
||||
}
|
||||
|
||||
public R3ToR4Loader setPatchUrls(boolean patchUrls) {
|
||||
this.patchUrls = patchUrls;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isKillPrimitives() {
|
||||
return killPrimitives;
|
||||
}
|
||||
|
||||
public R3ToR4Loader setKillPrimitives(boolean killPrimitives) {
|
||||
this.killPrimitives = killPrimitives;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +1,33 @@
|
||||
package org.hl7.fhir.convertors.loaders;
|
||||
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@ -64,9 +64,7 @@ public class R3ToR5Loader extends BaseLoader implements IContextResourceLoader,
|
||||
}
|
||||
|
||||
private List<CodeSystem> cslist = new ArrayList<>();
|
||||
private boolean patchUrls;
|
||||
private boolean killPrimitives;
|
||||
|
||||
|
||||
@Override
|
||||
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
|
||||
Resource r3 = null;
|
||||
@ -105,8 +103,8 @@ public class R3ToR5Loader extends BaseLoader implements IContextResourceLoader,
|
||||
for (BundleEntryComponent be : b.getEntry()) {
|
||||
if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
|
||||
StructureDefinition sd = (StructureDefinition) be.getResource();
|
||||
sd.setUrl(sd.getUrl().replace("http://hl7.org/fhir/", "http://hl7.org/fhir/3.0/"));
|
||||
sd.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").setValue(new UriType("http://hl7.org/fhir"));
|
||||
sd.setUrl(sd.getUrl().replace(URL_BASE, URL_DSTU3));
|
||||
sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
|
||||
for (ElementDefinition ed : sd.getSnapshot().getElement())
|
||||
patchUrl(ed);
|
||||
for (ElementDefinition ed : sd.getDifferential().getElement())
|
||||
@ -116,14 +114,42 @@ public class R3ToR5Loader extends BaseLoader implements IContextResourceLoader,
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.hl7.fhir.r5.model.Resource loadResource(InputStream stream, boolean isJson) throws FHIRException, IOException {
|
||||
Resource r3 = null;
|
||||
if (isJson)
|
||||
r3 = new JsonParser().parse(stream);
|
||||
else
|
||||
r3 = new XmlParser().parse(stream);
|
||||
org.hl7.fhir.r5.model.Resource r5 = VersionConvertor_30_50.convertResource(r3, false);
|
||||
if (!cslist.isEmpty()) {
|
||||
throw new FHIRException("Error: Cannot have included code systems");
|
||||
}
|
||||
if (killPrimitives) {
|
||||
throw new FHIRException("Cannot kill primitives when using deferred loading");
|
||||
}
|
||||
if (patchUrls) {
|
||||
if (r5 instanceof StructureDefinition) {
|
||||
StructureDefinition sd = (StructureDefinition) r5;
|
||||
sd.setUrl(sd.getUrl().replace(URL_BASE, URL_R4));
|
||||
sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
|
||||
for (ElementDefinition ed : sd.getSnapshot().getElement())
|
||||
patchUrl(ed);
|
||||
for (ElementDefinition ed : sd.getDifferential().getElement())
|
||||
patchUrl(ed);
|
||||
}
|
||||
}
|
||||
return r5;
|
||||
}
|
||||
|
||||
private void patchUrl(ElementDefinition ed) {
|
||||
for (TypeRefComponent tr : ed.getType()) {
|
||||
for (CanonicalType s : tr.getTargetProfile()) {
|
||||
s.setValue(s.getValue().replace("http://hl7.org/fhir/", "http://hl7.org/fhir/3.0/"));
|
||||
s.setValue(s.getValue().replace(URL_BASE, URL_DSTU3));
|
||||
}
|
||||
for (CanonicalType s : tr.getProfile()) {
|
||||
s.setValue(s.getValue().replace("http://hl7.org/fhir/", "http://hl7.org/fhir/3.0/"));
|
||||
s.setValue(s.getValue().replace(URL_BASE, URL_DSTU3));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -161,27 +187,8 @@ public class R3ToR5Loader extends BaseLoader implements IContextResourceLoader,
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isPatchUrls() {
|
||||
return patchUrls;
|
||||
}
|
||||
|
||||
public R3ToR5Loader setPatchUrls(boolean patchUrls) {
|
||||
this.patchUrls = patchUrls;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isKillPrimitives() {
|
||||
return killPrimitives;
|
||||
}
|
||||
|
||||
public R3ToR5Loader setKillPrimitives(boolean killPrimitives) {
|
||||
this.killPrimitives = killPrimitives;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.hl7.fhir.r4.model.Resource convertR4(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +1,33 @@
|
||||
package org.hl7.fhir.convertors.loaders;
|
||||
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@ -64,9 +64,7 @@ public class R4ToR5Loader extends BaseLoader implements IContextResourceLoader,
|
||||
}
|
||||
|
||||
private List<CodeSystem> cslist = new ArrayList<>();
|
||||
private boolean patchUrls;
|
||||
private boolean killPrimitives;;
|
||||
|
||||
|
||||
@Override
|
||||
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
|
||||
Resource r4 = null;
|
||||
@ -105,8 +103,8 @@ public class R4ToR5Loader extends BaseLoader implements IContextResourceLoader,
|
||||
for (BundleEntryComponent be : b.getEntry()) {
|
||||
if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
|
||||
StructureDefinition sd = (StructureDefinition) be.getResource();
|
||||
sd.setUrl(sd.getUrl().replace("http://hl7.org/fhir/", "http://hl7.org/fhir/4.0/"));
|
||||
sd.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").setValue(new UriType("http://hl7.org/fhir"));
|
||||
sd.setUrl(sd.getUrl().replace(URL_BASE, URL_R4));
|
||||
sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
|
||||
for (ElementDefinition ed : sd.getSnapshot().getElement())
|
||||
patchUrl(ed);
|
||||
for (ElementDefinition ed : sd.getDifferential().getElement())
|
||||
@ -117,13 +115,41 @@ public class R4ToR5Loader extends BaseLoader implements IContextResourceLoader,
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.hl7.fhir.r5.model.Resource loadResource(InputStream stream, boolean isJson) throws FHIRException, IOException {
|
||||
Resource r4 = null;
|
||||
if (isJson)
|
||||
r4 = new JsonParser().parse(stream);
|
||||
else
|
||||
r4 = new XmlParser().parse(stream);
|
||||
org.hl7.fhir.r5.model.Resource r5 = VersionConvertor_40_50.convertResource(r4);
|
||||
if (!cslist.isEmpty()) {
|
||||
throw new FHIRException("Error: Cannot have included code systems");
|
||||
}
|
||||
if (killPrimitives) {
|
||||
throw new FHIRException("Cannot kill primitives when using deferred loading");
|
||||
}
|
||||
if (patchUrls) {
|
||||
if (r5 instanceof StructureDefinition) {
|
||||
StructureDefinition sd = (StructureDefinition) r5;
|
||||
sd.setUrl(sd.getUrl().replace(URL_BASE, "http://hl7.org/fhir/4.0/"));
|
||||
sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType("http://hl7.org/fhir"));
|
||||
for (ElementDefinition ed : sd.getSnapshot().getElement())
|
||||
patchUrl(ed);
|
||||
for (ElementDefinition ed : sd.getDifferential().getElement())
|
||||
patchUrl(ed);
|
||||
}
|
||||
}
|
||||
return r5;
|
||||
}
|
||||
|
||||
private void patchUrl(ElementDefinition ed) {
|
||||
for (TypeRefComponent tr : ed.getType()) {
|
||||
for (CanonicalType s : tr.getTargetProfile()) {
|
||||
s.setValue(s.getValue().replace("http://hl7.org/fhir/", "http://hl7.org/fhir/4.0/"));
|
||||
s.setValue(s.getValue().replace(URL_BASE, "http://hl7.org/fhir/4.0/"));
|
||||
}
|
||||
for (CanonicalType s : tr.getProfile()) {
|
||||
s.setValue(s.getValue().replace("http://hl7.org/fhir/", "http://hl7.org/fhir/4.0/"));
|
||||
s.setValue(s.getValue().replace(URL_BASE, "http://hl7.org/fhir/4.0/"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -161,24 +187,6 @@ public class R4ToR5Loader extends BaseLoader implements IContextResourceLoader,
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isPatchUrls() {
|
||||
return patchUrls;
|
||||
}
|
||||
|
||||
public R4ToR5Loader setPatchUrls(boolean patchUrls) {
|
||||
this.patchUrls = patchUrls;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isKillPrimitives() {
|
||||
return killPrimitives;
|
||||
}
|
||||
|
||||
public R4ToR5Loader setKillPrimitives(boolean killPrimitives) {
|
||||
this.killPrimitives = killPrimitives;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
|
||||
return null;
|
||||
|
@ -1,33 +1,33 @@
|
||||
package org.hl7.fhir.convertors.loaders;
|
||||
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@ -63,9 +63,7 @@ public class R5ToR5Loader extends BaseLoader implements IContextResourceLoader,
|
||||
}
|
||||
|
||||
private List<CodeSystem> cslist = new ArrayList<>();
|
||||
private boolean patchUrls;
|
||||
private boolean killPrimitives;;
|
||||
|
||||
|
||||
@Override
|
||||
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
|
||||
Resource r5 = null;
|
||||
@ -103,8 +101,8 @@ public class R5ToR5Loader extends BaseLoader implements IContextResourceLoader,
|
||||
for (BundleEntryComponent be : b.getEntry()) {
|
||||
if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
|
||||
StructureDefinition sd = (StructureDefinition) be.getResource();
|
||||
sd.setUrl(sd.getUrl().replace("http://hl7.org/fhir/", "http://hl7.org/fhir/4.0/"));
|
||||
sd.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").setValue(new UriType("http://hl7.org/fhir"));
|
||||
sd.setUrl(sd.getUrl().replace(URL_BASE, URL_R4));
|
||||
sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
|
||||
for (ElementDefinition ed : sd.getSnapshot().getElement())
|
||||
patchUrl(ed);
|
||||
for (ElementDefinition ed : sd.getDifferential().getElement())
|
||||
@ -115,13 +113,41 @@ public class R5ToR5Loader extends BaseLoader implements IContextResourceLoader,
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource loadResource(InputStream stream, boolean isJson) throws FHIRException, IOException {
|
||||
Resource r5 = null;
|
||||
if (isJson)
|
||||
r5 = new JsonParser().parse(stream);
|
||||
else
|
||||
r5 = new XmlParser().parse(stream);
|
||||
|
||||
if (!cslist.isEmpty()) {
|
||||
throw new FHIRException("Error: Cannot have included code systems");
|
||||
}
|
||||
if (killPrimitives) {
|
||||
throw new FHIRException("Cannot kill primitives when using deferred loading");
|
||||
}
|
||||
if (patchUrls) {
|
||||
if (r5 instanceof StructureDefinition) {
|
||||
StructureDefinition sd = (StructureDefinition) r5;
|
||||
sd.setUrl(sd.getUrl().replace(URL_BASE, URL_R4));
|
||||
sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
|
||||
for (ElementDefinition ed : sd.getSnapshot().getElement())
|
||||
patchUrl(ed);
|
||||
for (ElementDefinition ed : sd.getDifferential().getElement())
|
||||
patchUrl(ed);
|
||||
}
|
||||
}
|
||||
return r5;
|
||||
}
|
||||
|
||||
private void patchUrl(ElementDefinition ed) {
|
||||
for (TypeRefComponent tr : ed.getType()) {
|
||||
for (CanonicalType s : tr.getTargetProfile()) {
|
||||
s.setValue(s.getValue().replace("http://hl7.org/fhir/", "http://hl7.org/fhir/4.0/"));
|
||||
s.setValue(s.getValue().replace(URL_BASE, URL_R4));
|
||||
}
|
||||
for (CanonicalType s : tr.getProfile()) {
|
||||
s.setValue(s.getValue().replace("http://hl7.org/fhir/", "http://hl7.org/fhir/4.0/"));
|
||||
s.setValue(s.getValue().replace(URL_BASE, URL_R4));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -159,24 +185,6 @@ public class R5ToR5Loader extends BaseLoader implements IContextResourceLoader,
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isPatchUrls() {
|
||||
return patchUrls;
|
||||
}
|
||||
|
||||
public R5ToR5Loader setPatchUrls(boolean patchUrls) {
|
||||
this.patchUrls = patchUrls;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isKillPrimitives() {
|
||||
return killPrimitives;
|
||||
}
|
||||
|
||||
public R5ToR5Loader setKillPrimitives(boolean killPrimitives) {
|
||||
this.killPrimitives = killPrimitives;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.hl7.fhir.dstu3.model.Resource convertR3(org.hl7.fhir.r5.model.Resource resource) throws FHIRException {
|
||||
return null;
|
||||
|
@ -1,33 +1,33 @@
|
||||
package org.hl7.fhir.dstu2.utils;
|
||||
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
@ -1,33 +1,33 @@
|
||||
package org.hl7.fhir.r5.context;
|
||||
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
@ -49,6 +49,7 @@ import org.hl7.fhir.exceptions.DefinitionException;
|
||||
import org.hl7.fhir.exceptions.FHIRException;
|
||||
import org.hl7.fhir.exceptions.TerminologyServiceException;
|
||||
import org.hl7.fhir.r5.conformance.ProfileUtilities;
|
||||
import org.hl7.fhir.r5.context.CanonicalResourceManager.CanonicalResourceProxy;
|
||||
import org.hl7.fhir.r5.context.IWorkerContext.ILoggingService.LogCategory;
|
||||
import org.hl7.fhir.r5.context.TerminologyCache.CacheToken;
|
||||
import org.hl7.fhir.r5.model.BooleanType;
|
||||
@ -160,7 +161,8 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
||||
private CanonicalResourceManager<Questionnaire> questionnaires = new CanonicalResourceManager<Questionnaire>(false);
|
||||
private CanonicalResourceManager<OperationDefinition> operations = new CanonicalResourceManager<OperationDefinition>(false);
|
||||
private CanonicalResourceManager<PlanDefinition> plans = new CanonicalResourceManager<PlanDefinition>(false);
|
||||
private List<NamingSystem> systems = new ArrayList<NamingSystem>();
|
||||
private CanonicalResourceManager<NamingSystem> systems = new CanonicalResourceManager<NamingSystem>(false);
|
||||
|
||||
private UcumService ucumService;
|
||||
protected Map<String, byte[]> binaries = new HashMap<String, byte[]>();
|
||||
|
||||
@ -216,7 +218,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
||||
plans.copy(other.plans);
|
||||
questionnaires.copy(other.questionnaires);
|
||||
operations.copy(other.operations);
|
||||
systems.addAll(other.systems);
|
||||
systems.copy(other.systems);
|
||||
guides.copy(other.guides);
|
||||
capstmts.copy(other.capstmts);
|
||||
measures.copy(other.measures);
|
||||
@ -246,6 +248,69 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
||||
cacheResourceFromPackage(r, null);
|
||||
}
|
||||
|
||||
|
||||
public void registerResourceFromPackage(CanonicalResourceProxy r, PackageVersion packageInfo) throws FHIRException {
|
||||
synchronized (lock) {
|
||||
|
||||
String url = r.getUrl();
|
||||
if (!allowLoadingDuplicates && hasResource(r.getType(), url)) {
|
||||
// spcial workaround for known problems with existing packages
|
||||
if (Utilities.existsInList(url, "http://hl7.org/fhir/SearchParameter/example")) {
|
||||
return;
|
||||
}
|
||||
throw new DefinitionException(formatMessage(I18nConstants.DUPLICATE_RESOURCE_, url));
|
||||
}
|
||||
switch(r.getType()) {
|
||||
case "StructureDefinition":
|
||||
StructureDefinition sd = (StructureDefinition) r.getResource();
|
||||
if ("1.4.0".equals(version)) {
|
||||
fixOldSD(sd);
|
||||
}
|
||||
structures.register(r, packageInfo);
|
||||
break;
|
||||
case "ValueSet":
|
||||
valueSets.register(r, packageInfo);
|
||||
break;
|
||||
case "CodeSystem":
|
||||
codeSystems.register(r, packageInfo);
|
||||
break;
|
||||
case "ImplementationGuide":
|
||||
guides.register(r, packageInfo);
|
||||
break;
|
||||
case "CapabilityStatement":
|
||||
capstmts.register(r, packageInfo);
|
||||
break;
|
||||
case "Measure":
|
||||
measures.register(r, packageInfo);
|
||||
break;
|
||||
case "Library":
|
||||
libraries.register(r, packageInfo);
|
||||
break;
|
||||
case "SearchParameter":
|
||||
searchParameters.register(r, packageInfo);
|
||||
break;
|
||||
case "PlanDefinition":
|
||||
plans.register(r, packageInfo);
|
||||
break;
|
||||
case "OperationDefinition":
|
||||
operations.register(r, packageInfo);
|
||||
break;
|
||||
case "Questionnaire":
|
||||
questionnaires.register(r, packageInfo);
|
||||
break;
|
||||
case "ConceptMap":
|
||||
maps.register(r, packageInfo);
|
||||
break;
|
||||
case "StructureMap":
|
||||
transforms.register(r, packageInfo);
|
||||
break;
|
||||
case "NamingSystem":
|
||||
systems.register(r, packageInfo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void cacheResourceFromPackage(Resource r, PackageVersion packageInfo) throws FHIRException {
|
||||
synchronized (lock) {
|
||||
Map<String, Resource> map = allResourcesById.get(r.fhirType());
|
||||
@ -297,7 +362,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
||||
else if (r instanceof StructureMap)
|
||||
transforms.see((StructureMap) m, packageInfo);
|
||||
else if (r instanceof NamingSystem)
|
||||
systems.add((NamingSystem) r);
|
||||
systems.see((NamingSystem) m, packageInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -842,6 +907,10 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
||||
return fetchResourceWithException(class_, uri, null);
|
||||
}
|
||||
|
||||
public <T extends Resource> T fetchResourceWithException(String cls, String uri) throws FHIRException {
|
||||
return fetchResourceWithException(cls, uri, null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Resource> T fetchResourceWithException(Class<T> class_, String uri, CanonicalResource source) throws FHIRException {
|
||||
if (uri == null) {
|
||||
@ -936,6 +1005,114 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
||||
if (uri.matches(Constants.URI_REGEX) && !uri.contains("ValueSet"))
|
||||
return null;
|
||||
|
||||
// it might be a special URL.
|
||||
if (Utilities.isAbsoluteUrl(uri) || uri.startsWith("ValueSet/")) {
|
||||
Resource res = null; // findTxValueSet(uri);
|
||||
if (res != null)
|
||||
return (T) res;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (supportedCodeSystems.contains(uri))
|
||||
return null;
|
||||
throw new FHIRException(formatMessage(I18nConstants.NOT_DONE_YET_CANT_FETCH_, uri));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Resource> T fetchResourceWithException(String cls, String uri, CanonicalResource source) throws FHIRException {
|
||||
if (uri == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ("StructureDefinition".equals(cls)) {
|
||||
uri = ProfileUtilities.sdNs(uri, getOverrideVersionNs());
|
||||
}
|
||||
synchronized (lock) {
|
||||
|
||||
String version = null;
|
||||
if (uri.contains("|")) {
|
||||
version = uri.substring(uri.lastIndexOf("|")+1);
|
||||
uri = uri.substring(0, uri.lastIndexOf("|"));
|
||||
}
|
||||
if (uri.contains("#"))
|
||||
uri = uri.substring(0, uri.indexOf("#"));
|
||||
if (cls == null || "Resource".equals(cls)) {
|
||||
if (structures.has(uri))
|
||||
return (T) structures.get(uri, version);
|
||||
if (guides.has(uri))
|
||||
return (T) guides.get(uri, version);
|
||||
if (capstmts.has(uri))
|
||||
return (T) capstmts.get(uri, version);
|
||||
if (measures.has(uri))
|
||||
return (T) measures.get(uri, version);
|
||||
if (libraries.has(uri))
|
||||
return (T) libraries.get(uri, version);
|
||||
if (valueSets.has(uri))
|
||||
return (T) valueSets.get(uri, version);
|
||||
if (codeSystems.has(uri))
|
||||
return (T) codeSystems.get(uri, version);
|
||||
if (operations.has(uri))
|
||||
return (T) operations.get(uri, version);
|
||||
if (searchParameters.has(uri))
|
||||
return (T) searchParameters.get(uri, version);
|
||||
if (plans.has(uri))
|
||||
return (T) plans.get(uri, version);
|
||||
if (maps.has(uri))
|
||||
return (T) maps.get(uri, version);
|
||||
if (transforms.has(uri))
|
||||
return (T) transforms.get(uri, version);
|
||||
if (questionnaires.has(uri))
|
||||
return (T) questionnaires.get(uri, version);
|
||||
for (Map<String, Resource> rt : allResourcesById.values()) {
|
||||
for (Resource r : rt.values()) {
|
||||
if (r instanceof CanonicalResource) {
|
||||
CanonicalResource mr = (CanonicalResource) r;
|
||||
if (uri.equals(mr.getUrl()))
|
||||
return (T) mr;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ("ImplementationGuide".equals(cls)) {
|
||||
return (T) guides.get(uri, version);
|
||||
} else if ("CapabilityStatement".equals(cls)) {
|
||||
return (T) capstmts.get(uri, version);
|
||||
} else if ("Measure".equals(cls)) {
|
||||
return (T) measures.get(uri, version);
|
||||
} else if ("Library".equals(cls)) {
|
||||
return (T) libraries.get(uri, version);
|
||||
} else if ("StructureDefinition".equals(cls)) {
|
||||
return (T) structures.get(uri, version);
|
||||
} else if ("StructureMap".equals(cls)) {
|
||||
return (T) transforms.get(uri, version);
|
||||
} else if ("ValueSet".equals(cls)) {
|
||||
return (T) valueSets.get(uri, version);
|
||||
} else if ("CodeSystem".equals(cls)) {
|
||||
return (T) codeSystems.get(uri, version);
|
||||
} else if ("ConceptMap".equals(cls)) {
|
||||
return (T) maps.get(uri, version);
|
||||
} else if ("PlanDefinition".equals(cls)) {
|
||||
return (T) plans.get(uri, version);
|
||||
} else if ("OperationDefinition".equals(cls)) {
|
||||
OperationDefinition od = operations.get(uri, version);
|
||||
return (T) od;
|
||||
} else if ("Questionnaire.class".equals(cls)) {
|
||||
return (T) questionnaires.get(uri, version);
|
||||
} else if ("SearchParameter.class".equals(cls)) {
|
||||
SearchParameter res = searchParameters.get(uri, version);
|
||||
return (T) res;
|
||||
}
|
||||
if ("CodeSystem".equals(cls) && codeSystems.has(uri))
|
||||
return (T) codeSystems.get(uri, version);
|
||||
if ("ValueSet".equals(cls) && valueSets.has(uri))
|
||||
return (T) valueSets.get(uri, version);
|
||||
|
||||
if ("Questionnaire".equals(cls))
|
||||
return (T) questionnaires.get(uri, version);
|
||||
if (cls == null) {
|
||||
if (uri.matches(Constants.URI_REGEX) && !uri.contains("ValueSet"))
|
||||
return null;
|
||||
|
||||
// it might be a special URL.
|
||||
if (Utilities.isAbsoluteUrl(uri) || uri.startsWith("ValueSet/")) {
|
||||
Resource res = null; // findTxValueSet(uri);
|
||||
@ -1024,6 +1201,14 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
||||
}
|
||||
}
|
||||
|
||||
public <T extends Resource> boolean hasResource(String cls, String uri) {
|
||||
try {
|
||||
return fetchResourceWithException(cls, uri) != null;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public TranslationServices translator() {
|
||||
return translator;
|
||||
@ -1104,33 +1289,31 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
||||
if (map.containsKey(id))
|
||||
map.remove(id);
|
||||
|
||||
if (fhirType.equals("StructureDefinition"))
|
||||
if (fhirType.equals("StructureDefinition")) {
|
||||
structures.drop(id);
|
||||
else if (fhirType.equals("ImplementationGuide"))
|
||||
} else if (fhirType.equals("ImplementationGuide")) {
|
||||
guides.drop(id);
|
||||
else if (fhirType.equals("CapabilityStatement"))
|
||||
} else if (fhirType.equals("CapabilityStatement")) {
|
||||
capstmts.drop(id);
|
||||
else if (fhirType.equals("Measure"))
|
||||
} else if (fhirType.equals("Measure")) {
|
||||
measures.drop(id);
|
||||
else if (fhirType.equals("Library"))
|
||||
} else if (fhirType.equals("Library")) {
|
||||
libraries.drop(id);
|
||||
else if (fhirType.equals("ValueSet"))
|
||||
} else if (fhirType.equals("ValueSet")) {
|
||||
valueSets.drop(id);
|
||||
else if (fhirType.equals("CodeSystem"))
|
||||
} else if (fhirType.equals("CodeSystem")) {
|
||||
codeSystems.drop(id);
|
||||
else if (fhirType.equals("OperationDefinition"))
|
||||
} else if (fhirType.equals("OperationDefinition")) {
|
||||
operations.drop(id);
|
||||
else if (fhirType.equals("Questionnaire"))
|
||||
} else if (fhirType.equals("Questionnaire")) {
|
||||
questionnaires.drop(id);
|
||||
else if (fhirType.equals("ConceptMap"))
|
||||
} else if (fhirType.equals("ConceptMap")) {
|
||||
maps.drop(id);
|
||||
else if (fhirType.equals("StructureMap"))
|
||||
} else if (fhirType.equals("StructureMap")) {
|
||||
transforms.drop(id);
|
||||
else if (fhirType.equals("NamingSystem"))
|
||||
for (int i = systems.size()-1; i >= 0; i--) {
|
||||
if (systems.get(i).getId().equals(id))
|
||||
systems.remove(i);
|
||||
}
|
||||
} else if (fhirType.equals("NamingSystem")) {
|
||||
systems.drop(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1227,7 +1410,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
||||
String uri = OIDUtils.getUriForOid(oid);
|
||||
if (uri != null)
|
||||
return uri;
|
||||
for (NamingSystem ns : systems) {
|
||||
for (NamingSystem ns : systems.getList()) {
|
||||
if (hasOid(ns, oid)) {
|
||||
uri = getUri(ns);
|
||||
if (uri != null)
|
||||
|
@ -9,8 +9,12 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.hl7.fhir.exceptions.FHIRException;
|
||||
import org.hl7.fhir.r5.context.CanonicalResourceManager.CanonicalResourceProxy;
|
||||
import org.hl7.fhir.r5.context.IWorkerContext.PackageVersion;
|
||||
import org.hl7.fhir.r5.model.CanonicalResource;
|
||||
import org.hl7.fhir.r5.model.CodeSystem;
|
||||
import org.hl7.fhir.r5.terminologies.CodeSystemUtilities;
|
||||
import org.hl7.fhir.utilities.VersionUtilities;
|
||||
|
||||
/**
|
||||
@ -23,6 +27,66 @@ import org.hl7.fhir.utilities.VersionUtilities;
|
||||
|
||||
public class CanonicalResourceManager<T extends CanonicalResource> {
|
||||
|
||||
public static abstract class CanonicalResourceProxy {
|
||||
private String type;
|
||||
private String id;
|
||||
private String url;
|
||||
private String version;
|
||||
private CanonicalResource resource;
|
||||
|
||||
public CanonicalResourceProxy(String type, String id, String url, String version) {
|
||||
super();
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
this.url = url;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public boolean hasId() {
|
||||
return id != null;
|
||||
}
|
||||
|
||||
public boolean hasUrl() {
|
||||
return url != null;
|
||||
}
|
||||
|
||||
public boolean hasVersion() {
|
||||
return version != null;
|
||||
}
|
||||
|
||||
public CanonicalResource getResource() throws FHIRException {
|
||||
if (resource == null) {
|
||||
resource = loadResource();
|
||||
if (resource instanceof CodeSystem) {
|
||||
CodeSystemUtilities.crossLinkCodeSystem((CodeSystem) resource);
|
||||
}
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
public void setResource(CanonicalResource resource) {
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
public abstract CanonicalResource loadResource() throws FHIRException;
|
||||
}
|
||||
|
||||
public class CanonicalListSorter implements Comparator<CanonicalResource> {
|
||||
|
||||
@Override
|
||||
@ -35,37 +99,54 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
|
||||
|
||||
private class CachedCanonicalResource<T1 extends CanonicalResource> {
|
||||
private T1 resource;
|
||||
private CanonicalResourceProxy proxy;
|
||||
private PackageVersion packageInfo;
|
||||
|
||||
public CachedCanonicalResource(T1 resource, PackageVersion packageInfo) {
|
||||
super();
|
||||
this.resource = resource;
|
||||
this.packageInfo = packageInfo;
|
||||
}
|
||||
|
||||
public CachedCanonicalResource(CanonicalResourceProxy proxy, PackageVersion packageInfo) {
|
||||
super();
|
||||
this.proxy = proxy;
|
||||
this.packageInfo = packageInfo;
|
||||
}
|
||||
|
||||
public T1 getResource() {
|
||||
if (resource == null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
T1 res = (T1) proxy.getResource();
|
||||
synchronized (this) {
|
||||
resource = res;
|
||||
}
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
public PackageVersion getPackageInfo() {
|
||||
return packageInfo;
|
||||
}
|
||||
public String getUrl() {
|
||||
return resource.getUrl();
|
||||
return resource != null ? resource.getUrl() : proxy.getUrl();
|
||||
}
|
||||
public String getId() {
|
||||
return resource.getId();
|
||||
return resource != null ? resource.getId() : proxy.getId();
|
||||
}
|
||||
public String getVersion() {
|
||||
return resource.getVersion();
|
||||
return resource != null ? resource.getVersion() : proxy.getVersion();
|
||||
}
|
||||
public boolean hasVersion() {
|
||||
return resource.hasVersion();
|
||||
return resource != null ? resource.hasVersion() : proxy.getVersion() != null;
|
||||
}
|
||||
}
|
||||
|
||||
public class MetadataResourceVersionComparator<T1 extends CachedCanonicalResource<T>> implements Comparator<T1> {
|
||||
@Override
|
||||
public int compare(T1 arg1, T1 arg2) {
|
||||
String v1 = arg1.getResource().getVersion();
|
||||
String v2 = arg2.getResource().getVersion();
|
||||
String v1 = arg1.getVersion();
|
||||
String v2 = arg2.getVersion();
|
||||
if (v1 == null && v2 == null) {
|
||||
return Integer.compare(list.indexOf(arg1), list.indexOf(arg2)); // retain original order
|
||||
} else if (v1 == null) {
|
||||
@ -86,7 +167,7 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
|
||||
|
||||
private boolean enforceUniqueId;
|
||||
private List<CachedCanonicalResource<T>> list = new ArrayList<>();
|
||||
private Map<String, T> map = new HashMap<>();
|
||||
private Map<String, CachedCanonicalResource<T>> map = new HashMap<>();
|
||||
|
||||
|
||||
public CanonicalResourceManager(boolean enforceUniqueId) {
|
||||
@ -101,18 +182,31 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
|
||||
map.putAll(source.map);
|
||||
}
|
||||
|
||||
public void register(CanonicalResourceProxy r, PackageVersion packgeInfo) {
|
||||
if (!r.hasId()) {
|
||||
throw new FHIRException("An id is required for a deferred load resource");
|
||||
}
|
||||
CanonicalResourceManager<T>.CachedCanonicalResource<T> cr = new CachedCanonicalResource<T>(r, packgeInfo);
|
||||
see(cr);
|
||||
}
|
||||
|
||||
public void see(T r, PackageVersion packgeInfo) {
|
||||
if (!r.hasId()) {
|
||||
r.setId(UUID.randomUUID().toString());
|
||||
}
|
||||
if (enforceUniqueId && map.containsKey(r.getId())) {
|
||||
drop(r.getId());
|
||||
CanonicalResourceManager<T>.CachedCanonicalResource<T> cr = new CachedCanonicalResource<T>(r, packgeInfo);
|
||||
see(cr);
|
||||
}
|
||||
|
||||
public void see(CachedCanonicalResource<T> cr) {
|
||||
if (enforceUniqueId && map.containsKey(cr.getId())) {
|
||||
drop(cr.getId());
|
||||
}
|
||||
// special case logic for UTG support prior to version 5
|
||||
if (packgeInfo != null && packgeInfo.getId().startsWith("hl7.terminology")) {
|
||||
if (cr.getPackageInfo() != null && cr.getPackageInfo().getId().startsWith("hl7.terminology")) {
|
||||
List<CachedCanonicalResource<T>> toDrop = new ArrayList<>();
|
||||
for (CachedCanonicalResource<T> n : list) {
|
||||
if (n.getResource().getUrl().equals(r.getUrl()) && isBasePackage(n.getPackageInfo())) {
|
||||
if (n.getUrl().equals(cr.getUrl()) && isBasePackage(n.getPackageInfo())) {
|
||||
toDrop.add(n);
|
||||
}
|
||||
}
|
||||
@ -120,15 +214,15 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
|
||||
drop(n.getId());
|
||||
}
|
||||
}
|
||||
list.add(new CachedCanonicalResource<T>(r, packgeInfo));
|
||||
map.put(r.getId(), r); // we do this so we can drop by id
|
||||
list.add(cr);
|
||||
map.put(cr.getId(), cr); // we do this so we can drop by id
|
||||
|
||||
if (r.hasUrl()) {
|
||||
if (cr.getUrl() != null) {
|
||||
// first, this is the correct reosurce for this version (if it has a version)
|
||||
if (r.hasVersion()) {
|
||||
map.put(r.getUrl()+"|"+r.getVersion(), r);
|
||||
if (cr.hasVersion()) {
|
||||
map.put(cr.getUrl()+"|"+cr.getVersion(), cr);
|
||||
}
|
||||
updateList(r.getUrl(), r.getVersion());
|
||||
updateList(cr.getUrl(), cr.getVersion());
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,19 +241,19 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
|
||||
// sort by version as much as we are able
|
||||
Collections.sort(rl, new MetadataResourceVersionComparator<CachedCanonicalResource<T>>());
|
||||
// the current is the latest
|
||||
map.put(url, rl.get(rl.size()-1).getResource());
|
||||
map.put(url, rl.get(rl.size()-1));
|
||||
// now, also, the latest for major/minor
|
||||
if (version != null) {
|
||||
T latest = null;
|
||||
CachedCanonicalResource<T> latest = null;
|
||||
for (CachedCanonicalResource<T> t : rl) {
|
||||
if (VersionUtilities.versionsCompatible(t.getResource().getVersion(), version)) {
|
||||
latest = t.getResource();
|
||||
if (VersionUtilities.versionsCompatible(t.getVersion(), version)) {
|
||||
latest = t;
|
||||
}
|
||||
}
|
||||
if (latest != null) { // might be null if it's not using semver
|
||||
String lv = VersionUtilities.getMajMin(latest.getVersion());
|
||||
if (lv != null && !lv.equals(version))
|
||||
map.put(url+"|"+lv, rl.get(rl.size()-1).getResource());
|
||||
map.put(url+"|"+lv, rl.get(rl.size()-1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -167,7 +261,7 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
|
||||
|
||||
|
||||
public T get(String url) {
|
||||
return map.get(url);
|
||||
return map.containsKey(url) ? map.get(url).getResource() : null;
|
||||
}
|
||||
|
||||
public boolean has(String url) {
|
||||
@ -179,10 +273,10 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
|
||||
return get(system);
|
||||
} else {
|
||||
if (map.containsKey(system+"|"+version))
|
||||
return map.get(system+"|"+version);
|
||||
return map.get(system+"|"+version).getResource();
|
||||
String mm = VersionUtilities.getMajMin(version);
|
||||
if (mm != null)
|
||||
return map.get(system+"|"+mm);
|
||||
if (mm != null && map.containsKey(system+"|"+mm))
|
||||
return map.get(system+"|"+mm).getResource();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ public interface IWorkerContext {
|
||||
|
||||
public interface IContextResourceLoader {
|
||||
Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException;
|
||||
|
||||
Resource loadResource(InputStream stream, boolean isJson) throws FHIRException, IOException;
|
||||
String[] getTypes();
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,9 @@ import org.hl7.fhir.exceptions.FHIRException;
|
||||
import org.hl7.fhir.exceptions.FHIRFormatError;
|
||||
import org.hl7.fhir.r5.conformance.ProfileUtilities;
|
||||
import org.hl7.fhir.r5.conformance.ProfileUtilities.ProfileKnowledgeProvider;
|
||||
import org.hl7.fhir.r5.context.CanonicalResourceManager.CanonicalResourceProxy;
|
||||
import org.hl7.fhir.r5.context.IWorkerContext.ILoggingService.LogCategory;
|
||||
import org.hl7.fhir.r5.context.SimpleWorkerContext.PackageResourceLoader;
|
||||
import org.hl7.fhir.r5.formats.IParser;
|
||||
import org.hl7.fhir.r5.formats.JsonParser;
|
||||
import org.hl7.fhir.r5.formats.ParserType;
|
||||
@ -76,7 +78,11 @@ import org.hl7.fhir.r5.utils.IResourceValidator;
|
||||
import org.hl7.fhir.utilities.CSFileInputStream;
|
||||
import org.hl7.fhir.utilities.TextFile;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
import org.hl7.fhir.utilities.VersionUtilities;
|
||||
import org.hl7.fhir.utilities.cache.BasePackageCacheManager;
|
||||
import org.hl7.fhir.utilities.cache.FilesystemPackageCacheManager;
|
||||
import org.hl7.fhir.utilities.cache.NpmPackage;
|
||||
import org.hl7.fhir.utilities.cache.NpmPackage.PackageResourceInformation;
|
||||
import org.hl7.fhir.utilities.i18n.I18nConstants;
|
||||
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
||||
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType;
|
||||
@ -92,10 +98,39 @@ import ca.uhn.fhir.parser.DataFormatException;
|
||||
|
||||
public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerContext, ProfileKnowledgeProvider {
|
||||
|
||||
public class PackageResourceLoader extends CanonicalResourceProxy {
|
||||
|
||||
private String filename;
|
||||
private IContextResourceLoader loader;
|
||||
|
||||
public PackageResourceLoader(PackageResourceInformation pri, IContextResourceLoader loader) {
|
||||
super(pri.getType(), pri.getId(), pri.getUrl(),pri.getVersion());
|
||||
this.filename = pri.getFilename();
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CanonicalResource loadResource() {
|
||||
try {
|
||||
FileInputStream f = new FileInputStream(filename);
|
||||
try {
|
||||
if (loader != null) {
|
||||
return (CanonicalResource) loader.loadResource(f, true);
|
||||
} else {
|
||||
return (CanonicalResource) new JsonParser().parse(f);
|
||||
}
|
||||
} finally {
|
||||
f.close();
|
||||
}
|
||||
} catch (FHIRFormatError | IOException e) {
|
||||
throw new FHIRException("Error loading "+filename+": "+e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface ILoadFilter {
|
||||
|
||||
boolean isOkToLoad(Resource resource);
|
||||
|
||||
boolean isOkToLoad(String resourceType);
|
||||
}
|
||||
|
||||
public interface IValidatorFactory {
|
||||
@ -109,7 +144,7 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
|
||||
private boolean ignoreProfileErrors;
|
||||
private boolean progress;
|
||||
private List<String> loadedPackages = new ArrayList<String>();
|
||||
|
||||
|
||||
public SimpleWorkerContext() throws FileNotFoundException, IOException, FHIRException {
|
||||
super();
|
||||
}
|
||||
@ -138,6 +173,11 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
|
||||
validatorFactory = other.validatorFactory;
|
||||
}
|
||||
|
||||
|
||||
public List<String> getLoadedPackages() {
|
||||
return loadedPackages;
|
||||
}
|
||||
|
||||
// -- Initializations
|
||||
/**
|
||||
* Load the working context from the validation pack
|
||||
@ -157,12 +197,9 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
|
||||
}
|
||||
|
||||
public static SimpleWorkerContext fromPackage(NpmPackage pi, boolean allowDuplicates) throws FileNotFoundException, IOException, FHIRException {
|
||||
return fromPackage(pi, allowDuplicates, null);
|
||||
}
|
||||
public static SimpleWorkerContext fromPackage(NpmPackage pi, boolean allowDuplicates, ILoadFilter filter) throws FileNotFoundException, IOException, FHIRException {
|
||||
SimpleWorkerContext res = new SimpleWorkerContext();
|
||||
res.setAllowLoadingDuplicates(allowDuplicates);
|
||||
res.loadFromPackage(pi, null, filter);
|
||||
res.loadFromPackage(pi, null);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -173,14 +210,10 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
|
||||
}
|
||||
|
||||
public static SimpleWorkerContext fromPackage(NpmPackage pi, IContextResourceLoader loader) throws FileNotFoundException, IOException, FHIRException {
|
||||
return fromPackage(pi, loader, null);
|
||||
}
|
||||
|
||||
public static SimpleWorkerContext fromPackage(NpmPackage pi, IContextResourceLoader loader, ILoadFilter filter) throws FileNotFoundException, IOException, FHIRException {
|
||||
SimpleWorkerContext res = new SimpleWorkerContext();
|
||||
res.setAllowLoadingDuplicates(true);
|
||||
res.version = pi.getNpm().get("version").getAsString();
|
||||
res.loadFromPackage(pi, loader, filter);
|
||||
res.loadFromPackage(pi, loader);
|
||||
res.finishLoading();
|
||||
return res;
|
||||
}
|
||||
@ -323,37 +356,62 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
|
||||
loadFromStream(new CSFileInputStream(path), loader);
|
||||
}
|
||||
|
||||
public void loadFromPackage(NpmPackage pi, IContextResourceLoader loader, ILoadFilter filter) throws IOException {
|
||||
// public void loadFromPackage(NpmPackage pi, IContextResourceLoader loader, ILoadFilter filter) throws IOException {
|
||||
// if (progress) {
|
||||
// System.out.println("Load Package "+pi.name()+"#"+pi.version());
|
||||
// }
|
||||
// loadedPackages.add(pi.id()+"#"+pi.version());
|
||||
// String [] types = loader != null ? loader.getTypes() : new String[] { "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem" };
|
||||
// for (PackageResourceInformation pri : pi.listIndexedResources(types)) {
|
||||
// try {
|
||||
// registerResourceFromPackage(new PackageResourceLoader(pri, loader), new PackageVersion(pi.id(), pi.version()));
|
||||
// } catch (FHIRException e) {
|
||||
// throw new FHIRException(formatMessage(I18nConstants.ERROR_READING__FROM_PACKAGE__, pri.getFilename(), pi.name(), pi.version(), e.getMessage()), e);
|
||||
// }
|
||||
// }
|
||||
// for (String s : pi.list("other")) {
|
||||
// binaries.put(s, TextFile.streamToBytes(pi.load("other", s)));
|
||||
// }
|
||||
// if (version == null) {
|
||||
// version = pi.version();
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void loadFromPackage(NpmPackage pi, IContextResourceLoader loader, String... types) throws FileNotFoundException, IOException, FHIRException {
|
||||
if (progress) {
|
||||
System.out.println("Load Package "+pi.name()+"#"+pi.version());
|
||||
}
|
||||
loadedPackages.add(pi.id()+"#"+pi.version());
|
||||
for (String s : pi.listResources(loader.getTypes())) {
|
||||
try {
|
||||
loadDefinitionItem(s, pi.load("package", s), loader, filter, new PackageVersion(pi.id(), pi.version()));
|
||||
} catch (FHIRException | IOException e) {
|
||||
throw new FHIRException(formatMessage(I18nConstants.ERROR_READING__FROM_PACKAGE__, s, pi.name(), pi.version(), e.getMessage()), e);
|
||||
|
||||
|
||||
if (types.length == 0 && loader != null) {
|
||||
types = loader.getTypes();
|
||||
}
|
||||
if (VersionUtilities.isR2Ver(pi.fhirVersion())) {
|
||||
// can't lazy load R2 because of valueset/codesystem implementation
|
||||
if (types.length == 0) {
|
||||
types = new String[] { "StructureDefinition", "ValueSet", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem" };
|
||||
}
|
||||
for (String s : pi.listResources(loader.getTypes())) {
|
||||
try {
|
||||
loadDefinitionItem(s, pi.load("package", s), loader, null, new PackageVersion(pi.id(), pi.version()));
|
||||
} catch (FHIRException e) {
|
||||
throw new FHIRException(formatMessage(I18nConstants.ERROR_READING__FROM_PACKAGE__, s, pi.name(), pi.version(), e.getMessage()), e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (types.length == 0) {
|
||||
types = new String[] { "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem" };
|
||||
}
|
||||
for (PackageResourceInformation pri : pi.listIndexedResources(types)) {
|
||||
try {
|
||||
registerResourceFromPackage(new PackageResourceLoader(pri, loader), new PackageVersion(pi.id(), pi.version()));
|
||||
} catch (FHIRException e) {
|
||||
throw new FHIRException(formatMessage(I18nConstants.ERROR_READING__FROM_PACKAGE__, pri.getFilename(), pi.name(), pi.version(), e.getMessage()), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String s : pi.list("other")) {
|
||||
binaries.put(s, TextFile.streamToBytes(pi.load("other", s)));
|
||||
}
|
||||
if (version == null) {
|
||||
version = pi.version();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFromPackage(NpmPackage pi, IContextResourceLoader loader, String... types) throws FileNotFoundException, IOException, FHIRException {
|
||||
if (progress) {
|
||||
System.out.println("Load Package "+pi.name()+"#"+pi.version());
|
||||
}
|
||||
loadedPackages.add(pi.id()+"#"+pi.version());
|
||||
if (types.length == 0)
|
||||
types = new String[] { "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem" };
|
||||
for (String s : pi.listResources(types)) {
|
||||
loadDefinitionItem(s, pi.load("package", s), loader, null, new PackageVersion(pi.id(), pi.version()));
|
||||
}
|
||||
for (String s : pi.list("other")) {
|
||||
binaries.put(s, TextFile.streamToBytes(pi.load("other", s)));
|
||||
}
|
||||
|
@ -83,6 +83,9 @@ import org.hl7.fhir.r5.model.CodeSystem;
|
||||
import org.hl7.fhir.r5.model.CodeSystem.CodeSystemContentMode;
|
||||
import org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent;
|
||||
import org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionDesignationComponent;
|
||||
import org.hl7.fhir.r5.model.CodeSystem.ConceptPropertyComponent;
|
||||
import org.hl7.fhir.r5.model.CodeSystem.PropertyComponent;
|
||||
import org.hl7.fhir.r5.model.CodeSystem.PropertyType;
|
||||
import org.hl7.fhir.r5.model.DataType;
|
||||
import org.hl7.fhir.r5.model.DateTimeType;
|
||||
import org.hl7.fhir.r5.model.Enumerations.FilterOperator;
|
||||
@ -101,11 +104,75 @@ import org.hl7.fhir.r5.model.ValueSet.ValueSetComposeComponent;
|
||||
import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent;
|
||||
import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent;
|
||||
import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionParameterComponent;
|
||||
import org.hl7.fhir.r5.terminologies.ValueSetExpanderSimple.AllConceptsFilter;
|
||||
import org.hl7.fhir.r5.terminologies.ValueSetExpanderSimple.IConceptFilter;
|
||||
import org.hl7.fhir.r5.terminologies.ValueSetExpanderSimple.PropertyFilter;
|
||||
import org.hl7.fhir.r5.utils.ToolingExtensions;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
|
||||
public class ValueSetExpanderSimple implements ValueSetExpander {
|
||||
|
||||
public class PropertyFilter implements IConceptFilter {
|
||||
|
||||
private ConceptSetFilterComponent filter;
|
||||
private PropertyComponent property;
|
||||
|
||||
public PropertyFilter(ConceptSetFilterComponent fc, PropertyComponent propertyDefinition) {
|
||||
this.filter = fc;
|
||||
this.property = propertyDefinition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includeConcept(CodeSystem cs, ConceptDefinitionComponent def) {
|
||||
ConceptPropertyComponent pc = getPropertyForConcept(def);
|
||||
if (pc != null) {
|
||||
String v = pc.getValue().isPrimitive() ? pc.getValue().primitiveValue() : null;
|
||||
switch (filter.getOp()) {
|
||||
case DESCENDENTOF: throw new FHIRException("not supported yet");
|
||||
case EQUAL: return filter.getValue().equals(v);
|
||||
case EXISTS: throw new FHIRException("not supported yet");
|
||||
case GENERALIZES: throw new FHIRException("not supported yet");
|
||||
case IN: throw new FHIRException("not supported yet");
|
||||
case ISA: throw new FHIRException("not supported yet");
|
||||
case ISNOTA: throw new FHIRException("not supported yet");
|
||||
case NOTIN: throw new FHIRException("not supported yet");
|
||||
case NULL: throw new FHIRException("not supported yet");
|
||||
case REGEX: throw new FHIRException("not supported yet");
|
||||
default:
|
||||
throw new FHIRException("Shouldn't get here");
|
||||
}
|
||||
} else if (property.getType() == PropertyType.BOOLEAN && filter.getOp() == FilterOperator.EQUAL) {
|
||||
return "false".equals(filter.getValue());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private ConceptPropertyComponent getPropertyForConcept(ConceptDefinitionComponent def) {
|
||||
for (ConceptPropertyComponent pc : def.getProperty()) {
|
||||
if (pc.getCode().equals(property.getCode())) {
|
||||
return pc;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class AllConceptsFilter implements IConceptFilter {
|
||||
|
||||
@Override
|
||||
public boolean includeConcept(CodeSystem cs, ConceptDefinitionComponent def) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IConceptFilter {
|
||||
|
||||
boolean includeConcept(CodeSystem cs, ConceptDefinitionComponent def);
|
||||
|
||||
}
|
||||
|
||||
private List<ValueSetExpansionContainsComponent> codes = new ArrayList<ValueSet.ValueSetExpansionContainsComponent>();
|
||||
private List<ValueSetExpansionContainsComponent> roots = new ArrayList<ValueSet.ValueSetExpansionContainsComponent>();
|
||||
private Map<String, ValueSetExpansionContainsComponent> map = new HashMap<String, ValueSet.ValueSetExpansionContainsComponent>();
|
||||
@ -214,7 +281,7 @@ public class ValueSetExpanderSimple implements ValueSetExpander {
|
||||
return list;
|
||||
}
|
||||
|
||||
private void addCodeAndDescendents(CodeSystem cs, String system, ConceptDefinitionComponent def, ValueSetExpansionContainsComponent parent, Parameters expParams, List<ValueSet> filters, ConceptDefinitionComponent exclusion) throws FHIRException {
|
||||
private void addCodeAndDescendents(CodeSystem cs, String system, ConceptDefinitionComponent def, ValueSetExpansionContainsComponent parent, Parameters expParams, List<ValueSet> filters, ConceptDefinitionComponent exclusion, IConceptFilter filterFunc) throws FHIRException {
|
||||
def.checkNoModifiers("Code in Code System", "expanding");
|
||||
if (exclusion != null) {
|
||||
if (exclusion.getCode().equals(def.getCode()))
|
||||
@ -224,24 +291,25 @@ public class ValueSetExpanderSimple implements ValueSetExpander {
|
||||
ValueSetExpansionContainsComponent np = null;
|
||||
boolean abs = CodeSystemUtilities.isNotSelectable(cs, def);
|
||||
boolean inc = CodeSystemUtilities.isInactive(cs, def);
|
||||
if (includeAbstract || !abs)
|
||||
if ((includeAbstract || !abs) && filterFunc.includeConcept(cs, def)) {
|
||||
np = addCode(system, def.getCode(), def.getDisplay(), parent, def.getDesignation(), expParams, abs, inc, filters);
|
||||
}
|
||||
for (ConceptDefinitionComponent c : def.getConcept()) {
|
||||
addCodeAndDescendents(cs, system, c, np, expParams, filters, exclusion);
|
||||
addCodeAndDescendents(cs, system, c, np, expParams, filters, exclusion, filterFunc);
|
||||
}
|
||||
if (def.hasUserData(CodeSystemUtilities.USER_DATA_CROSS_LINK)) {
|
||||
List<ConceptDefinitionComponent> children = (List<ConceptDefinitionComponent>) def.getUserData(CodeSystemUtilities.USER_DATA_CROSS_LINK);
|
||||
for (ConceptDefinitionComponent c : children)
|
||||
addCodeAndDescendents(cs, system, c, np, expParams, filters, exclusion);
|
||||
addCodeAndDescendents(cs, system, c, np, expParams, filters, exclusion, filterFunc);
|
||||
}
|
||||
} else {
|
||||
for (ConceptDefinitionComponent c : def.getConcept()) {
|
||||
addCodeAndDescendents(cs, system, c, null, expParams, filters, exclusion);
|
||||
addCodeAndDescendents(cs, system, c, null, expParams, filters, exclusion, filterFunc);
|
||||
}
|
||||
if (def.hasUserData(CodeSystemUtilities.USER_DATA_CROSS_LINK)) {
|
||||
List<ConceptDefinitionComponent> children = (List<ConceptDefinitionComponent>) def.getUserData(CodeSystemUtilities.USER_DATA_CROSS_LINK);
|
||||
for (ConceptDefinitionComponent c : children)
|
||||
addCodeAndDescendents(cs, system, c, null, expParams, filters, exclusion);
|
||||
addCodeAndDescendents(cs, system, c, null, expParams, filters, exclusion, filterFunc);
|
||||
}
|
||||
}
|
||||
|
||||
@ -517,7 +585,7 @@ public class ValueSetExpanderSimple implements ValueSetExpander {
|
||||
if (inc.getConcept().size() == 0 && inc.getFilter().size() == 0) {
|
||||
// special case - add all the code system
|
||||
for (ConceptDefinitionComponent def : cs.getConcept()) {
|
||||
addCodeAndDescendents(cs, inc.getSystem(), def, null, expParams, imports, null);
|
||||
addCodeAndDescendents(cs, inc.getSystem(), def, null, expParams, imports, null, new AllConceptsFilter());
|
||||
}
|
||||
if (cs.getContent() == CodeSystemContentMode.FRAGMENT) {
|
||||
addFragmentWarning(exp, cs);
|
||||
@ -556,14 +624,14 @@ public class ValueSetExpanderSimple implements ValueSetExpander {
|
||||
ConceptDefinitionComponent def = getConceptForCode(cs.getConcept(), fc.getValue());
|
||||
if (def == null)
|
||||
throw new TerminologyServiceException("Code '" + fc.getValue() + "' not found in system '" + inc.getSystem() + "'");
|
||||
addCodeAndDescendents(cs, inc.getSystem(), def, null, expParams, imports, null);
|
||||
addCodeAndDescendents(cs, inc.getSystem(), def, null, expParams, imports, null, new AllConceptsFilter());
|
||||
} else if ("concept".equals(fc.getProperty()) && fc.getOp() == FilterOperator.ISNOTA) {
|
||||
// special: all codes in the target code system that are not under the value
|
||||
ConceptDefinitionComponent defEx = getConceptForCode(cs.getConcept(), fc.getValue());
|
||||
if (defEx == null)
|
||||
throw new TerminologyServiceException("Code '" + fc.getValue() + "' not found in system '" + inc.getSystem() + "'");
|
||||
for (ConceptDefinitionComponent def : cs.getConcept()) {
|
||||
addCodeAndDescendents(cs, inc.getSystem(), def, null, expParams, imports, defEx);
|
||||
addCodeAndDescendents(cs, inc.getSystem(), def, null, expParams, imports, defEx, new AllConceptsFilter());
|
||||
}
|
||||
} else if ("concept".equals(fc.getProperty()) && fc.getOp() == FilterOperator.DESCENDENTOF) {
|
||||
// special: all codes in the target code system under the value
|
||||
@ -571,11 +639,11 @@ public class ValueSetExpanderSimple implements ValueSetExpander {
|
||||
if (def == null)
|
||||
throw new TerminologyServiceException("Code '" + fc.getValue() + "' not found in system '" + inc.getSystem() + "'");
|
||||
for (ConceptDefinitionComponent c : def.getConcept())
|
||||
addCodeAndDescendents(cs, inc.getSystem(), c, null, expParams, imports, null);
|
||||
addCodeAndDescendents(cs, inc.getSystem(), c, null, expParams, imports, null, new AllConceptsFilter());
|
||||
if (def.hasUserData(CodeSystemUtilities.USER_DATA_CROSS_LINK)) {
|
||||
List<ConceptDefinitionComponent> children = (List<ConceptDefinitionComponent>) def.getUserData(CodeSystemUtilities.USER_DATA_CROSS_LINK);
|
||||
for (ConceptDefinitionComponent c : children)
|
||||
addCodeAndDescendents(cs, inc.getSystem(), c, null, expParams, imports, null);
|
||||
addCodeAndDescendents(cs, inc.getSystem(), c, null, expParams, imports, null, new AllConceptsFilter());
|
||||
}
|
||||
|
||||
} else if ("display".equals(fc.getProperty()) && fc.getOp() == FilterOperator.EQUAL) {
|
||||
@ -590,11 +658,34 @@ public class ValueSetExpanderSimple implements ValueSetExpander {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
} else if (isDefinedProperty(cs, fc.getProperty())) {
|
||||
for (ConceptDefinitionComponent def : cs.getConcept()) {
|
||||
addCodeAndDescendents(cs, inc.getSystem(), def, null, expParams, imports, null, new PropertyFilter(fc, getPropertyDefinition(cs, fc.getProperty())));
|
||||
}
|
||||
} else {
|
||||
throw new NotImplementedException("Search by property[" + fc.getProperty() + "] and op[" + fc.getOp() + "] is not supported yet");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PropertyComponent getPropertyDefinition(CodeSystem cs, String property) {
|
||||
for (PropertyComponent cp : cs.getProperty()) {
|
||||
if (cp.getCode().equals(property)) {
|
||||
return cp;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isDefinedProperty(CodeSystem cs, String property) {
|
||||
for (PropertyComponent cp : cs.getProperty()) {
|
||||
if (cp.getCode().equals(property)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void addFragmentWarning(ValueSetExpansionComponent exp, CodeSystem cs) {
|
||||
for (Extension ex : cs.getExtensionsByUrl(ToolingExtensions.EXT_EXP_FRAGMENT)) {
|
||||
if (ex.getValue().primitiveValue().equals(cs.getUrl())) {
|
||||
|
@ -1,13 +1,30 @@
|
||||
package org.hl7.fhir.r5.test;
|
||||
|
||||
import org.hl7.fhir.r5.context.CanonicalResourceManager;
|
||||
import org.hl7.fhir.r5.context.CanonicalResourceManager.CanonicalResourceProxy;
|
||||
import org.hl7.fhir.r5.context.IWorkerContext.PackageVersion;
|
||||
import org.hl7.fhir.r5.model.CanonicalResource;
|
||||
import org.hl7.fhir.r5.model.ValueSet;
|
||||
import org.hl7.fhir.r5.test.CanonicalResourceManagerTester.DeferredLoadTestResource;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class CanonicalResourceManagerTester {
|
||||
|
||||
public class DeferredLoadTestResource extends CanonicalResourceProxy {
|
||||
private CanonicalResource resource;
|
||||
|
||||
public DeferredLoadTestResource(CanonicalResource resource) {
|
||||
super(resource.fhirType(), resource.getId(), resource.getUrl(), resource.getVersion());
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CanonicalResource loadResource() {
|
||||
return resource;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleNoVersion() {
|
||||
CanonicalResourceManager<ValueSet> mrm = new CanonicalResourceManager<>(true);
|
||||
@ -157,8 +174,7 @@ public class CanonicalResourceManagerTester {
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0"));
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
|
||||
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -422,4 +438,376 @@ public class CanonicalResourceManagerTester {
|
||||
Assertions.assertTrue(mrm.get("http://terminology.hl7.org/ValueSet/234").getName().equals("2"));
|
||||
Assertions.assertNull(mrm.get("http://terminology.hl7.org/ValueSet/234", "2.0.0")); // this will get dropped completely because of UTG rules
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleNoVersionDeferredLoad() {
|
||||
CanonicalResourceManager<ValueSet> mrm = new CanonicalResourceManager<>(true);
|
||||
ValueSet vs = new ValueSet();
|
||||
vs.setId("2345");
|
||||
vs.setUrl("http://url/ValueSet/234");
|
||||
// no version
|
||||
DeferredLoadTestResource vsd = new DeferredLoadTestResource(vs);
|
||||
|
||||
mrm.clear();
|
||||
mrm.register(vsd, null);
|
||||
|
||||
Assertions.assertEquals(mrm.size(), 1);
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
|
||||
Assertions.assertNotNull(mrm.get("2345"));
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
|
||||
mrm.register(vsd, null);
|
||||
Assertions.assertEquals(mrm.size(), 1);
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
|
||||
Assertions.assertNotNull(mrm.get("2345"));
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
|
||||
|
||||
mrm.drop("2344");
|
||||
Assertions.assertEquals(mrm.size(), 1);
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
|
||||
Assertions.assertNotNull(mrm.get("2345"));
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
|
||||
|
||||
mrm.drop("2345");
|
||||
Assertions.assertEquals(mrm.size(), 0);
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234"));
|
||||
Assertions.assertNull(mrm.get("2345"));
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleWithVersionDeferredLoad() {
|
||||
CanonicalResourceManager<ValueSet> mrm = new CanonicalResourceManager<>(true);
|
||||
ValueSet vs = new ValueSet();
|
||||
vs.setId("2345");
|
||||
vs.setUrl("http://url/ValueSet/234");
|
||||
vs.setVersion("4.0.1");
|
||||
DeferredLoadTestResource vsd = new DeferredLoadTestResource(vs);
|
||||
|
||||
mrm.clear();
|
||||
mrm.register(vsd, null);
|
||||
|
||||
Assertions.assertNotNull(mrm.get("2345"));
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleWithVersionNotSemVerDeferredLoad() {
|
||||
CanonicalResourceManager<ValueSet> mrm = new CanonicalResourceManager<>(true);
|
||||
ValueSet vs = new ValueSet();
|
||||
vs.setId("2345");
|
||||
vs.setUrl("http://url/ValueSet/234");
|
||||
vs.setVersion("20140403");
|
||||
DeferredLoadTestResource vsd = new DeferredLoadTestResource(vs);
|
||||
|
||||
mrm.clear();
|
||||
mrm.register(vsd, null);
|
||||
|
||||
Assertions.assertNotNull(mrm.get("2345"));
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "20140403"));
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "20140402"));
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "2014"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleWithDuplicateIds1DeferredLoad() {
|
||||
CanonicalResourceManager<ValueSet> mrm = new CanonicalResourceManager<>(false);
|
||||
ValueSet vs1 = new ValueSet();
|
||||
vs1.setId("2345");
|
||||
vs1.setUrl("http://url/ValueSet/234");
|
||||
vs1.setVersion("4.0.1");
|
||||
vs1.setName("1");
|
||||
DeferredLoadTestResource vs1d = new DeferredLoadTestResource(vs1);
|
||||
|
||||
ValueSet vs2 = new ValueSet();
|
||||
vs2.setId("2345");
|
||||
vs2.setUrl("http://url/ValueSet/234");
|
||||
vs2.setVersion("4.0.2");
|
||||
vs2.setName("2");
|
||||
DeferredLoadTestResource vs2d = new DeferredLoadTestResource(vs2);
|
||||
|
||||
mrm.clear();
|
||||
mrm.register(vs1d, null);
|
||||
|
||||
Assertions.assertEquals(mrm.size(), 1);
|
||||
Assertions.assertNotNull(mrm.get("2345"));
|
||||
Assertions.assertEquals(mrm.get("2345").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "1");
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
|
||||
|
||||
mrm.register(vs2d, null);
|
||||
|
||||
Assertions.assertEquals(mrm.size(), 2);
|
||||
Assertions.assertNotNull(mrm.get("2345"));
|
||||
Assertions.assertEquals(mrm.get("2345").getName(), "2");
|
||||
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "2");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "2");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "2");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "2");
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
|
||||
|
||||
mrm.drop("2346"); // doesn't exist;
|
||||
Assertions.assertEquals(mrm.size(), 2);
|
||||
Assertions.assertNotNull(mrm.get("2345"));
|
||||
Assertions.assertNull(mrm.get("2346"));
|
||||
Assertions.assertEquals(mrm.get("2345").getName(), "2");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "2");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "2");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "2");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "2");
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
|
||||
|
||||
mrm.drop("2345"); // vs2;
|
||||
Assertions.assertEquals(mrm.size(), 0);
|
||||
Assertions.assertNull(mrm.get("2345"));
|
||||
Assertions.assertNull(mrm.get("2346"));
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234"));
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0"));
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleWithDuplicateIds2DeferredLoad() {
|
||||
CanonicalResourceManager<ValueSet> mrm = new CanonicalResourceManager<>(true);
|
||||
ValueSet vs1 = new ValueSet();
|
||||
vs1.setId("2345");
|
||||
vs1.setUrl("http://url/ValueSet/234");
|
||||
vs1.setVersion("4.0.1");
|
||||
vs1.setName("1");
|
||||
DeferredLoadTestResource vs1d = new DeferredLoadTestResource(vs1);
|
||||
|
||||
ValueSet vs2 = new ValueSet();
|
||||
vs2.setId("2345");
|
||||
vs2.setUrl("http://url/ValueSet/234");
|
||||
vs2.setVersion("4.0.2");
|
||||
vs2.setName("2");
|
||||
DeferredLoadTestResource vs2d = new DeferredLoadTestResource(vs2);
|
||||
|
||||
mrm.clear();
|
||||
mrm.register(vs1d, null);
|
||||
|
||||
Assertions.assertEquals(mrm.size(), 1);
|
||||
Assertions.assertNotNull(mrm.get("2345"));
|
||||
Assertions.assertEquals(mrm.get("2345").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "1");
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
|
||||
|
||||
mrm.register(vs2d, null);
|
||||
|
||||
Assertions.assertEquals(mrm.size(), 1);
|
||||
Assertions.assertNotNull(mrm.get("2345"));
|
||||
Assertions.assertEquals(mrm.get("2345").getName(), "2");
|
||||
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "2");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "2");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "2");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "2");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "2");
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
|
||||
|
||||
mrm.drop("2345"); // vs2;
|
||||
Assertions.assertEquals(mrm.size(), 0);
|
||||
Assertions.assertNull(mrm.get("2345"));
|
||||
Assertions.assertNull(mrm.get("2346"));
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234"));
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.0"));
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleWithVersions1DeferredLoad() {
|
||||
CanonicalResourceManager<ValueSet> mrm = new CanonicalResourceManager<>(true);
|
||||
ValueSet vs1 = new ValueSet();
|
||||
vs1.setId("2345");
|
||||
vs1.setUrl("http://url/ValueSet/234");
|
||||
vs1.setVersion("4.0.1");
|
||||
vs1.setName("1");
|
||||
DeferredLoadTestResource vs1d = new DeferredLoadTestResource(vs1);
|
||||
|
||||
ValueSet vs2 = new ValueSet();
|
||||
vs2.setId("2346");
|
||||
vs2.setUrl("http://url/ValueSet/234");
|
||||
vs2.setVersion("4.0.2");
|
||||
vs2.setName("2");
|
||||
DeferredLoadTestResource vs2d = new DeferredLoadTestResource(vs2);
|
||||
|
||||
mrm.clear();
|
||||
mrm.register(vs1d, null);
|
||||
|
||||
Assertions.assertEquals(mrm.size(), 1);
|
||||
Assertions.assertNotNull(mrm.get("2345"));
|
||||
Assertions.assertEquals(mrm.get("2345").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "1");
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
|
||||
|
||||
mrm.register(vs2d, null);
|
||||
|
||||
Assertions.assertEquals(mrm.size(), 2);
|
||||
Assertions.assertNotNull(mrm.get("2345"));
|
||||
Assertions.assertEquals(mrm.get("2345").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("2346"));
|
||||
Assertions.assertEquals(mrm.get("2346").getName(), "2");
|
||||
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "2");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "2");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "2");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "2");
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
|
||||
|
||||
mrm.drop("2346"); // vs2;
|
||||
Assertions.assertEquals(mrm.size(), 1);
|
||||
Assertions.assertNotNull(mrm.get("2345"));
|
||||
Assertions.assertNull(mrm.get("2346"));
|
||||
Assertions.assertEquals(mrm.get("2345").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "1");
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleWithVersions2DeferredLoad() {
|
||||
CanonicalResourceManager<ValueSet> mrm = new CanonicalResourceManager<>(true);
|
||||
ValueSet vs1 = new ValueSet();
|
||||
vs1.setId("2345");
|
||||
vs1.setUrl("http://url/ValueSet/234");
|
||||
vs1.setVersion("4.0.1");
|
||||
vs1.setName("1");
|
||||
DeferredLoadTestResource vs1d = new DeferredLoadTestResource(vs1);
|
||||
|
||||
ValueSet vs2 = new ValueSet();
|
||||
vs2.setId("2346");
|
||||
vs2.setUrl("http://url/ValueSet/234");
|
||||
vs2.setVersion("4.0.2");
|
||||
vs2.setName("2");
|
||||
DeferredLoadTestResource vs2d = new DeferredLoadTestResource(vs2);
|
||||
|
||||
mrm.clear();
|
||||
mrm.register(vs1d, null);
|
||||
|
||||
Assertions.assertEquals(mrm.size(), 1);
|
||||
Assertions.assertNotNull(mrm.get("2345"));
|
||||
Assertions.assertEquals(mrm.get("2345").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "1");
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
|
||||
|
||||
mrm.register(vs2d, null);
|
||||
|
||||
Assertions.assertEquals(mrm.size(), 2);
|
||||
Assertions.assertNotNull(mrm.get("2345"));
|
||||
Assertions.assertEquals(mrm.get("2345").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("2346"));
|
||||
Assertions.assertEquals(mrm.get("2346").getName(), "2");
|
||||
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "2");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "2");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "1");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "2");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "2");
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
|
||||
|
||||
mrm.drop("2345"); // vs1;
|
||||
Assertions.assertEquals(mrm.size(), 1);
|
||||
Assertions.assertNull(mrm.get("2345"));
|
||||
Assertions.assertNotNull(mrm.get("2346"));
|
||||
Assertions.assertEquals(mrm.get("2346").getName(), "2");
|
||||
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234").getName(), "2");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.0"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.0").getName(), "2");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.1"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.1").getName(), "2");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0.2"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0.2").getName(), "2");
|
||||
Assertions.assertNotNull(mrm.get("http://url/ValueSet/234", "4.0"));
|
||||
Assertions.assertEquals(mrm.get("http://url/ValueSet/234", "4.0").getName(), "2");
|
||||
Assertions.assertNull(mrm.get("http://url/ValueSet/234", "4.1"));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -72,6 +72,11 @@ public class SnapShotGenerationTests {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource loadResource(InputStream stream, boolean isJson) throws FHIRException, IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getTypes() {
|
||||
return types;
|
||||
|
@ -447,6 +447,10 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
|
||||
return loadPackageFromFile(id, version.substring(5));
|
||||
}
|
||||
|
||||
if (version == null && id.contains("#")) {
|
||||
version = id.substring(id.indexOf("#")+1);
|
||||
id = id.substring(0, id.indexOf("#"));
|
||||
}
|
||||
NpmPackage p = loadPackageFromCacheOnly(id, version);
|
||||
if (p != null) {
|
||||
if ("current".equals(version)) {
|
||||
|
@ -61,6 +61,7 @@ import org.hl7.fhir.exceptions.FHIRException;
|
||||
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
|
||||
import org.hl7.fhir.utilities.TextFile;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
import org.hl7.fhir.utilities.cache.NpmPackage.PackageResourceInformationSorter;
|
||||
import org.hl7.fhir.utilities.cache.PackageGenerator.PackageType;
|
||||
import org.hl7.fhir.utilities.json.JSONUtil;
|
||||
import org.hl7.fhir.utilities.json.JsonTrackingParser;
|
||||
@ -82,6 +83,50 @@ import com.google.gson.JsonObject;
|
||||
*/
|
||||
public class NpmPackage {
|
||||
|
||||
public class PackageResourceInformationSorter implements Comparator<PackageResourceInformation> {
|
||||
@Override
|
||||
public int compare(PackageResourceInformation o1, PackageResourceInformation o2) {
|
||||
return o1.filename.compareTo(o2.filename);
|
||||
}
|
||||
}
|
||||
|
||||
public class PackageResourceInformation {
|
||||
private String id;
|
||||
private String type;
|
||||
private String url;
|
||||
private String version;
|
||||
private String filename;
|
||||
private String supplements;
|
||||
|
||||
public PackageResourceInformation(String root, JsonObject fi) throws IOException {
|
||||
super();
|
||||
id = JSONUtil.str(fi, "id");
|
||||
type = JSONUtil.str(fi, "resourceType");
|
||||
url = JSONUtil.str(fi, "url");
|
||||
version = JSONUtil.str(fi, "version");
|
||||
filename = Utilities.path(root, JSONUtil.str(fi, "filename"));
|
||||
supplements = JSONUtil.str(fi, "supplements");
|
||||
}
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
public String getFilename() {
|
||||
return filename;
|
||||
}
|
||||
public String getSupplements() {
|
||||
return supplements;
|
||||
}
|
||||
|
||||
}
|
||||
public class IndexVersionSorter implements Comparator<JsonObject> {
|
||||
|
||||
@Override
|
||||
@ -489,6 +534,19 @@ public class NpmPackage {
|
||||
return res;
|
||||
}
|
||||
|
||||
public List<PackageResourceInformation> listIndexedResources(String... types) throws IOException {
|
||||
List<PackageResourceInformation> res = new ArrayList<PackageResourceInformation>();
|
||||
NpmPackageFolder folder = folders.get("package");
|
||||
for (JsonElement e : folder.index.getAsJsonArray("files")) {
|
||||
JsonObject fi = e.getAsJsonObject();
|
||||
if (Utilities.existsInList(JSONUtil.str(fi, "resourceType"), types)) {
|
||||
res.add(new PackageResourceInformation(folder.folder.getAbsolutePath(), fi));
|
||||
}
|
||||
}
|
||||
// Collections.sort(res, new PackageResourceInformationSorter());
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* use the name from listResources()
|
||||
*
|
||||
|
@ -44,16 +44,24 @@ public class NpmPackageIndexBuilder {
|
||||
files.add(fi);
|
||||
fi.addProperty("filename", name);
|
||||
fi.addProperty("resourceType", json.get("resourceType").getAsString());
|
||||
if (json.has("id") && json.get("id").isJsonPrimitive())
|
||||
if (json.has("id") && json.get("id").isJsonPrimitive()) {
|
||||
fi.addProperty("id", json.get("id").getAsString());
|
||||
if (json.has("url") && json.get("url").isJsonPrimitive())
|
||||
}
|
||||
if (json.has("url") && json.get("url").isJsonPrimitive()) {
|
||||
fi.addProperty("url", json.get("url").getAsString());
|
||||
if (json.has("version") && json.get("version").isJsonPrimitive())
|
||||
}
|
||||
if (json.has("version") && json.get("version").isJsonPrimitive()) {
|
||||
fi.addProperty("version", json.get("version").getAsString());
|
||||
if (json.has("kind") && json.get("kind").isJsonPrimitive())
|
||||
}
|
||||
if (json.has("kind") && json.get("kind").isJsonPrimitive()) {
|
||||
fi.addProperty("kind", json.get("kind").getAsString());
|
||||
if (json.has("type") && json.get("type").isJsonPrimitive())
|
||||
}
|
||||
if (json.has("type") && json.get("type").isJsonPrimitive()) {
|
||||
fi.addProperty("type", json.get("type").getAsString());
|
||||
}
|
||||
if (json.has("supplements") && json.get("supplements").isJsonPrimitive()) {
|
||||
fi.addProperty("supplements", json.get("supplements").getAsString());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error parsing "+name+": "+e.getMessage());
|
||||
|
@ -6,6 +6,7 @@ import org.hl7.fhir.convertors.loaders.R2016MayToR5Loader;
|
||||
import org.hl7.fhir.convertors.loaders.R2ToR5Loader;
|
||||
import org.hl7.fhir.convertors.loaders.R3ToR5Loader;
|
||||
import org.hl7.fhir.convertors.loaders.R4ToR5Loader;
|
||||
import org.hl7.fhir.convertors.loaders.R5ToR5Loader;
|
||||
import org.hl7.fhir.convertors.txClient.TerminologyClientFactory;
|
||||
import org.hl7.fhir.exceptions.DefinitionException;
|
||||
import org.hl7.fhir.exceptions.FHIRException;
|
||||
@ -38,6 +39,7 @@ import org.hl7.fhir.utilities.TextFile;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
import org.hl7.fhir.utilities.VersionUtilities;
|
||||
import org.hl7.fhir.utilities.cache.NpmPackage;
|
||||
import org.hl7.fhir.utilities.cache.PackageClient;
|
||||
import org.hl7.fhir.utilities.cache.FilesystemPackageCacheManager;
|
||||
import org.hl7.fhir.utilities.cache.ToolsVersion;
|
||||
import org.hl7.fhir.utilities.i18n.I18nBase;
|
||||
@ -259,7 +261,6 @@ public class ValidationEngine implements IValidatorResourceFetcher {
|
||||
private FilesystemPackageCacheManager pcm;
|
||||
private PrintWriter mapLog;
|
||||
private boolean debug;
|
||||
private Set<String> loadedIgs = new HashSet<>();
|
||||
private IValidatorResourceFetcher fetcher;
|
||||
private boolean assumeValidRestReferences;
|
||||
private boolean noExtensibleBindingMessages;
|
||||
@ -368,18 +369,32 @@ public class ValidationEngine implements IValidatorResourceFetcher {
|
||||
}
|
||||
|
||||
private void loadCoreDefinitions(String src, boolean recursive) throws Exception {
|
||||
Map<String, byte[]> source = loadIgSource(src, recursive, true);
|
||||
if (version == null)
|
||||
version = getVersionFromPack(source);
|
||||
context = SimpleWorkerContext.fromDefinitions(source, loaderForVersion(), new PackageVersion(src));
|
||||
if (pcm == null) {
|
||||
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
|
||||
}
|
||||
NpmPackage npm = pcm.loadPackage(src, null);
|
||||
if (npm != null) {
|
||||
version = npm.fhirVersion();
|
||||
context = SimpleWorkerContext.fromPackage(npm, loaderForVersion());
|
||||
} else {
|
||||
Map<String, byte[]> source = loadIgSource(src, recursive, true);
|
||||
if (version == null) {
|
||||
version = getVersionFromPack(source);
|
||||
}
|
||||
context = SimpleWorkerContext.fromDefinitions(source, loaderForVersion(), new PackageVersion(src));
|
||||
grabNatives(source, "http://hl7.org/fhir");
|
||||
}
|
||||
context.setAllowLoadingDuplicates(true); // because of Forge
|
||||
context.setExpansionProfile(makeExpProfile());
|
||||
NpmPackage npm = pcm.loadPackage("hl7.fhir.xver-extensions", "0.0.4");
|
||||
context.loadFromPackage(npm, null);
|
||||
grabNatives(source, "http://hl7.org/fhir");
|
||||
NpmPackage npmX = pcm.loadPackage("hl7.fhir.xver-extensions", "0.0.4");
|
||||
context.loadFromPackage(npmX, null);
|
||||
}
|
||||
|
||||
private IContextResourceLoader loaderForVersion() {
|
||||
return loaderForVersion(version);
|
||||
}
|
||||
|
||||
private IContextResourceLoader loaderForVersion(String version) {
|
||||
if (Utilities.noString(version))
|
||||
return null;
|
||||
if (version.startsWith("1.0"))
|
||||
@ -390,6 +405,8 @@ public class ValidationEngine implements IValidatorResourceFetcher {
|
||||
return new R3ToR5Loader(new String[] { "CapabilityStatement", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire","ConceptMap","StructureMap", "NamingSystem"});
|
||||
if (version.startsWith("4.0"))
|
||||
return new R4ToR5Loader(new String[] { "CapabilityStatement", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire","ConceptMap","StructureMap", "NamingSystem"});
|
||||
if (version.startsWith("5.0"))
|
||||
return new R5ToR5Loader(new String[] { "CapabilityStatement", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire","ConceptMap","StructureMap", "NamingSystem"});
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -590,10 +607,10 @@ public class ValidationEngine implements IValidatorResourceFetcher {
|
||||
}
|
||||
|
||||
public Map<String, byte[]> loadPackage(NpmPackage pi) throws Exception {
|
||||
loadedIgs.add(pi.name()+"#"+pi.version());
|
||||
context.getLoadedPackages().add(pi.name()+"#"+pi.version());
|
||||
Map<String, byte[]> res = new HashMap<String, byte[]>();
|
||||
for (String s : pi.dependencies()) {
|
||||
if (!loadedIgs.contains(s)) {
|
||||
if (! context.getLoadedPackages().contains(s)) {
|
||||
if (!VersionUtilities.isCorePackage(s)) {
|
||||
System.out.println("+ .. load IG from "+s);
|
||||
res.putAll(fetchByPackage(s));
|
||||
@ -752,34 +769,46 @@ public class ValidationEngine implements IValidatorResourceFetcher {
|
||||
}
|
||||
|
||||
public void loadIg(String src, boolean recursive) throws IOException, FHIRException, Exception {
|
||||
String canonical = null;
|
||||
Map<String, byte[]> source = loadIgSource(src, recursive, true);
|
||||
String version = Constants.VERSION;
|
||||
if (this.version != null)
|
||||
version = this.version;
|
||||
if (source.containsKey("version.info"))
|
||||
version = readInfoVersion(source.get("version.info"));
|
||||
|
||||
for (Entry<String, byte[]> t : source.entrySet()) {
|
||||
String fn = t.getKey();
|
||||
if (!exemptFile(fn)) {
|
||||
Resource r = loadFileWithErrorChecking(version, t, fn);
|
||||
if (r != null) {
|
||||
context.cacheResource(r);
|
||||
if (r instanceof ImplementationGuide) {
|
||||
canonical = ((ImplementationGuide) r).getUrl();
|
||||
igs.add((ImplementationGuide) r);
|
||||
if (canonical.contains("/ImplementationGuide/")) {
|
||||
Resource r2 = r.copy();
|
||||
((ImplementationGuide) r2).setUrl(canonical.substring(0, canonical.indexOf("/ImplementationGuide/")));
|
||||
context.cacheResource(r2);
|
||||
NpmPackage npm = pcm.loadPackage(src, null);
|
||||
if (npm != null) {
|
||||
for (String s : npm.dependencies()) {
|
||||
if (!context.getLoadedPackages().contains(s)) {
|
||||
if (!VersionUtilities.isCorePackage(s)) {
|
||||
loadIg(s, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
context.loadFromPackage(npm, loaderForVersion(npm.fhirVersion()));
|
||||
} else {
|
||||
String canonical = null;
|
||||
Map<String, byte[]> source = loadIgSource(src, recursive, true);
|
||||
String version = Constants.VERSION;
|
||||
if (this.version != null)
|
||||
version = this.version;
|
||||
if (source.containsKey("version.info"))
|
||||
version = readInfoVersion(source.get("version.info"));
|
||||
|
||||
for (Entry<String, byte[]> t : source.entrySet()) {
|
||||
String fn = t.getKey();
|
||||
if (!exemptFile(fn)) {
|
||||
Resource r = loadFileWithErrorChecking(version, t, fn);
|
||||
if (r != null) {
|
||||
context.cacheResource(r);
|
||||
if (r instanceof ImplementationGuide) {
|
||||
canonical = ((ImplementationGuide) r).getUrl();
|
||||
igs.add((ImplementationGuide) r);
|
||||
if (canonical.contains("/ImplementationGuide/")) {
|
||||
Resource r2 = r.copy();
|
||||
((ImplementationGuide) r2).setUrl(canonical.substring(0, canonical.indexOf("/ImplementationGuide/")));
|
||||
context.cacheResource(r2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (canonical != null) {
|
||||
grabNatives(source, canonical);
|
||||
if (canonical != null) {
|
||||
grabNatives(source, canonical);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -287,7 +287,7 @@ public class R3R4ConversionTests implements ITransformerServices, IValidatorReso
|
||||
return;
|
||||
|
||||
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
|
||||
R3ToR4Loader ldr = new R3ToR4Loader().setPatchUrls(true).setKillPrimitives(true);
|
||||
R3ToR4Loader ldr = (R3ToR4Loader) new R3ToR4Loader().setPatchUrls(true).setKillPrimitives(true);
|
||||
|
||||
System.out.println("loading R3");
|
||||
contextR3 = new SimpleWorkerContext();
|
||||
|
Loading…
x
Reference in New Issue
Block a user