From 43253e8d10528921a45c01ab8668a92016e49806 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Sun, 12 Mar 2023 21:53:38 +1100 Subject: [PATCH 1/6] improve extension representation --- .../hl7/fhir/r5/conformance/profile/ProfileUtilities.java | 8 ++++++++ .../java/org/hl7/fhir/r5/model/StructureDefinition.java | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfileUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfileUtilities.java index 3864901c3..9b32e57e4 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfileUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfileUtilities.java @@ -3906,5 +3906,13 @@ public class ProfileUtilities extends TranslatingUtilities { this.allowUnknownProfile = allowUnknownProfile; } + public static boolean isSimpleExtension(StructureDefinition sd) { + if (!isExtensionDefinition(sd)) { + return false; + } + ElementDefinition value = sd.getSnapshot().getElementByPath("Extension.value"); + return value != null && !value.isProhibited(); + } + } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/StructureDefinition.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/StructureDefinition.java index 912ae8444..0861ad248 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/StructureDefinition.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/StructureDefinition.java @@ -1234,8 +1234,11 @@ public class StructureDefinition extends CanonicalResource { // added from java-adornments.txt: public ElementDefinition getElementByPath(String path) { + if (path == null) { + return null; + } for (ElementDefinition ed : getElement()) { - if (path.equals(ed.getPath())) { + if (path.equals(ed.getPath()) || (path+"[x]").equals(ed.getPath())) { return ed; } } From 2dc72fcaf1b310dd8bd0142e39e74d8c83779dec Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Sun, 12 Mar 2023 21:54:21 +1100 Subject: [PATCH 2/6] fix bug parsing FML (id) --- .../r5/renderers/StructureMapRenderer.java | 29 ++++++++++++++++--- .../structuremap/StructureMapUtilities.java | 8 +++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/StructureMapRenderer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/StructureMapRenderer.java index 76c0445ed..4c1dfd2de 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/StructureMapRenderer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/StructureMapRenderer.java @@ -10,6 +10,7 @@ import java.util.Map; import java.util.Set; import org.hl7.fhir.exceptions.FHIRException; +import org.hl7.fhir.r5.model.CodeSystem; import org.hl7.fhir.r5.model.CodeType; import org.hl7.fhir.r5.model.ConceptMap; import org.hl7.fhir.r5.model.Enumeration; @@ -155,7 +156,12 @@ public class StructureMapRenderer extends TerminologyRenderer { x.b().tx(" prefix "); x.tx(""+prefix); x.color(COLOR_SYNTAX).tx(" = \""); - x.tx(cg.getSource()); + CodeSystem cs = context.getContext().fetchResource(CodeSystem.class, cg.getSource()); + if (cs != null && cs.hasUserData("path")) { + x.ah(cs.getUserString("path"), cs.present()).tx(cg.getSource()); + } else { + x.tx(cg.getSource()); + } x.color(COLOR_SYNTAX).tx("\"\r\n"); prefix++; } @@ -164,7 +170,12 @@ public class StructureMapRenderer extends TerminologyRenderer { x.b().tx(" prefix "); x.tx(""+prefix); x.color(COLOR_SYNTAX).tx(" = \""); - x.tx(""+cg.getTarget()); + CodeSystem cs = context.getContext().fetchResource(CodeSystem.class, cg.getTarget()); + if (cs != null && cs.hasUserData("path")) { + x.ah(cs.getUserString("path"), cs.present()).tx(cg.getTarget()); + } else { + x.tx(""+cg.getTarget()); + } x.color(COLOR_SYNTAX).tx("\"\r\n"); prefix++; } @@ -247,7 +258,12 @@ public class StructureMapRenderer extends TerminologyRenderer { for (StructureMapStructureComponent s : map.getStructure()) { x.b().tx("uses"); x.color(COLOR_SYNTAX).tx(" \""); - x.tx(s.getUrl()); + StructureDefinition sd = context.getContext().fetchResource(StructureDefinition.class, s.getUrl()); + if (sd != null && sd.hasUserData("path")) { + x.ah(sd.getUserString("path"), sd.present()).tx(s.getUrl()); + } else { + x.tx(s.getUrl()); + } x.color(COLOR_SYNTAX).tx("\" "); if (s.hasAlias()) { x.b().tx("alias "); @@ -267,7 +283,12 @@ public class StructureMapRenderer extends TerminologyRenderer { for (UriType s : map.getImport()) { x.b().tx("imports"); x.color(COLOR_SYNTAX).tx(" \""); - x.tx(s.getValue()); + StructureMap m = context.getContext().fetchResource(StructureMap.class, s.getValue()); + if (m != null) { + x.ah(m.getUserString("path"), m.present()).tx(s.getValue()); + } else { + x.tx(s.getValue()); + } x.color(COLOR_SYNTAX).tx("\"\r\n"); } if (map.hasImport()) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/structuremap/StructureMapUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/structuremap/StructureMapUtilities.java index 7ad8632e1..3a789416d 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/structuremap/StructureMapUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/structuremap/StructureMapUtilities.java @@ -664,6 +664,14 @@ public class StructureMapUtilities { } } } + result.setId(result.getName()); + if (!result.hasStatus()) { + result.setStatus(PublicationStatus.DRAFT); + } + if (!result.hasDescription() && result.hasTitle()) { + result.setDescription(result.getTitle()); + } + while (lexer.hasToken("conceptmap")) parseConceptMap(result, lexer); From f11bdb9560244bfec93bf5677df6a1ab8e2f3f13 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Sun, 12 Mar 2023 21:55:44 +1100 Subject: [PATCH 3/6] fix NPE --- .../org/hl7/fhir/r5/elementmodel/FmlParser.java | 3 +++ .../java/org/hl7/fhir/r5/utils/FHIRPathEngine.java | 14 ++------------ 2 files changed, 5 insertions(+), 12 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 a36c7a3c9..6920ddd02 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 @@ -83,6 +83,9 @@ public class FmlParser extends ParserBase { if (!result.hasChild("status")) { result.makeElement("status").setValue("draft"); } + if (!result.hasChild("id") && result.hasChild("name")) { + result.makeElement("id").setValue(result.getChildValue("name")); + } if (!result.hasChild("description") && result.hasChild("title")) { result.makeElement("description").setValue(result.getChildValue("title")); } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java index 3ef9b1634..97d851c94 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java @@ -5027,10 +5027,11 @@ public class FHIRPathEngine { if (s != null) { Base res = null; if (s.startsWith("#")) { + String t = s.substring(1); Property p = context.rootResource.getChildByName("contained"); if (p != null) { for (Base c : p.getValues()) { - if (chompHash(s).equals(chompHash(c.getIdBase()))) { + if (t.equals(c.getIdBase())) { res = c; break; } @@ -5052,17 +5053,6 @@ public class FHIRPathEngine { return result; } - /** - * Strips a leading hashmark (#) if present at the start of a string - */ - private String chompHash(String theId) { - String retVal = theId; - while (retVal.startsWith("#")) { - retVal = retVal.substring(1); - } - return retVal; - } - private List funcExtension(ExecutionContext context, List focus, ExpressionNode exp) throws FHIRException { List result = new ArrayList(); List nl = execute(context, focus, exp.getParameters().get(0), true); From 7f68418cc620a594bdc896da7ab6296cf9738535 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Sun, 12 Mar 2023 21:58:09 +1100 Subject: [PATCH 4/6] update test case dependency --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index dd2d00de1..ac1f81e08 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ 6.2.1 - 1.2.19 + 1.2.20-SNAPSHOT 5.7.1 1.8.2 3.0.0-M5 From 96f265653e639c15f52d5c6501754a358a3b51aa Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Sun, 12 Mar 2023 23:02:46 +1100 Subject: [PATCH 5/6] fix run time test --- .../src/main/java/org/hl7/fhir/r5/elementmodel/FmlParser.java | 4 ++-- .../hl7/fhir/r5/utils/structuremap/StructureMapUtilities.java | 4 +++- org.hl7.fhir.utilities/src/main/resources/Messages.properties | 4 ++-- .../org/hl7/fhir/validation/instance/InstanceValidator.java | 4 ++-- 4 files changed, 9 insertions(+), 7 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 6920ddd02..c51fb2ed9 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 @@ -84,10 +84,10 @@ public class FmlParser extends ParserBase { result.makeElement("status").setValue("draft"); } if (!result.hasChild("id") && result.hasChild("name")) { - result.makeElement("id").setValue(result.getChildValue("name")); + result.makeElement("id").setValue(Utilities.makeId(result.getChildValue("name"))); } if (!result.hasChild("description") && result.hasChild("title")) { - result.makeElement("description").setValue(result.getChildValue("title")); + result.makeElement("description").setValue(Utilities.makeId(result.getChildValue("title"))); } while (lexer.hasToken("conceptmap")) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/structuremap/StructureMapUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/structuremap/StructureMapUtilities.java index 3a789416d..1d2fe42fc 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/structuremap/StructureMapUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/structuremap/StructureMapUtilities.java @@ -664,7 +664,9 @@ public class StructureMapUtilities { } } } - result.setId(result.getName()); + if (!result.hasId() && result.hasName()) { + result.setId(Utilities.makeId(result.getName())); + } if (!result.hasStatus()) { result.setStatus(PublicationStatus.DRAFT); } diff --git a/org.hl7.fhir.utilities/src/main/resources/Messages.properties b/org.hl7.fhir.utilities/src/main/resources/Messages.properties index 4e18e76f7..8604cd89c 100644 --- a/org.hl7.fhir.utilities/src/main/resources/Messages.properties +++ b/org.hl7.fhir.utilities/src/main/resources/Messages.properties @@ -130,8 +130,8 @@ Reference_REF_NotFound_Bundle = Bundled or contained reference not found within Reference_REF_ResourceType = Matching reference for reference {0} has resourceType {1} Reference_REF_WrongTarget = The type ''{0}'' is not a valid Target for this element (must be one of {1}) REFERENCE_REF_WRONGTARGET_LOAD = The type ''{2}'' is not a valid Target for the element {0} (must be {1}) -Resource_RES_ID_Malformed_Length = Invalid Resource id: Too long -Resource_RES_ID_Malformed_Chars = Invalid Resource id: Invalid Characters +Resource_RES_ID_Malformed_Length = Invalid Resource id: Too long ({0} chars) +Resource_RES_ID_Malformed_Chars = Invalid Resource id: Invalid Characters (''{0}'') Resource_RES_ID_Missing = Resource requires an id, but none is present Resource_RES_ID_Prohibited = Resource has an id, but none is allowed Terminology_PassThrough_TX_Message = {0} for ''{1}#{2}'' diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java index 15f06b042..211e759c9 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java @@ -6222,9 +6222,9 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat if (eid.getProperty() != null && eid.getProperty().getDefinition() != null && eid.getProperty().getDefinition().getBase().getPath().equals("Resource.id")) { NodeStack ns = stack.push(eid, -1, eid.getProperty().getDefinition(), null); if (eid.primitiveValue() != null && eid.primitiveValue().length() > 64) { - ok = rule(errors, NO_RULE_DATE, IssueType.INVALID, eid.line(), eid.col(), ns.getLiteralPath(), false, I18nConstants.RESOURCE_RES_ID_MALFORMED_LENGTH) && ok; + ok = rule(errors, NO_RULE_DATE, IssueType.INVALID, eid.line(), eid.col(), ns.getLiteralPath(), false, I18nConstants.RESOURCE_RES_ID_MALFORMED_LENGTH, eid.primitiveValue().length()) && ok; } else { - ok = rule(errors, NO_RULE_DATE, IssueType.INVALID, eid.line(), eid.col(), ns.getLiteralPath(), FormatUtilities.isValidId(eid.primitiveValue()), I18nConstants.RESOURCE_RES_ID_MALFORMED_CHARS) && ok; + ok = rule(errors, NO_RULE_DATE, IssueType.INVALID, eid.line(), eid.col(), ns.getLiteralPath(), FormatUtilities.isValidId(eid.primitiveValue()), I18nConstants.RESOURCE_RES_ID_MALFORMED_CHARS, eid.primitiveValue()) && ok; } } } From 7b30dc02f95e3bdbdd95628c6ce755ce7278f3ac Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Mon, 13 Mar 2023 05:10:08 +1100 Subject: [PATCH 6/6] check for NPE --- .../main/java/org/hl7/fhir/r5/elementmodel/FmlParser.java | 5 ++++- .../fhir/r5/utils/structuremap/StructureMapUtilities.java | 5 ++++- 2 files changed, 8 insertions(+), 2 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 c51fb2ed9..463264666 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 @@ -84,7 +84,10 @@ public class FmlParser extends ParserBase { result.makeElement("status").setValue("draft"); } if (!result.hasChild("id") && result.hasChild("name")) { - result.makeElement("id").setValue(Utilities.makeId(result.getChildValue("name"))); + String id = Utilities.makeId(result.getChildValue("name")); + if (!Utilities.noString(id)) { + result.makeElement("id").setValue(id); + } } if (!result.hasChild("description") && result.hasChild("title")) { result.makeElement("description").setValue(Utilities.makeId(result.getChildValue("title"))); diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/structuremap/StructureMapUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/structuremap/StructureMapUtilities.java index 1d2fe42fc..fcf608def 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/structuremap/StructureMapUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/structuremap/StructureMapUtilities.java @@ -665,7 +665,10 @@ public class StructureMapUtilities { } } if (!result.hasId() && result.hasName()) { - result.setId(Utilities.makeId(result.getName())); + String id = Utilities.makeId(result.getName()); + if (Utilities.noString(id)) { + result.setId(id); + } } if (!result.hasStatus()) { result.setStatus(PublicationStatus.DRAFT);