fix bug when canonical resource has no URL

This commit is contained in:
Grahame Grieve 2020-07-22 06:59:53 +10:00
parent 6421226011
commit 701ac1b560
2 changed files with 59 additions and 51 deletions

View File

@ -591,56 +591,63 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
Parameters p = expParameters.copy();
return expandVS(vs, cacheOk, heirarchical, p);
}
public ValueSetExpansionOutcome expandVS(ValueSet vs, boolean cacheOk, boolean heirarchical, Parameters p) {
if (p == null)
if (p == null) {
throw new Error(formatMessage(I18nConstants.NO_PARAMETERS_PROVIDED_TO_EXPANDVS));
}
if (vs.hasExpansion()) {
return new ValueSetExpansionOutcome(vs.copy());
}
if (!vs.hasUrl())
if (!vs.hasUrl()) {
throw new Error(formatMessage(I18nConstants.NO_VALUE_SET_IN_URL));
CacheToken cacheToken = txCache.generateExpandToken(vs, heirarchical);
ValueSetExpansionOutcome res;
if (cacheOk) {
res = txCache.getExpansion(cacheToken);
if (res != null)
return res;
}
p.setParameter("includeDefinition", false);
p.setParameter("excludeNested", !heirarchical);
// ok, first we try to expand locally
try {
ValueSetExpanderSimple vse = new ValueSetExpanderSimple(this);
res = vse.doExpand(vs, p);
if (!res.getValueset().hasUrl())
throw new Error(formatMessage(I18nConstants.NO_URL_IN_EXPAND_VALUE_SET));
txCache.cacheExpansion(cacheToken, res, TerminologyCache.TRANSIENT);
}
CacheToken cacheToken = txCache.generateExpandToken(vs, heirarchical);
ValueSetExpansionOutcome res;
if (cacheOk) {
res = txCache.getExpansion(cacheToken);
if (res != null) {
return res;
} catch (Exception e) {
}
// if that failed, we try to expand on the server
if (noTerminologyServer)
return new ValueSetExpansionOutcome(formatMessage(I18nConstants.ERROR_EXPANDING_VALUESET_RUNNING_WITHOUT_TERMINOLOGY_SERVICES), TerminologyServiceErrorClass.NOSERVICE);
Map<String, String> params = new HashMap<String, String>();
params.put("_limit", Integer.toString(expandCodesLimit ));
params.put("_incomplete", "true");
tlog("$expand on "+txCache.summary(vs));
try {
ValueSet result = txClient.expandValueset(vs, p, params);
if (!result.hasUrl())
result.setUrl(vs.getUrl());
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).setTxLink(txLog == null ? null : txLog.getLastId());
}
p.setParameter("includeDefinition", false);
p.setParameter("excludeNested", !heirarchical);
// ok, first we try to expand locally
try {
ValueSetExpanderSimple vse = new ValueSetExpanderSimple(this);
res = vse.doExpand(vs, p);
if (!res.getValueset().hasUrl()) {
throw new Error(formatMessage(I18nConstants.NO_URL_IN_EXPAND_VALUE_SET));
}
txCache.cacheExpansion(cacheToken, res, TerminologyCache.PERMANENT);
txCache.cacheExpansion(cacheToken, res, TerminologyCache.TRANSIENT);
return res;
} catch (Exception e) {
}
// if that failed, we try to expand on the server
if (noTerminologyServer) {
return new ValueSetExpansionOutcome(formatMessage(I18nConstants.ERROR_EXPANDING_VALUESET_RUNNING_WITHOUT_TERMINOLOGY_SERVICES), TerminologyServiceErrorClass.NOSERVICE);
}
Map<String, String> params = new HashMap<String, String>();
params.put("_limit", Integer.toString(expandCodesLimit ));
params.put("_incomplete", "true");
tlog("$expand on "+txCache.summary(vs));
try {
ValueSet result = txClient.expandValueset(vs, p, params);
if (!result.hasUrl()) {
result.setUrl(vs.getUrl());
}
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).setTxLink(txLog == null ? null : txLog.getLastId());
}
txCache.cacheExpansion(cacheToken, res, TerminologyCache.PERMANENT);
return res;
}

View File

@ -25,7 +25,7 @@ import com.google.gson.JsonObject;
public class PackageHacker {
public static void main(String[] args) throws FileNotFoundException, IOException {
new PackageHacker().edit("M:\\web\\hl7.org\\fhir\\R4\\package.tgz");
new PackageHacker().edit("M:\\web\\terminology.hl7.org\\hl7.terminology.r3.tgz");
}
private void edit(String name) throws FileNotFoundException, IOException {
@ -57,21 +57,22 @@ public class PackageHacker {
private void change(JsonObject npm, Map<String, byte[]> content) throws FileNotFoundException, IOException {
// fixVersions(npm);
// npm.addProperty("name", "hl7.terminology");
// npm.remove("version");
// npm.addProperty("version", "4.2.0");
// npm.remove("name");
// npm.addProperty("name", "hl7.terminology.r5");
npm.remove("version");
npm.addProperty("version", "1.0.0");
// npm.remove("canonical");
// npm.addProperty("canonical", "http://hl7.org/fhir/us/davinci-drug-formulary");
//// npm.remove("description");
//// npm.addProperty("description", "Group Wrapper that includes all the R4 packages");
// npm.remove("url");
// npm.addProperty("url", "http://hl7.org/fhir/us/davinci-drug-formulary/Jun2019");
JsonObject dep = new JsonObject();
npm.add("dependencies", dep);
dep.addProperty("hl7.fhir.r4.core", "4.0.1");
dep.addProperty("hl7.fhir.r4.examples", "4.0.1");
dep.addProperty("hl7.fhir.r4.expansions", "4.0.1");
dep.addProperty("hl7.fhir.r4.elements", "4.0.1");
// npm.addProperty("url", "https://terminology.hl7.org/1.0.0/");
// JsonObject dep = new JsonObject();
// npm.add("dependencies", dep);
// dep.addProperty("hl7.fhir.r4.core", "4.0.1");
// dep.addProperty("hl7.fhir.r4.examples", "4.0.1");
// dep.addProperty("hl7.fhir.r4.expansions", "4.0.1");
// dep.addProperty("hl7.fhir.r4.elements", "4.0.1");
}
private void fixVersions(JsonObject npm) {