From b898cfe59fadc8ae88d8c24169cc191953908cbf Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Tue, 14 Nov 2023 11:59:29 +1100 Subject: [PATCH] fix up VSAC import for large value sets --- .../fhir/convertors/misc/VSACImporter.java | 19 +++++++++++++++++++ .../org/hl7/fhir/r4/model/Parameters.java | 7 +++++++ .../java/org/hl7/fhir/r4/model/ValueSet.java | 10 ++++++++++ .../r4/utils/client/FHIRToolingClient.java | 11 +++++++++++ 4 files changed, 47 insertions(+) diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/VSACImporter.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/VSACImporter.java index ef54dd519..2842218c4 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/VSACImporter.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/VSACImporter.java @@ -13,10 +13,13 @@ import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.r4.formats.IParser.OutputStyle; import org.hl7.fhir.r4.formats.JsonParser; import org.hl7.fhir.r4.model.CapabilityStatement; +import org.hl7.fhir.r4.model.IntegerType; import org.hl7.fhir.r4.model.OperationOutcome; import org.hl7.fhir.r4.model.OperationOutcome.IssueSeverity; import org.hl7.fhir.r4.model.OperationOutcome.IssueType; +import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.ValueSet; +import org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent; import org.hl7.fhir.r4.utils.client.FHIRToolingClient; import org.hl7.fhir.r4.terminologies.JurisdictionUtilities; import org.hl7.fhir.utilities.CSVReader; @@ -63,6 +66,16 @@ public class VSACImporter extends OIDBasedValueSetImporter { errs.put(oid, "Expansion: " +e.getMessage()); System.out.println(e.getMessage()); } + while (isIncomplete(vs.getExpansion())) { + Parameters p = new Parameters(); + p.addParameter("offset", vs.getExpansion().getParameter("offset").getValueIntegerType().getValue() + vs.getExpansion().getParameter("count").getValueIntegerType().getValue()); + ValueSet vse = fhirToolingClient.expandValueset(vs.getUrl(), p); + vs.getExpansion().getContains().addAll(vse.getExpansion().getContains()); + vs.getExpansion().setParameter(vse.getExpansion().getParameter()); + } + vs.getExpansion().setOffsetElement(null); + vs.getExpansion().getParameter().clear(); + if (vs.hasTitle()) { if (vs.getTitle().equals(vs.getDescription())) { @@ -97,6 +110,12 @@ public class VSACImporter extends OIDBasedValueSetImporter { System.out.println("Done. " + i + " ValueSets"); } + private boolean isIncomplete(ValueSetExpansionComponent expansion) { + IntegerType c = expansion.getParameter("count").getValueIntegerType(); + IntegerType offset = expansion.getParameter("offset").getValueIntegerType(); + return c.getValue() + offset.getValue() < expansion.getTotal(); + } + private String makeValidName(String name) { StringBuilder b = new StringBuilder(); boolean upper = true; diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/Parameters.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/Parameters.java index ff9373106..8f1711cb0 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/Parameters.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/Parameters.java @@ -885,6 +885,13 @@ public class Parameters extends Resource implements IBaseParameters { return this; } + + public Parameters addParameter(String name, int i) { + addParameter().setName(name).setValue(new IntegerType(i)); + return this; + } + + public Parameters addParameter(String name, String s) { if (s != null) addParameter().setName(name).setValue(new StringType(s)); diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ValueSet.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ValueSet.java index 86fb59114..6a252670a 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ValueSet.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ValueSet.java @@ -3268,6 +3268,14 @@ public class ValueSet extends MetadataResource { } + public ValueSetExpansionParameterComponent getParameter(String name) { + for (ValueSetExpansionParameterComponent t : getParameter()) { + if (name.equals(t.getName())) { + return t; + } + } + return null; + } } @Block() @@ -6241,6 +6249,8 @@ public class ValueSet extends MetadataResource { return ResourceType.ValueSet; } + + /** * Search parameter: date *

diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/FHIRToolingClient.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/FHIRToolingClient.java index 3b3b2ad46..168400b2a 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/FHIRToolingClient.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/FHIRToolingClient.java @@ -383,6 +383,17 @@ public class FHIRToolingClient { public ValueSet expandValueset(String vsUrl, Parameters expParams) { Map parameters = new HashMap<>(); parameters.put("url", vsUrl); + if (expParams != null) { + for (ParametersParameterComponent p : expParams.getParameter()) { + if (p.getValue() == null) { + throw new FHIRException("Non-value Parameters are not supported for parameter '"+p.getName()+"'"); + } else if (p.getValue() instanceof PrimitiveType) { + parameters.put(p.getName(), p.getValue().primitiveValue()); + } else { + throw new FHIRException("Complex Parameters are not supported for parameter '"+p.getName()+"'"); + } + } + } org.hl7.fhir.r4.utils.client.network.ResourceRequest result = null; try {