From c6d1ff1fa0b5368c024a84585f55c53a2032f709 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Thu, 5 May 2022 05:41:32 +1000 Subject: [PATCH 1/3] Handle invalid HTTP responses better --- .../hl7/fhir/utilities/SimpleHTTPClient.java | 8 +- .../hl7/fhir/validation/ipa/IPAValidator.java | 84 +++++++++++++++++++ 2 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ipa/IPAValidator.java diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/SimpleHTTPClient.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/SimpleHTTPClient.java index 25d671c95..bca68df6a 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/SimpleHTTPClient.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/SimpleHTTPClient.java @@ -71,8 +71,12 @@ public class SimpleHTTPClient { public void checkThrowException() throws IOException { if (code >= 300) { String filename = Utilities.path("[tmp]", "fhir-http-"+(++counter)+".log"); - TextFile.bytesToFile(content, filename); - throw new IOException("Invalid HTTP response "+code+" from "+source+" ("+message+") (content in "+filename+")"); + if (content.length == 0) { + throw new IOException("Invalid HTTP response "+code+" from "+source+" ("+message+") (no content)"); + } else { + TextFile.bytesToFile(content, filename); + throw new IOException("Invalid HTTP response "+code+" from "+source+" ("+message+") (content in "+filename+")"); + } } } } diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ipa/IPAValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ipa/IPAValidator.java new file mode 100644 index 000000000..f2ddf4332 --- /dev/null +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ipa/IPAValidator.java @@ -0,0 +1,84 @@ +package org.hl7.fhir.validation.ipa; + +import java.util.List; + +import org.hl7.fhir.r4.model.Patient; +import org.hl7.fhir.validation.instance.InstanceValidator; + +/** + * You give this validator three parameters: + * URL of server + * access token for the server (most be already logged in) + * patient ID - the patient ID that was authorised by the log in + * + * @author grahamegrieve + * + */ +public class IPAValidator { + + private String address; + private String token; + private String urn; + private InstanceValidator validator; + + public IPAValidator(String address, String token, String urn, InstanceValidator validator) { + super(); + this.address = address; + this.token = token; + this.urn = urn; + this.validator = validator; + } + + public String getAddress() { + return address; + } + public void setAddress(String address) { + this.address = address; + } + public String getToken() { + return token; + } + public void setToken(String token) { + this.token = token; + } + public String getUrn() { + return urn; + } + public void setUrn(String urn) { + this.urn = urn; + } + public InstanceValidator getValidator() { + return validator; + } + public void setValidator(InstanceValidator validator) { + this.validator = validator; + } + + public void validate() { + List patients = searchPatients(); + // check list of patients that have access to + // require that at least one of the patients matches the URL + // validate all resources and links + // validate search parameters + // check self links + +// AllergyIntolerance patient patient+clinical-status +// Condition patient patient+category, patient+clinical-status, patient+code, patient+onset-date, patient+category+clinical_status +// DocumentReference _id, patient, patient+category, patient+type patient+category+date, patient+status, patient+type+period +// Immunization patient patient+date, patient+status +// MedicationRequest patient patient+intent, patient+intent+authoredon, patient+intent+status +// MedicationStatement subject subject+status +// Observation patient+category, patient+code, patient+category+date patient+category+status, patient+code+date +// Patient _id, identifier birthdate, family, gender, given, name, family+gender, birthdate+family, birthdate+name, gender+name + + + + + + } + + private List searchPatients() { + + return null; + } +} From df71644ba5ca7affcb3bf29ee70a24460f678fda Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Thu, 5 May 2022 05:47:54 +1000 Subject: [PATCH 2/3] Fix NPEs --- .../hl7/fhir/r5/comparison/CodeSystemComparer.java | 2 +- .../hl7/fhir/r5/conformance/ProfileUtilities.java | 3 +++ .../org/hl7/fhir/r5/context/SimpleWorkerContext.java | 12 +++++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/CodeSystemComparer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/CodeSystemComparer.java index a78b1c324..ced654a50 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/CodeSystemComparer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/comparison/CodeSystemComparer.java @@ -422,7 +422,7 @@ public class CodeSystemComparer extends CanonicalResourceComparer { ConceptPropertyComponent cp = null; if (cd != null) { for (ConceptPropertyComponent t : cd.getProperty()) { - if (t.getCode().equals(c)) { + if (t.hasCode() && t.getCode().equals(c)) { cp = t; } } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java index 32fc567ae..50d12aef1 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java @@ -3800,6 +3800,9 @@ public class ProfileUtilities extends TranslatingUtilities { if (contentReference.contains("#")) { String url = contentReference.substring(0, contentReference.indexOf("#")); contentReference = contentReference.substring(contentReference.indexOf("#")); + if (Utilities.noString(url)) { + url = source.getUrl(); + } if (!url.equals(source.getUrl())) { source = context.fetchResource(StructureDefinition.class, url); if (source == null) { diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/SimpleWorkerContext.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/SimpleWorkerContext.java index 5f3d46224..1eca40e1a 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/SimpleWorkerContext.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/SimpleWorkerContext.java @@ -490,11 +490,13 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon types = new String[] { "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem", "Measures" }; } for (PackageResourceInformation pri : pi.listIndexedResources(types)) { - try { - registerResourceFromPackage(new PackageResourceLoader(pri, loader), new PackageVersion(pi.id(), pi.version(), pi.dateAsDate())); - t++; - } catch (FHIRException e) { - throw new FHIRException(formatMessage(I18nConstants.ERROR_READING__FROM_PACKAGE__, pri.getFilename(), pi.name(), pi.version(), e.getMessage()), e); + if (!pri.getFilename().contains("ig-r4")) { + try { + registerResourceFromPackage(new PackageResourceLoader(pri, loader), new PackageVersion(pi.id(), pi.version(), pi.dateAsDate())); + t++; + } catch (FHIRException e) { + throw new FHIRException(formatMessage(I18nConstants.ERROR_READING__FROM_PACKAGE__, pri.getFilename(), pi.name(), pi.version(), e.getMessage()), e); + } } } } From 3bc1f4bb3872b86f8f5de880a35ce05f7932a62b Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Thu, 5 May 2022 07:56:10 +1000 Subject: [PATCH 3/3] release notes --- RELEASE_NOTES.md | 4 ++-- .../hl7/fhir/utilities/npm/PackageHacker.java | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 7b06c6ab5..b2cf9edac 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,7 +1,7 @@ ## Validator Changes -* no changes +* Handle invalid HTTP responses better when accessing packages ## Other code changes -* no changes \ No newline at end of file +* Fix various rendering NPEs \ No newline at end of file diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/PackageHacker.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/PackageHacker.java index cd05c17fa..df8dec017 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/PackageHacker.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/PackageHacker.java @@ -27,7 +27,7 @@ public class PackageHacker { private static boolean useSecureReferences = false; public static void main(String[] args) throws FileNotFoundException, IOException { - new PackageHacker().edit("M:\\web\\hl7.org\\fhir\\5.0.0-snapshot1\\hl7.fhir.r5.examples.tgz"); + new PackageHacker().edit("/Users/grahamegrieve/work/test-cases/validator/swiss.mednet.fhir#0.5.0.tgz"); } private void edit(String name) throws FileNotFoundException, IOException { @@ -59,7 +59,7 @@ public class PackageHacker { private void change(JsonObject npm, Map content) throws FileNotFoundException, IOException { fixVersions(npm); - npm.remove("notForPublication"); +// npm.remove("notForPublication"); // npm.addProperty("url", "http://hl7.org/fhir/us/carin-rtpbc/STU1"); // npm.remove("name"); // npm.addProperty("name", "hl7.fhir.uv.smart-app-launch"); @@ -69,10 +69,14 @@ public class PackageHacker { //// npm.addProperty("description", "Group Wrapper that includes all the R4 packages"); // npm.remove("url"); // npm.addProperty("url", "https://terminology.hl7.org/1.0.0/"); -// npm.remove("dependencies"); -// JsonObject dep = new JsonObject(); -// npm.add("dependencies", dep); -// dep.addProperty("hl7.fhir.r3.core", "3.0.1"); + npm.remove("dependencies"); + JsonObject dep = new JsonObject(); + npm.add("dependencies", dep); + dep.addProperty("hl7.fhir.r4.core", "4.0.1"); + dep.addProperty("ch.fhir.ig.ch-core", "2.0.0"); + dep.addProperty("ch.fhir.ig.ch-epr-term", "2.0.4"); + dep.addProperty("ch.fhir.ig.ch-emed","2.0.0"); + // 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");