2229 - Remove support for the upload-igpack CLI command. (#2233)

* 2229 - Remove support for the upload-igpack CLI command.

* 2229 - Revert changes made to the ValidateCommand class since it only takes an igpack as a parameter and therefore, should NOT have been removed.

* 2229 - Remove the igpack option from the Validate command.

* Update hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_3_0/2229-remove-upload-igpack-command.yaml

Co-authored-by: James Agnew <jamesagnew@gmail.com>

Co-authored-by: Kevin Dougan <kevindougan@kevins-mbp.lan>
Co-authored-by: James Agnew <jamesagnew@gmail.com>
This commit is contained in:
Kevin Dougan SmileCDR 2020-12-14 09:50:16 -05:00 committed by GitHub
parent ab64aa540f
commit 9036df25fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 4 additions and 810 deletions

View File

@ -91,11 +91,6 @@
<artifactId>hapi-fhir-validation-resources-r4</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hapi-fhir-igpacks</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hapi-fhir-jpaserver-model</artifactId>

View File

@ -33,11 +33,6 @@
<type>jar</type>
<classifier>classes</classifier>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-igpacks</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-jpaserver-migrate</artifactId>

View File

@ -169,7 +169,6 @@ public abstract class BaseApp {
commands.add(new ValidationDataUploader());
commands.add(new WebsocketSubscribeCommand());
commands.add(new UploadTerminologyCommand());
commands.add(new IgPackUploader());
commands.add(new ExportConceptMapToCsvCommand());
commands.add(new ImportCsvToConceptMapCommand());
commands.add(new HapiFlywayMigrateDatabaseCommand());

View File

@ -1,116 +0,0 @@
package ca.uhn.fhir.cli;
/*-
* #%L
* HAPI FHIR - Command Line Client - API
* %%
* Copyright (C) 2014 - 2020 University Health Network
* %%
* 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.FhirContext;
import ca.uhn.fhir.context.support.IValidationSupport;
import ca.uhn.fhir.igpacks.parser.IgPackParserDstu3;
import ca.uhn.fhir.rest.client.api.IGenericClient;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.hl7.fhir.dstu3.model.StructureDefinition;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Collection;
public class IgPackUploader extends BaseCommand {
// TODO: Don't use qualified names for loggers in HAPI CLI.
private static final Logger ourLog = LoggerFactory.getLogger(IgPackUploader.class);
@Override
public String getCommandDescription() {
return "Uploads an Implementation Guide Validation Pack";
}
@Override
public String getCommandName() {
return "upload-igpack";
}
@Override
public Options getOptions() {
Options options = new Options();
addFhirVersionOption(options);
Option opt = new Option("t", "target", true, "Base URL for the target server (e.g. \"http://example.com/fhir\")");
opt.setRequired(false);
options.addOption(opt);
opt = new Option("u", "url", true, "The URL to the validation.pack file, e.g. http://hl7.org/fhir/us/core/validator.pack");
opt.setRequired(true);
options.addOption(opt);
return options;
}
@Override
public void run(CommandLine theCommandLine) throws ParseException{
parseFhirContext(theCommandLine);
IGenericClient client = newClient(theCommandLine);
String url = theCommandLine.getOptionValue("u");
Collection<File> files = null;
try {
files = loadFile(url, null, false);
} catch (IOException e) {
throw new CommandFailureException(e);
}
for (File nextFile : files) {
FhirContext ctx = getFhirContext();
switch (ctx.getVersion().getVersion()) {
case DSTU3:
IgPackParserDstu3 packParser = new IgPackParserDstu3(ctx);
IValidationSupport ig = null;
try {
ig = packParser.parseIg(new FileInputStream(nextFile), nextFile.getName());
} catch (FileNotFoundException e) {
throw new CommandFailureException(e);
}
Iterable<IBaseResource> conformanceResources = ig.fetchAllConformanceResources();
for (IBaseResource nextResource : conformanceResources) {
String nextResourceUrl = ((IPrimitiveType<?>)ctx.newTerser().getSingleValueOrNull(nextResource, "url")).getValueAsString();
ourLog.info("Uploading resource: {}", nextResourceUrl);
client
.update()
.resource(nextResource)
.conditional()
.and(StructureDefinition.URL.matches().value(nextResourceUrl))
.execute();
}
break;
default:
throw new ParseException("This command does not support FHIR version " + ctx.getVersion().getVersion());
}
}
}
}

View File

@ -23,10 +23,7 @@ package ca.uhn.fhir.cli;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.support.DefaultProfileValidationSupport;
import ca.uhn.fhir.context.support.IValidationSupport;
import ca.uhn.fhir.igpacks.parser.IgPackParserDstu2;
import ca.uhn.fhir.igpacks.parser.IgPackParserDstu3;
import ca.uhn.fhir.parser.DataFormatException;
import ca.uhn.fhir.parser.LenientErrorHandler;
import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.SingleValidationMessage;
import ca.uhn.fhir.validation.ValidationResult;
@ -147,25 +144,11 @@ public class ValidateCommand extends BaseCommand {
localProfileResource = ca.uhn.fhir.rest.api.EncodingEnum.detectEncodingNoDefault(input).newParser(ctx).parseResource(input);
}
byte[] igPack = null;
String igpackFilename = null;
if (theCommandLine.hasOption("igpack")) {
igpackFilename = theCommandLine.getOptionValue("igpack");
igPack = loadFileAsByteArray(igpackFilename);
}
if (theCommandLine.hasOption("p")) {
switch (ctx.getVersion().getVersion()) {
case DSTU2: {
ValidationSupportChain validationSupport = new ValidationSupportChain(
new DefaultProfileValidationSupport(ctx), new InMemoryTerminologyServerValidationSupport(ctx));
if (igPack != null) {
FhirContext hl7orgCtx = FhirContext.forDstu2Hl7Org();
hl7orgCtx.setParserErrorHandler(new LenientErrorHandler(false));
IgPackParserDstu2 parser = new IgPackParserDstu2(hl7orgCtx);
IValidationSupport igValidationSupport = parser.parseIg(igPack, igpackFilename);
validationSupport.addValidationSupport(igValidationSupport);
}
if (theCommandLine.hasOption("r")) {
validationSupport.addValidationSupport((IValidationSupport) new LoadingValidationSupportDstu2());
@ -180,11 +163,6 @@ public class ValidateCommand extends BaseCommand {
FhirInstanceValidator instanceValidator = new FhirInstanceValidator(ctx);
val.registerValidatorModule(instanceValidator);
ValidationSupportChain validationSupport = new ValidationSupportChain(new DefaultProfileValidationSupport(ctx), new InMemoryTerminologyServerValidationSupport(ctx));
if (igPack != null) {
IgPackParserDstu3 parser = new IgPackParserDstu3(getFhirContext());
IValidationSupport igValidationSupport = parser.parseIg(igPack, igpackFilename);
validationSupport.addValidationSupport(igValidationSupport);
}
if (theCommandLine.hasOption("r")) {
validationSupport.addValidationSupport((IValidationSupport) new LoadingValidationSupportDstu3());

View File

@ -1,13 +0,0 @@
package ca.uhn.fhir.cli;
import org.junit.jupiter.api.Test;
public class InstallIgPackTest {
@Test
public void testInstallIgPack() {
}
}

View File

@ -1,11 +1,8 @@
package ca.uhn.fhir.cli;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
public class ValidateCommandTest {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ValidateCommandTest.class);
@ -25,38 +22,4 @@ public class ValidateCommandTest {
"-p",
"-n", resourcePath});
}
@Test
@Disabled
public void testValidateUsingIgPackSucceedingDstu2() {
String resourcePath = ValidateCommandTest.class.getResource("/argo-dstu2-observation-good.json").getFile();
ourLog.info(resourcePath);
App.main(new String[] {
"validate",
"-v", "dstu2",
"-p",
"--igpack", "src/test/resources/argo-dstu2.pack",
"-n", resourcePath});
}
@Test
public void testValidateUsingIgPackFailingDstu2() {
String resourcePath = ValidateCommandTest.class.getResource("/argo-dstu2-observation-bad.json").getFile();
ourLog.info(resourcePath);
try {
App.main(new String[] {
"validate",
"-v", "dstu2",
"-p",
"--igpack", "src/test/resources/argo-dstu2.pack",
"-n", resourcePath});
// Should not get here
fail();
} catch (CommandFailureException e) {
// good
}
}
}

View File

@ -0,0 +1,4 @@
---
type: remove
issue: 2229
title: "Remove support for the `upload-igpack` command. This command is no longer supported, as the IGPack format has been withdrawn and replaced with the FHIR NPM Package specification, which is also supported by HAPI FHIR"

View File

@ -1,68 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>hapi-deployable-pom</artifactId>
<groupId>ca.uhn.hapi.fhir</groupId>
<version>5.3.0-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hapi-fhir-igpacks</artifactId>
<dependencies>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-jpaserver-base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-dstu3</artifactId>
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<dumpOnExit>true</dumpOnExit>
</configuration>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,166 +0,0 @@
package ca.uhn.fhir.igpacks.parser;
/*-
* #%L
* hapi-fhir-igpacks
* %%
* Copyright (C) 2014 - 2020 University Health Network
* %%
* 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.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.parser.LenientErrorHandler;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.util.StopWatch;
import org.apache.commons.lang3.Validate;
import org.hl7.fhir.dstu3.model.IdType;
import org.hl7.fhir.dstu3.model.ImplementationGuide;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
public abstract class BaseIgPackParser<T> {
private static final Logger ourLog = LoggerFactory.getLogger(BaseIgPackParser.class);
private final FhirContext myCtx;
public BaseIgPackParser(FhirContext theCtx) {
FhirVersionEnum expectedVersion = provideExpectedVersion();
Validate.isTrue(theCtx.getVersion().getVersion() == expectedVersion, "theCtx is not for the correct version, expecting " + expectedVersion);
myCtx = theCtx;
}
public FhirContext getCtx() {
return myCtx;
}
protected abstract T createValidationSupport(Map<IIdType, IBaseResource> theIgResources);
private IBaseResource findResource(Map<String, IBaseResource> theCandidateResources, IIdType theId) {
IBaseResource retVal = theCandidateResources.get(theId.toUnqualifiedVersionless().getValue());
if (retVal == null) {
throw new InternalErrorException("Unknown reference in ImplementationGuide: " + theId);
}
return retVal;
}
/**
* @param theIgInputStream The "validator.pack" ZIP file
* @param theDescription A description (just used for logs)
*/
public T parseIg(InputStream theIgInputStream, String theDescription) {
Validate.notNull(theIgInputStream, "theIdInputStream must not be null");
String igResourceName = "ImplementationGuide-ig.json";
ourLog.info("Parsing IGPack: {}", theDescription);
StopWatch sw = new StopWatch();
ZipInputStream zipInputStream = new ZipInputStream(theIgInputStream);
ZipEntry entry;
try {
Map<String, IBaseResource> candidateResources = new HashMap<>();
Map<IIdType, IBaseResource> igResources = new HashMap<>();
while ((entry = zipInputStream.getNextEntry()) != null) {
if (entry.getName().endsWith(".json")) {
IBaseResource parsed;
InputStreamReader nextReader = new InputStreamReader(zipInputStream, Constants.CHARSET_UTF8);
if (entry.getName().equals(igResourceName)) {
parsed = FhirContext.forDstu3().newJsonParser().parseResource(ImplementationGuide.class, nextReader);
} else {
LenientErrorHandler errorHandler = new LenientErrorHandler();
errorHandler.setErrorOnInvalidValue(false);
parsed = myCtx.newJsonParser().setParserErrorHandler(errorHandler).parseResource(nextReader);
}
candidateResources.put(entry.getName(), parsed);
}
}
ourLog.info("Parsed {} candidateResources in {}ms", candidateResources.size(), sw.getMillis());
ImplementationGuide ig = (ImplementationGuide) candidateResources.get(igResourceName);
if (ig == null) {
throw new InternalErrorException("IG Pack '" + theDescription + "' does not contain a resource named: " + igResourceName);
}
HashMap<String, IBaseResource> newCandidateResources = new HashMap<>();
for (IBaseResource next : candidateResources.values()) {
newCandidateResources.put(next.getIdElement().toUnqualifiedVersionless().getValue(), next);
}
candidateResources = newCandidateResources;
for (ImplementationGuide.ImplementationGuidePackageComponent nextPackage : ig.getPackage()) {
ourLog.info("Processing package {}", nextPackage.getName());
for (ImplementationGuide.ImplementationGuidePackageResourceComponent nextResource : nextPackage.getResource()) {
if (isNotBlank(nextResource.getSourceReference().getReference())) {
IdType id = new IdType(nextResource.getSourceReference().getReference());
if (isNotBlank(id.getResourceType())) {
switch (id.getResourceType()) {
case "CodeSystem":
case "ConceptMap":
case "StructureDefinition":
case "ValueSet":
IBaseResource resource = findResource(candidateResources, id);
igResources.put(id.toUnqualifiedVersionless(), resource);
break;
}
}
}
}
}
ourLog.info("IG contains {} resources", igResources.size());
return createValidationSupport(igResources);
} catch (Exception e) {
throw new InternalErrorException("Failure while parsing IG: " + e, e);
}
}
/**
* @param theIgPack The "validator.pack" ZIP file
* @param theDescription A description (just used for logs)
*/
public T parseIg(byte[] theIgPack, String theDescription) {
return parseIg(new ByteArrayInputStream(theIgPack), theDescription);
}
protected abstract FhirVersionEnum provideExpectedVersion();
}

View File

@ -1,56 +0,0 @@
package ca.uhn.fhir.igpacks.parser;
/*-
* #%L
* hapi-fhir-igpacks
* %%
* Copyright (C) 2014 - 2020 University Health Network
* %%
* 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.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.context.support.IValidationSupport;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import java.util.Map;
public class IgPackParserDstu2 extends BaseIgPackParser<IValidationSupport> {
public IgPackParserDstu2(FhirContext theCtx) {
super(massage(theCtx));
}
@Override
protected IValidationSupport createValidationSupport(Map<IIdType, IBaseResource> theIgResources) {
return new IgPackValidationSupportDstu2(getCtx(), theIgResources);
}
@Override
protected FhirVersionEnum provideExpectedVersion() {
return FhirVersionEnum.DSTU2_HL7ORG;
}
private static FhirContext massage(FhirContext theCtx) {
if (theCtx.getVersion().getVersion() == FhirVersionEnum.DSTU2) {
return FhirContext.forDstu2Hl7Org();
} else {
return theCtx;
}
}
}

View File

@ -1,48 +0,0 @@
package ca.uhn.fhir.igpacks.parser;
/*-
* #%L
* hapi-fhir-igpacks
* %%
* Copyright (C) 2014 - 2020 University Health Network
* %%
* 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.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.context.support.IValidationSupport;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import java.util.Map;
public class IgPackParserDstu3 extends BaseIgPackParser<IValidationSupport> {
public IgPackParserDstu3(FhirContext theCtx) {
super(theCtx);
}
@Override
protected IValidationSupport createValidationSupport(Map<IIdType, IBaseResource> theIgResources) {
return new IgPackValidationSupportDstu3(getCtx(), theIgResources);
}
@Override
protected FhirVersionEnum provideExpectedVersion() {
return FhirVersionEnum.DSTU3;
}
}

View File

@ -1,88 +0,0 @@
package ca.uhn.fhir.igpacks.parser;
/*-
* #%L
* hapi-fhir-igpacks
* %%
* Copyright (C) 2014 - 2020 University Health Network
* %%
* 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.FhirContext;
import ca.uhn.fhir.context.support.IValidationSupport;
import ca.uhn.fhir.context.support.ValidationSupportContext;
import org.hl7.fhir.dstu2.model.ConceptMap;
import org.hl7.fhir.dstu2.model.StructureDefinition;
import org.hl7.fhir.dstu2.model.ValueSet;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import java.util.Map;
public class IgPackValidationSupportDstu2 implements IValidationSupport {
private final Map<IIdType, IBaseResource> myIgResources;
private FhirContext myCtx;
public IgPackValidationSupportDstu2(FhirContext theCtx, Map<IIdType, IBaseResource> theIgResources) {
myCtx = theCtx;
myIgResources = theIgResources;
}
@Override
public <T extends IBaseResource> T fetchResource(Class<T> theClass, String theUri) {
for (Map.Entry<IIdType, IBaseResource> next : myIgResources.entrySet()) {
if (theClass.equals(ConceptMap.class)) {
if (theClass.isAssignableFrom(next.getValue().getClass())) {
ConceptMap sd = ((ConceptMap) next.getValue());
if (sd.getUrl().equals(theUri)) {
return (T) sd;
}
}
}
if (theClass.equals(StructureDefinition.class)) {
if (theClass.isAssignableFrom(next.getValue().getClass())) {
StructureDefinition sd = ((StructureDefinition) next.getValue());
if (sd.getUrl().equals(theUri)) {
return (T) sd;
}
}
}
if (theClass.equals(ValueSet.class)) {
if (theClass.isAssignableFrom(next.getValue().getClass())) {
ValueSet sd = ((ValueSet) next.getValue());
if (sd.getUrl().equals(theUri)) {
return (T) sd;
}
}
}
}
return null;
}
@Override
public boolean isCodeSystemSupported(ValidationSupportContext theValidationSupportContext, String theSystem) {
return false;
}
@Override
public FhirContext getFhirContext() {
return myCtx;
}
}

View File

@ -1,124 +0,0 @@
package ca.uhn.fhir.igpacks.parser;
/*-
* #%L
* hapi-fhir-igpacks
* %%
* Copyright (C) 2014 - 2020 University Health Network
* %%
* 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.FhirContext;
import ca.uhn.fhir.context.support.ConceptValidationOptions;
import ca.uhn.fhir.context.support.IValidationSupport;
import ca.uhn.fhir.context.support.ValidationSupportContext;
import org.hl7.fhir.dstu3.model.CodeSystem;
import org.hl7.fhir.dstu3.model.ConceptMap;
import org.hl7.fhir.dstu3.model.StructureDefinition;
import org.hl7.fhir.dstu3.model.ValueSet;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class IgPackValidationSupportDstu3 implements IValidationSupport {
private final Map<IIdType, IBaseResource> myIgResources;
private FhirContext myCtx;
public IgPackValidationSupportDstu3(FhirContext theCtx, Map<IIdType, IBaseResource> theIgResources) {
myIgResources = theIgResources;
myCtx = theCtx;
}
@Override
public List<IBaseResource> fetchAllConformanceResources() {
return new ArrayList<>(myIgResources.values());
}
@Override
public ValueSet fetchValueSet(String theSystem) {
return fetchResource(ValueSet.class, theSystem);
}
@Override
public <T extends IBaseResource> T fetchResource(Class<T> theClass, String theUri) {
for (Map.Entry<IIdType, IBaseResource> next : myIgResources.entrySet()) {
if (theClass.equals(CodeSystem.class)) {
if (theClass.isAssignableFrom(next.getValue().getClass())) {
CodeSystem sd = ((CodeSystem) next.getValue());
if (sd.getUrl().equals(theUri)) {
return (T) sd;
}
}
}
if (theClass.equals(ConceptMap.class)) {
if (theClass.isAssignableFrom(next.getValue().getClass())) {
ConceptMap sd = ((ConceptMap) next.getValue());
if (sd.getUrl().equals(theUri)) {
return (T) sd;
}
}
}
if (theClass.equals(StructureDefinition.class)) {
if (theClass.isAssignableFrom(next.getValue().getClass())) {
StructureDefinition sd = ((StructureDefinition) next.getValue());
if (sd.getUrl().equals(theUri)) {
return (T) sd;
}
}
}
if (theClass.equals(ValueSet.class)) {
if (theClass.isAssignableFrom(next.getValue().getClass())) {
ValueSet sd = ((ValueSet) next.getValue());
if (sd.getUrl().equals(theUri)) {
return (T) sd;
}
}
}
}
return null;
}
@Override
public StructureDefinition fetchStructureDefinition(String theUrl) {
return fetchResource(StructureDefinition.class, theUrl);
}
@Override
public boolean isCodeSystemSupported(ValidationSupportContext theValidationSupportContext, String theSystem) {
return false;
}
@Override
public CodeValidationResult validateCode(ValidationSupportContext theValidationSupportContext, ConceptValidationOptions theOptions, String theCodeSystem, String theCode, String theDisplay, String theValueSetUrl) {
return null;
}
@Override
public LookupCodeResult lookupCode(ValidationSupportContext theValidationSupportContext, String theSystem, String theCode) {
return null;
}
@Override
public FhirContext getFhirContext() {
return myCtx;
}
}

View File

@ -1,30 +0,0 @@
package ca.uhn.fhir.igpack.parser;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.support.IValidationSupport;
import ca.uhn.fhir.igpacks.parser.IgPackParserDstu3;
import org.hl7.fhir.dstu3.model.ValueSet;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class IgPackParserDstu3Test {
private static final Logger ourLog = LoggerFactory.getLogger(IgPackParserDstu3Test.class);
@Test
public void testParseIg() {
FhirContext ctx = FhirContext.forDstu3();
IgPackParserDstu3 igParser = new IgPackParserDstu3(ctx);
IValidationSupport result = igParser.parseIg(IgPackParserDstu3Test.class.getResourceAsStream("/us-core-stu3-validator.pack"), "US-Core STU3");
assertNotNull(result.fetchResource(ValueSet.class, "http://hl7.org/fhir/us/core/ValueSet/simple-language"));
assertEquals(50, result.fetchAllConformanceResources().size());
}
}

View File

@ -1,30 +0,0 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} [%file:%line] - %msg%n
</pattern>
</encoder>
</appender>
<logger name="org.eclipse" additivity="false" level="info">
<appender-ref ref="STDOUT" />
</logger>
<logger name="org.apache" additivity="false" level="info">
<appender-ref ref="STDOUT" />
</logger>
<logger name="org.thymeleaf" additivity="false" level="warn">
<appender-ref ref="STDOUT" />
</logger>
<!--
<logger name="ca.uhn.fhir.rest.client" additivity="false" level="trace">
<appender-ref ref="STDOUT" />
</logger>
-->
<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>

View File

@ -2530,7 +2530,6 @@
<module>hapi-fhir-validation-resources-r4</module>
<module>hapi-fhir-structures-r5</module>
<module>hapi-fhir-validation-resources-r5</module>
<module>hapi-fhir-igpacks</module>
<module>hapi-fhir-elasticsearch-6</module>
<module>hapi-fhir-jpaserver-api</module>
<module>hapi-fhir-jpaserver-model</module>