Skip to content

Commit

Permalink
Merge pull request hapifhir#1534 from hapifhir/2024-01-gg-tx-server-r…
Browse files Browse the repository at this point in the history
…ework

Refactor Context to support multiple terminology services
  • Loading branch information
grahamegrieve authored Jan 8, 2024
2 parents cdfd941 + 3e2039a commit 2bae733
Show file tree
Hide file tree
Showing 34 changed files with 801 additions and 213 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ major upgrade to validation - use terminology server to perform more logic, and
* R6 release support
* IPS tool development
* Improved errors publishing IGs
* Refactor Context to support multiple terminology services
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS

import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_14_50;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_14_50;
import org.hl7.fhir.convertors.txClient.TerminologyClientFactory;
import org.hl7.fhir.dstu2016may.formats.JsonParser;
import org.hl7.fhir.dstu2016may.formats.XmlParser;
import org.hl7.fhir.dstu2016may.model.Resource;
Expand All @@ -49,6 +50,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
import org.hl7.fhir.r5.terminologies.client.TerminologyClientManager.ITerminologyClientFactory;

public class R2016MayToR5Loader extends BaseLoaderR5 {

Expand Down Expand Up @@ -136,4 +138,9 @@ protected String versionString() {
return "4.3";
}

@Override
public ITerminologyClientFactory txFactory() {
return new TerminologyClientFactory(versionString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS

import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_50;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_50;
import org.hl7.fhir.convertors.txClient.TerminologyClientFactory;
import org.hl7.fhir.dstu2.formats.JsonParser;
import org.hl7.fhir.dstu2.formats.XmlParser;
import org.hl7.fhir.dstu2.model.Resource;
Expand All @@ -50,6 +51,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
import org.hl7.fhir.r5.terminologies.client.TerminologyClientManager.ITerminologyClientFactory;

public class R2ToR5Loader extends BaseLoaderR5 implements IContextResourceLoader {

Expand Down Expand Up @@ -140,4 +142,9 @@ protected String versionString() {
return "1.0";
}

@Override
public ITerminologyClientFactory txFactory() {
return new TerminologyClientFactory(versionString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS

import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_50;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_50;
import org.hl7.fhir.convertors.txClient.TerminologyClientFactory;
import org.hl7.fhir.dstu3.formats.JsonParser;
import org.hl7.fhir.dstu3.formats.XmlParser;
import org.hl7.fhir.dstu3.model.Resource;
Expand All @@ -50,6 +51,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
import org.hl7.fhir.r5.terminologies.client.TerminologyClientManager.ITerminologyClientFactory;

public class R3ToR5Loader extends BaseLoaderR5 implements IContextResourceLoader {

Expand Down Expand Up @@ -135,4 +137,9 @@ protected String versionString() {
return "3.0";
}

@Override
public ITerminologyClientFactory txFactory() {
return new TerminologyClientFactory(versionString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS

import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_40_50;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_40_50;
import org.hl7.fhir.convertors.txClient.TerminologyClientFactory;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4.formats.JsonParser;
import org.hl7.fhir.r4.formats.XmlParser;
Expand All @@ -51,6 +52,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
import org.hl7.fhir.r5.terminologies.client.TerminologyClientManager.ITerminologyClientFactory;
import org.hl7.fhir.utilities.VersionUtilities;

public class R4BToR5Loader extends BaseLoaderR5 implements IContextResourceLoader {
Expand Down Expand Up @@ -143,4 +145,9 @@ protected String versionString() {
}


@Override
public ITerminologyClientFactory txFactory() {
return new TerminologyClientFactory(versionString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS

import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_40_50;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_40_50;
import org.hl7.fhir.convertors.txClient.TerminologyClientFactory;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4.formats.JsonParser;
import org.hl7.fhir.r4.formats.XmlParser;
Expand All @@ -51,6 +52,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
import org.hl7.fhir.r5.terminologies.client.TerminologyClientManager.ITerminologyClientFactory;
import org.hl7.fhir.utilities.VersionUtilities;

public class R4ToR5Loader extends BaseLoaderR5 implements IContextResourceLoader {
Expand Down Expand Up @@ -144,4 +146,9 @@ protected String versionString() {
}


@Override
public ITerminologyClientFactory txFactory() {
return new TerminologyClientFactory(versionString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.List;
import java.util.UUID;

import org.hl7.fhir.convertors.txClient.TerminologyClientFactory;

/*
Copyright (c) 2011+, HL7, Inc.
All rights reserved.
Expand Down Expand Up @@ -47,6 +49,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
import org.hl7.fhir.r5.terminologies.client.TerminologyClientManager.ITerminologyClientFactory;

public class R5ToR5Loader extends BaseLoaderR5 {

Expand Down Expand Up @@ -128,4 +131,9 @@ protected String versionString() {
}


@Override
public ITerminologyClientFactory txFactory() {
return new TerminologyClientFactory(versionString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.List;
import java.util.UUID;

import org.hl7.fhir.convertors.txClient.TerminologyClientFactory;

/*
Copyright (c) 2011+, HL7, Inc.
All rights reserved.
Expand Down Expand Up @@ -47,6 +49,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
import org.hl7.fhir.r5.terminologies.client.TerminologyClientManager.ITerminologyClientFactory;

public class R6ToR5Loader extends BaseLoaderR5 {

Expand Down Expand Up @@ -120,5 +123,10 @@ protected String versionString() {
return "5.0";
}

@Override
public ITerminologyClientFactory txFactory() {
return new TerminologyClientFactory(versionString());
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,27 @@
import java.net.URISyntaxException;

import org.hl7.fhir.r5.terminologies.client.ITerminologyClient;
import org.hl7.fhir.r5.terminologies.client.TerminologyClientManager.ITerminologyClientFactory;
import org.hl7.fhir.r5.terminologies.client.TerminologyClientR5;
import org.hl7.fhir.utilities.FhirPublication;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.VersionUtilities;

public class TerminologyClientFactory {
public class TerminologyClientFactory implements ITerminologyClientFactory {

public static ITerminologyClient makeClient(String id, String url, String userAgent, FhirPublication v) throws URISyntaxException {
if (v == null)
return new TerminologyClientR5(id, checkEndsWith("/r4", url), userAgent);
switch (v) {
case DSTU2016May:
return new TerminologyClientR3(id, checkEndsWith("/r3", url), userAgent); // r3 is the least worst match
case DSTU1:
throw new Error("The version " + v + " is not currently supported");
case DSTU2:
return new TerminologyClientR2(id, checkEndsWith("/r2", url), userAgent);
case R4:
return new TerminologyClientR4(id, checkEndsWith("/r4", url), userAgent);
case R4B:
return new TerminologyClientR4(id, checkEndsWith("/r4", url), userAgent);
case R5:
return new TerminologyClientR5(id, checkEndsWith("/r4", url), userAgent); // r4 for now, since the terminology is currently the same
case STU3:
return new TerminologyClientR3(id, checkEndsWith("/r3", url), userAgent);
default:
throw new Error("The version " + v + " is not currently supported");
}
private String v;

public TerminologyClientFactory(FhirPublication v) {
super();
this.v = v == null ? null : v.toCode();
}

public TerminologyClientFactory(String version) {
super();
this.v = version;
}

public static ITerminologyClient makeClient(String id, String url, String userAgent, String v) throws URISyntaxException {
public ITerminologyClient makeClient(String id, String url, String userAgent) throws URISyntaxException {
if (v == null)
return new TerminologyClientR5(id, checkEndsWith("/r4", url), userAgent);
v = VersionUtilities.getMajMin(v);
Expand All @@ -57,7 +48,7 @@ public static ITerminologyClient makeClient(String id, String url, String userAg
throw new Error("The version " + v + " is not currently supported");
}

private static String checkEndsWith(String term, String url) {
private String checkEndsWith(String term, String url) {
if (url.endsWith(term))
return url;
if (Utilities.isTxFhirOrgServer(url)) {
Expand All @@ -66,4 +57,9 @@ private static String checkEndsWith(String term, String url) {
return url;
}

@Override
public String getVersion() {
return v;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,9 @@ public ITerminologyClient setContentLanguage(String lang) {
client.setContentLanguage(lang);
return this;
}

@Override
public int getUseCount() {
return client.getUseCount();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,10 @@ public ITerminologyClient setContentLanguage(String lang) {
client.setContentLanguage(lang);
return this;
}

@Override
public int getUseCount() {
return client.getUseCount();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,11 @@ public ITerminologyClient setContentLanguage(String lang) {
client.setContentLanguage(lang);
return this;
}

@Override
public int getUseCount() {
return client.getUseCount();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,22 @@ private static List<Arguments> getHttpAndHttpsArgs(String baseUrl, FhirPublicati
@ParameterizedTest
@MethodSource("data")
public void testMakeClient(String url, FhirPublication fhirPublication, String expectedAddress) throws URISyntaxException {
ITerminologyClient terminologyClient = TerminologyClientFactory.makeClient("id", url, "dummyUserAgent", fhirPublication);
ITerminologyClient terminologyClient = new TerminologyClientFactory(fhirPublication).makeClient("id", url, "dummyUserAgent");
assertEquals(expectedAddress, terminologyClient.getAddress());
}

@Test
public void testMakeClientDstu1Fails() throws URISyntaxException {
assertThrows(Error.class, () -> {
ITerminologyClient terminologyClient = TerminologyClientFactory.makeClient("id", "urldoesnotmatter", "dummyUserAgent", FhirPublication.DSTU1);
ITerminologyClient terminologyClient = new TerminologyClientFactory(FhirPublication.DSTU1).makeClient("id", "urldoesnotmatter", "dummyUserAgent");
}
);
}

@Test
public void testMakeClientNullFails() throws URISyntaxException {
assertThrows(Error.class, () -> {
ITerminologyClient terminologyClient = TerminologyClientFactory.makeClient("id", "urldoesnotmatter", "dummyUserAgent", FhirPublication.NULL);
ITerminologyClient terminologyClient = new TerminologyClientFactory(FhirPublication.NULL).makeClient("id", "urldoesnotmatter", "dummyUserAgent");
}
);
}
Expand Down
Loading

0 comments on commit 2bae733

Please sign in to comment.