From ede7628b4420218d80a946b1560fe5c15d0fc24a Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Tue, 22 Oct 2024 05:16:31 +1030 Subject: [PATCH] profile code generation fixes --- .../hl7/fhir/r4/profilemodel/PEInstance.java | 28 ++++++++++++++----- .../hl7/fhir/r5/profilemodel/PEInstance.java | 28 ++++++++++++++----- .../r5/profilemodel/gen/PECodeGenerator.java | 20 +++++++++---- 3 files changed, 56 insertions(+), 20 deletions(-) diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/profilemodel/PEInstance.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/profilemodel/PEInstance.java index 67c306062..16e154b6c 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/profilemodel/PEInstance.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/profilemodel/PEInstance.java @@ -46,6 +46,7 @@ import org.hl7.fhir.r4.model.Extension; import org.hl7.fhir.r4.model.HumanName; import org.hl7.fhir.r4.context.IWorkerContext; import org.hl7.fhir.r4.model.Address; +import org.hl7.fhir.r4.model.BackboneElement; import org.hl7.fhir.r4.model.PrimitiveType; import org.hl7.fhir.r4.model.Quantity; import org.hl7.fhir.r4.model.Reference; @@ -225,6 +226,10 @@ public class PEInstance { return (Type) data; } + public BackboneElement asElement() { + return (BackboneElement) data; + } + public CodeableConcept asCodeableConcept() { return (CodeableConcept) asDataType(); } @@ -293,18 +298,27 @@ public class PEInstance { return builder.getContext(); } - public void addChild(String name, Type value) { + public Base addChild(String name, Type value) { PEDefinition child = byName(definition.children(), name); Base b = data.setProperty(child.schemaName(), value); - } - - public void addChild(String name, String value) { - PEDefinition child = byName(definition.children(), name); - Base b = data.setProperty(child.schemaName(), new StringType(value)); + return b; } - public void addChild(String name, Date value) { + public Base addChild(String name, BackboneElement value) { + PEDefinition child = byName(definition.children(), name); + Base b = data.setProperty(child.schemaName(), value); + return b; + } + + public Base addChild(String name, String value) { + PEDefinition child = byName(definition.children(), name); + Base b = data.setProperty(child.schemaName(), new StringType(value)); + return b; + } + + public Base addChild(String name, Date value) { PEDefinition child = byName(definition.children(), name); Base b = data.setProperty(child.schemaName(), new DateType(value)); + return b; } } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/profilemodel/PEInstance.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/profilemodel/PEInstance.java index a139b1ea9..c6b726784 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/profilemodel/PEInstance.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/profilemodel/PEInstance.java @@ -46,6 +46,7 @@ import org.hl7.fhir.r5.model.Extension; import org.hl7.fhir.r5.model.HumanName; import org.hl7.fhir.r5.context.IWorkerContext; import org.hl7.fhir.r5.model.Address; +import org.hl7.fhir.r5.model.BackboneElement; import org.hl7.fhir.r5.model.PrimitiveType; import org.hl7.fhir.r5.model.Quantity; import org.hl7.fhir.r5.model.Reference; @@ -225,6 +226,10 @@ public class PEInstance { return (DataType) data; } + public BackboneElement asElement() { + return (BackboneElement) data; + } + public CodeableConcept asCodeableConcept() { return (CodeableConcept) asDataType(); } @@ -293,18 +298,27 @@ public class PEInstance { return builder.getContext(); } - public void addChild(String name, DataType value) { + public Base addChild(String name, DataType value) { PEDefinition child = byName(definition.children(), name); Base b = data.setProperty(child.schemaName(), value); - } - - public void addChild(String name, String value) { - PEDefinition child = byName(definition.children(), name); - Base b = data.setProperty(child.schemaName(), new StringType(value)); + return b; } - public void addChild(String name, Date value) { + public Base addChild(String name, BackboneElement value) { + PEDefinition child = byName(definition.children(), name); + Base b = data.setProperty(child.schemaName(), value); + return b; + } + + public Base addChild(String name, String value) { + PEDefinition child = byName(definition.children(), name); + Base b = data.setProperty(child.schemaName(), new StringType(value)); + return b; + } + + public Base addChild(String name, Date value) { PEDefinition child = byName(definition.children(), name); Base b = data.setProperty(child.schemaName(), new DateType(value)); + return b; } } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/profilemodel/gen/PECodeGenerator.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/profilemodel/gen/PECodeGenerator.java index 0855aeeb0..76629a331 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/profilemodel/gen/PECodeGenerator.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/profilemodel/gen/PECodeGenerator.java @@ -252,7 +252,7 @@ public class PECodeGenerator { w(enums, " public enum "+name+" {"); for (int i = 0; i < vse.getValueset().getExpansion().getContains().size(); i++) { ValueSetExpansionContainsComponent cc = vse.getValueset().getExpansion().getContains().get(i); - String code = Utilities.nmtokenize(cc.getCode()).toUpperCase(); + String code = Utilities.javaTokenize(cc.getCode(), true).toUpperCase(); if (cc.getAbstract()) { code = "_"+code; } @@ -398,7 +398,11 @@ public class PECodeGenerator { private void genLoad(boolean isPrim, boolean isAbstract, String name, String sname, String type, String init, String ptype, String ltype, String cname, String csname, boolean isList, boolean isFixed, PEType typeInfo, boolean isEnum) { if (isList) { w(load, " for (PEInstance item : src.children(\""+sname+"\")) {"); - w(load, " "+name+".add(("+type+") item.asDataType());"); + if ("BackboneElement".equals(type)) { + w(load, " "+name+".add(("+type+") item.asElement());"); + } else { + w(load, " "+name+".add(("+type+") item.asDataType());"); + } w(load, " }"); } else if (isEnum) { w(load, " if (src.hasChild(\""+name+"\")) {"); @@ -407,7 +411,7 @@ public class PECodeGenerator { } else if ("Coding".equals(typeInfo.getName())) { w(load, " "+name+" = "+type+".fromCoding((Coding) src.child(\""+name+"\").asDataType());"); } else { - w(load, " "+name+" = "+type+".fromCode(src.child(\""+name+"\").asDataType()).primitiveValue());"); + w(load, " "+name+" = "+type+".fromCode(src.child(\""+name+"\").asDataType().primitiveValue());"); } w(load, " }"); } else if (isPrim) { @@ -424,8 +428,12 @@ public class PECodeGenerator { w(load, " "+name+" = "+type+".fromSource(src.child(\""+name+"\"));"); w(load, " }"); } else { - w(load, " if (src.hasChild(\""+name+"\")) {"); - w(load, " "+name+" = ("+type+") src.child(\""+name+"\").asDataType();"); + w(load, " if (src.hasChild(\""+name+"\")) {"); + if ("BackboneElement".equals(type)) { + w(load, " "+name+" = ("+type+") src.child(\""+name+"\").asElement();"); + } else { + w(load, " "+name+" = ("+type+") src.child(\""+name+"\").asDataType();"); + } w(load, " }"); } } @@ -447,7 +455,7 @@ public class PECodeGenerator { } else if ("Coding".equals(typeInfo.getName())) { w(save, " tgt.addChild(\""+sname+"\", "+name+".toCoding());"); } else { - w(save, " tgt.addChild(\""+sname+"\", "+name+").toCode();"); + w(save, " tgt.addChild(\""+sname+"\", "+name+".toCode());"); } w(save, " }"); } else if (isPrim) {