Search in sources :

Example 1 with CompartmentDefinition

use of org.hl7.fhir.r5.model.CompartmentDefinition in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method generate.

public void generate(CompartmentDefinition cpd) {
    StringBuilder in = new StringBuilder();
    StringBuilder out = new StringBuilder();
    for (CompartmentDefinitionResourceComponent cc : cpd.getResource()) {
        CommaSeparatedStringBuilder rules = new CommaSeparatedStringBuilder();
        if (!cc.hasParam()) {
            out.append(" <li><a href=\"").append(cc.getCode().toLowerCase()).append(".html\">").append(cc.getCode()).append("</a></li>\r\n");
        } else if (!rules.equals("{def}")) {
            for (StringType p : cc.getParam()) rules.append(p.asStringValue());
            in.append(" <tr><td><a href=\"").append(cc.getCode().toLowerCase()).append(".html\">").append(cc.getCode()).append("</a></td><td>").append(rules.toString()).append("</td></tr>\r\n");
        }
    }
    XhtmlNode x;
    try {
        x = new XhtmlParser().parseFragment("<div><p>\r\nThe following resources may be in this compartment:\r\n</p>\r\n" + "<table class=\"grid\">\r\n" + " <tr><td><b>Resource</b></td><td><b>Inclusion Criteria</b></td></tr>\r\n" + in.toString() + "</table>\r\n" + "<p>\r\nA resource is in this compartment if the nominated search parameter (or chain) refers to the patient resource that defines the compartment.\r\n</p>\r\n" + "<p>\r\n\r\n</p>\r\n" + "<p>\r\nThe following resources are never in this compartment:\r\n</p>\r\n" + "<ul>\r\n" + out.toString() + "</ul></div>\r\n");
        inject(cpd, x, NarrativeStatus.GENERATED);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) CompartmentDefinitionResourceComponent(org.hl7.fhir.dstu2016may.model.CompartmentDefinition.CompartmentDefinitionResourceComponent) StringType(org.hl7.fhir.dstu2016may.model.StringType) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 2 with CompartmentDefinition

use of org.hl7.fhir.r5.model.CompartmentDefinition in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeCompartmentDefinition.

protected void composeCompartmentDefinition(Complex parent, String parentType, String name, CompartmentDefinition element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeDomainResource(t, "CompartmentDefinition", name, element, index);
    if (element.hasUrlElement())
        composeUri(t, "CompartmentDefinition", "url", element.getUrlElement(), -1);
    if (element.hasNameElement())
        composeString(t, "CompartmentDefinition", "name", element.getNameElement(), -1);
    if (element.hasTitleElement())
        composeString(t, "CompartmentDefinition", "title", element.getTitleElement(), -1);
    if (element.hasStatusElement())
        composeEnum(t, "CompartmentDefinition", "status", element.getStatusElement(), -1);
    if (element.hasExperimentalElement())
        composeBoolean(t, "CompartmentDefinition", "experimental", element.getExperimentalElement(), -1);
    if (element.hasDateElement())
        composeDateTime(t, "CompartmentDefinition", "date", element.getDateElement(), -1);
    if (element.hasPublisherElement())
        composeString(t, "CompartmentDefinition", "publisher", element.getPublisherElement(), -1);
    for (int i = 0; i < element.getContact().size(); i++) composeContactDetail(t, "CompartmentDefinition", "contact", element.getContact().get(i), i);
    if (element.hasDescriptionElement())
        composeMarkdown(t, "CompartmentDefinition", "description", element.getDescriptionElement(), -1);
    if (element.hasPurposeElement())
        composeMarkdown(t, "CompartmentDefinition", "purpose", element.getPurposeElement(), -1);
    for (int i = 0; i < element.getUseContext().size(); i++) composeUsageContext(t, "CompartmentDefinition", "useContext", element.getUseContext().get(i), i);
    for (int i = 0; i < element.getJurisdiction().size(); i++) composeCodeableConcept(t, "CompartmentDefinition", "jurisdiction", element.getJurisdiction().get(i), i);
    if (element.hasCodeElement())
        composeEnum(t, "CompartmentDefinition", "code", element.getCodeElement(), -1);
    if (element.hasSearchElement())
        composeBoolean(t, "CompartmentDefinition", "search", element.getSearchElement(), -1);
    for (int i = 0; i < element.getResource().size(); i++) composeCompartmentDefinitionCompartmentDefinitionResourceComponent(t, "CompartmentDefinition", "resource", element.getResource().get(i), i);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

Example 3 with CompartmentDefinition

use of org.hl7.fhir.r5.model.CompartmentDefinition 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 4 with CompartmentDefinition

use of org.hl7.fhir.r5.model.CompartmentDefinition in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeCompartmentDefinitionCompartmentDefinitionResourceComponent.

protected void composeCompartmentDefinitionCompartmentDefinitionResourceComponent(Complex parent, String parentType, String name, CompartmentDefinition.CompartmentDefinitionResourceComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "resource", name, element, index);
    if (element.hasCodeElement())
        composeCode(t, "CompartmentDefinition", "code", element.getCodeElement(), -1);
    for (int i = 0; i < element.getParam().size(); i++) composeString(t, "CompartmentDefinition", "param", element.getParam().get(i), i);
    if (element.hasDocumentationElement())
        composeString(t, "CompartmentDefinition", "documentation", element.getDocumentationElement(), -1);
}
Also used : Complex(org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)

Example 5 with CompartmentDefinition

use of org.hl7.fhir.r5.model.CompartmentDefinition in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeCompartmentDefinitionCompartmentDefinitionResourceComponent.

protected void composeCompartmentDefinitionCompartmentDefinitionResourceComponent(Complex parent, String parentType, String name, CompartmentDefinition.CompartmentDefinitionResourceComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "resource", name, element, index);
    if (element.hasCodeElement())
        composeCode(t, "CompartmentDefinition", "code", element.getCodeElement(), -1);
    for (int i = 0; i < element.getParam().size(); i++) composeString(t, "CompartmentDefinition", "param", element.getParam().get(i), i);
    if (element.hasDocumentationElement())
        composeString(t, "CompartmentDefinition", "documentation", element.getDocumentationElement(), -1);
}
Also used : Complex(org.hl7.fhir.r4.utils.formats.Turtle.Complex)

Aggregations

CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)8 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)5 XhtmlParser (org.hl7.fhir.utilities.xhtml.XhtmlParser)5 IOException (java.io.IOException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 FHIRException (org.hl7.fhir.exceptions.FHIRException)4 NotImplementedException (org.apache.commons.lang3.NotImplementedException)3 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)3 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)3 CompartmentDefinitionResourceComponent (org.hl7.fhir.r5.model.CompartmentDefinition.CompartmentDefinitionResourceComponent)3 ParseException (java.text.ParseException)2 Compartment (org.hl7.fhir.definitions.model.Compartment)2 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)2 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)2 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)2 CompartmentDefinition (org.hl7.fhir.r5.model.CompartmentDefinition)2 StringType (org.hl7.fhir.r5.model.StringType)2 Configuration (au.csiro.pathling.Configuration)1 StringLiteralPath (au.csiro.pathling.fhirpath.literal.StringLiteralPath)1 FhirContext (ca.uhn.fhir.context.FhirContext)1