Skip to content

Commit

Permalink
fix concept map error #227
Browse files Browse the repository at this point in the history
  • Loading branch information
oliveregger committed Apr 29, 2024
1 parent 14d46d6 commit eec29b4
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 13 deletions.
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@
"projectName": "matchbox-server",
"vmArgs": "-Dspring.config.additional-location=file:/Users/oegger/Documents/github/matchbox/matchbox-server/target/test-classes/application-test-r5onr4.yaml",
"cwd": "${workspaceFolder}/matchbox-server"
},
{
"type": "java",
"name": "Launch Matchbox-Server (alis)",
"request": "launch",
"mainClass": "ca.uhn.fhir.jpa.starter.Application",
"projectName": "matchbox-server",
"vmArgs": "-Dspring.config.additional-location=file:with-alis/application.yaml",
"cwd": "${workspaceFolder}/matchbox-server"
}, {
"type": "java",
"name": "Launch Matchbox-Server",
Expand Down
3 changes: 2 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
2024/04/xx Release 3.8.3
2024/04/29 Release 3.8.3

- profile validation with different ig version issues, GUI & EVS Client [#225](https://github.com/ahdis/matchbox/issues/225)
- improved the profile selection in the validation GUI
- FML: Side effect exception when updating a StructureMap [#227](https://github.com/ahdis/matchbox/issues/227)

2024/04/22 Release 3.8.2

Expand Down
2 changes: 1 addition & 1 deletion matchbox-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>matchbox</artifactId>
<groupId>health.matchbox</groupId>
<version>3.8.2</version>
<version>3.8.3</version>
</parent>

<artifactId>matchbox-engine</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ public MatchboxEngine getEngine() throws MatchboxEngineCreationException {
try { engine = new MatchboxEngine(this.fromNothing()); }
catch (final IOException e) { throw new MatchboxEngineCreationException(e); }
engine.setVersion(this.fhirVersion.toCode());
engine.getContext().setAllowLoadingDuplicates(false);
if (this.txServer == null) {
engine.getContext().setCanRunWithoutTerminology(true);
engine.getContext().setNoTerminologyServer(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.TerminologyServiceException;
import org.hl7.fhir.r5.comparison.VersionComparisonAnnotation;
import org.hl7.fhir.r5.conformance.profile.ProfileUtilities;
import org.hl7.fhir.r5.context.CanonicalResourceManager.CanonicalResourceProxy;
import org.hl7.fhir.r5.context.ILoggingService.LogCategory;
Expand Down Expand Up @@ -383,9 +384,16 @@ public void registerResourceFromPackage(CanonicalResourceProxy r, PackageInforma
if (Utilities.existsInList(url, "http://hl7.org/fhir/SearchParameter/example")) {
return;
}
// matchbox patch for duplicate resources, see https://github.com/ahdis/matchbox/issues/227
// org.hl7.fhir.r5.conformance.R5ExtensionsLoader.loadR5SpecialTypes(R5ExtensionsLoader.java:141)
CanonicalResource ex = fetchResourceWithException(r.getType(), url);
throw new DefinitionException(formatMessage(I18nConstants.DUPLICATE_RESOURCE_, url, r.getVersion(), ex.getVersion(),
ex.fhirType()));
if (laterVersion(r.getVersion(), ex.getVersion())) {
logger.logMessage("Note replacing old version: " + formatMessage(I18nConstants.DUPLICATE_RESOURCE_, url, r.getVersion(), ex.getVersion(), ex.fhirType()));
dropResource(ex);
} else {
logger.logMessage("Note keeping newer version: " + formatMessage(I18nConstants.DUPLICATE_RESOURCE_, url, r.getVersion(), ex.getVersion(), ex.fhirType()));
return;
}
}
switch(r.getType()) {
case "StructureDefinition":
Expand Down Expand Up @@ -508,9 +516,16 @@ public void cacheResourceFromPackage(Resource r, PackageInformation packageInfo)
if (Utilities.existsInList(url, "http://hl7.org/fhir/SearchParameter/example")) {
return;
}
CanonicalResource ex = (CanonicalResource) fetchResourceWithException(r.getClass(), url);
throw new DefinitionException(formatMessage(I18nConstants.DUPLICATE_RESOURCE_, url, ((CanonicalResource) r).getVersion(), ex.getVersion(),
ex.fhirType()));
// matchbox patch for duplicate resources, see https://github.com/ahdis/matchbox/issues/227
// org.hl7.fhir.r5.conformance.R5ExtensionsLoader.loadR5SpecialTypes(R5ExtensionsLoader.java:141)
CanonicalResource ex = fetchResourceWithException(m.fhirType(), url);
if (laterVersion(m.getVersion(), ex.getVersion())) {
logger.logMessage("Note replacing old version: " + formatMessage(I18nConstants.DUPLICATE_RESOURCE_, url, m.getVersion(), ex.getVersion(), ex.fhirType()));
dropResource(ex);
} else {
logger.logMessage("Note keeping newer version: " + formatMessage(I18nConstants.DUPLICATE_RESOURCE_, url, m.getVersion(), ex.getVersion(), ex.fhirType()));
return;
}
}
if (r instanceof StructureDefinition) {
StructureDefinition sd = (StructureDefinition) m;
Expand Down
2 changes: 1 addition & 1 deletion matchbox-frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "matchbox",
"version": "3.8.2",
"version": "3.8.3",
"license": "MIT",
"scripts": {
"ng": "ng",
Expand Down
2 changes: 1 addition & 1 deletion matchbox-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>matchbox</artifactId>
<groupId>health.matchbox</groupId>
<version>3.8.2</version>
<version>3.8.3</version>
</parent>

<artifactId>matchbox-server</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,12 @@ public ca.uhn.fhir.rest.api.server.IBundleProvider search(jakarta.servlet.http.H
if (theUrl != null) {
String url = theUrl.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValue();
R5 r = matchboxEngine.getContext().fetchResource(classR5,url);
resources.add(r);
if (r != null)
resources.add(r);
} else {
resources.addAll(matchboxEngine.getContext().fetchResourcesByType(classR5));
}

switch (getFhirVersion(this.cliContext.getFhirVersion())) {
case "4.0.1": return new SimpleBundleProvider(
resources.stream().map(VersionConvertorFactory_40_50::convertResource).collect(Collectors.toList()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_50;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_40_50;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_43_50;
import org.hl7.fhir.r4.model.ConceptMap.ConceptMapGroupComponent;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.instance.model.api.IBaseBinary;
import org.hl7.fhir.r5.context.SimpleWorkerContext;
import org.hl7.fhir.r5.model.CanonicalResource;
import org.hl7.fhir.r5.model.ImplementationGuide;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.utilities.ByteProvider;
Expand Down Expand Up @@ -104,6 +106,42 @@ public FhirContext getFhirContext(FhirVersionEnum theFhirVersion) {
return myVersionToContext.computeIfAbsent(theFhirVersion, v -> new FhirContext(v));
}

private void cleanModifierExtensions(org.hl7.fhir.r5.model.ConceptMap r) {
for ( org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent group :r.getGroup()) {
group.getElement().forEach(element -> {
element.getTarget().forEach(target -> {
target.getModifierExtension().clear();
});
});
}
}

private void cleanModifierExtensions(org.hl7.fhir.r5.model.StructureMap r) {
r.getContained().forEach(c -> {
if (c instanceof org.hl7.fhir.r5.model.ConceptMap) {
cleanModifierExtensions((org.hl7.fhir.r5.model.ConceptMap) c);
}
});
}

private void cleanModifierExtensions(org.hl7.fhir.r4.model.ConceptMap r) {
for ( ConceptMapGroupComponent group :r.getGroup()) {
group.getElement().forEach(element -> {
element.getTarget().forEach(target -> {
target.getModifierExtension().clear();
});
});
}
}

private void cleanModifierExtensions(org.hl7.fhir.r4.model.StructureMap r) {
r.getContained().forEach(c -> {
if (c instanceof org.hl7.fhir.r4.model.ConceptMap) {
cleanModifierExtensions((org.hl7.fhir.r4.model.ConceptMap) c);
}
});
}

private org.hl7.fhir.r5.model.Resource loadPackageEntity(NpmPackageVersionResourceEntity contents) {
try {
final var binary = MatchboxServerUtils.getBinaryFromId(contents.getResourceBinary().getId(), myDaoRegistry);
Expand All @@ -115,8 +153,12 @@ private org.hl7.fhir.r5.model.Resource loadPackageEntity(NpmPackageVersionResour
return VersionConvertorFactory_30_50
.convertResource(new org.hl7.fhir.dstu3.formats.JsonParser().parse(resourceContents));
case R4:
org.hl7.fhir.r4.model.Resource r = new org.hl7.fhir.r4.formats.JsonParser().parse(resourceContents);
if (r instanceof org.hl7.fhir.r4.model.StructureMap ) {
cleanModifierExtensions((org.hl7.fhir.r4.model.StructureMap) r);
}
return VersionConvertorFactory_40_50
.convertResource(new org.hl7.fhir.r4.formats.JsonParser().parse(resourceContents));
.convertResource(r);
case R4B:
return VersionConvertorFactory_43_50
.convertResource(new org.hl7.fhir.r4b.formats.JsonParser().parse(resourceContents));
Expand Down Expand Up @@ -224,7 +266,24 @@ public void loadIg(List<ImplementationGuide> igs, Map<String, ByteProvider> bina
Resource r = null;
try {
r = loadResourceByVersion(npm.fhirVersion(), TextFile.streamToBytes(pi.load("package", s)), s);
this.getContext().cacheResource(r);
// https://github.com/ahdis/matchbox/issues/227
if (r instanceof org.hl7.fhir.r5.model.StructureMap ) {
cleanModifierExtensions((org.hl7.fhir.r5.model.StructureMap) r);
}
if (r instanceof org.hl7.fhir.r5.model.ConceptMap ) {
cleanModifierExtensions((org.hl7.fhir.r5.model.ConceptMap) r);
}
if (r instanceof CanonicalResource) {
CanonicalResource m = (CanonicalResource) r;
String url = m.getUrl();
if (this.getContext().hasResource(r.getClass(), url)) {
log.error("Duplicate canonical resource: " + r.getClass().getName() + " from package " +pi.name() + "#" + pi.version() + " with url " + url);
} else {
this.getContext().cacheResource(r);
}
} else {
log.error("Resource is not a CanonicalResource: " + r.getClass().getName() + " from package " +pi.name() + "#" + pi.version());
}
} catch (FHIRException e) {
log.error(s, e);
} catch (IOException e) {
Expand Down
33 changes: 33 additions & 0 deletions matchbox-server/with-alis/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
server:
servlet:
context-path: /matchboxv3
hapi:
fhir:
server_address: http://localhost:8080/matchboxv3/fhir
implementationguides:
fhir_r4_core:
name: hl7.fhir.r4.core
version: 4.0.1
url: classpath:/hl7.fhir.r4.core.tgz
fhir_terminology:
name: hl7.terminology
version: 5.4.0
url: classpath:/hl7.terminology#5.4.0.tgz
fhir_extensions:
name: hl7.fhir.uv.extensions.r4
version: 1.0.0
url: classpath:/hl7.fhir.uv.extensions.r4#1.0.0.tgz
hl7_fhir_uv_ips:
name: ch.fhir.ig.ch-alis
version: 0.2.0
url: file:/Users/oegger/Documents/github/ch-alis/output/package.tgz
staticLocation: file:/apps/
matchbox:
fhir:
context:
fhirVersion: 4.0.1
txServer: http://tx.fhir.org
onlyOneEngine: true
spring:
datasource:
url: "jdbc:h2:mem:test"
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<groupId>health.matchbox</groupId>
<artifactId>matchbox</artifactId>
<version>3.8.2</version>
<version>3.8.3</version>
<packaging>pom</packaging>
<name>matchbox</name>
<description>An open-source implementation to support testing and implementation of FHIR based solutions and map or
Expand Down

0 comments on commit eec29b4

Please sign in to comment.