Skip to content

Commit

Permalink
Fixes for changes to core - BOM handling and terminology stack rework
Browse files Browse the repository at this point in the history
  • Loading branch information
Grahame Grieve committed Jan 29, 2024
1 parent f3f8332 commit eabe071
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private void addAllResourcesChoice(Definitions definitions, JsonObject schema, L
private void save(JsonObject s, String filename) throws IOException {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(s);
TextFile.stringToFile(json, filename, false); // remove BOM, see https://chat.fhir.org/#narrow/stream/implementers/subject/Removal.20of.20byte.20order.20mark.20in.20json.20schemas
TextFile.stringToFile(json, filename); // remove BOM, see https://chat.fhir.org/#narrow/stream/implementers/subject/Removal.20of.20byte.20order.20mark.20in.20json.20schemas
}

private void produceCombinedSchema(Definitions definitions, String xsdDir, String dstDir, String srcDir) throws Exception {
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/org/hl7/fhir/tools/publisher/BuildWorkerContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.fhir.ucum.UcumEssenceService;
import org.fhir.ucum.UcumException;
import org.fhir.ucum.UcumService;
import org.hl7.fhir.convertors.txClient.TerminologyClientR5;
import org.hl7.fhir.definitions.model.Definitions;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
Expand Down Expand Up @@ -62,6 +61,7 @@
import org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent;
import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent;
import org.hl7.fhir.r5.terminologies.client.ITerminologyClient;
import org.hl7.fhir.r5.terminologies.client.TerminologyClientR5;
import org.hl7.fhir.r5.terminologies.utilities.ValidationResult;
import org.hl7.fhir.r5.utils.client.EFhirClientException;
import org.hl7.fhir.r5.utils.validation.IResourceValidator;
Expand Down Expand Up @@ -129,11 +129,12 @@ public class BuildWorkerContext extends BaseWorkerContext implements IWorkerCont

public BuildWorkerContext(Definitions definitions, String terminologyCachePath, ITerminologyClient client, CanonicalResourceManager<CodeSystem> codeSystems, CanonicalResourceManager<ValueSet> valueSets, CanonicalResourceManager<ConceptMap> maps, CanonicalResourceManager<StructureDefinition> profiles, CanonicalResourceManager<ImplementationGuide> guides, String folder) throws UcumException, ParserConfigurationException, SAXException, IOException, FHIRException {
super(codeSystems, valueSets, maps, profiles, guides);
initTS(terminologyCachePath);
initTxCache(terminologyCachePath);
this.definitions = definitions;
this.tcc.setClient(client);
this.terminologyClientManager.setMasterClient(client);
this.terminologyClientManager.setUsage("publication");
this.txLog = new HTMLClientLogger(null);
setExpansionProfile(buildExpansionProfile());
setExpansionParameters(buildExpansionProfile());
this.setTranslator(new TranslatorXml(Utilities.path(folder, "implementations", "translations.xml")));
setWarnAboutMissingMessages(false);
}
Expand All @@ -149,11 +150,11 @@ private Parameters buildExpansionProfile() {
}

public boolean hasClient() {
return tcc.getClient() != null;
return terminologyClientManager.hasClient();
}

public ITerminologyClient getClient() {
return tcc.getClient();
return terminologyClientManager.getMasterClient();
}

public StructureDefinition getExtensionStructure(StructureDefinition context, String url) throws Exception {
Expand Down Expand Up @@ -559,14 +560,14 @@ private String lookupLoinc(String code) throws Exception {
try {
triedServer = true;
// for this, we use the FHIR client
if (tcc.getClient() == null) {
tcc.setClient(new TerminologyClientR5("tx.fhir.org", tcc.getServer(), "fhir/main-build"));
if (terminologyClientManager.getMasterClient() == null) {
terminologyClientManager.setMasterClient(new TerminologyClientR5("tx-dev.fhir.org", "?", "fhir/main-build"));
this.txLog = new HTMLClientLogger(null);
}
Map<String, String> params = new HashMap<String, String>();
params.put("code", code);
params.put("system", "http://loinc.org");
Parameters result = tcc.getClient().lookupCode(params);
Parameters result = terminologyClientManager.getMasterClient().lookupCode(params);

for (ParametersParameterComponent p : result.getParameter()) {
if (p.getName().equals("display"))
Expand Down
39 changes: 35 additions & 4 deletions src/main/java/org/hl7/fhir/tools/publisher/ExampleInspector.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -53,6 +54,10 @@
import org.hl7.fhir.r5.utils.validation.IResourceValidator;
import org.hl7.fhir.r5.utils.validation.IValidationPolicyAdvisor;
import org.hl7.fhir.r5.utils.validation.IValidatorResourceFetcher;
import org.hl7.fhir.r5.utils.validation.IValidationPolicyAdvisor.AdditionalBindingPurpose;
import org.hl7.fhir.r5.utils.validation.IValidationPolicyAdvisor.CodedContentValidationAction;
import org.hl7.fhir.r5.utils.validation.IValidationPolicyAdvisor.ElementValidationAction;
import org.hl7.fhir.r5.utils.validation.IValidationPolicyAdvisor.ResourceValidationAction;
import org.hl7.fhir.r5.utils.validation.constants.BestPracticeWarningLevel;
import org.hl7.fhir.r5.utils.validation.constants.BindingKind;
import org.hl7.fhir.r5.utils.validation.constants.CodedContentValidationPolicy;
Expand Down Expand Up @@ -696,18 +701,44 @@ public ReferenceValidationPolicy policyForReference(IResourceValidator validator


@Override
public ContainedReferenceValidationPolicy policyForContained(IResourceValidator validator, Object appContext, String containerType, String containerId, SpecialElement containingResourceType, String path, String url) {
public ContainedReferenceValidationPolicy policyForContained(IResourceValidator validator,
Object appContext,
StructureDefinition structure,
ElementDefinition element,
String containerType,
String containerId,
Element.SpecialElement containingResourceType,
String path,
String url) {
return ContainedReferenceValidationPolicy.CHECK_VALID;
}


@Override
public CodedContentValidationPolicy policyForCodedContent(IResourceValidator validator, Object appContext, String stackPath, ElementDefinition definition,
StructureDefinition structure, BindingKind kind, ValueSet valueSet, List<String> systems) {
return CodedContentValidationPolicy.VALUESET;
public EnumSet<CodedContentValidationAction> policyForCodedContent(IResourceValidator validator,
Object appContext,
String stackPath,
ElementDefinition definition,
StructureDefinition structure,
BindingKind kind,
AdditionalBindingPurpose purpose,
ValueSet valueSet,
List<String> systems) {
return EnumSet.allOf(CodedContentValidationAction.class);
}


@Override
public EnumSet<ResourceValidationAction> policyForResource(IResourceValidator validator, Object appContext,
StructureDefinition type, String path) {
return EnumSet.allOf(ResourceValidationAction.class);
}

@Override
public EnumSet<ElementValidationAction> policyForElement(IResourceValidator validator, Object appContext,
StructureDefinition structure, ElementDefinition element, String path) {
return EnumSet.allOf(ElementValidationAction.class);
}
public List<ValidationMessage> getErrors() {
return errorsInt;
}
Expand Down
23 changes: 11 additions & 12 deletions src/main/java/org/hl7/fhir/tools/publisher/PageProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.hl7.fhir.convertors.SpecDifferenceEvaluator;
import org.hl7.fhir.convertors.TypeLinkProvider;
import org.hl7.fhir.convertors.loaders.loaderR5.R4ToR5Loader;
import org.hl7.fhir.convertors.txClient.TerminologyClientR5;
import org.hl7.fhir.definitions.Config;
import org.hl7.fhir.definitions.generators.specification.BaseGenerator;
import org.hl7.fhir.definitions.generators.specification.DataTypeTableGenerator;
Expand Down Expand Up @@ -224,6 +223,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.hl7.fhir.r5.terminologies.TerminologyCacheManager;
import org.hl7.fhir.r5.terminologies.ValueSetUtilities;
import org.hl7.fhir.r5.terminologies.client.ITerminologyClient;
import org.hl7.fhir.r5.terminologies.client.TerminologyClientR5;
import org.hl7.fhir.r5.terminologies.expansion.ValueSetExpansionOutcome;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.r5.utils.Translations;
Expand Down Expand Up @@ -532,8 +532,6 @@ public PageProcessor(String tsServer) throws URISyntaxException, UcumException {
private static final String REASON_UNKNOWN = "Unknown";
private static final String UNNOWN_DESCRIPTION = "no reason provided";
public static final String CODE_LIMIT_EXPANSION = "1000";
public static final String TOO_MANY_CODES_TEXT_NOT_EMPTY = "This value set has >1000 codes in it. In order to keep the publication size manageable, only a selection (1000 codes) of the whole set of codes is shown";
public static final String TOO_MANY_CODES_TEXT_EMPTY = "This value set cannot be expanded because of the way it is defined - it has an infinite number of members";
private static final String NO_CODESYSTEM_TEXT = "This value set refers to code systems that the FHIR Publication Tooling does not support";

private static final String VS_INC_START = ""; // "<div style=\"background-color: Floralwhite; border:1px solid maroon; padding: 5px;\">";
Expand Down Expand Up @@ -2316,7 +2314,7 @@ public void updateDiffEngineDefinitions() {
if (vs.hasUserData("expansion"))
evs = (ValueSet) vs.getUserData("expansion");
else {
ValueSetExpansionOutcome vse = getWorkerContext().expandVS(vs, true, false);
ValueSetExpansionOutcome vse = getWorkerContext().expandVS(vs, true, false, true);
if (vse.getValueset() != null) {
evs = vse.getValueset();
vs.setUserData("expansion", evs);
Expand Down Expand Up @@ -2730,7 +2728,7 @@ private String umlForDt(String dt, String id) throws Exception {
String s = "\r\n[diagram]\r\n"+
"classes="+dt+"\r\n"+
"element-attributes=true\r\n";
TextFile.stringToFileNoPrefix(s, tmp.getAbsolutePath());
TextFile.stringToFile(s, tmp.getAbsolutePath());
return new SvgGenerator(this, "", null, false, "", version).generate(tmp.getAbsolutePath(), id);
} finally {
tmp.delete();
Expand Down Expand Up @@ -5415,7 +5413,7 @@ private String expandValueSetIG(ValueSet vs, boolean heirarchy) throws Exception
exp.setCompose(null);
exp.setText(null);
exp.setDescription("Value Set Contents (Expansion) for "+vs.present()+" at "+Config.DATE_FORMAT().format(new Date()));
RenderingContext lrc = rc.copy().setTooCostlyNoteEmpty(TOO_MANY_CODES_TEXT_EMPTY).setTooCostlyNoteNotEmpty(TOO_MANY_CODES_TEXT_NOT_EMPTY);
RenderingContext lrc = rc.copy();
RendererFactory.factory(exp, lrc).render(exp);
return "<hr/>\r\n"+VS_INC_START+""+new XhtmlComposer(XhtmlComposer.HTML).compose(exp.getText().getDiv())+VS_INC_END;
} catch (Exception e) {
Expand All @@ -5425,7 +5423,7 @@ private String expandValueSetIG(ValueSet vs, boolean heirarchy) throws Exception

private String processExpansionError(String error) {
if (error.contains("Too many codes"))
return TOO_MANY_CODES_TEXT_NOT_EMPTY;
return "This value set has >1000 codes in it. In order to keep the publication size manageable, only a selection (1000 codes) of the whole set of codes is shown";
if (error.contains("unable to provide support"))
return NO_CODESYSTEM_TEXT;
return "This value set could not be expanded by the publication tooling: "+Utilities.escapeXml(error);
Expand Down Expand Up @@ -5477,7 +5475,7 @@ private String vsCLD(String fileTitle, ValueSet vs, String prefix) throws Except
vs1.setExpansion(null);
vs1.setText(null);
ImplementationGuideDefn ig = (ImplementationGuideDefn) vs.getUserData(ToolResourceUtilities.NAME_RES_IG);
RenderingContext lrc = rc.copy().setLocalPrefix(prefix).setTooCostlyNoteNotEmpty(TOO_MANY_CODES_TEXT_NOT_EMPTY);
RenderingContext lrc = rc.copy().setLocalPrefix(prefix);
RendererFactory.factory(vs1, lrc).render(vs1);
return "<hr/>\r\n"+VS_INC_START+""+new XhtmlComposer(XhtmlComposer.HTML).compose(vs1.getText().getDiv())+VS_INC_END;
}
Expand Down Expand Up @@ -11352,7 +11350,7 @@ private ElementDefn getElementDefn(String n) throws Exception {
public String expandVS(ValueSet vs, String prefix, String base) {
try {

ValueSetExpansionOutcome result = workerContext.expandVS(vs, true, true);
ValueSetExpansionOutcome result = workerContext.expandVS(vs, true, true, true);
if (result.getError() != null)
return "<hr/>\r\n"+VS_INC_START+"<!--3-->"+processExpansionError(result.getError())+VS_INC_END;

Expand All @@ -11369,11 +11367,12 @@ public String expandVS(ValueSet vs, String prefix, String base) {
IniFile sini = new IniFile(Utilities.path(folders.rootDir, "temp", "stats.ini"));
sini.setIntegerProperty("valuesets", vs.getId(), i, null);
sini.save();
RenderingContext lrc = rc.copy().setLocalPrefix(prefix).setTooCostlyNoteEmpty(TOO_MANY_CODES_TEXT_EMPTY).setTooCostlyNoteNotEmpty(TOO_MANY_CODES_TEXT_NOT_EMPTY);
RenderingContext lrc = rc.copy().setLocalPrefix(prefix);
RendererFactory.factory(exp, lrc).render(exp);
return "<hr/>\r\n"+VS_INC_START+""+new XhtmlComposer(XhtmlComposer.HTML).compose(exp.getText().getDiv())+VS_INC_END;
} catch (Exception e) {
e.printStackTrace();
// e.printStackTrace();
System.err.println(e.getMessage());
return "<hr/>\r\n"+VS_INC_START+"<!--5-->"+processExpansionError(e instanceof NullPointerException ? "NullPointerException" : e.getMessage())+" "+Utilities.escapeXml(stack(e))+VS_INC_END;
}
}
Expand Down Expand Up @@ -12423,7 +12422,7 @@ public void setExtensionsLocation(String extensionsLocation) {

@Override
public boolean isDebugLogging() {
return true;
return false;
}

@Override
Expand Down
Loading

0 comments on commit eabe071

Please sign in to comment.