diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/DefaultProfileValidationSupport.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/DefaultProfileValidationSupport.java index 257080e74d5..5d0cdf4fae5 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/DefaultProfileValidationSupport.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/DefaultProfileValidationSupport.java @@ -43,6 +43,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.Properties; @@ -341,6 +342,12 @@ public class DefaultProfileValidationSupport implements IValidationSupport { private void loadStructureDefinitions(Map theCodeSystems, String theClasspath) { ourLog.info("Loading structure definitions from classpath: {}", theClasspath); + + String packageUserData = null; + if (myCtx.getVersion().getVersion().isEqualOrNewerThan(FhirVersionEnum.DSTU3)) { + packageUserData = "hl7.fhir." + myCtx.getVersion().getVersion().name().replace("DSTU", "R").toLowerCase(Locale.US); + } + try (InputStream valueSetText = DefaultProfileValidationSupport.class.getResourceAsStream(theClasspath)) { if (valueSetText != null) { try (InputStreamReader reader = new InputStreamReader(valueSetText, Constants.CHARSET_UTF8)) { @@ -358,6 +365,12 @@ public class DefaultProfileValidationSupport implements IValidationSupport { } + // This is used by the validator to determine which package a given SD came from. + // I don't love this use of magic strings but that's what is expected currently + if (packageUserData != null) { + next.setUserData("package", packageUserData); + } + } } } else { diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/IValidationSupport.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/IValidationSupport.java index 2b5df22bc6d..7a8cb40fbf6 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/IValidationSupport.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/IValidationSupport.java @@ -32,6 +32,7 @@ import org.hl7.fhir.instance.model.api.IBase; import org.hl7.fhir.instance.model.api.IBaseCoding; import org.hl7.fhir.instance.model.api.IBaseParameters; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IPrimitiveType; import javax.annotation.Nonnull; @@ -257,10 +258,13 @@ public interface IValidationSupport { /** * Fetch the given binary data by key. + * * @param binaryKey * @return */ - default byte[] fetchBinary(String binaryKey) { return null; } + default byte[] fetchBinary(String binaryKey) { + return null; + } /** * Validates that the given code exists and if possible returns a display @@ -814,14 +818,14 @@ public interface IValidationSupport { class TranslateCodeRequest { - private List myCodings; private final String myTargetSystemUrl; private final String myConceptMapUrl; private final String myConceptMapVersion; private final String mySourceValueSetUrl; private final String myTargetValueSetUrl; - private final Long myResourcePid; + private final IIdType myResourceId; private final boolean myReverse; + private List myCodings; public TranslateCodeRequest(List theCodings, String theTargetSystemUrl) { myCodings = theCodings; @@ -830,26 +834,26 @@ public interface IValidationSupport { myConceptMapVersion = null; mySourceValueSetUrl = null; myTargetValueSetUrl = null; - myResourcePid = null; + myResourceId = null; myReverse = false; } public TranslateCodeRequest( - List theCodings, - String theTargetSystemUrl, - String theConceptMapUrl, - String theConceptMapVersion, - String theSourceValueSetUrl, - String theTargetValueSetUrl, - Long theResourcePid, - boolean theReverse) { + List theCodings, + String theTargetSystemUrl, + String theConceptMapUrl, + String theConceptMapVersion, + String theSourceValueSetUrl, + String theTargetValueSetUrl, + IIdType theResourceId, + boolean theReverse) { myCodings = theCodings; myTargetSystemUrl = theTargetSystemUrl; myConceptMapUrl = theConceptMapUrl; myConceptMapVersion = theConceptMapVersion; mySourceValueSetUrl = theSourceValueSetUrl; myTargetValueSetUrl = theTargetValueSetUrl; - myResourcePid = theResourcePid; + myResourceId = theResourceId; myReverse = theReverse; } @@ -872,7 +876,7 @@ public interface IValidationSupport { .append(myConceptMapVersion, that.myConceptMapVersion) .append(mySourceValueSetUrl, that.mySourceValueSetUrl) .append(myTargetValueSetUrl, that.myTargetValueSetUrl) - .append(myResourcePid, that.myResourcePid) + .append(myResourceId, that.myResourceId) .append(myReverse, that.myReverse) .isEquals(); } @@ -886,7 +890,7 @@ public interface IValidationSupport { .append(myConceptMapVersion) .append(mySourceValueSetUrl) .append(myTargetValueSetUrl) - .append(myResourcePid) + .append(myResourceId) .append(myReverse) .toHashCode(); } @@ -915,8 +919,8 @@ public interface IValidationSupport { return myTargetValueSetUrl; } - public Long getResourcePid() { - return myResourcePid; + public IIdType getResourceId() { + return myResourceId; } public boolean isReverse() { diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/DatatypeUtil.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/DatatypeUtil.java index ae0d0a88a15..1f6d4404dee 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/DatatypeUtil.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/DatatypeUtil.java @@ -68,4 +68,11 @@ public class DatatypeUtil { return thePrimitiveType != null ? thePrimitiveType.getValueAsString() : null; } + /** + * Returns {@link IPrimitiveType#getValue()} if thePrimitiveType is + * not null, else returns null. + */ + public static Boolean toBooleanValue(IPrimitiveType thePrimitiveType) { + return thePrimitiveType != null ? thePrimitiveType.getValue() : null; + } } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/SingleValidationMessage.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/SingleValidationMessage.java index 02e7f45f659..311afbf49b2 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/SingleValidationMessage.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/SingleValidationMessage.java @@ -34,6 +34,13 @@ public class SingleValidationMessage { private String myMessageId; private ResultSeverityEnum mySeverity; + /** + * Constructor + */ + public SingleValidationMessage() { + super(); + } + @Override public boolean equals(Object obj) { if (this == obj) { diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/CreatePackageCommand.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/CreatePackageCommand.java index e9eb2b2cf92..74e7d308a91 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/CreatePackageCommand.java +++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/CreatePackageCommand.java @@ -25,8 +25,6 @@ import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import com.google.common.io.Files; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; @@ -35,6 +33,8 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.io.filefilter.FalseFileFilter; import org.apache.commons.io.filefilter.IOFileFilter; import org.apache.commons.io.filefilter.WildcardFileFilter; +import org.hl7.fhir.utilities.json.model.JsonArray; +import org.hl7.fhir.utilities.json.model.JsonObject; import org.hl7.fhir.utilities.npm.NpmPackage; import org.hl7.fhir.utilities.npm.PackageGenerator; import org.slf4j.Logger; @@ -53,7 +53,6 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; @SuppressWarnings("UnstableApiUsage") public class CreatePackageCommand extends BaseCommand { - private static final Logger ourLog = LoggerFactory.getLogger(CreatePackageCommand.class); public static final String TARGET_DIRECTORY_OPT = "target-directory"; public static final String DEPENDENCY_OPT = "dependency"; public static final String INCLUDE_EXAMPLE_OPT = "include-example"; @@ -61,6 +60,7 @@ public class CreatePackageCommand extends BaseCommand { public static final String VERSION_OPT = "version"; public static final String NAME_OPT = "name"; public static final String DESCRIPTION_OPT = "description"; + private static final Logger ourLog = LoggerFactory.getLogger(CreatePackageCommand.class); private File myWorkDirectory; private String myPackageName; private String myPackageVersion; @@ -119,7 +119,7 @@ public class CreatePackageCommand extends BaseCommand { myPackageVersion = theCommandLine.getOptionValue(VERSION_OPT); if (isBlank(myPackageVersion)) { - throw new ParseException(Msg.code(1548) + "No package version supplied (--"+VERSION_OPT+")"); + throw new ParseException(Msg.code(1548) + "No package version supplied (--" + VERSION_OPT + ")"); } if (!NpmPackage.isValidVersion(myPackageVersion)) { throw new ParseException(Msg.code(1549) + "Invalid package version: " + myPackageVersion); diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/CreatePackageCommandTest.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/CreatePackageCommandTest.java index 78bfabac245..3f94fc96722 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/CreatePackageCommandTest.java +++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/CreatePackageCommandTest.java @@ -99,18 +99,19 @@ public class CreatePackageCommandTest extends BaseTest { String packageJsonContents = IOUtils.toString(new FileInputStream(new File(myExtractDirectory, "package/package.json")), Charsets.UTF_8); ourLog.info("Package.json:\n{}", packageJsonContents); - String expectedPackageJson = "{\n" + - " \"name\": \"com.example.ig\",\n" + - " \"version\": \"1.0.1\",\n" + - " \"fhirVersions\": [\n" + - " \"4.0.1\"\n" + - " ],\n" + - " \"dependencies\": {\n" + - " \"hl7.fhir.core\": \"4.0.1\",\n" + - " \"foo.bar\": \"1.2.3\"\n" + - " }\n" + - "}"; - assertEquals(expectedPackageJson, packageJsonContents); + String expectedPackageJson = """ + { + "name" : "com.example.ig", + "version" : "1.0.1", + "description" : "", + "fhirVersions" : ["4.0.1"], + "dependencies" : { + "hl7.fhir.core" : "4.0.1", + "foo.bar" : "1.2.3" + } + } + """; + assertEquals(expectedPackageJson.trim(), packageJsonContents.trim()); // Try parsing the module again to make sure we can NpmPackage loadedPackage = NpmPackage.fromPackage(new FileInputStream(igArchive)); @@ -153,14 +154,15 @@ public class CreatePackageCommandTest extends BaseTest { String packageJsonContents = IOUtils.toString(new FileInputStream(new File(myExtractDirectory, "package/package.json")), Charsets.UTF_8); ourLog.info("Package.json:\n{}", packageJsonContents); - String expectedPackageJson = "{\n" + - " \"name\": \"com.example.ig\",\n" + - " \"version\": \"1.0.1\",\n" + - " \"fhirVersions\": [\n" + - " \"4.0.1\"\n" + - " ]\n" + - "}"; - assertEquals(expectedPackageJson, packageJsonContents); + String expectedPackageJson = """ + { + "name" : "com.example.ig", + "version" : "1.0.1", + "description" : "", + "fhirVersions" : ["4.0.1"] + } + """; + assertEquals(expectedPackageJson.trim(), packageJsonContents.trim()); // Try parsing the module again to make sure we can NpmPackage loadedPackage = NpmPackage.fromPackage(new FileInputStream(igArchive)); diff --git a/hapi-fhir-converter/src/main/java/ca/uhn/hapi/converters/canonical/VersionCanonicalizer.java b/hapi-fhir-converter/src/main/java/ca/uhn/hapi/converters/canonical/VersionCanonicalizer.java index 640a29a1628..d1be72e29db 100644 --- a/hapi-fhir-converter/src/main/java/ca/uhn/hapi/converters/canonical/VersionCanonicalizer.java +++ b/hapi-fhir-converter/src/main/java/ca/uhn/hapi/converters/canonical/VersionCanonicalizer.java @@ -27,12 +27,16 @@ import ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt; import ca.uhn.fhir.model.dstu2.composite.CodingDt; import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_40; import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_50; +import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_14_40; +import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_14_50; import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_40; import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_50; import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_40_50; import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_43_50; import org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_40; import org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_50; +import org.hl7.fhir.convertors.factory.VersionConvertorFactory_14_40; +import org.hl7.fhir.convertors.factory.VersionConvertorFactory_14_50; import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_40; import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_50; import org.hl7.fhir.convertors.factory.VersionConvertorFactory_40_50; @@ -40,14 +44,17 @@ import org.hl7.fhir.convertors.factory.VersionConvertorFactory_43_50; import org.hl7.fhir.dstu2.model.Resource; import org.hl7.fhir.instance.model.api.IBaseCoding; import org.hl7.fhir.instance.model.api.IBaseDatatype; +import org.hl7.fhir.instance.model.api.IBaseParameters; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r4.model.CodeSystem; import org.hl7.fhir.r4.model.CodeableConcept; import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.r4.model.ConceptMap; +import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.ValueSet; import org.hl7.fhir.r5.model.CapabilityStatement; import org.hl7.fhir.r5.model.SearchParameter; +import org.hl7.fhir.r5.model.StructureDefinition; import java.util.List; @@ -71,13 +78,16 @@ public class VersionCanonicalizer { private static final BaseAdvisor_10_50 ADVISOR_10_50 = new BaseAdvisor_10_50(false); private static final BaseAdvisor_40_50 ADVISOR_40_50 = new BaseAdvisor_40_50(false); private static final BaseAdvisor_43_50 ADVISOR_43_50 = new BaseAdvisor_43_50(false); + private static final BaseAdvisor_14_40 ADVISOR_14_40 = new BaseAdvisor_14_40(false); + private static final BaseAdvisor_14_50 ADVISOR_14_50 = new BaseAdvisor_14_50(false); + private final IStrategy myStrategy; public VersionCanonicalizer(FhirContext theTargetContext) { this(theTargetContext.getVersion().getVersion()); } - @SuppressWarnings({"EnumSwitchStatementWhichMissesCases", "EnhancedSwitchMigration"}) + @SuppressWarnings({"EnhancedSwitchMigration"}) public VersionCanonicalizer(FhirVersionEnum theTargetVersion) { switch (theTargetVersion) { case DSTU2: @@ -86,6 +96,9 @@ public class VersionCanonicalizer { case DSTU2_HL7ORG: myStrategy = new Dstu2Strategy(true); break; + case DSTU2_1: + myStrategy = new Dstu21Strategy(); + break; case DSTU3: myStrategy = new Dstu3Strategy(); break; @@ -166,6 +179,39 @@ public class VersionCanonicalizer { return myStrategy.searchParameterToCanonical(theSearchParameter); } + public IBaseParameters parametersFromCanonical(Parameters theParameters) { + return myStrategy.parametersFromCanonical(theParameters); + } + + public StructureDefinition structureDefinitionToCanonical(IBaseResource theResource) { + StructureDefinition retVal = myStrategy.structureDefinitionToCanonical(theResource); + String packageUserData = (String) theResource.getUserData("package"); + if (packageUserData != null) { + retVal.setUserData("package", packageUserData); + } + return retVal; + } + + public IBaseResource structureDefinitionFromCanonical(StructureDefinition theResource) { + return myStrategy.structureDefinitionFromCanonical(theResource); + } + + public IBaseResource valueSetFromValidatorCanonical(org.hl7.fhir.r5.model.ValueSet theResource) { + return myStrategy.valueSetFromValidatorCanonical(theResource); + } + + public org.hl7.fhir.r5.model.Resource resourceToValidatorCanonical(IBaseResource theResource) { + return myStrategy.resourceToValidatorCanonical(theResource); + } + + public org.hl7.fhir.r5.model.ValueSet valueSetToValidatorCanonical(IBaseResource theResource) { + return myStrategy.valueSetToValidatorCanonical(theResource); + } + + public org.hl7.fhir.r5.model.CodeSystem codeSystemToValidatorCanonical(IBaseResource theResource) { + return myStrategy.codeSystemToValidatorCanonical(theResource); + } + private interface IStrategy { CapabilityStatement capabilityStatementToCanonical(IBaseResource theCapabilityStatement); @@ -183,6 +229,20 @@ public class VersionCanonicalizer { ConceptMap conceptMapToCanonical(IBaseResource theConceptMap); SearchParameter searchParameterToCanonical(IBaseResource theSearchParameter); + + IBaseParameters parametersFromCanonical(Parameters theParameters); + + StructureDefinition structureDefinitionToCanonical(IBaseResource theResource); + + IBaseResource structureDefinitionFromCanonical(StructureDefinition theResource); + + IBaseResource valueSetFromValidatorCanonical(org.hl7.fhir.r5.model.ValueSet theResource); + + org.hl7.fhir.r5.model.Resource resourceToValidatorCanonical(IBaseResource theResource); + + org.hl7.fhir.r5.model.ValueSet valueSetToValidatorCanonical(IBaseResource theResource); + + org.hl7.fhir.r5.model.CodeSystem codeSystemToValidatorCanonical(IBaseResource theResource); } private static class Dstu2Strategy implements IStrategy { @@ -292,6 +352,48 @@ public class VersionCanonicalizer { return retVal; } + @Override + public IBaseParameters parametersFromCanonical(Parameters theParameters) { + Resource converted = VersionConvertorFactory_10_40.convertResource(theParameters, ADVISOR_10_40); + return (IBaseParameters) reencodeToHl7Org(converted); + } + + @Override + public StructureDefinition structureDefinitionToCanonical(IBaseResource theResource) { + org.hl7.fhir.dstu2.model.Resource reencoded = reencodeToHl7Org(theResource); + return (StructureDefinition) VersionConvertorFactory_10_50.convertResource(reencoded, ADVISOR_10_50); + } + + @Override + public IBaseResource structureDefinitionFromCanonical(StructureDefinition theResource) { + Resource converted = VersionConvertorFactory_10_50.convertResource(theResource, ADVISOR_10_50); + return reencodeToHl7Org(converted); + } + + @Override + public IBaseResource valueSetFromValidatorCanonical(org.hl7.fhir.r5.model.ValueSet theResource) { + Resource converted = VersionConvertorFactory_10_50.convertResource(theResource, ADVISOR_10_50); + return reencodeToHl7Org(converted); + } + + @Override + public org.hl7.fhir.r5.model.Resource resourceToValidatorCanonical(IBaseResource theResource) { + org.hl7.fhir.dstu2.model.Resource reencoded = reencodeToHl7Org(theResource); + return VersionConvertorFactory_10_50.convertResource(reencoded, ADVISOR_10_50); + } + + @Override + public org.hl7.fhir.r5.model.ValueSet valueSetToValidatorCanonical(IBaseResource theResource) { + org.hl7.fhir.dstu2.model.Resource reencoded = reencodeToHl7Org(theResource); + return (org.hl7.fhir.r5.model.ValueSet) VersionConvertorFactory_10_50.convertResource(reencoded, ADVISOR_10_50); + } + + @Override + public org.hl7.fhir.r5.model.CodeSystem codeSystemToValidatorCanonical(IBaseResource theResource) { + org.hl7.fhir.dstu2.model.Resource reencoded = reencodeToHl7Org(theResource); + return (org.hl7.fhir.r5.model.CodeSystem) VersionConvertorFactory_10_50.convertResource(reencoded, ADVISOR_10_50); + } + private Resource reencodeToHl7Org(IBaseResource theInput) { if (myHl7OrgStructures) { return (Resource) theInput; @@ -308,6 +410,84 @@ public class VersionCanonicalizer { } + private static class Dstu21Strategy implements IStrategy { + + @Override + public CapabilityStatement capabilityStatementToCanonical(IBaseResource theCapabilityStatement) { + return (CapabilityStatement) VersionConvertorFactory_14_50.convertResource((org.hl7.fhir.dstu2016may.model.Resource) theCapabilityStatement, ADVISOR_14_50); + } + + @Override + public Coding codingToCanonical(IBaseCoding theCoding) { + return (org.hl7.fhir.r4.model.Coding) VersionConvertorFactory_14_40.convertType((org.hl7.fhir.dstu2016may.model.Coding) theCoding, ADVISOR_14_40); + } + + @Override + public CodeableConcept codeableConceptToCanonical(IBaseDatatype theCodeableConcept) { + return (org.hl7.fhir.r4.model.CodeableConcept) VersionConvertorFactory_14_40.convertType((org.hl7.fhir.dstu2016may.model.CodeableConcept) theCodeableConcept, ADVISOR_14_40); + } + + @Override + public ValueSet valueSetToCanonical(IBaseResource theValueSet) { + return (ValueSet) VersionConvertorFactory_14_40.convertResource((org.hl7.fhir.dstu2016may.model.Resource) theValueSet, ADVISOR_14_40); + } + + @Override + public CodeSystem codeSystemToCanonical(IBaseResource theCodeSystem) { + return (CodeSystem) VersionConvertorFactory_14_40.convertResource((org.hl7.fhir.dstu2016may.model.Resource) theCodeSystem, ADVISOR_14_40); + } + + @Override + public IBaseResource valueSetFromCanonical(ValueSet theValueSet) { + return VersionConvertorFactory_14_40.convertResource(theValueSet, ADVISOR_14_40); + } + + @Override + public ConceptMap conceptMapToCanonical(IBaseResource theConceptMap) { + return (ConceptMap) VersionConvertorFactory_14_40.convertResource((org.hl7.fhir.dstu2016may.model.Resource) theConceptMap, ADVISOR_14_40); + } + + @Override + public SearchParameter searchParameterToCanonical(IBaseResource theSearchParameter) { + return (SearchParameter) VersionConvertorFactory_14_50.convertResource((org.hl7.fhir.dstu2016may.model.Resource) theSearchParameter, ADVISOR_14_50); + } + + @Override + public IBaseParameters parametersFromCanonical(Parameters theParameters) { + return (IBaseParameters) VersionConvertorFactory_14_40.convertResource(theParameters, ADVISOR_14_40); + } + + @Override + public StructureDefinition structureDefinitionToCanonical(IBaseResource theResource) { + return (StructureDefinition) VersionConvertorFactory_14_50.convertResource((org.hl7.fhir.dstu2016may.model.Resource) theResource, ADVISOR_14_50); + } + + @Override + public IBaseResource structureDefinitionFromCanonical(StructureDefinition theResource) { + return VersionConvertorFactory_14_50.convertResource(theResource, ADVISOR_14_50); + } + + @Override + public IBaseResource valueSetFromValidatorCanonical(org.hl7.fhir.r5.model.ValueSet theResource) { + return VersionConvertorFactory_14_50.convertResource(theResource, ADVISOR_14_50); + } + + @Override + public org.hl7.fhir.r5.model.Resource resourceToValidatorCanonical(IBaseResource theResource) { + return VersionConvertorFactory_14_50.convertResource((org.hl7.fhir.dstu2016may.model.Resource) theResource, ADVISOR_14_50); + } + + @Override + public org.hl7.fhir.r5.model.ValueSet valueSetToValidatorCanonical(IBaseResource theResource) { + return (org.hl7.fhir.r5.model.ValueSet) VersionConvertorFactory_14_50.convertResource((org.hl7.fhir.dstu2016may.model.Resource) theResource, ADVISOR_14_50); + } + + @Override + public org.hl7.fhir.r5.model.CodeSystem codeSystemToValidatorCanonical(IBaseResource theResource) { + return (org.hl7.fhir.r5.model.CodeSystem) VersionConvertorFactory_14_50.convertResource((org.hl7.fhir.dstu2016may.model.Resource) theResource, ADVISOR_14_50); + } + } + private static class Dstu3Strategy implements IStrategy { @Override @@ -349,6 +529,41 @@ public class VersionCanonicalizer { public SearchParameter searchParameterToCanonical(IBaseResource theSearchParameter) { return (SearchParameter) VersionConvertorFactory_30_50.convertResource((org.hl7.fhir.dstu3.model.Resource) theSearchParameter, ADVISOR_30_50); } + + @Override + public IBaseParameters parametersFromCanonical(Parameters theParameters) { + return (IBaseParameters) VersionConvertorFactory_30_40.convertResource(theParameters, ADVISOR_30_40); + } + + @Override + public StructureDefinition structureDefinitionToCanonical(IBaseResource theResource) { + return (StructureDefinition) VersionConvertorFactory_30_50.convertResource((org.hl7.fhir.dstu3.model.Resource) theResource, ADVISOR_30_50); + } + + @Override + public IBaseResource structureDefinitionFromCanonical(StructureDefinition theResource) { + return VersionConvertorFactory_30_50.convertResource(theResource, ADVISOR_30_50); + } + + @Override + public IBaseResource valueSetFromValidatorCanonical(org.hl7.fhir.r5.model.ValueSet theResource) { + return VersionConvertorFactory_30_50.convertResource(theResource, ADVISOR_30_50); + } + + @Override + public org.hl7.fhir.r5.model.Resource resourceToValidatorCanonical(IBaseResource theResource) { + return VersionConvertorFactory_30_50.convertResource((org.hl7.fhir.dstu3.model.Resource) theResource, ADVISOR_30_50); + } + + @Override + public org.hl7.fhir.r5.model.ValueSet valueSetToValidatorCanonical(IBaseResource theResource) { + return (org.hl7.fhir.r5.model.ValueSet) VersionConvertorFactory_30_50.convertResource((org.hl7.fhir.dstu3.model.Resource) theResource, ADVISOR_30_50); + } + + @Override + public org.hl7.fhir.r5.model.CodeSystem codeSystemToValidatorCanonical(IBaseResource theResource) { + return (org.hl7.fhir.r5.model.CodeSystem) VersionConvertorFactory_30_50.convertResource((org.hl7.fhir.dstu3.model.Resource) theResource, ADVISOR_30_50); + } } private static class R4Strategy implements IStrategy { @@ -392,6 +607,41 @@ public class VersionCanonicalizer { return (SearchParameter) VersionConvertorFactory_40_50.convertResource((org.hl7.fhir.r4.model.Resource) theSearchParameter, ADVISOR_40_50); } + @Override + public IBaseParameters parametersFromCanonical(Parameters theParameters) { + return theParameters; + } + + @Override + public StructureDefinition structureDefinitionToCanonical(IBaseResource theResource) { + return (StructureDefinition) VersionConvertorFactory_40_50.convertResource((org.hl7.fhir.r4.model.Resource) theResource, ADVISOR_40_50); + } + + @Override + public IBaseResource structureDefinitionFromCanonical(StructureDefinition theResource) { + return VersionConvertorFactory_40_50.convertResource(theResource, ADVISOR_40_50); + } + + @Override + public IBaseResource valueSetFromValidatorCanonical(org.hl7.fhir.r5.model.ValueSet theResource) { + return VersionConvertorFactory_40_50.convertResource(theResource, ADVISOR_40_50); + } + + @Override + public org.hl7.fhir.r5.model.Resource resourceToValidatorCanonical(IBaseResource theResource) { + return VersionConvertorFactory_40_50.convertResource((org.hl7.fhir.r4.model.Resource) theResource, ADVISOR_40_50); + } + + @Override + public org.hl7.fhir.r5.model.ValueSet valueSetToValidatorCanonical(IBaseResource theResource) { + return (org.hl7.fhir.r5.model.ValueSet) VersionConvertorFactory_40_50.convertResource((org.hl7.fhir.r4.model.Resource) theResource, ADVISOR_40_50); + } + + @Override + public org.hl7.fhir.r5.model.CodeSystem codeSystemToValidatorCanonical(IBaseResource theResource) { + return (org.hl7.fhir.r5.model.CodeSystem) VersionConvertorFactory_40_50.convertResource((org.hl7.fhir.r4.model.Resource) theResource, ADVISOR_40_50); + } + } private static class R4BStrategy implements IStrategy { @@ -442,6 +692,42 @@ public class VersionCanonicalizer { return (SearchParameter) VersionConvertorFactory_43_50.convertResource((org.hl7.fhir.r4b.model.Resource) theSearchParameter, ADVISOR_43_50); } + @Override + public IBaseParameters parametersFromCanonical(Parameters theParameters) { + org.hl7.fhir.r5.model.Parameters parametersR5 = (org.hl7.fhir.r5.model.Parameters) VersionConvertorFactory_40_50.convertResource(theParameters, ADVISOR_40_50); + return (IBaseParameters) VersionConvertorFactory_43_50.convertResource(parametersR5, ADVISOR_43_50); + } + + @Override + public StructureDefinition structureDefinitionToCanonical(IBaseResource theResource) { + return (StructureDefinition) VersionConvertorFactory_43_50.convertResource((org.hl7.fhir.r4b.model.Resource) theResource, ADVISOR_43_50); + } + + @Override + public IBaseResource structureDefinitionFromCanonical(StructureDefinition theResource) { + return VersionConvertorFactory_43_50.convertResource(theResource, ADVISOR_43_50); + } + + @Override + public IBaseResource valueSetFromValidatorCanonical(org.hl7.fhir.r5.model.ValueSet theResource) { + return VersionConvertorFactory_43_50.convertResource(theResource, ADVISOR_43_50); + } + + @Override + public org.hl7.fhir.r5.model.Resource resourceToValidatorCanonical(IBaseResource theResource) { + return VersionConvertorFactory_43_50.convertResource((org.hl7.fhir.r4b.model.Resource) theResource, ADVISOR_43_50); + } + + @Override + public org.hl7.fhir.r5.model.ValueSet valueSetToValidatorCanonical(IBaseResource theResource) { + return (org.hl7.fhir.r5.model.ValueSet) VersionConvertorFactory_43_50.convertResource((org.hl7.fhir.r4b.model.Resource) theResource, ADVISOR_43_50); + } + + @Override + public org.hl7.fhir.r5.model.CodeSystem codeSystemToValidatorCanonical(IBaseResource theResource) { + return (org.hl7.fhir.r5.model.CodeSystem) VersionConvertorFactory_43_50.convertResource((org.hl7.fhir.r4b.model.Resource) theResource, ADVISOR_43_50); + } + } @@ -487,6 +773,41 @@ public class VersionCanonicalizer { return (SearchParameter) theSearchParameter; } + @Override + public IBaseParameters parametersFromCanonical(Parameters theParameters) { + return (IBaseParameters) VersionConvertorFactory_40_50.convertResource(theParameters, ADVISOR_40_50); + } + + @Override + public StructureDefinition structureDefinitionToCanonical(IBaseResource theResource) { + return (StructureDefinition) theResource; + } + + @Override + public IBaseResource structureDefinitionFromCanonical(StructureDefinition theResource) { + return theResource; + } + + @Override + public IBaseResource valueSetFromValidatorCanonical(org.hl7.fhir.r5.model.ValueSet theResource) { + return theResource; + } + + @Override + public org.hl7.fhir.r5.model.Resource resourceToValidatorCanonical(IBaseResource theResource) { + return (org.hl7.fhir.r5.model.Resource) theResource; + } + + @Override + public org.hl7.fhir.r5.model.ValueSet valueSetToValidatorCanonical(IBaseResource theResource) { + return (org.hl7.fhir.r5.model.ValueSet) theResource; + } + + @Override + public org.hl7.fhir.r5.model.CodeSystem codeSystemToValidatorCanonical(IBaseResource theResource) { + return (org.hl7.fhir.r5.model.CodeSystem) theResource; + } + } diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_3_0/4289-allow-conceptmap-translation-with-forcedid.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_3_0/4289-allow-conceptmap-translation-with-forcedid.yaml new file mode 100644 index 00000000000..5066784797f --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_3_0/4289-allow-conceptmap-translation-with-forcedid.yaml @@ -0,0 +1,6 @@ +--- +type: fix +issue: 4289 +title: "The ConceptMap/$translate operation did not work for transation against + a ConceptMap resource ID if the ID was non-numeric. This has been fixed. Thanks to + Panayiotis Savva for the report!" diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_3_0/changes.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_3_0/changes.yaml index 2014d019005..292032121b1 100644 --- a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_3_0/changes.yaml +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_3_0/changes.yaml @@ -10,6 +10,7 @@
  • log4j-to-slf4j (JPA): 2.17.1 -> 2.19.0
  • Jetty (CLI): 9.4.48.v20220622 -> 10.0.12
  • Spring Boot: 2.7.4 -> 2.7.5
  • +
  • Graphql-Java (OpenAPI): 17.4 -> 19.2
  • In addition the following dependencies have been replaced with newer equivalents:
      diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoStructureDefinitionDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoStructureDefinitionDstu2.java deleted file mode 100644 index e1165d2c10c..00000000000 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoStructureDefinitionDstu2.java +++ /dev/null @@ -1,34 +0,0 @@ -package ca.uhn.fhir.jpa.dao; - -/* - * #%L - * HAPI FHIR JPA Server - * %% - * Copyright (C) 2014 - 2022 Smile CDR, Inc. - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import ca.uhn.fhir.i18n.Msg; -import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoStructureDefinition; -import ca.uhn.fhir.model.dstu2.resource.StructureDefinition; -import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; - -public class FhirResourceDaoStructureDefinitionDstu2 extends BaseHapiFhirResourceDao implements IFhirResourceDaoStructureDefinition { - @Override - public StructureDefinition generateSnapshot(StructureDefinition theInput, String theUrl, String theWebUrl, String theName) { - throw new InvalidRequestException(Msg.code(943) + "Snapshot generation not supported for DSTU2"); - } - -} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoStructureDefinitionR5.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaResourceDaoStructureDefinition.java similarity index 63% rename from hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoStructureDefinitionR5.java rename to hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaResourceDaoStructureDefinition.java index 6d40674407b..e54b749253f 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoStructureDefinitionR5.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaResourceDaoStructureDefinition.java @@ -1,11 +1,10 @@ -package ca.uhn.fhir.jpa.dao.r5; +package ca.uhn.fhir.jpa.dao; import ca.uhn.fhir.context.support.IValidationSupport; import ca.uhn.fhir.context.support.ValidationSupportContext; import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoStructureDefinition; -import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao; import org.apache.commons.lang3.Validate; -import org.hl7.fhir.r5.model.StructureDefinition; +import org.hl7.fhir.instance.model.api.IBaseResource; import org.springframework.beans.factory.annotation.Autowired; /* @@ -28,14 +27,14 @@ import org.springframework.beans.factory.annotation.Autowired; * #L% */ -public class FhirResourceDaoStructureDefinitionR5 extends BaseHapiFhirResourceDao implements IFhirResourceDaoStructureDefinition { +public class JpaResourceDaoStructureDefinition extends BaseHapiFhirResourceDao implements IFhirResourceDaoStructureDefinition { @Autowired private IValidationSupport myValidationSupport; @Override - public StructureDefinition generateSnapshot(StructureDefinition theInput, String theUrl, String theWebUrl, String theName) { - StructureDefinition output = (StructureDefinition) myValidationSupport.generateSnapshot(new ValidationSupportContext(myValidationSupport), theInput, theUrl, theWebUrl, theName); + public T generateSnapshot(T theInput, String theUrl, String theWebUrl, String theName) { + T output = (T) myValidationSupport.generateSnapshot(new ValidationSupportContext(myValidationSupport), theInput, theUrl, theWebUrl, theName); Validate.notNull(output); return output; } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoConceptMapDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoConceptMapDstu3.java deleted file mode 100644 index a3a4a6350bb..00000000000 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoConceptMapDstu3.java +++ /dev/null @@ -1,79 +0,0 @@ -package ca.uhn.fhir.jpa.dao.dstu3; - -/* - * #%L - * HAPI FHIR JPA Server - * %% - * Copyright (C) 2014 - 2022 Smile CDR, Inc. - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import ca.uhn.fhir.context.support.IValidationSupport; -import ca.uhn.fhir.i18n.Msg; -import ca.uhn.fhir.context.support.TranslateConceptResults; -import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoConceptMap; -import ca.uhn.fhir.jpa.api.model.TranslationRequest; -import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao; -import ca.uhn.fhir.jpa.model.cross.IBasePersistedResource; -import ca.uhn.fhir.jpa.model.entity.ResourceTable; -import ca.uhn.fhir.jpa.term.api.ITermConceptMappingSvc; -import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.api.server.storage.TransactionDetails; -import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; -import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_40; -import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_40; -import org.hl7.fhir.dstu3.model.ConceptMap; -import org.hl7.fhir.exceptions.FHIRException; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.springframework.beans.factory.annotation.Autowired; - -import java.util.Collections; -import java.util.Date; - -public class FhirResourceDaoConceptMapDstu3 extends BaseHapiFhirResourceDao implements IFhirResourceDaoConceptMap { - @Autowired - private ITermConceptMappingSvc myTermConceptMappingSvc; - @Autowired - private IValidationSupport myValidationSupport; - - @Override - public TranslateConceptResults translate(TranslationRequest theTranslationRequest, RequestDetails theRequestDetails) { - IValidationSupport.TranslateCodeRequest translateCodeRequest = theTranslationRequest.asTranslateCodeRequest(); - return myValidationSupport.translateConcept(translateCodeRequest); - } - - - @Override - public ResourceTable updateEntity(RequestDetails theRequestDetails, IBaseResource theResource, IBasePersistedResource theEntity, Date theDeletedTimestampOrNull, boolean thePerformIndexing, - boolean theUpdateVersion, TransactionDetails theTransactionDetails, boolean theForceUpdate, boolean theCreateNewHistoryEntry) { - ResourceTable retVal = super.updateEntity(theRequestDetails, theResource, theEntity, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theTransactionDetails, theForceUpdate, theCreateNewHistoryEntry); - - if (!retVal.isUnchangedInCurrentOperation()) { - if (retVal.getDeleted() == null) { - try { - ConceptMap conceptMap = (ConceptMap) theResource; - org.hl7.fhir.r4.model.ConceptMap converted = (org.hl7.fhir.r4.model.ConceptMap) VersionConvertorFactory_30_40.convertResource(conceptMap, new BaseAdvisor_30_40(false)); - myTermConceptMappingSvc.storeTermConceptMapAndChildren(retVal, converted); - } catch (FHIRException fe) { - throw new InternalErrorException(Msg.code(1083) + fe); - } - } else { - myTermConceptMappingSvc.deleteConceptMapAndChildren(retVal); - } - } - - return retVal; - } -} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoStructureDefinitionDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoStructureDefinitionDstu3.java deleted file mode 100644 index 24ffe7126f6..00000000000 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoStructureDefinitionDstu3.java +++ /dev/null @@ -1,43 +0,0 @@ -package ca.uhn.fhir.jpa.dao.dstu3; - -import ca.uhn.fhir.context.support.IValidationSupport; -import ca.uhn.fhir.context.support.ValidationSupportContext; -import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoStructureDefinition; -import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao; -import org.apache.commons.lang3.Validate; -import org.hl7.fhir.dstu3.model.StructureDefinition; -import org.springframework.beans.factory.annotation.Autowired; - -/* - * #%L - * HAPI FHIR JPA Server - * %% - * Copyright (C) 2014 - 2022 Smile CDR, Inc. - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -public class FhirResourceDaoStructureDefinitionDstu3 extends BaseHapiFhirResourceDao implements IFhirResourceDaoStructureDefinition { - - @Autowired - private IValidationSupport myValidationSupport; - - @Override - public StructureDefinition generateSnapshot(StructureDefinition theInput, String theUrl, String theWebUrl, String theName) { - StructureDefinition output = (StructureDefinition) myValidationSupport.generateSnapshot(new ValidationSupportContext(myValidationSupport), theInput, theUrl, theName, null); - Validate.notNull(output); - return output; - } - -} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoStructureDefinitionR4.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoStructureDefinitionR4.java deleted file mode 100644 index af7fd8a9d7d..00000000000 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoStructureDefinitionR4.java +++ /dev/null @@ -1,43 +0,0 @@ -package ca.uhn.fhir.jpa.dao.r4; - -import ca.uhn.fhir.context.support.IValidationSupport; -import ca.uhn.fhir.context.support.ValidationSupportContext; -import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoStructureDefinition; -import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao; -import org.apache.commons.lang3.Validate; -import org.hl7.fhir.r4.model.StructureDefinition; -import org.springframework.beans.factory.annotation.Autowired; - -/* - * #%L - * HAPI FHIR JPA Server - * %% - * Copyright (C) 2014 - 2022 Smile CDR, Inc. - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -public class FhirResourceDaoStructureDefinitionR4 extends BaseHapiFhirResourceDao implements IFhirResourceDaoStructureDefinition { - - @Autowired - private IValidationSupport myValidationSupport; - - @Override - public StructureDefinition generateSnapshot(StructureDefinition theInput, String theUrl, String theWebUrl, String theName) { - StructureDefinition output = (StructureDefinition) myValidationSupport.generateSnapshot(new ValidationSupportContext(myValidationSupport), theInput, theUrl, theWebUrl, theName); - Validate.notNull(output); - return output; - } - -} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4b/FhirResourceDaoConceptMapR4B.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4b/FhirResourceDaoConceptMapR4B.java deleted file mode 100644 index a026298677c..00000000000 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4b/FhirResourceDaoConceptMapR4B.java +++ /dev/null @@ -1,45 +0,0 @@ -package ca.uhn.fhir.jpa.dao.r4b; - -/*- - * #%L - * HAPI FHIR JPA Server - * %% - * Copyright (C) 2014 - 2022 Smile CDR, Inc. - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import ca.uhn.fhir.context.support.IValidationSupport; -import ca.uhn.fhir.context.support.TranslateConceptResults; -import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoConceptMap; -import ca.uhn.fhir.jpa.api.model.TranslationRequest; -import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao; -import ca.uhn.fhir.jpa.term.api.ITermConceptMappingSvc; -import ca.uhn.fhir.rest.api.server.RequestDetails; -import org.hl7.fhir.r4b.model.ConceptMap; -import org.springframework.beans.factory.annotation.Autowired; - -public class FhirResourceDaoConceptMapR4B extends BaseHapiFhirResourceDao implements IFhirResourceDaoConceptMap { - @Autowired - private ITermConceptMappingSvc myTermConceptMappingSvc; - @Autowired - private IValidationSupport myValidationSupport; - - @Override - public TranslateConceptResults translate(TranslationRequest theTranslationRequest, RequestDetails theRequestDetails) { - IValidationSupport.TranslateCodeRequest translateCodeRequest = theTranslationRequest.asTranslateCodeRequest(); - return myValidationSupport.translateConcept(translateCodeRequest); - } - -} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4b/FhirResourceDaoStructureDefinitionR4B.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4b/FhirResourceDaoStructureDefinitionR4B.java deleted file mode 100644 index dc9e7e13e9b..00000000000 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4b/FhirResourceDaoStructureDefinitionR4B.java +++ /dev/null @@ -1,43 +0,0 @@ -package ca.uhn.fhir.jpa.dao.r4b; - -import ca.uhn.fhir.context.support.IValidationSupport; -import ca.uhn.fhir.context.support.ValidationSupportContext; -import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoStructureDefinition; -import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao; -import org.apache.commons.lang3.Validate; -import org.hl7.fhir.r4b.model.StructureDefinition; -import org.springframework.beans.factory.annotation.Autowired; - -/* - * #%L - * HAPI FHIR JPA Server - * %% - * Copyright (C) 2014 - 2022 Smile CDR, Inc. - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -public class FhirResourceDaoStructureDefinitionR4B extends BaseHapiFhirResourceDao implements IFhirResourceDaoStructureDefinition { - - @Autowired - private IValidationSupport myValidationSupport; - - @Override - public StructureDefinition generateSnapshot(StructureDefinition theInput, String theUrl, String theWebUrl, String theName) { - StructureDefinition output = (StructureDefinition) myValidationSupport.generateSnapshot(new ValidationSupportContext(myValidationSupport), theInput, theUrl, theWebUrl, theName); - Validate.notNull(output); - return output; - } - -} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoConceptMapR5.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoConceptMapR5.java deleted file mode 100644 index e96528ff8a5..00000000000 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoConceptMapR5.java +++ /dev/null @@ -1,71 +0,0 @@ -package ca.uhn.fhir.jpa.dao.r5; - -/*- - * #%L - * HAPI FHIR JPA Server - * %% - * Copyright (C) 2014 - 2022 Smile CDR, Inc. - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import ca.uhn.fhir.context.support.IValidationSupport; -import ca.uhn.fhir.context.support.TranslateConceptResults; -import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoConceptMap; -import ca.uhn.fhir.jpa.api.model.TranslationRequest; -import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao; -import ca.uhn.fhir.jpa.model.cross.IBasePersistedResource; -import ca.uhn.fhir.jpa.model.entity.ResourceTable; -import ca.uhn.fhir.jpa.term.api.ITermConceptMappingSvc; -import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.api.server.storage.TransactionDetails; -import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_40_50; -import org.hl7.fhir.convertors.factory.VersionConvertorFactory_40_50; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.r5.model.ConceptMap; -import org.springframework.beans.factory.annotation.Autowired; - -import java.util.Collections; -import java.util.Date; - -public class FhirResourceDaoConceptMapR5 extends BaseHapiFhirResourceDao implements IFhirResourceDaoConceptMap { - @Autowired - private ITermConceptMappingSvc myTermConceptMappingSvc; - @Autowired - private IValidationSupport myValidationSupport; - - @Override - public TranslateConceptResults translate(TranslationRequest theTranslationRequest, RequestDetails theRequestDetails) { - IValidationSupport.TranslateCodeRequest translateCodeRequest = theTranslationRequest.asTranslateCodeRequest(); - return myValidationSupport.translateConcept(translateCodeRequest); - } - - @Override - public ResourceTable updateEntity(RequestDetails theRequestDetails, IBaseResource theResource, IBasePersistedResource theEntity, Date theDeletedTimestampOrNull, boolean thePerformIndexing, - boolean theUpdateVersion, TransactionDetails theTransactionDetails, boolean theForceUpdate, boolean theCreateNewHistoryEntry) { - ResourceTable retVal = super.updateEntity(theRequestDetails, theResource, theEntity, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theTransactionDetails, theForceUpdate, theCreateNewHistoryEntry); - if (!retVal.isUnchangedInCurrentOperation()) { - - if (retVal.getDeleted() == null) { - ConceptMap conceptMap = (ConceptMap) theResource; - myTermConceptMappingSvc.storeTermConceptMapAndChildren(retVal, - (org.hl7.fhir.r4.model.ConceptMap) VersionConvertorFactory_40_50.convertResource(conceptMap, new BaseAdvisor_40_50(false))); - } else { - myTermConceptMappingSvc.deleteConceptMapAndChildren(retVal); - } - } - - return retVal; - } -} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/graphql/GraphQLProviderWithIntrospection.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/graphql/GraphQLProviderWithIntrospection.java index b76da578eba..86f742671d8 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/graphql/GraphQLProviderWithIntrospection.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/graphql/GraphQLProviderWithIntrospection.java @@ -36,13 +36,17 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import graphql.ExecutionResult; import graphql.GraphQL; +import graphql.language.InterfaceTypeDefinition; import graphql.scalar.GraphqlStringCoercing; import graphql.schema.GraphQLScalarType; import graphql.schema.GraphQLSchema; +import graphql.schema.TypeResolver; +import graphql.schema.TypeResolverProxy; import graphql.schema.idl.RuntimeWiring; import graphql.schema.idl.SchemaGenerator; import graphql.schema.idl.SchemaParser; import graphql.schema.idl.TypeDefinitionRegistry; +import graphql.schema.idl.TypeRuntimeWiring; import org.apache.commons.io.output.StringBuilderWriter; import org.apache.commons.lang3.Validate; import org.hl7.fhir.common.hapi.validation.validator.VersionSpecificWorkerContextWrapper; @@ -132,18 +136,36 @@ public class GraphQLProviderWithIntrospection extends GraphQLProvider { final StringBuilder schemaBuilder = new StringBuilder(); try (Writer writer = new StringBuilderWriter(schemaBuilder)) { + // Generate FHIR base types schemas myGenerator.generateTypes(writer, theOperations); // Fix up a few things that are missing from the generated schema writer - .append("\ntype Resource {") - .append("\n id: [token]" + "\n}") - .append("\n"); - writer - .append("\ninput ResourceInput {") - .append("\n id: [token]" + "\n}") + .append("\ninterface Element {") + .append("\n id: ID") + .append("\n}") .append("\n"); +// writer +// .append("\ninterface Quantity {\n") +// .append("id: String\n") +// .append("extension: [Extension]\n") +// .append("value: decimal _value: ElementBase\n") +// .append("comparator: code _comparator: ElementBase\n") +// .append("unit: String _unit: ElementBase\n") +// .append("system: uri _system: ElementBase\n") +// .append("code: code _code: ElementBase\n") +// .append("\n}") +// .append("\n"); + +// writer +// .append("\ntype Resource {") +// .append("\n id: [token]" + "\n}") +// .append("\n"); +// writer +// .append("\ninput ResourceInput {") +// .append("\n id: [token]" + "\n}") +// .append("\n"); // Generate schemas for the resource types for (String nextResourceType : theResourceTypes) { @@ -195,6 +217,15 @@ public class GraphQLProviderWithIntrospection extends GraphQLProvider { runtimeWiringBuilder.scalar(new GraphQLScalarType.Builder().name(next).coercing(new GraphqlStringCoercing()).build()); } + for (InterfaceTypeDefinition next : typeDefinitionRegistry.getTypes(InterfaceTypeDefinition.class)) { + TypeResolver resolver = new TypeResolverProxy(); + TypeRuntimeWiring wiring = TypeRuntimeWiring + .newTypeWiring(next.getName()) + .typeResolver(resolver) + .build(); + runtimeWiringBuilder.type(wiring); + } + RuntimeWiring runtimeWiring = runtimeWiringBuilder.build(); GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/packages/PackageInstallerSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/packages/PackageInstallerSvcImpl.java index d4343d1a9a6..40f50ecd69f 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/packages/PackageInstallerSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/packages/PackageInstallerSvcImpl.java @@ -50,13 +50,14 @@ import ca.uhn.fhir.util.SearchParameterUtil; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Lists; import com.google.gson.Gson; -import com.google.gson.JsonElement; import org.apache.commons.lang3.Validate; import org.hl7.fhir.instance.model.api.IBase; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.hl7.fhir.r4.model.Identifier; +import org.hl7.fhir.utilities.json.model.JsonElement; +import org.hl7.fhir.utilities.json.model.JsonObject; import org.hl7.fhir.utilities.npm.IPackageCacheManager; import org.hl7.fhir.utilities.npm.NpmPackage; import org.slf4j.Logger; @@ -205,8 +206,8 @@ public class PackageInstallerSvcImpl implements IPackageInstallerSvc { * @throws ImplementationGuideInstallationException if installation fails */ private void install(NpmPackage npmPackage, PackageInstallationSpec theInstallationSpec, PackageInstallOutcomeJson theOutcome) throws ImplementationGuideInstallationException { - String name = npmPackage.getNpm().get("name").getAsString(); - String version = npmPackage.getNpm().get("version").getAsString(); + String name = npmPackage.getNpm().get("name").asJsonString().getValue(); + String version = npmPackage.getNpm().get("version").asJsonString().getValue(); String fhirVersion = npmPackage.fhirVersion(); String currentFhirVersion = myFhirContext.getVersion().getVersion().getFhirVersionString(); @@ -248,11 +249,9 @@ public class PackageInstallerSvcImpl implements IPackageInstallerSvc { private void fetchAndInstallDependencies(NpmPackage npmPackage, PackageInstallationSpec theInstallationSpec, PackageInstallOutcomeJson theOutcome) throws ImplementationGuideInstallationException { if (npmPackage.getNpm().has("dependencies")) { - JsonElement dependenciesElement = npmPackage.getNpm().get("dependencies"); - Map dependencies = new Gson().fromJson(dependenciesElement, HashMap.class); - for (Map.Entry d : dependencies.entrySet()) { - String id = d.getKey(); - String ver = d.getValue(); + JsonObject dependenciesElement = npmPackage.getNpm().get("dependencies").asJsonObject(); + for (String id : dependenciesElement.getNames()) { + String ver = dependenciesElement.getJsonString(id).asString(); try { theOutcome.getMessage().add("Package " + npmPackage.id() + "#" + npmPackage.version() + " depends on package " + id + "#" + ver); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderConceptMap.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderConceptMap.java new file mode 100644 index 00000000000..b8d640bab33 --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderConceptMap.java @@ -0,0 +1,158 @@ +package ca.uhn.fhir.jpa.provider; + +/* + * #%L + * HAPI FHIR JPA Server + * %% + * Copyright (C) 2014 - 2022 Smile CDR, Inc. + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import ca.uhn.fhir.context.support.TranslateConceptResults; +import ca.uhn.fhir.i18n.Msg; +import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoConceptMap; +import ca.uhn.fhir.jpa.api.model.TranslationRequest; +import ca.uhn.fhir.jpa.model.util.JpaConstants; +import ca.uhn.fhir.jpa.term.TermConceptMappingSvcImpl; +import ca.uhn.fhir.rest.annotation.IdParam; +import ca.uhn.fhir.rest.annotation.Operation; +import ca.uhn.fhir.rest.annotation.OperationParam; +import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; +import ca.uhn.hapi.converters.canonical.VersionCanonicalizer; +import org.hl7.fhir.instance.model.api.IBaseCoding; +import org.hl7.fhir.instance.model.api.IBaseDatatype; +import org.hl7.fhir.instance.model.api.IBaseParameters; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.instance.model.api.IIdType; +import org.hl7.fhir.instance.model.api.IPrimitiveType; +import org.hl7.fhir.r4.model.CodeableConcept; +import org.hl7.fhir.r4.model.Coding; +import org.hl7.fhir.r4.model.ConceptMap; +import org.hl7.fhir.r4.model.Parameters; +import org.hl7.fhir.r4.model.StringType; +import org.springframework.beans.factory.annotation.Autowired; + +import javax.servlet.http.HttpServletRequest; + +import static ca.uhn.fhir.util.DatatypeUtil.toBooleanValue; +import static ca.uhn.fhir.util.DatatypeUtil.toStringValue; +import static org.apache.commons.lang3.StringUtils.isNotBlank; + +public abstract class BaseJpaResourceProviderConceptMap extends BaseJpaResourceProvider { + + @Autowired + private VersionCanonicalizer myVersionCanonicalizer; + + @Operation(name = JpaConstants.OPERATION_TRANSLATE, idempotent = true, returnParameters = { + @OperationParam(name = "result", typeName = "boolean", min = 1, max = 1), + @OperationParam(name = "message", typeName = "string", min = 0, max = 1), + }) + public IBaseParameters translate( + HttpServletRequest theServletRequest, + @IdParam(optional = true) IIdType theId, + @OperationParam(name = "url", min = 0, max = 1, typeName = "uri") IPrimitiveType theUrl, + @OperationParam(name = "conceptMapVersion", min = 0, max = 1, typeName = "string") IPrimitiveType theConceptMapVersion, + @OperationParam(name = "code", min = 0, max = 1, typeName = "code") IPrimitiveType theSourceCode, + @OperationParam(name = "system", min = 0, max = 1, typeName = "uri") IPrimitiveType theSourceCodeSystem, + @OperationParam(name = "version", min = 0, max = 1, typeName = "string") IPrimitiveType theSourceCodeSystemVersion, + @OperationParam(name = "source", min = 0, max = 1, typeName = "uri") IPrimitiveType theSourceValueSet, + @OperationParam(name = "coding", min = 0, max = 1, typeName = "Coding") IBaseCoding theSourceCoding, + @OperationParam(name = "codeableConcept", min = 0, max = 1, typeName = "CodeableConcept") IBaseDatatype theSourceCodeableConcept, + @OperationParam(name = "target", min = 0, max = 1, typeName = "uri") IPrimitiveType theTargetValueSet, + @OperationParam(name = "targetsystem", min = 0, max = 1, typeName = "uri") IPrimitiveType theTargetCodeSystem, + @OperationParam(name = "reverse", min = 0, max = 1, typeName = "boolean") IPrimitiveType theReverse, + RequestDetails theRequestDetails + ) { + Coding sourceCoding = myVersionCanonicalizer.codingToCanonical(theSourceCoding); + CodeableConcept sourceCodeableConcept = myVersionCanonicalizer.codeableConceptToCanonical(theSourceCodeableConcept); + + boolean haveSourceCode = theSourceCode != null + && isNotBlank(theSourceCode.getValue()); + boolean haveSourceCodeSystem = theSourceCodeSystem != null + && theSourceCodeSystem.hasValue(); + boolean haveSourceCodeSystemVersion = theSourceCodeSystemVersion != null + && theSourceCodeSystemVersion.hasValue(); + boolean haveSourceCoding = sourceCoding != null + && sourceCoding.hasCode(); + boolean haveSourceCodeableConcept = sourceCodeableConcept != null + && sourceCodeableConcept.hasCoding() + && sourceCodeableConcept.getCodingFirstRep().hasCode(); + boolean haveReverse = theReverse != null; + boolean haveId = theId != null && theId.hasIdPart(); + + // + if ((!haveSourceCode && !haveSourceCoding && !haveSourceCodeableConcept) + || moreThanOneTrue(haveSourceCode, haveSourceCoding, haveSourceCodeableConcept)) { + throw new InvalidRequestException(Msg.code(1154) + "One (and only one) of the in parameters (code, coding, codeableConcept) must be provided, to identify the code that is to be translated."); + } + + TranslationRequest translationRequest = new TranslationRequest(); + translationRequest.setUrl(toStringValue(theUrl)); + translationRequest.setConceptMapVersion(toStringValue(theConceptMapVersion)); + + if (haveSourceCode) { + translationRequest.getCodeableConcept().addCoding().setCode(toStringValue(theSourceCode)); + + if (haveSourceCodeSystem) { + translationRequest.getCodeableConcept().getCodingFirstRep().setSystem(toStringValue(theSourceCodeSystem)); + } + + if (haveSourceCodeSystemVersion) { + translationRequest.getCodeableConcept().getCodingFirstRep().setVersion(toStringValue(theSourceCodeSystemVersion)); + } + } else if (haveSourceCoding) { + translationRequest.getCodeableConcept().addCoding(sourceCoding); + } else { + translationRequest.setCodeableConcept(sourceCodeableConcept); + } + + translationRequest.setSource(toStringValue(theSourceValueSet)); + translationRequest.setTarget(toStringValue(theTargetValueSet)); + translationRequest.setTargetSystem(toStringValue(theTargetCodeSystem)); + + if (haveReverse) { + translationRequest.setReverse(toBooleanValue(theReverse)); + } + + if (haveId) { + translationRequest.setResourceId(theId); + } + + startRequest(theServletRequest); + try { + IFhirResourceDaoConceptMap dao = (IFhirResourceDaoConceptMap) getDao(); + TranslateConceptResults result = dao.translate(translationRequest, theRequestDetails); + Parameters parameters = TermConceptMappingSvcImpl.toParameters(result); + return myVersionCanonicalizer.parametersFromCanonical(parameters); + } finally { + endRequest(theServletRequest); + } + } + + private static boolean moreThanOneTrue(boolean... theBooleans) { + boolean haveOne = false; + for (boolean next : theBooleans) { + if (next) { + if (haveOne) { + return true; + } else { + haveOne = true; + } + } + } + return false; + } +} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderConceptMapDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderConceptMapDstu3.java deleted file mode 100644 index 1421e95203d..00000000000 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderConceptMapDstu3.java +++ /dev/null @@ -1,180 +0,0 @@ -package ca.uhn.fhir.jpa.provider.dstu3; - -/* - * #%L - * HAPI FHIR JPA Server - * %% - * Copyright (C) 2014 - 2022 Smile CDR, Inc. - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import ca.uhn.fhir.context.support.TranslateConceptResults; -import ca.uhn.fhir.i18n.Msg; -import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoConceptMap; -import ca.uhn.fhir.jpa.api.model.TranslationRequest; -import ca.uhn.fhir.jpa.model.util.JpaConstants; -import ca.uhn.fhir.jpa.provider.BaseJpaResourceProvider; -import ca.uhn.fhir.jpa.term.TermConceptMappingSvcImpl; -import ca.uhn.fhir.rest.annotation.IdParam; -import ca.uhn.fhir.rest.annotation.Operation; -import ca.uhn.fhir.rest.annotation.OperationParam; -import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; -import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; -import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_40; -import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_40; -import org.hl7.fhir.dstu3.model.BooleanType; -import org.hl7.fhir.dstu3.model.CodeType; -import org.hl7.fhir.dstu3.model.CodeableConcept; -import org.hl7.fhir.dstu3.model.Coding; -import org.hl7.fhir.dstu3.model.ConceptMap; -import org.hl7.fhir.dstu3.model.IdType; -import org.hl7.fhir.dstu3.model.Parameters; -import org.hl7.fhir.dstu3.model.StringType; -import org.hl7.fhir.dstu3.model.UriType; -import org.hl7.fhir.exceptions.FHIRException; - -import javax.servlet.http.HttpServletRequest; - -public abstract class BaseJpaResourceProviderConceptMapDstu3 extends BaseJpaResourceProvider { - @Operation(name = JpaConstants.OPERATION_TRANSLATE, idempotent = true, returnParameters = { - @OperationParam(name = "result", type = BooleanType.class, min = 1, max = 1), - @OperationParam(name = "message", type = StringType.class, min = 0, max = 1), - }) - public Parameters translate( - HttpServletRequest theServletRequest, - @IdParam(optional = true) IdType theId, - @OperationParam(name = "url", min = 0, max = 1) UriType theUrl, - @OperationParam(name = "conceptMapVersion", min = 0, max = 1) StringType theConceptMapVersion, - @OperationParam(name = "code", min = 0, max = 1) CodeType theSourceCode, - @OperationParam(name = "system", min = 0, max = 1) UriType theSourceCodeSystem, - @OperationParam(name = "version", min = 0, max = 1) StringType theSourceCodeSystemVersion, - @OperationParam(name = "source", min = 0, max = 1) UriType theSourceValueSet, - @OperationParam(name = "coding", min = 0, max = 1) Coding theSourceCoding, - @OperationParam(name = "codeableConcept", min = 0, max = 1) CodeableConcept theSourceCodeableConcept, - @OperationParam(name = "target", min = 0, max = 1) UriType theTargetValueSet, - @OperationParam(name = "targetsystem", min = 0, max = 1) UriType theTargetCodeSystem, - @OperationParam(name = "reverse", min = 0, max = 1) BooleanType theReverse, - RequestDetails theRequestDetails - ) { - boolean haveUrl = theUrl != null - && theUrl.hasValue(); - boolean haveConceptMapVersion = theConceptMapVersion != null - && theConceptMapVersion.hasValue(); - boolean haveSourceCode = theSourceCode != null - && theSourceCode.hasValue(); - boolean haveSourceCodeSystem = theSourceCodeSystem != null - && theSourceCodeSystem.hasValue(); - boolean haveSourceCodeSystemVersion = theSourceCodeSystemVersion != null - && theSourceCodeSystemVersion.hasValue(); - boolean haveSourceValueSet = theSourceValueSet != null - && theSourceValueSet.hasValue(); - boolean haveSourceCoding = theSourceCoding != null - && theSourceCoding.hasCode(); - boolean haveSourceCodeableConcept = theSourceCodeableConcept != null - && theSourceCodeableConcept.hasCoding() - && theSourceCodeableConcept.getCodingFirstRep().hasCode(); - boolean haveTargetValueSet = theTargetValueSet != null - && theTargetValueSet.hasValue(); - boolean haveTargetCodeSystem = theTargetCodeSystem != null - && theTargetCodeSystem.hasValue(); - boolean haveReverse = theReverse != null; - boolean haveId = theId != null && theId.hasIdPart(); - - // - if ((!haveSourceCode && !haveSourceCoding && !haveSourceCodeableConcept) - || moreThanOneTrue(haveSourceCode, haveSourceCoding, haveSourceCodeableConcept)) { - throw new InvalidRequestException(Msg.code(1149) + "One (and only one) of the in parameters (code, coding, codeableConcept) must be provided, to identify the code that is to be translated."); - } - - TranslationRequest translationRequest = new TranslationRequest(); - try { - - if (haveUrl) { - translationRequest.setUrl((org.hl7.fhir.r4.model.UriType) VersionConvertorFactory_30_40.convertType(theUrl, new BaseAdvisor_30_40(false))); - } - - if (haveConceptMapVersion) { - translationRequest.setConceptMapVersion((org.hl7.fhir.r4.model.StringType) VersionConvertorFactory_30_40.convertType(theConceptMapVersion, new BaseAdvisor_30_40(false))); - } - - // Convert from DSTU3 to R4 - if (haveSourceCode) { - translationRequest.getCodeableConcept().addCoding().setCodeElement((org.hl7.fhir.r4.model.CodeType) VersionConvertorFactory_30_40.convertType(theSourceCode, new BaseAdvisor_30_40(false))); - - if (haveSourceCodeSystem) { - translationRequest.getCodeableConcept().getCodingFirstRep().setSystemElement((org.hl7.fhir.r4.model.UriType) VersionConvertorFactory_30_40.convertType(theSourceCodeSystem, new BaseAdvisor_30_40(false))); - } - - if (haveSourceCodeSystemVersion) { - translationRequest.getCodeableConcept().getCodingFirstRep().setVersionElement((org.hl7.fhir.r4.model.StringType) VersionConvertorFactory_30_40.convertType(theSourceCodeSystemVersion, new BaseAdvisor_30_40(false))); - } - } else if (haveSourceCoding) { - translationRequest.getCodeableConcept().addCoding((org.hl7.fhir.r4.model.Coding) VersionConvertorFactory_30_40.convertType(theSourceCoding, new BaseAdvisor_30_40(false))); - } else { - translationRequest.setCodeableConcept((org.hl7.fhir.r4.model.CodeableConcept) VersionConvertorFactory_30_40.convertType(theSourceCodeableConcept, new BaseAdvisor_30_40(false))); - } - - if (haveSourceValueSet) { - translationRequest.setSource((org.hl7.fhir.r4.model.UriType) VersionConvertorFactory_30_40.convertType(theSourceValueSet, new BaseAdvisor_30_40(false))); - } - - if (haveTargetValueSet) { - translationRequest.setTarget((org.hl7.fhir.r4.model.UriType) VersionConvertorFactory_30_40.convertType(theTargetValueSet, new BaseAdvisor_30_40(false))); - } - - if (haveTargetCodeSystem) { - translationRequest.setTargetSystem((org.hl7.fhir.r4.model.UriType) VersionConvertorFactory_30_40.convertType(theTargetCodeSystem, new BaseAdvisor_30_40(false))); - } - - if (haveReverse) { - translationRequest.setReverse((org.hl7.fhir.r4.model.BooleanType) VersionConvertorFactory_30_40.convertType(theReverse, new BaseAdvisor_30_40(false))); - } - - if (haveId) { - translationRequest.setResourceId(theId.getIdPartAsLong()); - } - } catch (FHIRException fe) { - throw new InternalErrorException(Msg.code(1150) + fe); - } - - startRequest(theServletRequest); - try { - IFhirResourceDaoConceptMap dao = (IFhirResourceDaoConceptMap) getDao(); - TranslateConceptResults result = dao.translate(translationRequest, theRequestDetails); - - // Convert from R4 to DSTU3 - return (Parameters) VersionConvertorFactory_30_40.convertResource(TermConceptMappingSvcImpl.toParameters(result), new BaseAdvisor_30_40(false)); - } catch (FHIRException fe) { - throw new InternalErrorException(Msg.code(1151) + fe); - } finally { - endRequest(theServletRequest); - } - } - - private static boolean moreThanOneTrue(boolean... theBooleans) { - boolean haveOne = false; - for (boolean next : theBooleans) { - if (next) { - if (haveOne) { - return true; - } else { - haveOne = true; - } - } - } - return false; - } -} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4/BaseJpaResourceProviderConceptMapR4.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4/BaseJpaResourceProviderConceptMapR4.java deleted file mode 100644 index 8dbbc6ab345..00000000000 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4/BaseJpaResourceProviderConceptMapR4.java +++ /dev/null @@ -1,167 +0,0 @@ -package ca.uhn.fhir.jpa.provider.r4; - -/* - * #%L - * HAPI FHIR JPA Server - * %% - * Copyright (C) 2014 - 2022 Smile CDR, Inc. - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import ca.uhn.fhir.context.support.TranslateConceptResults; -import ca.uhn.fhir.i18n.Msg; -import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoConceptMap; -import ca.uhn.fhir.jpa.api.model.TranslationRequest; -import ca.uhn.fhir.jpa.model.util.JpaConstants; -import ca.uhn.fhir.jpa.provider.BaseJpaResourceProvider; -import ca.uhn.fhir.jpa.term.TermConceptMappingSvcImpl; -import ca.uhn.fhir.rest.annotation.IdParam; -import ca.uhn.fhir.rest.annotation.Operation; -import ca.uhn.fhir.rest.annotation.OperationParam; -import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; -import org.hl7.fhir.r4.model.BooleanType; -import org.hl7.fhir.r4.model.CodeType; -import org.hl7.fhir.r4.model.CodeableConcept; -import org.hl7.fhir.r4.model.Coding; -import org.hl7.fhir.r4.model.ConceptMap; -import org.hl7.fhir.r4.model.IdType; -import org.hl7.fhir.r4.model.Parameters; -import org.hl7.fhir.r4.model.StringType; -import org.hl7.fhir.r4.model.UriType; - -import javax.servlet.http.HttpServletRequest; - -public abstract class BaseJpaResourceProviderConceptMapR4 extends BaseJpaResourceProvider { - @Operation(name = JpaConstants.OPERATION_TRANSLATE, idempotent = true, returnParameters = { - @OperationParam(name = "result", type = BooleanType.class, min = 1, max = 1), - @OperationParam(name = "message", type = StringType.class, min = 0, max = 1), - }) - public Parameters translate( - HttpServletRequest theServletRequest, - @IdParam(optional = true) IdType theId, - @OperationParam(name = "url", min = 0, max = 1) UriType theUrl, - @OperationParam(name = "conceptMapVersion", min = 0, max = 1) StringType theConceptMapVersion, - @OperationParam(name = "code", min = 0, max = 1) CodeType theSourceCode, - @OperationParam(name = "system", min = 0, max = 1) UriType theSourceCodeSystem, - @OperationParam(name = "version", min = 0, max = 1) StringType theSourceCodeSystemVersion, - @OperationParam(name = "source", min = 0, max = 1) UriType theSourceValueSet, - @OperationParam(name = "coding", min = 0, max = 1) Coding theSourceCoding, - @OperationParam(name = "codeableConcept", min = 0, max = 1) CodeableConcept theSourceCodeableConcept, - @OperationParam(name = "target", min = 0, max = 1) UriType theTargetValueSet, - @OperationParam(name = "targetsystem", min = 0, max = 1) UriType theTargetCodeSystem, - @OperationParam(name = "reverse", min = 0, max = 1) BooleanType theReverse, - RequestDetails theRequestDetails - ) { - boolean haveUrl = theUrl != null - && theUrl.hasValue(); - boolean haveConceptMapVersion = theConceptMapVersion != null - && theConceptMapVersion.hasValue(); - boolean haveSourceCode = theSourceCode != null - && theSourceCode.hasCode(); - boolean haveSourceCodeSystem = theSourceCodeSystem != null - && theSourceCodeSystem.hasValue(); - boolean haveSourceCodeSystemVersion = theSourceCodeSystemVersion != null - && theSourceCodeSystemVersion.hasValue(); - boolean haveSourceValueSet = theSourceValueSet != null - && theSourceValueSet.hasValue(); - boolean haveSourceCoding = theSourceCoding != null - && theSourceCoding.hasCode(); - boolean haveSourceCodeableConcept = theSourceCodeableConcept != null - && theSourceCodeableConcept.hasCoding() - && theSourceCodeableConcept.getCodingFirstRep().hasCode(); - boolean haveTargetValueSet = theTargetValueSet != null - && theTargetValueSet.hasValue(); - boolean haveTargetCodeSystem = theTargetCodeSystem != null - && theTargetCodeSystem.hasValue(); - boolean haveReverse = theReverse != null; - boolean haveId = theId != null && theId.hasIdPart(); - - // - if ((!haveSourceCode && !haveSourceCoding && !haveSourceCodeableConcept) - || moreThanOneTrue(haveSourceCode, haveSourceCoding, haveSourceCodeableConcept)) { - throw new InvalidRequestException(Msg.code(1154) + "One (and only one) of the in parameters (code, coding, codeableConcept) must be provided, to identify the code that is to be translated."); - } - - TranslationRequest translationRequest = new TranslationRequest(); - - if (haveUrl) { - translationRequest.setUrl(theUrl); - } - - if (haveConceptMapVersion) { - translationRequest.setConceptMapVersion(theConceptMapVersion); - } - - if (haveSourceCode) { - translationRequest.getCodeableConcept().addCoding().setCodeElement(theSourceCode); - - if (haveSourceCodeSystem) { - translationRequest.getCodeableConcept().getCodingFirstRep().setSystemElement(theSourceCodeSystem); - } - - if (haveSourceCodeSystemVersion) { - translationRequest.getCodeableConcept().getCodingFirstRep().setVersionElement(theSourceCodeSystemVersion); - } - } else if (haveSourceCoding) { - translationRequest.getCodeableConcept().addCoding(theSourceCoding); - } else { - translationRequest.setCodeableConcept(theSourceCodeableConcept); - } - - if (haveSourceValueSet) { - translationRequest.setSource(theSourceValueSet); - } - - if (haveTargetValueSet) { - translationRequest.setTarget(theTargetValueSet); - } - - if (haveTargetCodeSystem) { - translationRequest.setTargetSystem(theTargetCodeSystem); - } - - if (haveReverse) { - translationRequest.setReverse(theReverse); - } - - if (haveId) { - translationRequest.setResourceId(theId.getIdPartAsLong()); - } - - startRequest(theServletRequest); - try { - IFhirResourceDaoConceptMap dao = (IFhirResourceDaoConceptMap) getDao(); - TranslateConceptResults result = dao.translate(translationRequest, theRequestDetails); - return TermConceptMappingSvcImpl.toParameters(result); - } finally { - endRequest(theServletRequest); - } - } - - private static boolean moreThanOneTrue(boolean... theBooleans) { - boolean haveOne = false; - for (boolean next : theBooleans) { - if (next) { - if (haveOne) { - return true; - } else { - haveOne = true; - } - } - } - return false; - } -} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4b/BaseJpaResourceProviderConceptMapR4B.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4b/BaseJpaResourceProviderConceptMapR4B.java deleted file mode 100644 index d33f15093ed..00000000000 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4b/BaseJpaResourceProviderConceptMapR4B.java +++ /dev/null @@ -1,27 +0,0 @@ -package ca.uhn.fhir.jpa.provider.r4b; - -/* - * #%L - * HAPI FHIR JPA Server - * %% - * Copyright (C) 2014 - 2022 Smile CDR, Inc. - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import ca.uhn.fhir.jpa.provider.BaseJpaResourceProvider; -import org.hl7.fhir.r4b.model.ConceptMap; - -public abstract class BaseJpaResourceProviderConceptMapR4B extends BaseJpaResourceProvider { -} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r5/BaseJpaResourceProviderConceptMapR5.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r5/BaseJpaResourceProviderConceptMapR5.java deleted file mode 100644 index 7fb88361ff5..00000000000 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r5/BaseJpaResourceProviderConceptMapR5.java +++ /dev/null @@ -1,171 +0,0 @@ -package ca.uhn.fhir.jpa.provider.r5; - -/* - * #%L - * HAPI FHIR JPA Server - * %% - * Copyright (C) 2014 - 2022 Smile CDR, Inc. - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import ca.uhn.fhir.context.support.TranslateConceptResults; -import ca.uhn.fhir.i18n.Msg; -import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoConceptMap; -import ca.uhn.fhir.jpa.api.model.TranslationRequest; -import ca.uhn.fhir.jpa.model.util.JpaConstants; -import ca.uhn.fhir.jpa.provider.BaseJpaResourceProvider; -import ca.uhn.fhir.jpa.term.TermConceptMappingSvcImpl; -import ca.uhn.fhir.rest.annotation.IdParam; -import ca.uhn.fhir.rest.annotation.Operation; -import ca.uhn.fhir.rest.annotation.OperationParam; -import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; -import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_40_50; -import org.hl7.fhir.convertors.factory.VersionConvertorFactory_40_50; -import org.hl7.fhir.r5.model.BooleanType; -import org.hl7.fhir.r5.model.CodeType; -import org.hl7.fhir.r5.model.CodeableConcept; -import org.hl7.fhir.r5.model.Coding; -import org.hl7.fhir.r5.model.ConceptMap; -import org.hl7.fhir.r5.model.IdType; -import org.hl7.fhir.r5.model.Parameters; -import org.hl7.fhir.r5.model.StringType; -import org.hl7.fhir.r5.model.UriType; - -import javax.servlet.http.HttpServletRequest; - -public abstract class BaseJpaResourceProviderConceptMapR5 extends BaseJpaResourceProvider { - @Operation(name = JpaConstants.OPERATION_TRANSLATE, idempotent = true, returnParameters = { - @OperationParam(name = "result", type = BooleanType.class, min = 1, max = 1), - @OperationParam(name = "message", type = StringType.class, min = 0, max = 1), - }) - public Parameters translate( - HttpServletRequest theServletRequest, - @IdParam(optional = true) IdType theId, - @OperationParam(name = "url", min = 0, max = 1) UriType theUrl, - @OperationParam(name = "conceptMapVersion", min = 0, max = 1) StringType theConceptMapVersion, - @OperationParam(name = "code", min = 0, max = 1) CodeType theSourceCode, - @OperationParam(name = "system", min = 0, max = 1) UriType theSourceCodeSystem, - @OperationParam(name = "version", min = 0, max = 1) StringType theSourceCodeSystemVersion, - @OperationParam(name = "source", min = 0, max = 1) UriType theSourceValueSet, - @OperationParam(name = "coding", min = 0, max = 1) Coding theSourceCoding, - @OperationParam(name = "codeableConcept", min = 0, max = 1) CodeableConcept theSourceCodeableConcept, - @OperationParam(name = "target", min = 0, max = 1) UriType theTargetValueSet, - @OperationParam(name = "targetsystem", min = 0, max = 1) UriType theTargetCodeSystem, - @OperationParam(name = "reverse", min = 0, max = 1) BooleanType theReverse, - RequestDetails theRequestDetails - ) { - boolean haveUrl = theUrl != null - && theUrl.hasValue(); - boolean haveConceptMapVersion = theConceptMapVersion != null - && theConceptMapVersion.hasValue(); - boolean haveSourceCode = theSourceCode != null - && theSourceCode.hasCode(); - boolean haveSourceCodeSystem = theSourceCodeSystem != null - && theSourceCodeSystem.hasValue(); - boolean haveSourceCodeSystemVersion = theSourceCodeSystemVersion != null - && theSourceCodeSystemVersion.hasValue(); - boolean haveSourceValueSet = theSourceValueSet != null - && theSourceValueSet.hasValue(); - boolean haveSourceCoding = theSourceCoding != null - && theSourceCoding.hasCode(); - boolean haveSourceCodeableConcept = theSourceCodeableConcept != null - && theSourceCodeableConcept.hasCoding() - && theSourceCodeableConcept.getCodingFirstRep().hasCode(); - boolean haveTargetValueSet = theTargetValueSet != null - && theTargetValueSet.hasValue(); - boolean haveTargetCodeSystem = theTargetCodeSystem != null - && theTargetCodeSystem.hasValue(); - boolean haveReverse = theReverse != null; - boolean haveId = theId != null && theId.hasIdPart(); - - // - if ((!haveSourceCode && !haveSourceCoding && !haveSourceCodeableConcept) - || moreThanOneTrue(haveSourceCode, haveSourceCoding, haveSourceCodeableConcept)) { - throw new InvalidRequestException(Msg.code(1161) + "One (and only one) of the in parameters (code, coding, codeableConcept) must be provided, to identify the code that is to be translated."); - } - - TranslationRequest translationRequest = new TranslationRequest(); - - if (haveUrl) { - translationRequest.setUrl((org.hl7.fhir.r4.model.UriType) VersionConvertorFactory_40_50.convertType(theUrl, new BaseAdvisor_40_50(false))); - } - - if (haveConceptMapVersion) { - translationRequest.setConceptMapVersion((org.hl7.fhir.r4.model.StringType) VersionConvertorFactory_40_50.convertType(theConceptMapVersion, new BaseAdvisor_40_50(false))); - } - - if (haveSourceCode) { - translationRequest.getCodeableConcept().addCoding().setCodeElement((org.hl7.fhir.r4.model.CodeType) VersionConvertorFactory_40_50.convertType(theSourceCode, new BaseAdvisor_40_50(false))); - - if (haveSourceCodeSystem) { - translationRequest.getCodeableConcept().getCodingFirstRep().setSystemElement((org.hl7.fhir.r4.model.UriType) VersionConvertorFactory_40_50.convertType(theSourceCodeSystem, new BaseAdvisor_40_50(false))); - } - - if (haveSourceCodeSystemVersion) { - translationRequest.getCodeableConcept().getCodingFirstRep() - .setVersionElement((org.hl7.fhir.r4.model.StringType) VersionConvertorFactory_40_50.convertType(theSourceCodeSystemVersion, new BaseAdvisor_40_50(false))); - } - } else if (haveSourceCoding) { - translationRequest.getCodeableConcept().addCoding((org.hl7.fhir.r4.model.Coding) VersionConvertorFactory_40_50.convertType(theSourceCoding, new BaseAdvisor_40_50(false))); - } else { - translationRequest.setCodeableConcept((org.hl7.fhir.r4.model.CodeableConcept) VersionConvertorFactory_40_50.convertType(theSourceCodeableConcept, new BaseAdvisor_40_50(false))); - } - - if (haveSourceValueSet) { - translationRequest.setSource((org.hl7.fhir.r4.model.UriType) VersionConvertorFactory_40_50.convertType(theSourceValueSet, new BaseAdvisor_40_50(false))); - } - - if (haveTargetValueSet) { - translationRequest.setTarget((org.hl7.fhir.r4.model.UriType) VersionConvertorFactory_40_50.convertType(theTargetValueSet, new BaseAdvisor_40_50(false))); - } - - if (haveTargetCodeSystem) { - translationRequest.setTargetSystem((org.hl7.fhir.r4.model.UriType) VersionConvertorFactory_40_50.convertType(theTargetCodeSystem, new BaseAdvisor_40_50(false))); - } - - if (haveReverse) { - translationRequest.setReverse((org.hl7.fhir.r4.model.BooleanType) VersionConvertorFactory_40_50.convertType(theReverse, new BaseAdvisor_40_50(false))); - } - - if (haveId) { - translationRequest.setResourceId(theId.getIdPartAsLong()); - } - - startRequest(theServletRequest); - try { - IFhirResourceDaoConceptMap dao = (IFhirResourceDaoConceptMap) getDao(); - TranslateConceptResults result = dao.translate(translationRequest, theRequestDetails); - org.hl7.fhir.r4.model.Parameters parameters = TermConceptMappingSvcImpl.toParameters(result); - return (Parameters) VersionConvertorFactory_40_50.convertResource(parameters, new BaseAdvisor_40_50(false)); - } finally { - endRequest(theServletRequest); - } - } - - private static boolean moreThanOneTrue(boolean... theBooleans) { - boolean haveOne = false; - for (boolean next : theBooleans) { - if (next) { - if (haveOne) { - return true; - } else { - haveOne = true; - } - } - } - return false; - } -} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermConceptMappingSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermConceptMappingSvcImpl.java index 04beeed8a0d..bd1f42e37f2 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermConceptMappingSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermConceptMappingSvcImpl.java @@ -20,12 +20,14 @@ package ca.uhn.fhir.jpa.term; * #L% */ -import ca.uhn.fhir.i18n.Msg; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.support.TranslateConceptResult; import ca.uhn.fhir.context.support.TranslateConceptResults; +import ca.uhn.fhir.i18n.Msg; +import ca.uhn.fhir.interceptor.model.RequestPartitionId; import ca.uhn.fhir.jpa.api.model.TranslationQuery; import ca.uhn.fhir.jpa.api.model.TranslationRequest; +import ca.uhn.fhir.jpa.api.svc.IIdHelperService; import ca.uhn.fhir.jpa.dao.data.ITermConceptMapDao; import ca.uhn.fhir.jpa.dao.data.ITermConceptMapGroupDao; import ca.uhn.fhir.jpa.dao.data.ITermConceptMapGroupElementDao; @@ -38,6 +40,7 @@ import ca.uhn.fhir.jpa.model.entity.ResourceTable; import ca.uhn.fhir.jpa.term.api.ITermConceptMappingSvc; import ca.uhn.fhir.jpa.util.MemoryCacheService; import ca.uhn.fhir.jpa.util.ScrollableResultsIterator; +import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; @@ -47,6 +50,7 @@ import org.apache.commons.lang3.StringUtils; import org.hibernate.ScrollMode; import org.hibernate.ScrollableResults; import org.hl7.fhir.exceptions.FHIRException; +import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.BooleanType; import org.hl7.fhir.r4.model.CodeType; import org.hl7.fhir.r4.model.Coding; @@ -102,6 +106,8 @@ public class TermConceptMappingSvcImpl implements ITermConceptMappingSvc { private FhirContext myContext; @Autowired private MemoryCacheService myMemoryCacheService; + @Autowired + private IIdHelperService myIdHelperService; @Override @Transactional @@ -328,14 +334,14 @@ public class TermConceptMappingSvcImpl implements ITermConceptMappingSvc { } if (translationQuery.hasTargetSystem()) { - predicates.add(criteriaBuilder.equal(groupJoin.get("myTarget"), translationQuery.getTargetSystem().getValueAsString())); + predicates.add(criteriaBuilder.equal(groupJoin.get("myTarget"), translationQuery.getTargetSystem())); } if (translationQuery.hasUrl()) { - predicates.add(criteriaBuilder.equal(conceptMapJoin.get("myUrl"), translationQuery.getUrl().getValueAsString())); + predicates.add(criteriaBuilder.equal(conceptMapJoin.get("myUrl"), translationQuery.getUrl())); if (translationQuery.hasConceptMapVersion()) { // both url and conceptMapVersion - predicates.add(criteriaBuilder.equal(conceptMapJoin.get("myVersion"), translationQuery.getConceptMapVersion().getValueAsString())); + predicates.add(criteriaBuilder.equal(conceptMapJoin.get("myVersion"), translationQuery.getConceptMapVersion())); } else { if (StringUtils.isNotBlank(latestConceptMapVersion)) { // only url and use latestConceptMapVersion @@ -347,15 +353,17 @@ public class TermConceptMappingSvcImpl implements ITermConceptMappingSvc { } if (translationQuery.hasSource()) { - predicates.add(criteriaBuilder.equal(conceptMapJoin.get("mySource"), translationQuery.getSource().getValueAsString())); + predicates.add(criteriaBuilder.equal(conceptMapJoin.get("mySource"), translationQuery.getSource())); } if (translationQuery.hasTarget()) { - predicates.add(criteriaBuilder.equal(conceptMapJoin.get("myTarget"), translationQuery.getTarget().getValueAsString())); + predicates.add(criteriaBuilder.equal(conceptMapJoin.get("myTarget"), translationQuery.getTarget())); } if (translationQuery.hasResourceId()) { - predicates.add(criteriaBuilder.equal(conceptMapJoin.get("myResourcePid"), translationQuery.getResourceId())); + IIdType resourceId = translationQuery.getResourceId(); + ResourcePersistentId resourcePid = myIdHelperService.getPidOrThrowException(RequestPartitionId.defaultPartition(), resourceId); + predicates.add(criteriaBuilder.equal(conceptMapJoin.get("myResourcePid"), resourcePid.getIdAsLong())); } Predicate outerPredicate = criteriaBuilder.and(predicates.toArray(new Predicate[0])); @@ -455,10 +463,10 @@ public class TermConceptMappingSvcImpl implements ITermConceptMappingSvc { } if (translationQuery.hasUrl()) { - predicates.add(criteriaBuilder.equal(conceptMapJoin.get("myUrl"), translationQuery.getUrl().getValueAsString())); + predicates.add(criteriaBuilder.equal(conceptMapJoin.get("myUrl"), translationQuery.getUrl())); if (translationQuery.hasConceptMapVersion()) { // both url and conceptMapVersion - predicates.add(criteriaBuilder.equal(conceptMapJoin.get("myVersion"), translationQuery.getConceptMapVersion().getValueAsString())); + predicates.add(criteriaBuilder.equal(conceptMapJoin.get("myVersion"), translationQuery.getConceptMapVersion())); } else { if (StringUtils.isNotBlank(latestConceptMapVersion)) { // only url and use latestConceptMapVersion @@ -470,19 +478,21 @@ public class TermConceptMappingSvcImpl implements ITermConceptMappingSvc { } if (translationQuery.hasTargetSystem()) { - predicates.add(criteriaBuilder.equal(groupJoin.get("mySource"), translationQuery.getTargetSystem().getValueAsString())); + predicates.add(criteriaBuilder.equal(groupJoin.get("mySource"), translationQuery.getTargetSystem())); } if (translationQuery.hasSource()) { - predicates.add(criteriaBuilder.equal(conceptMapJoin.get("myTarget"), translationQuery.getSource().getValueAsString())); + predicates.add(criteriaBuilder.equal(conceptMapJoin.get("myTarget"), translationQuery.getSource())); } if (translationQuery.hasTarget()) { - predicates.add(criteriaBuilder.equal(conceptMapJoin.get("mySource"), translationQuery.getTarget().getValueAsString())); + predicates.add(criteriaBuilder.equal(conceptMapJoin.get("mySource"), translationQuery.getTarget())); } if (translationQuery.hasResourceId()) { - predicates.add(criteriaBuilder.equal(conceptMapJoin.get("myResourcePid"), translationQuery.getResourceId())); + IIdType resourceId = translationQuery.getResourceId(); + ResourcePersistentId resourcePid = myIdHelperService.getPidOrThrowException(RequestPartitionId.defaultPartition(), resourceId); + predicates.add(criteriaBuilder.equal(conceptMapJoin.get("myResourcePid"), resourcePid.getIdAsLong())); } Predicate outerPredicate = criteriaBuilder.and(predicates.toArray(new Predicate[0])); @@ -600,7 +610,7 @@ public class TermConceptMappingSvcImpl implements ITermConceptMappingSvc { Pageable page = PageRequest.of(0, 1); List theConceptMapList = myConceptMapDao.getTermConceptMapEntitiesByUrlOrderByMostRecentUpdate(page, - theTranslationRequest.getUrl().asStringValue()); + theTranslationRequest.getUrl()); if (!theConceptMapList.isEmpty()) { return theConceptMapList.get(0).getVersion(); } diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmControllerSvcImplTest.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmControllerSvcImplTest.java index e436b638d68..500b9275ca4 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmControllerSvcImplTest.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmControllerSvcImplTest.java @@ -151,7 +151,7 @@ public class MdmControllerSvcImplTest extends BaseLinkR4Test { ServletRequestDetails details = new ServletRequestDetails(); details.setTenantId(PARTITION_2); IBaseParameters clearJob = myMdmControllerSvc.submitMdmClearJob(urls, batchSize, details); - String jobId = ((StringType) ((Parameters) clearJob).getParameter("jobId")).getValueAsString(); + String jobId = ((StringType) ((Parameters) clearJob).getParameterValue("jobId")).getValueAsString(); myBatch2JobHelper.awaitJobCompletion(jobId); assertLinkCount(2); diff --git a/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java b/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java index 83866421663..dfb6fe1b254 100644 --- a/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java +++ b/hapi-fhir-jpaserver-test-dstu2/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java @@ -307,16 +307,42 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { @Test public void testIndexNoDuplicatesUri() { ConceptMap res = new ConceptMap(); - res.addElement().addTarget().addDependsOn().setElement("http://foo"); - res.addElement().addTarget().addDependsOn().setElement("http://foo"); - res.addElement().addTarget().addDependsOn().setElement("http://bar"); - res.addElement().addTarget().addDependsOn().setElement("http://bar"); + res.setUrl("http://foo"); + res.addElement() + .setCodeSystem("http://cs") + .setCodeSystem("C") + .addTarget() + .setCodeSystem("http://cs2") + .setCode("T") + .addDependsOn() + .setElement("http://foo"); + res.addElement() + .setCodeSystem("C") + .setCodeSystem("http://cs") + .addTarget() + .setCodeSystem("http://cs2") + .setCode("T") + .addDependsOn().setElement("http://foo"); + res.addElement() + .setCodeSystem("http://cs") + .setCodeSystem("C") + .addTarget() + .setCodeSystem("http://cs2") + .setCode("T") + .addDependsOn().setElement("http://bar"); + res.addElement() + .setCodeSystem("http://cs") + .setCodeSystem("C") + .addTarget() + .setCodeSystem("http://cs2") + .setCode("T") + .addDependsOn().setElement("http://bar"); IIdType id = myConceptMapDao.create(res, mySrd).getId().toUnqualifiedVersionless(); runInTransaction(() -> { Class type = ResourceIndexedSearchParamUri.class; - List results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i WHERE i.myMissing = false", type).getResultList(); + List results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i WHERE i.myMissing = false AND i.myParamName = 'dependson'", type).getResultList(); ourLog.info(toStringMultiline(results)); assertEquals(2, results.size()); }); diff --git a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ConceptMapTest.java b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ConceptMapTest.java index 0ec6eb0bdc2..a780706cc19 100644 --- a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ConceptMapTest.java +++ b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ConceptMapTest.java @@ -49,7 +49,7 @@ public class FhirResourceDaoDstu3ConceptMapTest extends BaseJpaDstu3Test { translationRequest.getCodeableConcept().addCoding() .setSystem(CS_URL) .setCode("12345"); - translationRequest.setTargetSystem(new UriType(CS_URL_3)); + translationRequest.setTargetSystem(CS_URL_3); TranslateConceptResults translationResult = myConceptMapDao.translate(translationRequest, null); @@ -73,7 +73,7 @@ public class FhirResourceDaoDstu3ConceptMapTest extends BaseJpaDstu3Test { translationRequest.getCodeableConcept().addCoding() .setSystem(CS_URL) .setCode("12345"); - translationRequest.setTargetSystem(new UriType(CS_URL_3)); + translationRequest.setTargetSystem(CS_URL_3); TranslateConceptResults translationResult = myConceptMapDao.translate(translationRequest, null); diff --git a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/packages/NpmDstu3Test.java b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/packages/NpmDstu3Test.java index 821372b559c..fd08eb7fca3 100644 --- a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/packages/NpmDstu3Test.java +++ b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/packages/NpmDstu3Test.java @@ -29,6 +29,8 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; @@ -100,7 +102,8 @@ public class NpmDstu3Test extends BaseJpaDstu3Test { ourLog.info("Fail Outcome: {}", myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(e.getOperationOutcome())); OperationOutcome oo = (OperationOutcome) e.getOperationOutcome(); - assertEquals("Condition.subject: minimum required = 1, but only found 0 (from http://fhir.de/StructureDefinition/condition-de-basis/0.2)", oo.getIssueFirstRep().getDiagnostics()); + assertThat(oo.getIssueFirstRep().getDiagnostics(), + containsString("Condition.subject: minimum required = 1, but only found 0 (from http://fhir.de/StructureDefinition/condition-de-basis/0.2")); } } diff --git a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/CompositionDocumentDstu3Test.java b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/CompositionDocumentDstu3Test.java index 2bf3823a473..c952dd3ca71 100644 --- a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/CompositionDocumentDstu3Test.java +++ b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/CompositionDocumentDstu3Test.java @@ -116,6 +116,7 @@ public class CompositionDocumentDstu3Test extends BaseResourceProviderDstu3Test String theUrl = myServerBase + "/" + compId + "/$document?_format=json"; Bundle bundle = fetchBundle(theUrl, EncodingEnum.JSON); + ourLog.info("Resp: {}", myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle)); bundle.getEntry().stream() .forEach(entry -> { @@ -123,7 +124,7 @@ public class CompositionDocumentDstu3Test extends BaseResourceProviderDstu3Test }); assertThat(bundle.getType(), is(equalTo(Bundle.BundleType.DOCUMENT))); - assertNull(bundle.getLink("next")); + assertNull(bundle.getLinkOrCreate("next").getUrl()); Set actual = new HashSet<>(); for (BundleEntryComponent nextEntry : bundle.getEntry()) { diff --git a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderQuestionnaireResponseDstu3Test.java b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderQuestionnaireResponseDstu3Test.java index 517ff763792..718e40e8d26 100644 --- a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderQuestionnaireResponseDstu3Test.java +++ b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderQuestionnaireResponseDstu3Test.java @@ -84,7 +84,7 @@ public class ResourceProviderQuestionnaireResponseDstu3Test extends BaseResource myClient.create().resource(qr1).execute(); fail(); } catch (UnprocessableEntityException e) { - assertThat(e.toString(), containsString("Answer value must be of type string")); + assertThat(e.toString(), containsString("Answer value must be of the type string")); } } diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ConceptMapTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ConceptMapTest.java index ccd56ef59fd..be8f0ced754 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ConceptMapTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ConceptMapTest.java @@ -70,7 +70,7 @@ public class FhirResourceDaoR4ConceptMapTest extends BaseJpaR4Test { translationRequest.getCodeableConcept().addCoding() .setSystem(CS_URL) .setCode("12345"); - translationRequest.setTargetSystem(new UriType(CS_URL_3)); + translationRequest.setTargetSystem(CS_URL_3); TranslateConceptResults translationResult = myConceptMapDao.translate(translationRequest, null); @@ -94,7 +94,7 @@ public class FhirResourceDaoR4ConceptMapTest extends BaseJpaR4Test { translationRequest.getCodeableConcept().addCoding() .setSystem(CS_URL) .setCode("12345"); - translationRequest.setTargetSystem(new UriType(CS_URL_3)); + translationRequest.setTargetSystem(CS_URL_3); TranslateConceptResults translationResult = myConceptMapDao.translate(translationRequest, null); @@ -138,7 +138,7 @@ public class FhirResourceDaoR4ConceptMapTest extends BaseJpaR4Test { translationRequest.getCodeableConcept().addCoding() .setSystem(CS_URL) .setCode("12345"); - translationRequest.setTargetSystem(new UriType(CS_URL_2)); + translationRequest.setTargetSystem(CS_URL_2); TranslateConceptResults translationResult = myConceptMapDao.translate(translationRequest, null); @@ -173,7 +173,7 @@ public class FhirResourceDaoR4ConceptMapTest extends BaseJpaR4Test { translationRequest.getCodeableConcept().addCoding() .setSystem(CS_URL) .setCode("BOGUS"); - translationRequest.setTargetSystem(new UriType(CS_URL_3)); + translationRequest.setTargetSystem(CS_URL_3); TranslateConceptResults translationResult = myConceptMapDao.translate(translationRequest, null); @@ -256,7 +256,7 @@ public class FhirResourceDaoR4ConceptMapTest extends BaseJpaR4Test { translationRequest.getCodeableConcept().addCoding() .setSystem(CS_URL) .setCode("12345"); - translationRequest.setTargetSystem(new UriType(CS_URL_2)); + translationRequest.setTargetSystem(CS_URL_2); TranslateConceptResults translationResult = myConceptMapDao.translate(translationRequest, null); @@ -295,7 +295,7 @@ public class FhirResourceDaoR4ConceptMapTest extends BaseJpaR4Test { translationRequest.getCodeableConcept().addCoding() .setSystem(CS_URL) .setCode("12345"); - translationRequest.setTargetSystem(new UriType(CS_URL_3)); + translationRequest.setTargetSystem(CS_URL_3); TranslateConceptResults translationResult = myConceptMapDao.translate(translationRequest, null); @@ -479,7 +479,7 @@ public class FhirResourceDaoR4ConceptMapTest extends BaseJpaR4Test { TranslationRequest translationRequest = new TranslationRequest(); translationRequest.getCodeableConcept().addCoding() .setCode("12345"); - translationRequest.setSource(new UriType(VS_URL)); + translationRequest.setSource(VS_URL); TranslateConceptResults translationResult = myConceptMapDao.translate(translationRequest, null); @@ -532,7 +532,7 @@ public class FhirResourceDaoR4ConceptMapTest extends BaseJpaR4Test { TranslationRequest translationRequest = new TranslationRequest(); translationRequest.getCodeableConcept().addCoding() .setCode("12345"); - translationRequest.setTarget(new UriType(VS_URL_2)); + translationRequest.setTarget(VS_URL_2); TranslateConceptResults translationResult = myConceptMapDao.translate(translationRequest, null); @@ -588,7 +588,7 @@ public class FhirResourceDaoR4ConceptMapTest extends BaseJpaR4Test { translationRequest.getCodeableConcept().addCoding() .setSystem(CS_URL_2) .setCode("34567"); - translationRequest.setTargetSystem(new UriType(CS_URL_4)); + translationRequest.setTargetSystem(CS_URL_4); translationRequest.setReverse(true); TranslateConceptResults translationResult = myConceptMapDao.translate(translationRequest, null); @@ -736,7 +736,7 @@ public class FhirResourceDaoR4ConceptMapTest extends BaseJpaR4Test { translationRequest.getCodeableConcept().addCoding() .setSystem(CS_URL_3) .setCode("67890"); - translationRequest.setTargetSystem(new UriType(CS_URL)); + translationRequest.setTargetSystem(CS_URL); translationRequest.setReverse(true); TranslateConceptResults translationResult = myConceptMapDao.translate(translationRequest, null); @@ -771,7 +771,7 @@ public class FhirResourceDaoR4ConceptMapTest extends BaseJpaR4Test { translationRequest.getCodeableConcept().addCoding() .setSystem(CS_URL_3) .setCode("BOGUS"); - translationRequest.setTargetSystem(new UriType(CS_URL)); + translationRequest.setTargetSystem(CS_URL); translationRequest.setReverse(true); TranslateConceptResults translationResult = myConceptMapDao.translate(translationRequest, null); @@ -850,7 +850,7 @@ public class FhirResourceDaoR4ConceptMapTest extends BaseJpaR4Test { translationRequest.getCodeableConcept().addCoding() .setSystem(CS_URL_2) .setCode("34567"); - translationRequest.setTargetSystem(new UriType(CS_URL)); + translationRequest.setTargetSystem(CS_URL); translationRequest.setReverse(true); TranslateConceptResults translationResult = myConceptMapDao.translate(translationRequest, null); @@ -891,7 +891,7 @@ public class FhirResourceDaoR4ConceptMapTest extends BaseJpaR4Test { translationRequest.getCodeableConcept().addCoding() .setSystem(CS_URL_2) .setCode("34567"); - translationRequest.setTargetSystem(new UriType(CS_URL_4)); + translationRequest.setTargetSystem(CS_URL_4); translationRequest.setReverse(true); TranslateConceptResults translationResult = myConceptMapDao.translate(translationRequest, null); @@ -1026,7 +1026,7 @@ public class FhirResourceDaoR4ConceptMapTest extends BaseJpaR4Test { TranslationRequest translationRequest = new TranslationRequest(); translationRequest.getCodeableConcept().addCoding() .setCode("34567"); - translationRequest.setSource(new UriType(VS_URL_2)); + translationRequest.setSource(VS_URL_2); translationRequest.setReverse(true); TranslateConceptResults translationResult = myConceptMapDao.translate(translationRequest, null); @@ -1073,7 +1073,7 @@ public class FhirResourceDaoR4ConceptMapTest extends BaseJpaR4Test { TranslationRequest translationRequest = new TranslationRequest(); translationRequest.getCodeableConcept().addCoding() .setCode("34567"); - translationRequest.setTarget(new UriType(VS_URL)); + translationRequest.setTarget(VS_URL); translationRequest.setReverse(true); TranslateConceptResults translationResult = myConceptMapDao.translate(translationRequest, null); @@ -1122,7 +1122,7 @@ public class FhirResourceDaoR4ConceptMapTest extends BaseJpaR4Test { translationRequest.getCodeableConcept().addCoding() .setSystem("http://source") .setCode("source1"); - translationRequest.setTarget(new UriType("http://target")); + translationRequest.setTarget("http://target"); ourLog.info("*** About to translate"); TranslateConceptResults translationResult = myConceptMapDao.translate(translationRequest, null); @@ -1177,7 +1177,7 @@ public class FhirResourceDaoR4ConceptMapTest extends BaseJpaR4Test { translationRequest.getCodeableConcept().addCoding() .setSystem("http://source") .setCode("source1"); - translationRequest.setTarget(new UriType("http://target")); + translationRequest.setTarget("http://target"); ourLog.info("*** About to translate"); TranslateConceptResults translationResult = myConceptMapDao.translate(translationRequest, null); @@ -1209,7 +1209,7 @@ public class FhirResourceDaoR4ConceptMapTest extends BaseJpaR4Test { .setCode("263204007"); TranslationRequest request = new TranslationRequest(); request.setCodeableConcept(sourceCode); - request.setTargetSystem(new UriType("http://hl7.org/fhir/sid/icd-10-us")); + request.setTargetSystem("http://hl7.org/fhir/sid/icd-10-us"); TranslateConceptResults outcome = myConceptMapDao.translate(request, mySrd); assertEquals("S52.209A", outcome.getResults().get(0).getCode()); diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java index 11ed60f3dcc..5a8caeba3d1 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java @@ -151,7 +151,10 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { encoded = encode(oo); ourLog.info(encoded); assertEquals(1, oo.getIssue().size(), encoded); - assertEquals("The code provided (http://cs#code99) is not in the value set http://vs, and a code from this value set is required: Unknown code 'http://cs#code99' for in-memory expansion of ValueSet 'http://vs'", oo.getIssueFirstRep().getDiagnostics(), encoded); + assertThat(oo.getIssue().get(0).getDiagnostics(), + containsString("The code provided (http://cs#code99) is not in the value set")); + assertThat(oo.getIssue().get(0).getDiagnostics(), + containsString("Unknown code 'http://cs#code99' for in-memory expansion of ValueSet 'http://vs'")); assertEquals(OperationOutcome.IssueSeverity.ERROR, oo.getIssueFirstRep().getSeverity(), encoded); } @@ -182,7 +185,10 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { encoded = encode(oo); ourLog.info(encoded); assertEquals(1, oo.getIssue().size()); - assertEquals("The code provided (http://cs#code99) is not in the value set http://vs, and a code from this value set is required: Unknown code 'http://cs#code99' for in-memory expansion of ValueSet 'http://vs'", oo.getIssueFirstRep().getDiagnostics()); + assertThat(oo.getIssueFirstRep().getDiagnostics(), + containsString("The code provided (http://cs#code99) is not in the value set")); + assertThat(oo.getIssueFirstRep().getDiagnostics(), + containsString("Unknown code 'http://cs#code99' for in-memory expansion of ValueSet 'http://vs'")); assertEquals(OperationOutcome.IssueSeverity.ERROR, oo.getIssueFirstRep().getSeverity()); } @@ -216,9 +222,11 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { encoded = encode(oo); ourLog.info(encoded); assertEquals(2, oo.getIssue().size()); - assertEquals("CodeSystem is unknown and can't be validated: http://cs for 'http://cs#code99'", oo.getIssue().get(0).getDiagnostics()); + assertThat(oo.getIssue().get(0).getDiagnostics(), + containsString("CodeSystem is unknown and can't be validated: http://cs for 'http://cs#code99'")); assertEquals(OperationOutcome.IssueSeverity.WARNING, oo.getIssue().get(0).getSeverity()); - assertEquals("The code provided (http://cs#code99) is not in the value set http://vs, and a code from this value set is required: Unknown code 'http://cs#code99' for in-memory expansion of ValueSet 'http://vs'", oo.getIssue().get(1).getDiagnostics()); + assertThat(oo.getIssue().get(1).getDiagnostics(), + containsString("The code provided (http://cs#code99) is not in the value set 'ValueSet[http://vs]'")); assertEquals(OperationOutcome.IssueSeverity.ERROR, oo.getIssue().get(1).getSeverity()); } @@ -257,9 +265,8 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { encoded = encode(oo); ourLog.info(encoded); assertEquals(1, oo.getIssue().size()); - assertTrue(oo.getIssueFirstRep() - .getDiagnostics().contains("The code provided (http://cs#code99) is not in the value set http://vs, and a code from this value set is required: Unknown code 'http://cs#code99' for in-memory expansion of ValueSet 'http://vs'") - ); + assertThat(oo.getIssue().get(0).getDiagnostics(), + containsString("The code provided (http://cs#code99) is not in the value set")); assertEquals(OperationOutcome.IssueSeverity.ERROR, oo.getIssueFirstRep().getSeverity()); } @@ -354,7 +361,12 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { encoded = encode(oo); ourLog.info(encoded); assertEquals(1, oo.getIssue().size()); - assertEquals("The code provided (http://cs#code1) is not in the value set http://vs, and a code from this value set is required: Failed to expand ValueSet 'http://vs' (in-memory). Could not validate code http://cs#code1. Error was: HAPI-0702: Unable to expand ValueSet because CodeSystem could not be found: http://cs", oo.getIssueFirstRep().getDiagnostics()); + assertThat(oo.getIssue().get(0).getDiagnostics(), + containsString("The code provided (http://cs#code1) is not in the value set")); + assertThat(oo.getIssue().get(0).getDiagnostics(), + containsString("Failed to expand ValueSet 'http://vs' (in-memory). Could not validate code http://cs#code1")); + assertThat(oo.getIssue().get(0).getDiagnostics(), + containsString("HAPI-0702: Unable to expand ValueSet because CodeSystem could not be found: http://cs")); assertEquals(OperationOutcome.IssueSeverity.ERROR, oo.getIssueFirstRep().getSeverity()); } @@ -520,7 +532,8 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { outcome = (OperationOutcome) e.getOperationOutcome(); String outcomeStr = myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome); ourLog.info("Validation outcome: {}", outcomeStr); - assertThat(outcomeStr, containsString("The code provided (http://unitsofmeasure.org#cm) is not in the value set https://bb/ValueSet/BBDemographicAgeUnit, and a code from this value set is required")); + assertThat(outcomeStr, + containsString("The code provided (http://unitsofmeasure.org#cm) is not in the value set")); } // Before, the VS wasn't pre-expanded. Try again with it pre-expanded @@ -554,7 +567,8 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { outcome = (OperationOutcome) e.getOperationOutcome(); String outcomeStr = myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome); ourLog.info("Validation outcome: {}", outcomeStr); - assertThat(outcomeStr, containsString("The code provided (http://unitsofmeasure.org#cm) is not in the value set https://bb/ValueSet/BBDemographicAgeUnit, and a code from this value set is required")); + assertThat(outcomeStr, + containsString("The code provided (http://unitsofmeasure.org#cm) is not in the value set")); } } @@ -1043,7 +1057,8 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { } catch (PreconditionFailedException e) { outcome = (OperationOutcome) e.getOperationOutcome(); ourLog.info("Outcome: {}", myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome)); - assertEquals("None of the codings provided are in the value set 'MessageCategory' (http://example.com/valueset), and a coding from this value set is required) (codes = http://example.com/foo-foo#some-code)", outcome.getIssueFirstRep().getDiagnostics()); + assertThat(outcome.getIssueFirstRep().getDiagnostics(), + containsString("None of the codings provided are in the value set 'MessageCategory'")); assertEquals(OperationOutcome.IssueSeverity.ERROR, outcome.getIssueFirstRep().getSeverity()); } } @@ -1396,7 +1411,10 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { // It would be ok for this to produce 0 issues, or just an information message too assertEquals(1, OperationOutcomeUtil.getIssueCount(myFhirContext, oo)); - assertEquals("None of the codings provided are in the value set 'IdentifierType' (http://hl7.org/fhir/ValueSet/identifier-type), and a coding should come from this value set unless it has no suitable code (note that the validator cannot judge what is suitable) (codes = http://foo#bar)", OperationOutcomeUtil.getFirstIssueDetails(myFhirContext, oo)); + assertThat(OperationOutcomeUtil.getFirstIssueDetails(myFhirContext, oo), + containsString("None of the codings provided are in the value set 'IdentifierType'")); + assertThat(OperationOutcomeUtil.getFirstIssueDetails(myFhirContext, oo), + containsString("a coding should come from this value set unless it has no suitable code (note that the validator cannot judge what is suitable) (codes = http://foo#bar)")); } diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/interceptor/validation/RepositoryValidatingInterceptorR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/interceptor/validation/RepositoryValidatingInterceptorR4Test.java index 05634376739..c55b2e56a89 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/interceptor/validation/RepositoryValidatingInterceptorR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/interceptor/validation/RepositoryValidatingInterceptorR4Test.java @@ -386,7 +386,8 @@ public class RepositoryValidatingInterceptorR4Test extends BaseJpaR4Test { fail(); } catch (PreconditionFailedException e) { OperationOutcome oo = (OperationOutcome) e.getOperationOutcome(); - assertEquals("Observation.status: minimum required = 1, but only found 0 (from http://hl7.org/fhir/StructureDefinition/Observation)", oo.getIssue().get(0).getDiagnostics()); + assertThat(oo.getIssue().get(0).getDiagnostics(), + containsString("Observation.status: minimum required = 1, but only found 0")); } } diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/partition/PartitionManagementProviderTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/partition/PartitionManagementProviderTest.java index a6b90f5d56a..db988ecb5cc 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/partition/PartitionManagementProviderTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/partition/PartitionManagementProviderTest.java @@ -89,9 +89,9 @@ public class PartitionManagementProviderTest { verify(myPartitionConfigSvc, times(1)).createPartition(any()); verifyNoMoreInteractions(myPartitionConfigSvc); - assertEquals(123, ((IntegerType) response.getParameter(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_ID)).getValue().intValue()); - assertEquals("PARTITION-123", ((StringType) response.getParameter(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_NAME)).getValue()); - assertEquals("a description", ((StringType) response.getParameter(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_DESC)).getValue()); + assertEquals(123, ((IntegerType) response.getParameterValue(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_ID)).getValue().intValue()); + assertEquals("PARTITION-123", ((StringType) response.getParameterValue(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_NAME)).getValue()); + assertEquals("a description", ((StringType) response.getParameterValue(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_DESC)).getValue()); } @Nonnull @@ -141,9 +141,9 @@ public class PartitionManagementProviderTest { verify(myPartitionConfigSvc, times(1)).getPartitionById(any()); verifyNoMoreInteractions(myPartitionConfigSvc); - assertEquals(123, ((IntegerType) response.getParameter(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_ID)).getValue().intValue()); - assertEquals("PARTITION-123", ((StringType) response.getParameter(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_NAME)).getValue()); - assertEquals("a description", ((StringType) response.getParameter(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_DESC)).getValue()); + assertEquals(123, ((IntegerType) response.getParameterValue(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_ID)).getValue().intValue()); + assertEquals("PARTITION-123", ((StringType) response.getParameterValue(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_NAME)).getValue()); + assertEquals("a description", ((StringType) response.getParameterValue(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_DESC)).getValue()); } @Test @@ -182,9 +182,9 @@ public class PartitionManagementProviderTest { verify(myPartitionConfigSvc, times(1)).updatePartition(any()); verifyNoMoreInteractions(myPartitionConfigSvc); - assertEquals(123, ((IntegerType) response.getParameter(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_ID)).getValue().intValue()); - assertEquals("PARTITION-123", ((StringType) response.getParameter(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_NAME)).getValue()); - assertEquals("a description", ((StringType) response.getParameter(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_DESC)).getValue()); + assertEquals(123, ((IntegerType) response.getParameterValue(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_ID)).getValue().intValue()); + assertEquals("PARTITION-123", ((StringType) response.getParameterValue(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_NAME)).getValue()); + assertEquals("a description", ((StringType) response.getParameterValue(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_DESC)).getValue()); } @Test diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/MultitenantBatchOperationR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/MultitenantBatchOperationR4Test.java index 3c9e91aaa77..d285be89db0 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/MultitenantBatchOperationR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/MultitenantBatchOperationR4Test.java @@ -152,7 +152,7 @@ public class MultitenantBatchOperationR4Test extends BaseMultitenantResourceProv .withParameters(input) .execute(); ourLog.info(myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(response)); - StringType jobId = (StringType) response.getParameter(ProviderConstants.OPERATION_REINDEX_RESPONSE_JOB_ID); + StringType jobId = (StringType) response.getParameterValue(ProviderConstants.OPERATION_REINDEX_RESPONSE_JOB_ID); myBatch2JobHelper.awaitJobCompletion(jobId.getValue()); @@ -176,7 +176,7 @@ public class MultitenantBatchOperationR4Test extends BaseMultitenantResourceProv .withParameters(input) .execute(); ourLog.info(myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(response)); - jobId = (StringType) response.getParameter(ProviderConstants.OPERATION_REINDEX_RESPONSE_JOB_ID); + jobId = (StringType) response.getParameterValue(ProviderConstants.OPERATION_REINDEX_RESPONSE_JOB_ID); myBatch2JobHelper.awaitJobCompletion(jobId.getValue()); @@ -219,7 +219,7 @@ public class MultitenantBatchOperationR4Test extends BaseMultitenantResourceProv .withParameters(input) .execute(); ourLog.info(myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(response)); - StringType jobId = (StringType) response.getParameter(ProviderConstants.OPERATION_REINDEX_RESPONSE_JOB_ID); + StringType jobId = (StringType) response.getParameterValue(ProviderConstants.OPERATION_REINDEX_RESPONSE_JOB_ID); myBatch2JobHelper.awaitJobCompletion(jobId.getValue()); diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/RemoteTerminologyServiceResourceProviderR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/RemoteTerminologyServiceResourceProviderR4Test.java index 8b6b2734c2b..c31db7196e3 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/RemoteTerminologyServiceResourceProviderR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/RemoteTerminologyServiceResourceProviderR4Test.java @@ -100,7 +100,7 @@ public class RemoteTerminologyServiceResourceProviderR4Test { assertEquals(CODE, myCodeSystemProvider.myLastCode.getCode()); assertEquals(DISPLAY, myCodeSystemProvider.myLastDisplay.getValue()); assertEquals(CODE_SYSTEM, myCodeSystemProvider.myLastUrl.getValueAsString()); - assertEquals(SAMPLE_MESSAGE, myCodeSystemProvider.myNextReturnParams.getParameter("message").toString()); + assertEquals(SAMPLE_MESSAGE, myCodeSystemProvider.myNextReturnParams.getParameterValue("message").toString()); } @Test @@ -112,7 +112,7 @@ public class RemoteTerminologyServiceResourceProviderR4Test { assertEquals(IValidationSupport.IssueSeverity.ERROR, outcome.getSeverity()); assertEquals(SAMPLE_MESSAGE, outcome.getMessage()); - assertEquals(false, ((BooleanType)myCodeSystemProvider.myNextReturnParams.getParameter("result")).booleanValue()); + assertEquals(false, ((BooleanType)myCodeSystemProvider.myNextReturnParams.getParameterValue("result")).booleanValue()); } @Test @@ -143,7 +143,7 @@ public class RemoteTerminologyServiceResourceProviderR4Test { assertEquals(CODE, myValueSetProvider.myLastCode.getCode()); assertEquals(DISPLAY, myValueSetProvider.myLastDisplay.getValue()); assertEquals(VALUE_SET_URL, myValueSetProvider.myLastUrl.getValueAsString()); - assertEquals(SAMPLE_MESSAGE, myValueSetProvider.myNextReturnParams.getParameter("message").toString()); + assertEquals(SAMPLE_MESSAGE, myValueSetProvider.myNextReturnParams.getParameterValue("message").toString()); } private void createNextCodeSystemReturnParameters(boolean theResult, String theDisplay, String theMessage) { diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderQuestionnaireResponseR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderQuestionnaireResponseR4Test.java index 656a2669740..78ff14d21e4 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderQuestionnaireResponseR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderQuestionnaireResponseR4Test.java @@ -118,7 +118,7 @@ public class ResourceProviderQuestionnaireResponseR4Test extends BaseResourcePro myClient.create().resource(qr1).execute(); fail(); } catch (UnprocessableEntityException e) { - assertThat(myFhirContext.newJsonParser().encodeResourceToString(e.getOperationOutcome()), containsString("Answer value must be of type string")); + assertThat(myFhirContext.newJsonParser().encodeResourceToString(e.getOperationOutcome()), containsString("Answer value must be of the type string")); } } diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ConceptMapTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ConceptMapTest.java index cd367e51aca..cf3639f9e1f 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ConceptMapTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ConceptMapTest.java @@ -2,6 +2,10 @@ package ca.uhn.fhir.jpa.provider.r4; import ca.uhn.fhir.jpa.provider.BaseResourceProviderR4Test; import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.rest.param.TokenParam; +import com.ctc.wstx.shaded.msv_core.util.Uri; +import org.apache.commons.io.IOUtils; +import org.apache.http.client.methods.HttpGet; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.BooleanType; import org.hl7.fhir.r4.model.Bundle; @@ -24,7 +28,10 @@ import org.slf4j.LoggerFactory; import org.springframework.transaction.annotation.Transactional; import java.io.IOException; +import java.nio.charset.StandardCharsets; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; @@ -1958,4 +1965,43 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test part = getPartByName(param, "source"); assertEquals(CM_URL, ((UriType) part.getValue()).getValueAsString()); } + + + /** + * See #4289 + */ + @Test + public void testConceptMapWithNonNumericId() { + ConceptMap cm = new ConceptMap(); + cm.setId("cyehr-cm-allergytype-snomed2hl7fhir"); + cm.setUrl("ttp://ig.ehealth4u.eu/fhir/ConceptMap/cyehr-cm-allergytype-snomed2hl7fhir"); + cm.setSource(new UriType("http://ig.ehealth4u.eu/fhir/ValueSet/cyehr-vs-ehdsiadverseeventtype")); + cm.setTarget(new UriType("http://hl7.org/fhir/ValueSet/allergy-intolerance-type")); + ConceptMapGroupComponent group = cm.addGroup(); + group.setSource("http://snomed.info/sct"); + group.setTarget("http://hl7.org/fhir/allergy-intolerance-type"); + group.addElement() + .setCode("609328004") + .setDisplay("Allergic disposition") + .addTarget() + .setCode("allergy") + .setDisplay("Allergy") + .setEquivalence(ConceptMapEquivalence.WIDER); + + myConceptMapDao.update(cm, mySrd); + + Parameters outcome = myClient + .operation() + .onInstance("ConceptMap/cyehr-cm-allergytype-snomed2hl7fhir") + .named("$translate") + .withParameter(Parameters.class, "code", new CodeType("609328004")) + .andParameter("system", new UriType("http://snomed.info/sct")) + .andParameter("target", new UriType("http://hl7.org/fhir/ValueSet/allergy-intolerance-type")) + .execute(); + + ourLog.info(myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome)); + + } + + } diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4RemoteTerminologyTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4RemoteTerminologyTest.java index f364593f426..a377a90a444 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4RemoteTerminologyTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4RemoteTerminologyTest.java @@ -110,8 +110,8 @@ public class ResourceProviderR4RemoteTerminologyTest extends BaseResourceProvide String resp = myFhirContext.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam); ourLog.info(resp); - assertEquals(true, ((BooleanType)respParam.getParameter("result")).booleanValue()); - assertEquals(DISPLAY, respParam.getParameter("display").toString()); + assertEquals(true, ((BooleanType)respParam.getParameterValue("result")).booleanValue()); + assertEquals(DISPLAY, respParam.getParameterValue("display").toString()); } @Test @@ -135,8 +135,8 @@ public class ResourceProviderR4RemoteTerminologyTest extends BaseResourceProvide String resp = myFhirContext.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam); ourLog.info(resp); - assertEquals(true, ((BooleanType)respParam.getParameter("result")).booleanValue()); - assertEquals(DISPLAY, respParam.getParameter("display").toString()); + assertEquals(true, ((BooleanType)respParam.getParameterValue("result")).booleanValue()); + assertEquals(DISPLAY, respParam.getParameterValue("display").toString()); } @Test @@ -159,8 +159,8 @@ public class ResourceProviderR4RemoteTerminologyTest extends BaseResourceProvide String resp = myFhirContext.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam); ourLog.info(resp); - assertEquals(true, ((BooleanType)respParam.getParameter("result")).booleanValue()); - assertEquals(DISPLAY_BODY_MASS_INDEX, respParam.getParameter("display").toString()); + assertEquals(true, ((BooleanType)respParam.getParameterValue("result")).booleanValue()); + assertEquals(DISPLAY_BODY_MASS_INDEX, respParam.getParameterValue("display").toString()); } private void createNextCodeSystemReturnParameters(boolean theResult, String theDisplay, String theMessage) { diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java index 97b7a4f0b30..2490ed2825d 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java @@ -6864,7 +6864,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { ourLog.info(resp); assertEquals(412, response.getStatusLine().getStatusCode()); - assertThat(resp, stringContainsInOrder("Duplicated property name: name")); + assertThat(resp, stringContainsInOrder("The JSON property 'name' is a duplicate and will be ignored")); } finally { response.getEntity().getContent().close(); response.close(); diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ValueSetNoVerCSNoVerTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ValueSetNoVerCSNoVerTest.java index 11ce8ed3834..18c78ed3593 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ValueSetNoVerCSNoVerTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ValueSetNoVerCSNoVerTest.java @@ -1400,7 +1400,7 @@ public class ResourceProviderR4ValueSetNoVerCSNoVerTest extends BaseResourceProv .named(ProviderConstants.OPERATION_INVALIDATE_EXPANSION) .withNoParameters(Parameters.class) .execute(); - assertEquals("ValueSet with URL \"http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2\" precaluclated expansion with 24 concept(s) has been invalidated", outcome.getParameter("message").primitiveValue()); + assertEquals("ValueSet with URL \"http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2\" precaluclated expansion with 24 concept(s) has been invalidated", outcome.getParameterValue("message").toString()); assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, runInTransaction(()->myTermValueSetDao.findTermValueSetByUrlAndNullVersion("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2").orElseThrow(()->new IllegalStateException()).getExpansionStatus())); @@ -1410,7 +1410,7 @@ public class ResourceProviderR4ValueSetNoVerCSNoVerTest extends BaseResourceProv .named(ProviderConstants.OPERATION_INVALIDATE_EXPANSION) .withNoParameters(Parameters.class) .execute(); - assertEquals("ValueSet with URL \"http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2\" already has status: NOT_EXPANDED", outcome.getParameter("message").primitiveValue()); + assertEquals("ValueSet with URL \"http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2\" already has status: NOT_EXPANDED", outcome.getParameterValue("message").toString()); } @Test diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/term/TermConceptMappingSvcImplTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/term/TermConceptMappingSvcImplTest.java index 81f6cdba1b4..8b527dcf99a 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/term/TermConceptMappingSvcImplTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/term/TermConceptMappingSvcImplTest.java @@ -17,6 +17,7 @@ import org.hl7.fhir.r4.model.CodeableConcept; import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.r4.model.ConceptMap; import org.hl7.fhir.r4.model.Enumerations; +import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.StringType; import org.hl7.fhir.r4.model.UriType; import org.hl7.fhir.r4.model.codesystems.HttpVerb; @@ -83,7 +84,7 @@ public class TermConceptMappingSvcImplTest extends BaseTermR4Test { translationRequest.getCodeableConcept().addCoding() .setSystem(CS_URL) .setCode("12345"); - translationRequest.setTargetSystem(new UriType(CS_URL_3)); + translationRequest.setTargetSystem(CS_URL_3); List targets = myConceptMappingSvc.translate(translationRequest).getResults(); assertNotNull(targets); @@ -137,7 +138,7 @@ public class TermConceptMappingSvcImplTest extends BaseTermR4Test { translationRequest.getCodeableConcept().addCoding() .setSystem(CS_URL) .setCode("12345"); - translationRequest.setTargetSystem(new UriType(CS_URL_2)); + translationRequest.setTargetSystem(CS_URL_2); List targets = myConceptMappingSvc.translate(translationRequest).getResults(); assertNotNull(targets); @@ -179,7 +180,7 @@ public class TermConceptMappingSvcImplTest extends BaseTermR4Test { translationRequest.getCodeableConcept().addCoding() .setSystem(CS_URL) .setCode("BOGUS"); - translationRequest.setTargetSystem(new UriType(CS_URL_3)); + translationRequest.setTargetSystem(CS_URL_3); List targets = myConceptMappingSvc.translate(translationRequest).getResults(); assertNotNull(targets); @@ -211,7 +212,7 @@ public class TermConceptMappingSvcImplTest extends BaseTermR4Test { TranslationRequest translationRequest = new TranslationRequest() .addCode(CS_URL, "12345") - .setTargetSystem(new UriType(CS_URL_2)); + .setTargetSystem(CS_URL_2); TranslateConceptResults resp = myConceptMappingSvc.translate(translationRequest); assertEquals(1, resp.size()); @@ -306,7 +307,7 @@ public class TermConceptMappingSvcImplTest extends BaseTermR4Test { translationRequest.getCodeableConcept().addCoding() .setSystem(CS_URL) .setCode("12345"); - translationRequest.setTargetSystem(new UriType(CS_URL_2)); + translationRequest.setTargetSystem(CS_URL_2); List targets = myConceptMappingSvc.translate(translationRequest).getResults(); assertNotNull(targets); @@ -354,7 +355,7 @@ public class TermConceptMappingSvcImplTest extends BaseTermR4Test { translationRequest.getCodeableConcept().addCoding() .setSystem(CS_URL) .setCode("12345"); - translationRequest.setTargetSystem(new UriType(CS_URL_3)); + translationRequest.setTargetSystem(CS_URL_3); List targets = myConceptMappingSvc.translate(translationRequest).getResults(); assertNotNull(targets); @@ -590,7 +591,7 @@ public class TermConceptMappingSvcImplTest extends BaseTermR4Test { TranslationRequest translationRequest = new TranslationRequest(); translationRequest.getCodeableConcept().addCoding() .setCode("12345"); - translationRequest.setSource(new UriType(VS_URL)); + translationRequest.setSource(VS_URL); List targets = myConceptMappingSvc.translate(translationRequest).getResults(); assertNotNull(targets); @@ -660,7 +661,7 @@ public class TermConceptMappingSvcImplTest extends BaseTermR4Test { TranslationRequest translationRequest = new TranslationRequest(); translationRequest.getCodeableConcept().addCoding() .setCode("12345"); - translationRequest.setTarget(new UriType(VS_URL_2)); + translationRequest.setTarget(VS_URL_2); List targets = myConceptMappingSvc.translate(translationRequest).getResults(); assertNotNull(targets); @@ -733,7 +734,7 @@ public class TermConceptMappingSvcImplTest extends BaseTermR4Test { translationRequest.getCodeableConcept().addCoding() .setSystem(CS_URL_2) .setCode("34567"); - translationRequest.setTargetSystem(new UriType(CS_URL_4)); + translationRequest.setTargetSystem(CS_URL_4); translationRequest.setReverse(true); TranslateConceptResults elements = myConceptMappingSvc.translateWithReverse(translationRequest); @@ -775,7 +776,7 @@ public class TermConceptMappingSvcImplTest extends BaseTermR4Test { translationRequest.getCodeableConcept().addCoding() .setSystem(CS_URL_3) .setCode("BOGUS"); - translationRequest.setTargetSystem(new UriType(CS_URL)); + translationRequest.setTargetSystem(CS_URL); TranslateConceptResults elements = myConceptMappingSvc.translateWithReverse(translationRequest); assertNotNull(elements); @@ -861,7 +862,7 @@ public class TermConceptMappingSvcImplTest extends BaseTermR4Test { translationRequest.getCodeableConcept().addCoding() .setSystem(CS_URL_2) .setCode("34567"); - translationRequest.setTargetSystem(new UriType(CS_URL)); + translationRequest.setTargetSystem(CS_URL); translationRequest.setReverse(true); TranslateConceptResults elements = myConceptMappingSvc.translateWithReverse(translationRequest); @@ -910,7 +911,7 @@ public class TermConceptMappingSvcImplTest extends BaseTermR4Test { translationRequest.getCodeableConcept().addCoding() .setSystem(CS_URL_2) .setCode("34567"); - translationRequest.setTargetSystem(new UriType(CS_URL_4)); + translationRequest.setTargetSystem(CS_URL_4); translationRequest.setReverse(true); TranslateConceptResults elements = myConceptMappingSvc.translateWithReverse(translationRequest); @@ -1075,7 +1076,7 @@ public class TermConceptMappingSvcImplTest extends BaseTermR4Test { TranslationRequest translationRequest = new TranslationRequest(); translationRequest.getCodeableConcept().addCoding() .setCode("34567"); - translationRequest.setSource(new UriType(VS_URL_2)); + translationRequest.setSource(VS_URL_2); translationRequest.setReverse(true); TranslateConceptResults elements = myConceptMappingSvc.translateWithReverse(translationRequest); @@ -1133,7 +1134,7 @@ public class TermConceptMappingSvcImplTest extends BaseTermR4Test { TranslationRequest translationRequest = new TranslationRequest(); translationRequest.getCodeableConcept().addCoding() .setCode("34567"); - translationRequest.setTarget(new UriType(VS_URL)); + translationRequest.setTarget(VS_URL); translationRequest.setReverse(true); TranslateConceptResults elements = myConceptMappingSvc.translateWithReverse(translationRequest); @@ -1570,7 +1571,7 @@ public class TermConceptMappingSvcImplTest extends BaseTermR4Test { "theConceptMapVersion", "theSourceValueSetUrl", "theTargetValueSetUrl", - 0L, + new IdType("ConceptMap/2"), false ); @@ -1582,12 +1583,12 @@ public class TermConceptMappingSvcImplTest extends BaseTermR4Test { TranslationRequest expected = new TranslationRequest(); expected.setCodeableConcept(sourceCodeableConcept); - expected.setConceptMapVersion(new StringType(theRequest.getConceptMapVersion())); - expected.setUrl(new UriType(theRequest.getConceptMapUrl())); - expected.setSource(new UriType(theRequest.getSourceValueSetUrl())); - expected.setTarget(new UriType(theRequest.getTargetValueSetUrl())); - expected.setTargetSystem(new UriType(theRequest.getTargetSystemUrl())); - expected.setResourceId(theRequest.getResourcePid()); + expected.setConceptMapVersion((theRequest.getConceptMapVersion())); + expected.setUrl((theRequest.getConceptMapUrl())); + expected.setSource((theRequest.getSourceValueSetUrl())); + expected.setTarget((theRequest.getTargetValueSetUrl())); + expected.setTargetSystem((theRequest.getTargetSystemUrl())); + expected.setResourceId(theRequest.getResourceId()); expected.setReverse(theRequest.isReverse()); ITermConceptMappingSvc mock = mock(TermConceptMappingSvcImpl.class); @@ -1612,7 +1613,7 @@ public class TermConceptMappingSvcImplTest extends BaseTermR4Test { "theConceptMapVersion", "theSourceValueSetUrl", "theTargetValueSetUrl", - 0L, + new IdType("ConceptMap/A"), true ); @@ -1624,12 +1625,12 @@ public class TermConceptMappingSvcImplTest extends BaseTermR4Test { TranslationRequest expected = new TranslationRequest(); expected.setCodeableConcept(sourceCodeableConcept); - expected.setConceptMapVersion(new StringType(theRequest.getConceptMapVersion())); - expected.setUrl(new UriType(theRequest.getConceptMapUrl())); - expected.setSource(new UriType(theRequest.getSourceValueSetUrl())); - expected.setTarget(new UriType(theRequest.getTargetValueSetUrl())); - expected.setTargetSystem(new UriType(theRequest.getTargetSystemUrl())); - expected.setResourceId(theRequest.getResourcePid()); + expected.setConceptMapVersion((theRequest.getConceptMapVersion())); + expected.setUrl((theRequest.getConceptMapUrl())); + expected.setSource((theRequest.getSourceValueSetUrl())); + expected.setTarget((theRequest.getTargetValueSetUrl())); + expected.setTargetSystem((theRequest.getTargetSystemUrl())); + expected.setResourceId(theRequest.getResourceId()); expected.setReverse(theRequest.isReverse()); ITermConceptMappingSvc mock = mock(TermConceptMappingSvcImpl.class); @@ -1643,11 +1644,11 @@ public class TermConceptMappingSvcImplTest extends BaseTermR4Test { private static void assertSameTranslationRequest(TranslationRequest expected, TranslationRequest actual) { assertTrue(expected.getCodeableConcept().equalsDeep(actual.getCodeableConcept())); - assertEquals(expected.getConceptMapVersion().asStringValue(), actual.getConceptMapVersion().asStringValue()); - assertEquals(expected.getUrl().asStringValue(), actual.getUrl().asStringValue()); - assertEquals(expected.getSource().asStringValue(), actual.getSource().asStringValue()); - assertEquals(expected.getTarget().asStringValue(), actual.getTarget().asStringValue()); - assertEquals(expected.getTargetSystem().asStringValue(), actual.getTargetSystem().asStringValue()); + assertEquals(expected.getConceptMapVersion(), actual.getConceptMapVersion()); + assertEquals(expected.getUrl(), actual.getUrl()); + assertEquals(expected.getSource(), actual.getSource()); + assertEquals(expected.getTarget(), actual.getTarget()); + assertEquals(expected.getTargetSystem(), actual.getTargetSystem()); assertEquals(expected.getResourceId(), actual.getResourceId()); assertEquals(expected.getReverseAsBoolean(), actual.getReverseAsBoolean()); } diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcDeltaR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcDeltaR4Test.java index 7b49b958a58..4d0f07d4d90 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcDeltaR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcDeltaR4Test.java @@ -492,8 +492,8 @@ public class TerminologySvcDeltaR4Test extends BaseJpaR4Test { Parameters output = (Parameters) result.toParameters(myFhirContext, null); ourLog.info(myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(output)); - assertEquals("Description of my life", ((StringType) output.getParameter("name")).getValue()); - assertEquals("1.2.3", ((StringType) output.getParameter("version")).getValue()); + assertEquals("Description of my life", ((StringType) output.getParameterValue("name")).getValue()); + assertEquals("1.2.3", ((StringType) output.getParameterValue("version")).getValue()); assertEquals(false, output.getParameterBool("abstract")); List designations = output.getParameter().stream().filter(t -> t.getName().equals("designation")).collect(Collectors.toList()); diff --git a/hapi-fhir-storage-batch2-jobs/src/test/java/ca/uhn/fhir/batch2/jobs/reindex/ReindexProviderTest.java b/hapi-fhir-storage-batch2-jobs/src/test/java/ca/uhn/fhir/batch2/jobs/reindex/ReindexProviderTest.java index 79f1d8dc04f..777ea2f70c9 100644 --- a/hapi-fhir-storage-batch2-jobs/src/test/java/ca/uhn/fhir/batch2/jobs/reindex/ReindexProviderTest.java +++ b/hapi-fhir-storage-batch2-jobs/src/test/java/ca/uhn/fhir/batch2/jobs/reindex/ReindexProviderTest.java @@ -112,7 +112,7 @@ public class ReindexProviderTest { // Verify ourLog.info(myCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(response)); - StringType jobId = (StringType) response.getParameter(ProviderConstants.OPERATION_REINDEX_RESPONSE_JOB_ID); + StringType jobId = (StringType) response.getParameterValue(ProviderConstants.OPERATION_REINDEX_RESPONSE_JOB_ID); assertEquals(TEST_JOB_ID, jobId.getValue()); verify(myJobCoordinator, times(1)).startInstance(myStartRequestCaptor.capture()); @@ -144,7 +144,7 @@ public class ReindexProviderTest { // Verify ourLog.info(myCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(response)); - StringType jobId = (StringType) response.getParameter(ProviderConstants.OPERATION_REINDEX_RESPONSE_JOB_ID); + StringType jobId = (StringType) response.getParameterValue(ProviderConstants.OPERATION_REINDEX_RESPONSE_JOB_ID); assertEquals(TEST_JOB_ID, jobId.getValue()); verify(myJobCoordinator, times(1)).startInstance(myStartRequestCaptor.capture()); diff --git a/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/api/model/TranslationQuery.java b/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/api/model/TranslationQuery.java index feebcfac1c2..10ed21d2dde 100644 --- a/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/api/model/TranslationQuery.java +++ b/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/api/model/TranslationQuery.java @@ -22,18 +22,19 @@ package ca.uhn.fhir.jpa.api.model; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.Coding; -import org.hl7.fhir.r4.model.StringType; -import org.hl7.fhir.r4.model.UriType; + +import static org.apache.commons.lang3.StringUtils.isNotBlank; public class TranslationQuery { private Coding myCoding; - private Long myResourceId; - private UriType myUrl; - private StringType myConceptMapVersion; - private UriType mySource; - private UriType myTarget; - private UriType myTargetSystem; + private IIdType myResourceId; + private String myUrl; + private String myConceptMapVersion; + private String mySource; + private String myTarget; + private String myTargetSystem; public TranslationQuery() { super(); @@ -53,71 +54,71 @@ public class TranslationQuery { return myResourceId != null; } - public Long getResourceId() { + public IIdType getResourceId() { return myResourceId; } - public void setResourceId(Long theResourceId) { + public void setResourceId(IIdType theResourceId) { myResourceId = theResourceId; } public boolean hasUrl() { - return myUrl != null && myUrl.hasValue(); + return isNotBlank(myUrl); } - public UriType getUrl() { + public String getUrl() { return myUrl; } - public void setUrl(UriType theUrl) { + public void setUrl(String theUrl) { myUrl = theUrl; } public boolean hasConceptMapVersion() { - return myConceptMapVersion != null && myConceptMapVersion.hasValue(); + return isNotBlank(myConceptMapVersion); } - public StringType getConceptMapVersion() { + public String getConceptMapVersion() { return myConceptMapVersion; } - public void setConceptMapVersion(StringType theConceptMapVersion) { + public void setConceptMapVersion(String theConceptMapVersion) { myConceptMapVersion = theConceptMapVersion; } public boolean hasSource() { - return mySource != null && mySource.hasValue(); + return isNotBlank(mySource); } - public UriType getSource() { + public String getSource() { return mySource; } - public void setSource(UriType theSource) { + public void setSource(String theSource) { mySource = theSource; } public boolean hasTarget() { - return myTarget != null && myTarget.hasValue(); + return isNotBlank(myTarget); } - public UriType getTarget() { + public String getTarget() { return myTarget; } - public void setTarget(UriType theTarget) { + public void setTarget(String theTarget) { myTarget = theTarget; } public boolean hasTargetSystem() { - return myTargetSystem != null && myTargetSystem.hasValue(); + return isNotBlank(myTargetSystem); } - public UriType getTargetSystem() { + public String getTargetSystem() { return myTargetSystem; } - public void setTargetSystem(UriType theTargetSystem) { + public void setTargetSystem(String theTargetSystem) { myTargetSystem = theTargetSystem; } diff --git a/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/api/model/TranslationRequest.java b/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/api/model/TranslationRequest.java index d89b882e40a..849f4ad4ff5 100644 --- a/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/api/model/TranslationRequest.java +++ b/hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/api/model/TranslationRequest.java @@ -23,25 +23,25 @@ package ca.uhn.fhir.jpa.api.model; import ca.uhn.fhir.context.support.IValidationSupport; import org.apache.commons.lang3.Validate; import org.hl7.fhir.instance.model.api.IBaseCoding; -import org.hl7.fhir.r4.model.BooleanType; +import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.CodeableConcept; import org.hl7.fhir.r4.model.Coding; -import org.hl7.fhir.r4.model.StringType; -import org.hl7.fhir.r4.model.UriType; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import static org.apache.commons.lang3.StringUtils.isNotBlank; + public class TranslationRequest { private CodeableConcept myCodeableConcept; - private Long myResourceId; - private BooleanType myReverse; - private UriType myUrl; - private StringType myConceptMapVersion; - private UriType mySource; - private UriType myTarget; - private UriType myTargetSystem; + private IIdType myResourceId; + private Boolean myReverse; + private String myUrl; + private String myConceptMapVersion; + private String mySource; + private String myTarget; + private String myTargetSystem; public TranslationRequest() { super(); @@ -72,75 +72,71 @@ public class TranslationRequest { return this; } - public Long getResourceId() { + public IIdType getResourceId() { return myResourceId; } - public void setResourceId(Long theResourceId) { + public void setResourceId(IIdType theResourceId) { myResourceId = theResourceId; } - public BooleanType getReverse() { + public Boolean getReverse() { return myReverse; } - public void setReverse(BooleanType theReverse) { + public void setReverse(Boolean theReverse) { myReverse = theReverse; } - public void setReverse(boolean theReverse) { - myReverse = new BooleanType(theReverse); - } - public boolean getReverseAsBoolean() { if (hasReverse()) { - return myReverse.booleanValue(); + return myReverse; } return false; } - public UriType getUrl() { + public String getUrl() { return myUrl; } - public TranslationRequest setUrl(UriType theUrl) { + public TranslationRequest setUrl(String theUrl) { myUrl = theUrl; return this; } - public StringType getConceptMapVersion() { + public String getConceptMapVersion() { return myConceptMapVersion; } - public TranslationRequest setConceptMapVersion(StringType theConceptMapVersion) { + public TranslationRequest setConceptMapVersion(String theConceptMapVersion) { myConceptMapVersion = theConceptMapVersion; return this; } - public UriType getSource() { + public String getSource() { return mySource; } - public TranslationRequest setSource(UriType theSource) { + public TranslationRequest setSource(String theSource) { mySource = theSource; return this; } - public UriType getTarget() { + public String getTarget() { return myTarget; } - public TranslationRequest setTarget(UriType theTarget) { + public TranslationRequest setTarget(String theTarget) { myTarget = theTarget; return this; } - public UriType getTargetSystem() { + public String getTargetSystem() { return myTargetSystem; } - public TranslationRequest setTargetSystem(UriType theTargetSystem) { + public TranslationRequest setTargetSystem(String theTargetSystem) { myTargetSystem = theTargetSystem; return this; } @@ -193,33 +189,33 @@ public class TranslationRequest { } public boolean hasUrl() { - return myUrl != null && myUrl.hasValue(); + return isNotBlank(myUrl); } public boolean hasConceptMapVersion() { - return myConceptMapVersion != null && myConceptMapVersion.hasValue(); + return isNotBlank(myConceptMapVersion); } public boolean hasSource() { - return mySource != null && mySource.hasValue(); + return isNotBlank(mySource); } public boolean hasTarget() { - return myTarget != null && myTarget.hasValue(); + return isNotBlank(myTarget); } public boolean hasTargetSystem() { - return myTargetSystem != null && myTargetSystem.hasValue(); + return isNotBlank(myTargetSystem); } public IValidationSupport.TranslateCodeRequest asTranslateCodeRequest() { return new IValidationSupport.TranslateCodeRequest( Collections.unmodifiableList(this.getCodeableConcept().getCoding()), - this.getTargetSystem() != null ? this.getTargetSystem().asStringValue() : null, - this.getUrl() != null ? this.getUrl().asStringValue() : null, - this.getConceptMapVersion() != null ? this.getConceptMapVersion().asStringValue() : null, - this.getSource() != null ? this.getSource().asStringValue() : null, - this.getTarget() != null ? this.getTarget().asStringValue() : null, + this.getTargetSystem(), + this.getUrl(), + this.getConceptMapVersion(), + this.getSource(), + this.getTarget(), this.getResourceId(), this.getReverseAsBoolean() ); @@ -237,12 +233,12 @@ public class TranslationRequest { TranslationRequest translationRequest = new TranslationRequest(); translationRequest.setCodeableConcept(sourceCodeableConcept); - translationRequest.setConceptMapVersion(new StringType(theRequest.getConceptMapVersion())); - translationRequest.setUrl(new UriType(theRequest.getConceptMapUrl())); - translationRequest.setSource(new UriType(theRequest.getSourceValueSetUrl())); - translationRequest.setTarget(new UriType(theRequest.getTargetValueSetUrl())); - translationRequest.setTargetSystem(new UriType(theRequest.getTargetSystemUrl())); - translationRequest.setResourceId(theRequest.getResourcePid()); + translationRequest.setConceptMapVersion(theRequest.getConceptMapVersion()); + translationRequest.setUrl(theRequest.getConceptMapUrl()); + translationRequest.setSource(theRequest.getSourceValueSetUrl()); + translationRequest.setTarget(theRequest.getTargetValueSetUrl()); + translationRequest.setTargetSystem(theRequest.getTargetSystemUrl()); + translationRequest.setResourceId(theRequest.getResourceId()); translationRequest.setReverse(theRequest.isReverse()); return translationRequest; diff --git a/hapi-fhir-structures-r4/src/main/java/org/hl7/fhir/r4/hapi/rest/server/helper/BatchHelperR4.java b/hapi-fhir-structures-r4/src/main/java/org/hl7/fhir/r4/hapi/rest/server/helper/BatchHelperR4.java index 7e331bf4eaa..53dc8bf9893 100644 --- a/hapi-fhir-structures-r4/src/main/java/org/hl7/fhir/r4/hapi/rest/server/helper/BatchHelperR4.java +++ b/hapi-fhir-structures-r4/src/main/java/org/hl7/fhir/r4/hapi/rest/server/helper/BatchHelperR4.java @@ -11,13 +11,13 @@ public class BatchHelperR4 { @Nonnull public static Long jobIdFromParameters(Parameters response) { - DecimalType jobIdDecimal = (DecimalType) response.getParameter(ProviderConstants.OPERATION_BATCH_RESPONSE_JOB_ID); + DecimalType jobIdDecimal = (DecimalType) response.getParameterValue(ProviderConstants.OPERATION_BATCH_RESPONSE_JOB_ID); return jobIdDecimal.getValue().longValue(); } @Nonnull public static String jobIdFromBatch2Parameters(Parameters response) { - StringType jobIdString = (StringType) response.getParameter(ProviderConstants.OPERATION_BATCH_RESPONSE_JOB_ID); + StringType jobIdString = (StringType) response.getParameterValue(ProviderConstants.OPERATION_BATCH_RESPONSE_JOB_ID); return jobIdString.getValue(); } } diff --git a/hapi-fhir-structures-r5/src/main/java/org/hl7/fhir/r5/hapi/ctx/HapiWorkerContext.java b/hapi-fhir-structures-r5/src/main/java/org/hl7/fhir/r5/hapi/ctx/HapiWorkerContext.java index 550495e8519..9007b6d528d 100644 --- a/hapi-fhir-structures-r5/src/main/java/org/hl7/fhir/r5/hapi/ctx/HapiWorkerContext.java +++ b/hapi-fhir-structures-r5/src/main/java/org/hl7/fhir/r5/hapi/ctx/HapiWorkerContext.java @@ -15,6 +15,7 @@ import org.fhir.ucum.UcumService; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.TerminologyServiceException; import org.hl7.fhir.r5.context.IWorkerContext; +import org.hl7.fhir.r5.context.IWorkerContextManager; import org.hl7.fhir.r5.formats.IParser; import org.hl7.fhir.r5.formats.ParserType; import org.hl7.fhir.r5.model.CanonicalResource; @@ -73,16 +74,6 @@ public final class HapiWorkerContext extends I18nBase implements IWorkerContext setValidationMessageLanguage(getLocale()); } - @Override - public List allStructures() { - return myValidationSupport.fetchAllStructureDefinitions(); - } - - @Override - public List getStructures() { - return allStructures(); - } - @Override public CodeSystem fetchCodeSystem(String theSystem) { if (myValidationSupport == null) { @@ -101,25 +92,6 @@ public final class HapiWorkerContext extends I18nBase implements IWorkerContext } } - @Override - public List findMapsForSource(String theUrl) { - throw new UnsupportedOperationException(Msg.code(201)); - } - - @Override - public String getAbbreviation(String theName) { - throw new UnsupportedOperationException(Msg.code(202)); - } - - @Override - public IParser getParser(ParserType theType) { - throw new UnsupportedOperationException(Msg.code(203)); - } - - @Override - public IParser getParser(String theType) { - throw new UnsupportedOperationException(Msg.code(204)); - } @Override public List getResourceNames() { @@ -131,26 +103,12 @@ public final class HapiWorkerContext extends I18nBase implements IWorkerContext return result; } - @Override - public IParser newJsonParser() { - throw new UnsupportedOperationException(Msg.code(205)); - } @Override public IResourceValidator newValidator() { throw new UnsupportedOperationException(Msg.code(206)); } - @Override - public IParser newXmlParser() { - throw new UnsupportedOperationException(Msg.code(207)); - } - - @Override - public String oid2Uri(String theCode) { - throw new UnsupportedOperationException(Msg.code(208)); - } - @Override public Map getNSUrlMap() { throw new UnsupportedOperationException(Msg.code(2107)); @@ -245,21 +203,6 @@ public final class HapiWorkerContext extends I18nBase implements IWorkerContext return validateCode(theOptions, null, null, code, null, vs); } - @Override - @CoverageIgnore - public List allConformanceResources() { - throw new UnsupportedOperationException(Msg.code(210)); - } - - @Override - public void generateSnapshot(StructureDefinition p) throws FHIRException { - myValidationSupport.generateSnapshot(new ValidationSupportContext(myValidationSupport), p, "", "", ""); - } - - @Override - public void generateSnapshot(StructureDefinition mr, boolean ifLogical) { - - } @Override public Parameters getExpansionParameters() { @@ -271,12 +214,6 @@ public final class HapiWorkerContext extends I18nBase implements IWorkerContext myExpansionProfile = theExpParameters; } - @Override - @CoverageIgnore - public boolean hasCache() { - throw new UnsupportedOperationException(Msg.code(211)); - } - @Override public ValueSetExpander.ValueSetExpansionOutcome expandVS(ValueSet theSource, boolean theCacheOk, boolean theHierarchical) { throw new UnsupportedOperationException(Msg.code(2128)); @@ -316,10 +253,6 @@ public final class HapiWorkerContext extends I18nBase implements IWorkerContext return myCtx.getVersion().getVersion().getFhirVersionString(); } - @Override - public String getSpecUrl() { - throw new UnsupportedOperationException(Msg.code(215)); - } @Override public UcumService getUcumService() { @@ -346,40 +279,13 @@ public final class HapiWorkerContext extends I18nBase implements IWorkerContext throw new UnsupportedOperationException(Msg.code(219)); } - @Override - public List listTransforms() { - throw new UnsupportedOperationException(Msg.code(220)); - } - @Override - public StructureMap getTransform(String url) { - throw new UnsupportedOperationException(Msg.code(221)); - } - - @Override - public String getOverrideVersionNs() { - return myOverrideVersionNs; - } - - @Override - public void setOverrideVersionNs(String value) { - myOverrideVersionNs = value; - } @Override public StructureDefinition fetchTypeDefinition(String typeName) { return fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/" + typeName); } - @Override - public StructureDefinition fetchRawProfile(String url) { - throw new UnsupportedOperationException(Msg.code(222)); - } - - @Override - public List getTypeNames() { - throw new UnsupportedOperationException(Msg.code(223)); - } @Override public T fetchResource(Class theClass, String theUri) { @@ -441,10 +347,6 @@ public final class HapiWorkerContext extends I18nBase implements IWorkerContext return myCtx.getResourceTypes(); } - @Override - public List getCanonicalResourceNames() { - throw new UnsupportedOperationException(Msg.code(2113)); - } @Override public ValueSetExpander.ValueSetExpansionOutcome expandVS(ElementDefinitionBindingComponent theBinding, boolean theCacheOk, boolean theHierarchical) throws FHIRException { @@ -452,10 +354,6 @@ public final class HapiWorkerContext extends I18nBase implements IWorkerContext } - @Override - public String getLinkForUrl(String corePath, String url) { - throw new UnsupportedOperationException(Msg.code(231)); - } @Override public Set getBinaryKeysAsSet() { @@ -518,16 +416,10 @@ public final class HapiWorkerContext extends I18nBase implements IWorkerContext } @Override - public IPackageLoadingTracker getPackageTracker() { + public IWorkerContextManager.IPackageLoadingTracker getPackageTracker() { throw new UnsupportedOperationException(Msg.code(2112)); } - @Override - public IWorkerContext setPackageTracker( - IPackageLoadingTracker packageTracker) { - return null; - } - @Override public PackageVersion getPackageForUrl(String s) { return null; @@ -541,4 +433,18 @@ public final class HapiWorkerContext extends I18nBase implements IWorkerContext return retVal; } + + @Override + public List fetchResourcesByType(Class theClass) { + if (theClass.equals(StructureDefinition.class)) { + return myValidationSupport.fetchAllStructureDefinitions(); + } + + throw new UnsupportedOperationException(Msg.code(2113) + "Can't fetch all resources of type: " + theClass); + } + + @Override + public IWorkerContext setPackageTracker(IWorkerContextManager.IPackageLoadingTracker theIPackageLoadingTracker) { + throw new UnsupportedOperationException(Msg.code(220)); + } } diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/support/CommonCodeSystemsTerminologyService.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/support/CommonCodeSystemsTerminologyService.java index 6be07f49de7..13dda26c5ce 100644 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/support/CommonCodeSystemsTerminologyService.java +++ b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/support/CommonCodeSystemsTerminologyService.java @@ -1,12 +1,13 @@ package org.hl7.fhir.common.hapi.validation.support; -import ca.uhn.fhir.i18n.Msg; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.support.ConceptValidationOptions; import ca.uhn.fhir.context.support.IValidationSupport; import ca.uhn.fhir.context.support.ValidationSupportContext; +import ca.uhn.fhir.i18n.Msg; import ca.uhn.fhir.util.ClasspathUtil; +import ca.uhn.hapi.converters.canonical.VersionCanonicalizer; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; @@ -15,7 +16,6 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; import org.fhir.ucum.UcumEssenceService; import org.fhir.ucum.UcumException; -import org.hl7.fhir.common.hapi.validation.validator.VersionSpecificWorkerContextWrapper; import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_40; import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_40_50; import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_40; @@ -37,7 +37,6 @@ import java.util.Optional; import static org.apache.commons.lang3.StringUtils.defaultString; import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank; -import static org.hl7.fhir.common.hapi.validation.support.SnapshotGeneratingValidationSupport.newVersionTypeConverter; /** * This {@link IValidationSupport validation support module} can be used to validate codes against common @@ -62,11 +61,11 @@ public class CommonCodeSystemsTerminologyService implements IValidationSupport { private static final String USPS_CODESYSTEM_URL = "https://www.usps.com/"; private static final String USPS_VALUESET_URL = "http://hl7.org/fhir/us/core/ValueSet/us-core-usps-state"; private static final Logger ourLog = LoggerFactory.getLogger(CommonCodeSystemsTerminologyService.class); - private static Map USPS_CODES = Collections.unmodifiableMap(buildUspsCodes()); - private static Map ISO_4217_CODES = Collections.unmodifiableMap(buildIso4217Codes()); - private static Map ISO_3166_CODES = Collections.unmodifiableMap(buildIso3166Codes()); + private static final Map USPS_CODES = Collections.unmodifiableMap(buildUspsCodes()); + private static final Map ISO_4217_CODES = Collections.unmodifiableMap(buildIso4217Codes()); + private static final Map ISO_3166_CODES = Collections.unmodifiableMap(buildIso3166Codes()); private final FhirContext myFhirContext; - private final VersionSpecificWorkerContextWrapper.IVersionTypeConverter myVersionConverter; + private final VersionCanonicalizer myVersionCanonicalizer; private volatile org.hl7.fhir.r5.model.ValueSet myLanguagesVs; private volatile Map myLanguagesLanugageMap; private volatile Map myLanguagesRegionMap; @@ -78,7 +77,7 @@ public class CommonCodeSystemsTerminologyService implements IValidationSupport { Validate.notNull(theFhirContext); myFhirContext = theFhirContext; - myVersionConverter = newVersionTypeConverter(myFhirContext.getVersion().getVersion()); + myVersionCanonicalizer = new VersionCanonicalizer(theFhirContext); } @Override @@ -117,7 +116,7 @@ public class CommonCodeSystemsTerminologyService implements IValidationSupport { IBaseResource languagesVs = myLanguagesVs; if (languagesVs == null) { languagesVs = theValidationSupportContext.getRootValidationSupport().fetchValueSet("http://hl7.org/fhir/ValueSet/languages"); - myLanguagesVs = (org.hl7.fhir.r5.model.ValueSet) myVersionConverter.toCanonical(languagesVs); + myLanguagesVs = myVersionCanonicalizer.valueSetToValidatorCanonical(languagesVs); } Optional match = myLanguagesVs .getCompose() @@ -288,12 +287,14 @@ public class CommonCodeSystemsTerminologyService implements IValidationSupport { } } } + private LookupCodeResult buildLookupResultForLanguageAndRegion(@Nonnull String theOriginalCode, @Nonnull String theLanguage, @Nonnull String theRegion) { LookupCodeResult lookupCodeResult = buildNotFoundLookupCodeResult(theOriginalCode); lookupCodeResult.setCodeDisplay(theLanguage + " " + theRegion); lookupCodeResult.setFound(true); return lookupCodeResult; } + private LookupCodeResult buildLookupResultForLanguage(@Nonnull String theOriginalCode, @Nonnull String theLanguage) { LookupCodeResult lookupCodeResult = buildNotFoundLookupCodeResult(theOriginalCode); lookupCodeResult.setCodeDisplay(theLanguage); diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/support/SnapshotGeneratingValidationSupport.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/support/SnapshotGeneratingValidationSupport.java index e0456c5f7c2..43a64bb39a6 100644 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/support/SnapshotGeneratingValidationSupport.java +++ b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/support/SnapshotGeneratingValidationSupport.java @@ -1,18 +1,17 @@ package org.hl7.fhir.common.hapi.validation.support; -import ca.uhn.fhir.i18n.Msg; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.support.IValidationSupport; import ca.uhn.fhir.context.support.ValidationSupportContext; +import ca.uhn.fhir.i18n.Msg; import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; +import ca.uhn.hapi.converters.canonical.VersionCanonicalizer; import org.apache.commons.lang3.Validate; import org.hl7.fhir.common.hapi.validation.validator.ProfileKnowledgeWorkerR5; import org.hl7.fhir.common.hapi.validation.validator.VersionSpecificWorkerContextWrapper; -import org.hl7.fhir.common.hapi.validation.validator.VersionTypeConverterDstu3; -import org.hl7.fhir.common.hapi.validation.validator.VersionTypeConverterR4; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r5.conformance.ProfileUtilities; import org.hl7.fhir.r5.context.IWorkerContext; @@ -20,7 +19,6 @@ import org.hl7.fhir.utilities.validation.ValidationMessage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.Nullable; import java.util.ArrayList; import static org.apache.commons.lang3.StringUtils.isBlank; @@ -38,6 +36,7 @@ import static org.apache.commons.lang3.StringUtils.isBlank; public class SnapshotGeneratingValidationSupport implements IValidationSupport { private static final Logger ourLog = LoggerFactory.getLogger(SnapshotGeneratingValidationSupport.class); private final FhirContext myCtx; + private final VersionCanonicalizer myVersionCanonicalizer; /** * Constructor @@ -45,8 +44,10 @@ public class SnapshotGeneratingValidationSupport implements IValidationSupport { public SnapshotGeneratingValidationSupport(FhirContext theCtx) { Validate.notNull(theCtx); myCtx = theCtx; + myVersionCanonicalizer = new VersionCanonicalizer(theCtx); } + @SuppressWarnings("EnumSwitchStatementWhichMissesCases") @Override public IBaseResource generateSnapshot(ValidationSupportContext theValidationSupportContext, IBaseResource theInput, String theUrl, String theWebUrl, String theProfileName) { @@ -55,10 +56,7 @@ public class SnapshotGeneratingValidationSupport implements IValidationSupport { FhirVersionEnum version = theInput.getStructureFhirVersionEnum(); assert version == myCtx.getVersion().getVersion(); - VersionSpecificWorkerContextWrapper.IVersionTypeConverter converter = newVersionTypeConverter(version); - Validate.notNull(converter, "Can not generate snapshot for version: %s", version); - - org.hl7.fhir.r5.model.StructureDefinition inputCanonical = (org.hl7.fhir.r5.model.StructureDefinition) converter.toCanonical(theInput); + org.hl7.fhir.r5.model.StructureDefinition inputCanonical = myVersionCanonicalizer.structureDefinitionToCanonical(theInput); inputUrl = inputCanonical.getUrl(); if (theValidationSupportContext.getCurrentlyGeneratingSnapshots().contains(inputUrl)) { @@ -77,33 +75,33 @@ public class SnapshotGeneratingValidationSupport implements IValidationSupport { throw new PreconditionFailedException(Msg.code(705) + "Unknown base definition: " + baseDefinition); } - org.hl7.fhir.r5.model.StructureDefinition baseCanonical = (org.hl7.fhir.r5.model.StructureDefinition) converter.toCanonical(base); + org.hl7.fhir.r5.model.StructureDefinition baseCanonical = myVersionCanonicalizer.structureDefinitionToCanonical(base); if (baseCanonical.getSnapshot().getElement().isEmpty()) { // If the base definition also doesn't have a snapshot, generate that first theValidationSupportContext.getRootValidationSupport().generateSnapshot(theValidationSupportContext, base, null, null, null); - baseCanonical = (org.hl7.fhir.r5.model.StructureDefinition) converter.toCanonical(base); + baseCanonical = myVersionCanonicalizer.structureDefinitionToCanonical(base); } ArrayList messages = new ArrayList<>(); org.hl7.fhir.r5.conformance.ProfileUtilities.ProfileKnowledgeProvider profileKnowledgeProvider = new ProfileKnowledgeWorkerR5(myCtx); - IWorkerContext context = new VersionSpecificWorkerContextWrapper(theValidationSupportContext, converter); + IWorkerContext context = new VersionSpecificWorkerContextWrapper(theValidationSupportContext, myVersionCanonicalizer); ProfileUtilities profileUtilities = new ProfileUtilities(context, messages, profileKnowledgeProvider); profileUtilities.generateSnapshot(baseCanonical, inputCanonical, theUrl, theWebUrl, theProfileName); switch (version) { case DSTU3: - org.hl7.fhir.dstu3.model.StructureDefinition generatedDstu3 = (org.hl7.fhir.dstu3.model.StructureDefinition) converter.fromCanonical(inputCanonical); + org.hl7.fhir.dstu3.model.StructureDefinition generatedDstu3 = (org.hl7.fhir.dstu3.model.StructureDefinition) myVersionCanonicalizer.structureDefinitionFromCanonical(inputCanonical); ((org.hl7.fhir.dstu3.model.StructureDefinition) theInput).getSnapshot().getElement().clear(); ((org.hl7.fhir.dstu3.model.StructureDefinition) theInput).getSnapshot().getElement().addAll(generatedDstu3.getSnapshot().getElement()); break; case R4: - org.hl7.fhir.r4.model.StructureDefinition generatedR4 = (org.hl7.fhir.r4.model.StructureDefinition) converter.fromCanonical(inputCanonical); + org.hl7.fhir.r4.model.StructureDefinition generatedR4 = (org.hl7.fhir.r4.model.StructureDefinition) myVersionCanonicalizer.structureDefinitionFromCanonical(inputCanonical); ((org.hl7.fhir.r4.model.StructureDefinition) theInput).getSnapshot().getElement().clear(); ((org.hl7.fhir.r4.model.StructureDefinition) theInput).getSnapshot().getElement().addAll(generatedR4.getSnapshot().getElement()); break; case R5: - org.hl7.fhir.r5.model.StructureDefinition generatedR5 = (org.hl7.fhir.r5.model.StructureDefinition) converter.fromCanonical(inputCanonical); + org.hl7.fhir.r5.model.StructureDefinition generatedR5 = (org.hl7.fhir.r5.model.StructureDefinition) myVersionCanonicalizer.structureDefinitionFromCanonical(inputCanonical); ((org.hl7.fhir.r5.model.StructureDefinition) theInput).getSnapshot().getElement().clear(); ((org.hl7.fhir.r5.model.StructureDefinition) theInput).getSnapshot().getElement().addAll(generatedR5.getSnapshot().getElement()); break; @@ -132,27 +130,4 @@ public class SnapshotGeneratingValidationSupport implements IValidationSupport { return myCtx; } - @Nullable - public static VersionSpecificWorkerContextWrapper.IVersionTypeConverter newVersionTypeConverter(FhirVersionEnum version) { - VersionSpecificWorkerContextWrapper.IVersionTypeConverter converter; - switch (version) { - case DSTU3: - converter = new VersionTypeConverterDstu3(); - break; - case R4: - converter = new VersionTypeConverterR4(); - break; - case R5: - converter = VersionSpecificWorkerContextWrapper.IDENTITY_VERSION_TYPE_CONVERTER; - break; - case DSTU2: - case DSTU2_HL7ORG: - case DSTU2_1: - default: - return null; - } - return converter; - } - - } diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/ProfileKnowledgeWorkerR5.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/ProfileKnowledgeWorkerR5.java index f5d1317f77c..dd674785c37 100644 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/ProfileKnowledgeWorkerR5.java +++ b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/ProfileKnowledgeWorkerR5.java @@ -25,7 +25,14 @@ public class ProfileKnowledgeWorkerR5 implements org.hl7.fhir.r5.conformance.Pro return (def instanceof RuntimePrimitiveDatatypeDefinition) || (def instanceof RuntimeCompositeDatatypeDefinition); } - @Override + @Override + public boolean isPrimitiveType(String typeSimple) { + BaseRuntimeElementDefinition def = myCtx.getElementDefinition(typeSimple); + Validate.notNull(typeSimple); + return (def instanceof RuntimePrimitiveDatatypeDefinition); + } + + @Override public boolean isResource(String typeSimple) { BaseRuntimeElementDefinition def = myCtx.getElementDefinition(typeSimple); Validate.notNull(typeSimple); diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/ValidatorWrapper.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/ValidatorWrapper.java index cfc21d20aee..29d28d372e1 100644 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/ValidatorWrapper.java +++ b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/ValidatorWrapper.java @@ -10,7 +10,6 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import org.apache.commons.codec.Charsets; import org.apache.commons.io.input.ReaderInputStream; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.r5.context.IWorkerContext; @@ -32,6 +31,7 @@ import org.w3c.dom.NodeList; import java.io.InputStream; import java.io.StringReader; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -137,9 +137,9 @@ class ValidatorWrapper { List messages = new ArrayList<>(); - List profileUrls = new ArrayList<>(); - for (String next : theValidationContext.getOptions().getProfiles()) { - fetchAndAddProfile(theWorkerContext, profileUrls, next); + List profiles = new ArrayList<>(); + for (String nextProfileUrl : theValidationContext.getOptions().getProfiles()) { + fetchAndAddProfile(theWorkerContext, profiles, nextProfileUrl, messages); } String input = theValidationContext.getResourceAsString(); @@ -158,16 +158,16 @@ class ValidatorWrapper { } // Determine if meta/profiles are present... - ArrayList profiles = determineIfProfilesSpecified(document); - for (String nextProfile : profiles) { - fetchAndAddProfile(theWorkerContext, profileUrls, nextProfile); + ArrayList profileUrls = determineIfProfilesSpecified(document); + for (String nextProfileUrl : profileUrls) { + fetchAndAddProfile(theWorkerContext, profiles, nextProfileUrl, messages); } String resourceAsString = theValidationContext.getResourceAsString(); - InputStream inputStream = new ReaderInputStream(new StringReader(resourceAsString), Charsets.UTF_8); + InputStream inputStream = new ReaderInputStream(new StringReader(resourceAsString), StandardCharsets.UTF_8); Manager.FhirFormat format = Manager.FhirFormat.XML; - v.validate(null, messages, inputStream, format, profileUrls); + v.validate(null, messages, inputStream, format, profiles); } else if (encoding == EncodingEnum.JSON) { @@ -178,19 +178,19 @@ class ValidatorWrapper { if (meta != null) { JsonElement profileElement = meta.get("profile"); if (profileElement != null && profileElement.isJsonArray()) { - JsonArray profiles = profileElement.getAsJsonArray(); - for (JsonElement element : profiles) { - String nextProfile = element.getAsString(); - fetchAndAddProfile(theWorkerContext, profileUrls, nextProfile); + JsonArray profilesArray = profileElement.getAsJsonArray(); + for (JsonElement element : profilesArray) { + String nextProfileUrl = element.getAsString(); + fetchAndAddProfile(theWorkerContext, profiles, nextProfileUrl, messages); } } } String resourceAsString = theValidationContext.getResourceAsString(); - InputStream inputStream = new ReaderInputStream(new StringReader(resourceAsString), Charsets.UTF_8); + InputStream inputStream = new ReaderInputStream(new StringReader(resourceAsString), StandardCharsets.UTF_8); Manager.FhirFormat format = Manager.FhirFormat.JSON; - v.validate(null, messages, inputStream, format, profileUrls); + v.validate(null, messages, inputStream, format, profiles); } else { throw new IllegalArgumentException(Msg.code(649) + "Unknown encoding: " + encoding); @@ -211,13 +211,12 @@ class ValidatorWrapper { return messages; } - private void fetchAndAddProfile(IWorkerContext theWorkerContext, List theProfileStructureDefinitions, String theUrl) throws org.hl7.fhir.exceptions.FHIRException { + private void fetchAndAddProfile(IWorkerContext theWorkerContext, List theProfileStructureDefinitions, String theUrl, List theMessages) { try { - - // NOTE: We expect the following call to generate a snapshot if needed - StructureDefinition structureDefinition = theWorkerContext.fetchRawProfile(theUrl); - - theProfileStructureDefinitions.add(structureDefinition); + StructureDefinition structureDefinition = theWorkerContext.fetchResource(StructureDefinition.class, theUrl); + if (structureDefinition != null) { + theProfileStructureDefinitions.add(structureDefinition); + } } catch (FHIRException e) { ourLog.debug("Failed to load profile: {}", theUrl); } diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionSpecificWorkerContextWrapper.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionSpecificWorkerContextWrapper.java index 8afb0065b4f..596b5367a7b 100644 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionSpecificWorkerContextWrapper.java +++ b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionSpecificWorkerContextWrapper.java @@ -1,28 +1,24 @@ package org.hl7.fhir.common.hapi.validation.validator; -import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.support.ConceptValidationOptions; import ca.uhn.fhir.context.support.IValidationSupport; import ca.uhn.fhir.context.support.ValidationSupportContext; import ca.uhn.fhir.i18n.Msg; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; -import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.sl.cache.CacheFactory; import ca.uhn.fhir.sl.cache.LoadingCache; import ca.uhn.fhir.system.HapiSystemProperties; +import ca.uhn.hapi.converters.canonical.VersionCanonicalizer; import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.fhir.ucum.UcumService; -import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_50; -import org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_50; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.TerminologyServiceException; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r5.context.IWorkerContext; -import org.hl7.fhir.r5.formats.IParser; -import org.hl7.fhir.r5.formats.ParserType; +import org.hl7.fhir.r5.context.IWorkerContextManager; import org.hl7.fhir.r5.model.CanonicalResource; import org.hl7.fhir.r5.model.CodeSystem; import org.hl7.fhir.r5.model.Coding; @@ -55,67 +51,55 @@ import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank; public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWorkerContext { - public static final IVersionTypeConverter IDENTITY_VERSION_TYPE_CONVERTER = new VersionTypeConverterR5(); private static final Logger ourLog = LoggerFactory.getLogger(VersionSpecificWorkerContextWrapper.class); - private static final FhirContext ourR5Context = FhirContext.forR5(); private final ValidationSupportContext myValidationSupportContext; - private final IVersionTypeConverter myModelConverter; + private final VersionCanonicalizer myVersionCanonicalizer; private final LoadingCache myFetchResourceCache; private volatile List myAllStructures; private org.hl7.fhir.r5.model.Parameters myExpansionProfile; - public VersionSpecificWorkerContextWrapper(ValidationSupportContext theValidationSupportContext, IVersionTypeConverter theModelConverter) { + public VersionSpecificWorkerContextWrapper(ValidationSupportContext theValidationSupportContext, VersionCanonicalizer theVersionCanonicalizer) { myValidationSupportContext = theValidationSupportContext; - myModelConverter = theModelConverter; + myVersionCanonicalizer = theVersionCanonicalizer; long timeoutMillis = HapiSystemProperties.getTestValidationResourceCachesMs(); myFetchResourceCache = CacheFactory.build(timeoutMillis, 10000, key -> { - String fetchResourceName = key.getResourceName(); - if (myValidationSupportContext.getRootValidationSupport().getFhirContext().getVersion().getVersion() == FhirVersionEnum.DSTU2) { - if ("CodeSystem".equals(fetchResourceName)) { - fetchResourceName = "ValueSet"; - } + String fetchResourceName = key.getResourceName(); + if (myValidationSupportContext.getRootValidationSupport().getFhirContext().getVersion().getVersion() == FhirVersionEnum.DSTU2) { + if ("CodeSystem".equals(fetchResourceName)) { + fetchResourceName = "ValueSet"; } + } - Class fetchResourceType; - if (fetchResourceName.equals("Resource")) { - fetchResourceType = null; - } else { - fetchResourceType = myValidationSupportContext.getRootValidationSupport().getFhirContext().getResourceDefinition(fetchResourceName).getImplementingClass(); + Class fetchResourceType; + if (fetchResourceName.equals("Resource")) { + fetchResourceType = null; + } else { + fetchResourceType = myValidationSupportContext.getRootValidationSupport().getFhirContext().getResourceDefinition(fetchResourceName).getImplementingClass(); + } + + IBaseResource fetched = myValidationSupportContext.getRootValidationSupport().fetchResource(fetchResourceType, key.getUri()); + + Resource canonical = myVersionCanonicalizer.resourceToValidatorCanonical(fetched); + + if (canonical instanceof StructureDefinition) { + StructureDefinition canonicalSd = (StructureDefinition) canonical; + if (canonicalSd.getSnapshot().isEmpty()) { + ourLog.info("Generating snapshot for StructureDefinition: {}", canonicalSd.getUrl()); + fetched = myValidationSupportContext.getRootValidationSupport().generateSnapshot(theValidationSupportContext, fetched, "", null, ""); + Validate.isTrue(fetched != null, "StructureDefinition %s has no snapshot, and no snapshot generator is configured", key.getUri()); + canonical = myVersionCanonicalizer.resourceToValidatorCanonical(fetched); } + } - IBaseResource fetched = myValidationSupportContext.getRootValidationSupport().fetchResource(fetchResourceType, key.getUri()); - - Resource canonical = myModelConverter.toCanonical(fetched); - - if (canonical instanceof StructureDefinition) { - StructureDefinition canonicalSd = (StructureDefinition) canonical; - if (canonicalSd.getSnapshot().isEmpty()) { - ourLog.info("Generating snapshot for StructureDefinition: {}", canonicalSd.getUrl()); - fetched = myValidationSupportContext.getRootValidationSupport().generateSnapshot(theValidationSupportContext, fetched, "", null, ""); - Validate.isTrue(fetched != null, "StructureDefinition %s has no snapshot, and no snapshot generator is configured", key.getUri()); - canonical = myModelConverter.toCanonical(fetched); - } - } - - return canonical; - }); + return canonical; + }); setValidationMessageLanguage(getLocale()); } - @Override - public List allConformanceResources() { - throw new UnsupportedOperationException(Msg.code(650)); - } - - @Override - public String getLinkForUrl(String corePath, String url) { - throw new UnsupportedOperationException(Msg.code(651)); - } - @Override public Set getBinaryKeysAsSet() { throw new UnsupportedOperationException(Msg.code(2118)); @@ -177,13 +161,13 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo } @Override - public IPackageLoadingTracker getPackageTracker() { + public IWorkerContextManager.IPackageLoadingTracker getPackageTracker() { throw new UnsupportedOperationException(Msg.code(2108)); } @Override public IWorkerContext setPackageTracker( - IPackageLoadingTracker packageTracker) { + IWorkerContextManager.IPackageLoadingTracker packageTracker) { throw new UnsupportedOperationException(Msg.code(2114)); } @@ -192,27 +176,6 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo throw new UnsupportedOperationException(Msg.code(2109)); } - @Override - public void generateSnapshot(StructureDefinition input) throws FHIRException { - if (input.hasSnapshot()) { - return; - } - - org.hl7.fhir.r5.conformance.ProfileUtilities.ProfileKnowledgeProvider profileKnowledgeProvider = new ProfileKnowledgeWorkerR5(ourR5Context); - ArrayList messages = new ArrayList<>(); - org.hl7.fhir.r5.model.StructureDefinition base = fetchResource(StructureDefinition.class, input.getBaseDefinition()); - if (base == null) { - throw new PreconditionFailedException(Msg.code(658) + "Unknown base definition: " + input.getBaseDefinition()); - } - new org.hl7.fhir.r5.conformance.ProfileUtilities(this, messages, profileKnowledgeProvider).generateSnapshot(base, input, "", null, ""); - - } - - @Override - public void generateSnapshot(StructureDefinition theStructureDefinition, boolean theB) { - // nothing yet - } - @Override public org.hl7.fhir.r5.model.Parameters getExpansionParameters() { return myExpansionProfile; @@ -223,16 +186,15 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo myExpansionProfile = expParameters; } - @Override - public List allStructures() { + private List allStructures() { List retVal = myAllStructures; if (retVal == null) { retVal = new ArrayList<>(); for (IBaseResource next : myValidationSupportContext.getRootValidationSupport().fetchAllStructureDefinitions()) { try { - Resource converted = myModelConverter.toCanonical(next); - retVal.add((StructureDefinition) converted); + StructureDefinition converted = myVersionCanonicalizer.structureDefinitionToCanonical(next); + retVal.add(converted); } catch (FHIRException e) { throw new InternalErrorException(Msg.code(659) + e); } @@ -243,11 +205,6 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo return retVal; } - @Override - public List getStructures() { - return allStructures(); - } - @Override public void cacheResource(Resource res) { @@ -292,7 +249,7 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo public ValueSetExpander.ValueSetExpansionOutcome expandVS(org.hl7.fhir.r5.model.ValueSet source, boolean cacheOk, boolean Hierarchical) { IBaseResource convertedSource; try { - convertedSource = myModelConverter.fromCanonical(source); + convertedSource = myVersionCanonicalizer.valueSetFromValidatorCanonical(source); } catch (FHIRException e) { throw new InternalErrorException(Msg.code(661) + e); } @@ -301,7 +258,7 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo org.hl7.fhir.r5.model.ValueSet convertedResult = null; if (expanded.getValueSet() != null) { try { - convertedResult = (ValueSet) myModelConverter.toCanonical(expanded.getValueSet()); + convertedResult = myVersionCanonicalizer.valueSetToValidatorCanonical(expanded.getValueSet()); } catch (FHIRException e) { throw new InternalErrorException(Msg.code(662) + e); } @@ -340,7 +297,7 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo return null; } try { - return (org.hl7.fhir.r5.model.CodeSystem) myModelConverter.toCanonical(fetched); + return (org.hl7.fhir.r5.model.CodeSystem) myVersionCanonicalizer.codeSystemToValidatorCanonical(fetched); } catch (FHIRException e) { throw new InternalErrorException(Msg.code(665) + e); } @@ -353,7 +310,7 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo return null; } try { - return (org.hl7.fhir.r5.model.CodeSystem) myModelConverter.toCanonical(fetched); + return (org.hl7.fhir.r5.model.CodeSystem) myVersionCanonicalizer.codeSystemToValidatorCanonical(fetched); } catch (FHIRException e) { throw new InternalErrorException(Msg.code(1992) + e); } @@ -397,26 +354,6 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo throw new UnsupportedOperationException(Msg.code(668)); } - @Override - public List findMapsForSource(String url) { - throw new UnsupportedOperationException(Msg.code(669)); - } - - @Override - public String getAbbreviation(String name) { - throw new UnsupportedOperationException(Msg.code(670)); - } - - @Override - public IParser getParser(ParserType type) { - throw new UnsupportedOperationException(Msg.code(671)); - } - - @Override - public IParser getParser(String type) { - throw new UnsupportedOperationException(Msg.code(672)); - } - @Override public List getResourceNames() { return new ArrayList<>(myValidationSupportContext.getRootValidationSupport().getFhirContext().getResourceTypes()); @@ -427,47 +364,11 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo return myValidationSupportContext.getRootValidationSupport().getFhirContext().getResourceTypes(); } - @Override - public List getCanonicalResourceNames() { - throw new UnsupportedOperationException(Msg.code(2110)); - } - - @Override - public org.hl7.fhir.r5.model.StructureMap getTransform(String url) { - throw new UnsupportedOperationException(Msg.code(673)); - } - - @Override - public String getOverrideVersionNs() { - return null; - } - - @Override - public void setOverrideVersionNs(String value) { - throw new UnsupportedOperationException(Msg.code(674)); - } - @Override public StructureDefinition fetchTypeDefinition(String typeName) { return fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/" + typeName); } - @Override - public StructureDefinition fetchRawProfile(String url) { - StructureDefinition retVal = fetchResource(StructureDefinition.class, url); - - if (retVal != null && retVal.getSnapshot().isEmpty()) { - generateSnapshot(retVal); - } - - return retVal; - } - - @Override - public List getTypeNames() { - throw new UnsupportedOperationException(Msg.code(675)); - } - @Override public UcumService getUcumService() { throw new UnsupportedOperationException(Msg.code(676)); @@ -483,16 +384,6 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo return myValidationSupportContext.getRootValidationSupport().getFhirContext().getVersion().getVersion().getFhirVersionString(); } - @Override - public String getSpecUrl() { - throw new UnsupportedOperationException(Msg.code(678)); - } - - @Override - public boolean hasCache() { - throw new UnsupportedOperationException(Msg.code(679)); - } - @Override public boolean hasResource(Class class_, String uri) { throw new UnsupportedOperationException(Msg.code(680)); @@ -508,31 +399,11 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo throw new UnsupportedOperationException(Msg.code(681)); } - @Override - public List listTransforms() { - throw new UnsupportedOperationException(Msg.code(682)); - } - - @Override - public IParser newJsonParser() { - throw new UnsupportedOperationException(Msg.code(683)); - } - @Override public IResourceValidator newValidator() { throw new UnsupportedOperationException(Msg.code(684)); } - @Override - public IParser newXmlParser() { - throw new UnsupportedOperationException(Msg.code(685)); - } - - @Override - public String oid2Uri(String code) { - throw new UnsupportedOperationException(Msg.code(686)); - } - @Override public Map getNSUrlMap() { throw new UnsupportedOperationException(Msg.code(2111)); @@ -575,7 +446,7 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo try { if (theValueSet != null) { - convertedVs = myModelConverter.fromCanonical(theValueSet); + convertedVs = myVersionCanonicalizer.valueSetFromValidatorCanonical(theValueSet); } } catch (FHIRException e) { throw new InternalErrorException(Msg.code(689) + e); @@ -591,7 +462,7 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo IBaseResource convertedVs = null; try { if (theValueSet != null) { - convertedVs = myModelConverter.fromCanonical(theValueSet); + convertedVs = myVersionCanonicalizer.valueSetFromValidatorCanonical(theValueSet); } } catch (FHIRException e) { throw new InternalErrorException(Msg.code(690) + e); @@ -608,7 +479,7 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo try { if (theValueSet != null) { - convertedVs = myModelConverter.fromCanonical(theValueSet); + convertedVs = myVersionCanonicalizer.valueSetFromValidatorCanonical(theValueSet); } } catch (FHIRException e) { throw new InternalErrorException(Msg.code(691) + e); @@ -662,12 +533,12 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo myFetchResourceCache.invalidateAll(); } - public interface IVersionTypeConverter { - - org.hl7.fhir.r5.model.Resource toCanonical(IBaseResource theNonCanonical); - - IBaseResource fromCanonical(org.hl7.fhir.r5.model.Resource theCanonical); - + @Override + public List fetchResourcesByType(Class theClass) { + if (theClass.equals(StructureDefinition.class)) { + return (List) allStructures(); + } + throw new UnsupportedOperationException(Msg.code(650) + "Unable to fetch resources of type: " + theClass); } private static class ResourceKey { @@ -716,18 +587,6 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo } } - private static class VersionTypeConverterR5 implements IVersionTypeConverter { - @Override - public Resource toCanonical(IBaseResource theNonCanonical) { - return (Resource) theNonCanonical; - } - - @Override - public IBaseResource fromCanonical(Resource theCanonical) { - return theCanonical; - } - } - public static ConceptValidationOptions convertConceptValidationOptions(ValidationOptions theOptions) { ConceptValidationOptions retVal = new ConceptValidationOptions(); if (theOptions.isGuessSystem()) { @@ -738,65 +597,8 @@ public class VersionSpecificWorkerContextWrapper extends I18nBase implements IWo @Nonnull public static VersionSpecificWorkerContextWrapper newVersionSpecificWorkerContextWrapper(IValidationSupport theValidationSupport) { - IVersionTypeConverter converter; - - switch (theValidationSupport.getFhirContext().getVersion().getVersion()) { - case DSTU2: - case DSTU2_HL7ORG: { - converter = new IVersionTypeConverter() { - @Override - public Resource toCanonical(IBaseResource theNonCanonical) { - Resource retVal = VersionConvertorFactory_10_50.convertResource((org.hl7.fhir.dstu2.model.Resource) theNonCanonical, new BaseAdvisor_10_50(false)); - if (theNonCanonical instanceof org.hl7.fhir.dstu2.model.ValueSet) { - org.hl7.fhir.dstu2.model.ValueSet valueSet = (org.hl7.fhir.dstu2.model.ValueSet) theNonCanonical; - if (valueSet.hasCodeSystem() && valueSet.getCodeSystem().hasSystem()) { - if (!valueSet.hasCompose()) { - ValueSet valueSetR5 = (ValueSet) retVal; - valueSetR5.getCompose().addInclude().setSystem(valueSet.getCodeSystem().getSystem()); - } - } - } - return retVal; - } - - @Override - public IBaseResource fromCanonical(Resource theCanonical) { - return VersionConvertorFactory_10_50.convertResource(theCanonical, new BaseAdvisor_10_50(false)); - } - }; - break; - } - - case DSTU2_1: { - converter = new VersionTypeConverterDstu21(); - break; - } - - case DSTU3: { - converter = new VersionTypeConverterDstu3(); - break; - } - - case R4: { - converter = new VersionTypeConverterR4(); - break; - } - - case R4B: { - converter = new VersionTypeConverterR4B(); - break; - } - - case R5: { - converter = IDENTITY_VERSION_TYPE_CONVERTER; - break; - } - - default: - throw new IllegalStateException(Msg.code(692)); - } - - return new VersionSpecificWorkerContextWrapper(new ValidationSupportContext(theValidationSupport), converter); + VersionCanonicalizer versionCanonicalizer = new VersionCanonicalizer(theValidationSupport.getFhirContext()); + return new VersionSpecificWorkerContextWrapper(new ValidationSupportContext(theValidationSupport), versionCanonicalizer); } } diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionTypeConverterDstu21.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionTypeConverterDstu21.java deleted file mode 100644 index 5f7abb52de9..00000000000 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionTypeConverterDstu21.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.hl7.fhir.common.hapi.validation.validator; - -import org.hl7.fhir.convertors.factory.VersionConvertorFactory_14_50; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.r5.model.Resource; - -public class VersionTypeConverterDstu21 implements VersionSpecificWorkerContextWrapper.IVersionTypeConverter { - @Override - public Resource toCanonical(IBaseResource theNonCanonical) { - return VersionConvertorFactory_14_50.convertResource((org.hl7.fhir.dstu2016may.model.Resource) theNonCanonical, new VersionTypeAdvisorDstu21()); - } - - @Override - public IBaseResource fromCanonical(Resource theCanonical) { - return VersionConvertorFactory_14_50.convertResource(theCanonical); - } -} diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionTypeConverterDstu3.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionTypeConverterDstu3.java deleted file mode 100644 index f025f50cf3e..00000000000 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionTypeConverterDstu3.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.hl7.fhir.common.hapi.validation.validator; - -import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_50; -import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_50; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.r5.model.Resource; - -public class VersionTypeConverterDstu3 implements VersionSpecificWorkerContextWrapper.IVersionTypeConverter { - @Override - public Resource toCanonical(IBaseResource theNonCanonical) { - return VersionConvertorFactory_30_50.convertResource((org.hl7.fhir.dstu3.model.Resource) theNonCanonical, new BaseAdvisor_30_50(false)); - } - - @Override - public IBaseResource fromCanonical(Resource theCanonical) { - return VersionConvertorFactory_30_50.convertResource(theCanonical, new BaseAdvisor_30_50(false)); - } -} diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionTypeConverterR4.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionTypeConverterR4.java deleted file mode 100644 index 761ef392d05..00000000000 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionTypeConverterR4.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.hl7.fhir.common.hapi.validation.validator; - -import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_40_50; -import org.hl7.fhir.convertors.factory.VersionConvertorFactory_40_50; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.r5.model.Resource; - -public class VersionTypeConverterR4 implements VersionSpecificWorkerContextWrapper.IVersionTypeConverter { - @Override - public Resource toCanonical(IBaseResource theNonCanonical) { - return VersionConvertorFactory_40_50.convertResource((org.hl7.fhir.r4.model.Resource) theNonCanonical, new BaseAdvisor_40_50(false)); - } - - @Override - public IBaseResource fromCanonical(Resource theCanonical) { - return VersionConvertorFactory_40_50.convertResource(theCanonical, new BaseAdvisor_40_50(false)); - } -} diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionTypeConverterR4B.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionTypeConverterR4B.java deleted file mode 100644 index dc35d6a29aa..00000000000 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/validator/VersionTypeConverterR4B.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.hl7.fhir.common.hapi.validation.validator; - -import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_43_50; -import org.hl7.fhir.convertors.factory.VersionConvertorFactory_43_50; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.r5.model.Resource; - -public class VersionTypeConverterR4B implements VersionSpecificWorkerContextWrapper.IVersionTypeConverter { - @Override - public Resource toCanonical(IBaseResource theNonCanonical) { - return VersionConvertorFactory_43_50.convertResource((org.hl7.fhir.r4b.model.Resource) theNonCanonical, new BaseAdvisor_43_50(false)); - } - - @Override - public IBaseResource fromCanonical(Resource theCanonical) { - return VersionConvertorFactory_43_50.convertResource(theCanonical, new BaseAdvisor_43_50(false)); - } -} diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/support/RemoteTerminologyServiceValidationSupportTest.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/support/RemoteTerminologyServiceValidationSupportTest.java index a40059965d6..5f95cf86b97 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/support/RemoteTerminologyServiceValidationSupportTest.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/support/RemoteTerminologyServiceValidationSupportTest.java @@ -127,8 +127,8 @@ public class RemoteTerminologyServiceValidationSupportTest { assertEquals(CODE, myCodeSystemProvider.myLastCode.getCode()); assertEquals(CODE_SYSTEM, myCodeSystemProvider.myLastUrl.getValueAsString()); - assertEquals(CODE_SYSTEM_VERSION_AS_TEXT, myCodeSystemProvider.myNextReturnParams.getParameter("name").toString()); - assertTrue(Boolean.parseBoolean(myCodeSystemProvider.myNextReturnParams.getParameter("result").primitiveValue())); + assertEquals(CODE_SYSTEM_VERSION_AS_TEXT, myCodeSystemProvider.myNextReturnParams.getParameterValue("name").toString()); + assertTrue(Boolean.parseBoolean(myCodeSystemProvider.myNextReturnParams.getParameterValue("result").primitiveValue())); } @Test @@ -141,11 +141,11 @@ public class RemoteTerminologyServiceValidationSupportTest { assertNotNull(outcome, "Call to lookupCode() should return a non-NULL result!"); assertEquals(DISPLAY, outcome.getCodeDisplay()); assertEquals(CODE_SYSTEM_VERSION, outcome.getCodeSystemVersion()); - assertEquals(CODE_SYSTEM_VERSION_AS_TEXT, myCodeSystemProvider.myNextReturnParams.getParameter("name").toString()); + assertEquals(CODE_SYSTEM_VERSION_AS_TEXT, myCodeSystemProvider.myNextReturnParams.getParameterValue("name").toString()); assertEquals(CODE, myCodeSystemProvider.myLastCode.getCode()); assertEquals(CODE_SYSTEM, myCodeSystemProvider.myLastUrl.getValueAsString()); - assertTrue(Boolean.parseBoolean(myCodeSystemProvider.myNextReturnParams.getParameter("result").primitiveValue())); + assertTrue(Boolean.parseBoolean(myCodeSystemProvider.myNextReturnParams.getParameterValue("result").primitiveValue())); validateExtraCodeSystemParams(); } diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/validator/VersionSpecificWorkerContextWrapperTest.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/validator/VersionSpecificWorkerContextWrapperTest.java index 6c79280f1d5..e85932809f6 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/validator/VersionSpecificWorkerContextWrapperTest.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/validator/VersionSpecificWorkerContextWrapperTest.java @@ -5,6 +5,7 @@ import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.support.IValidationSupport; import ca.uhn.fhir.context.support.ValidationSupportContext; import ca.uhn.fhir.i18n.HapiLocalizer; +import ca.uhn.hapi.converters.canonical.VersionCanonicalizer; import org.hl7.fhir.r5.model.Resource; import org.junit.jupiter.api.Test; @@ -29,12 +30,12 @@ public class VersionSpecificWorkerContextWrapperTest { IValidationSupport validationSupport = mockValidationSupportWithTwoBinaries(); ValidationSupportContext mockContext = mockValidationSupportContext(validationSupport); - VersionSpecificWorkerContextWrapper.IVersionTypeConverter converter = mock(VersionSpecificWorkerContextWrapper.IVersionTypeConverter.class); - VersionSpecificWorkerContextWrapper wrapper = new VersionSpecificWorkerContextWrapper(mockContext, converter); + VersionCanonicalizer versionCanonicalizer = new VersionCanonicalizer(FhirContext.forR5Cached()); + VersionSpecificWorkerContextWrapper wrapper = new VersionSpecificWorkerContextWrapper(mockContext, versionCanonicalizer); - assertTrue(wrapper.hasBinaryKey(EXPECTED_BINARY_KEY_1), "wrapper should have binary key " + EXPECTED_BINARY_KEY_1 ); - assertTrue(wrapper.hasBinaryKey(EXPECTED_BINARY_KEY_2), "wrapper should have binary key " + EXPECTED_BINARY_KEY_1 ); + assertTrue(wrapper.hasBinaryKey(EXPECTED_BINARY_KEY_1), "wrapper should have binary key " + EXPECTED_BINARY_KEY_1); + assertTrue(wrapper.hasBinaryKey(EXPECTED_BINARY_KEY_2), "wrapper should have binary key " + EXPECTED_BINARY_KEY_1); assertFalse(wrapper.hasBinaryKey(NON_EXISTENT_BINARY_KEY), "wrapper should not have binary key " + NON_EXISTENT_BINARY_KEY); } @@ -45,9 +46,9 @@ public class VersionSpecificWorkerContextWrapperTest { IValidationSupport validationSupport = mockValidationSupportWithTwoBinaries(); ValidationSupportContext mockContext = mockValidationSupportContext(validationSupport); - VersionSpecificWorkerContextWrapper.IVersionTypeConverter converter = mock(VersionSpecificWorkerContextWrapper.IVersionTypeConverter.class); - VersionSpecificWorkerContextWrapper wrapper = new VersionSpecificWorkerContextWrapper(mockContext, converter); + VersionCanonicalizer versionCanonicalizer = new VersionCanonicalizer(FhirContext.forR5Cached()); + VersionSpecificWorkerContextWrapper wrapper = new VersionSpecificWorkerContextWrapper(mockContext, versionCanonicalizer); assertArrayEquals(EXPECTED_BINARY_CONTENT_1, wrapper.getBinaryForKey(EXPECTED_BINARY_KEY_1)); assertArrayEquals(EXPECTED_BINARY_CONTENT_2, wrapper.getBinaryForKey(EXPECTED_BINARY_KEY_2)); @@ -60,9 +61,9 @@ public class VersionSpecificWorkerContextWrapperTest { IValidationSupport validationSupport = mockValidationSupport(); ValidationSupportContext mockContext = mockValidationSupportContext(validationSupport); - VersionSpecificWorkerContextWrapper.IVersionTypeConverter converter = mock(VersionSpecificWorkerContextWrapper.IVersionTypeConverter.class); - VersionSpecificWorkerContextWrapper wrapper = new VersionSpecificWorkerContextWrapper(mockContext, converter); + VersionCanonicalizer versionCanonicalizer = new VersionCanonicalizer(FhirContext.forR5Cached()); + VersionSpecificWorkerContextWrapper wrapper = new VersionSpecificWorkerContextWrapper(mockContext, versionCanonicalizer); wrapper.cacheResource(mock(Resource.class)); } diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidatorDstu3Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidatorDstu3Test.java index 87a7d13b948..ac7ab8e86af 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidatorDstu3Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidatorDstu3Test.java @@ -598,7 +598,7 @@ public class FhirInstanceValidatorDstu3Test { List issues = logResultsAndReturnNonInformationalOnes(output); assertThat(issues.stream().map(SingleValidationMessage::getMessage).collect(Collectors.toList()).toString(), - containsString("None of the codings provided are in the value set 'Value Set Finnish PHR Medication Context' (http://phr.kanta.fi/ValueSet/fiphr-vs-medicationcontext), and a coding from this value set is required) (codes = http://phr.kanta.fi/fiphr-cs-medicationcontext#13)")); + containsString("None of the codings provided are in the value set 'Value Set Finnish PHR Medication Context'")); } @Test @@ -669,7 +669,10 @@ public class FhirInstanceValidatorDstu3Test { } else if (t.getMessage().contains("The valueSet reference http://www.rfc-editor.org/bcp/bcp13.txt on element")) { return false; } else if (t.getMessage().contains("The Unicode sequence has unterminated bi-di control characters")) { - // Some DSTU3 structures conain bi-di control characters, and a check for this was added recently. + // Some DSTU3 structures contain bi-di control characters, and a check for this was added recently. + return false; + } else if (t.getMessage().contains("The markdown contains content that appears to be an embedded")) { + // Some DSTU3 structures contain URLs with <> around them return false; } else { return true; @@ -783,7 +786,7 @@ public class FhirInstanceValidatorDstu3Test { Patient resource = loadResource("/dstu3/nl/nl-core-patient-01.json", Patient.class); ValidationResult results = myVal.validateWithResult(resource); List outcome = logResultsAndReturnNonInformationalOnes(results); - assertThat(outcome.toString(), containsString("Could not confirm that the codes provided are in the value set http://decor.nictiz.nl/fhir/ValueSet/2.16.840.1.113883.2.4.3.11.60.40.2.20.5.1--20171231000000")); + assertThat(outcome.toString(), containsString("Could not confirm that the codes provided are in the value set 'LandGBACodelijst'")); } private void loadNL() throws IOException { @@ -867,7 +870,7 @@ public class FhirInstanceValidatorDstu3Test { ourLog.info(output.getMessages().get(0).getLocationString()); ourLog.info(output.getMessages().get(0).getMessage()); assertEquals("Patient", output.getMessages().get(0).getLocationString()); - assertEquals("Unrecognised property '@foo'", output.getMessages().get(0).getMessage()); + assertEquals("Unrecognized property 'foo'", output.getMessages().get(0).getMessage()); } @Test @@ -1185,9 +1188,10 @@ public class FhirInstanceValidatorDstu3Test { ValidationResult output = myVal.validateWithResult(input); logResultsAndReturnAll(output); - assertEquals( - "The value provided ('notvalidcode') is not in the value set 'ObservationStatus' (http://hl7.org/fhir/ValueSet/observation-status), and a code is required from this value set) (error message = Unknown code 'notvalidcode' for in-memory expansion of ValueSet 'http://hl7.org/fhir/ValueSet/observation-status')", - output.getMessages().get(0).getMessage()); + assertThat( + output.getMessages().get(0).getMessage(), + containsString("The value provided ('notvalidcode') is not in the value set 'ObservationStatus'") + ); } @Test @@ -1282,9 +1286,9 @@ public class FhirInstanceValidatorDstu3Test { List all = logResultsAndReturnAll(output); assertEquals(1, all.size()); assertEquals("Patient.identifier[0].type", all.get(0).getLocationString()); - assertEquals( - "None of the codings provided are in the value set 'Identifier Type Codes' (http://hl7.org/fhir/ValueSet/identifier-type), and a coding should come from this value set unless it has no suitable code (note that the validator cannot judge what is suitable) (codes = http://example.com/foo/bar#bar)", - all.get(0).getMessage()); + assertThat( + all.get(0).getMessage(), + containsString("None of the codings provided are in the value set 'Identifier Type Codes'")); assertEquals(ResultSeverityEnum.WARNING, all.get(0).getSeverity()); } diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireResponseValidatorDstu3Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireResponseValidatorDstu3Test.java index 1fac9165f5d..f45584521b4 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireResponseValidatorDstu3Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireResponseValidatorDstu3Test.java @@ -211,7 +211,7 @@ public class QuestionnaireResponseValidatorDstu3Test { ValidationResult errors = myVal.validateWithResult(qa); ourLog.info(errors.toString()); - assertThat(errors.toString(), containsString("Answer value must be of type boolean")); + assertThat(errors.toString(), containsString("Answer value must be of the type boolean")); } @Test diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/ResourceValidatorDstu3Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/ResourceValidatorDstu3Test.java index f8a8abc33ee..8e4f2f0209d 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/ResourceValidatorDstu3Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/ResourceValidatorDstu3Test.java @@ -166,7 +166,7 @@ public class ResourceValidatorDstu3Test { ValidationResult output = val.validateWithResult(p); List all = logResultsAndReturnNonInformationalOnes(output); - assertEquals("None of the codings provided are in the value set 'Marital Status Codes' (http://hl7.org/fhir/ValueSet/marital-status), and a coding should come from this value set unless it has no suitable code (note that the validator cannot judge what is suitable) (codes = http://hl7.org/fhir/v3/MaritalStatus#FOO)", output.getMessages().get(0).getMessage()); + assertThat(output.getMessages().get(0).getMessage(), containsString("None of the codings provided are in the value set 'Marital Status Codes'")); assertEquals(ResultSeverityEnum.WARNING, output.getMessages().get(0).getSeverity()); } diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/CustomResourceGenerationTest.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/CustomResourceGenerationTest.java index fd1ebd79748..32b29892d7d 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/CustomResourceGenerationTest.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/CustomResourceGenerationTest.java @@ -44,8 +44,8 @@ public class CustomResourceGenerationTest extends BaseTest { assertEquals(3, result.getMessages().size()); assertEquals("Error parsing JSON: the primitive value must be a boolean", result.getMessages().get(0).getMessage()); - assertEquals("This property must be an Array, not a primitive property", result.getMessages().get(1).getMessage()); - assertEquals("Unrecognised property '@id1'", result.getMessages().get(2).getMessage()); + assertEquals("This property must be an Array, not a Primitive property", result.getMessages().get(1).getMessage()); + assertEquals("Unrecognized property 'id1'", result.getMessages().get(2).getMessage()); } diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java index 25e1781c7b6..9bd8e5af7e1 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java @@ -445,7 +445,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { ValidationResult result = val.validateWithResult(operationDefinition); List all = logResultsAndReturnAll(result); assertFalse(result.isSuccessful()); - assertEquals("This property must be an Array, not a primitive property", all.get(0).getMessage()); + assertEquals("This property must be an Array, not a Primitive property", all.get(0).getMessage()); } @Test @@ -704,7 +704,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { ValidationResult output = myFhirValidator.validateWithResult(input); List errors = logResultsAndReturnAll(output); assertEquals(2, errors.size()); - assertEquals("None of the codings provided are in the value set 'LOINC Diagnostic Report Codes' (http://hl7.org/fhir/ValueSet/report-codes), and a coding is recommended to come from this value set) (codes = http://loinc.org#1-8)", errors.get(0).getMessage()); + assertThat(errors.get(0).getMessage(), containsString("None of the codings provided are in the value set 'LOINC Diagnostic Report Codes'")); assertEquals("Base64 encoded values SHOULD not contain any whitespace (per RFC 4648). Note that non-validating readers are encouraged to accept whitespace anyway", errors.get(1).getMessage()); } @@ -802,7 +802,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { ValidationResult output = myFhirValidator.validateWithResult(patient); logResultsAndReturnNonInformationalOnes(output); - assertThat(output.getMessages().toString(), containsString("Error parsing JSON source: Duplicated property name")); + assertThat(output.getMessages().toString(), containsString("The JSON property 'name' is a duplicate and will be ignored")); } @Test @@ -930,13 +930,13 @@ public class FhirInstanceValidatorR4Test extends BaseTest { ourLog.info(output.getMessages().get(0).getLocationString()); ourLog.info(output.getMessages().get(0).getMessage()); assertEquals("Patient", output.getMessages().get(0).getLocationString()); - assertEquals("Unrecognised property '@foo'", output.getMessages().get(0).getMessage()); + assertEquals("Unrecognized property 'foo'", output.getMessages().get(0).getMessage()); OperationOutcome operationOutcome = (OperationOutcome) output.toOperationOutcome(); ourLog.info(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(operationOutcome)); - assertEquals("Unrecognised property '@foo'", operationOutcome.getIssue().get(0).getDiagnostics()); + assertEquals("Unrecognized property 'foo'", operationOutcome.getIssue().get(0).getDiagnostics()); assertEquals("Patient", operationOutcome.getIssue().get(0).getLocation().get(0).getValue()); - assertEquals("Line 5, Col 24", operationOutcome.getIssue().get(0).getLocation().get(1).getValue()); + assertEquals("Line 5, Col 23", operationOutcome.getIssue().get(0).getLocation().get(1).getValue()); } @Test @@ -1243,7 +1243,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { ValidationResult output = myFhirValidator.validateWithResult(input); assertThat(output.getMessages().size(), greaterThan(0)); - assertEquals("Observation.status: minimum required = 1, but only found 0 (from http://hl7.org/fhir/StructureDefinition/Observation)", output.getMessages().get(0).getMessage()); + assertThat(output.getMessages().get(0).getMessage(), containsString("Observation.status: minimum required = 1, but only found 0")); } @@ -1409,7 +1409,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { List all = logResultsAndReturnAll(output); assertEquals(1, all.size()); assertEquals("Patient.identifier[0].type", all.get(0).getLocationString()); - assertThat(all.get(0).getMessage(), containsString("None of the codings provided are in the value set 'IdentifierType' (http://hl7.org/fhir/ValueSet/identifier-type), and a coding should come from this value set unless it has no suitable code (note that the validator cannot judge what is suitable) (codes = http://example.com/foo/bar#bar)")); + assertThat(all.get(0).getMessage(), containsString("None of the codings provided are in the value set 'IdentifierType'")); assertEquals(ResultSeverityEnum.WARNING, all.get(0).getSeverity()); } diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/QuestionnaireResponseValidatorR4Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/QuestionnaireResponseValidatorR4Test.java index ecd02a7faca..d89a32f2aa1 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/QuestionnaireResponseValidatorR4Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/QuestionnaireResponseValidatorR4Test.java @@ -187,7 +187,7 @@ public class QuestionnaireResponseValidatorR4Test { ValidationResult errors = myVal.validateWithResult(qa); ourLog.info(errors.toString()); - assertThat(errors.toString(), containsString("Answer value must be of type boolean")); + assertThat(errors.toString(), containsString("Answer value must be of the type boolean")); } @Test diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r5/validation/FhirInstanceValidatorR5Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r5/validation/FhirInstanceValidatorR5Test.java index fd40a927c76..d37dbb062e9 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r5/validation/FhirInstanceValidatorR5Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r5/validation/FhirInstanceValidatorR5Test.java @@ -505,7 +505,7 @@ public class FhirInstanceValidatorR5Test { ourLog.info(output.getMessages().get(0).getLocationString()); ourLog.info(output.getMessages().get(0).getMessage()); assertEquals("Patient", output.getMessages().get(0).getLocationString()); - assertEquals("Unrecognised property '@foo'", output.getMessages().get(0).getMessage()); + assertEquals("Unrecognized property 'foo'", output.getMessages().get(0).getMessage()); } @Test @@ -835,7 +835,7 @@ public class FhirInstanceValidatorR5Test { ValidationResult output = myVal.validateWithResult(input); assertThat(output.getMessages().size(), greaterThan(0)); - assertEquals("Observation.status: minimum required = 1, but only found 0 (from http://hl7.org/fhir/StructureDefinition/Observation)", output.getMessages().get(0).getMessage()); + assertThat(output.getMessages().get(0).getMessage(), containsString("Observation.status: minimum required = 1, but only found 0")); } @@ -972,9 +972,9 @@ public class FhirInstanceValidatorR5Test { List all = logResultsAndReturnAll(output); assertEquals(1, all.size()); assertEquals("Patient.identifier[0].type", all.get(0).getLocationString()); - assertEquals( - "None of the codings provided are in the value set 'Identifier Type Codes' (http://hl7.org/fhir/ValueSet/identifier-type), and a coding should come from this value set unless it has no suitable code (note that the validator cannot judge what is suitable) (codes = http://example.com/foo/bar#bar)", - all.get(0).getMessage()); + assertThat( + all.get(0).getMessage(), + containsString("None of the codings provided are in the value set 'Identifier Type Codes'")); assertEquals(ResultSeverityEnum.WARNING, all.get(0).getSeverity()); } diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r5/validation/QuestionnaireResponseValidatorR5Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r5/validation/QuestionnaireResponseValidatorR5Test.java index d9bf95853d1..d5e3c3a276b 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r5/validation/QuestionnaireResponseValidatorR5Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r5/validation/QuestionnaireResponseValidatorR5Test.java @@ -205,7 +205,7 @@ public class QuestionnaireResponseValidatorR5Test { ValidationResult errors = myVal.validateWithResult(qa); ourLog.info(errors.toString()); - assertThat(errors.toString(), containsString("Answer value must be of type boolean")); + assertThat(errors.toString(), containsString("Answer value must be of the type boolean")); } @Test diff --git a/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm b/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm index 5c83a76ad1d..94654b5e9c0 100644 --- a/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm +++ b/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm @@ -5,7 +5,6 @@ import java.util.*; import org.apache.commons.lang3.StringUtils; -import ca.uhn.fhir.jpa.provider${package_suffix}.*; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.api.annotation.*; @@ -25,9 +24,9 @@ import ca.uhn.fhir.rest.api.SearchContainedModeEnum; public class ${className}ResourceProvider extends ## We have specialized base classes for RPs that handle certain resource types. These ## RPs implement type specific operations -#if ( ${className} == 'CodeSystem' || ${className} == 'Composition' || ${className} == 'Encounter' || ${className} == 'Observation' || ${className} == 'Patient' || ${className} == 'StructureDefinition' ) +#if ( ${className} == 'CodeSystem' || ${className} == 'Composition' || ${className} == 'ConceptMap' || ${className} == 'Encounter' || ${className} == 'Observation' || ${className} == 'Patient' || ${className} == 'StructureDefinition' ) ca.uhn.fhir.jpa.provider.BaseJpaResourceProvider${className}<${className}> -#elseif ( $version != 'dstu' && (${className} == 'QuestionnaireAnswers' || ${className} == 'CodeSystem' || ($version != 'dstu2' && ${className} == 'ConceptMap') || ${className} == 'Composition' || ${className} == 'StructureDefinition')) +#elseif ( $version != 'dstu' && (${className} == 'QuestionnaireAnswers' || ${className} == 'CodeSystem' || ${className} == 'Composition' || ${className} == 'StructureDefinition')) BaseJpaResourceProvider${className}${versionCapitalized} #else ca.uhn.fhir.jpa.provider.BaseJpaResourceProvider<${className}> diff --git a/hapi-tinder-plugin/src/main/resources/vm/jpa_spring_beans_java.vm b/hapi-tinder-plugin/src/main/resources/vm/jpa_spring_beans_java.vm index 806f9f563b2..effa0dc4c9b 100644 --- a/hapi-tinder-plugin/src/main/resources/vm/jpa_spring_beans_java.vm +++ b/hapi-tinder-plugin/src/main/resources/vm/jpa_spring_beans_java.vm @@ -55,22 +55,17 @@ FhirContext myFhirContext; #foreach ( $res in $resources ) @Bean(name="my${res.name}Dao${versionCapitalized}") public -#if ( (${versionCapitalized.startsWith('R')} || ${versionCapitalized} == 'Dstu3') && (${res.name} == 'ConceptMap') ) - IFhirResourceDao${res.name} -#elseif ( ${res.name} == 'CodeSystem' || ${res.name} == 'Composition' || ${res.name} == 'Encounter' || ${res.name} == 'Everything' || ${res.name} == 'Observation' || ${res.name} == 'Patient' || ${res.name} == 'Subscription' || ${res.name} == 'SearchParameter' || ${res.name} == 'StructureDefinition' || ${res.name} == 'ValueSet' ) +#if ( ${res.name} == 'CodeSystem' || ${res.name} == 'Composition' || ${res.name} == 'ConceptMap' || ${res.name} == 'Encounter' || ${res.name} == 'Everything' || ${res.name} == 'Observation' || ${res.name} == 'Patient' || ${res.name} == 'Subscription' || ${res.name} == 'SearchParameter' || ${res.name} == 'StructureDefinition' || ${res.name} == 'ValueSet' ) IFhirResourceDao${res.name}<${resourcePackage}.${res.declaringClassNameComplete}> #else IFhirResourceDao<${resourcePackage}.${res.declaringClassNameComplete}> #end dao${res.declaringClassNameComplete}${versionCapitalized}() { -#if ( ${res.name} == 'Bundle' || ${res.name} == 'CodeSystem' || ${res.name} == 'Composition' || ${res.name} == 'Encounter' || ${res.name} == 'Observation' || ${res.name} == 'Patient' || ${res.name} == 'SearchParameter' || ${res.name} == 'ValueSet' ) +#if ( ${res.name} == 'Bundle' || ${res.name} == 'CodeSystem' || ${res.name} == 'Composition' || ${res.name} == 'ConceptMap' || ${res.name} == 'Encounter' || ${res.name} == 'Observation' || ${res.name} == 'Patient' || ${res.name} == 'SearchParameter' || ${res.name} == 'StructureDefinition' || ${res.name} == 'ValueSet' ) ca.uhn.fhir.jpa.dao.JpaResourceDao${res.name}<${resourcePackage}.${res.declaringClassNameComplete}> retVal; retVal = new ca.uhn.fhir.jpa.dao.JpaResourceDao${res.name}<>(); -#elseif ( (${versionCapitalized.startsWith('R')} || ${versionCapitalized} == 'Dstu3') && (${res.name} == 'ConceptMap') ) - ca.uhn.fhir.jpa.dao.JpaResourceDao${res.name} retVal; - retVal = new ca.uhn.fhir.jpa.dao.JpaResourceDao${res.name}<>(); -#elseif ( ${res.name} == 'Everything' || ${res.name} == 'Subscription' || ${res.name} == 'StructureDefinition') +#elseif ( ${res.name} == 'Everything' || ${res.name} == 'Subscription') ca.uhn.fhir.jpa.dao${package_suffix}.FhirResourceDao${res.name}${versionCapitalized} retVal; retVal = new ca.uhn.fhir.jpa.dao${package_suffix}.FhirResourceDao${res.name}${versionCapitalized}(); #else diff --git a/pom.xml b/pom.xml index 7205dae7616..53a7ed092be 100644 --- a/pom.xml +++ b/pom.xml @@ -845,7 +845,7 @@ - 5.6.68 + 5.6.82-SNAPSHOT 1.0.3 -Dfile.encoding=UTF-8 -Xmx2048m @@ -1028,7 +1028,7 @@ com.graphql-java graphql-java - 17.4 + 19.2