Merge pull request #1200 from hapifhir/gg-202303-mega-tx-rework

Gg 202303 mega tx rework
This commit is contained in:
Grahame Grieve 2023-04-04 08:25:16 +10:00 committed by GitHub
commit 98204b57b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
89 changed files with 1710 additions and 357 deletions

View File

@ -387,7 +387,7 @@ public class ExtensionDefinitionGenerator {
private List<StructureDefinition> loadSource() throws IOException, FHIRException {
List<StructureDefinition> list = new ArrayList<>();
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
NpmPackage npm = pcm.loadPackage("hl7.fhir.core", sourceVersion.toCode());
if (sourceVersion == FHIRVersion._4_0_0)
context = SimpleWorkerContext.fromPackage(npm);

View File

@ -109,7 +109,7 @@ public class PackageVisitor {
public void visitPackages() throws IOException, ParserConfigurationException, SAXException {
System.out.println("Finding packages");
pc = new PackageClient(PackageServer.primaryServer());
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
Map<String, String> cpidMap = getAllCIPackages();
Set<String> cpidSet = new HashSet<>();
@ -178,7 +178,7 @@ public class PackageVisitor {
processor.processResource(pid+"#current", npm, fv, type, s, TextFile.streamToBytes(npm.load("package", s)));
} catch (Exception e) {
System.out.println("####### Error loading "+pid+"#current["+fv+"]/"+type+" ####### "+e.getMessage());
e.printStackTrace();
// e.printStackTrace();
}
}
}

View File

@ -107,7 +107,7 @@ public class SearchParameterAnalysis implements IPackageVisitorProcessor {
versions.get(version).version = version;
}
try {
if (VersionUtilities.isR5Ver(version)) {
if (VersionUtilities.isR5Plus(version)) {
processR5SP(core, versions.get(version), content);
} else if (VersionUtilities.isR4BVer(version)) {
processR4SP(core, versions.get(version), content);

View File

@ -73,7 +73,7 @@ public abstract class BaseLoaderR5 implements IContextResourceLoader {
}
protected BaseLoaderR5 loaderFactory(NpmPackage npm) throws JsonSyntaxException, IOException {
if (VersionUtilities.isR5Ver(npm.fhirVersion())) {
if (VersionUtilities.isR5Plus(npm.fhirVersion())) {
return new R5ToR5Loader(types, lkp.forNewPackage(npm));
} else if (VersionUtilities.isR4Ver(npm.fhirVersion())) {
return new R4ToR5Loader(types, lkp.forNewPackage(npm), npm.version());

View File

@ -54,9 +54,6 @@ import org.hl7.fhir.r5.model.UriType;
public class R5ToR5Loader extends BaseLoaderR5 {
// TODO Grahame, will this ever be populated? No conversion is being done?
private final List<CodeSystem> cslist = new ArrayList<>();
public R5ToR5Loader(List<String> types, ILoaderKnowledgeProviderR5 lkp) {
super(types, lkp);
}
@ -78,11 +75,6 @@ public class R5ToR5Loader extends BaseLoaderR5 {
b.setType(BundleType.COLLECTION);
b.addEntry().setResource(r5).setFullUrl(r5 instanceof CanonicalResource ? ((CanonicalResource) r5).getUrl() : null);
}
for (CodeSystem cs : cslist) {
BundleEntryComponent be = b.addEntry();
be.setFullUrl(cs.getUrl());
be.setResource(cs);
}
if (killPrimitives) {
List<BundleEntryComponent> remove = new ArrayList<BundleEntryComponent>();
for (BundleEntryComponent be : b.getEntry()) {
@ -113,9 +105,6 @@ public class R5ToR5Loader extends BaseLoaderR5 {
r5 = new XmlParser().parse(stream);
setPath(r5);
if (!cslist.isEmpty()) {
throw new FHIRException("Error: Cannot have included code systems");
}
if (killPrimitives) {
throw new FHIRException("Cannot kill primitives when using deferred loading");
}

View File

@ -0,0 +1,128 @@
package org.hl7.fhir.convertors.loaders.loaderR5;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/*
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 org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.formats.JsonParser;
import org.hl7.fhir.r5.formats.XmlParser;
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.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.ElementDefinition.TypeRefComponent;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
import org.hl7.fhir.r5.model.UriType;
public class R6ToR5Loader extends BaseLoaderR5 {
public R6ToR5Loader(List<String> types, ILoaderKnowledgeProviderR5 lkp) {
super(types, lkp);
}
@Override
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
Resource r5 = null;
if (isJson)
r5 = new JsonParser().parse(stream);
else
r5 = new XmlParser().parse(stream);
Bundle b;
if (r5 instanceof Bundle)
b = (Bundle) r5;
else {
b = new Bundle();
b.setId(UUID.randomUUID().toString().toLowerCase());
b.setType(BundleType.COLLECTION);
b.addEntry().setResource(r5).setFullUrl(r5 instanceof CanonicalResource ? ((CanonicalResource) r5).getUrl() : null);
}
if (killPrimitives) {
List<BundleEntryComponent> remove = new ArrayList<BundleEntryComponent>();
for (BundleEntryComponent be : b.getEntry()) {
if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
StructureDefinition sd = (StructureDefinition) be.getResource();
if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE)
remove.add(be);
}
}
b.getEntry().removeAll(remove);
}
if (patchUrls) {
for (BundleEntryComponent be : b.getEntry()) {
if (be.hasResource()) {
doPatchUrls(be.getResource());
}
}
}
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);
setPath(r5);
if (killPrimitives) {
throw new FHIRException("Cannot kill primitives when using deferred loading");
}
if (patchUrls) {
doPatchUrls(r5);
}
return r5;
}
@Override
public List<CodeSystem> getCodeSystems() {
return new ArrayList<>();
}
@Override
protected String versionString() {
return "5.0";
}
}

View File

@ -228,7 +228,7 @@ public class NpmPackageVersionConverter {
return new org.hl7.fhir.dstu3.formats.JsonParser().composeBytes(VersionConvertorFactory_10_30.convertResource(res));
} else if (VersionUtilities.isR4Ver(version)) {
return new org.hl7.fhir.r4.formats.JsonParser().composeBytes(VersionConvertorFactory_10_40.convertResource(res));
} else if (VersionUtilities.isR5Ver(version)) {
} else if (VersionUtilities.isR5Plus(version)) {
return new org.hl7.fhir.r5.formats.JsonParser().composeBytes(VersionConvertorFactory_10_50.convertResource(res));
}
} else if (VersionUtilities.isR2BVer(currentVersion)) {
@ -242,7 +242,7 @@ public class NpmPackageVersionConverter {
return new org.hl7.fhir.dstu3.formats.JsonParser().composeBytes(VersionConvertorFactory_14_30.convertResource(res));
} else if (VersionUtilities.isR4Ver(version)) {
return new org.hl7.fhir.r4.formats.JsonParser().composeBytes(VersionConvertorFactory_14_40.convertResource(res));
} else if (VersionUtilities.isR5Ver(version)) {
} else if (VersionUtilities.isR5Plus(version)) {
return new org.hl7.fhir.r5.formats.JsonParser().composeBytes(VersionConvertorFactory_14_50.convertResource(res));
}
} else if (VersionUtilities.isR3Ver(currentVersion)) {
@ -256,7 +256,7 @@ public class NpmPackageVersionConverter {
return new org.hl7.fhir.dstu3.formats.JsonParser().composeBytes(res);
} else if (VersionUtilities.isR4Ver(version)) {
return new org.hl7.fhir.r4.formats.JsonParser().composeBytes(VersionConvertorFactory_30_40.convertResource(res));
} else if (VersionUtilities.isR5Ver(version)) {
} else if (VersionUtilities.isR5Plus(version)) {
return new org.hl7.fhir.r5.formats.JsonParser().composeBytes(VersionConvertorFactory_30_50.convertResource(res));
}
} else if (VersionUtilities.isR4Ver(currentVersion)) {
@ -270,10 +270,10 @@ public class NpmPackageVersionConverter {
return new org.hl7.fhir.dstu3.formats.JsonParser().composeBytes(VersionConvertorFactory_30_40.convertResource(res, new BaseAdvisor_30_40(false)));
} else if (VersionUtilities.isR4Ver(version)) {
return new org.hl7.fhir.r4.formats.JsonParser().composeBytes(res);
} else if (VersionUtilities.isR5Ver(version)) {
} else if (VersionUtilities.isR5Plus(version)) {
return new org.hl7.fhir.r5.formats.JsonParser().composeBytes(VersionConvertorFactory_40_50.convertResource(res));
}
} else if (VersionUtilities.isR5Ver(currentVersion)) {
} else if (VersionUtilities.isR5Plus(currentVersion)) {
org.hl7.fhir.r5.model.Resource res = new org.hl7.fhir.r5.formats.JsonParser().parse(cnt);
convertResourceR5(res);
if (VersionUtilities.isR2Ver(version)) {
@ -284,7 +284,7 @@ public class NpmPackageVersionConverter {
return new org.hl7.fhir.dstu3.formats.JsonParser().composeBytes(VersionConvertorFactory_30_50.convertResource(res, new BaseAdvisor_30_50(false)));
} else if (VersionUtilities.isR4Ver(version)) {
return new org.hl7.fhir.r4.formats.JsonParser().composeBytes(VersionConvertorFactory_40_50.convertResource(res));
} else if (VersionUtilities.isR5Ver(version)) {
} else if (VersionUtilities.isR5Plus(version)) {
return new org.hl7.fhir.r5.formats.JsonParser().composeBytes(res);
}
}

View File

@ -16,7 +16,7 @@ public class OIDBasedValueSetImporter {
protected IWorkerContext context;
protected void init() throws FHIRException, IOException {
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
NpmPackage npm = pcm.loadPackage("hl7.fhir.r5.core", "current");
SimpleWorkerContext context = new SimpleWorkerContext.SimpleWorkerContextBuilder().withAllowLoadingDuplicates(true).fromPackage(npm);
context.loadFromPackage(pcm.loadPackage("hl7.terminology"), null);

View File

@ -90,7 +90,7 @@ public class UTGVersionSorter {
private Map<String, CanonicalResource> loadPackageR2(String id) throws IOException {
Map<String, CanonicalResource> res = new HashMap<>();
if (pcm == null) {
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
}
System.out.println("Load " + id);
NpmPackage npm = pcm.loadPackage(id);
@ -104,7 +104,7 @@ public class UTGVersionSorter {
private Map<String, CanonicalResource> loadPackageR3(String id) throws IOException {
Map<String, CanonicalResource> res = new HashMap<>();
if (pcm == null) {
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
}
System.out.println("Load " + id);
NpmPackage npm = pcm.loadPackage(id);
@ -118,7 +118,7 @@ public class UTGVersionSorter {
private Map<String, CanonicalResource> loadPackageR4(String id) throws IOException {
Map<String, CanonicalResource> res = new HashMap<>();
if (pcm == null) {
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
}
System.out.println("Load " + id);
NpmPackage npm = pcm.loadPackage(id);

View File

@ -517,7 +517,7 @@ public class CorePackageVersionConvertor {
if (VersionUtilities.isR3Ver(fhirVersion)) {
if (VersionUtilities.isR4Ver(versionTarget) || VersionUtilities.isR4BVer(versionTarget)) {
return new ContentConverter3to4(fhirVersion);
} else if (VersionUtilities.isR5Ver(versionTarget)) {
} else if (VersionUtilities.isR5Plus(versionTarget)) {
return new ContentConverter3to5(fhirVersion);
} else if (VersionUtilities.isR2Ver(versionTarget)) {
return new ContentConverter3to2(fhirVersion);
@ -527,7 +527,7 @@ public class CorePackageVersionConvertor {
} else if (VersionUtilities.isR2Ver(fhirVersion)) {
if (VersionUtilities.isR4Ver(versionTarget) || VersionUtilities.isR4BVer(versionTarget)) {
return new ContentConverter2to4(fhirVersion);
} else if (VersionUtilities.isR5Ver(versionTarget)) {
} else if (VersionUtilities.isR5Plus(versionTarget)) {
return new ContentConverter2to5(fhirVersion);
} else if (VersionUtilities.isR3Ver(versionTarget)) {
return new ContentConverter2to3(fhirVersion);
@ -535,7 +535,7 @@ public class CorePackageVersionConvertor {
} else if (VersionUtilities.isR2BVer(fhirVersion)) {
if (VersionUtilities.isR4Ver(versionTarget) || VersionUtilities.isR4BVer(versionTarget)) {
return new ContentConverter2Bto4(fhirVersion);
} else if (VersionUtilities.isR5Ver(versionTarget)) {
} else if (VersionUtilities.isR5Plus(versionTarget)) {
return new ContentConverter2Bto5(fhirVersion);
} else if (VersionUtilities.isR3Ver(versionTarget)) {
return new ContentConverter2Bto3(fhirVersion);
@ -543,7 +543,7 @@ public class CorePackageVersionConvertor {
} else if (VersionUtilities.isR4Ver(fhirVersion)) {
if (VersionUtilities.isR3Ver(versionTarget)) {
return new ContentConverter4to3(fhirVersion);
} else if (VersionUtilities.isR5Ver(versionTarget)) {
} else if (VersionUtilities.isR5Plus(versionTarget)) {
return new ContentConverter4to5(fhirVersion);
} else if (VersionUtilities.isR2Ver(versionTarget)) {
return new ContentConverter4to2(fhirVersion);
@ -555,7 +555,7 @@ public class CorePackageVersionConvertor {
} else if (VersionUtilities.isR4BVer(fhirVersion)) {
if (VersionUtilities.isR3Ver(versionTarget)) {
return new ContentConverter4to3(fhirVersion);
} else if (VersionUtilities.isR5Ver(versionTarget)) {
} else if (VersionUtilities.isR5Plus(versionTarget)) {
return new ContentConverter4to5(fhirVersion);
} else if (VersionUtilities.isR4Ver(versionTarget)) {
return new ContentConverter4to4(fhirVersion);
@ -564,7 +564,7 @@ public class CorePackageVersionConvertor {
} else if (VersionUtilities.isR2BVer(versionTarget)) {
return new ContentConverter4to2B(fhirVersion);
}
} else if (VersionUtilities.isR5Ver(fhirVersion)) {
} else if (VersionUtilities.isR5Plus(fhirVersion)) {
if (VersionUtilities.isR4Ver(versionTarget) || VersionUtilities.isR4BVer(versionTarget)) {
return new ContentConverter5to4(fhirVersion);
} else if (VersionUtilities.isR3Ver(versionTarget)) {

View File

@ -51,7 +51,7 @@ public class TerminologyClientFactory {
if (VersionUtilities.isR4BVer(v)) {
return new TerminologyClientR4(checkEndsWith("/r4", url), userAgent);
}
if (VersionUtilities.isR5Ver(v)) {
if (VersionUtilities.isR5Plus(v)) {
return new TerminologyClientR5(checkEndsWith("/r4", url), userAgent); // r4 for now, since the terminology is currently the same
}
throw new Error("The version " + v + " is not currently supported");

View File

@ -26,7 +26,7 @@ class Convertor_Factory_40_50Test {
@BeforeAll
static public void setUp() throws Exception {
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
context = TestingUtilities.getWorkerContext(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1"));
}

View File

@ -210,7 +210,7 @@ public class Analyser {
if (ok) {
if (cd.getValueSet() != null) {
ValueSet vs = definitions.getValuesets().get(cd.getValueSet());
if (vs.hasName() && vs.getName().contains("ColorCodesOrRGB")) {
if (vs != null && vs.hasName() && vs.getName().contains("ColorCodesOrRGB")) {
return false;
}
if (vs != null && vs.hasCompose() && vs.getCompose().getInclude().size() == 1) {

View File

@ -75,7 +75,7 @@ public class JavaCoreGenerator {
Date ddate = new Date();
String date = config.DATE_FORMAT().format(ddate);
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
System.out.println("Cache: "+pcm.getFolder());
System.out.println("Load hl7.fhir."+pid+".core");
NpmPackage npm = pcm.loadPackage("hl7.fhir."+pid+".core", version);

View File

@ -81,7 +81,7 @@ public class TestingUtilities {
if (fcontext == null) {
FilesystemPackageCacheManager pcm;
try {
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1"));
fcontext.setUcumService(new UcumEssenceService(TestingUtilities.resourceNameToFile("ucum", "ucum-essence.xml")));
fcontext.setExpansionProfile(new Parameters());

View File

@ -30,7 +30,7 @@ public class CDARoundTripTests {
@BeforeAll
public void setUp() throws Exception {
context = new SimpleWorkerContext();
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
context.loadFromPackage(pcm.loadPackage("hl7.fhir.core", "current"), null, "StructureDefinition");
context.loadFromPackage(pcm.loadPackage("hl7.fhir.cda", "current"), null, "StructureDefinition");
}

View File

@ -2573,6 +2573,10 @@ public class ProfileUtilities extends TranslatingUtilities {
return element;
}
private String baseSpecUrl() {
return VersionUtilities.getSpecUrl(context.getVersion());
}
public static String processRelativeUrls(String markdown, String webUrl, String basePath, List<String> resourceNames, Set<String> baseFilenames, Set<String> localFilenames, boolean processRelatives) {
if (markdown == null) {
return "";
@ -2600,6 +2604,9 @@ public class ProfileUtilities extends TranslatingUtilities {
if (isLikelySourceURLReference(url, resourceNames, baseFilenames, localFilenames)) {
b.append("](");
b.append(basePath);
if (!basePath.endsWith("/")) {
b.append("/");
}
i = i + 1;
} else {
b.append("](");
@ -2686,28 +2693,6 @@ public class ProfileUtilities extends TranslatingUtilities {
url.startsWith("resource-definitions.html");
}
private String baseSpecUrl() {
if (VersionUtilities.isR5Ver(context.getVersion())) {
return "http://build.fhir.org/";
}
if (VersionUtilities.isR4Ver(context.getVersion())) {
return "http://hl7.org/fhir/R4/";
}
if (VersionUtilities.isR3Ver(context.getVersion())) {
return "http://hl7.org/fhir/STU3/";
}
if (VersionUtilities.isR2BVer(context.getVersion())) {
return "http://hl7.org/fhir/2016May/";
}
if (VersionUtilities.isR2Ver(context.getVersion())) {
return "http://hl7.org/fhir/DSTU2/";
}
if (VersionUtilities.isR4BVer(context.getVersion())) {
return "http://hl7.org/fhir/2021Mar/";
}
return "";
}
private List<ElementDefinition> getSiblings(List<ElementDefinition> list, ElementDefinition current) {
List<ElementDefinition> result = new ArrayList<ElementDefinition>();
String path = current.getPath();

View File

@ -1,87 +0,0 @@
package org.hl7.fhir.r4b.model;
/*
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 org.hl7.fhir.r4b.model.Enumerations.FHIRVersion;
import org.hl7.fhir.utilities.VersionUtilities;
/**
* This enumreation is special, and hand crafted. It only supports a subset of the actual published FHIR versions, those that are still supported.
* @author graha
*
*/
public enum FhirPublication {
NULL,
DSTU1,
DSTU2,
DSTU2016May,
STU3,
R4,
R4B,
R5;
public static FhirPublication fromCode(String v) {
if (VersionUtilities.isR2Ver(v))
return FhirPublication.DSTU2;
if (VersionUtilities.isR2BVer(v))
return FhirPublication.DSTU2016May;
if (VersionUtilities.isR3Ver(v))
return FhirPublication.STU3;
if (VersionUtilities.isR4Ver(v))
return FhirPublication.R4;
if (VersionUtilities.isR4BVer(v))
return FhirPublication.R4B;
if (VersionUtilities.isR5Ver(v))
return FhirPublication.R5;
return null;
}
public String toCode() {
switch (this) {
case DSTU1: return "0.01";
case DSTU2: return "1.0.2";
case DSTU2016May: return "1.4.0";
case STU3: return "3.0.1";
case R4: return "4.0.1";
case R4B: return "4.3.0";
case R5: return "5.0.0";
default:
return "??";
}
}
public static FhirPublication fromVersion(FHIRVersion v) {
return fromCode(v.toCode());
}
}

View File

@ -18,10 +18,10 @@ import org.hl7.fhir.r4b.context.IWorkerContext;
import org.hl7.fhir.r4b.model.Base;
import org.hl7.fhir.r4b.model.DomainResource;
import org.hl7.fhir.r4b.model.Enumerations.FHIRVersion;
import org.hl7.fhir.r4b.model.FhirPublication;
import org.hl7.fhir.r4b.renderers.utils.Resolver.IReferenceResolver;
import org.hl7.fhir.r4b.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r4b.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.utilities.FhirPublication;
import org.hl7.fhir.utilities.MarkDownProcessor;
import org.hl7.fhir.utilities.MarkDownProcessor.Dialect;
import org.hl7.fhir.utilities.Utilities;

View File

@ -23,6 +23,7 @@ import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.VersionUtilities;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode;
import org.hl7.fhir.utilities.npm.ToolsVersion;
import org.hl7.fhir.utilities.tests.BaseTestingUtilities;
import org.w3c.dom.Document;
@ -73,7 +74,7 @@ public class TestingUtilities extends BaseTestingUtilities {
static public Map<String, IWorkerContext> fcontexts;
public static IWorkerContext context() {
return context("4.0.1");
return context("4.3.0");
}
public static IWorkerContext context(String version) {
@ -88,7 +89,7 @@ public class TestingUtilities extends BaseTestingUtilities {
if (!fcontexts.containsKey(v)) {
FilesystemPackageCacheManager pcm;
try {
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
IWorkerContext fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackage(VersionUtilities.packageForVersion(version), version));
fcontext.setUcumService(new UcumEssenceService(TestingUtilities.loadTestResourceStream("ucum", "ucum-essence.xml")));
fcontext.setExpansionProfile(new Parameters());

View File

@ -0,0 +1,69 @@
package org.hl7.fhir.r4b.utils;
import org.hl7.fhir.r4b.model.Base;
import org.hl7.fhir.r4b.model.DataType;
import org.hl7.fhir.r4b.model.Property;
import org.hl7.fhir.r4b.model.Resource;
import org.hl7.fhir.utilities.Utilities;
public class DataTypeVisitor {
public interface IDatatypeVisitor<T extends DataType> {
Class<T> classT();
boolean visit(String path, T node);
}
private boolean anyFalse;
private boolean anyTrue;
private int nodeCount;
private int selectedCount;
public <T extends DataType> void visit(Resource resource, IDatatypeVisitor<T> visitor) {
visitNode(resource.fhirType(), resource, visitor);
}
@SuppressWarnings("unchecked")
private <T extends DataType> void visitNode(String path, Base node, IDatatypeVisitor<T> visitor) {
nodeCount++;
if (node instanceof DataType && visitor.classT().isInstance(node)) {
selectedCount++;
boolean ok = visitor.visit(path, (T) node);
if (ok) {
anyTrue = true;
} else {
anyFalse = true;
}
}
for (Property p : node.children()) {
if (p.isList()) {
int i = 0;
for (Base b : p.getValues()) {
visitNode(path+"."+p.getName()+"["+i+"]", b, visitor);
i++;
}
} else {
for (Base b : p.getValues()) {
visitNode(path+"."+p.getName(), b, visitor);
}
}
}
}
public boolean isAnyFalse() {
return anyFalse;
}
public boolean isAnyTrue() {
return anyTrue;
}
public int getNodeCount() {
return nodeCount;
}
public int getSelectedCount() {
return selectedCount;
}
}

View File

@ -26,7 +26,7 @@ public class CDARoundTripTests {
@BeforeAll
public static void setUp() throws Exception {
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
context = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1"));
fp = new FHIRPathEngine(context);

View File

@ -35,7 +35,7 @@ public class ParsingTests {
}
public static Stream<Arguments> data() throws ParserConfigurationException, IOException, FHIRFormatError, SAXException {
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
npm = pcm.loadPackage("hl7.fhir.r4b.examples", "4.3.0");
List<Arguments> objects = new ArrayList<>();
List<String> names = npm.list("package");

View File

@ -555,7 +555,7 @@ public class SnapShotGenerationTests {
pu.setDebug(test.isDebug());
pu.setIds(test.getSource(), false);
if (!TestingUtilities.context().hasPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER)) {
NpmPackage npm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION).loadPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER);
NpmPackage npm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER).loadPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER);
TestingUtilities.context().loadFromPackage(npm, new TestLoader(new String[]{"StructureDefinition"}), new String[]{"StructureDefinition"});
}
pu.setXver(new XVerExtensionManager(TestingUtilities.context()));

View File

@ -24,7 +24,7 @@ public class StructureMapUtilitiesTest implements ITransformerServices {
@BeforeAll
static public void setUp() throws Exception {
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
context = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1"));
}

View File

@ -24,7 +24,7 @@ public class XmlParserTests {
@BeforeAll
public static void setUp() throws Exception {
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
context = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1"));
fp = new FHIRPathEngine(context);

View File

@ -657,6 +657,30 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
}
return cs;
}
@Override
public CodeSystem fetchSupplementedCodeSystem(String system) {
CodeSystem cs = fetchCodeSystem(system);
if (cs != null) {
List<CodeSystem> supplements = codeSystems.getSupplements(cs);
if (supplements.size() > 0) {
cs = CodeSystemUtilities.mergeSupplements(cs, supplements);
}
}
return cs;
}
@Override
public CodeSystem fetchSupplementedCodeSystem(String system, String version) {
CodeSystem cs = fetchCodeSystem(system, version);
if (cs != null) {
List<CodeSystem> supplements = codeSystems.getSupplements(cs);
if (supplements.size() > 0) {
cs = CodeSystemUtilities.mergeSupplements(cs, supplements);
}
}
return cs;
}
@Override
public boolean supportsSystem(String system) throws TerminologyServiceException {
@ -820,7 +844,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
return res;
}
}
p.setParameter("includeDefinition", false);
p.setParameter("excludeNested", !hierarchical);
if (incompleteOk) {
p.setParameter("incomplete-ok", true);
@ -846,7 +870,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
txCache.cacheExpansion(cacheToken, res, TerminologyCache.TRANSIENT);
return res;
}
if (res.getErrorClass() == TerminologyServiceErrorClass.INTERNAL_ERROR) { // this class is created specifically to say: don't consult the server
if (res.getErrorClass() == TerminologyServiceErrorClass.INTERNAL_ERROR || isNoTerminologyServer()) { // this class is created specifically to say: don't consult the server
return new ValueSetExpansionOutcome(res.getError(), res.getErrorClass());
}
@ -872,7 +896,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
}
res = new ValueSetExpansionOutcome(result).setTxLink(txLog.getLastId());
} catch (Exception e) {
res = new ValueSetExpansionOutcome(e.getMessage() == null ? e.getClass().getName() : e.getMessage(), TerminologyServiceErrorClass.UNKNOWN, allErrors).setTxLink(txLog == null ? null : txLog.getLastId());
res = new ValueSetExpansionOutcome((e.getMessage() == null ? e.getClass().getName() : e.getMessage()), TerminologyServiceErrorClass.UNKNOWN, allErrors).setTxLink(txLog == null ? null : txLog.getLastId());
}
txCache.cacheExpansion(cacheToken, res, TerminologyCache.PERMANENT);
return res;

View File

@ -30,14 +30,16 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
private String id;
private String url;
private String version;
private String supplements;
private CanonicalResource resource;
public CanonicalResourceProxy(String type, String id, String url, String version) {
public CanonicalResourceProxy(String type, String id, String url, String version, String supplements) {
super();
this.type = type;
this.id = id;
this.url = url;
this.version = version;
this.supplements = supplements;
}
public String getType() {
@ -68,6 +70,10 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
return version != null;
}
public String getSupplements() {
return supplements;
}
public CanonicalResource getResource() throws FHIRException {
if (resource == null) {
resource = loadResource();
@ -111,7 +117,7 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
private T1 resource;
private CanonicalResourceProxy proxy;
private PackageInformation packageInfo;
public CachedCanonicalResource(T1 resource, PackageInformation packageInfo) {
super();
this.resource = resource;
@ -159,6 +165,14 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
@Override
public String toString() {
return resource != null ? resource.fhirType()+"/"+resource.getId()+"["+resource.getUrl()+"|"+resource.getVersion()+"]" : proxy.toString();
}
public String supplements() {
if (resource == null) {
return proxy.getSupplements();
} else {
return resource instanceof CodeSystem ? ((CodeSystem) resource).getSupplements() : null;
}
}
}
@ -191,6 +205,7 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
private Map<String, List<CachedCanonicalResource<T>>> listForId = new HashMap<>();
private Map<String, List<CachedCanonicalResource<T>>> listForUrl = new HashMap<>();
private Map<String, CachedCanonicalResource<T>> map = new HashMap<>();
private Map<String, List<CachedCanonicalResource<T>>> supplements = new HashMap<>(); // general index based on CodeSystem.supplements
private String version; // for debugging purposes
@ -288,6 +303,7 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
if (!listForUrl.containsKey(cr.getUrl())) {
listForUrl.put(cr.getUrl(), new ArrayList<>());
}
addToSupplements(cr);
List<CachedCanonicalResource<T>> set = listForUrl.get(cr.getUrl());
set.add(cr);
Collections.sort(set, new MetadataResourceVersionComparator<CachedCanonicalResource<T>>());
@ -324,10 +340,27 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
}
}
private void addToSupplements(CanonicalResourceManager<T>.CachedCanonicalResource<T> cr) {
String surl = cr.supplements();
if (surl != null) {
List<CanonicalResourceManager<T>.CachedCanonicalResource<T>> list = supplements.get(surl);
if (list == null) {
list = new ArrayList<>();
supplements.put(surl, list);
}
list.add(cr);
}
}
public void drop(CachedCanonicalResource<T> cr) {
while (map.values().remove(cr));
while (listForId.values().remove(cr));
while (listForUrl.values().remove(cr));
String surl = cr.supplements();
if (surl != null) {
supplements.get(surl).remove(cr);
}
list.remove(cr);
List<CachedCanonicalResource<T>> set = listForUrl.get(cr.getUrl());
if (set != null) { // it really should be
@ -514,6 +547,54 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
}
}
public List<T> getSupplements(T cr) {
if (cr.hasSourcePackage()) {
List<String> pvl = new ArrayList<>();
pvl.add(cr.getSourcePackage().getVID());
return getSupplements(cr.getUrl(), cr.getVersion(), pvl);
} else {
return getSupplements(cr.getUrl(), cr.getVersion(), null);
}
}
public List<T> getSupplements(String url) {
return getSupplements(url, null, null);
}
public List<T> getSupplements(String url, String version) {
return getSupplements(url, version, null);
}
public List<T> getSupplements(String url, String version, List<String> pvlist) {
boolean possibleMatches = false;
List<T> res = new ArrayList<>();
if (version != null) {
List<CanonicalResourceManager<T>.CachedCanonicalResource<T>> list = supplements.get(url+"|"+version);
if (list != null) {
for (CanonicalResourceManager<T>.CachedCanonicalResource<T> t : list) {
possibleMatches = true;
if (pvlist == null || pvlist.contains(t.getPackageInfo().getVID())) {
res.add(t.getResource());
}
}
}
}
List<CanonicalResourceManager<T>.CachedCanonicalResource<T>> list = supplements.get(url);
if (list != null) {
for (CanonicalResourceManager<T>.CachedCanonicalResource<T> t : list) {
possibleMatches = true;
if (pvlist == null || pvlist.contains(t.getPackageInfo().getVID())) {
res.add(t.getResource());
}
}
}
if (res.isEmpty() && pvlist != null && possibleMatches) {
return getSupplements(url, version, null);
} else {
return res;
}
}
public void clear() {
list.clear();
map.clear();

View File

@ -544,6 +544,14 @@ public interface IWorkerContext {
public CodeSystem fetchCodeSystem(String system);
public CodeSystem fetchCodeSystem(String system, String version);
/**
* Like fetchCodeSystem, except that the context will find any CodeSysetm supplements and merge them into the
* @param system
* @return
*/
public CodeSystem fetchSupplementedCodeSystem(String system);
public CodeSystem fetchSupplementedCodeSystem(String system, String version);
/**
* True if the underlying terminology service provider will do
* expansion and code validation for the terminology. Corresponds

View File

@ -97,7 +97,7 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
private final IContextResourceLoader loader;
public PackageResourceLoader(PackageResourceInformation pri, IContextResourceLoader loader) {
super(pri.getResourceType(), pri.getId(), loader == null ? pri.getUrl() :loader.patchUrl(pri.getUrl(), pri.getResourceType()), pri.getVersion());
super(pri.getResourceType(), pri.getId(), loader == null ? pri.getUrl() :loader.patchUrl(pri.getUrl(), pri.getResourceType()), pri.getVersion(), pri.getSupplements());
this.filename = pri.getFilename();
this.loader = loader;
}

View File

@ -0,0 +1,55 @@
package org.hl7.fhir.r5.elementmodel;
import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.utilities.i18n.LanguageFileProducer;
import org.hl7.fhir.utilities.i18n.LanguageFileProducer.LanguageProducerLanguageSession;
import org.hl7.fhir.utilities.i18n.LanguageFileProducer.TextUnit;
/**
* in here:
* * generateTranslations
* * importFromTranslations
* * stripTranslations
* * switchLanguage
*
* in the validator
*
* @author grahamegrieve
* generateTranslations = -langTransform export -src {src} -tgt {tgt} -dest {dest}
* importFromTranslations = -langTransform import -src {src} -tgt {tgt} -dest {dest}
*/
public class LangaugeUtils {
IWorkerContext context;
public LangaugeUtils(IWorkerContext context) {
super();
this.context = context;
}
public void generateTranslations(Element resource, LanguageProducerLanguageSession session) {
translate(resource, session);
}
private void translate(Element element, LanguageProducerLanguageSession langSession) {
if (element.isPrimitive() && isTranslatable(element)) {
String base = element.primitiveValue();
if (base != null) {
String translation = element.getTranslation(langSession.getTargetLang());
langSession.entry(new TextUnit(element.getPath(), base, translation));
}
}
for (Element c: element.getChildren()) {
translate(c, langSession);
}
}
private boolean isTranslatable(Element element) {
return element.getProperty().isTranslatable();
}
public static boolean matches(String dstLang, String srcLang) {
return dstLang == null ? false : dstLang.equals(srcLang);
}
}

View File

@ -12,6 +12,9 @@ import org.hl7.fhir.r5.model.DataType;
import org.hl7.fhir.r5.model.DomainResource;
import org.hl7.fhir.r5.model.Element;
import org.hl7.fhir.r5.model.Extension;
import org.hl7.fhir.r5.model.Property;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.utilities.Utilities;
public class ExtensionsUtils {
@ -275,4 +278,103 @@ public class ExtensionsUtils {
return result;
}
public static boolean stripExtensions(Element element, String... exceptions) {
return stripExtensions(element, Utilities.strings(exceptions));
}
public static boolean stripExtensions(Element element, List<String> exceptions) {
boolean res = element.getExtension().removeIf(ex -> !exceptions.contains(ex.getUrl()));
if (element instanceof BackboneElement) {
res = ((BackboneElement) element).getModifierExtension().removeIf(ex -> !exceptions.contains(ex.getUrl())) || res;
}
if (element instanceof BackboneElement) {
res = ((BackboneElement) element).getModifierExtension().removeIf(ex -> !exceptions.contains(ex.getUrl())) || res;
}
for (Property p : element.children()) {
for (Base v : p.getValues()) {
if (v instanceof Element) {
res = stripExtensions((Element) v, exceptions) || res;
} else if (v instanceof Element) {
res = stripExtensions((Resource) v, exceptions) || res;
}
}
}
return res;
}
public static boolean stripExtensions(Resource resource, String... exceptions) {
return stripExtensions(resource, Utilities.strings(exceptions));
}
public static boolean stripExtensions(Resource resource, List<String> exceptions) {
boolean res = false;
if (resource instanceof DomainResource) {
res = ((DomainResource) resource).getExtension().removeIf(ex -> !exceptions.contains(ex.getUrl())) ||
((DomainResource) resource).getModifierExtension().removeIf(ex -> !exceptions.contains(ex.getUrl()));
}
for (Property p : resource.children()) {
for (Base v : p.getValues()) {
if (v instanceof Element) {
res = stripExtensions((Element) v, exceptions) || res;
} else if (v instanceof Element) {
res = stripExtensions((Resource) v, exceptions) || res;
}
}
}
return res;
}
public static void copyExtensions(List<Extension> source, List<Extension> dest, String... urls) {
if (source != null && dest != null) {
for (Extension ex : source) {
if (Utilities.existsInList(ex.getUrl(), urls)) {
dest.add(ex.copy());
}
}
}
}
public static DataType getExtensionValue(List<Extension> extensions, String url) {
for (Extension ex : extensions) {
if (ex.getUrl().equals(url)) {
return ex.getValue();
}
}
return null;
}
public static String getExtensionString(List<Extension> extensions, String url) {
for (Extension ex : extensions) {
if (ex.getUrl().equals(url)) {
return ex.getValue().primitiveValue();
}
}
return null;
}
public static Integer getExtensionInteger(List<Extension> extensions, String url) {
for (Extension ex : extensions) {
if (ex.getUrl().equals(url) && ex.hasValueIntegerType()) {
return ex.getValueIntegerType().getValue();
}
}
return null;
}
public static boolean hasExtension(List<Extension> extensions, String url) {
if (extensions == null) {
return false;
}
for (Extension ex : extensions) {
if (ex.getUrl().equals(url)) {
return true;
}
}
return false;
}
}

View File

@ -12021,6 +12021,10 @@ The primary difference between a medicationstatement and a medicationadministrat
* R5 Final QA.
*/
_5_0_0DRAFTFINAL,
/**
* R6 Rolling ci-build.
*/
_6_0_0CIBUILD,
/**
* added to help the parsers
*/
@ -12142,6 +12146,8 @@ The primary difference between a medicationstatement and a medicationadministrat
return _5_0_0SNAPSHOT3;
if ("5.0.0-draft-final".equals(codeString))
return _5_0_0DRAFTFINAL;
if ("6.0.0-cibuild".equals(codeString))
return _6_0_0CIBUILD;
throw new FHIRException("Unknown FHIRVersion code '"+codeString+"'");
}
public static boolean isValidCode(String codeString) {
@ -12208,6 +12214,7 @@ The primary difference between a medicationstatement and a medicationadministrat
case _5_0_0BALLOT: return "5.0.0-ballot";
case _5_0_0SNAPSHOT3: return "5.0.0-snapshot3";
case _5_0_0DRAFTFINAL: return "5.0.0-draft-final";
case _6_0_0CIBUILD: return "6.0.0-cibuild";
case NULL: return null;
default: return "?";
}
@ -12271,6 +12278,7 @@ The primary difference between a medicationstatement and a medicationadministrat
case _5_0_0BALLOT: return "http://hl7.org/fhir/FHIR-version";
case _5_0_0SNAPSHOT3: return "http://hl7.org/fhir/FHIR-version";
case _5_0_0DRAFTFINAL: return "http://hl7.org/fhir/FHIR-version";
case _6_0_0CIBUILD: return "http://hl7.org/fhir/FHIR-version";
case NULL: return null;
default: return "?";
}
@ -12334,6 +12342,7 @@ The primary difference between a medicationstatement and a medicationadministrat
case _5_0_0BALLOT: return "R5 Ballot.";
case _5_0_0SNAPSHOT3: return "R5 January 2023 Staging Release + Connectathon 32.";
case _5_0_0DRAFTFINAL: return "R5 Final QA.";
case _6_0_0CIBUILD: return "R6 Rolling ci-build.";
case NULL: return null;
default: return "?";
}
@ -12397,6 +12406,7 @@ The primary difference between a medicationstatement and a medicationadministrat
case _5_0_0BALLOT: return "5.0.0-ballot";
case _5_0_0SNAPSHOT3: return "5.0.0-snapshot3";
case _5_0_0DRAFTFINAL: return "5.0.0-draft-final";
case _6_0_0CIBUILD: return "6.0.0-cibuild";
case NULL: return null;
default: return "?";
}
@ -12539,6 +12549,8 @@ The primary difference between a medicationstatement and a medicationadministrat
return FHIRVersion._5_0_0SNAPSHOT3;
if ("5.0.0-draft-final".equals(codeString))
return FHIRVersion._5_0_0DRAFTFINAL;
if ("6.0.0-cibuild".equals(codeString))
return FHIRVersion._6_0_0CIBUILD;
throw new IllegalArgumentException("Unknown FHIRVersion code '"+codeString+"'");
}
@ -12664,6 +12676,8 @@ The primary difference between a medicationstatement and a medicationadministrat
return new Enumeration<FHIRVersion>(this, FHIRVersion._5_0_0SNAPSHOT3, code);
if ("5.0.0-draft-final".equals(codeString))
return new Enumeration<FHIRVersion>(this, FHIRVersion._5_0_0DRAFTFINAL, code);
if ("6.0.0-cibuild".equals(codeString))
return new Enumeration<FHIRVersion>(this, FHIRVersion._6_0_0CIBUILD, code);
throw new FHIRException("Unknown FHIRVersion code '"+codeString+"'");
}
public String toCode(FHIRVersion code) {
@ -12781,6 +12795,8 @@ The primary difference between a medicationstatement and a medicationadministrat
return "5.0.0-snapshot3";
if (code == FHIRVersion._5_0_0DRAFTFINAL)
return "5.0.0-draft-final";
if (code == FHIRVersion._6_0_0CIBUILD)
return "6.0.0-cibuild";
return "?";
}
public String toSystem(FHIRVersion code) {

View File

@ -68,6 +68,11 @@ public class Extension extends BaseExtension implements IBaseExtension<Extension
@Description(shortDefinition="Value of extension", formalDefinition="Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list)." )
protected DataType value;
@Override
public String toString() {
return url + "=" + value.toString();
}
private static final long serialVersionUID = 465890108L;
/**

View File

@ -7159,6 +7159,12 @@ public class ImplementationGuide extends CanonicalResource {
@Description(shortDefinition="Location of the resource", formalDefinition="Where this resource is found." )
protected Reference reference;
@Override
public String toString() {
return "ImplementationGuideDefinitionResourceComponent [name=" + name + ", reference=" + reference
+ ", profile=" + profile + "]";
}
/**
* Indicates the FHIR Version(s) this artifact is intended to apply to. If no versions are specified, the resource is assumed to apply to all the versions stated in ImplementationGuide.fhirVersion.
*/

View File

@ -1810,5 +1810,15 @@ public boolean getParameterBool(String name) {
}
// end addition
public String getParameterString(String name) {
for (ParametersParameterComponent p : getParameter()) {
if (p.getName().equals(name)) {
if (p.getValue() instanceof PrimitiveType)
return ((PrimitiveType) p.getValue()).primitiveValue();
}
}
return null;
}
}

View File

@ -7,6 +7,7 @@ import java.util.List;
import java.util.Map;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.Enumerations.CodeSystemContentMode;
@ -138,23 +139,29 @@ public class CodeSystemRenderer extends TerminologyRenderer {
}
}
private String sentenceForContent(CodeSystemContentMode mode) {
switch (mode) {
case COMPLETE: return "This code system <param name='cs'/> defines the following code<if test='code-count != 1'>s</if>:";
case EXAMPLE: return "This code system <param name='cs'/> provides some example code<if test='code-count != 1'>s</if>:";
case FRAGMENT: return "This code system <param name='cs'/> provides a fragment that includes following code<if test='code-count != 1'>s</if>:";
case NOTPRESENT: return "This code system <param name='cs'/> defines codes, but no codes are represented here";
case SUPPLEMENT: return "This code system <param name='cs'/> defines properties on the following code<if test='code-count != 1'>s</if>:";
}
throw new FHIRException("Unknown CodeSystemContentMode mode");
}
private boolean generateCodeSystemContent(XhtmlNode x, CodeSystem cs, boolean hasExtensions, List<UsedConceptMap> maps, boolean props) throws FHIRFormatError, DefinitionException, IOException {
if (props) {
x.para().b().tx(getContext().getWorker().translator().translate("xhtml-gen-cs", "Concepts", getContext().getLang()));
}
XhtmlNode p = x.para();
p.tx(getContext().getWorker().translator().translateAndFormat("xhtml-gen-cs", getContext().getLang(), "This code system "));
p.code().tx(cs.getUrl());
if (cs.getContent() == CodeSystemContentMode.COMPLETE)
p.tx(getContext().getWorker().translator().translateAndFormat("xhtml-gen-cs", getContext().getLang(), " defines the following codes")+":");
else if (cs.getContent() == CodeSystemContentMode.EXAMPLE)
p.tx(getContext().getWorker().translator().translateAndFormat("xhtml-gen-cs", getContext().getLang(), " defines some example codes")+":");
else if (cs.getContent() == CodeSystemContentMode.FRAGMENT )
p.tx(getContext().getWorker().translator().translateAndFormat("xhtml-gen-cs", getContext().getLang(), " defines many codes, of which the following are a subset")+":");
else if (cs.getContent() == CodeSystemContentMode.NOTPRESENT ) {
p.tx(getContext().getWorker().translator().translateAndFormat("xhtml-gen-cs", getContext().getLang(), " defines many codes, but they are not represented here"));
p.param("cs").code().tx(cs.getUrl());
p.paramValue("code-count", CodeSystemUtilities.countCodes(cs));
p.sentenceForParams(sentenceForContent(cs.getContent()));
if (cs.getContent() == CodeSystemContentMode.NOTPRESENT) {
return false;
}
XhtmlNode t = x.table( "codes");
boolean definitions = false;
boolean commentS = false;
@ -198,7 +205,7 @@ public class CodeSystemRenderer extends TerminologyRenderer {
if (langs.size() > 0) {
Collections.sort(langs);
x.para().b().tx("Additional Language Displays");
t = x.table( "codes");
t = x.table("codes");
XhtmlNode tr = t.tr();
tr.td().b().tx("Code");
for (String lang : langs)

View File

@ -146,8 +146,13 @@ public class DataRenderer extends Renderer implements CodeResolver {
String left = text.substring(0, text.indexOf("[[["));
String link = text.substring(text.indexOf("[[[")+3, text.indexOf("]]]"));
String right = text.substring(text.indexOf("]]]")+3);
String path = null;
String url = link;
String[] parts = link.split("\\#");
if (parts[0].contains(".")) {
path = parts[0];
parts[0] = parts[0].substring(0, parts[0].indexOf("."));
}
StructureDefinition p = getContext().getWorker().fetchResource(StructureDefinition.class, parts[0]);
if (p == null)
p = getContext().getWorker().fetchTypeDefinition(parts[0]);
@ -160,7 +165,7 @@ public class DataRenderer extends Renderer implements CodeResolver {
} else
throw new DefinitionException("Unable to resolve markdown link "+link);
text = left+"["+link+"]("+url+")"+right;
text = left+"["+link+"]("+url+(path == null ? "" : "#"+path)+")"+right;
}
// 2. markdown

View File

@ -949,10 +949,15 @@ public class ProfileDrivenRenderer extends ResourceRenderer {
private boolean exemptFromRendering(ElementDefinition child) {
if (child == null)
return false;
if ("Composition.subject".equals(child.getPath()))
if ("DomainResource.text".equals(child.getBase().getPath())) {
return true;
if ("Composition.section".equals(child.getPath()))
}
if ("Composition.subject".equals(child.getPath())) {
return true;
}
if ("Composition.section".equals(child.getPath())) {
return true;
}
return false;
}

View File

@ -1025,7 +1025,11 @@ public class QuestionnaireRenderer extends TerminologyRenderer {
if (qi.getEnableWhen().size() == 1) {
renderEnableWhen(td, qi.getEnableWhen().get(0));
} else {
td.tx(qi.getEnableBehavior().getDisplay()+" are true:");
if (qi.hasEnableBehavior()) {
td.tx(qi.getEnableBehavior().getDisplay()+" are true:");
} else {
td.tx("?? are true:");
}
XhtmlNode ul = td.ul();
for (QuestionnaireItemEnableWhenComponent ew : qi.getEnableWhen()) {
renderEnableWhen(ul.li(), ew);

View File

@ -7,6 +7,7 @@ import java.util.List;
import org.hl7.fhir.r5.model.Base;
import org.hl7.fhir.r5.model.DataType;
import org.hl7.fhir.r5.model.Expression;
import org.hl7.fhir.r5.model.Questionnaire;
import org.hl7.fhir.r5.model.QuestionnaireResponse;
import org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent;
import org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseItemComponent;
@ -127,15 +128,27 @@ public class QuestionnaireResponseRenderer extends ResourceRenderer {
return r;
}
private Row addTreeRoot(HierarchicalTableGenerator gen, List<Row> rows, ResourceWrapper q) throws IOException {
private Row addTreeRoot(HierarchicalTableGenerator gen, List<Row> rows, ResourceWrapper qr) throws IOException {
Row r = gen.new Row();
rows.add(r);
Base b = qr.get("questionnaire");
String ref = b == null ? null : b.primitiveValue();
Questionnaire q = context.getContext().fetchResource(Questionnaire.class, ref);
r.setIcon("icon_q_root.gif", "QuestionnaireResponseRoot");
r.getCells().add(gen.new Cell(null, null, q.getId(), null, null));
r.getCells().add(gen.new Cell(null, null, "", null, null));
r.getCells().add(gen.new Cell(null, null, "QuestionnaireResponse", null, null));
r.getCells().add(gen.new Cell(null, null, qr.getId(), null, null));
r.getCells().add(gen.new Cell(null, null, "", null, null));
if (ref == null ) {
r.getCells().add(gen.new Cell(null, null, "", null, null));
r.getCells().add(gen.new Cell("Questionnaire:", null, "None specified", null, null));
} else if (q == null || !q.hasWebPath()) {
r.getCells().add(gen.new Cell(null, null, "", null, null));
r.getCells().add(gen.new Cell("Questionnaire:", null, ref, null, null));
} else{
r.getCells().add(gen.new Cell(null, null, "", null, null));
r.getCells().add(gen.new Cell("Questionnaire:", q.getWebPath(), q.present(), null, null));
}
return r;
}

View File

@ -174,7 +174,7 @@ public class RequirementsRenderer extends ResourceRenderer {
}
Resource r = context.getWorker().fetchResource(Resource.class, url, req);
ResourceWithReference t = null;
if (r == null) {
if (r == null && context.getResolver() != null) {
t = context.getResolver().resolve(context, url);
}
if (r != null) {

View File

@ -1874,7 +1874,7 @@ public class StructureDefinitionRenderer extends ResourceRenderer {
erow.getSubRows().add(row);
Cell c = gen.new Cell();
row.getCells().add(c);
c.addPiece(gen.new Piece((ed.getBase().getPath().equals(ed.getPath()) ? ref+ed.getPath() : corePath+(VersionUtilities.isR5Ver(context.getWorker().getVersion()) ? "types-definitions.html#"+ed.getBase().getPath() : "element-definitions.html#"+ed.getBase().getPath())), t.getName(), null));
c.addPiece(gen.new Piece((ed.getBase().getPath().equals(ed.getPath()) ? ref+ed.getPath() : corePath+(VersionUtilities.isR5Plus(context.getWorker().getVersion()) ? "types-definitions.html#"+ed.getBase().getPath() : "element-definitions.html#"+ed.getBase().getPath())), t.getName(), null));
c = gen.new Cell();
row.getCells().add(c);
c.addPiece(gen.new Piece(null, null, null));

View File

@ -57,6 +57,7 @@ import org.hl7.fhir.r5.model.DataType;
import org.hl7.fhir.r5.model.DateTimeType;
import org.hl7.fhir.r5.model.DecimalType;
import org.hl7.fhir.r5.model.Enumerations.PublicationStatus;
import org.hl7.fhir.r5.model.Extension;
import org.hl7.fhir.r5.terminologies.CodeSystemUtilities.ConceptDefinitionComponentSorter;
import org.hl7.fhir.r5.model.Identifier;
import org.hl7.fhir.r5.model.IntegerType;
@ -64,6 +65,7 @@ import org.hl7.fhir.r5.model.Meta;
import org.hl7.fhir.r5.model.StringType;
import org.hl7.fhir.r5.model.UriType;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
import org.hl7.fhir.utilities.StandardsStatus;
import org.hl7.fhir.utilities.Utilities;
@ -246,7 +248,7 @@ public class CodeSystemUtilities {
throw new Error("Unknown property type "+value.getClass().getName());
}
private static void defineProperty(CodeSystem cs, String code, PropertyType pt) {
private static String defineProperty(CodeSystem cs, String code, PropertyType pt) {
String url = "http://hl7.org/fhir/concept-properties#"+code;
for (PropertyComponent p : cs.getProperty()) {
if (p.getCode().equals(code)) {
@ -256,11 +258,11 @@ public class CodeSystemUtilities {
if (!p.getType().equals(pt)) {
throw new Error("Type mismatch for code "+code+" type = "+p.getType()+" vs "+pt);
}
return;
return code;
}
}
cs.addProperty().setCode(code).setUri(url).setType(pt).setUri(url);
return code;
}
public static void defineNotSelectableProperty(CodeSystem cs) {
@ -708,5 +710,113 @@ public class CodeSystemUtilities {
}
return false;
}
public static int countCodes(CodeSystem cs) {
return countCodes(cs.getConcept());
}
private static int countCodes(List<ConceptDefinitionComponent> concept) {
int t = concept.size();
for (ConceptDefinitionComponent cd : concept) {
t = t + (cd.hasConcept() ? countCodes(cd.getConcept()) : 0);
}
return t;
}
public static CodeSystem mergeSupplements(CodeSystem cs, List<CodeSystem> supplements) {
CodeSystem ret = cs.copy();
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
for (CodeSystem sup : supplements) {
b.append(sup.getVersionedUrl());
}
ret.setUserData("supplements.installed", b.toString());
for (ConceptDefinitionComponent t : ret.getConcept()) {
mergeSupplements(ret, t, supplements);
}
return ret;
}
private static void mergeSupplements(CodeSystem ret, ConceptDefinitionComponent fdef, List<CodeSystem> supplements) {
for (CodeSystem cs : supplements) {
ConceptDefinitionComponent def = CodeSystemUtilities.findCode(cs.getConcept(), fdef.getCode());
if (def != null) {
for (Extension ext : def.getExtension()) {
fdef.addExtension(ext.copy());
}
for (ConceptDefinitionDesignationComponent d : def.getDesignation()) {
fdef.addDesignation(d.copy());
}
for (ConceptPropertyComponent p : def.getProperty()) {
PropertyComponent pd = CodeSystemUtilities.getPropertyDefinition(cs, p);
String code;
if (pd != null) {
code = defineProperty(ret, pd, propertyTypeForType(p.getValue()));
} else {
code = defineProperty(ret, p.getCode(), propertyTypeForType(p.getValue()));
}
fdef.addProperty().setCode(code).setValue(p.getValue());
}
}
for (ConceptDefinitionComponent t : fdef.getConcept()) {
mergeSupplements(ret, t, supplements);
}
}
}
private static PropertyType propertyTypeForType(DataType value) {
if (value == null) {
return PropertyType.NULL;
}
if (value instanceof CodeType) {
return PropertyType.CODE;
}
if (value instanceof CodeType) {
return PropertyType.CODING;
}
if (value instanceof CodeType) {
return PropertyType.STRING;
}
if (value instanceof CodeType) {
return PropertyType.INTEGER;
}
if (value instanceof CodeType) {
return PropertyType.BOOLEAN;
}
if (value instanceof CodeType) {
return PropertyType.DATETIME;
}
if (value instanceof CodeType) {
return PropertyType.DECIMAL;
}
throw new FHIRException("Unsupported property value for a CodeSystem Property: "+value.fhirType());
}
private static String defineProperty(CodeSystem cs, PropertyComponent pd, PropertyType pt) {
for (PropertyComponent p : cs.getProperty()) {
if (p.getCode().equals(pd.getCode())) {
if (!p.getUri().equals(pd.getUri())) {
throw new Error("URI mismatch for code "+pd.getCode()+" url = "+p.getUri()+" vs "+pd.getUri());
}
if (!p.getType().equals(pt)) {
throw new Error("Type mismatch for code "+pd.getCode()+" type = "+p.getType().toCode()+" vs "+pt.toCode());
}
return pd.getCode();
}
}
cs.addProperty().setCode(pd.getCode()).setUri(pd.getUri()).setType(pt);
return pd.getCode();
}
private static PropertyComponent getPropertyDefinition(CodeSystem cs, ConceptPropertyComponent p) {
for (PropertyComponent t : cs.getProperty()) {
if (t.getCode().equals(p.getCode())) {
return t;
}
}
return null;
}
}

View File

@ -41,7 +41,7 @@ import org.hl7.fhir.r5.model.ValueSet;
public interface ValueSetExpander {
public enum TerminologyServiceErrorClass {
UNKNOWN, NOSERVICE, SERVER_ERROR, VALUESET_UNSUPPORTED, CODESYSTEM_UNSUPPORTED, BLOCKED_BY_OPTIONS, INTERNAL_ERROR;
UNKNOWN, NOSERVICE, SERVER_ERROR, VALUESET_UNSUPPORTED, CODESYSTEM_UNSUPPORTED, BLOCKED_BY_OPTIONS, INTERNAL_ERROR, BUSINESS_RULE;
public boolean isInfrastructure() {
return this == NOSERVICE || this == SERVER_ERROR || this == VALUESET_UNSUPPORTED;
@ -102,6 +102,9 @@ public interface ValueSetExpander {
if (!allErrors.contains(error)) {
allErrors.add(error);
}
if (!errList.contains(error)) {
errList.add(error);
}
}
public ValueSet getValueset() {

View File

@ -81,6 +81,10 @@ import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.exceptions.NoTerminologyServiceException;
import org.hl7.fhir.exceptions.TerminologyServiceException;
import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.elementmodel.LangaugeUtils;
import org.hl7.fhir.r5.extensions.ExtensionConstants;
import org.hl7.fhir.r5.extensions.Extensions;
import org.hl7.fhir.r5.extensions.ExtensionsUtils;
import org.hl7.fhir.r5.model.BooleanType;
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.Enumerations.CodeSystemContentMode;
@ -98,6 +102,7 @@ import org.hl7.fhir.r5.model.PackageInformation;
import org.hl7.fhir.r5.model.Parameters;
import org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent;
import org.hl7.fhir.r5.model.PrimitiveType;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.UriType;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent;
@ -117,6 +122,12 @@ import com.google.errorprone.annotations.NoAllocation;
public class ValueSetExpanderSimple extends ValueSetWorker implements ValueSetExpander {
public interface IConceptFilter {
boolean includeConcept(CodeSystem cs, ConceptDefinitionComponent def);
}
public class PropertyFilter implements IConceptFilter {
private ConceptSetFilterComponent filter;
@ -172,12 +183,20 @@ public class ValueSetExpanderSimple extends ValueSetWorker implements ValueSetEx
}
}
public interface IConceptFilter {
public class RegexFilter implements IConceptFilter {
boolean includeConcept(CodeSystem cs, ConceptDefinitionComponent def);
private String regex;
protected RegexFilter(String regex) {
super();
this.regex = regex;
}
@Override
public boolean includeConcept(CodeSystem cs, ConceptDefinitionComponent def) {
return def.getCode().matches(regex);
}
}
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>();
@ -189,6 +208,7 @@ public class ValueSetExpanderSimple extends ValueSetWorker implements ValueSetEx
private ValueSet focus;
private int maxExpansionSize = 500;
private List<String> allErrors = new ArrayList<>();
private List<String> requiredSupplements = new ArrayList<>();
private int total;
private boolean checkCodesWhenExpanding;
@ -208,8 +228,9 @@ public class ValueSetExpanderSimple extends ValueSetWorker implements ValueSetEx
maxExpansionSize = theMaxExpansionSize;
}
private ValueSetExpansionContainsComponent addCode(String system, String code, String display, ValueSetExpansionContainsComponent parent, List<ConceptDefinitionDesignationComponent> designations, Parameters expParams,
boolean isAbstract, boolean inactive, List<ValueSet> filters, boolean noInactive, boolean deprecated, List<ValueSetExpansionPropertyComponent> vsProp) {
private ValueSetExpansionContainsComponent addCode(String system, String code, String display, String dispLang, ValueSetExpansionContainsComponent parent, List<ConceptDefinitionDesignationComponent> designations, Parameters expParams,
boolean isAbstract, boolean inactive, String definition, List<ValueSet> filters, boolean noInactive, boolean deprecated, List<ValueSetExpansionPropertyComponent> vsProp,
List<ConceptPropertyComponent> csProps, List<org.hl7.fhir.r5.model.ValueSet.ConceptPropertyComponent> expProps, List<Extension> csExtList, List<Extension> vsExtList) {
if (filters != null && !filters.isEmpty() && !filterContainsCode(filters, system, code))
return null;
@ -227,10 +248,61 @@ public class ValueSetExpanderSimple extends ValueSetWorker implements ValueSetEx
if (deprecated) {
ValueSetUtilities.setDeprecated(vsProp, n);
}
if (expParams.getParameterBool("includeDefinition") && definition != null) {
n.addExtension(Extensions.makeVSConceptDefinition(definition));
}
if (ExtensionsUtils.hasExtension(csExtList, "http://hl7.org/fhir/StructureDefinition/codesystem-label")) {
ValueSetUtilities.addProperty(focus, n, "http://hl7.org/fhir/concept-properties#label", "label", ExtensionsUtils.getExtensionValue(csExtList, "http://hl7.org/fhir/StructureDefinition/codesystem-label"));
}
if (ExtensionsUtils.hasExtension(vsExtList, "http://hl7.org/fhir/StructureDefinition/valueset-label")) {
ValueSetUtilities.addProperty(focus, n, "http://hl7.org/fhir/concept-properties#label", "label", ExtensionsUtils.getExtensionValue(vsExtList, "http://hl7.org/fhir/StructureDefinition/valueset-label"));
}
if (ExtensionsUtils.hasExtension(csExtList, "http://hl7.org/fhir/StructureDefinition/codesystem-conceptOrder")) {
ValueSetUtilities.addProperty(focus, n, "http://hl7.org/fhir/concept-properties#order", "order", ExtensionsUtils.getExtensionValue(csExtList, "http://hl7.org/fhir/StructureDefinition/codesystem-conceptOrder"));
}
if (ExtensionsUtils.hasExtension(vsExtList, "http://hl7.org/fhir/StructureDefinition/valueset-conceptOrder")) {
ValueSetUtilities.addProperty(focus, n, "http://hl7.org/fhir/concept-properties#order", "order", ExtensionsUtils.getExtensionValue(vsExtList, "http://hl7.org/fhir/StructureDefinition/valueset-conceptOrder"));
}
if (ExtensionsUtils.hasExtension(csExtList, "http://hl7.org/fhir/StructureDefinition/itemWeight")) {
ValueSetUtilities.addProperty(focus, n, "http://hl7.org/fhir/concept-properties#itemWeight", "weight", ExtensionsUtils.getExtensionValue(csExtList, "http://hl7.org/fhir/StructureDefinition/itemWeight"));
}
if (ExtensionsUtils.hasExtension(vsExtList, "http://hl7.org/fhir/StructureDefinition/itemWeight")) {
ValueSetUtilities.addProperty(focus, n, "http://hl7.org/fhir/concept-properties#itemWeight", "weight", ExtensionsUtils.getExtensionValue(vsExtList, "http://hl7.org/fhir/StructureDefinition/itemWeight"));
}
ExtensionsUtils.copyExtensions(csExtList, n.getExtension(),
"http://hl7.org/fhir/StructureDefinition/coding-sctdescid",
"http://hl7.org/fhir/StructureDefinition/rendering-style",
"http://hl7.org/fhir/StructureDefinition/rendering-xhtml",
"http://hl7.org/fhir/StructureDefinition/codesystem-alternate");
ExtensionsUtils.copyExtensions(vsExtList, n.getExtension(),
"http://hl7.org/fhir/StructureDefinition/valueset-supplement",
"http://hl7.org/fhir/StructureDefinition/valueset-deprecated",
"http://hl7.org/fhir/StructureDefinition/valueset-concept-definition",
"http://hl7.org/fhir/StructureDefinition/coding-sctdescid",
"http://hl7.org/fhir/StructureDefinition/rendering-style",
"http://hl7.org/fhir/StructureDefinition/rendering-xhtml");
// display and designations
String srcLang = dispLang;
String dstLang = focus.getLanguage();
boolean usedDisplay = false;
ConceptDefinitionDesignationComponent tu = expParams.hasParameter("displayLanguage") ? getMatchingLang(designations, expParams.getParameterString("displayLanguage")) : null;
if (tu != null) {
n.setDisplay(tu.getValue());
} else if (display != null && (srcLang == null || dstLang == null || LangaugeUtils.matches(dstLang, srcLang))) {
n.setDisplay(display);
usedDisplay = true;
} else {
// we don't have a usable display
}
if (expParams.getParameterBool("includeDesignations") && designations != null) {
if (!usedDisplay && display != null) {
n.addDesignation().setLanguage(srcLang).setValue(display);
}
for (ConceptDefinitionDesignationComponent t : designations) {
if (t.getLanguage() != null || t.getValue() != null) {
if (t != tu && (t.hasLanguage() || t.hasUse()) && t.getValue() != null) {
ConceptReferenceDesignationComponent d = n.addDesignation();
if (t.getLanguage() != null) {
d.setLanguage(t.getLanguage().trim());
@ -238,14 +310,32 @@ public class ValueSetExpanderSimple extends ValueSetWorker implements ValueSetEx
if (t.getValue() != null) {
d.setValue(t.getValue().trim());
}
if (t.getUse() != null) {
d.setUse(t.getUse());
}
}
}
}
ConceptDefinitionDesignationComponent t = expParams.hasLanguage() ? getMatchingLang(designations, expParams.getLanguage()) : null;
if (t == null)
n.setDisplay(display);
else
n.setDisplay(t.getValue());
for (ParametersParameterComponent p : expParams.getParameter()) {
if ("property".equals(p.getName())) {
if (csProps != null && p.hasValue()) {
for (ConceptPropertyComponent cp : csProps) {
if (p.getValue().primitiveValue().equals(cp.getCode())) {
n.addProperty().setCode(cp.getCode()).setValue(cp.getValue());
}
}
}
if (expProps != null && p.hasValue()) {
for (org.hl7.fhir.r5.model.ValueSet.ConceptPropertyComponent cp : expProps) {
if (p.getValue().primitiveValue().equals(cp.getCode())) {
n.addProperty(cp);
}
}
}
}
}
String s = key(n);
if (map.containsKey(s) || excludeKeys.contains(s)) {
@ -290,12 +380,12 @@ public class ValueSetExpanderSimple extends ValueSetWorker implements ValueSetEx
return null;
}
private void addCodeAndDescendents(ValueSetExpansionContainsComponent focus, ValueSetExpansionContainsComponent parent, Parameters expParams, List<ValueSet> filters, boolean noInactive, List<ValueSetExpansionPropertyComponent> vsProps) throws FHIRException {
private void addCodeAndDescendents(ValueSetExpansionContainsComponent focus, ValueSetExpansionContainsComponent parent, Parameters expParams, List<ValueSet> filters, boolean noInactive, List<ValueSetExpansionPropertyComponent> vsProps, ValueSet vsSrc) throws FHIRException {
focus.checkNoModifiers("Expansion.contains", "expanding");
ValueSetExpansionContainsComponent np = addCode(focus.getSystem(), focus.getCode(), focus.getDisplay(), parent,
convert(focus.getDesignation()), expParams, focus.getAbstract(), focus.getInactive(), filters, noInactive, false, vsProps);
ValueSetExpansionContainsComponent np = addCode(focus.getSystem(), focus.getCode(), focus.getDisplay(), vsSrc.getLanguage(), parent,
convert(focus.getDesignation()), expParams, focus.getAbstract(), focus.getInactive(), focus.getExtensionString(ToolingExtensions.EXT_DEFINITION), filters, noInactive, false, vsProps, null, focus.getProperty(), null, focus.getExtension());
for (ValueSetExpansionContainsComponent c : focus.getContains())
addCodeAndDescendents(focus, np, expParams, filters, noInactive, vsProps);
addCodeAndDescendents(focus, np, expParams, filters, noInactive, vsProps, vsSrc);
}
private List<ConceptDefinitionDesignationComponent> convert(List<ConceptReferenceDesignationComponent> designations) {
@ -310,7 +400,8 @@ public class ValueSetExpanderSimple extends ValueSetWorker implements ValueSetEx
return list;
}
private void addCodeAndDescendents(CodeSystem cs, String system, ConceptDefinitionComponent def, ValueSetExpansionContainsComponent parent, Parameters expParams, List<ValueSet> filters, ConceptDefinitionComponent exclusion, IConceptFilter filterFunc, boolean noInactive, List<ValueSetExpansionPropertyComponent> vsProps) throws FHIRException {
private void addCodeAndDescendents(CodeSystem cs, String system, ConceptDefinitionComponent def, ValueSetExpansionContainsComponent parent, Parameters expParams, List<ValueSet> filters,
ConceptDefinitionComponent exclusion, IConceptFilter filterFunc, boolean noInactive, List<ValueSetExpansionPropertyComponent> vsProps) throws FHIRException {
def.checkNoModifiers("Code in Code System", "expanding");
if (exclusion != null) {
if (exclusion.getCode().equals(def.getCode()))
@ -321,7 +412,7 @@ public class ValueSetExpanderSimple extends ValueSetWorker implements ValueSetEx
boolean inc = CodeSystemUtilities.isInactive(cs, def);
boolean dep = CodeSystemUtilities.isDeprecated(cs, def, false);
if ((includeAbstract || !abs) && filterFunc.includeConcept(cs, def)) {
np = addCode(system, def.getCode(), def.getDisplay(), parent, def.getDesignation(), expParams, abs, inc, filters, noInactive, dep, vsProps);
np = addCode(system, def.getCode(), def.getDisplay(), cs.getLanguage(), parent, def.getDesignation(), expParams, abs, inc, def.getDefinition(), filters, noInactive, dep, vsProps, def.getProperty(), null, def.getExtension(), null);
}
for (ConceptDefinitionComponent c : def.getConcept()) {
addCodeAndDescendents(cs, system, c, np, expParams, filters, exclusion, filterFunc, noInactive, vsProps);
@ -334,7 +425,7 @@ public class ValueSetExpanderSimple extends ValueSetWorker implements ValueSetEx
}
private void addCodes(ValueSetExpansionComponent expand, List<ValueSetExpansionParameterComponent> params, Parameters expParams, List<ValueSet> filters, boolean noInactive, List<ValueSetExpansionPropertyComponent> vsProps) throws ETooCostly, FHIRException {
private void addCodes(ValueSetExpansionComponent expand, List<ValueSetExpansionParameterComponent> params, Parameters expParams, List<ValueSet> filters, boolean noInactive, List<ValueSetExpansionPropertyComponent> vsProps, ValueSet vsSrc) throws ETooCostly, FHIRException {
if (expand != null) {
if (expand.getContains().size() > maxExpansionSize)
throw failCostly("Too many codes to display (>" + Integer.toString(expand.getContains().size()) + ")");
@ -343,7 +434,7 @@ public class ValueSetExpanderSimple extends ValueSetWorker implements ValueSetEx
params.add(p);
}
copyImportContains(expand.getContains(), null, expParams, filters, noInactive, vsProps);
copyImportContains(expand.getContains(), null, expParams, filters, noInactive, vsProps, vsSrc);
}
}
@ -365,7 +456,7 @@ public class ValueSetExpanderSimple extends ValueSetWorker implements ValueSetEx
throw fail("Processing Value set references in exclude is not yet done in "+ctxt);
// importValueSet(imp.getValue(), params, expParams);
CodeSystem cs = context.fetchCodeSystem(exc.getSystem());
CodeSystem cs = context.fetchSupplementedCodeSystem(exc.getSystem());
if ((cs == null || cs.getContent() != CodeSystemContentMode.COMPLETE) && context.supportsSystem(exc.getSystem())) {
ValueSetExpansionOutcome vse = context.expandVS(exc, false, false);
ValueSet valueset = vse.getValueset();
@ -432,11 +523,19 @@ public class ValueSetExpanderSimple extends ValueSetWorker implements ValueSetEx
focus.getExpansion().setTimestampElement(DateTimeType.now());
focus.getExpansion().setIdentifier(Factory.createUUID());
for (ParametersParameterComponent p : expParams.getParameter()) {
if (Utilities.existsInList(p.getName(), "includeDesignations", "excludeNested", "activeOnly"))
if (Utilities.existsInList(p.getName(), "includeDesignations", "excludeNested", "activeOnly")) {
focus.getExpansion().addParameter().setName(p.getName()).setValue(p.getValue());
}
}
for (Extension s : focus.getExtensionsByUrl(ExtensionConstants.EXT_VSSUPPLEMENT)) {
requiredSupplements.add(s.getValue().primitiveValue());
}
if (expParams.hasLanguage()) {
focus.setLanguage(expParams.getLanguage());
}
if (source.hasCompose()) {
ExtensionsUtils.stripExtensions(focus.getCompose());
handleCompose(source.getCompose(), focus.getExpansion(), expParams, source.getUrl(), focus.getExpansion().getExtension(), source);
}
@ -456,6 +555,9 @@ public class ValueSetExpanderSimple extends ValueSetWorker implements ValueSetEx
if (total > 0) {
focus.getExpansion().setTotal(total);
}
if (!requiredSupplements.isEmpty()) {
return new ValueSetExpansionOutcome("Required supplements not found: "+requiredSupplements.toString(), TerminologyServiceErrorClass.BUSINESS_RULE, allErrors);
}
return new ValueSetExpansionOutcome(focus);
}
@ -591,11 +693,12 @@ public class ValueSetExpanderSimple extends ValueSetWorker implements ValueSetEx
}
}
private void copyImportContains(List<ValueSetExpansionContainsComponent> list, ValueSetExpansionContainsComponent parent, Parameters expParams, List<ValueSet> filter, boolean noInactive, List<ValueSetExpansionPropertyComponent> vsProps) throws FHIRException {
private void copyImportContains(List<ValueSetExpansionContainsComponent> list, ValueSetExpansionContainsComponent parent, Parameters expParams, List<ValueSet> filter, boolean noInactive, List<ValueSetExpansionPropertyComponent> vsProps, ValueSet vsSrc) throws FHIRException {
for (ValueSetExpansionContainsComponent c : list) {
c.checkNoModifiers("Imported Expansion in Code System", "expanding");
ValueSetExpansionContainsComponent np = addCode(c.getSystem(), c.getCode(), c.getDisplay(), parent, null, expParams, c.getAbstract(), c.getInactive(), filter, noInactive, false, vsProps);
copyImportContains(c.getContains(), np, expParams, filter, noInactive, vsProps);
ValueSetExpansionContainsComponent np = addCode(c.getSystem(), c.getCode(), c.getDisplay(), vsSrc.getLanguage(), parent, null, expParams, c.getAbstract(), c.getInactive(), c.getExtensionString(ToolingExtensions.EXT_DEFINITION),
filter, noInactive, false, vsProps, null, c.getProperty(), null, c.getExtension());
copyImportContains(c.getContains(), np, expParams, filter, noInactive, vsProps, vsSrc);
}
}
@ -612,13 +715,18 @@ public class ValueSetExpanderSimple extends ValueSetWorker implements ValueSetEx
ValueSet base = imports.get(0);
imports.remove(0);
base.checkNoModifiers("Imported ValueSet", "expanding");
copyImportContains(base.getExpansion().getContains(), null, expParams, imports, noInactive, base.getExpansion().getProperty());
copyImportContains(base.getExpansion().getContains(), null, expParams, imports, noInactive, base.getExpansion().getProperty(), base);
} else {
CodeSystem cs = context.fetchCodeSystem(inc.getSystem());
CodeSystem cs = context.fetchSupplementedCodeSystem(inc.getSystem());
if (isServerSide(inc.getSystem()) || (cs == null || (cs.getContent() != CodeSystemContentMode.COMPLETE && cs.getContent() != CodeSystemContentMode.FRAGMENT))) {
doServerIncludeCodes(inc, heirarchical, exp, imports, expParams, extensions, noInactive, valueSet.getExpansion().getProperty());
} else {
doInternalIncludeCodes(inc, exp, expParams, imports, cs, noInactive);
if (cs.hasUserData("supplements.installed")) {
for (String s : cs.getUserString("supplements.installed").split("\\,")) {
requiredSupplements.remove(s);
}
}
doInternalIncludeCodes(inc, exp, expParams, imports, cs, noInactive, valueSet);
}
}
}
@ -647,26 +755,18 @@ public class ValueSetExpanderSimple extends ValueSetWorker implements ValueSetEx
}
for (Extension ex : vs.getExpansion().getExtension()) {
if (Utilities.existsInList(ex.getUrl(), ToolingExtensions.EXT_EXP_TOOCOSTLY, "http://hl7.org/fhir/StructureDefinition/valueset-unclosed")) {
if (!hasExtension(extensions, ex.getUrl())) {
if (!ExtensionsUtils.hasExtension(extensions, ex.getUrl())) {
extensions.add(ex);
}
}
}
for (ValueSetExpansionContainsComponent cc : vs.getExpansion().getContains()) {
addCodeAndDescendents(cc, null, expParams, imports, noInactive, vsProps);
addCodeAndDescendents(cc, null, expParams, imports, noInactive, vsProps, vs);
}
}
private boolean hasExtension(List<Extension> extensions, String url) {
for (Extension ex : extensions) {
if (ex.getUrl().equals(url)) {
return true;
}
}
return false;
}
public void doInternalIncludeCodes(ConceptSetComponent inc, ValueSetExpansionComponent exp, Parameters expParams, List<ValueSet> imports, CodeSystem cs, boolean noInactive) throws NoTerminologyServiceException, TerminologyServiceException, FHIRException {
public void doInternalIncludeCodes(ConceptSetComponent inc, ValueSetExpansionComponent exp, Parameters expParams, List<ValueSet> imports, CodeSystem cs, boolean noInactive, Resource vsSrc) throws NoTerminologyServiceException, TerminologyServiceException, FHIRException {
if (cs == null) {
if (context.isNoTerminologyServer())
throw failTSE("Unable to find code system " + inc.getSystem().toString());
@ -696,10 +796,11 @@ public class ValueSetExpanderSimple extends ValueSetWorker implements ValueSetEx
if (!inc.getConcept().isEmpty()) {
canBeHeirarchy = false;
for (ConceptReferenceComponent c : inc.getConcept()) {
c.checkNoModifiers("Code in Code System", "expanding");
c.checkNoModifiers("Code in Value Set", "expanding");
ConceptDefinitionComponent def = CodeSystemUtilities.findCode(cs.getConcept(), c.getCode());
Boolean inactive = false; // default is true if we're a fragment and
if (def == null) {
def.checkNoModifiers("Code in Code System", "expanding");
if (cs.getContent() == CodeSystemContentMode.FRAGMENT) {
addFragmentWarning(exp, cs);
} else if (cs.getContent() == CodeSystemContentMode.EXAMPLE) {
@ -712,7 +813,8 @@ public class ValueSetExpanderSimple extends ValueSetWorker implements ValueSetEx
} else {
inactive = CodeSystemUtilities.isInactive(cs, def);
}
addCode(inc.getSystem(), c.getCode(), !Utilities.noString(c.getDisplay()) ? c.getDisplay() : def == null ? null : def.getDisplay(), null, convertDesignations(c.getDesignation()), expParams, false, inactive, imports, noInactive, false, exp.getProperty());
addCode(inc.getSystem(), c.getCode(), !Utilities.noString(c.getDisplay()) ? c.getDisplay() : def == null ? null : def.getDisplay(), c.hasDisplay() ? vsSrc.getLanguage() : cs.getLanguage(), null, mergeDesignations(def, convertDesignations(c.getDesignation())),
expParams, false, inactive, def == null ? null : def.getDefinition(), imports, noInactive, false, exp.getProperty(), def != null ? def.getProperty() : null, null, def == null ? null : def.getExtension(), c.getExtension());
}
}
if (inc.getFilter().size() > 1) {
@ -758,8 +860,8 @@ public class ValueSetExpanderSimple extends ValueSetWorker implements ValueSetEx
if (def != null) {
if (isNotBlank(def.getDisplay()) && isNotBlank(fc.getValue())) {
if (def.getDisplay().contains(fc.getValue())) {
addCode(inc.getSystem(), def.getCode(), def.getDisplay(), null, def.getDesignation(), expParams, CodeSystemUtilities.isNotSelectable(cs, def), CodeSystemUtilities.isInactive(cs, def),
imports, noInactive, false, exp.getProperty());
addCode(inc.getSystem(), def.getCode(), def.getDisplay(), cs.getLanguage(), null, def.getDesignation(), expParams, CodeSystemUtilities.isNotSelectable(cs, def), CodeSystemUtilities.isInactive(cs, def),
def.getDefinition(), imports, noInactive, false, exp.getProperty(), def.getProperty(), null, def.getExtension(), null);
}
}
}
@ -767,12 +869,24 @@ public class ValueSetExpanderSimple extends ValueSetWorker implements ValueSetEx
for (ConceptDefinitionComponent def : cs.getConcept()) {
addCodeAndDescendents(cs, inc.getSystem(), def, null, expParams, imports, null, new PropertyFilter(fc, getPropertyDefinition(cs, fc.getProperty())), noInactive, exp.getProperty());
}
} else if ("regex".equals(fc.getProperty()) && fc.getOp() == FilterOperator.EQUAL) {
for (ConceptDefinitionComponent def : cs.getConcept()) {
addCodeAndDescendents(cs, inc.getSystem(), def, null, expParams, imports, null, new RegexFilter(fc.getValue()), noInactive, exp.getProperty());
}
} else {
throw fail("Search by property[" + fc.getProperty() + "] and op[" + fc.getOp() + "] is not supported yet");
}
}
}
private List<ConceptDefinitionDesignationComponent> mergeDesignations(ConceptDefinitionComponent def,
List<ConceptDefinitionDesignationComponent> list) {
List<ConceptDefinitionDesignationComponent> res = new ArrayList<>();
res.addAll(def.getDesignation());
res.addAll(list);
return res;
}
private PropertyComponent getPropertyDefinition(CodeSystem cs, String property) {
for (PropertyComponent cp : cs.getProperty()) {
if (cp.getCode().equals(property)) {

View File

@ -42,6 +42,8 @@ import org.hl7.fhir.r5.model.BooleanType;
import org.hl7.fhir.r5.model.CanonicalType;
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.DateTimeType;
import org.hl7.fhir.r5.model.StringType;
import org.hl7.fhir.r5.model.IntegerType;
import org.hl7.fhir.r5.model.Enumerations.FilterOperator;
import org.hl7.fhir.r5.model.Enumerations.PublicationStatus;
import org.hl7.fhir.r5.model.Identifier;
@ -52,6 +54,7 @@ import org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent;
import org.hl7.fhir.r5.model.CodeSystem.ConceptPropertyComponent;
import org.hl7.fhir.r5.model.CodeType;
import org.hl7.fhir.r5.model.Coding;
import org.hl7.fhir.r5.model.DataType;
import org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent;
import org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent;
import org.hl7.fhir.r5.model.ValueSet.ValueSetComposeComponent;
@ -328,5 +331,54 @@ public class ValueSetUtilities {
return false;
}
public static void addProperty(ValueSet vs, ValueSetExpansionContainsComponent ctxt, String url, String code, String value) {
if (value != null) {
addProperty(vs, ctxt, url, code, new StringType(value));
}
}
public static void addProperty(ValueSet vs, ValueSetExpansionContainsComponent ctxt, String url, String code, Integer value) {
if (value != null) {
addProperty(vs, ctxt, url, code, new IntegerType(value));
}
}
public static void addProperty(ValueSet vs, ValueSetExpansionContainsComponent ctxt, String url, String code, DataType value) {
code = defineProperty(vs, url, code);
org.hl7.fhir.r5.model.ValueSet.ConceptPropertyComponent p = getProperty(ctxt.getProperty(), code);
if (p != null)
p.setValue(value);
else
ctxt.addProperty().setCode(code).setValue(value);
}
private static org.hl7.fhir.r5.model.ValueSet.ConceptPropertyComponent getProperty(List<org.hl7.fhir.r5.model.ValueSet.ConceptPropertyComponent> list, String code) {
for (org.hl7.fhir.r5.model.ValueSet.ConceptPropertyComponent t : list) {
if (code.equals(t.getCode())) {
return t;
}
}
return null;
}
private static String defineProperty(ValueSet vs, String url, String code) {
for (ValueSetExpansionPropertyComponent p : vs.getExpansion().getProperty()) {
if (p.hasUri() && p.getUri().equals(url)) {
return p.getCode();
}
}
for (ValueSetExpansionPropertyComponent p : vs.getExpansion().getProperty()) {
if (p.hasCode() && p.getCode().equals(code)) {
p.setUri(url);
return code;
}
}
ValueSetExpansionPropertyComponent p = vs.getExpansion().addProperty();
p.setUri(url);
p.setCode(code);
return code;
}
}

View File

@ -2,6 +2,7 @@ package org.hl7.fhir.r5.test.utils;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.utilities.CSFile;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.ToolGlobalSettings;
@ -181,7 +182,7 @@ public class CompareUtilities extends BaseTestingUtilities {
String diff = null;
if (System.getProperty("os.name").contains("Linux"))
diff = Utilities.path("/", "usr", "bin", "meld");
else {
else if (System.getenv("ProgramFiles(X86)") != null) {
if (Utilities.checkFile("WinMerge", Utilities.path(System.getenv("ProgramFiles(X86)"), "WinMerge"), "\\WinMergeU.exe", null))
diff = Utilities.path(System.getenv("ProgramFiles(X86)"), "WinMerge", "WinMergeU.exe");
else if (Utilities.checkFile("WinMerge", Utilities.path(System.getenv("ProgramFiles(X86)"), "Meld"), "\\Meld.exe", null))
@ -271,7 +272,7 @@ public class CompareUtilities extends BaseTestingUtilities {
String actualJsonString = actualJsonPrimitive.getAsString();
String expectedJsonString = expectedJsonPrimitive.getAsString();
if (!(actualJsonString.contains("<div") && expectedJsonString.contains("<div")))
if (!actualJsonString.equals(expectedJsonString))
if (!matches(actualJsonString, expectedJsonString))
if (!sameBytes(unBase64(actualJsonString), unBase64(expectedJsonString)))
return createNotEqualMessage("string property values differ at " + path, expectedJsonString, actualJsonString);
} else if (actualJsonPrimitive.isNumber() && expectedJsonPrimitive.isNumber()) {
@ -301,6 +302,20 @@ public class CompareUtilities extends BaseTestingUtilities {
return null;
}
private static boolean matches(String actualJsonString, String expectedJsonString) {
if (expectedJsonString.startsWith("$") && expectedJsonString.endsWith("$")) {
switch (expectedJsonString) {
case "$$" : return true;
case "$instant$": return actualJsonString.matches("([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])T([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(\\.[0-9]{1,9})?(Z|(\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))");
case "$uuid$": return actualJsonString.matches("urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}");
default:
throw new Error("Unhandled template: "+expectedJsonString);
}
} else {
return actualJsonString.equals(expectedJsonString);
}
}
public static String checkTextIsSame(String expected, String actual) throws JsonSyntaxException, FileNotFoundException, IOException {
return checkTextIsSame(expected, actual, true);
}
@ -349,4 +364,5 @@ public class CompareUtilities extends BaseTestingUtilities {
return createNotEqualMessage("Strings differ in length but match to the end of the shortest.", Integer.toString(expectedString.length()), Integer.toString(actualString.length()));
return null;
}
}

View File

@ -16,6 +16,7 @@ import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.VersionUtilities;
import org.hl7.fhir.utilities.npm.BasePackageCacheManager.InputStreamWithSrc;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.IPackageProvider;
import org.hl7.fhir.utilities.npm.NpmPackage;
import org.hl7.fhir.utilities.npm.ToolsVersion;
@ -77,7 +78,7 @@ public class TestingUtilities extends BaseTestingUtilities {
FilesystemPackageCacheManager pcm;
try {
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
IWorkerContext fcontext = null;
if (VersionUtilities.isR5Ver(version)) {
// for purposes of stability, the R5 core package comes from the test case repository

View File

@ -0,0 +1,68 @@
package org.hl7.fhir.r5.utils;
import org.hl7.fhir.r5.model.Base;
import org.hl7.fhir.r5.model.DataType;
import org.hl7.fhir.r5.model.Property;
import org.hl7.fhir.r5.model.Resource;
public class DataTypeVisitor {
public interface IDatatypeVisitor<T extends DataType> {
Class<T> classT();
boolean visit(String path, T node);
}
private boolean anyFalse;
private boolean anyTrue;
private int nodeCount;
private int selectedCount;
public <T extends DataType> void visit(Resource resource, IDatatypeVisitor<T> visitor) {
visitNode(resource.fhirType(), resource, visitor);
}
@SuppressWarnings("unchecked")
private <T extends DataType> void visitNode(String path, Base node, IDatatypeVisitor<T> visitor) {
nodeCount++;
if (node instanceof DataType && visitor.classT().isInstance(node)) {
selectedCount++;
boolean ok = visitor.visit(path, (T) node);
if (ok) {
anyTrue = true;
} else {
anyFalse = true;
}
}
for (Property p : node.children()) {
if (p.isList()) {
int i = 0;
for (Base b : p.getValues()) {
visitNode(path+"."+p.getName()+"["+i+"]", b, visitor);
i++;
}
} else {
for (Base b : p.getValues()) {
visitNode(path+"."+p.getName(), b, visitor);
}
}
}
}
public boolean isAnyFalse() {
return anyFalse;
}
public boolean isAnyTrue() {
return anyTrue;
}
public int getNodeCount() {
return nodeCount;
}
public int getSelectedCount() {
return selectedCount;
}
}

View File

@ -4,6 +4,8 @@ import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.model.CanonicalResource;
import org.hl7.fhir.r5.model.ElementDefinition;
import org.hl7.fhir.r5.model.Enumerations.BindingStrength;
import org.hl7.fhir.r5.model.Extension;
import org.hl7.fhir.r5.model.MarkdownType;
import org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule;
import org.hl7.fhir.r5.model.StructureDefinition;
@ -15,24 +17,23 @@ public class R5Hacker {
}
}
private static void fixSD(StructureDefinition sd) {
if (sd.getDerivation() == TypeDerivationRule.CONSTRAINT) {
for (ElementDefinition ed : sd.getDifferential().getElement()) {
fix(ed);
}
for (ElementDefinition ed : sd.getSnapshot().getElement()) {
fix(ed);
}
for (ElementDefinition ed : sd.getDifferential().getElement()) {
fix(ed);
}
for (ElementDefinition ed : sd.getSnapshot().getElement()) {
fix(ed);
}
}
private static void fix(ElementDefinition ed) {
if (ed.hasDefinition()) {
ed.setDefinition(ed.getDefinition().replace("http://hl7.org/fhir/5.0.0-snapshot3/", "http://hl7.org/fhir/R5/"));
}
if (ed.hasBinding() && ed.getBinding().hasExtension(ToolingExtensions.EXT_BINDING_DEFINITION)) {
Extension ext = ed.getBinding().getExtensionByUrl(ToolingExtensions.EXT_BINDING_DEFINITION);
ext.setValue(new MarkdownType(ext.getValue().primitiveValue()));
}
}

View File

@ -15,6 +15,8 @@ import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.utilities.i18n.LanguageFileProducer;
import org.hl7.fhir.utilities.i18n.LanguageFileProducer.LanguageProducerLanguageSession;
import org.hl7.fhir.utilities.i18n.LanguageFileProducer.LanguageProducerSession;
import org.hl7.fhir.utilities.i18n.LanguageFileProducer.TextUnit;
public class ResourceLanguageFileBuilder {
@ -75,7 +77,7 @@ public class ResourceLanguageFileBuilder {
String ppath = path+"."+p.getName()+(p.isList() ? "["+i+"]" : "");
i++;
if (isTranslatable(p, b, pid)) {
sess.entry(ppath, b.primitiveValue(), getTranslation(b, target));
sess.entry(new TextUnit(ppath, b.primitiveValue(), getTranslation(b, target)));
}
for (Property pp : b.children()) {
process(sess, pp, pid, ppath);

View File

@ -122,7 +122,7 @@ public class ToolingExtensions {
public static final String EXT_IGP_PAGES = "http://hl7.org/fhir/StructureDefinition/igpublisher-folder-pages";
public static final String EXT_IGP_SPREADSHEET = "http://hl7.org/fhir/StructureDefinition/igpublisher-spreadsheet";
public static final String EXT_IGP_MAPPING_CSV = "http://hl7.org/fhir/StructureDefinition/igpublisher-mapping-csv";
public static final String EXT_IGP_BUNDLE = "http://hl7.org/fhir/StructureDefinition/igpublisher-bundle";
public static final String EXT_IGP_BUNDLE = "http://hl7.org/fhir/tools/StructureDefinition/igpublisher-bundle";
public static final String EXT_IGP_BASE = "http://hl7.org/fhir/StructureDefinition/igpublisher-res-base";
public static final String EXT_IGP_DEFNS = "http://hl7.org/fhir/StructureDefinition/igpublisher-res-defns";
public static final String EXT_IGP_FORMAT = "http://hl7.org/fhir/StructureDefinition/igpublisher-res-format";

View File

@ -16,6 +16,7 @@ import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.r5.utils.FHIRPathEngine;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode;
import org.hl7.fhir.utilities.npm.ToolsVersion;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
@ -28,7 +29,7 @@ public class CDARoundTripTests {
@BeforeAll
public static void setUp() throws Exception {
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
context = TestingUtilities.getWorkerContext(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1"));
fp = new FHIRPathEngine(context);

View File

@ -7,6 +7,7 @@ import java.util.List;
import org.hl7.fhir.r5.context.CanonicalResourceManager;
import org.hl7.fhir.r5.context.CanonicalResourceManager.CanonicalResourceProxy;
import org.hl7.fhir.r5.model.CanonicalResource;
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.PackageInformation;
import org.hl7.fhir.r5.model.ValueSet;
import org.junit.jupiter.api.Assertions;
@ -18,7 +19,7 @@ public class CanonicalResourceManagerTests {
private CanonicalResource resource;
public DeferredLoadTestResource(CanonicalResource resource) {
super(resource.fhirType(), resource.getId(), resource.getUrl(), resource.getVersion());
super(resource.fhirType(), resource.getId(), resource.getUrl(), resource.getVersion(), resource instanceof CodeSystem ? ((CodeSystem) resource).getSupplements() : null);
this.resource = resource;
}
@ -853,4 +854,77 @@ public class CanonicalResourceManagerTests {
Assertions.assertEquals("2", mrm.get("http://url/ValueSet/234", "4.0.2", pvl2).getName());
}
@Test
public void testSupplements() {
CanonicalResourceManager<CodeSystem> mrm = new CanonicalResourceManager<>(true);
CodeSystem csb1 = new CodeSystem();
csb1.setId("2345");
csb1.setUrl("http://url/CodeSystem/234");
csb1.setVersion("4.0.1");
csb1.setName("1");
mrm.see(csb1, new PackageInformation("pid.one", "1.0.0", new Date()));
CodeSystem csb2 = new CodeSystem();
csb2.setId("2346");
csb2.setUrl("http://url/CodeSystem/234");
csb2.setVersion("4.0.1");
csb2.setName("2");
mrm.see(csb2, new PackageInformation("pid.two", "1.0.0", new Date()));
CodeSystem css1 = new CodeSystem();
css1.setId("s2345");
css1.setUrl("http://url/CodeSystem/s234");
css1.setVersion("4.0.1");
css1.setName("s1");
css1.setSupplements("http://url/CodeSystem/234");
mrm.see(css1, new PackageInformation("pid.one", "1.0.0", new Date()));
CodeSystem css2 = new CodeSystem();
css2.setId("s2346");
css2.setUrl("http://url/CodeSystem/s234");
css2.setVersion("4.0.1");
css2.setName("s2");
css2.setSupplements("http://url/CodeSystem/234");
mrm.see(css2, new PackageInformation("pid.two", "1.0.0", new Date()));
List<CodeSystem> sl = mrm.getSupplements("http://url/CodeSystem/234");
Assertions.assertEquals(2, sl.size());
sl = mrm.getSupplements("http://url/CodeSystem/234", "1.0.1");
Assertions.assertEquals(2, sl.size());
sl = mrm.getSupplements("http://url/CodeSystem/s234");
Assertions.assertEquals(0, sl.size());
List<String> pvl = new ArrayList<>();
pvl.add("pid.two#1.0.0");
sl = mrm.getSupplements("http://url/CodeSystem/234", "1.0.1", pvl);
Assertions.assertEquals(1, sl.size());
mrm.drop("s2346");
sl = mrm.getSupplements("http://url/CodeSystem/234");
Assertions.assertEquals(1, sl.size());
sl = mrm.getSupplements("http://url/CodeSystem/234", "1.0.1");
Assertions.assertEquals(1, sl.size());
sl = mrm.getSupplements("http://url/CodeSystem/s234");
Assertions.assertEquals(0, sl.size());
pvl = new ArrayList<>();
pvl.add("pid.two#1.0.0");
sl = mrm.getSupplements("http://url/CodeSystem/234", "1.0.1", pvl);
Assertions.assertEquals(1, sl.size()); // cause we fall back to the other
pvl = new ArrayList<>();
pvl.add("pid.one#1.0.0");
sl = mrm.getSupplements("http://url/CodeSystem/234", "1.0.1", pvl);
Assertions.assertEquals(1, sl.size());
mrm.drop("s2345");
mrm.drop("s2346");
sl = mrm.getSupplements("http://url/CodeSystem/234");
Assertions.assertEquals(0, sl.size());
sl = mrm.getSupplements("http://url/CodeSystem/234", "1.0.1");
Assertions.assertEquals(0, sl.size());
sl = mrm.getSupplements("http://url/CodeSystem/s234");
Assertions.assertEquals(0, sl.size());
}
}

View File

@ -18,6 +18,7 @@ import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager;
import org.hl7.fhir.utilities.npm.NpmPackage;
import org.hl7.fhir.utilities.npm.ToolsVersion;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
@ -34,7 +35,7 @@ public class ParsingTests {
}
public static Stream<Arguments> data() throws ParserConfigurationException, IOException, FHIRFormatError, SAXException {
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
// npm = pcm.loadPackage("hl7.fhir.r5.examples", "5.0.0");
npm = NpmPackage.fromPackage(TestingUtilities.loadTestResourceStream("r5", "packages", "hl7.fhir.r5.examples.tgz"));
List<Arguments> objects = new ArrayList<>();

View File

@ -48,6 +48,7 @@ import org.hl7.fhir.utilities.npm.CommonPackages;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager;
import org.hl7.fhir.utilities.npm.NpmPackage;
import org.hl7.fhir.utilities.npm.ToolsVersion;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode;
import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity;
import org.hl7.fhir.utilities.xml.XMLUtil;
@ -535,7 +536,7 @@ public class SnapShotGenerationTests {
pu.setIds(test.getSource(), false);
pu.setAllowUnknownProfile(test.allow);
if (!TestingUtilities.getSharedWorkerContext().hasPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER)) {
NpmPackage npm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION).loadPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER);
NpmPackage npm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER).loadPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER);
TestingUtilities.getSharedWorkerContext().loadFromPackage(npm, new TestPackageLoader(Utilities.strings("StructureDefinition")), Utilities.strings("StructureDefinition"));
}
pu.setXver(new XVerExtensionManager(TestingUtilities.getSharedWorkerContext()));

View File

@ -18,6 +18,7 @@ import org.hl7.fhir.r5.utils.structuremap.ITransformerServices;
import org.hl7.fhir.r5.utils.structuremap.StructureMapUtilities;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager;
import org.hl7.fhir.utilities.npm.ToolsVersion;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@ -28,7 +29,7 @@ public class StructureMapUtilitiesTest implements ITransformerServices {
@BeforeAll
static public void setUp() throws Exception {
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
context = TestingUtilities.getWorkerContext(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1"));
}

View File

@ -14,6 +14,7 @@ import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.r5.utils.FHIRPathEngine;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager;
import org.hl7.fhir.utilities.npm.ToolsVersion;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@ -25,7 +26,7 @@ public class XmlParserTests {
@BeforeAll
public static void setUp() throws Exception {
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
context = TestingUtilities.getWorkerContext(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1"));
fp = new FHIRPathEngine(context);

View File

@ -13,7 +13,8 @@ public enum FhirPublication {
STU3,
R4,
R4B,
R5;
R5,
R6;
public static FhirPublication fromCode(String v) {
if (VersionUtilities.isR2Ver(v))
@ -28,6 +29,8 @@ public enum FhirPublication {
return FhirPublication.R4B;
if (VersionUtilities.isR5Ver(v))
return FhirPublication.R5;
if (VersionUtilities.isR6Ver(v))
return FhirPublication.R6;
return null;
}
@ -40,6 +43,7 @@ public enum FhirPublication {
case R4: return "4.0.1";
case R4B: return "4.3.0";
case R5: return "5.0.0";
case R6: return "6.0.0";
default:
return "??";
}

View File

@ -54,12 +54,6 @@ public class VersionUtilities {
return url;
}
}
public static final String CURRENT_VERSION = "5.0";
public static final String CURRENT_FULL_VERSION = "5.0.0";
public static final String CURRENT_DEFAULT_VERSION = "4.0";
public static final String CURRENT_DEFAULT_FULL_VERSION = "4.0.1";
public static String packageForVersion(String v) {
if (isR2Ver(v)) {
@ -83,15 +77,14 @@ public class VersionUtilities {
return "hl7.fhir.r5.core";
}
if (isR6Ver(v)) {
return "hl7.fhir.r6.core";
}
if ("current".equals(v)) {
return "hl7.fhir.r5.core";
}
if (v != null && v.startsWith(CURRENT_VERSION)) {
return "hl7.fhir.r5.core";
}
if (Utilities.existsInList(v, "4.4.0", "4.5.0")) {
return "hl7.fhir.r5.core";
}
return null;
}
@ -111,8 +104,8 @@ public class VersionUtilities {
if (isR5Ver(v)) {
return "5.0.0";
}
if (v != null && v.startsWith(CURRENT_VERSION)) {
return "current";
if (isR6Ver(v)) {
return "6.0.0";
}
return v;
}
@ -130,8 +123,11 @@ public class VersionUtilities {
if (isR4Ver(v)) {
return "4.0";
}
if (v != null && v.startsWith(CURRENT_VERSION)) {
return "current";
if (isR5Ver(v)) {
return "5.0";
}
if (isR6Ver(v)) {
return "6.0";
}
return v;
}
@ -140,15 +136,19 @@ public class VersionUtilities {
if (version.contains("-")) {
version = version.substring(0, version.indexOf("-"));
}
return Utilities.existsInList(version, "1.0.2", "1.4.0", "3.0.2", "4.0.1", "4.1.0", "4.3.0", "5.0.0", CURRENT_FULL_VERSION);
return Utilities.existsInList(version, "1.0.2", "1.4.0", "3.0.2", "4.0.1", "4.1.0", "4.3.0", "5.0.0", "6.0.0");
}
public static String listSupportedVersions() {
return "1.0.2, 1.4.0, 3.0.2, 4.0.1, 4.1.0, 4.3.0, 5.0, " + CURRENT_FULL_VERSION;
return "1.0.2, 1.4.0, 3.0.2, 4.0.1, 4.1.0, 4.3.0, 5.0, 6.0";
}
public static boolean isR6Ver(String ver) {
return ver != null && (ver.startsWith("6.0"));
}
public static boolean isR5Ver(String ver) {
return ver != null && (ver.startsWith("5.0") || ver.startsWith(CURRENT_VERSION) || ver.equals("current"));
return ver != null && (ver.startsWith("5.0"));
}
public static boolean isR4BVer(String ver) {
@ -197,24 +197,20 @@ public class VersionUtilities {
if (s.contains("#")) {
s = s.substring(0, s.indexOf("#"));
}
return Utilities.existsInList(s, "hl7.fhir.core","hl7.fhir.r2.core", "hl7.fhir.r2b.core", "hl7.fhir.r3.core", "hl7.fhir.r4.core", "hl7.fhir.r4b.core", "hl7.fhir.r5.core");
return Utilities.existsInList(s, "hl7.fhir.core","hl7.fhir.r2.core", "hl7.fhir.r2b.core", "hl7.fhir.r3.core", "hl7.fhir.r4.core", "hl7.fhir.r4b.core", "hl7.fhir.r5.core", "hl7.fhir.r6.core");
}
public static String getMajMin(String version) {
if (version == null)
return null;
if ("current".equals(version)) {
return CURRENT_VERSION;
}
if (Utilities.charCount(version, '.') == 1) {
String[] p = version.split("\\.");
return p[0]+"."+p[1];
} else if (Utilities.charCount(version, '.') == 2) {
String[] p = version.split("\\.");
return p[0]+"."+p[1];
} else if (Utilities.existsInList(version, "R2", "R2B", "R3", "R4", "R4B", "R5")) {
} else if (Utilities.existsInList(version, "R2", "R2B", "R3", "R4", "R4B", "R5", "R6")) {
switch (version) {
case "R2": return "1.0";
case "R2B": return "1.4";
@ -222,6 +218,7 @@ public class VersionUtilities {
case "R4": return "4.0";
case "R4B": return "4.3";
case "R5": return "5.0";
case "R6": return "6.0";
}
}
return null;
@ -376,6 +373,9 @@ public class VersionUtilities {
if ("r5".equals(version)) {
return "5.0.0";
}
if ("r6".equals(version)) {
return "6.0.0-cibuild";
}
throw new FHIRException("Unknown version "+version);
}
@ -386,7 +386,7 @@ public class VersionUtilities {
String v = url.substring(20, 24);
if (v.endsWith("/")) {
v = v.substring(0, v.length()-1);
if (Utilities.existsInList(v, "1.0", "1.4", "3.0", "4.0", "5.0", CURRENT_VERSION)) {
if (Utilities.existsInList(v, "1.0", "1.4", "3.0", "4.0", "5.0", "6.0")) {
return new VersionURLInfo(v, "http://hl7.org/fhir/"+url.substring(24));
}
}
@ -497,7 +497,7 @@ public class VersionUtilities {
res.add("ValueSet");
}
if (isR5Ver(version) || "current".equals(version)) {
if (isR5Ver(version) || isR6Ver(version)) {
res.add("ActorDefinition");
res.add("ActivityDefinition");
res.add("CapabilityStatement");
@ -555,9 +555,6 @@ public class VersionUtilities {
if (version == null) {
return false;
}
if (version.startsWith(CURRENT_VERSION) || version.equals("current")) {
return true;
}
String v = getMajMin(version);
return v.compareTo("4.5") >= 0;
}
@ -599,6 +596,7 @@ public class VersionUtilities {
case "4.0" : return "http://hl7.org/fhir/R4";
case "4.3" : return "http://hl7.org/fhir/R4B";
case "5.0" : return "http://hl7.org/fhir/R5";
case "6.0" : return "http://hl7.org/fhir/R6";
default:
return "http://hl7.org/fhir";
}
@ -612,6 +610,7 @@ public class VersionUtilities {
case "4.0" : return "R4";
case "4.3" : return "R4B";
case "5.0" : return "R5";
case "6.0" : return "R6";
default:
return "R?";
}
@ -621,5 +620,9 @@ public class VersionUtilities {
return version != null && (version.startsWith("5.") || version.startsWith("6.") || "current".equals(version));
}
public static boolean isR6Plus(String version) {
return version != null && version.startsWith("6.");
}
}

View File

@ -306,6 +306,7 @@ public class I18nConstants {
public static final String PROFILE___ERROR_GENERATING_SNAPSHOT = "Profile___Error_generating_snapshot";
public static final String PROFILE___HAS_NO_BASE_AND_NO_SNAPSHOT = "Profile___has_no_base_and_no_snapshot";
public static final String QUESTIONNAIRE_QR_ITEM_BADOPTION = "Questionnaire_QR_Item_BadOption";
public static final String QUESTIONNAIRE_QR_ITEM_BADOPTION_CS = "QUESTIONNAIRE_QR_ITEM_BADOPTION_CS";
public static final String QUESTIONNAIRE_QR_ITEM_CODING = "Questionnaire_QR_Item_Coding";
public static final String QUESTIONNAIRE_QR_ITEM_CODINGNOOPTIONS = "Questionnaire_QR_Item_CodingNoOptions";
public static final String QUESTIONNAIRE_QR_ITEM_DATENOOPTIONS = "Questionnaire_QR_Item_DateNoOptions";

View File

@ -1,9 +1,56 @@
package org.hl7.fhir.utilities.i18n;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.hl7.fhir.utilities.i18n.LanguageFileProducer.TextUnit;
import java.util.HashMap;
public abstract class LanguageFileProducer {
public static class TextUnit {
private String context;
private String srcText;
private String tgtText;
public TextUnit(String context, String srcText, String tgtText) {
super();
this.context = context;
this.srcText = srcText;
this.tgtText = tgtText;
}
public String getContext() {
return context;
}
public String getSrcText() {
return srcText;
}
public String getTgtText() {
return tgtText;
}
}
public class Translations {
private String id;
private Map<String, String> translations = new HashMap<>();
protected Translations(String id) {
super();
this.id = id;
}
public String getId() {
return id;
}
public Map<String, String> getTranslations() {
return translations;
}
}
public abstract class LanguageProducerLanguageSession {
protected String id;
@ -27,7 +74,7 @@ public abstract class LanguageFileProducer {
public abstract void finish() throws IOException;
public abstract void entry(String id, String src, String dst);
public abstract void entry(TextUnit unit);
}
public abstract class LanguageProducerSession {
@ -35,7 +82,7 @@ public abstract class LanguageFileProducer {
protected String id;
protected String baseLang;
protected LanguageProducerSession( String id, String baseLang) {
protected LanguageProducerSession(String id, String baseLang) {
super();
this.id = id;
this.baseLang = baseLang;
@ -58,4 +105,5 @@ public abstract class LanguageFileProducer {
public abstract LanguageProducerSession startSession(String id, String baseLang) throws IOException;
public abstract void finish();
public abstract List<TextUnit> loadTranslations(String baseLang, String targetLang);
}

View File

@ -1,6 +1,7 @@
package org.hl7.fhir.utilities.i18n;
import java.io.IOException;
import java.util.List;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
@ -70,17 +71,23 @@ public class PoGetTextProducer extends LanguageFileProducer {
}
@Override
public void entry(String id, String src, String dst) {
ln("#: "+id);
public void entry(TextUnit unit) {
ln("#: "+unit.getContext());
// if (context != null) {
// ln("#. "+context);
// }
ln("msgid \""+src+"\"");
ln("msgstr \""+dst+"\"");
ln("msgid \""+unit.getSrcText()+"\"");
ln("msgstr \""+unit.getTgtText()+"\"");
ln("");
}
}
@Override
public List<TextUnit> loadTranslations(String baseLang, String tgtLang) {
return null;
}
}

View File

@ -1,9 +1,11 @@
package org.hl7.fhir.utilities.i18n;
import java.io.IOException;
import java.util.List;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.i18n.LanguageFileProducer.TextUnit;
public class XLIFFProducer extends LanguageFileProducer {
@ -34,16 +36,16 @@ public class XLIFFProducer extends LanguageFileProducer {
}
@Override
public void entry(String id, String src, String dst) {
public void entry(TextUnit unit) {
i++;
ln(" <trans-unit id=\""+id+"\" resname=\""+this.id+"\">");
ln(" <trans-unit id=\""+id+"\" resname=\""+unit.getContext()+"\">");
// if (context != null) {
// ln(" <notes>");
// ln(" <note id=\"n"+i+"\">"+Utilities.escapeXml(context)+"</note>");
// ln(" </notes>");
// }
ln(" <source>"+Utilities.escapeXml(src)+"</source>");
ln(" <target>"+Utilities.escapeXml(dst)+"</target>");
ln(" <source>"+Utilities.escapeXml(unit.getSrcText())+"</source>");
ln(" <target>"+Utilities.escapeXml(unit.getTgtText())+"</target>");
ln(" </trans-unit>");
}
@ -81,4 +83,10 @@ public class XLIFFProducer extends LanguageFileProducer {
public void finish() {
// nothing
}
@Override
public List<TextUnit> loadTranslations(String baseLang, String tgtLang) {
return null;
}
}

View File

@ -36,6 +36,7 @@ import org.hl7.fhir.utilities.json.model.JsonArray;
import org.hl7.fhir.utilities.json.model.JsonElement;
import org.hl7.fhir.utilities.json.model.JsonObject;
import org.hl7.fhir.utilities.json.parser.JsonParser;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.IPackageProvider;
import org.hl7.fhir.utilities.npm.NpmPackage.NpmPackageFolder;
import org.hl7.fhir.utilities.npm.PackageList.PackageListEntry;
@ -88,6 +89,11 @@ import org.slf4j.LoggerFactory;
public class FilesystemPackageCacheManager extends BasePackageCacheManager implements IPackageCacheManager {
public enum FilesystemPackageCacheMode {
USER, SYSTEM, TESTING
}
// When running in testing mode, some packages are provided from the test case repository rather than by the normal means
// the PackageProvider is responsible for this. if no package provider is defined, or it declines to handle the package,
// then the normal means will be used
@ -111,31 +117,32 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
private JsonArray buildInfo;
private boolean suppressErrors;
/**
* Constructor
*/
@Deprecated
public FilesystemPackageCacheManager(boolean userMode, int toolsVersion) throws IOException {
myPackageServers.addAll(PackageServer.publicServers());
if (userMode)
cacheFolder = Utilities.path(System.getProperty("user.home"), ".fhir", "packages");
else
cacheFolder = Utilities.path("var", "lib", ".fhir", "packages");
if (!(new File(cacheFolder).exists()))
Utilities.createDirectory(cacheFolder);
if (!(new File(Utilities.path(cacheFolder, "packages.ini")).exists()))
TextFile.stringToFile("[cache]\r\nversion=" + CACHE_VERSION + "\r\n\r\n[urls]\r\n\r\n[local]\r\n\r\n", Utilities.path(cacheFolder, "packages.ini"), false);
createIniFile();
}
public FilesystemPackageCacheManager(boolean userMode) throws IOException {
init(userMode ? FilesystemPackageCacheMode.USER : FilesystemPackageCacheMode.SYSTEM);
}
public FilesystemPackageCacheManager(FilesystemPackageCacheMode mode) throws IOException {
init(mode);
}
public void init(FilesystemPackageCacheMode mode) throws IOException {
myPackageServers.addAll(PackageServer.publicServers());
if (userMode)
cacheFolder = Utilities.path(System.getProperty("user.home"), ".fhir", "packages");
else
switch (mode) {
case SYSTEM:
cacheFolder = Utilities.path("var", "lib", ".fhir", "packages");
break;
case USER:
cacheFolder = Utilities.path(System.getProperty("user.home"), ".fhir", "packages");
break;
case TESTING:
cacheFolder = Utilities.path("[tmp]", ".fhir", "packages");
break;
default:
break;
}
if (!(new File(cacheFolder).exists()))
Utilities.createDirectory(cacheFolder);
if (!(new File(Utilities.path(cacheFolder, "packages.ini")).exists()))

View File

@ -968,7 +968,7 @@ public class HierarchicalTableGenerator extends TranslatingUtilities {
for (Cell c : r.getCells()) {
tc = tc + c.span;
}
check(tc == size, "All rows must have the same number of columns as the titles ("+Integer.toString(size)+") but row "+path+" doesn't - it has "+tc+" ("+r.getCells().get(0).text()+"): "+r.getCells());
check(tc == size, "All rows must have the same number of columns as the titles ("+Integer.toString(size)+") but row "+path+" doesn't - it has "+tc+" ("+(r.getCells().size() > 0 ? "??" : r.getCells().get(0).text())+"): "+r.getCells());
int i = 0;
for (Row c : r.getSubRows()) {
check(c, "rows", size, path, i, r.getSubRows().size());

View File

@ -37,6 +37,7 @@ import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import org.hl7.fhir.exceptions.FHIRException;
@ -52,7 +53,6 @@ import ca.uhn.fhir.model.primitive.XhtmlDt;
public class XhtmlNode extends XhtmlFluent implements IBaseXhtml {
private static final long serialVersionUID = -4362547161441436492L;
public static class Location implements Serializable {
private static final long serialVersionUID = -4079302502900219721L;
private int line;
@ -87,6 +87,8 @@ public class XhtmlNode extends XhtmlFluent implements IBaseXhtml {
private boolean notPretty;
private boolean seperated;
private Boolean emptyExpanded;
private Map<String, XhtmlNode> namedParams;
private Map<String, String> namedParamValues;
public XhtmlNode() {
super();
@ -769,5 +771,70 @@ public class XhtmlNode extends XhtmlFluent implements IBaseXhtml {
return span("color: "+color, null);
}
public XhtmlNode param(String name) {
XhtmlNode node = new XhtmlNode(NodeType.Element, "p"); // this node is dead will never appear anywhere, but we are in paragraph mode
if (namedParams == null) {
namedParams = new HashMap<>();
}
namedParams.put(name, node);
return node;
}
public void paramValue(String name, String value) {
if (namedParamValues == null) {
namedParamValues = new HashMap<>();
}
namedParamValues.put(name, value);
}
public void paramValue(String name, int value) {
if (namedParamValues == null) {
namedParamValues = new HashMap<>();
}
namedParamValues.put(name, Integer.toString(value));
}
public void sentenceForParams(String structure) throws FHIRException, IOException {
XhtmlNode script = new XhtmlParser().parseFragment("<div>"+structure+"</div>");
for (XhtmlNode n : script.getChildNodes()) {
if ("param".equals(n.getName())) {
XhtmlNode node = namedParams.get(n.getAttribute("name"));
if (node != null) {
this.getChildNodes().addAll(node.getChildNodes());
}
} else if ("if".equals(n.getName())) {
String test = n.getAttribute("test");
if (passesTest(test)) {
this.getChildNodes().addAll(n.getChildNodes());
}
} else {
this.getChildNodes().add(n);
}
}
namedParams = null;
namedParamValues = null;
}
private boolean passesTest(String test) {
String[] p = test.split("\\s+");
if (p.length != 3) {
return false;
}
if (!namedParamValues.containsKey(p[0])) {
return false;
}
String pv = namedParamValues.get(p[0]);
switch (p[1]) {
case "=": return p[2].equalsIgnoreCase(pv);
case "!=": return !p[2].equalsIgnoreCase(pv);
case "<": return Utilities.isInteger(p[2]) && Utilities.isInteger(pv) && Integer.parseInt(pv) < Integer.parseInt(p[2]);
case "<=": return Utilities.isInteger(p[2]) && Utilities.isInteger(pv) && Integer.parseInt(pv) <= Integer.parseInt(p[2]);
case ">": return Utilities.isInteger(p[2]) && Utilities.isInteger(pv) && Integer.parseInt(pv) > Integer.parseInt(p[2]);
case ">=": return Utilities.isInteger(p[2]) && Utilities.isInteger(pv) && Integer.parseInt(pv) >= Integer.parseInt(p[2]);
}
return false;
}
}

View File

@ -72,7 +72,8 @@ Profile_VAL_MissingElement = Missing element ''{0}'' - required by fixed value a
Profile_VAL_NotAllowed = The element {0} is present in the instance but not allowed in the applicable {1} specified in profile
Measure_MR_M_None = No Measure is identified, so no validation can be performed against the Measure
Measure_MR_M_NotFound = The Measure ''{0}'' could not be resolved, so no validation can be performed against the Measure
Questionnaire_QR_Item_BadOption = The value provided ({0}::{1}) is not in the options value set in the questionnaire
Questionnaire_QR_Item_BadOption = The code provided {1} 9in the system {0}) is not in the options value set ({2}) in the questionnaire
QUESTIONNAIRE_QR_ITEM_BADOPTION_CS The code provided {1} cannot be validated in the options value set ({2}) in the questionnaire because the system {0} is unknown
Questionnaire_QR_Item_Coding = Error {0} validating Coding against Questionnaire Options
Questionnaire_QR_Item_CodingNoOptions = Cannot validate Coding option because no option list is provided
Questionnaire_QR_Item_DateNoOptions = Cannot validate date answer option because no option list is provided

View File

@ -7,6 +7,7 @@ import java.util.List;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.npm.CommonPackages;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode;
import org.hl7.fhir.utilities.npm.NpmPackage;
import org.hl7.fhir.utilities.npm.ToolsVersion;
import org.junit.jupiter.api.Assertions;
@ -16,14 +17,15 @@ public class PackageCacheTests {
@Test
public void testPath() throws IOException {
FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(FilesystemPackageCacheMode.TESTING);
NpmPackage npm = cache.loadPackage(CommonPackages.ID_PUBPACK, CommonPackages.VER_PUBPACK);
cache.clear();
List<String> list = cache.listPackages();
if (!list.isEmpty()) {
System.out.println("remaining packages: "+list.toString());
}
Assertions.assertTrue(list.isEmpty(), "List should be true but is "+list.toString());
NpmPackage npm = cache.loadPackage(CommonPackages.ID_PUBPACK, CommonPackages.VER_PUBPACK);
npm = cache.loadPackage(CommonPackages.ID_PUBPACK, CommonPackages.VER_PUBPACK);
npm.loadAllFiles();
Assertions.assertNotNull(npm);
File dir = new File(Utilities.path("[tmp]", "cache"));
@ -41,7 +43,7 @@ public class PackageCacheTests {
@Test
public void testPatchWildCard() throws IOException {
FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(FilesystemPackageCacheMode.TESTING);
cache.clear();
Assertions.assertEquals(cache.loadPackage("hl7.fhir.us.core", "3.1.0").version(), "3.1.0");
Assertions.assertEquals(cache.loadPackage("hl7.fhir.us.core", "3.1.1").version(), "3.1.1");
@ -51,7 +53,7 @@ public class PackageCacheTests {
@Test
public void testNotCaseSensitive() throws IOException {
FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(FilesystemPackageCacheMode.TESTING);
cache.clear();
Assertions.assertEquals(cache.loadPackage("KBV.Basis", "1.1.3").version(), "1.1.3");
Assertions.assertEquals(cache.loadPackage("kbv.basis", "1.1.3").version(), "1.1.3");
@ -59,7 +61,7 @@ public class PackageCacheTests {
@Test
public void testLastReleasedVersion() throws IOException {
FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
FilesystemPackageCacheManager cache = new FilesystemPackageCacheManager(FilesystemPackageCacheMode.TESTING);
cache.clear();
Assertions.assertEquals("0.0.8", cache.loadPackage(CommonPackages.ID_PUBPACK, "0.0.8").version());
Assertions.assertEquals(CommonPackages.VER_PUBPACK, cache.loadPackage(CommonPackages.ID_PUBPACK).version());

View File

@ -7,6 +7,7 @@ import java.io.ObjectOutputStream;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.xhtml.NodeType;
import org.hl7.fhir.utilities.xhtml.XhtmlComposer;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.hl7.fhir.utilities.xhtml.XhtmlParser;
@ -150,5 +151,62 @@ public class XhtmlNodeTest {
Assertions.assertEquals(src.trim(), xml.trim());
}
@Test
public void testComposeScripted1() throws IOException {
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
x.para().tx("This is a paragraph");
Assertions.assertEquals("<div><p>This is a paragraph</p></div>", new XhtmlComposer(true, false).compose(x));
}
@Test
public void testComposeScripted2() throws IOException {
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
XhtmlNode p = x.para();
p.tx("This is ");
p.tx("a paragraph");
Assertions.assertEquals("<div><p>This is a paragraph</p></div>", new XhtmlComposer(true, false).compose(x));
}
@Test
public void testComposeScripted3() throws IOException {
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
XhtmlNode p = x.para();
p.tx("This is a ");
p.b().tx("long");
p.tx(" paragraph");
Assertions.assertEquals("<div><p>This is a <b>long</b> paragraph</p></div>", new XhtmlComposer(true, false).compose(x));
}
@Test
public void testComposeScripted4() throws IOException {
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
XhtmlNode p = x.para();
p.param("long").b().tx("long");
p.sentenceForParams("This <b>is</b> a <param name='long'/> paragraph");
Assertions.assertEquals("<div><p>This <b>is</b> a <b>long</b> paragraph</p></div>", new XhtmlComposer(true, false).compose(x));
}
@Test
public void testComposeScripted5() throws IOException {
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
XhtmlNode p = x.para();
p.param("long").b().tx("long");
p.paramValue("count", "2");
p.sentenceForParams("This <b>is</b> a <param name='long'/> paragraph<if test='count != 1'>s</if>");
Assertions.assertEquals("<div><p>This <b>is</b> a <b>long</b> paragraphs</p></div>", new XhtmlComposer(true, false).compose(x));
}
@Test
public void testComposeScripted6() throws IOException {
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
XhtmlNode p = x.para();
p.param("long").b().tx("long");
p.paramValue("count", "1");
p.sentenceForParams("This <b>is</b> a <param name='long'/> paragraph<if test='count != 1'>s</if>");
Assertions.assertEquals("<div><p>This <b>is</b> a <b>long</b> paragraph</p></div>", new XhtmlComposer(true, false).compose(x));
}
}

View File

@ -829,7 +829,7 @@ public class IgLoader {
else
throw new FHIRException("Unsupported format for " + fn);
r = VersionConvertorFactory_10_50.convertResource(res, new org.hl7.fhir.convertors.misc.IGR2ConvertorAdvisor5());
} else if (fhirVersion.startsWith("5.0") || "current".equals(fhirVersion)) {
} else if (fhirVersion.startsWith("5.0")) {
if (fn.endsWith(".xml") && !fn.endsWith("template.xml"))
r = new XmlParser().parse(new ByteArrayInputStream(content));
else if (fn.endsWith(".json") && !fn.endsWith("template.json"))

View File

@ -358,7 +358,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
engine.initContext(timeTracker);
engine.setIgLoader(new IgLoader(engine.getPcm(), engine.getContext(), engine.getVersion(), engine.isDebug()));
loadTx(engine);
if (VersionUtilities.isR5Ver(version)) {
if (VersionUtilities.isR5Plus(version)) {
engine.loadPackage("hl7.fhir.uv.extensions", null);
}
return engine;
@ -377,7 +377,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
if (THO) {
loadTx(engine);
}
if (VersionUtilities.isR5Ver(version)) {
if (VersionUtilities.isR5Plus(version)) {
engine.loadPackage("hl7.fhir.uv.extensions", null);
}
return engine;
@ -394,7 +394,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
if (VersionUtilities.isR4BVer(version)) {
pid = "hl7.terminology.r4";
}
if (VersionUtilities.isR5Ver(version)) {
if (VersionUtilities.isR5Plus(version)) {
pid = "hl7.terminology.r5";
}
if (pid != null) {
@ -881,7 +881,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
new org.hl7.fhir.dstu2.formats.JsonParser().setOutputStyle(org.hl7.fhir.dstu2.formats.IParser.OutputStyle.PRETTY).compose(s, res);
else
throw new FHIRException("Unsupported format for " + fn);
} else if (VersionUtilities.isR5Ver(version)) {
} else if (VersionUtilities.isR5Plus(version)) {
if (fn.endsWith(".xml") && !fn.endsWith("template.xml"))
new XmlParser().setOutputStyle(org.hl7.fhir.r5.formats.IParser.OutputStyle.PRETTY).compose(s, r);
else if (fn.endsWith(".json") && !fn.endsWith("template.json"))
@ -973,7 +973,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
public FilesystemPackageCacheManager getPcm() throws IOException {
if (pcm == null) {
//System.out.println("Creating Package manager?");
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
}
return pcm;
}

View File

@ -20,6 +20,7 @@ import org.hl7.fhir.convertors.loaders.loaderR5.R3ToR5Loader;
import org.hl7.fhir.convertors.loaders.loaderR5.R4BToR5Loader;
import org.hl7.fhir.convertors.loaders.loaderR5.R4ToR5Loader;
import org.hl7.fhir.convertors.loaders.loaderR5.R5ToR5Loader;
import org.hl7.fhir.convertors.loaders.loaderR5.R6ToR5Loader;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.context.SimpleWorkerContext;
@ -75,6 +76,9 @@ public class ValidatorUtils {
if (VersionUtilities.isR5Ver(version)) {
return new R5ToR5Loader(Utilities.strings("CapabilityStatement", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem"), loader);
}
if (VersionUtilities.isR6Ver(version)) {
return new R6ToR5Loader(Utilities.strings("CapabilityStatement", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem"), loader);
}
return null;
}

View File

@ -50,6 +50,8 @@ public class CliContext {
@JsonProperty("htmlInMarkdownCheck")
private HtmlInMarkdownCheck htmlInMarkdownCheck = HtmlInMarkdownCheck.WARNING;
@JsonProperty("langTransform")
private String langTransform = null;
@JsonProperty("map")
private String map = null;
@JsonProperty("output")
@ -136,6 +138,17 @@ public class CliContext {
return this;
}
@JsonProperty("langTransform")
public String getLangTransform() {
return langTransform;
}
@JsonProperty("langTransform")
public CliContext setLangTransform(String langTransform) {
this.langTransform = langTransform;
return this;
}
@JsonProperty("igs")
public List<String> getIgs() {
return igs;

View File

@ -107,7 +107,7 @@ public class ValidationService {
public VersionSourceInformation scanForVersions(CliContext cliContext) throws Exception {
VersionSourceInformation versions = new VersionSourceInformation();
IgLoader igLoader = new IgLoader(
new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION),
new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER),
new SimpleWorkerContext.SimpleWorkerContextBuilder().fromNothing(),
null);
for (String src : cliContext.getIgs()) {
@ -392,11 +392,7 @@ public class ValidationService {
IgLoader igLoader = new IgLoader(validator.getPcm(), validator.getContext(), validator.getVersion(), validator.isDebug());
igLoader.loadIg(validator.getIgs(), validator.getBinaries(), "hl7.terminology", false);
if (!VersionUtilities.isR5Ver(validator.getContext().getVersion())) {
System.out.print(" Load R5 Extensions");
R5ExtensionsLoader r5e = new R5ExtensionsLoader(validator.getPcm(), validator.getContext());
r5e.load();
r5e.loadR5Extensions();
System.out.println(" - " + r5e.getCount() + " resources (" + tt.milestone() + ")");
igLoader.loadIg(validator.getIgs(), validator.getBinaries(), "hl7.fhir.uv.extensions", false);
}
System.out.print(" Terminology server " + cliContext.getTxServer());
String txver = validator.setTerminologyServer(cliContext.getTxServer(), cliContext.getTxLog(), ver);
@ -458,7 +454,7 @@ public class ValidationService {
public String determineVersion(CliContext cliContext, String sessionId) throws Exception {
if (cliContext.getMode() != EngineMode.VALIDATION) {
return "current";
return "5.0";
}
System.out.println("Scanning for versions (no -version parameter):");
VersionSourceInformation versions = scanForVersions(cliContext);
@ -468,8 +464,8 @@ public class ValidationService {
}
}
if (versions.isEmpty()) {
System.out.println(" No Version Info found: Using Default version '" + VersionUtilities.CURRENT_DEFAULT_VERSION + "'");
return VersionUtilities.CURRENT_DEFAULT_FULL_VERSION;
System.out.println(" No Version Info found: Using Default version R5");
return "5.0.0";
}
if (versions.size() == 1) {
System.out.println("-> use version " + versions.version());

View File

@ -13,7 +13,7 @@ public class Common {
public static String getVersion(String[] args) {
String v = Params.getParam(args, "-version");
if (v == null) {
v = "current";
v = "5.0";
for (int i = 0; i < args.length; i++) {
if ("-ig".equals(args[i])) {
if (i + 1 == args.length)
@ -24,16 +24,20 @@ public class Common {
}
}
}
} else if ("1.0".equals(v)) {
} else if (VersionUtilities.isR2Ver(v)) {
v = "1.0";
} else if ("1.4".equals(v)) {
} else if (VersionUtilities.isR2BVer(v)) {
v = "1.4";
} else if ("3.0".equals(v)) {
} else if (VersionUtilities.isR3Ver(v)) {
v = "3.0";
} else if ("4.0".equals(v)) {
} else if (VersionUtilities.isR4Ver(v)) {
v = "4.0";
} else if (v.startsWith(Constants.VERSION)) {
v = "current";
} else if (VersionUtilities.isR4BVer(v)) {
v = "4.3";
} else if (VersionUtilities.isR5Ver(v)) {
v = "5.0";
} else if (VersionUtilities.isR6Ver(v)) {
v = "6.0";
}
return v;
}
@ -49,7 +53,7 @@ public class Common {
*/
public static String getVersionFromIGName(String defaultValue, String igFileName) {
if (igFileName.equals("hl7.fhir.core")) {
defaultValue = "current";
defaultValue = "5.0";
} else if (igFileName.startsWith("hl7.fhir.core#")) {
defaultValue = VersionUtilities.getCurrentPackageVersion(igFileName.substring(14));
} else if (igFileName.startsWith("hl7.fhir.r2.core#") || igFileName.equals("hl7.fhir.r2.core")) {
@ -61,7 +65,9 @@ public class Common {
} else if (igFileName.startsWith("hl7.fhir.r4.core#") || igFileName.equals("hl7.fhir.r4.core")) {
defaultValue = "4.0";
} else if (igFileName.startsWith("hl7.fhir.r5.core#") || igFileName.equals("hl7.fhir.r5.core")) {
defaultValue = "current";
defaultValue = "5.0";
} else if (igFileName.startsWith("hl7.fhir.r6.core#") || igFileName.equals("hl7.fhir.r6.core")) {
defaultValue = "6.0";
}
return defaultValue;
}

View File

@ -22,7 +22,7 @@ public class Display {
}
public static void printCliArgumentsAndInfo(String[] args) throws IOException {
System.out.println(" Paths: Current = " + System.getProperty("user.dir") + ", Package Cache = " + new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION).getFolder());
System.out.println(" Paths: Current = " + System.getProperty("user.dir") + ", Package Cache = " + new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER).getFolder());
System.out.print(" Params:");
for (String s : args) {
System.out.print(s.contains(" ") ? " \"" + s + "\"" : " " + s);
@ -40,9 +40,6 @@ public class Display {
final static String[][] PLACEHOLDERS = {
{ getMoustacheString("XML_AND_JSON_FHIR_VERSIONS"), "1.0, 1.4, 3.0, 4.0," + Constants.VERSION_MM },
{ getMoustacheString("TURTLE_FHIR_VERSIONS"), "3.0, 4.0, " + Constants.VERSION_MM },
{ getMoustacheString("FHIR_MAJOR_VERSIONS"), "1.0|1.4|3.0|" + VersionUtilities.CURRENT_VERSION},
{ getMoustacheString("FHIR_MINOR_VERSIONS"), "1.0.2|1.4.0|3.0.2|4.0.1|" + VersionUtilities.CURRENT_FULL_VERSION },
{ getMoustacheString("FHIR_CURRENT_VERSION"), VersionUtilities.CURRENT_VERSION},
};
final static String replacePlaceholders(final String input, final String[][] placeholders) {

View File

@ -4,6 +4,7 @@ public enum EngineMode {
VALIDATION,
COMPILE,
TRANSFORM,
LANG_TRANSFORM,
NARRATIVE,
SNAPSHOT,
SCAN,

View File

@ -41,6 +41,7 @@ public class Params {
public static final String NO_NATIVE = "-no-native";
public static final String COMPILE = "-compile";
public static final String TRANSFORM = "-transform";
public static final String LANG_TRANSFORM = "-lang-transform";
public static final String NARRATIVE = "-narrative";
public static final String SNAPSHOT = "-snapshot";
public static final String SCAN = "-scan";
@ -237,6 +238,9 @@ public class Params {
} else if (args[i].equals(TRANSFORM)) {
cliContext.setMap(args[++i]);
cliContext.setMode(EngineMode.TRANSFORM);
} else if (args[i].equals(LANG_TRANSFORM)) {
cliContext.setLangTransform(args[++i]);
cliContext.setMode(EngineMode.LANG_TRANSFORM);
} else if (args[i].equals(COMPILE)) {
cliContext.setMap(args[++i]);
cliContext.setMode(EngineMode.COMPILE);

View File

@ -23,6 +23,7 @@ import org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType;
import org.hl7.fhir.r5.model.StringType;
import org.hl7.fhir.r5.model.TimeType;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.terminologies.ValueSetExpander.TerminologyServiceErrorClass;
import org.hl7.fhir.r5.utils.FHIRPathEngine;
import org.hl7.fhir.r5.utils.XVerExtensionManager;
import org.hl7.fhir.r5.utils.validation.ValidationContextCarrier;
@ -562,7 +563,11 @@ public class QuestionnaireValidator extends BaseValidator {
ValidationResult res = context.validateCode(new ValidationOptions(stack.getWorkingLang()), c, vs, vc);
timeTracker.tx(t, "vc "+c.getSystem()+"#"+c.getCode()+" '"+c.getDisplay()+"'");
if (!res.isOk()) {
ok = txRule(errors, NO_RULE_DATE, res.getTxLink(), IssueType.CODEINVALID, value.line(), value.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_BADOPTION, c.getSystem(), c.getCode()) && ok;
if (res.getErrorClass() == TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED) {
txWarning(errors, NO_RULE_DATE, res.getTxLink(), IssueType.CODEINVALID, value.line(), value.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_BADOPTION_CS, c.getSystem(), c.getCode(), vs.present());
} else {
ok = txRule(errors, NO_RULE_DATE, res.getTxLink(), IssueType.CODEINVALID, value.line(), value.col(), stack.getLiteralPath(), false, I18nConstants.QUESTIONNAIRE_QR_ITEM_BADOPTION, c.getSystem(), c.getCode(), vs.present()) && ok;
}
} else if (res.getSeverity() != null) {
super.addValidationMessage(errors, NO_RULE_DATE, IssueType.CODEINVALID, value.line(), value.col(), stack.getLiteralPath(), res.getMessage(), res.getSeverity(), Source.TerminologyEngine, null);
} else if (res.getMessage() != null) {

View File

@ -570,7 +570,7 @@ public class StructureDefinitionValidator extends BaseValidator {
StructureDefinition t = determineBaseType(sd);
if (t == null) {
ok = rule(errors, NO_RULE_DATE, IssueType.EXCEPTION, stack.getLiteralPath(), false, I18nConstants.SD_ED_TYPE_PROFILE_NOTYPE, p) && ok;
} else if (!VersionUtilities.isR5Ver(context.getVersion())) {
} else if (!VersionUtilities.isR5Plus(context.getVersion())) {
ok = rule(errors, NO_RULE_DATE, IssueType.EXCEPTION, stack.getLiteralPath(), VersionUtilities.getCanonicalResourceNames(context.getVersion()).contains(t.getType()) || "Resource".equals(t.getType()), I18nConstants.SD_ED_TYPE_PROFILE_WRONG_TARGET, p, t, code, path, "Canonical Resource") && ok;
} else {
ok = rule(errors, NO_RULE_DATE, IssueType.EXCEPTION, stack.getLiteralPath(), Utilities.existsInList(t.getType(), "Resource", "CanonicalResource") || VersionUtilities.getCanonicalResourceNames(context.getVersion()).contains(t.getType()), I18nConstants.SD_ED_TYPE_PROFILE_WRONG_TARGET, p, t, code, path, "Canonical Resource") && ok;

View File

@ -21,7 +21,7 @@ public class PackageValidator {
}
private void execute() throws IOException {
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
PackageClient pc = new PackageClient(PackageServer.primaryServer());
for (PackageInfo t : pc.search(null, null, null, false)) {

View File

@ -17,5 +17,5 @@ public class TestModules {
VALIDATION_MODULE
};
public static final List<String> JUNIT4_CLASSNAMES = Arrays.asList("org.hl7.fhir.validation.tests.ValidationTests");
public static final List<String> JUNIT4_CLASSNAMES = Arrays.asList("org.hl7.fhir.validation.tests.ValidationTests", "org.hl7.fhir.terminologies.tests.TerminologyServiceTests");
}

View File

@ -110,7 +110,7 @@ public class ComparisonTests {
if (context == null) {
System.out.println("---- Load R5 ----------------------------------------------------------------");
context = TestingUtilities.getSharedWorkerContext();
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
NpmPackage npm = pcm.loadPackage("hl7.fhir.us.core#3.1.0");
BaseWorkerContext bc = (BaseWorkerContext) context;
boolean dupl = bc.isAllowLoadingDuplicates();
@ -123,7 +123,7 @@ public class ComparisonTests {
if (!new File(Utilities.path("[tmp]", "comparison")).exists()) {
System.out.println("---- Set up Output ----------------------------------------------------------");
Utilities.createDirectory(Utilities.path("[tmp]", "comparison"));
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
NpmPackage npm = pcm.loadPackage(CommonPackages.ID_PUBPACK, CommonPackages.VER_PUBPACK);
for (String f : npm.list("other")) {
TextFile.streamToFile(npm.load("other", f), Utilities.path("[tmp]", "comparison", f));

View File

@ -309,7 +309,7 @@ public class R3R4ConversionTests implements ITransformerServices, IValidatorReso
if (contextR3 != null)
return;
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
R3ToR4Loader ldr = (R3ToR4Loader) new R3ToR4Loader().setPatchUrls(true).setKillPrimitives(true);
System.out.println("loading R3");

View File

@ -89,7 +89,7 @@ public class UtilitiesXTests {
if (!fcontexts.containsKey(version)) {
FilesystemPackageCacheManager pcm;
try {
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
pcm = new FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager.FilesystemPackageCacheMode.USER);
IWorkerContext fcontext = TestingUtilities.getWorkerContext(pcm.loadPackage(VersionUtilities.packageForVersion(version), version), loaderForVersion(version));
fcontext.setUcumService(new UcumEssenceService(UtilitiesXTests.loadTestResourceStream("ucum", "ucum-essence.xml")));
fcontext.setExpansionProfile(new Parameters());

View File

@ -0,0 +1,249 @@
package org.hl7.fhir.terminology.tests;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_50;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_14_50;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_50;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_40_50;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
import org.hl7.fhir.r5.formats.JsonParser;
import org.hl7.fhir.r5.formats.XmlParser;
import org.hl7.fhir.r5.model.Constants;
import org.hl7.fhir.r5.model.OperationOutcome;
import org.hl7.fhir.r5.model.OperationOutcome.IssueSeverity;
import org.hl7.fhir.r5.model.OperationOutcome.IssueType;
import org.hl7.fhir.r5.model.OperationOutcome.OperationOutcomeIssueComponent;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionParameterComponent;
import org.hl7.fhir.r5.terminologies.ValueSetExpander.ValueSetExpansionOutcome;
import org.hl7.fhir.r5.test.utils.CompareUtilities;
import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.terminology.tests.TerminologyServiceTests.JsonObjectPair;
import org.hl7.fhir.utilities.FhirPublication;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.json.model.JsonObject;
import org.hl7.fhir.validation.ValidationEngine;
import org.hl7.fhir.validation.tests.ValidationEngineTests;
import org.hl7.fhir.validation.tests.utilities.TestUtilities;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import com.google.common.base.Charsets;
@RunWith(Parameterized.class)
public class TerminologyServiceTests {
public static class JsonObjectPair {
public JsonObjectPair(JsonObject suite, JsonObject test) {
this.suite = suite;
this.test = test;
}
private JsonObject suite;
private JsonObject test;
}
@Parameters(name = "{index}: id {0}")
public static Iterable<Object[]> data() throws IOException {
String contents = TestingUtilities.loadTestResource("tx", "test-cases.json");
Map<String, JsonObjectPair> examples = new HashMap<String, JsonObjectPair>();
manifest = org.hl7.fhir.utilities.json.parser.JsonParser.parseObject(contents);
for (org.hl7.fhir.utilities.json.model.JsonObject suite : manifest.getJsonObjects("suites")) {
String sn = suite.asString("name");
for (org.hl7.fhir.utilities.json.model.JsonObject test : suite.getJsonObjects("tests")) {
String tn = test.asString("name");
examples.put(sn+"."+tn, new JsonObjectPair(suite, test));
}
}
List<String> names = new ArrayList<String>(examples.size());
names.addAll(examples.keySet());
Collections.sort(names);
List<Object[]> objects = new ArrayList<Object[]>(examples.size());
for (String id : names) {
objects.add(new Object[]{id, examples.get(id)});
}
return objects;
}
private static org.hl7.fhir.utilities.json.model.JsonObject manifest;
private JsonObjectPair setup;
private String version;
private String name;
private static ValidationEngine baseEngine;
public TerminologyServiceTests(String name, JsonObjectPair setup) {
this.name = name;
this.setup = setup;
version = "5.0.0";
}
@SuppressWarnings("deprecation")
@Test
public void test() throws Exception {
if (baseEngine == null) {
baseEngine = TestUtilities.getValidationEngine("hl7.fhir.r5.core#5.0.0", null, null, FhirPublication.R5, true, "5.0.0");
}
ValidationEngine engine = new ValidationEngine(this.baseEngine);
for (String s : setup.suite.forceArray("setup").asStrings()) {
Resource res = loadResource(s);
engine.seeResource(res);
}
Resource req = loadResource(setup.test.asString("request"));
String resp = TestingUtilities.loadTestResource("tx", setup.test.asString("response"));
if (setup.test.asString("operation").equals("expand")) {
expand(engine, req, resp, setup.test.asString("response"));
} else if (setup.test.asString("operation").equals("validate-code")) {
validate(engine, req, resp);
} else {
Assertions.fail("Unknown Operation "+setup.test.asString("operation"));
}
}
private void expand(ValidationEngine engine, Resource req, String resp, String fn) throws IOException {
String fp = Utilities.path("[tmp]", "tx", fn);
File fo = new File(fp);
if (fo.exists()) {
fo.delete();
}
org.hl7.fhir.r5.model.Parameters p = ( org.hl7.fhir.r5.model.Parameters) req;
ValueSet vs = engine.getContext().fetchResource(ValueSet.class, p.getParameterValue("url").primitiveValue());
boolean hierarchical = p.hasParameter("excludeNested") ? p.getParameterBool("excludeNested") == false : true;
Assertions.assertNotNull(vs);
ValueSetExpansionOutcome vse = engine.getContext().expandVS(vs, false, hierarchical, false, p);
if (resp.contains("\"ValueSet\"")) {
if (vse.getValueset() == null) {
Assertions.fail(vse.getError());
} else {
if (!p.hasParameter("excludeNested")) {
removeParameter(vse.getValueset(), "excludeNested");
}
String vsj = new JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(vse.getValueset());
String diff = CompareUtilities.checkJsonSrcIsSame(resp, vsj);
if (diff != null) {
Utilities.createDirectory(Utilities.getDirectoryForFile(fp));
TextFile.stringToFile(vsj, fp);
}
Assertions.assertTrue(diff == null, diff);
}
} else {
OperationOutcome oo = new OperationOutcome();
OperationOutcomeIssueComponent e = new OperationOutcomeIssueComponent();
e.setSeverity(IssueSeverity.ERROR);
switch (vse.getErrorClass()) {
case BLOCKED_BY_OPTIONS:
e.setCode(IssueType.FORBIDDEN);
break;
case BUSINESS_RULE:
e.setCode(IssueType.BUSINESSRULE);
break;
case CODESYSTEM_UNSUPPORTED:
e.setCode(IssueType.INVALID);
break;
case INTERNAL_ERROR:
e.setCode(IssueType.EXCEPTION);
break;
case NOSERVICE:
e.setCode(IssueType.CONFLICT);
break;
case SERVER_ERROR:
e.setCode(IssueType.EXCEPTION);
break;
case UNKNOWN:
e.setCode(IssueType.UNKNOWN);
break;
case VALUESET_UNSUPPORTED:
e.setCode(IssueType.NOTSUPPORTED);
break;
}
e.getDetails().setText(vse.getError());
oo.addIssue(e);
String ooj = new JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(oo);
String diff = CompareUtilities.checkJsonSrcIsSame(resp, ooj);
if (diff != null) {
Utilities.createDirectory(Utilities.getDirectoryForFile(fp));
TextFile.stringToFile(ooj, fp);
}
Assertions.assertTrue(diff == null, diff);
}
}
private void removeParameter(ValueSet valueset, String name) {
for (ValueSetExpansionParameterComponent exp : valueset.getExpansion().getParameter()) {
if (exp.getName().equals(name)) {
valueset.getExpansion().getParameter().remove(exp);
return;
}
}
}
private void validate(ValidationEngine engine2, Resource req, String resp) {
Assertions.fail("validate not done yet");
}
public Resource loadResource(String filename) throws IOException, FHIRFormatError, FileNotFoundException, FHIRException, DefinitionException {
String contents = TestingUtilities.loadTestResource("tx", filename);
try (InputStream inputStream = IOUtils.toInputStream(contents, Charsets.UTF_8)) {
if (filename.contains(".json")) {
if (Constants.VERSION.equals(version) || "5.0".equals(version))
return new JsonParser().parse(inputStream);
else if (org.hl7.fhir.dstu3.model.Constants.VERSION.equals(version) || "3.0".equals(version))
return VersionConvertorFactory_30_50.convertResource(new org.hl7.fhir.dstu3.formats.JsonParser().parse(inputStream));
else if (org.hl7.fhir.dstu2016may.model.Constants.VERSION.equals(version) || "1.4".equals(version))
return VersionConvertorFactory_14_50.convertResource(new org.hl7.fhir.dstu2016may.formats.JsonParser().parse(inputStream));
else if (org.hl7.fhir.dstu2.model.Constants.VERSION.equals(version) || "1.0".equals(version))
return VersionConvertorFactory_10_50.convertResource(new org.hl7.fhir.dstu2.formats.JsonParser().parse(inputStream));
else if (org.hl7.fhir.r4.model.Constants.VERSION.equals(version) || "4.0".equals(version))
return VersionConvertorFactory_40_50.convertResource(new org.hl7.fhir.r4.formats.JsonParser().parse(inputStream));
else
throw new FHIRException("unknown version " + version);
} else {
if (Constants.VERSION.equals(version) || "5.0".equals(version))
return new XmlParser().parse(inputStream);
else if (org.hl7.fhir.dstu3.model.Constants.VERSION.equals(version) || "3.0".equals(version))
return VersionConvertorFactory_30_50.convertResource(new org.hl7.fhir.dstu3.formats.XmlParser().parse(inputStream));
else if (org.hl7.fhir.dstu2016may.model.Constants.VERSION.equals(version) || "1.4".equals(version))
return VersionConvertorFactory_14_50.convertResource(new org.hl7.fhir.dstu2016may.formats.XmlParser().parse(inputStream));
else if (org.hl7.fhir.dstu2.model.Constants.VERSION.equals(version) || "1.0".equals(version))
return VersionConvertorFactory_10_50.convertResource(new org.hl7.fhir.dstu2.formats.XmlParser().parse(inputStream));
else if (org.hl7.fhir.r4.model.Constants.VERSION.equals(version) || "4.0".equals(version))
return VersionConvertorFactory_40_50.convertResource(new org.hl7.fhir.r4.formats.XmlParser().parse(inputStream));
else
throw new FHIRException("unknown version " + version);
}
}
}
@AfterClass
public static void saveWhenDone() throws IOException {
}
}

View File

@ -59,7 +59,7 @@ public class LoadIgTests {
hl7Validator.prepare();
IgLoader igLoader = new IgLoader(hl7Validator.getPcm(), hl7Validator.getContext(), hl7Validator.getVersion(), true);
byte[] b = TextFile.streamToBytes(TestingUtilities.loadTestResourceStream("r5", "snapshot-generation", "t34-expected.xml")); // yes the choice of R5 is deliberate here - it's the same content as R4.
byte[] b = TextFile.streamToBytes(TestingUtilities.loadTestResourceStream("r4b", "snapshot-generation", "t34-expected.xml")); // yes the choice of R5 is deliberate here - it's the same content as R4.
for (int i = 0; i < DO_TIMES; i++) {
System.gc();