Skip to content

Commit

Permalink
Merge pull request #1862 from hapifhir/2024-12-gg-r2-bye-bye
Browse files Browse the repository at this point in the history
2024 12 gg r2 bye bye
  • Loading branch information
grahamegrieve authored Dec 17, 2024
2 parents 9cce17d + eb4981c commit eff515e
Show file tree
Hide file tree
Showing 11 changed files with 534 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,54 @@ public ValueSetExpansionOutcome expandVS(ValueSet vs, boolean cacheOk, boolean h
return expandVS(vs, cacheOk, heirarchical, false, p);
}

@Override
public ValueSetExpansionOutcome expandVS(String url, boolean cacheOk, boolean hierarchical, int count) {
if (expParameters == null)
throw new Error(formatMessage(I18nConstants.NO_EXPANSION_PARAMETERS_PROVIDED));
if (noTerminologyServer) {
return new ValueSetExpansionOutcome(formatMessage(I18nConstants.ERROR_EXPANDING_VALUESET_RUNNING_WITHOUT_TERMINOLOGY_SERVICES), TerminologyServiceErrorClass.NOSERVICE, null, false);
}

Parameters p = expParameters.copy();
p.addParameter("count", count);
p.addParameter("url", new UriType(url));
p.setParameter("_limit",new IntegerType("10000"));
p.setParameter("_incomplete", new BooleanType("true"));

CacheToken cacheToken = txCache.generateExpandToken(url, hierarchical);
ValueSetExpansionOutcome res;
if (cacheOk) {
res = txCache.getExpansion(cacheToken);
if (res != null) {
return res;
}
}
p.setParameter("excludeNested", !hierarchical);
List<String> allErrors = new ArrayList<>();

p.addParameter().setName("cache-id").setValue(new IdType(terminologyClientManager.getCacheId()));
TerminologyClientContext tc = terminologyClientManager.chooseServer(url, true);

txLog("$expand "+url+" on "+tc.getAddress());

try {
ValueSet result = tc.getClient().expandValueset(null, p);
if (result != null) {
if (!result.hasUrl()) {
result.setUrl(url);
}
if (!result.hasUrl()) {
throw new Error(formatMessage(I18nConstants.NO_URL_IN_EXPAND_VALUE_SET_2));
}
}
res = new ValueSetExpansionOutcome(result).setTxLink(txLog.getLastId());
} catch (Exception e) {
res = new ValueSetExpansionOutcome((e.getMessage() == null ? e.getClass().getName() : e.getMessage()), TerminologyServiceErrorClass.UNKNOWN, allErrors, true).setTxLink(txLog == null ? null : txLog.getLastId());
}
txCache.cacheExpansion(cacheToken, res, TerminologyCache.PERMANENT);
return res;
}

@Override
public ValueSetExpansionOutcome expandVS(ValueSet vs, boolean cacheOk, boolean heirarchical, boolean incompleteOk) {
if (expParameters == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ public String getUrl() {
*/
public ValueSetExpansionOutcome expandVS(ValueSet source, boolean cacheOk, boolean heiarchical, boolean incompleteOk);

public ValueSetExpansionOutcome expandVS(String uri, boolean cacheOk, boolean heiarchical, int count); // set to 0 to just check existence

/**
* ValueSet Expansion - see $expand, but resolves the binding first
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ public SimpleWorkerContext build() throws IOException {
}

private SimpleWorkerContext build(SimpleWorkerContext context) throws IOException {
if (VersionUtilities.isR2Ver(context.getVersion()) || VersionUtilities.isR2Ver(context.getVersion())) {
System.out.println("As of end 2024, FHIR R2 (version "+context.getVersion()+") is no longer officially supported.");
}
context.initTxCache(terminologyCachePath);
context.setUserAgent(userAgent);
context.setLogger(loggingService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
Expand Down Expand Up @@ -70,16 +72,25 @@ public void render(RenderingStatus status, XhtmlNode x, NamingSystem ns) throws
if (ns.hasCopyright()) {
addMarkdown(row(tbl, (context.formatPhrase(RenderingContext.GENERAL_COPYRIGHT))), ns.getCopyright());
}
List<NamingSystem> nsl = new ArrayList<>();
nsl.add(ns);
renderList(x, nsl);
}

public void renderList(XhtmlNode x, List<NamingSystem> nsl) {

boolean hasPreferred = false;
boolean hasPeriod = false;
boolean hasComment = false;
for (NamingSystemUniqueIdComponent id : ns.getUniqueId()) {
hasPreferred = hasPreferred || id.hasPreferred();
hasPeriod = hasPeriod || id.hasPeriod();
hasComment = hasComment || id.hasComment();
for (NamingSystem ns : nsl) {
for (NamingSystemUniqueIdComponent id : ns.getUniqueId()) {
hasPreferred = hasPreferred || id.hasPreferred();
hasPeriod = hasPeriod || id.hasPeriod();
hasComment = hasComment || id.hasComment();
}
}
x.h3().tx(context.formatPhrase(RenderingContext.NAME_SYS_IDEN));
tbl = x.table("grid");
XhtmlNode tbl = x.table("grid");
XhtmlNode tr = tbl.tr();
tr.td().b().tx((context.formatPhrase(RenderingContext.GENERAL_TYPE)));
tr.td().b().tx((context.formatPhrase(RenderingContext.GENERAL_VALUE)));
Expand All @@ -92,21 +103,24 @@ public void render(RenderingStatus status, XhtmlNode x, NamingSystem ns) throws
if (hasComment) {
tr.td().b().tx((context.formatPhrase(RenderingContext.GENERAL_COMMENT)));
}
for (NamingSystemUniqueIdComponent id : ns.getUniqueId()) {
tr = tbl.tr();
tr.td().tx(id.getType().getDisplay());
tr.td().tx(id.getValue());
if (hasPreferred) {
tr.td().tx(id.getPreferredElement().primitiveValue());
}
if (hasPeriod) {
tr.td().tx(displayDataType(id.getPeriod()));
}
if (hasComment) {
tr.td().tx(id.getComment());
}
}
for (NamingSystem ns : nsl) {
for (NamingSystemUniqueIdComponent id : ns.getUniqueId()) {
tr = tbl.tr();
tr.td().tx(id.getType().getDisplay());
tr.td().tx(id.getValue());
if (hasPreferred) {
tr.td().tx(id.getPreferredElement().primitiveValue());
}
if (hasPeriod) {
tr.td().tx(displayDataType(id.getPeriod()));
}
if (hasComment) {
tr.td().tx(id.getComment());
}
}
}
}


private XhtmlNode row(XhtmlNode tbl, String name) {
XhtmlNode tr = tbl.tr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ public ITerminologyClient getClient() {
}

public void seeUse(Set<String> systems, TerminologyClientContextUseType useType) {
for (String s : systems) {
seeUse(s, useType);
if (systems != null) {
for (String s : systems) {
seeUse(s, useType);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,37 @@ public TerminologyClientContext chooseServer(ValueSet vs, Set<String> systems, b
}
}

public TerminologyClientContext chooseServer(String vs, boolean expand) throws TerminologyServiceException {
if (serverList.isEmpty()) {
return null;
}
if (IGNORE_TX_REGISTRY || !useEcosystem) {
return findClient(getMasterClient().getAddress(), null, expand);
}
String request = Utilities.pathURL(monitorServiceURL, "resolve?fhirVersion="+factory.getVersion()+"&valueSet="+Utilities.URLEncode(vs));
if (usage != null) {
request = request + "&usage="+usage;
}
try {
JsonObject json = JsonParser.parseObjectFromUrl(request);
for (JsonObject item : json.getJsonObjects("authoritative")) {
return findClient(item.asString("url"), null, expand);
}
for (JsonObject item : json.getJsonObjects("candidates")) {
return findClient(item.asString("url"), null, expand);
}
} catch (Exception e) {
String msg = "Error resolving valueSet "+vs+": "+e.getMessage();
if (!hasMessage(msg)) {
internalLog.add(new InternalLogEvent(msg, vs, request));
}
if (logger.isDebugLogging()) {
e.printStackTrace();
}
}
return null;
}

private void log(ValueSet vs, String server, Set<String> systems, List<ServerOptionList> choices, String message) {
String svs = (vs == null ? "null" : vs.getVersionedUrl());
String sys = systems.isEmpty() ? "--" : systems.size() == 1 ? systems.iterator().next() : systems.toString();
Expand Down Expand Up @@ -550,7 +581,7 @@ public SourcedValueSet findValueSetOnServer(String canonical) {
}
}
if (server == null) {
return null;
server = getMasterClient().getAddress();
}
if (server.contains("://tx.fhir.org")) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,13 @@ public CacheToken generateExpandToken(ValueSet vs, boolean hierarchical) {
ct.key = String.valueOf(hashJson(ct.request));
return ct;
}

public CacheToken generateExpandToken(String url, boolean hierarchical) {
CacheToken ct = new CacheToken();
ct.request = "{\"hierarchical\" : "+(hierarchical ? "true" : "false")+", \"url\": \""+Utilities.escapeJson(url)+"\"}\r\n";
ct.key = String.valueOf(hashJson(ct.request));
return ct;
}

public void nameCacheToken(ValueSet vs, CacheToken ct) {
if (vs != null) {
Expand Down
Loading

0 comments on commit eff515e

Please sign in to comment.