Search in sources :

Example 16 with CD

use of org.hl7.v3.CD in project org.hl7.fhir.core by hapifhir.

the class IEEE11073Convertor method generateMDC.

public static CodeSystem generateMDC(String src, String dst, UcumService ucum) throws IOException, FHIRException {
    CSVReader csv = new CSVReader(new FileInputStream(src));
    csv.readHeaders();
    CodeSystem cs = new CodeSystem();
    Map<String, String> ucumIssues = new HashMap<String, String>();
    int errorCount = 0;
    cs.setId("MDC");
    cs.setUrl("urn:iso:std:iso:11073:10101");
    cs.setVersion("[todo]");
    cs.setName("11073:10101 codes for the FHIR community");
    cs.setStatus(PublicationStatus.ACTIVE);
    cs.setExperimental(false);
    cs.setDateElement(new DateTimeType());
    cs.setPublisher("HL7 (FHIR Project)");
    ContactDetail cd = cs.addContact();
    ContactPoint cp = cd.addTelecom();
    cp.setSystem(ContactPointSystem.URL);
    cp.setValue("http://ieee?");
    cs.setDescription("1073 Codes for the FHIR community (generated from the Rosetta data");
    Identifier i = new Identifier();
    cs.setIdentifier(i);
    i.setSystem("urn:ietf:rfc:3986");
    i.setValue("urn:oid:2.16.840.1.113883.6.24");
    cs.setCaseSensitive(false);
    cs.setContent(CodeSystemContentMode.COMPLETE);
    cs.addProperty().setCode("ucum").setDescription("UCUM units associated with Concept").setType(PropertyType.STRING);
    cs.addProperty().setCode("unit").setDescription("MDC units associated with Concept").setType(PropertyType.STRING);
    cs.addProperty().setCode("refid").setDescription("MDC Reference Id for Concept").setType(PropertyType.CODE);
    Set<String> codes = new HashSet<String>();
    while (csv.line()) {
        if (csv.has("CF_CODE10")) {
            String code = csv.cell("CF_CODE10");
            if (codes.contains(code))
                System.out.println("Duplicate Code " + code);
            else {
                codes.add(code);
                ConceptDefinitionComponent c = cs.addConcept();
                c.setCode(code);
                c.setDisplay(csv.cell("Common Term"));
                c.setDefinition(csv.cell("Term Description"));
                String vd = csv.cell("Vendor_Description");
                if (!c.hasDefinition())
                    c.setDefinition(vd);
                if (!c.hasDisplay())
                    c.setDisplay(vd);
                String refid = csv.cell("REFID");
                c.addProperty().setCode("refid").setValue(new CodeType().setValue(refid));
                if (csv.has("Synonym"))
                    c.addDesignation().setValue(csv.cell("Synonym")).setUse(new Coding().setSystem("http://hl7.org/fhir/designation-use").setCode("synonym"));
                if (csv.has("Acronym"))
                    c.addDesignation().setValue(csv.cell("Acronym")).setUse(new Coding().setSystem("http://hl7.org/fhir/designation-use").setDisplay("acronym"));
                if (csv.has("Systematic Name")) {
                    String sysName = csv.cell("Systematic Name");
                    if (!c.hasDefinition())
                        c.setDefinition(sysName);
                    c.addDesignation().setValue(sysName).setUse(new Coding().setSystem("http://hl7.org/fhir/designation-use").setCode("structured-name"));
                }
                if (csv.has("UOM_MDC"))
                    c.addProperty().setCode("unit").setValue(new StringType().setValue(csv.cell("UOM_MDC")));
                if (csv.has("UOM_UCUM")) {
                    CommaSeparatedStringBuilder ul = new CommaSeparatedStringBuilder();
                    for (String u : csv.cell("UOM_UCUM").split(" ")) {
                        String msg = ucum.validate(u);
                        if (msg != null) {
                            errorCount++;
                            ucumIssues.put(u, msg);
                        } else
                            ul.append(u);
                    }
                    if (ul.length() > 0)
                        c.addProperty().setCode("ucum").setValue(new StringType().setValue(ul.toString()));
                }
            }
        }
    }
    csv.close();
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dst, "codesystem-" + cs.getId() + ".xml")), cs);
    System.out.println(errorCount + "UCUM errors");
    for (String u : sorted(ucumIssues.keySet())) System.out.println("Invalid UCUM code: " + u + " because " + ucumIssues.get(u));
    return cs;
}
Also used : XmlParser(org.hl7.fhir.dstu3.formats.XmlParser) CSVReader(org.hl7.fhir.utilities.CSVReader) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) FileInputStream(java.io.FileInputStream) ConceptDefinitionComponent(org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent) FileOutputStream(java.io.FileOutputStream)

Example 17 with CD

use of org.hl7.v3.CD in project org.hl7.fhir.core by hapifhir.

the class CCDAConverter method processAllergyProblemAct.

protected void processAllergyProblemAct(ListResource list, Element concern) throws Exception {
    cda.checkTemplateId(concern, "2.16.840.1.113883.10.20.22.4.30");
    // Allergy Problem Act - this is a concern - we treat the concern as information about it's place in the list
    checkNoNegationOrNullFlavor(concern, "Allergy Problem Act");
    checkNoSubject(concern, "Allergy Problem Act");
    // SHALL contain exactly one [1..1] Allergy - intolerance Observation
    for (Element entry : cda.getChildren(concern, "entryRelationship")) {
        Element obs = cda.getChild(entry, "observation");
        cda.checkTemplateId(obs, "2.16.840.1.113883.10.20.22.4.7");
        checkNoNegationOrNullFlavor(obs, "Allergy - intolerance Observation");
        checkNoSubject(obs, "Allergy Problem Act");
        AllergyIntolerance ai = new AllergyIntolerance();
        ListEntryComponent item = addItemToList(list, ai);
        // SHALL contain at least one [1..*] id (CONF:7472).
        for (Element e : cda.getChildren(concern, "id")) ai.getIdentifier().add(convert.makeIdentifierFromII(e));
        // SHALL contain exactly one [1..1] statusCode, which SHALL be selected from ValueSet 2.16.840.1.113883.3.88.12.80.68 HITSPProblemStatus DYNAMIC (CONF:7485)
        // the status code is about the concern (e.g. the entry in the list)
        // possible values: active, suspended, aborted, completed, with an effective time
        String s = cda.getStatus(concern);
        item.setFlag(Factory.newCodeableConcept(s, "http://hl7.org/fhir/v3/ActStatus", s));
        if (// only on this condition?
        s.equals("aborted"))
            item.setDeleted(true);
        // SHALL contain exactly one [1..1] effectiveTime (CONF:7498)
        Period p = convert.makePeriodFromIVL(cda.getChild(concern, "effectiveTime"));
        item.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/list-period", p, false));
        if (p.getEnd() != null)
            item.setDate(p.getEnd());
        else
            item.setDate(p.getStart());
        // SHALL contain at least one [1..*] id (CONF:7382)
        for (Element e : cda.getChildren(obs, "id")) ai.getIdentifier().add(convert.makeIdentifierFromII(e));
        // SHALL contain exactly one [1..1] effectiveTime (CONF:7387)
        ai.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/allergyintolerance-period", convert.makePeriodFromIVL(cda.getChild(obs, "effectiveTime")), false));
        // SHALL contain exactly one [1..1] value with @xsi:type="CD" (CONF:7390)
        CodeableConcept type = convert.makeCodeableConceptFromCD(cda.getChild(obs, "value"));
        // This value SHALL contain @code, which SHALL be selected from ValueSet 2.16.840.1.113883.3.88.12.3221.6.2 Allergy/Adverse Event Type
        String ss = type.getCoding().get(0).getCode();
        if (ss.equals("416098002") || ss.equals("414285001"))
            ai.setType(AllergyIntoleranceType.ALLERGY);
        else if (ss.equals("59037007") || ss.equals("235719002"))
            ai.setType(AllergyIntoleranceType.INTOLERANCE);
        ai.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/allergy-category", type, false));
        // SHOULD contain zero or one [0..1] participant (CONF:7402) such that it
        // ......This playingEntity SHALL contain exactly one [1..1] code
        ai.setCode(convert.makeCodeableConceptFromCD(cda.getDescendent(obs, "participant/participantRole/playingEntity/code")));
        // SHOULD contain zero or more [0..*] entryRelationship (CONF:7447) such that it SHALL contain exactly one [1..1] Reaction Observation (templateId:2.16.840.1.113883.10.20.22.4.9) (CONF:7450).
        for (Element e : cda.getChildren(obs, "entryRelationship")) {
            Element child = cda.getChild(e, "observation");
            if (cda.hasTemplateId(child, "2.16.840.1.113883.10.20.22.4.28") && ai.getClinicalStatus() == null) {
                // SHALL contain exactly one [1..1] value with @xsi:type="CE", where the @code SHALL be selected from ValueSet Problem Status Value Set 2.16.840.1.113883.3.88.12.80.68 DYNAMIC (CONF:7322).
                // 55561003  SNOMED CT  Active
                // 73425007  SNOMED CT  Inactive
                // 413322009  SNOMED CT  Resolved
                String sc = cda.getChild(child, "value").getAttribute("code");
                if (sc.equals("55561003")) {
                    ai.setClinicalStatus(AllergyIntoleranceClinicalStatus.ACTIVE);
                    ai.setVerificationStatus(AllergyIntoleranceVerificationStatus.CONFIRMED);
                } else
                    ai.setClinicalStatus(AllergyIntoleranceClinicalStatus.RESOLVED);
            } else if (cda.hasTemplateId(child, "2.16.840.1.113883.10.20.22.4.9")) {
                ai.getReaction().add(processAdverseReactionObservation(child));
            }
        }
        // SHOULD contain zero or one [0..1] entryRelationship (CONF:9961) such that it SHALL contain exactly one [1..1] Severity Observation (templateId:2.16.840.1.113883.10.20.22.4.8) (CONF:9963).
        ai.setCriticality(readCriticality(cda.getSeverity(obs)));
    }
}
Also used : AllergyIntolerance(org.hl7.fhir.dstu3.model.AllergyIntolerance) Element(org.w3c.dom.Element) ListEntryComponent(org.hl7.fhir.dstu3.model.ListResource.ListEntryComponent)

Example 18 with CD

use of org.hl7.v3.CD in project org.hl7.fhir.core by hapifhir.

the class CCDAConverter method processProcedure.

protected void processProcedure(ListResource list, Element procedure, ProcedureType type) throws Exception {
    switch(type) {
        case Procedure:
            cda.checkTemplateId(procedure, "2.16.840.1.113883.10.20.22.4.14");
            break;
        case Observation:
            cda.checkTemplateId(procedure, "2.16.840.1.113883.10.20.22.4.13");
            break;
        case Act:
            cda.checkTemplateId(procedure, "2.16.840.1.113883.10.20.22.4.12");
    }
    checkNoNegationOrNullFlavor(procedure, "Procedure (" + type + ")");
    checkNoSubject(procedure, "Procedure (" + type + ")");
    Procedure p = new Procedure();
    addItemToList(list, p);
    // moodCode is either INT or EVN. INT is not handled yet. INT is deprecated anyway
    if (procedure.getAttribute("moodCode").equals("INT"))
        p.getModifierExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-planned", Factory.newBoolean(true), false));
    // SHALL contain at least one [1..*] id (CONF:7655).
    for (Element e : cda.getChildren(procedure, "id")) p.getIdentifier().add(convert.makeIdentifierFromII(e));
    // SHALL contain exactly one [1..1] code (CONF:7656).
    // This code @code in a procedure activity SHOULD be selected from LOINC or SNOMED CT and MAY be selected from CPT-4, ICD9 Procedures, ICD10 Procedures
    p.setCode(convert.makeCodeableConceptFromCD(cda.getChild(procedure, "code")));
    // SHALL contain exactly one [1..1] statusCode/@code, which SHALL be selected from ValueSet 2.16.840.1.113883.11.20.9.22 ProcedureAct
    // completed | active | aborted | cancelled - not in FHIR
    p.getModifierExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-status", Factory.newCode(cda.getStatus(procedure)), false));
    // SHOULD contain zero or one [0..1] effectiveTime (CONF:7662).
    p.setPerformed(convert.makePeriodFromIVL(cda.getChild(procedure, "effectiveTime")));
    // MAY contain zero or one [0..1] priorityCode/@code, which SHALL be selected from ValueSet 2.16.840.1.113883.1.11.16866 ActPriority DYNAMIC (CONF:7668)
    p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-priority", convert.makeCodeableConceptFromCD(cda.getChild(procedure, "priorityCode")), false));
    // MAY contain zero or one [0..1] methodCode (CONF:7670).
    p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-method", convert.makeCodeableConceptFromCD(cda.getChild(procedure, "methodCode")), false));
    if (type == ProcedureType.Observation) {
    // for Procedure-Observation:
    // 9.	SHALL contain exactly one [1..1] value (CONF:16846).
    // don't know what this is. It's not the actual result of the procedure (that goes in results "This section records ... procedure observations"), and there seems to be no value. The example as <value xsi:type="CD"/> which is not valid
    // so we ignore this for now
    }
    // SHOULD contain zero or more [0..*] targetSiteCode/@code, which SHALL be selected from ValueSet 2.16.840.1.113883.3.88.12.3221.8.9 Body site DYNAMIC (CONF:7683).
    for (Element e : cda.getChildren(procedure, "targetSiteCode")) p.addBodySite(convert.makeCodeableConceptFromCD(e));
    // SHOULD contain zero or more [0..*] performer (CONF:7718) such that it
    for (Element e : cda.getChildren(procedure, "performer")) {
        ProcedurePerformerComponent pp = new ProcedurePerformerComponent();
        p.getPerformer().add(pp);
        pp.setActor(makeReferenceToPractitionerForAssignedEntity(e, p));
    }
    for (Element participant : cda.getChildren(procedure, "participant")) {
        Element participantRole = cda.getlastChild(participant);
        if (type == ProcedureType.Procedure && cda.hasTemplateId(participantRole, "2.16.840.1.113883.10.20.22.4.37")) {
            // MAY contain zero or more [0..*] participant (CONF:7751) such that it  SHALL contain exactly one [1..1] @typeCode="DEV" Device
            // implanted devices
            p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/implanted-devices", Factory.makeReference(processDevice(participantRole, p)), false));
        } else if (cda.hasTemplateId(participantRole, "2.16.840.1.113883.10.20.22.4.32")) {
            // MAY contain zero or more [0..*] participant (CONF:7765) such that it SHALL contain exactly one [1..1] Service Delivery Location (templateId:2.16.840.1.113883.10.20.22.4.32) (CONF:7767)
            p.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/location", Factory.makeReference(processSDLocation(participantRole, p)), false));
        }
    }
    for (Element e : cda.getChildren(procedure, "entryRelationship")) {
        Element a = /* act*/
        cda.getlastChild(e);
        if (a.getLocalName().equals("encounter")) {
        // MAY contain zero or more [0..*] entryRelationship (CONF:7768) such that it SHALL contain exactly one encounter which SHALL contain exactly one [1..1] id (CONF:7773).
        // todo - and process as a full encounter while we're at it
        } else if (cda.hasTemplateId(a, "2.16.840.1.113883.10.20.22.4.20")) {
            // MAY contain zero or one [0..1] entryRelationship (CONF:7775) such that it SHALL contain exactly one [1..1] Instructions (templateId:2.16.840.1.113883.10.20.22.4.20) (CONF:7778).
            // had code for type, plus text for instructions
            Extension n = Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-instructions", null, true);
            n.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-instructions-type", convert.makeCodeableConceptFromCD(cda.getChild(a, "code")), false));
            n.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/procedure-instructions-text", convert.makeStringFromED(cda.getChild(a, "text")), false));
            p.getExtension().add(n);
        } else if (cda.hasTemplateId(a, "2.16.840.1.113883.10.20.22.4.19")) {
            // MAY contain zero or more [0..*] entryRelationship (CONF:7779) such that it SHALL contain exactly one [1..1] Indication (templateId:2.16.840.1.113883.10.20.22.4.19) (CONF:7781).
            p.addReasonCode(processIndication(a));
        } else if (cda.hasTemplateId(cda.getlastChild(e), "2.16.840.1.113883.10.20.22.4.16")) {
        // MAY contain zero or one [0..1] entryRelationship (CONF:7886) such that it SHALL contain exactly one [1..1] Medication Activity (templateId:2.16.840.1.113883.10.20.22.4.16) (CONF:7888).
        // todo
        }
    }
}
Also used : Element(org.w3c.dom.Element) ProcedurePerformerComponent(org.hl7.fhir.dstu3.model.Procedure.ProcedurePerformerComponent)

Example 19 with CD

use of org.hl7.v3.CD in project org.hl7.fhir.core by hapifhir.

the class JavaResourceGenerator method generate.

// public void generate(ElementDefinition root, String name, JavaGenClass clss, ProfiledType cd, Date genDate, String version, boolean isAbstract, Map<String, SearchParameterDefn> nameToSearchParamDef, ElementDefinition template) throws Exception {
public void generate(Analysis analysis) throws Exception {
    if (analysis.getStructure().getKind() == StructureDefinitionKind.RESOURCE) {
        clss = JavaGenClass.Resource;
    } else {
        clss = JavaGenClass.Type;
    }
    write("package org.hl7.fhir." + jid + ".model;\r\n");
    startMark(version, genDate);
    // hasList(root);
    boolean hl = true;
    boolean hh = hasXhtml(analysis.getStructure().getSnapshot().getElement());
    boolean hd = hasDecimal(analysis.getStructure().getSnapshot().getElement());
    boolean hs = hasString(analysis.getStructure().getSnapshot().getElement());
    boolean he = hasSharedEnums(analysis.getStructure().getSnapshot().getElement());
    boolean hn = hasNestedTypes(analysis.getStructure().getSnapshot().getElement());
    if (hl || hh || hd || he) {
        if (hl) {
            write("import java.util.ArrayList;\r\n");
            write("import java.util.Date;\r\n");
            write("import java.util.List;\r\n");
        } else {
            write("import java.util.Date;\r\n");
        }
        if (hh) {
            write("import org.hl7.fhir.utilities.xhtml.NodeType;\r\n");
            write("import org.hl7.fhir.utilities.xhtml.XhtmlNode;\r\n");
        }
        if (hd)
            write("import java.math.*;\r\n");
        if (hs)
            write("import org.hl7.fhir.utilities.Utilities;\r\n");
        if (he)
            write("import org.hl7.fhir." + jid + ".model.Enumerations.*;\r\n");
    }
    if (hn) {
        if (clss == JavaGenClass.Resource) {
            write("import org.hl7.fhir.instance.model.api.IBaseBackboneElement;\r\n");
        } else {
            write("import org.hl7.fhir.instance.model.api.IBaseDatatypeElement;\r\n");
        }
    }
    write("import org.hl7.fhir.exceptions.FHIRException;\r\n");
    write("import org.hl7.fhir.instance.model.api.ICompositeType;\r\n");
    if (clss == JavaGenClass.Resource) {
        write("import ca.uhn.fhir.model.api.annotation.ResourceDef;\r\n");
        write("import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;\r\n");
    }
    if (clss == JavaGenClass.Resource || "BackboneElement".equals(analysis.getName()) || "BackboneType".equals(analysis.getName())) {
        write("import org.hl7.fhir.instance.model.api.IBaseBackboneElement;\r\n");
    }
    write("import ca.uhn.fhir.model.api.annotation.Child;\r\n");
    write("import ca.uhn.fhir.model.api.annotation.ChildOrder;\r\n");
    if (clss != JavaGenClass.Resource) {
        write("import ca.uhn.fhir.model.api.annotation.DatatypeDef;\r\n");
    }
    write("import ca.uhn.fhir.model.api.annotation.Description;\r\n");
    write("import ca.uhn.fhir.model.api.annotation.Block;\r\n");
    write("\r\n");
    if (config.getIni().hasProperty("imports", analysis.getName())) {
        for (String imp : config.getIni().getStringProperty("imports", analysis.getName()).split("\\,")) {
            write("import " + imp.replace("{{jid}}", jid) + ";\r\n");
        }
    }
    jdoc("", replaceTitle(analysis.getName(), analysis.getStructure().getDescription()));
    TypeInfo ti = analysis.getRootType();
    boolean hasChildren = ti.getChildren().size() > 0;
    String superName = analysis.getAncestor() == null ? null : analysis.getAncestor().getName();
    if (VersionUtilities.isR4BVer(version) && !Utilities.noString(config.getIni().getStringProperty("R4B.CanonicalResources", analysis.getName()))) {
        superName = "CanonicalResource";
    }
    String hierarchy = analysis.getAncestor() != null ? "extends " + superName : "";
    if (clss == JavaGenClass.Resource) {
        if (!analysis.isAbstract()) {
            write("@ResourceDef(name=\"" + upFirst(analysis.getName()).replace("ListResource", "List") + "\", profile=\"http://hl7.org/fhir/StructureDefinition/" + upFirst(analysis.getName()) + "\")\r\n");
        }
    } else {
        write("@DatatypeDef(name=\"" + upFirst(analysis.getName()) + "\")\r\n");
        hierarchy = hierarchy + " implements ICompositeType";
    }
    if (config.getIni().hasProperty("hierarchy", analysis.getName())) {
        String h = config.getIni().getStringProperty("hierarchy", analysis.getName());
        if (analysis.getAncestor() != null) {
            h = h.replace("{{super}}", superName);
        }
        hierarchy = h;
    }
    write("public " + (analysis.isAbstract() ? "abstract " : "") + "class " + analysis.getClassName() + " " + hierarchy.trim() + " {\r\n");
    write("\r\n");
    for (String s : sorted(analysis.getEnums().keySet())) {
        EnumInfo e = analysis.getEnums().get(s);
        generateEnum(e);
    }
    for (TypeInfo t : analysis.getTypeList()) {
        generateType(analysis, t);
    }
    allfields = "";
    int i = 0;
    for (ElementDefinition e : ti.getChildren()) {
        if (!analysis.isInterface()) {
            generateField(analysis, ti, e, "    ", i++);
        }
    }
    write("    private static final long serialVersionUID = " + Long.toString(allfields.hashCode()) + "L;\r\n\r\n");
    hashSum = hashSum + allfields.hashCode();
    List<ElementDefinition> mandatory = new ArrayList<ElementDefinition>();
    generateConstructor(analysis.getClassName(), mandatory, "  ");
    if (hasChildren) {
        for (ElementDefinition e : ti.getChildren()) {
            if (e.getMin() > 0)
                mandatory.add(e);
        }
        if (mandatory.size() > 0)
            generateConstructor(analysis.getClassName(), mandatory, "  ");
        generateTypeSpecificConstructors(analysis.getClassName());
        for (ElementDefinition e : ti.getChildren()) {
            if (analysis.isInterface()) {
                generateAbstractAccessors(analysis, ti, e, "    ");
            } else {
                generateAccessors(analysis, ti, e, "    ", matchingInheritedElement(ti.getInheritedChildren(), e, analysis.getName()));
            }
        }
        if (!analysis.isInterface() && ti.getInheritedChildren() != null) {
            for (ElementDefinition e : filterInherited(ti.getInheritedChildren(), ti.getChildren())) {
                generateUnimplementedAccessors(analysis, ti, e, "    ");
            }
        }
        generateChildrenRegister(analysis, ti, "    ");
        generatePropertyGetterId(analysis, ti, "    ");
        generatePropertySetterId(analysis, ti, "    ");
        generatePropertySetterName(analysis, ti, "    ");
        generatePropertyMaker(analysis, ti, "    ");
        generatePropertyTypeGetter(analysis, ti, "    ");
        generateChildAdder(analysis, ti, "    ");
    }
    generateFhirType(analysis.getName());
    // // check for mappings
    // for (String map : root.getMappings().keySet()) {
    // if ("http://hl7.org/fhir/workflow".equals(map)) {
    // String namenn = root.getMapping(map);
    // if (patterns.containsKey(namenn)) {
    // generateImpl(namenn, patterns.get(namenn), upFirst(name), root, version, genDate);
    // }
    // }
    // }
    generateCopy(analysis, ti, false);
    if (hasChildren) {
        generateEquals(analysis, ti, false);
        generateIsEmpty(analysis, ti, false);
    }
    if (clss == JavaGenClass.Resource && !analysis.isAbstract()) {
        write("  @Override\r\n");
        write("  public ResourceType getResourceType() {\r\n");
        write("    return ResourceType." + analysis.getName() + ";\r\n");
        write("   }\r\n");
        write("\r\n");
    } else if (analysis.isAbstract() && analysis.getAncestor() != null && Utilities.noString(superName)) {
        write("\r\n");
        write("  @Override\r\n");
        write("  public String getIdBase() {\r\n");
        write("    return getId();\r\n");
        write("  }\r\n");
        write("  \r\n");
        write("  @Override\r\n");
        write("  public void setIdBase(String value) {\r\n");
        write("    setId(value);\r\n");
        write("  }\r\n");
        write("  public abstract ResourceType getResourceType();\r\n");
    } else if (analysis.isAbstract() && analysis.getAncestor() != null && Utilities.noString(superName)) {
        write("  @Override\r\n");
        write("  public String getIdBase() {\r\n");
        write("    return getId();\r\n");
        write("  }\r\n");
        write("  \r\n");
        write("  @Override\r\n");
        write("  public void setIdBase(String value) {\r\n");
        write("    setId(value);\r\n");
        write("  }\r\n");
    }
    // Write resource fields which can be used as constants in client code
    // to refer to standard search params
    Set<String> spcodes = new HashSet<>();
    for (SearchParameter sp : analysis.getSearchParams()) {
        String code = sp.getCode();
        if (!spcodes.contains(code)) {
            spcodes.add(code);
            /* 
		     * For composite codes we want to find the two param this is a composite
		     * of. We generate search parameter constants which reference the 
		     * component parts of the composite.  
		     */
            if (sp.getType() == SearchParamType.COMPOSITE) {
                if (code.endsWith("-[x]")) {
                    // partialCode will have "value" in this example
                    String partialCode = code.substring(0, code.length() - 4);
                    partialCode = partialCode.substring(partialCode.lastIndexOf('-') + 1);
                    // rootCode will have "component-code"
                    String rootCode = code.substring(0, code.indexOf("-" + partialCode));
                    /*
		         * If the composite has the form "foo-bar[x]" we expand this to create 
		         * a constant for each of the possible [x] values, so that client have
		         * static binding to the individual possibilities. AFAIK this is only
		         * used right now in Observation (e.g. for code-value-[x]) 
		         */
                    for (SearchParameter nextCandidate : analysis.getSearchParams()) {
                        if (nextCandidate.getCode().startsWith(partialCode)) {
                            String nextCompositeCode = rootCode + "-" + nextCandidate.getCode();
                            String[] compositeOf = new String[] { rootCode, nextCandidate.getCode() };
                            writeSearchParameterField(analysis.getName(), clss, analysis.isAbstract(), sp, nextCompositeCode, compositeOf, analysis.getSearchParams(), analysis.getName());
                        }
                    }
                } else {
                    SearchParameter comp0 = definitions.getSearchParams().get(sp.getComponent().get(0).getDefinition());
                    SearchParameter comp1 = definitions.getSearchParams().get(sp.getComponent().get(1).getDefinition());
                    if (comp0 != null && comp1 != null) {
                        String[] compositeOf = new String[] { comp0.getCode(), comp1.getCode() };
                        writeSearchParameterField(analysis.getName(), clss, analysis.isAbstract(), sp, sp.getCode(), compositeOf, analysis.getSearchParams(), analysis.getName());
                    }
                }
            } else if (code.contains("[x]")) {
                /*
		       * We only know how to handle search parameters with [x] in the name
		       * where it's a composite, and the [x] comes last. Are there other possibilities?
		       */
                throw new Exception("Unable to generate constant for search parameter: " + code);
            } else {
                writeSearchParameterField(analysis.getName(), clss, analysis.isAbstract(), sp, code, null, analysis.getSearchParams(), analysis.getName());
            }
        }
    }
    if (VersionUtilities.isR4BVer(version)) {
        String extras = config.getIni().getStringProperty("R4B.NullImplementation", analysis.getName());
        if (!Utilities.noString(extras)) {
            for (String n : extras.split("\\,")) {
                String t = n.substring(n.indexOf(":") + 1);
                n = n.substring(0, n.indexOf(":"));
                if (n.endsWith("[]")) {
                    n = Utilities.capitalize(n.substring(0, n.length() - 2));
                    write("      @Override\r\n");
                    write("      public List<" + t + "> get" + n + "() {\r\n");
                    write("        return new ArrayList<>();\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public CanonicalResource set" + n + "(List<" + t + "> the" + n + ") {\r\n");
                    write("        return this;\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public boolean has" + n + "() {\r\n");
                    write("        return false;\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public " + t + " add" + n + "() {\r\n");
                    write("	        return null;\r\n");
                    write("	      }\r\n");
                    write("	      \r\n");
                    write("      @Override\r\n");
                    write("      public CanonicalResource add" + n + "(" + t + " t) {\r\n");
                    write("        return null;\r\n");
                    write("	      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public " + t + " get" + n + "FirstRep() {\r\n");
                    write("        return new " + t + "();\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                } else if (t.contains("|")) {
                    n = Utilities.capitalize(n);
                    String t1 = t.substring(0, t.indexOf("|"));
                    String t2 = t.substring(t.indexOf("|") + 1);
                    write("      @Override\r\n");
                    write("      public " + t1 + " get" + n + "() {\r\n");
                    if ("boolean".equals(t1)) {
                        write("        return false;\r\n");
                    } else {
                        write("        return new " + t1 + "();\r\n");
                    }
                    write("      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public " + t2 + " get" + n + "Element() {\r\n");
                    write("        return new " + t2 + "();\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public CanonicalResource set" + n + "(" + t1 + " the" + n + ") {\r\n");
                    write("        return this;\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public CanonicalResource set" + n + "Element(" + t2 + " the" + n + ") {\r\n");
                    write("        return this;\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public boolean has" + n + "() {\r\n");
                    write("        return false;\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public boolean has" + n + "Element() {\r\n");
                    write("        return false;\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      \r\n");
                } else {
                    n = Utilities.capitalize(n);
                    write("      @Override\r\n");
                    write("      public " + t + " get" + n + "() {\r\n");
                    write("        return new " + t + "();\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public CanonicalResource set" + n + "(" + t + " the" + n + ") {\r\n");
                    write("        return this;\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public boolean has" + n + "() {\r\n");
                    write("        return false;\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public boolean has" + n + "Element() {\r\n");
                    write("        return false;\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      \r\n");
                }
            }
        }
    }
    if (config.getAdornments().containsKey(analysis.getClassName())) {
        write("// Manual code (from Configuration.txt):\r\n");
        write(config.getAdornments().get(analysis.getClassName()) + "\r\n");
        write("// end addition\r\n");
    }
    write("\r\n");
    write("}\r\n");
    write("\r\n");
    flush();
}
Also used : EnumInfo(org.hl7.fhir.core.generator.analysis.EnumInfo) ArrayList(java.util.ArrayList) TypeInfo(org.hl7.fhir.core.generator.analysis.TypeInfo) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) SearchParameter(org.hl7.fhir.r5.model.SearchParameter) HashSet(java.util.HashSet)

Example 20 with CD

use of org.hl7.v3.CD in project org.hl7.fhir.core by hapifhir.

the class Analyser method scanNestedTypes.

private void scanNestedTypes(Analysis analysis, TypeInfo type, String path, ElementDefinition e) throws Exception {
    String tn = null;
    if (e.typeSummary().equals("code") && e.hasBinding()) {
        ElementDefinitionBindingComponent cd = e.getBinding();
        if (isEnum(cd)) {
            ValueSet vs = definitions.getValuesets().get(cd.getValueSet());
            if (vs != null) {
                tn = getCodeListType(vs.getName());
                EnumInfo ei = analysis.getEnums().get(tn);
                if (ei == null) {
                    ei = new EnumInfo(tn);
                    analysis.getEnums().put(tn, ei);
                    ei.setValueSet(vs);
                }
                if (tn.equals("SubscriptionStatus")) {
                    // work around cause there's a Resource with the same name
                    tn = "org.hl7.fhir.r4b.model.Enumerations." + tn;
                }
                e.setUserData("java.type", "Enumeration<" + tn + ">");
                e.setUserData("java.enum", ei);
            }
        }
    }
    if (tn == null) {
        if (e.getType().size() > 0 && !e.hasContentReference() && (!Utilities.existsInList(e.getType().get(0).getCode(), "Element", "BackboneElement"))) {
            tn = getTypeName(e);
            if (e.typeSummary().equals("xml:lang"))
                tn = "CodeType";
            if (e.typeSummary().equals("xhtml"))
                tn = "XhtmlNode";
            else if (e.getType().size() > 1)
                tn = "DataType";
            else if (definitions.hasPrimitiveType(tn))
                tn = upFirst(tn) + "Type";
            e.setUserData("java.type", tn);
        } else {
            if (e.hasContentReference()) {
                ElementDefinition er = getElementForPath(analysis.getStructure(), e.getContentReference().substring(1));
                tn = er.getUserString("java.type");
                if (Utilities.noString(tn)) {
                    // have to resolve this later
                    e.setUserData("java.type", "@" + er.getPath());
                } else {
                    e.setUserData("java.type", tn);
                }
            } else {
                String cpath;
                if (e.hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name")) {
                    tn = upFirst(e.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name")) + "Component";
                    cpath = e.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name");
                } else if (config.getIni().hasProperty("typenames", e.getPath())) {
                    tn = upFirst(config.getIni().getStringProperty("typenames", e.getPath())) + "Component";
                    cpath = config.getIni().getStringProperty("typenames", e.getPath());
                } else {
                    tn = path + upFirst(getTitle(e.getName())) + "Component";
                    cpath = path + getTitle(e.getName());
                }
                if (tn.equals("Element"))
                    tn = "Element_";
                if (analysis.getTypes().containsKey(tn)) {
                    char i = 'A';
                    while (analysis.getTypes().containsKey(tn + i)) {
                        i++;
                    }
                    tn = tn + i;
                }
                e.setUserData("java.type", tn);
                tn = upFirst(tn);
                TypeInfo ctype = new TypeInfo();
                ctype.setName(tn);
                analysis.getTypes().put(ctype.getName(), ctype);
                analysis.getTypeList().add(ctype);
                ctype.setDefn(e);
                ctype.setAncestorName(e.typeSummary());
                ctype.setChildren(filterChildren(new ProfileUtilities(null, null, null).getChildList(analysis.getStructure(), ctype.getDefn())));
                for (ElementDefinition c : ctype.getChildren()) {
                    scanNestedTypes(analysis, ctype, cpath, c);
                }
            }
        }
    }
}
Also used : ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) ElementDefinitionBindingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Aggregations

ArrayList (java.util.ArrayList)24 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)16 Coding (org.hl7.fhir.r4.model.Coding)10 ValueSet (org.hl7.fhir.r5.model.ValueSet)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)9 BindingSpecification (org.hl7.fhir.definitions.model.BindingSpecification)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 CD (net.ihe.gazelle.hl7v3.datatypes.CD)7 CS (net.ihe.gazelle.hl7v3.datatypes.CS)7 II (net.ihe.gazelle.hl7v3.datatypes.II)7 TS (net.ihe.gazelle.hl7v3.datatypes.TS)7 MCCIMT000100UV01Device (net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Device)7 MCCIMT000100UV01Receiver (net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Receiver)7 MCCIMT000100UV01Sender (net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Sender)7 Identifier (org.hl7.fhir.r4.model.Identifier)7 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)7 IOException (java.io.IOException)6 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)6 ContactDetail (org.hl7.fhir.r5.model.ContactDetail)5