Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PECodeGenerator does not work when a custom DataType of type list is encountered #1884

Open
zero-zero-senven opened this issue Jan 16, 2025 · 0 comments

Comments

@zero-zero-senven
Copy link

zero-zero-senven commented Jan 16, 2025

The question is repeated

I extended LFCodeableConcept and LFCoding locally (actually just modified part of the description) and then used them in LFPatient. When I used this Profile to generate PEDefinition, I found that the save method did not work properly. It still generatesCodeableConcept and Coding, but the field types are LFCodeableConcept and LFCoding

  //some code
  private List<LFCoding> codings = new ArrayList<>();
  //some code
  public void save(PEInstance tgt, boolean nulls) {
    tgt.clear("extension");
    for (Extension item : extensions) {
      tgt.addChild("extension", item);
    }
    tgt.clear("coding");
    for (LFCoding item : codings) {
      tgt.addChild("coding", item);
      //Actually, it should be
      //item.save(tgt.makeChild("coding"), false);
    }

  }

Solution

Through the phenomenon of the problem, I debug the code and find that the problem is genSave, the detailed code is here: https://github.com/hapifhir/org.hl7.fhir.core/blob/master/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/profilemodel/gen/PECodeGenerator.java#L456

So I copied the Extension and added a bit of processing, and now it works:

    private void genSave(boolean isPrim, boolean isAbstract, String name, String sname, String fname, String type, String init, String ptype, String ltype, String cname, String csname, boolean isList, boolean isFixed, boolean isExtension, PEType typeInfo, boolean isEnum) {
      w(save, "    tgt.clear(\""+fname+"\");");
      if (isList) {
        w(save, "    for ("+type+" item : "+name+") {");
        if (isExtension) {
          if (typeInfo != null && typeInfo.getUrl() != null && !typeInfo.getUrl().startsWith("http://hl7.org/fhir/StructureDefinition")) {
            w(save, "      item.save(tgt.makeChild(\""+fname+"\"), false);");
          } else {
            w(save, "      tgt.makeChild(\""+fname+"\").data().setProperty(\"value[x]\", item);");
          }
        } else if (isEnum) {
          if ("CodeableConcept".equals(typeInfo.getName())) {
            w(save, "      tgt.addChild(\""+fname+"\", item.toCodeableConcept());");
          } else if ("Coding".equals(typeInfo.getName())) {
            w(save, "      tgt.addChild(\""+fname+"\", item.toCoding());");
          } else {
            w(save, "      tgt.addChild(\""+fname+"\", item.toCode());");
          }
         // Determines whether to extend the DataType based on the url prefix
        } else if(typeInfo != null && typeInfo.getUrl() != null && !typeInfo.getUrl().startsWith("http://hl7.org/fhir/StructureDefinition")){
          w(save, "      item.save(tgt.makeChild(\""+fname+"\"), false);");
        }else{
          w(save, "      tgt.addChild(\""+fname+"\", item);");
        }
        w(save, "    }");
      } else if (isEnum) {
         .....
      }
      .....
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant