profile code generation fixes

This commit is contained in:
Grahame Grieve 2024-10-22 05:16:31 +10:30
parent eb13be1c87
commit ede7628b44
3 changed files with 56 additions and 20 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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) {