From ef6f92a21ee24fb5176aec54f2701a6c6ec0b7c3 Mon Sep 17 00:00:00 2001 From: dotasek Date: Thu, 21 Sep 2023 09:50:08 -0400 Subject: [PATCH 01/13] WIP return validation fragments --- .../r5/elementmodel/ValidatedFragment.java | 5 ++++- .../hl7/fhir/validation/ValidationEngine.java | 13 +++++++----- .../cli/services/ValidationService.java | 21 +++++++++++++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ValidatedFragment.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ValidatedFragment.java index 63a78970f..42f6a7d24 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ValidatedFragment.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ValidatedFragment.java @@ -50,5 +50,8 @@ public class ValidatedFragment { public String getFilename() { return name+"."+extension; } - + + public String getExtension() { + return extension; + } } \ No newline at end of file diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java index 5d9da1fac..d1484a4b9 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java @@ -32,12 +32,8 @@ import org.hl7.fhir.r5.context.IWorkerContext; import org.hl7.fhir.r5.context.IWorkerContextManager; import org.hl7.fhir.r5.context.SimpleWorkerContext; import org.hl7.fhir.r5.context.SystemOutLoggingService; -import org.hl7.fhir.r5.elementmodel.Element; -import org.hl7.fhir.r5.elementmodel.Manager; +import org.hl7.fhir.r5.elementmodel.*; import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat; -import org.hl7.fhir.r5.elementmodel.ObjectConverter; -import org.hl7.fhir.r5.elementmodel.ParserBase; -import org.hl7.fhir.r5.elementmodel.SHCParser; import org.hl7.fhir.r5.formats.FormatUtilities; import org.hl7.fhir.r5.formats.IParser.OutputStyle; import org.hl7.fhir.r5.formats.JsonParser; @@ -635,6 +631,13 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP return results.getEntryFirstRep().getResource(); } + + public List validateAsFragments(byte[] source, FhirFormat cntType, List profiles, List messages) throws FHIRException, IOException, EOperationOutcome { + InstanceValidator validator = getValidator(cntType); + validator.validate(null, messages, new ByteArrayInputStream(source), cntType, asSdList(profiles)); + return validator.validatedContent; + } + public OperationOutcome validate(byte[] source, FhirFormat cntType, List profiles, List messages) throws FHIRException, IOException, EOperationOutcome { InstanceValidator validator = getValidator(cntType); diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java index f7ef45a47..eda673aa1 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java @@ -29,6 +29,7 @@ import org.hl7.fhir.r5.elementmodel.Element; import org.hl7.fhir.r5.elementmodel.LanguageUtils; import org.hl7.fhir.r5.elementmodel.Manager; import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat; +import org.hl7.fhir.r5.elementmodel.ValidatedFragment; import org.hl7.fhir.r5.formats.IParser; import org.hl7.fhir.r5.formats.IParser.OutputStyle; import org.hl7.fhir.r5.model.Bundle; @@ -116,11 +117,31 @@ public class ValidationService { for (FileInfo fp : request.getFilesToValidate()) { List messages = new ArrayList<>(); + + List validatedFragments = validator.validateAsFragments(fp.getFileContent().getBytes(), Manager.FhirFormat.getFhirFormat(fp.getFileType()), + request.getCliContext().getProfiles(), messages); + + // TODO this chunk does not work for multi-file validation, as the fileName is overwritten + for (ValidatedFragment validatedFragment : validatedFragments) { + ValidationOutcome outcome = new ValidationOutcome(); + FileInfo fileInfo = new FileInfo( + validatedFragment.getFilename(), + new String(validatedFragment.getContent()), + validatedFragment.getExtension()); + outcome.setMessages(validatedFragment.getErrors()); + outcome.setFileInfo(fileInfo); + response.addOutcome(outcome); + } + + //TODO the code below works correctly for multi-file validation. + /* validator.validate(fp.getFileContent().getBytes(), Manager.FhirFormat.getFhirFormat(fp.getFileType()), request.getCliContext().getProfiles(), messages); + ValidationOutcome outcome = new ValidationOutcome().setFileInfo(fp); messages.forEach(outcome::addMessage); response.addOutcome(outcome); + */ } System.out.println(" Max Memory: "+Runtime.getRuntime().maxMemory()); return response; From ba8a4797e55ea806301ea9d959aa84167e8b5cc5 Mon Sep 17 00:00:00 2001 From: dotasek Date: Thu, 21 Sep 2023 13:15:42 -0400 Subject: [PATCH 02/13] If fileType is null, use ResourceChecker --- .../cli/services/ValidationService.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java index eda673aa1..be7cc97e7 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java @@ -62,10 +62,7 @@ import org.hl7.fhir.utilities.i18n.XLIFFProducer; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; import org.hl7.fhir.utilities.npm.NpmPackage; import org.hl7.fhir.utilities.validation.ValidationMessage; -import org.hl7.fhir.validation.IgLoader; -import org.hl7.fhir.validation.ValidationEngine; -import org.hl7.fhir.validation.ValidationRecord; -import org.hl7.fhir.validation.ValidatorUtils; +import org.hl7.fhir.validation.*; import org.hl7.fhir.validation.ValidatorUtils.SourceFile; import org.hl7.fhir.validation.cli.model.CliContext; import org.hl7.fhir.validation.cli.model.FileInfo; @@ -115,10 +112,19 @@ public class ValidationService { ValidationResponse response = new ValidationResponse().setSessionId(sessionId); - for (FileInfo fp : request.getFilesToValidate()) { + for (FileInfo fileToValidate : request.getFilesToValidate()) { + if (fileToValidate.getFileType() == null) { + Manager.FhirFormat format = ResourceChecker.checkIsResource(validator.getContext(), + false, + fileToValidate.getFileContent().getBytes(), + fileToValidate.getFileName(), + false); + fileToValidate.setFileType(format.getExtension()); + } + List messages = new ArrayList<>(); - List validatedFragments = validator.validateAsFragments(fp.getFileContent().getBytes(), Manager.FhirFormat.getFhirFormat(fp.getFileType()), + List validatedFragments = validator.validateAsFragments(fileToValidate.getFileContent().getBytes(), Manager.FhirFormat.getFhirFormat(fileToValidate.getFileType()), request.getCliContext().getProfiles(), messages); // TODO this chunk does not work for multi-file validation, as the fileName is overwritten From c79fa084731df57d0631ee1b2ecfb13ed574dc96 Mon Sep 17 00:00:00 2001 From: dotasek Date: Thu, 21 Sep 2023 13:59:41 -0400 Subject: [PATCH 03/13] Refactor "focus" ValidatedFragment usage --- .../hl7/fhir/r5/elementmodel/FmlParser.java | 6 +- .../hl7/fhir/r5/elementmodel/JsonParser.java | 8 +-- .../fhir/r5/elementmodel/TurtleParser.java | 66 +++++++++---------- .../r5/elementmodel/ValidatedFragment.java | 2 + .../r5/elementmodel/VerticalBarParser.java | 58 ++++++++-------- .../hl7/fhir/r5/elementmodel/XmlParser.java | 12 ++-- 6 files changed, 77 insertions(+), 75 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/FmlParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/FmlParser.java index 3c0cbfa9b..b4f332982 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/FmlParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/FmlParser.java @@ -50,9 +50,9 @@ public class FmlParser extends ParserBase { ByteArrayInputStream stream = new ByteArrayInputStream(content); String text = TextFile.streamToString(stream); List result = new ArrayList<>(); - ValidatedFragment ctxt = new ValidatedFragment("focus", "fml", content); - ctxt.setElement(parse(ctxt.getErrors(), text)); - result.add(ctxt); + ValidatedFragment focusFragment = new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "fml", content); + focusFragment.setElement(parse(focusFragment.getErrors(), text)); + result.add(focusFragment); return result; } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java index 49e1900a7..c71fd4d3c 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java @@ -122,7 +122,7 @@ public class JsonParser extends ParserBase { public List parse(InputStream inStream) throws IOException, FHIRException { // long start = System.currentTimeMillis(); byte[] content = TextFile.streamToBytes(inStream); - ValidatedFragment ctxt = new ValidatedFragment("focus", "json", content); + ValidatedFragment focusFragment = new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "json", content); ByteArrayInputStream stream = new ByteArrayInputStream(content); @@ -134,17 +134,17 @@ public class JsonParser extends ParserBase { try { obj = org.hl7.fhir.utilities.json.parser.JsonParser.parseObject(source, true, true); } catch (Exception e) { - logError(ctxt.getErrors(), ValidationMessage.NO_RULE_DATE, -1, -1,context.formatMessage(I18nConstants.DOCUMENT), IssueType.INVALID, context.formatMessage(I18nConstants.ERROR_PARSING_JSON_, e.getMessage()), IssueSeverity.FATAL); + logError(focusFragment.getErrors(), ValidationMessage.NO_RULE_DATE, -1, -1,context.formatMessage(I18nConstants.DOCUMENT), IssueType.INVALID, context.formatMessage(I18nConstants.ERROR_PARSING_JSON_, e.getMessage()), IssueSeverity.FATAL); } } else { obj = org.hl7.fhir.utilities.json.parser.JsonParser.parseObject(source, true, true); } if (obj != null) { - ctxt.setElement(parse(ctxt.getErrors(), obj)); + focusFragment.setElement(parse(focusFragment.getErrors(), obj)); } List res = new ArrayList<>(); - res.add(ctxt); + res.add(focusFragment); // long t =System.currentTimeMillis()-start; // System.out.println("json parser: "+(t)+"ms, "+(content.length/1024)+"kb "+(t == 0 ? "" : " @ "+(content.length / t)+"kb/s")); diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/TurtleParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/TurtleParser.java index 54c7a4f19..da39b2790 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/TurtleParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/TurtleParser.java @@ -2,34 +2,34 @@ package org.hl7.fhir.r5.elementmodel; import java.io.ByteArrayInputStream; -/* - Copyright (c) 2011+, HL7, Inc. - All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of HL7 nor the names of its contributors may be used to - endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - - */ +/* + Copyright (c) 2011+, HL7, Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of HL7 nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + */ @@ -82,7 +82,7 @@ public class TurtleParser extends ParserBase { @Override public List parse(InputStream inStream) throws IOException, FHIRException { byte[] content = TextFile.streamToBytes(inStream); - ValidatedFragment ctxt = new ValidatedFragment("focus", "ttl", content); + ValidatedFragment focusFragment = new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "ttl", content); ByteArrayInputStream stream = new ByteArrayInputStream(content); Turtle src = new Turtle(); @@ -90,16 +90,16 @@ public class TurtleParser extends ParserBase { try { src.parse(TextFile.streamToString(stream)); } catch (Exception e) { - logError(ctxt.getErrors(), ValidationMessage.NO_RULE_DATE, -1, -1, "(document)", IssueType.INVALID, context.formatMessage(I18nConstants.ERROR_PARSING_TURTLE_, e.getMessage()), IssueSeverity.FATAL); + logError(focusFragment.getErrors(), ValidationMessage.NO_RULE_DATE, -1, -1, "(document)", IssueType.INVALID, context.formatMessage(I18nConstants.ERROR_PARSING_TURTLE_, e.getMessage()), IssueSeverity.FATAL); return null; } - ctxt.setElement(parse(ctxt.getErrors(), src)); + focusFragment.setElement(parse(focusFragment.getErrors(), src)); } else { src.parse(TextFile.streamToString(stream)); - ctxt.setElement(parse(ctxt.getErrors(), src)); + focusFragment.setElement(parse(focusFragment.getErrors(), src)); } List res = new ArrayList<>(); - res.add(ctxt); + res.add(focusFragment); return res; } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ValidatedFragment.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ValidatedFragment.java index 42f6a7d24..243d426f4 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ValidatedFragment.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ValidatedFragment.java @@ -10,6 +10,8 @@ public class ValidatedFragment { private String extension; private Element element; private byte[] content; + + public final static String FOCUS_NAME = "focus"; private List errors = new ArrayList<>(); public ValidatedFragment(String name, String extension, Element element, byte[] content) { diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/VerticalBarParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/VerticalBarParser.java index 53e96eea7..d73c1b869 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/VerticalBarParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/VerticalBarParser.java @@ -1,33 +1,33 @@ package org.hl7.fhir.r5.elementmodel; -/* - Copyright (c) 2011+, HL7, Inc. - All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of HL7 nor the names of its contributors may be used to - endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - - */ +/* + Copyright (c) 2011+, HL7, Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of HL7 nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + */ @@ -465,7 +465,7 @@ public class VerticalBarParser extends ParserBase { while (!reader.isFinished()) // && (getOptions().getSegmentLimit() == 0 || getOptions().getSegmentLimit() > message.getSegments().size())) readSegment(message, reader); List res = new ArrayList<>(); - res.add(new ValidatedFragment("focus", "hl7", message, content)); + res.add(new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "hl7", message, content)); return res; } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java index 415cec75d..2759fcc13 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java @@ -114,7 +114,7 @@ public class XmlParser extends ParserBase { public List parse(InputStream inStream) throws FHIRFormatError, DefinitionException, FHIRException, IOException { byte[] content = TextFile.streamToBytes(inStream); - ValidatedFragment context = new ValidatedFragment("focus", "xml", content); + ValidatedFragment focusFragment = new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "xml", content); ByteArrayInputStream stream = new ByteArrayInputStream(content); Document doc = null; @@ -134,7 +134,7 @@ public class XmlParser extends ParserBase { // if we can, we'll inspect the header/encoding ourselves stream.mark(1024); - version = checkHeader(context.getErrors(), stream); + version = checkHeader(focusFragment.getErrors(), stream); stream.reset(); // use a slower parser that keeps location data @@ -168,17 +168,17 @@ public class XmlParser extends ParserBase { if (e.getMessage().contains("lineNumber:") && e.getMessage().contains("columnNumber:")) { int line = Utilities.parseInt(extractVal(e.getMessage(), "lineNumber"), 0); int col = Utilities.parseInt(extractVal(e.getMessage(), "columnNumber"), 0); - logError(context.getErrors(), ValidationMessage.NO_RULE_DATE, line, col, "(xml)", IssueType.INVALID, e.getMessage().substring(e.getMessage().lastIndexOf(";")+1).trim(), IssueSeverity.FATAL); + logError(focusFragment.getErrors(), ValidationMessage.NO_RULE_DATE, line, col, "(xml)", IssueType.INVALID, e.getMessage().substring(e.getMessage().lastIndexOf(";")+1).trim(), IssueSeverity.FATAL); } else { - logError(context.getErrors(), ValidationMessage.NO_RULE_DATE, 0, 0, "(xml)", IssueType.INVALID, e.getMessage(), IssueSeverity.FATAL); + logError(focusFragment.getErrors(), ValidationMessage.NO_RULE_DATE, 0, 0, "(xml)", IssueType.INVALID, e.getMessage(), IssueSeverity.FATAL); } doc = null; } if (doc != null) { - context.setElement(parse(context.getErrors(), doc)); + focusFragment.setElement(parse(focusFragment.getErrors(), doc)); } List res = new ArrayList<>(); - res.add(context); + res.add(focusFragment); return res; } From d8509440573b73081dd5b84392c59dd3bec595c6 Mon Sep 17 00:00:00 2001 From: dotasek Date: Tue, 26 Sep 2023 16:46:22 -0400 Subject: [PATCH 04/13] WIP track derived content for ValidatedFragment --- .../hl7/fhir/r5/elementmodel/FmlParser.java | 2 +- .../hl7/fhir/r5/elementmodel/JsonParser.java | 2 +- .../hl7/fhir/r5/elementmodel/SHCParser.java | 4 +- .../hl7/fhir/r5/elementmodel/SHLParser.java | 2 +- .../fhir/r5/elementmodel/TurtleParser.java | 2 +- .../r5/elementmodel/ValidatedFragment.java | 47 ++++++++----------- .../r5/elementmodel/VerticalBarParser.java | 2 +- .../hl7/fhir/r5/elementmodel/XmlParser.java | 2 +- .../cli/services/ValidationService.java | 29 ++++++------ 9 files changed, 43 insertions(+), 49 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/FmlParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/FmlParser.java index b4f332982..7f04c3286 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/FmlParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/FmlParser.java @@ -50,7 +50,7 @@ public class FmlParser extends ParserBase { ByteArrayInputStream stream = new ByteArrayInputStream(content); String text = TextFile.streamToString(stream); List result = new ArrayList<>(); - ValidatedFragment focusFragment = new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "fml", content); + ValidatedFragment focusFragment = new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "fml", content, false); focusFragment.setElement(parse(focusFragment.getErrors(), text)); result.add(focusFragment); return result; diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java index c71fd4d3c..14efb65de 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java @@ -122,7 +122,7 @@ public class JsonParser extends ParserBase { public List parse(InputStream inStream) throws IOException, FHIRException { // long start = System.currentTimeMillis(); byte[] content = TextFile.streamToBytes(inStream); - ValidatedFragment focusFragment = new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "json", content); + ValidatedFragment focusFragment = new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "json", content, false); ByteArrayInputStream stream = new ByteArrayInputStream(content); diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/SHCParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/SHCParser.java index 9e4737e01..b837cc1cd 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/SHCParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/SHCParser.java @@ -83,7 +83,7 @@ public class SHCParser extends ParserBase { byte[] content = TextFile.streamToBytes(inStream); ByteArrayInputStream stream = new ByteArrayInputStream(content); List res = new ArrayList<>(); - ValidatedFragment shc = new ValidatedFragment("shc", "json", content); + ValidatedFragment shc = new ValidatedFragment("shc", "json", content, false); res.add(shc); String src = TextFile.streamToString(stream).trim(); @@ -165,7 +165,7 @@ public class SHCParser extends ParserBase { return res; } // ok. all checks passed, we can now validate the bundle - ValidatedFragment bnd = new ValidatedFragment(path, "json", org.hl7.fhir.utilities.json.parser.JsonParser.composeBytes(cs.getJsonObject("fhirBundle"))); + ValidatedFragment bnd = new ValidatedFragment(path, "json", org.hl7.fhir.utilities.json.parser.JsonParser.composeBytes(cs.getJsonObject("fhirBundle")), true); res.add(bnd); bnd.setElement(jsonParser.parse(bnd.getErrors(), cs.getJsonObject("fhirBundle"))); } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/SHLParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/SHLParser.java index 5682b4aa0..2c4f64b1d 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/SHLParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/SHLParser.java @@ -280,7 +280,7 @@ public class SHLParser extends ParserBase { } private ValidatedFragment addNamedElement(List res, String name, String type, byte[] content) { - ValidatedFragment result = new ValidatedFragment(name, type, content); + ValidatedFragment result = new ValidatedFragment(name, type, content, true); res.add(result); return result; } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/TurtleParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/TurtleParser.java index da39b2790..66b55eb27 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/TurtleParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/TurtleParser.java @@ -82,7 +82,7 @@ public class TurtleParser extends ParserBase { @Override public List parse(InputStream inStream) throws IOException, FHIRException { byte[] content = TextFile.streamToBytes(inStream); - ValidatedFragment focusFragment = new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "ttl", content); + ValidatedFragment focusFragment = new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "ttl", content, false); ByteArrayInputStream stream = new ByteArrayInputStream(content); Turtle src = new Turtle(); diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ValidatedFragment.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ValidatedFragment.java index 243d426f4..8c7d965bd 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ValidatedFragment.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ValidatedFragment.java @@ -3,57 +3,50 @@ package org.hl7.fhir.r5.elementmodel; import java.util.ArrayList; import java.util.List; +import lombok.Getter; +import lombok.Setter; import org.hl7.fhir.utilities.validation.ValidationMessage; public class ValidatedFragment { + + @Getter private String name; + + @Getter private String extension; + + @Getter @Setter private Element element; + + @Getter @Setter private byte[] content; + @Getter + private final boolean isDerivedContent; public final static String FOCUS_NAME = "focus"; + + @Getter private List errors = new ArrayList<>(); - - public ValidatedFragment(String name, String extension, Element element, byte[] content) { + + + public ValidatedFragment(String name, String extension, Element element, byte[] content, boolean isDerivedContent) { super(); this.name = name; this.element = element; this.content = content; this.extension = extension; + this.isDerivedContent = isDerivedContent; } - public ValidatedFragment(String name, String extension, byte[] content) { + public ValidatedFragment(String name, String extension, byte[] content, boolean isDerivedContent) { super(); this.name = name; this.content = content; this.extension = extension; + this.isDerivedContent = isDerivedContent; } - - public String getName() { - return name; - } - - public Element getElement() { - return element; - } - - public byte[] getContent() { - return content; - } - - public List getErrors() { - return errors; - } - - public void setElement(Element element) { - this.element = element; - } - public String getFilename() { return name+"."+extension; } - public String getExtension() { - return extension; - } } \ No newline at end of file diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/VerticalBarParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/VerticalBarParser.java index d73c1b869..cca033fef 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/VerticalBarParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/VerticalBarParser.java @@ -465,7 +465,7 @@ public class VerticalBarParser extends ParserBase { while (!reader.isFinished()) // && (getOptions().getSegmentLimit() == 0 || getOptions().getSegmentLimit() > message.getSegments().size())) readSegment(message, reader); List res = new ArrayList<>(); - res.add(new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "hl7", message, content)); + res.add(new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "hl7", message, content, false)); return res; } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java index 2759fcc13..55b3c4d8d 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java @@ -114,7 +114,7 @@ public class XmlParser extends ParserBase { public List parse(InputStream inStream) throws FHIRFormatError, DefinitionException, FHIRException, IOException { byte[] content = TextFile.streamToBytes(inStream); - ValidatedFragment focusFragment = new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "xml", content); + ValidatedFragment focusFragment = new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "xml", content, false); ByteArrayInputStream stream = new ByteArrayInputStream(content); Document doc = null; diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java index be7cc97e7..4ecdafef5 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java @@ -127,27 +127,28 @@ public class ValidationService { List validatedFragments = validator.validateAsFragments(fileToValidate.getFileContent().getBytes(), Manager.FhirFormat.getFhirFormat(fileToValidate.getFileType()), request.getCliContext().getProfiles(), messages); - // TODO this chunk does not work for multi-file validation, as the fileName is overwritten - for (ValidatedFragment validatedFragment : validatedFragments) { + if (validatedFragments.size() == 1 && !validatedFragments.get(0).isDerivedContent()) { + ValidatedFragment validatedFragment = validatedFragments.get(0); ValidationOutcome outcome = new ValidationOutcome(); - FileInfo fileInfo = new FileInfo( - validatedFragment.getFilename(), + FileInfo fileInfo = new FileInfo( + fileToValidate.getFileName(), new String(validatedFragment.getContent()), validatedFragment.getExtension()); outcome.setMessages(validatedFragment.getErrors()); outcome.setFileInfo(fileInfo); response.addOutcome(outcome); + } else { + for (ValidatedFragment validatedFragment : validatedFragments) { + ValidationOutcome outcome = new ValidationOutcome(); + FileInfo fileInfo = new FileInfo( + validatedFragment.getFilename(), + new String(validatedFragment.getContent()), + validatedFragment.getExtension()); + outcome.setMessages(validatedFragment.getErrors()); + outcome.setFileInfo(fileInfo); + response.addOutcome(outcome); + } } - - //TODO the code below works correctly for multi-file validation. - /* - validator.validate(fp.getFileContent().getBytes(), Manager.FhirFormat.getFhirFormat(fp.getFileType()), - request.getCliContext().getProfiles(), messages); - - ValidationOutcome outcome = new ValidationOutcome().setFileInfo(fp); - messages.forEach(outcome::addMessage); - response.addOutcome(outcome); - */ } System.out.println(" Max Memory: "+Runtime.getRuntime().maxMemory()); return response; From c2071379f48fba204b825a38869e87c1b35d0c9e Mon Sep 17 00:00:00 2001 From: dotasek Date: Fri, 29 Sep 2023 11:00:01 -0400 Subject: [PATCH 05/13] Use txt extension for shc fragment --- .../src/main/java/org/hl7/fhir/r5/elementmodel/SHCParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/SHCParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/SHCParser.java index 92e67aab0..1e3d56895 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/SHCParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/SHCParser.java @@ -83,7 +83,7 @@ public class SHCParser extends ParserBase { byte[] content = TextFile.streamToBytes(inStream); ByteArrayInputStream stream = new ByteArrayInputStream(content); List res = new ArrayList<>(); - ValidatedFragment shc = new ValidatedFragment("shc", "json", content, false); + ValidatedFragment shc = new ValidatedFragment("shc", "txt", content, false); res.add(shc); String src = TextFile.streamToString(stream).trim(); From 9b5c26be2512b3af4ed18899c1b088299569d42b Mon Sep 17 00:00:00 2001 From: markiantorno Date: Sat, 30 Sep 2023 18:21:42 +0000 Subject: [PATCH 06/13] Release: v6.1.11 ## Validator Changes * Fix FHIRPath type resolution for logical models * Update parsers to record the element format for logical model validation * fix profile matching for CDA logical models ## Other code changes * Upgrade PackageVisitor for XIG ***NO_CI*** --- org.hl7.fhir.convertors/pom.xml | 2 +- org.hl7.fhir.dstu2/pom.xml | 2 +- org.hl7.fhir.dstu2016may/pom.xml | 2 +- org.hl7.fhir.dstu3/pom.xml | 2 +- org.hl7.fhir.r4/pom.xml | 2 +- org.hl7.fhir.r4b/pom.xml | 2 +- org.hl7.fhir.r5/pom.xml | 2 +- org.hl7.fhir.report/pom.xml | 2 +- org.hl7.fhir.utilities/pom.xml | 2 +- org.hl7.fhir.validation.cli/pom.xml | 2 +- org.hl7.fhir.validation/pom.xml | 2 +- pom.xml | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/org.hl7.fhir.convertors/pom.xml b/org.hl7.fhir.convertors/pom.xml index 361503d76..71574aa8d 100644 --- a/org.hl7.fhir.convertors/pom.xml +++ b/org.hl7.fhir.convertors/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.11-SNAPSHOT + 6.1.11 ../pom.xml diff --git a/org.hl7.fhir.dstu2/pom.xml b/org.hl7.fhir.dstu2/pom.xml index 1eb6320bb..49fe3cb19 100644 --- a/org.hl7.fhir.dstu2/pom.xml +++ b/org.hl7.fhir.dstu2/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.11-SNAPSHOT + 6.1.11 ../pom.xml diff --git a/org.hl7.fhir.dstu2016may/pom.xml b/org.hl7.fhir.dstu2016may/pom.xml index e37bdd975..1cf8e8bad 100644 --- a/org.hl7.fhir.dstu2016may/pom.xml +++ b/org.hl7.fhir.dstu2016may/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.11-SNAPSHOT + 6.1.11 ../pom.xml diff --git a/org.hl7.fhir.dstu3/pom.xml b/org.hl7.fhir.dstu3/pom.xml index 10ea12b45..e63cbe243 100644 --- a/org.hl7.fhir.dstu3/pom.xml +++ b/org.hl7.fhir.dstu3/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.11-SNAPSHOT + 6.1.11 ../pom.xml diff --git a/org.hl7.fhir.r4/pom.xml b/org.hl7.fhir.r4/pom.xml index 0cd9be460..06a77d802 100644 --- a/org.hl7.fhir.r4/pom.xml +++ b/org.hl7.fhir.r4/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.11-SNAPSHOT + 6.1.11 ../pom.xml diff --git a/org.hl7.fhir.r4b/pom.xml b/org.hl7.fhir.r4b/pom.xml index 4f2a087e3..10d626ac0 100644 --- a/org.hl7.fhir.r4b/pom.xml +++ b/org.hl7.fhir.r4b/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.11-SNAPSHOT + 6.1.11 ../pom.xml diff --git a/org.hl7.fhir.r5/pom.xml b/org.hl7.fhir.r5/pom.xml index bb25672df..6fb80dc9e 100644 --- a/org.hl7.fhir.r5/pom.xml +++ b/org.hl7.fhir.r5/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.11-SNAPSHOT + 6.1.11 ../pom.xml diff --git a/org.hl7.fhir.report/pom.xml b/org.hl7.fhir.report/pom.xml index 91764f9d1..8e2cac058 100644 --- a/org.hl7.fhir.report/pom.xml +++ b/org.hl7.fhir.report/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.11-SNAPSHOT + 6.1.11 ../pom.xml diff --git a/org.hl7.fhir.utilities/pom.xml b/org.hl7.fhir.utilities/pom.xml index 3e71e99de..f3067b311 100644 --- a/org.hl7.fhir.utilities/pom.xml +++ b/org.hl7.fhir.utilities/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.11-SNAPSHOT + 6.1.11 ../pom.xml diff --git a/org.hl7.fhir.validation.cli/pom.xml b/org.hl7.fhir.validation.cli/pom.xml index 33f44c241..ebcbf1ea4 100644 --- a/org.hl7.fhir.validation.cli/pom.xml +++ b/org.hl7.fhir.validation.cli/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.11-SNAPSHOT + 6.1.11 ../pom.xml diff --git a/org.hl7.fhir.validation/pom.xml b/org.hl7.fhir.validation/pom.xml index ae318c486..7247463ce 100644 --- a/org.hl7.fhir.validation/pom.xml +++ b/org.hl7.fhir.validation/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.11-SNAPSHOT + 6.1.11 ../pom.xml diff --git a/pom.xml b/pom.xml index 203868ac2..90c56ffdf 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ HAPI FHIR --> org.hl7.fhir.core - 6.1.11-SNAPSHOT + 6.1.11 pom From 627e40934b4e463fa7d110a67081ed1910c94770 Mon Sep 17 00:00:00 2001 From: markiantorno Date: Mon, 2 Oct 2023 13:18:11 +0000 Subject: [PATCH 07/13] Updating version to: 6.1.12-SNAPSHOT and incrementing test cases dependency. --- RELEASE_NOTES.md | 6 ++---- org.hl7.fhir.convertors/pom.xml | 2 +- org.hl7.fhir.dstu2/pom.xml | 2 +- org.hl7.fhir.dstu2016may/pom.xml | 2 +- org.hl7.fhir.dstu3/pom.xml | 2 +- org.hl7.fhir.r4/pom.xml | 2 +- org.hl7.fhir.r4b/pom.xml | 2 +- org.hl7.fhir.r5/pom.xml | 2 +- org.hl7.fhir.report/pom.xml | 2 +- org.hl7.fhir.utilities/pom.xml | 2 +- org.hl7.fhir.validation.cli/pom.xml | 2 +- org.hl7.fhir.validation/pom.xml | 2 +- pom.xml | 2 +- 13 files changed, 14 insertions(+), 16 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index a2f9a6ec6..7b06c6ab5 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,9 +1,7 @@ ## Validator Changes -* Fix FHIRPath type resolution for logical models -* Update parsers to record the element format for logical model validation -* fix profile matching for CDA logical models +* no changes ## Other code changes -* Upgrade PackageVisitor for XIG +* no changes \ No newline at end of file diff --git a/org.hl7.fhir.convertors/pom.xml b/org.hl7.fhir.convertors/pom.xml index 71574aa8d..4e09505e5 100644 --- a/org.hl7.fhir.convertors/pom.xml +++ b/org.hl7.fhir.convertors/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.11 + 6.1.12-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.dstu2/pom.xml b/org.hl7.fhir.dstu2/pom.xml index 49fe3cb19..4162c7ef5 100644 --- a/org.hl7.fhir.dstu2/pom.xml +++ b/org.hl7.fhir.dstu2/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.11 + 6.1.12-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.dstu2016may/pom.xml b/org.hl7.fhir.dstu2016may/pom.xml index 1cf8e8bad..f1555e0ed 100644 --- a/org.hl7.fhir.dstu2016may/pom.xml +++ b/org.hl7.fhir.dstu2016may/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.11 + 6.1.12-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.dstu3/pom.xml b/org.hl7.fhir.dstu3/pom.xml index e63cbe243..428ab99b2 100644 --- a/org.hl7.fhir.dstu3/pom.xml +++ b/org.hl7.fhir.dstu3/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.11 + 6.1.12-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.r4/pom.xml b/org.hl7.fhir.r4/pom.xml index 06a77d802..b3529c654 100644 --- a/org.hl7.fhir.r4/pom.xml +++ b/org.hl7.fhir.r4/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.11 + 6.1.12-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.r4b/pom.xml b/org.hl7.fhir.r4b/pom.xml index 10d626ac0..de73d91b0 100644 --- a/org.hl7.fhir.r4b/pom.xml +++ b/org.hl7.fhir.r4b/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.11 + 6.1.12-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.r5/pom.xml b/org.hl7.fhir.r5/pom.xml index 6fb80dc9e..854e1578d 100644 --- a/org.hl7.fhir.r5/pom.xml +++ b/org.hl7.fhir.r5/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.11 + 6.1.12-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.report/pom.xml b/org.hl7.fhir.report/pom.xml index 8e2cac058..18242dbb3 100644 --- a/org.hl7.fhir.report/pom.xml +++ b/org.hl7.fhir.report/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.11 + 6.1.12-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.utilities/pom.xml b/org.hl7.fhir.utilities/pom.xml index f3067b311..6c30a670b 100644 --- a/org.hl7.fhir.utilities/pom.xml +++ b/org.hl7.fhir.utilities/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.11 + 6.1.12-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.validation.cli/pom.xml b/org.hl7.fhir.validation.cli/pom.xml index ebcbf1ea4..ffacb9ad0 100644 --- a/org.hl7.fhir.validation.cli/pom.xml +++ b/org.hl7.fhir.validation.cli/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.11 + 6.1.12-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.validation/pom.xml b/org.hl7.fhir.validation/pom.xml index 7247463ce..dfabf8eb2 100644 --- a/org.hl7.fhir.validation/pom.xml +++ b/org.hl7.fhir.validation/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.11 + 6.1.12-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index 90c56ffdf..685bae4f3 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ HAPI FHIR --> org.hl7.fhir.core - 6.1.11 + 6.1.12-SNAPSHOT pom From a36b3ee1f5ce45f504e15c1d4406cb46ed143f3f Mon Sep 17 00:00:00 2001 From: dotasek Date: Wed, 4 Oct 2023 11:08:12 -0400 Subject: [PATCH 08/13] Update RELEASE_NOTES.md ***NO_CI*** --- RELEASE_NOTES.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 7b06c6ab5..7da8e3614 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,7 +1,8 @@ ## Validator Changes -* no changes +* Allow programmatic access to validated fragments. +* Identify derived validated fragments. ## Other code changes -* no changes \ No newline at end of file +* no changes From ff29b0908368a9f6b37d550c6ebef9e79983582b Mon Sep 17 00:00:00 2001 From: dotasek Date: Wed, 4 Oct 2023 13:28:30 -0400 Subject: [PATCH 09/13] Fix junit detection of sql on fhir, temporarily disable ***NO_CI*** --- .../r5/sql/{SQLOnFhirTestCases.java => SQLOnFhirTests.java} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/sql/{SQLOnFhirTestCases.java => SQLOnFhirTests.java} (97%) diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/sql/SQLOnFhirTestCases.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/sql/SQLOnFhirTests.java similarity index 97% rename from org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/sql/SQLOnFhirTestCases.java rename to org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/sql/SQLOnFhirTests.java index 5b9e36adb..74daafaec 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/sql/SQLOnFhirTestCases.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/sql/SQLOnFhirTests.java @@ -14,10 +14,8 @@ import javax.xml.parsers.ParserConfigurationException; import org.fhir.ucum.UcumException; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.r5.model.Base; -import org.hl7.fhir.r5.model.Factory; import org.hl7.fhir.r5.model.Resource; import org.hl7.fhir.r5.model.ResourceFactory; -import org.hl7.fhir.r5.sql.SQLOnFhirTestCases.RowSorter; import org.hl7.fhir.r5.test.utils.CompareUtilities; import org.hl7.fhir.r5.test.utils.TestingUtilities; import org.hl7.fhir.r5.utils.sql.Provider; @@ -28,12 +26,13 @@ import org.hl7.fhir.utilities.json.model.JsonElement; import org.hl7.fhir.utilities.json.model.JsonObject; import org.hl7.fhir.utilities.json.parser.JsonParser; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.xml.sax.SAXException; -public class SQLOnFhirTestCases { +public class SQLOnFhirTests { public class TestProvider implements Provider { @@ -110,6 +109,7 @@ public class SQLOnFhirTestCases { @SuppressWarnings("deprecation") @ParameterizedTest(name = "{index}: file {0}") @MethodSource("data") + @Disabled public void test(String name, TestDetails test) throws FileNotFoundException, IOException, FHIRException, org.hl7.fhir.exceptions.FHIRException, UcumException { this.details = test; Runner runner = new Runner(); From 752ab7a3d148dbe4490c779460b68a03e8c05985 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Thu, 5 Oct 2023 01:42:29 +0300 Subject: [PATCH 10/13] 2023 10 gg cda parsing fix 2 (#1451) * fix xml output to deal with namespaces properly * Improve rendering or xml_no_order * add command line demo app * fix CDA parsing error for sdtc:raceCode * Fix error message * Bump test case version --------- Co-authored-by: Grahame Grieve Co-authored-by: dotasek --- .../org/hl7/fhir/r4/utils/CmdLineApp.java | 335 ++++++++++++++++++ .../r4/utils/client/FHIRToolingClient.java | 19 + .../fhir/r4/utils/client/ResourceAddress.java | 4 + .../hl7/fhir/r5/elementmodel/XmlParser.java | 44 ++- .../StructureDefinitionRenderer.java | 7 +- .../src/main/resources/Messages.properties | 2 +- .../instance/InstanceValidator.java | 14 +- pom.xml | 2 +- 8 files changed, 416 insertions(+), 11 deletions(-) create mode 100644 org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/CmdLineApp.java diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/CmdLineApp.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/CmdLineApp.java new file mode 100644 index 000000000..f2778934d --- /dev/null +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/CmdLineApp.java @@ -0,0 +1,335 @@ +package org.hl7.fhir.r4.utils; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URISyntaxException; +import java.util.List; + +import org.hl7.fhir.exceptions.FHIRException; +import org.hl7.fhir.r4.context.SimpleWorkerContext; +import org.hl7.fhir.r4.formats.IParser.OutputStyle; +import org.hl7.fhir.r4.formats.JsonParser; +import org.hl7.fhir.r4.model.Base; +import org.hl7.fhir.r4.model.BooleanType; +import org.hl7.fhir.r4.model.Bundle; +import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent; +import org.hl7.fhir.r4.model.CapabilityStatement; +import org.hl7.fhir.r4.model.CodeType; +import org.hl7.fhir.r4.model.CodeableConcept; +import org.hl7.fhir.r4.model.Coding; +import org.hl7.fhir.r4.model.Condition; +import org.hl7.fhir.r4.model.HumanName; +import org.hl7.fhir.r4.model.Immunization; +import org.hl7.fhir.r4.model.Patient; +import org.hl7.fhir.r4.model.Period; +import org.hl7.fhir.r4.model.Procedure; +import org.hl7.fhir.r4.model.Property; +import org.hl7.fhir.r4.model.Resource; +import org.hl7.fhir.r4.model.StringType; +import org.hl7.fhir.r4.model.Type; +import org.hl7.fhir.r4.utils.client.FHIRToolingClient; +import org.hl7.fhir.utilities.Utilities; +import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; +import org.hl7.fhir.utilities.npm.NpmPackage; + +public class CmdLineApp { + + private FHIRToolingClient client; + private String currentId; + private Resource currentResource; + private SimpleWorkerContext context; + private FHIRPathEngine fpe; + + public static void main(String[] args) throws IOException, Exception { + new CmdLineApp().execute(); + } + + private void execute() throws IOException { + System.out.print("Loading..."); + NpmPackage npm = new FilesystemPackageCacheManager(true).loadPackage("hl7.fhir.r4.core"); + context = SimpleWorkerContext.fromPackage(npm); + fpe = new FHIRPathEngine(context); + System.out.println(" Done"); + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + genMenu(); + boolean finished = false; + do { + System.out.print("> "); + String cmd = reader.readLine(); + String[] p = cmd.split("\\s+"); + try { + if (p.length == 1 && p[0].equals("x")) { + finished = true; + } else if (p.length == 1 && p[0].equals("?")) { + genMenu(); + } else if (p.length >= 1 && p[0].equals("c")) { + if (p.length == 1) { + connectToServer("http://hapi.fhir.org/baseR4"); + } else { + connectToServer(p[1]); + } + } else if (p.length >= 1 && p[0].equals("imm")) { + if (p.length == 1) { + if (currentResource == null || !(currentResource instanceof Patient)) { + throw new FHIRException("Current resource must be a patient for this command"); + } + getImmunizations(); + } else { + select("Immunization", p[1]); + } + } else if (p.length >= 1 && p[0].equals("cnd")) { + if (p.length == 1) { + if (currentResource == null || !(currentResource instanceof Patient)) { + throw new FHIRException("Current resource must be a patient for this command"); + } + getConditions(); + } else { + select("Condition", p[1]); + } + } else if (p.length >= 1 && p[0].equals("prc")) { + if (p.length == 1) { + if (currentResource == null || !(currentResource instanceof Patient)) { + throw new FHIRException("Current resource must be a patient for this command"); + } + getProcedures(); + } else { + select("Procedure", p[1]); + } + } else if (p.length >= 1 && p[0].equals("v")) { + if (p.length == 1) { + viewResource(); + } else { + viewResource(p[1]); + } + } else if (p.length >= 2 && p[0].equals("s")) { + search(p); + } else if (p.length >= 2 && p[0].equals("p")) { + select("Patient", p[1]); + } else if (p.length == 3 && p[0].equals("e")) { + edit(p[1], p[2]); + } else { + System.out.println("Command unknown or not understood: "+cmd); + } + } catch (Exception e) { + System.out.println("Error executing command "+p[0]+": "+e.getMessage()); + } + } while (!finished); + + System.out.println("Finished!"); + } + + private void getImmunizations() { + + Bundle bnd = client.search("Immunization", "?patient="+currentId); + System.out.println(""+bnd.getTotal()+" Immunizations found. Printing "+bnd.getEntry().size()); + + for (BundleEntryComponent be : bnd.getEntry()) { + Resource imm = be.getResource(); + System.out.println(summary(imm)); + } + } + + private void getProcedures() { + + Bundle bnd = client.search("Procedure", "?patient="+currentId); + System.out.println(""+bnd.getTotal()+" Procedures found. Printing "+bnd.getEntry().size()); + + for (BundleEntryComponent be : bnd.getEntry()) { + Resource imm = be.getResource(); + System.out.println(summary(imm)); + } + } + + private void getConditions() { + + Bundle bnd = client.search("Condition", "?patient="+currentId); + System.out.println(""+bnd.getTotal()+" Conditions found. Printing "+bnd.getEntry().size()); + + for (BundleEntryComponent be : bnd.getEntry()) { + Resource imm = be.getResource(); + System.out.println(summary(imm)); + } + } + + private void edit(String path, String value) { + if (path.contains(".")) { + List list = fpe.evaluate(currentResource, fpe.parse(path.substring(0, path.lastIndexOf(".")))); + if (list.size() == 1) { + path = path.substring(path.lastIndexOf(".")+1); + Property p = list.get(0).getNamedProperty(path); + Base b = makeValue(p, value); + list.get(0).setProperty(path, b); + } else { + throw new FHIRException("Unable to set value at "+path+": "+list.size()+" matches"); + } + } else { + Property p = currentResource.getNamedProperty(path); + Base b = makeValue(p, value); + currentResource.setProperty(path, b); + } + currentResource = client.update(currentResource); + } + + private Base makeValue(Property p, String value) { + switch (p.getTypeCode()) { + case "boolean" : return new BooleanType(value); + case "code" : return new CodeType(value); + case "string" : return new StringType(value); + } + throw new FHIRException("Unhandled type "+p.getTypeCode()); + } + + private void viewResource(String path) { + System.out.println("Current Resource, query = "+path); + List list = fpe.evaluate(currentResource, fpe.parse(path)); + for (Base b : list) { + System.out.println(b.toString()); + } + } + + private void viewResource() throws IOException { + System.out.println("Current Resource:"); + System.out.println(new JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(currentResource)); + } + + private void select(String type, String id) { + if (type.equals("Patient")) { + currentResource = client.fetchResource(Patient.class, id); + } else if (type.equals("Immunization")) { + currentResource = client.fetchResource(Immunization.class, id); + } else if (type.equals("Condition")) { + currentResource = client.fetchResource(Condition.class, id); + } else if (type.equals("Procedure")) { + currentResource = client.fetchResource(Procedure.class, id); + } else { + throw new FHIRException("Unhandled type "+type); + } + currentId = type+"/"+id; + System.out.println("Resource = "+currentId+" "+summary(currentResource)); + } + + private String summary(Resource r) { + if (r instanceof Patient) { + Patient pat = (Patient) r; + return pat.getIdBase()+" "+pat.getGender()+" "+pat.getBirthDateElement().asStringValue()+" "+name(pat); + } + if (r instanceof Immunization) { + Immunization imm = (Immunization) r; + return imm.getIdBase()+" "+imm.getOccurrenceDateTimeType().asStringValue()+" "+code(imm.getVaccineCode())+" "+imm.getLotNumber()+" ("+imm.getStatus()+")"; + } + if (r instanceof Condition) { + Condition cnd = (Condition) r; + return cnd.getIdBase()+" "+code(cnd.getClinicalStatus())+" "+code(cnd.getVerificationStatus())+" "+code(cnd.getCode())+" "+cnd.getRecordedDateElement().asStringValue(); + } + if (r instanceof Procedure) { + Procedure prc = (Procedure) r; + return prc.getIdBase()+" "+prc.getStatusElement().asStringValue()+" "+code(prc.getCode())+" "+code(prc.getCode())+" "+dt(prc.getPerformed()); + } + return "??"; + } + + private String dt(Type type) { + if (type == null) { + return ""; + } + if (type.isPrimitive()) { + return type.primitiveValue(); + } + if (type instanceof Period) { + Period pd = (Period) type; + return pd.getStartElement().asStringValue()+" -> "+pd.getEndElement().asStringValue(); + } + return "??"; + } + + private String code(CodeableConcept cc) { + for (Coding c : cc.getCoding()) { + if (c.hasSystem()) { + String d = c.hasDisplay() ? " ("+c.getDisplay()+")" : ""; + if (c.hasCode()) { + switch (c.getSystem()) { + case "http://hl7.org/fhir/sid/cvx": return "CVX "+c.getCode()+d; + case "http://snomed.info/sct": return "SCT "+c.getCode()+d; + default: + if (Utilities.startsWithInList(c.getSystem(), "http://terminology.hl7.org")) { + return c.getCode(); + } else { + throw new FHIRException("Unknown system "+c.getSystem()); + } + } + } + } + } + for (Coding c : cc.getCoding()) { + if (c.hasCode()) { + return c.getCode(); + } + } + if (cc.hasText()) { + return cc.getText(); + } + return ""; + } + + private void search(String[] p) { + if (client == null) { + throw new FHIRException("Not connected to to a server"); + } + String search = "?name="+p[1]; + if (p.length > 2) { + search = search +"&gender="+p[2]; + if (p.length > 3) { + search = search +"&dob="+p[3]; + } + } + Bundle bnd = client.search("Patient", search); + System.out.println(""+bnd.getTotal()+" Patients found. Printing "+bnd.getEntry().size()); + + for (BundleEntryComponent be : bnd.getEntry()) { + Patient pat = (Patient) be.getResource(); + System.out.println(summary(pat)); + } + } + + private String name(Patient pat) { + if (pat.getName().size() > 0) { + return name(pat.getName().get(0)); + } + return null; + } + + private String name(HumanName n) { + if (n.hasText()) { + return n.getText(); + } + if (n.hasFamily()) { + if (n.hasGiven()) { + return n.getGiven().get(0)+" "+n.getFamily().toUpperCase(); + } else { + return n.getFamily().toUpperCase(); + } + } + return "??"; + } + + private void connectToServer(String url) throws URISyntaxException { + client = new FHIRToolingClient(url, "FHIR-Command-Line-App"); + CapabilityStatement cs = client.getCapabilitiesStatementQuick(); + System.out.println("Connected to "+url+": "+cs.getSoftware().getName()+"."); + } + + private void genMenu() { + System.out.println("Simple Client. Commands you can run:"); + System.out.println(" c {url} - connect to a server"); + System.out.println(" s {name} [{gender}] {{dob]} - find a patient record"); + System.out.println(" p {id} - choose a patient record"); + System.out.println(" v [{field}] - see a set of field(s) in the current resource, or the whole resource"); + System.out.println(" e {field} {value} - edit a field in the current resource"); + System.out.println(" imm [{id}] - get a list of the patient's immunizations, or use the resource for the id (then use e to edit it)"); + System.out.println(" cnd [{id}] - get a list of the patient's conditions, or use the resource for the id (then use e to edit it)"); + System.out.println(" prc [{id}] - get a list of the patient's procedures, or use the resource for the id (then use e to edit it)"); + System.out.println(" ? - print this again"); + System.out.println(" x - exit"); + } +} 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 95028e204..3b3b2ad46 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 @@ -595,4 +595,23 @@ public class FHIRToolingClient { public void setLanguage(String lang) { this.acceptLang = lang; } + + public Bundle search(String type, String criteria) { + return fetchFeed(Utilities.pathURL(base, type+criteria)); + } + + public T fetchResource(Class resourceClass, String id) { + org.hl7.fhir.r4.utils.client.network.ResourceRequest result = null; + try { + result = client.issueGetResourceRequest(resourceAddress.resolveGetResource(resourceClass, id), + getPreferredResourceFormat(), generateHeaders(), resourceClass.getName()+"/"+id, TIMEOUT_NORMAL); + } catch (IOException e) { + throw new FHIRException(e); + } + if (result.isUnsuccessfulRequest()) { + throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), + (OperationOutcome) result.getPayload()); + } + return (T) result.getPayload(); + } } diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/ResourceAddress.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/ResourceAddress.java index 3b11ed94f..bffaa5900 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/ResourceAddress.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/ResourceAddress.java @@ -91,6 +91,10 @@ public class ResourceAddress { return baseServiceUri.resolve(nameForClassWithSlash(resourceClass) + "/" + opName); } + public URI resolveGetResource(Class resourceClass, String id) { + return baseServiceUri.resolve(nameForClassWithSlash(resourceClass) + "/" + id); + } + public URI resolveOperationUri(Class resourceClass, String opName, Map parameters) { return appendHttpParameters(baseServiceUri.resolve(nameForClassWithSlash(resourceClass) + "$" + opName), diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java index 3158a7c32..da6868bb6 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/XmlParser.java @@ -61,6 +61,7 @@ import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat; import org.hl7.fhir.r5.formats.FormatUtilities; import org.hl7.fhir.r5.formats.IParser.OutputStyle; import org.hl7.fhir.r5.model.DateTimeType; +import org.hl7.fhir.r5.model.ElementDefinition; import org.hl7.fhir.r5.model.ElementDefinition.PropertyRepresentation; import org.hl7.fhir.r5.model.Enumeration; import org.hl7.fhir.r5.model.StructureDefinition; @@ -421,7 +422,11 @@ public class XmlParser extends ParserBase { element.getChildren().add(n); } else { String npath = path+"/"+pathPrefix(child.getNamespaceURI())+child.getLocalName(); - Element n = new Element(child.getLocalName(), property).markLocation(line(child, false), col(child, false)).setFormat(FhirFormat.XML); + String name = child.getLocalName(); + if (!property.isChoice() && !name.equals(property.getName())) { + name = property.getName(); + } + Element n = new Element(name, property).markLocation(line(child, false), col(child, false)).setFormat(FhirFormat.XML); if (property.isList()) { n.setPath(element.getPath()+"."+property.getName()+"["+repeatCount+"]"); } else { @@ -769,7 +774,11 @@ public class XmlParser extends ParserBase { } if (linkResolver != null) xml.link(linkResolver.resolveProperty(element.getProperty())); - xml.enter(element.getProperty().getXmlNamespace(),elementName); + if (!xml.namespaceDefined(element.getProperty().getXmlNamespace())) { + String abbrev = makeNamespaceAbbrev(element.getProperty(), xml); + xml.namespace(element.getProperty().getXmlNamespace(), abbrev); + } + xml.enter(element.getProperty().getXmlNamespace(), elementName); if (!root && element.getSpecial() != null) { if (linkResolver != null) xml.link(linkResolver.resolveProperty(element.getProperty())); @@ -791,6 +800,37 @@ public class XmlParser extends ParserBase { } } + private String makeNamespaceAbbrev(Property property, IXMLWriter xml) { + // it's a cosmetic thing, but we're going to try to come up with a nice namespace + + ElementDefinition ed = property.getDefinition(); + String ns = property.getXmlNamespace(); + String n = property.getXmlName(); + + String diff = property.getName().toLowerCase().replace(n.toLowerCase(), ""); + if (!Utilities.noString(diff) && diff.length() <= 5 && Utilities.isToken(diff) && !xml.abbreviationDefined(diff)) { + return diff; + } + + int i = ns.length()-1; + while (i > 0) { + if (Character.isAlphabetic(ns.charAt(i)) || Character.isDigit(ns.charAt(i))) { + i--; + } else { + break; + } + } + String tail = ns.substring(i+1); + if (!Utilities.noString(tail) && tail.length() <= 5 && Utilities.isToken(tail) && !xml.abbreviationDefined(tail)) { + return tail; + } + + i = 0; + while (xml.abbreviationDefined("ns"+i)) { + i++; + } + return "ns"+i; + } private String checkHeader(List errors, InputStream stream) throws IOException { try { // the stream will either start with the UTF-8 BOF or with slices = null; - if (ed.hasSlicing()) + if (ed.hasSlicing()) { slices = profileUtilities.getSliceList(profile, ed); - for (ElementInfo ei : children) - if (ei.definition == ed) + } + for (ElementInfo ei : children) { + if (ei.definition == ed) { count++; - else if (slices != null) { + } else if (slices != null) { for (ElementDefinition sed : slices) { if (ei.definition == sed) { count++; @@ -6228,6 +6229,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat } } } + } if (ed.getMin() > 0) { if (problematicPaths.contains(ed.getPath())) hintPlural(errors, NO_RULE_DATE, IssueType.NOTSUPPORTED, element.line(), element.col(), stack.getLiteralPath(), count >= ed.getMin(), count, I18nConstants.VALIDATION_VAL_PROFILE_NOCHECKMIN, profile.getVersionedUrl(), ed.getPath(), ed.getId(), ed.getSliceName(),ed.getLabel(), stack.getLiteralPath(), Integer.toString(ed.getMin())); @@ -6238,9 +6240,9 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat } } if (ed.hasMax() && !ed.getMax().equals("*")) { - if (problematicPaths.contains(ed.getPath())) + if (problematicPaths.contains(ed.getPath())) { hintPlural(errors, NO_RULE_DATE, IssueType.NOTSUPPORTED, element.line(), element.col(), stack.getLiteralPath(), count <= Integer.parseInt(ed.getMax()), count, I18nConstants.VALIDATION_VAL_PROFILE_NOCHECKMAX, profile.getVersionedUrl(), ed.getPath(), ed.getId(), ed.getSliceName(),ed.getLabel(), stack.getLiteralPath(), ed.getMax()); - else if (count > Integer.parseInt(ed.getMax())) { + } else if (count > Integer.parseInt(ed.getMax())) { ok = rulePlural(errors, NO_RULE_DATE, IssueType.STRUCTURE, element.line(), element.col(), stack.getLiteralPath(), false, count, I18nConstants.VALIDATION_VAL_PROFILE_MAXIMUM, profile.getVersionedUrl(), ed.getPath(), ed.getId(), ed.getSliceName(),ed.getLabel(), stack.getLiteralPath(), ed.getMax(), Integer.toString(count)) && ok; } } diff --git a/pom.xml b/pom.xml index 685bae4f3..8cdca3c78 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ 32.0.1-jre 6.4.1 - 1.4.7 + 1.4.8 2.15.2 5.9.2 1.8.2 From c8d9fcca257ec615a92ddab276450d40970645de Mon Sep 17 00:00:00 2001 From: dotasek Date: Wed, 4 Oct 2023 18:44:01 -0400 Subject: [PATCH 11/13] Update RELEASE_NOTES.md ***NO_CI*** --- RELEASE_NOTES.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 7da8e3614..85661cef3 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,8 +1,14 @@ ## Validator Changes -* Allow programmatic access to validated fragments. -* Identify derived validated fragments. +* fix CDA parsing error for sdtc:raceCode +* fix xml output to deal with namespaces properly +* fix FHIRPath join implementation to make separator parameter optional ## Other code changes -* no changes +* Improve rendering for xml_no_order extension +* add command line demo app +* rework xig into 3 steps +* add userData to JSON element +* Initial SQL On FHIR implementation +* Add getDistalNames() to FHIRPath for SQL-on-FHIR support From d705905c8c4c88308a619e644b78c05dd46fde03 Mon Sep 17 00:00:00 2001 From: markiantorno Date: Thu, 5 Oct 2023 01:50:02 +0000 Subject: [PATCH 12/13] Release: v6.1.12 ## Validator Changes * fix CDA parsing error for sdtc:raceCode * fix xml output to deal with namespaces properly * fix FHIRPath join implementation to make separator parameter optional ## Other code changes * Improve rendering for xml_no_order extension * add command line demo app * rework xig into 3 steps * add userData to JSON element * Initial SQL On FHIR implementation * Add getDistalNames() to FHIRPath for SQL-on-FHIR support ***NO_CI*** --- org.hl7.fhir.convertors/pom.xml | 2 +- org.hl7.fhir.dstu2/pom.xml | 2 +- org.hl7.fhir.dstu2016may/pom.xml | 2 +- org.hl7.fhir.dstu3/pom.xml | 2 +- org.hl7.fhir.r4/pom.xml | 2 +- org.hl7.fhir.r4b/pom.xml | 2 +- org.hl7.fhir.r5/pom.xml | 2 +- org.hl7.fhir.report/pom.xml | 2 +- org.hl7.fhir.utilities/pom.xml | 2 +- org.hl7.fhir.validation.cli/pom.xml | 2 +- org.hl7.fhir.validation/pom.xml | 2 +- pom.xml | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/org.hl7.fhir.convertors/pom.xml b/org.hl7.fhir.convertors/pom.xml index 4e09505e5..217c42ebb 100644 --- a/org.hl7.fhir.convertors/pom.xml +++ b/org.hl7.fhir.convertors/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.12-SNAPSHOT + 6.1.12 ../pom.xml diff --git a/org.hl7.fhir.dstu2/pom.xml b/org.hl7.fhir.dstu2/pom.xml index 4162c7ef5..9497a20eb 100644 --- a/org.hl7.fhir.dstu2/pom.xml +++ b/org.hl7.fhir.dstu2/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.12-SNAPSHOT + 6.1.12 ../pom.xml diff --git a/org.hl7.fhir.dstu2016may/pom.xml b/org.hl7.fhir.dstu2016may/pom.xml index f1555e0ed..cdf5d9c02 100644 --- a/org.hl7.fhir.dstu2016may/pom.xml +++ b/org.hl7.fhir.dstu2016may/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.12-SNAPSHOT + 6.1.12 ../pom.xml diff --git a/org.hl7.fhir.dstu3/pom.xml b/org.hl7.fhir.dstu3/pom.xml index 428ab99b2..d7c792ae4 100644 --- a/org.hl7.fhir.dstu3/pom.xml +++ b/org.hl7.fhir.dstu3/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.12-SNAPSHOT + 6.1.12 ../pom.xml diff --git a/org.hl7.fhir.r4/pom.xml b/org.hl7.fhir.r4/pom.xml index b3529c654..d11684284 100644 --- a/org.hl7.fhir.r4/pom.xml +++ b/org.hl7.fhir.r4/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.12-SNAPSHOT + 6.1.12 ../pom.xml diff --git a/org.hl7.fhir.r4b/pom.xml b/org.hl7.fhir.r4b/pom.xml index de73d91b0..fdda250d9 100644 --- a/org.hl7.fhir.r4b/pom.xml +++ b/org.hl7.fhir.r4b/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.12-SNAPSHOT + 6.1.12 ../pom.xml diff --git a/org.hl7.fhir.r5/pom.xml b/org.hl7.fhir.r5/pom.xml index 854e1578d..b5216e39b 100644 --- a/org.hl7.fhir.r5/pom.xml +++ b/org.hl7.fhir.r5/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.12-SNAPSHOT + 6.1.12 ../pom.xml diff --git a/org.hl7.fhir.report/pom.xml b/org.hl7.fhir.report/pom.xml index 18242dbb3..0b4c30403 100644 --- a/org.hl7.fhir.report/pom.xml +++ b/org.hl7.fhir.report/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.12-SNAPSHOT + 6.1.12 ../pom.xml diff --git a/org.hl7.fhir.utilities/pom.xml b/org.hl7.fhir.utilities/pom.xml index 6c30a670b..874da09fa 100644 --- a/org.hl7.fhir.utilities/pom.xml +++ b/org.hl7.fhir.utilities/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.12-SNAPSHOT + 6.1.12 ../pom.xml diff --git a/org.hl7.fhir.validation.cli/pom.xml b/org.hl7.fhir.validation.cli/pom.xml index ffacb9ad0..1003e7392 100644 --- a/org.hl7.fhir.validation.cli/pom.xml +++ b/org.hl7.fhir.validation.cli/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.12-SNAPSHOT + 6.1.12 ../pom.xml diff --git a/org.hl7.fhir.validation/pom.xml b/org.hl7.fhir.validation/pom.xml index dfabf8eb2..f2d65c478 100644 --- a/org.hl7.fhir.validation/pom.xml +++ b/org.hl7.fhir.validation/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.12-SNAPSHOT + 6.1.12 ../pom.xml diff --git a/pom.xml b/pom.xml index 8cdca3c78..c3c68ce39 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ HAPI FHIR --> org.hl7.fhir.core - 6.1.12-SNAPSHOT + 6.1.12 pom From 9ec1c68cfcf282bf62b525a5e68c593eb480ebfb Mon Sep 17 00:00:00 2001 From: markiantorno Date: Thu, 5 Oct 2023 02:20:25 +0000 Subject: [PATCH 13/13] Updating version to: 6.1.13-SNAPSHOT and incrementing test cases dependency. --- RELEASE_NOTES.md | 11 ++--------- org.hl7.fhir.convertors/pom.xml | 2 +- org.hl7.fhir.dstu2/pom.xml | 2 +- org.hl7.fhir.dstu2016may/pom.xml | 2 +- org.hl7.fhir.dstu3/pom.xml | 2 +- org.hl7.fhir.r4/pom.xml | 2 +- org.hl7.fhir.r4b/pom.xml | 2 +- org.hl7.fhir.r5/pom.xml | 2 +- org.hl7.fhir.report/pom.xml | 2 +- org.hl7.fhir.utilities/pom.xml | 2 +- org.hl7.fhir.validation.cli/pom.xml | 2 +- org.hl7.fhir.validation/pom.xml | 2 +- pom.xml | 2 +- 13 files changed, 14 insertions(+), 21 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 85661cef3..7b06c6ab5 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,14 +1,7 @@ ## Validator Changes -* fix CDA parsing error for sdtc:raceCode -* fix xml output to deal with namespaces properly -* fix FHIRPath join implementation to make separator parameter optional +* no changes ## Other code changes -* Improve rendering for xml_no_order extension -* add command line demo app -* rework xig into 3 steps -* add userData to JSON element -* Initial SQL On FHIR implementation -* Add getDistalNames() to FHIRPath for SQL-on-FHIR support +* no changes \ No newline at end of file diff --git a/org.hl7.fhir.convertors/pom.xml b/org.hl7.fhir.convertors/pom.xml index 217c42ebb..4178171b4 100644 --- a/org.hl7.fhir.convertors/pom.xml +++ b/org.hl7.fhir.convertors/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.12 + 6.1.13-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.dstu2/pom.xml b/org.hl7.fhir.dstu2/pom.xml index 9497a20eb..d4a62f7fb 100644 --- a/org.hl7.fhir.dstu2/pom.xml +++ b/org.hl7.fhir.dstu2/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.12 + 6.1.13-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.dstu2016may/pom.xml b/org.hl7.fhir.dstu2016may/pom.xml index cdf5d9c02..29dce09c5 100644 --- a/org.hl7.fhir.dstu2016may/pom.xml +++ b/org.hl7.fhir.dstu2016may/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.12 + 6.1.13-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.dstu3/pom.xml b/org.hl7.fhir.dstu3/pom.xml index d7c792ae4..da5a13833 100644 --- a/org.hl7.fhir.dstu3/pom.xml +++ b/org.hl7.fhir.dstu3/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.12 + 6.1.13-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.r4/pom.xml b/org.hl7.fhir.r4/pom.xml index d11684284..95ab63d49 100644 --- a/org.hl7.fhir.r4/pom.xml +++ b/org.hl7.fhir.r4/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.12 + 6.1.13-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.r4b/pom.xml b/org.hl7.fhir.r4b/pom.xml index fdda250d9..dcc94c768 100644 --- a/org.hl7.fhir.r4b/pom.xml +++ b/org.hl7.fhir.r4b/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.12 + 6.1.13-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.r5/pom.xml b/org.hl7.fhir.r5/pom.xml index b5216e39b..c81eb326a 100644 --- a/org.hl7.fhir.r5/pom.xml +++ b/org.hl7.fhir.r5/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.12 + 6.1.13-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.report/pom.xml b/org.hl7.fhir.report/pom.xml index 0b4c30403..1389cadd7 100644 --- a/org.hl7.fhir.report/pom.xml +++ b/org.hl7.fhir.report/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.12 + 6.1.13-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.utilities/pom.xml b/org.hl7.fhir.utilities/pom.xml index 874da09fa..9815b4743 100644 --- a/org.hl7.fhir.utilities/pom.xml +++ b/org.hl7.fhir.utilities/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.12 + 6.1.13-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.validation.cli/pom.xml b/org.hl7.fhir.validation.cli/pom.xml index 1003e7392..307e5e5da 100644 --- a/org.hl7.fhir.validation.cli/pom.xml +++ b/org.hl7.fhir.validation.cli/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.12 + 6.1.13-SNAPSHOT ../pom.xml diff --git a/org.hl7.fhir.validation/pom.xml b/org.hl7.fhir.validation/pom.xml index f2d65c478..5e0f7ce0e 100644 --- a/org.hl7.fhir.validation/pom.xml +++ b/org.hl7.fhir.validation/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir org.hl7.fhir.core - 6.1.12 + 6.1.13-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index c3c68ce39..89751d330 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ HAPI FHIR --> org.hl7.fhir.core - 6.1.12 + 6.1.13-SNAPSHOT pom