Search in sources :

Example 66 with ResourceDefn

use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.

the class ResourceTableGenerator method generate.

public XhtmlNode generate(ResourceDefn r, String prefix, boolean isActive) throws Exception {
    HierarchicalTableGenerator gen = new HierarchicalTableGenerator(dest, inlineGraphics, true);
    ElementDefn e = r.getRoot();
    RenderMode mode = e.typeCode().equals("Logical") && hasLogicalMapping(e) ? RenderMode.LOGICAL : RenderMode.RESOURCE;
    TableModel model = gen.initNormalTable(prefix, mode == RenderMode.LOGICAL, true, r.getName(), isActive);
    model.getRows().add(genElement(e, gen, true, e.getName(), false, prefix, mode, true, r.getStatus(), r.isAbstract(), r.isInterface()));
    return gen.generate(model, prefix, 0, null);
}
Also used : ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) HierarchicalTableGenerator(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator) TableModel(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel)

Example 67 with ResourceDefn

use of org.hl7.fhir.definitions.model.ResourceDefn in project org.hl7.fhir.core by hapifhir.

the class JavaResourceGenerator method writeSearchParameterField.

// private void generateImpl(String namenn, ResourceDefn resourceDefn, String jn, ElementDefinition root, String version, Date genDate) throws Exception {
// // TODO - restore this
// //    write("  public "+namenn+" get"+namenn+"() {\r\n");
// //    write("    return new "+jn+namenn+"Impl(this);\r\n");
// //    write("  }\r\n");
// //
// //    // now, generate the implementation
// //    JavaPatternImplGenerator jrg = new JavaPatternImplGenerator(new FileOutputStream(javaPatternDir+jn+namenn+"Impl.java"), definitions, adornments, enumInfo);
// //    jrg.generate(resourceDefn.getRoot(), jn, JavaGenClass.Resource, null, genDate, version, false, null, null, namenn, root);
// //    jrg.close();
// //
// }
private void writeSearchParameterField(String name, JavaGenClass clss, boolean isAbstract, SearchParameter sp, String code, String[] theCompositeOf, List<SearchParameter> searchParams, String rn) throws IOException {
    String constName = cleanSpName(code).toUpperCase();
    /*
     * SearchParamDefinition (SP_[name])
     */
    write(" /**\r\n");
    write("   * Search parameter: <b>" + code + "</b>\r\n");
    write("   * <p>\r\n");
    write("   * Description: <b>" + sp.getDescription() + "</b><br>\r\n");
    write("   * Type: <b>" + sp.getType().toCode() + "</b><br>\r\n");
    write("   * Path: <b>" + sp.getExpression() + "</b><br>\r\n");
    write("   * </p>\r\n");
    write("   */\r\n");
    write("  @SearchParamDefinition(name=\"" + code + "\", path=\"" + defaultString(sp.getExpression()) + "\", description=\"" + Utilities.escapeJava(sp.getDescription()) + "\", type=\"" + sp.getType().toCode() + "\"");
    if (theCompositeOf != null && theCompositeOf.length > 0) {
        write(", compositeOf={");
        for (int i = 0; i < theCompositeOf.length; i++) {
            if (i > 0) {
                write(", ");
            }
            write("\"" + theCompositeOf[i] + "\"");
        }
        write("}");
    }
    Set<String> providesMembershipIn = new TreeSet<String>();
    for (CompartmentDefinition next : this.definitions.getCompartments().getList()) {
        for (CompartmentDefinitionResourceComponent nextEntry : next.getResource()) {
            if (nextEntry.getCode().equals(upFirst(name))) {
                for (StringType nextPart : nextEntry.getParam()) {
                    if (nextPart.toString().equals(code)) {
                        providesMembershipIn.add(next.getName());
                    }
                }
            }
        }
    }
    if (providesMembershipIn.size() > 0) {
        write(", providesMembershipIn={ ");
        boolean first = true;
        for (String next : providesMembershipIn) {
            if (first) {
                first = false;
            } else {
                write(", ");
            }
            write("@ca.uhn.fhir.model.api.annotation.Compartment(name=\"" + upFirst(next) + "\")");
        }
        write(" }");
    }
    Set<String> targets = new TreeSet<>();
    for (CodeType c : sp.getTarget()) {
        targets.add(c.asStringValue());
    }
    if (targets != null && !targets.isEmpty() && !targets.contains("Any")) {
        write(", target={");
        boolean first = true;
        for (String nextTarget : targets) {
            if (first) {
                first = false;
            } else {
                write(", ");
            }
            write("List".equals(nextTarget) ? "ListResource" : nextTarget);
            write(".class");
        }
        write(" }");
    }
    write(" )\r\n");
    write("  public static final String SP_" + constName + " = \"" + code + "\";\r\n");
    String genericTypes = "";
    if (theCompositeOf != null && theCompositeOf.length > 0) {
        SearchParameter typeDef0 = findSearchParam(searchParams, theCompositeOf[0]);
        SearchParameter typeDef1 = findSearchParam(searchParams, theCompositeOf[1]);
        genericTypes = "<ca.uhn.fhir.rest.gclient." + upFirst(typeDef0.getType().toCode()) + "ClientParam" + ", ca.uhn.fhir.rest.gclient." + upFirst(typeDef1.getType().toCode()) + "ClientParam>";
    }
    /*
     * Client parameter ([name])
     */
    write(" /**\r\n");
    write("   * <b>Fluent Client</b> search parameter constant for <b>" + code + "</b>\r\n");
    write("   * <p>\r\n");
    write("   * Description: <b>" + sp.getDescription() + "</b><br>\r\n");
    write("   * Type: <b>" + sp.getType().toCode() + "</b><br>\r\n");
    write("   * Path: <b>" + sp.getExpression() + "</b><br>\r\n");
    write("   * </p>\r\n");
    write("   */\r\n");
    write("  public static final ca.uhn.fhir.rest.gclient." + upFirst(sp.getType().toCode()) + "ClientParam" + genericTypes + " " + constName + " = new ca.uhn.fhir.rest.gclient." + upFirst(sp.getType().toCode()) + "ClientParam" + genericTypes + "(SP_" + constName + ");\r\n\r\n");
    if (sp.getType() == SearchParamType.REFERENCE && clss == JavaGenClass.Resource && !isAbstract) {
        String incName = upFirst(name) + ":" + code;
        write("/**\r\n");
        write("   * Constant for fluent queries to be used to add include statements. Specifies\r\n");
        write("   * the path value of \"<b>" + incName + "</b>\".\r\n");
        write("   */\r\n");
        write("  public static final ca.uhn.fhir.model.api.Include INCLUDE_" + cleanSpName(code).toUpperCase() + " = new ca.uhn.fhir.model.api.Include(\"" + incName + "\").toLocked();\r\n\r\n");
    }
}
Also used : CompartmentDefinitionResourceComponent(org.hl7.fhir.r5.model.CompartmentDefinition.CompartmentDefinitionResourceComponent) StringType(org.hl7.fhir.r5.model.StringType) TreeSet(java.util.TreeSet) CompartmentDefinition(org.hl7.fhir.r5.model.CompartmentDefinition) CodeType(org.hl7.fhir.r5.model.CodeType) SearchParameter(org.hl7.fhir.r5.model.SearchParameter)

Example 68 with ResourceDefn

use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.

the class BreadCrumbManager method getSpineOrder1.

private void getSpineOrder1(List<String> res, Page page) throws Exception {
    if (page.getType() == PageType.resource) {
        ResourceDefn rd = definitions.getResourceByName(page.resource);
        String resource = page.resource.toLowerCase();
        res.add(resource + ".html");
        if (!rd.isAbstract()) {
            res.add(resource + "-examples.html");
            res.add(resource + "-definitions.html");
            if (!rd.getName().equals("Parameters")) {
                res.add(resource + "-mappings.html");
                res.add(resource + "-explanations.html");
                res.add(resource + "-profiles.html");
            }
        }
    } else if (!Utilities.noString(page.filename))
        res.add(page.filename);
    for (Node p : page.getChildren()) {
        if (p instanceof Page)
            getSpineOrder1(res, (Page) p);
        else {
        // ignore for now
        }
    }
}
Also used : XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn)

Example 69 with ResourceDefn

use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.

the class ResourceValidator method check.

public void check(List<ValidationMessage> errors, String name, ResourceDefn rd) throws Exception {
    for (String s : rd.getHints()) hint(errors, IssueType.INFORMATIONAL, rd.getName(), false, s);
    rule(errors, IssueType.STRUCTURE, rd.getName(), !name.equals("Metadata"), "The name 'Metadata' is not a legal name for a resource");
    rule(errors, IssueType.STRUCTURE, rd.getName(), !name.equals("History"), "The name 'History' is not a legal name for a resource");
    rule(errors, IssueType.STRUCTURE, rd.getName(), !name.equals("Tag"), "The name 'Tag' is not a legal name for a resource");
    rule(errors, IssueType.STRUCTURE, rd.getName(), !name.equals("Tags"), "The name 'Tags' is not a legal name for a resource");
    rule(errors, IssueType.STRUCTURE, rd.getName(), !name.equals("MailBox"), "The name 'MailBox' is not a legal name for a resource");
    rule(errors, IssueType.STRUCTURE, rd.getName(), !name.equals("Validation"), "The name 'Validation' is not a legal name for a resource");
    rule(errors, IssueType.REQUIRED, rd.getName(), name.equals("Parameters") || translations.hasTranslation(name), "The name '" + name + "' is not found in the file translations.xml");
    rule(errors, IssueType.STRUCTURE, rd.getName(), name.length() > 1 && Character.isUpperCase(name.charAt(0)), "Resource Name must start with an uppercase alpha character");
    rule(errors, IssueType.STRUCTURE, rd.getName(), !Utilities.noString(rd.getFmmLevel()), "Resource must have a maturity level");
    // too many downstream issues in the parsers, and it would only happen as a transient thing when designing the resources
    rule(errors, IssueType.REQUIRED, rd.getName(), rd.getRoot().getElements().size() > 0, "A resource must have at least one element in it before the build can proceed");
    // too many downstream issues in the parsers, and it would only happen as a transient thing when designing the resources
    rule(errors, IssueType.REQUIRED, rd.getName(), rd.getWg() != null, "A resource must have a designated owner");
    rule(errors, IssueType.REQUIRED, rd.getName(), !Utilities.noString(rd.getRoot().getW5()), "A resource must have a W5 category");
    rd.getRoot().setMinCardinality(0);
    rd.getRoot().setMaxCardinality(Integer.MAX_VALUE);
    // pattern related rules
    buildW5Mappings(rd.getRoot(), true);
    if ((isWorkflowPattern(rd, "Event") || isWorkflowPattern(rd, "Request")) && hasPatient(rd)) {
        rule(errors, IssueType.STRUCTURE, rd.getName(), rd.getSearchParams().containsKey("patient"), "An 'event' or 'request' resource must have a search parameter 'patient'");
    }
    if (suppressedwarning(errors, IssueType.REQUIRED, rd.getName(), hasW5Mappings(rd) || rd.getName().equals("Binary") || rd.getName().equals("OperationOutcome") || rd.getName().equals("Parameters"), "A resource must have w5 mappings")) {
        String w5Order = listW5Elements(rd);
        String w5CorrectOrder = listW5Correct(rd);
        if (!w5Order.equals(w5CorrectOrder)) {
            warning(errors, IssueType.REQUIRED, rd.getName(), false, "Resource elements are out of order. The correct order is '" + w5CorrectOrder + "' but the actual order is '" + w5Order + "'");
        // System.out.println("Resource "+parent.getName()+": elements are out of order. The correct order is '"+w5CorrectOrder+"' but the actual order is '"+w5Order+"'");
        }
        if (!Utilities.noString(rd.getProposedOrder())) {
            w5Order = listW5Elements(rd, rd.getProposedOrder());
            if (!w5Order.equals(w5CorrectOrder)) {
                rule(errors, IssueType.REQUIRED, rd.getName(), false, "Proposed Resource elements are out of order. The correct order is '" + w5CorrectOrder + "' but the proposed order is '" + w5Order + "'");
            } else
                System.out.println("Proposed order for " + rd.getName() + ": build order ok");
        }
    }
    if (Utilities.noString(rd.getEnteredInErrorStatus()))
        if (hasStatus(rd, "entered-in-error"))
            rd.setEnteredInErrorStatus(".status = entered-in-error");
        else if (hasStatus(rd, "retired"))
            rd.setEnteredInErrorStatus(".status = retired");
        else if (hasActivFalse(rd))
            rd.setEnteredInErrorStatus(".active = false");
        else
            // too many downstream issues in the parsers, and it would only happen as a transient thing when designing the resources
            warning(errors, IssueType.REQUIRED, rd.getName(), false, "A resource must have an 'entered in error' status");
    String s = rd.getRoot().getMapping(Definitions.RIM_MAPPING);
    hint(errors, IssueType.REQUIRED, rd.getName(), !Utilities.noString(s), "RIM Mapping is required");
    for (Operation op : rd.getOperations()) {
        warning(errors, IssueType.BUSINESSRULE, rd.getName() + ".$" + op.getName(), hasOpExample(op.getExamples(), false), "Operation must have an example request");
        warning(errors, IssueType.BUSINESSRULE, rd.getName() + ".$" + op.getName(), hasOpExample(op.getExamples(), true), "Operation must have an example response");
    }
    List<String> vsWarns = new ArrayList<String>();
    int vsWarnings = checkElement(errors, rd.getName(), rd.getRoot(), rd, null, s == null || !s.equalsIgnoreCase("n/a"), false, hasSummary(rd.getRoot()), vsWarns, true, rd.getStatus());
    if (!resourceIsTechnical(name)) {
        // these are exempt because identification is tightly managed
        ElementDefn id = rd.getRoot().getElementByName(definitions, "identifier", true, false);
        if (id == null)
            warning(errors, IssueType.STRUCTURE, rd.getName(), false, "All resources should have an identifier");
        else
            rule(errors, IssueType.STRUCTURE, rd.getName(), id.typeCode().equals("Identifier"), "If a resource has an element named identifier, it must have a type 'Identifier'");
    }
    rule(errors, IssueType.STRUCTURE, rd.getName(), rd.getRoot().getElementByName(definitions, "text", true, false) == null, "Element named \"text\" not allowed");
    rule(errors, IssueType.STRUCTURE, rd.getName(), rd.getRoot().getElementByName(definitions, "contained", true, false) == null, "Element named \"contained\" not allowed");
    if (rd.getRoot().getElementByName(definitions, "subject", true, false) != null && rd.getRoot().getElementByName(definitions, "subject", true, false).typeCode().startsWith("Reference"))
        rule(errors, IssueType.STRUCTURE, rd.getName(), rd.getSearchParams().containsKey("subject"), "A resource that contains a subject reference must have a search parameter 'subject'");
    ElementDefn ped = rd.getRoot().getElementByName(definitions, "patient", true, false);
    if (ped != null && ped.typeCode().startsWith("Reference")) {
        SearchParameterDefn spd = rd.getSearchParams().get("patient");
        if (rule(errors, IssueType.STRUCTURE, rd.getName(), spd != null, "A resource that contains a patient reference must have a search parameter 'patient'"))
            rule(errors, IssueType.STRUCTURE, rd.getName(), (spd.getTargets().size() == 1 && spd.getTargets().contains("Patient")) || (ped.getTypes().get(0).getParams().size() == 1 && ped.getTypes().get(0).getParams().get(0).equals("Patient")), "A Patient search parameter must only refer to patient");
    }
    ElementDefn sed = rd.getRoot().getElementByName(definitions, "subject", true, false);
    if (sed != null && sed.typeCode().startsWith("Reference") && sed.typeCode().contains("Patient"))
        warning(errors, IssueType.STRUCTURE, rd.getName(), rd.getSearchParams().containsKey("patient"), "A resource that contains a subject that can be a patient reference must have a search parameter 'patient'");
    if (rd.getRoot().getElementByName(definitions, "identifier", true, false) != null) {
        warning(errors, IssueType.STRUCTURE, rd.getName(), rd.getSearchParams().containsKey("identifier"), "A resource that contains an identifier must have a search parameter 'identifier'");
    }
    if (rd.getRoot().getElementByName(definitions, "status", true, false) != null) {
        // todo: change to a warning post STU3
        hint(errors, IssueType.STRUCTURE, rd.getName(), rd.getSearchParams().containsKey("status"), "A resource that contains a status element must have a search parameter 'status'");
    }
    if (rd.getRoot().getElementByName(definitions, "url", true, false) != null) {
        warning(errors, IssueType.STRUCTURE, rd.getName(), rd.getSearchParams().containsKey("url"), "A resource that contains a url element must have a search parameter 'url'");
    }
    checkSearchParams(errors, rd);
    for (Operation op : rd.getOperations()) {
        rule(errors, IssueType.STRUCTURE, rd.getName() + "/$" + op.getName(), !parentHasOp(rd.getRoot().typeCode(), op.getName()), "Duplicate Operation Name $" + op.getName() + " on " + rd.getName());
    }
    for (Compartment c : definitions.getCompartments()) {
        if (rule(errors, IssueType.STRUCTURE, rd.getName(), name.equals("Parameters") || c.getResources().containsKey(rd), "Resource not entered in resource map for compartment '" + c.getTitle() + "' (compartments.xml)")) {
            String param = c.getResources().get(rd);
            if (!Utilities.noString(param)) {
                // rule(errors, IssueType.STRUCTURE, parent.getName(), param.equals("{def}") || parent.getSearchParams().containsKey(c.getName()), "Resource "+parent.getName()+" in compartment " +c.getName()+" must have a search parameter named "+c.getName().toLowerCase()+")");
                for (String p : param.split("\\|")) {
                    String pn = p.trim();
                    if (pn.contains("."))
                        pn = pn.substring(0, pn.indexOf("."));
                    rule(errors, IssueType.STRUCTURE, rd.getName(), Utilities.noString(pn) || pn.equals("{def}") || rd.getSearchParams().containsKey(pn), "Resource " + rd.getName() + " in compartment " + c.getName() + ": parameter " + param + " was not found (" + pn + ")");
                }
            }
        }
    }
    // Remove suppressed messages
    List<ValidationMessage> suppressed = new ArrayList<ValidationMessage>();
    for (ValidationMessage em : errors) {
        if (isSuppressedMessage(em.getDisplay())) {
            suppressed.add(em);
        }
    }
    errors.removeAll(suppressed);
    // last check: if maturity level is
    int warnings = 0;
    int hints = 0;
    for (ValidationMessage em : errors) {
        if (em.getLevel() == IssueSeverity.WARNING)
            warnings++;
        else if (em.getLevel() == IssueSeverity.INFORMATION)
            hints++;
    }
    boolean ok = warnings == 0 || "0".equals(rd.getFmmLevel());
    if (rule(errors, IssueType.STRUCTURE, rd.getName(), ok, "Resource " + rd.getName() + " (FMM=" + rd.getFmmLevel() + ") cannot have an FMM level >1 (" + rd.getFmmLevel() + ") if it has warnings"))
        rule(errors, IssueType.STRUCTURE, rd.getName(), vsWarnings == 0 || "0".equals(rd.getFmmLevel()), "Resource " + rd.getName() + " (FMM=" + rd.getFmmLevel() + ") cannot have an FMM level >1 (" + rd.getFmmLevel() + ") if it has linked value set warnings (" + vsWarns.toString() + ")");
    ok = hints == 0 || Integer.parseInt(rd.getFmmLevel()) < 3;
    rule(errors, IssueType.STRUCTURE, rd.getName(), ok, "Resource " + rd.getName() + " (FMM=" + rd.getFmmLevel() + ") cannot have an FMM level >2 (" + rd.getFmmLevel() + ") if it has informational hints");
// if (isInterface(rd.getRoot().typeCode())) {
// checkInterface(errors, rd, definitions.getBaseResources().get(rd.getRoot().typeCode()));
// }
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage)

Example 70 with ResourceDefn

use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.

the class ProfileGenerator method generate.

public StructureDefinition generate(Profile pack, ConstraintStructure profile, ResourceDefn resource, String id, String html, ImplementationGuideDefn usage, List<ValidationMessage> issues, ResourceDefn baseResource) throws Exception {
    if (profile.getResource() != null)
        return profile.getResource();
    StructureDefinition p = new StructureDefinition();
    p.setId(FormatUtilities.makeId(id));
    p.setUrl("http://hl7.org/fhir/StructureDefinition/" + id);
    if (usage != null && !usage.isCore()) {
        if (!id.startsWith(usage.getCode() + "-"))
            throw new Exception("Error: " + id + " must start with " + usage.getCode() + "-");
    }
    if (!resource.getRoot().getTypes().isEmpty() && (resource.getRoot().getTypes().get(0).getProfile() != null))
        p.setBaseDefinition(resource.getRoot().getTypes().get(0).getProfile());
    else
        p.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/" + resource.getName());
    if (definitions.hasType(resource.getName()))
        p.setKind(StructureDefinitionKind.COMPLEXTYPE);
    else
        p.setKind(StructureDefinitionKind.RESOURCE);
    p.setType(resource.getName());
    p.setDerivation(TypeDerivationRule.CONSTRAINT);
    p.setAbstract(false);
    p.setUserData("filename", id);
    p.setUserData("path", ((usage == null || usage.isCore()) ? "" : usage.getCode() + File.separator) + id + ".html");
    p.setTitle(pack.metadata("display"));
    p.setFhirVersion(version);
    p.setVersion(version.toCode());
    if (pack.hasMetadata("summary-" + profile.getTitle()))
        ToolingExtensions.addMarkdownExtension(p, "http://hl7.org/fhir/StructureDefinition/structuredefinition-summary", pack.metadata("summary-" + profile.getTitle()));
    ToolResourceUtilities.updateUsage(p, usage.getCode());
    p.setName(pack.metadata("name"));
    p.setPublisher(pack.metadata("author.name"));
    if (pack.hasMetadata("author.reference"))
        p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, pack.metadata("author.reference")));
    // <code> opt Zero+ Coding assist with indexing and finding</code>
    p.setDescription(resource.getRoot().getShortDefn());
    if (!p.hasDescriptionElement() && pack.hasMetadata("description"))
        p.setDescription(preProcessMarkdown(pack.metadata("description"), "pack.description"));
    p.setPurpose(resource.getRoot().getRequirements());
    if (!p.hasPurpose() && pack.hasMetadata("requirements"))
        p.setPurpose(pack.metadata("requirements"));
    p.setExperimental(Utilities.existsInList(pack.metadata("Experimental"), "y", "Y", "true", "TRUE", "1"));
    if (pack.hasMetadata("date"))
        p.setDateElement(Factory.newDateTime(pack.metadata("date").substring(0, 10)));
    else
        p.setDate(genDate.getTime());
    if (pack.hasMetadata("fmm-level"))
        ToolingExtensions.addIntegerExtension(p, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(pack.getFmmLevel()));
    else if (pack.hasMetadata("fmm"))
        ToolingExtensions.addIntegerExtension(p, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(pack.metadata("fmm")));
    else if (!Utilities.noString(resource.getFmmLevel()))
        ToolingExtensions.addIntegerExtension(p, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(resource.getFmmLevel()));
    else if (baseResource != null && !Utilities.noString(baseResource.getFmmLevel()))
        ToolingExtensions.addIntegerExtension(p, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(baseResource.getFmmLevel()));
    if (pack.hasMetadata("workgroup"))
        ToolingExtensions.setCodeExtension(p, ToolingExtensions.EXT_WORKGROUP, pack.getWg());
    else if (resource.getWg() != null)
        ToolingExtensions.setCodeExtension(p, ToolingExtensions.EXT_WORKGROUP, resource.getWg().getCode());
    else if (baseResource != null && baseResource.getWg() != null)
        ToolingExtensions.setCodeExtension(p, ToolingExtensions.EXT_WORKGROUP, baseResource.getWg().getCode());
    if (pack.hasMetadata("Standards-Status"))
        ToolingExtensions.setStandardsStatus(p, StandardsStatus.fromCode(pack.metadata("Standards-Status")), null);
    else
        ToolingExtensions.setStandardsStatus(p, resource.getStatus(), null);
    if (pack.hasMetadata("status"))
        p.setStatus(PublicationStatus.fromCode(pack.metadata("status")));
    if (pack.getMetadata().containsKey("code"))
        for (String s : pack.getMetadata().get("code")) if (!Utilities.noString(s))
            p.getKeyword().add(Factory.makeCoding(s));
    if (pack.hasMetadata("datadictionary"))
        ToolingExtensions.setStringExtension(p, "http://hl7.org/fhir/StructureDefinition/datadictionary", pack.metadata("datadictionary"));
    Set<String> containedSlices = new HashSet<String>();
    p.setDifferential(new StructureDefinitionDifferentialComponent());
    defineElement(pack, p, p.getDifferential().getElement(), resource.getRoot(), resource.getName(), containedSlices, new ArrayList<ProfileGenerator.SliceHandle>(), SnapShotMode.None, true, null, null, false);
    List<String> names = new ArrayList<String>();
    names.addAll(resource.getSearchParams().keySet());
    Collections.sort(names);
    for (String pn : names) {
        pack.getSearchParameters().add(makeSearchParam(p, pack.getId() + "-" + resource.getName() + "-" + pn, resource.getName(), resource.getSearchParams().get(pn), resource));
    }
    StructureDefinition base = definitions.getSnapShotForBase(p.getBaseDefinition());
    List<String> errors = new ArrayList<String>();
    new ProfileUtilities(context, null, pkp).sortDifferential(base, p, p.getName(), errors, false);
    for (String s : errors) issues.add(new ValidationMessage(Source.ProfileValidator, IssueType.STRUCTURE, -1, -1, p.getUrl(), s, IssueSeverity.WARNING));
    reset();
    // ok, c is the differential. now we make the snapshot
    new ProfileUtilities(context, issues, pkp).generateSnapshot(base, p, "http://hl7.org/fhir/StructureDefinition/" + p.getType(), "http://hl7.org/fhir", p.getName());
    reset();
    p.getDifferential().getElement().get(0).getType().clear();
    p.getSnapshot().getElement().get(0).getType().clear();
    addElementConstraintToSnapshot(p);
    XhtmlNode div = new XhtmlNode(NodeType.Element, "div");
    div.addText("to do");
    p.setText(new Narrative());
    p.getText().setStatus(NarrativeStatus.GENERATED);
    p.getText().setDiv(div);
    new ProfileUtilities(context, issues, pkp).setIds(p, false);
    checkHasTypes(p);
    return p;
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ArrayList(java.util.ArrayList) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) Narrative(org.hl7.fhir.r5.model.Narrative) StructureDefinitionDifferentialComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionDifferentialComponent) HashSet(java.util.HashSet)

Aggregations

ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)75 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)42 ArrayList (java.util.ArrayList)38 FHIRException (org.hl7.fhir.exceptions.FHIRException)36 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)31 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)28 File (java.io.File)26 FileOutputStream (java.io.FileOutputStream)25 CSFile (org.hl7.fhir.utilities.CSFile)24 XmlParser (org.hl7.fhir.r5.formats.XmlParser)22 FileNotFoundException (java.io.FileNotFoundException)20 IOException (java.io.IOException)20 Example (org.hl7.fhir.definitions.model.Example)20 Profile (org.hl7.fhir.definitions.model.Profile)20 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)18 IniFile (org.hl7.fhir.utilities.IniFile)18 ImplementationGuideDefn (org.hl7.fhir.definitions.model.ImplementationGuideDefn)16 TransformerException (javax.xml.transform.TransformerException)15 TextFile (org.hl7.fhir.utilities.TextFile)15 SearchParameterDefn (org.hl7.fhir.definitions.model.SearchParameterDefn)14