Search in sources :

Example 6 with CompartmentDefinitionResourceComponent

use of org.hl7.fhir.r5.model.CompartmentDefinition.CompartmentDefinitionResourceComponent in project kindling by HL7.

the class Publisher method generateCompartmentDefinition.

private void generateCompartmentDefinition(Compartment c) throws Exception {
    CompartmentDefinition cpd = new CompartmentDefinition();
    cpd.setId(c.getName());
    cpd.setUrl("http://hl7.org/fhir/CompartmentDefinition/" + c.getName());
    cpd.setName("Base FHIR compartment definition for " + c.getTitle());
    cpd.setStatus(PublicationStatus.DRAFT);
    cpd.setDescription(c.getIdentity() + ". " + c.getDescription());
    cpd.setExperimental(true);
    cpd.setVersion(page.getVersion().toCode());
    cpd.setDate(page.getGenDate().getTime());
    cpd.setPublisher("FHIR Project Team");
    cpd.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, "http://hl7.org/fhir"));
    cpd.setCode(CompartmentType.fromCode(c.getTitle()));
    cpd.setSearch(true);
    for (String rn : page.getDefinitions().sortedResourceNames()) {
        ResourceDefn rd = page.getDefinitions().getResourceByName(rn);
        String rules = c.getResources().get(rd);
        CompartmentDefinitionResourceComponent cc = cpd.addResource().setCode(rd.getName());
        if (!Utilities.noString(rules)) {
            for (String p : rules.split("\\|")) cc.addParam(p.trim());
        }
    }
    RenderingContext lrc = page.getRc().copy().setLocalPrefix("").setTooCostlyNoteEmpty(PageProcessor.TOO_MANY_CODES_TEXT_EMPTY).setTooCostlyNoteNotEmpty(PageProcessor.TOO_MANY_CODES_TEXT_NOT_EMPTY);
    RendererFactory.factory(cpd, lrc).render(cpd);
    FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + "compartmentdefinition-" + c.getName().toLowerCase() + ".xml");
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, cpd);
    s.close();
    s = new FileOutputStream(page.getFolders().dstDir + "compartmentdefinition-" + c.getName().toLowerCase() + ".canonical.xml");
    new XmlParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, cpd);
    s.close();
    cloneToXhtml("compartmentdefinition-" + c.getName().toLowerCase(), "Compartment Definition for " + c.getName(), true, "resource-instance:CompartmentDefinition", "Compartment Definition for " + c.getName(), null, wg("fhir"));
    s = new FileOutputStream(page.getFolders().dstDir + "compartmentdefinition-" + c.getName().toLowerCase() + ".json");
    new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(s, cpd);
    s.close();
    s = new FileOutputStream(page.getFolders().dstDir + "compartmentdefinition-" + c.getName().toLowerCase() + ".canonical.json");
    new JsonParser().setOutputStyle(OutputStyle.CANONICAL).compose(s, cpd);
    s.close();
    jsonToXhtml("compartmentdefinition-" + c.getName().toLowerCase(), "Compartment Definition for " + c.getName(), resource2Json(cpd), "resource-instance:CompartmentDefinition", "Compartment Definition for " + c.getName(), null, wg("fhir"));
    s = new FileOutputStream(page.getFolders().dstDir + "compartmentdefinition-" + c.getName().toLowerCase() + ".ttl");
    new RdfParser().setOutputStyle(OutputStyle.PRETTY).compose(s, cpd);
    s.close();
    ttlToXhtml("compartmentdefinition-" + c.getName().toLowerCase(), "Compartment Definition for " + c.getName(), resource2Ttl(cpd), "resource-instance:CompartmentDefinition", "Compartment Definition for " + c.getName(), null, wg("fhir"));
    Utilities.copyFile(new CSFile(page.getFolders().dstDir + "compartmentdefinition-" + c.getName().toLowerCase() + ".xml"), new CSFile(page.getFolders().dstDir + "examples" + File.separator + "compartmentdefinition-" + c.getName().toLowerCase() + ".xml"));
    addToResourceFeed(cpd, page.getResourceBundle());
}
Also used : RenderingContext(org.hl7.fhir.r5.renderers.utils.RenderingContext) XmlParser(org.hl7.fhir.r5.formats.XmlParser) CompartmentDefinitionResourceComponent(org.hl7.fhir.r5.model.CompartmentDefinition.CompartmentDefinitionResourceComponent) CompartmentDefinition(org.hl7.fhir.r5.model.CompartmentDefinition) FileOutputStream(java.io.FileOutputStream) CSFile(org.hl7.fhir.utilities.CSFile) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) JsonParser(org.hl7.fhir.r5.formats.JsonParser) RdfParser(org.hl7.fhir.r5.formats.RdfParser)

Example 7 with CompartmentDefinitionResourceComponent

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

the class CompartmentDefinition method setProperty.

@Override
public Base setProperty(String name, Base value) throws FHIRException {
    if (name.equals("url")) {
        // UriType
        this.url = castToUri(value);
    } else if (name.equals("name")) {
        // StringType
        this.name = castToString(value);
    } else if (name.equals("title")) {
        // StringType
        this.title = castToString(value);
    } else if (name.equals("status")) {
        value = new PublicationStatusEnumFactory().fromType(castToCode(value));
        // Enumeration<PublicationStatus>
        this.status = (Enumeration) value;
    } else if (name.equals("experimental")) {
        // BooleanType
        this.experimental = castToBoolean(value);
    } else if (name.equals("date")) {
        // DateTimeType
        this.date = castToDateTime(value);
    } else if (name.equals("publisher")) {
        // StringType
        this.publisher = castToString(value);
    } else if (name.equals("contact")) {
        this.getContact().add(castToContactDetail(value));
    } else if (name.equals("description")) {
        // MarkdownType
        this.description = castToMarkdown(value);
    } else if (name.equals("purpose")) {
        // MarkdownType
        this.purpose = castToMarkdown(value);
    } else if (name.equals("useContext")) {
        this.getUseContext().add(castToUsageContext(value));
    } else if (name.equals("jurisdiction")) {
        this.getJurisdiction().add(castToCodeableConcept(value));
    } else if (name.equals("code")) {
        value = new CompartmentTypeEnumFactory().fromType(castToCode(value));
        // Enumeration<CompartmentType>
        this.code = (Enumeration) value;
    } else if (name.equals("search")) {
        // BooleanType
        this.search = castToBoolean(value);
    } else if (name.equals("resource")) {
        this.getResource().add((CompartmentDefinitionResourceComponent) value);
    } else
        return super.setProperty(name, value);
    return value;
}
Also used : PublicationStatusEnumFactory(org.hl7.fhir.dstu3.model.Enumerations.PublicationStatusEnumFactory)

Example 8 with CompartmentDefinitionResourceComponent

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

the class NarrativeGenerator method generate.

public boolean generate(ResourceContext rcontext, 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);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) CompartmentDefinitionResourceComponent(org.hl7.fhir.dstu3.model.CompartmentDefinition.CompartmentDefinitionResourceComponent) StringType(org.hl7.fhir.dstu3.model.StringType) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) ParseException(java.text.ParseException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 9 with CompartmentDefinitionResourceComponent

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

the class NarrativeGenerator method generate.

public boolean generate(ResourceContext rcontext, 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);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) CompartmentDefinitionResourceComponent(org.hl7.fhir.r4.model.CompartmentDefinition.CompartmentDefinitionResourceComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ParseException(java.text.ParseException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)5 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)5 XhtmlParser (org.hl7.fhir.utilities.xhtml.XhtmlParser)5 IOException (java.io.IOException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 NotImplementedException (org.apache.commons.lang3.NotImplementedException)3 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 CompartmentDefinitionResourceComponent (org.hl7.fhir.r5.model.CompartmentDefinition.CompartmentDefinitionResourceComponent)3 ParseException (java.text.ParseException)2 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)2 CompartmentDefinition (org.hl7.fhir.r5.model.CompartmentDefinition)2 StringType (org.hl7.fhir.r5.model.StringType)2 FileOutputStream (java.io.FileOutputStream)1 TreeSet (java.util.TreeSet)1 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)1 CompartmentDefinitionResourceComponent (org.hl7.fhir.dstu2016may.model.CompartmentDefinition.CompartmentDefinitionResourceComponent)1 ConformanceResourceStatusEnumFactory (org.hl7.fhir.dstu2016may.model.Enumerations.ConformanceResourceStatusEnumFactory)1 StringType (org.hl7.fhir.dstu2016may.model.StringType)1 CompartmentDefinitionResourceComponent (org.hl7.fhir.dstu3.model.CompartmentDefinition.CompartmentDefinitionResourceComponent)1