Search in sources :

Example 1 with NarrativeGenerator

use of org.hl7.fhir.r4.utils.NarrativeGenerator in project org.hl7.fhir.core by hapifhir.

the class CCDAConverter method addReference.

protected String addReference(DomainResource r, String title, String id) throws Exception {
    if (r.getText() == null)
        r.setText(new Narrative());
    if (r.getText().getDiv() == null) {
        r.getText().setStatus(NarrativeStatus.GENERATED);
        new NarrativeGenerator("", "", context).generate(r);
    }
    r.setMeta(new Meta().setLastUpdatedElement(InstantType.now()));
    r.setId(id);
    feed.getEntry().add(new BundleEntryComponent().setResource(r));
    return id;
}
Also used : NarrativeGenerator(org.hl7.fhir.dstu3.utils.NarrativeGenerator) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent)

Example 2 with NarrativeGenerator

use of org.hl7.fhir.r4.utils.NarrativeGenerator in project org.hl7.fhir.core by hapifhir.

the class ArgonautConverter method saveResource.

private void saveResource(Resource resource, String extraType) throws Exception {
    if (!WANT_SAVE)
        return;
    DomainResource dr = null;
    if (resource instanceof DomainResource) {
        dr = (DomainResource) resource;
        if (!dr.hasText()) {
            NarrativeGenerator generator = new NarrativeGenerator("", "", context);
            generator.generate(dr);
        }
    }
    XmlParser xparser = new XmlParser();
    xparser.setOutputStyle(OutputStyle.PRETTY);
    JsonParser jparser = new JsonParser();
    jparser.setOutputStyle(OutputStyle.PRETTY);
    ByteArrayOutputStream ba = new ByteArrayOutputStream();
    xparser.compose(ba, resource);
    ba.close();
    byte[] srcX = ba.toByteArray();
    ba = new ByteArrayOutputStream();
    jparser.compose(ba, resource);
    ba.close();
    byte[] srcJ = ba.toByteArray();
    String rn = resource.getResourceType().toString();
    if (extraType != null)
        rn = rn + extraType;
    zipX.addBytes(resource.getId() + ".xml", srcX, false);
    zipJ.addBytes(resource.getId() + ".json", srcJ, false);
    if (!zipsX.containsKey(rn)) {
        zipsX.put(rn, new ZipGenerator(Utilities.path(destFolder, "xml/type", rn + ".xml.zip")));
        zipsJ.put(rn, new ZipGenerator(Utilities.path(destFolder, "json/type", rn + ".json.zip")));
        stats.put(rn, new Stats());
    }
    zipsJ.get(rn).addBytes(resource.getId() + ".json", srcJ, false);
    zipsX.get(rn).addBytes(resource.getId() + ".xml", srcX, false);
    Stats ss = stats.get(rn);
    ss.setInstances(ss.getInstances() + 1);
    String profile = resource.getUserString("profile");
    validate(srcX, profile, resource, ss);
}
Also used : NarrativeGenerator(org.hl7.fhir.dstu3.utils.NarrativeGenerator) XmlParser(org.hl7.fhir.dstu3.formats.XmlParser) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ZipGenerator(org.hl7.fhir.utilities.ZipGenerator) JsonParser(org.hl7.fhir.dstu3.formats.JsonParser)

Example 3 with NarrativeGenerator

use of org.hl7.fhir.r4.utils.NarrativeGenerator in project org.hl7.fhir.core by hapifhir.

the class QuestionnaireBuilder method build.

public void build() throws FHIRException {
    if (profile == null)
        throw new DefinitionException("QuestionnaireBuilder.build: no profile found");
    if (resource != null)
        if (!profile.getBaseType().equals(resource.getResourceType().toString()))
            throw new DefinitionException("Wrong Type");
    if (prebuiltQuestionnaire != null)
        questionnaire = prebuiltQuestionnaire;
    else
        questionnaire = new Questionnaire();
    if (resource != null)
        response = new QuestionnaireResponse();
    processMetadata();
    List<ElementDefinition> list = new ArrayList<ElementDefinition>();
    List<QuestionnaireResponse.QuestionnaireResponseItemComponent> answerGroups = new ArrayList<QuestionnaireResponse.QuestionnaireResponseItemComponent>();
    if (resource != null)
        answerGroups.addAll(response.getItem());
    if (prebuiltQuestionnaire != null) {
        // give it a fake group to build
        Questionnaire.QuestionnaireItemComponent group = new Questionnaire.QuestionnaireItemComponent();
        group.setType(QuestionnaireItemType.GROUP);
        buildGroup(group, profile, profile.getSnapshot().getElement().get(0), list, answerGroups);
    } else
        buildGroup(questionnaire.getItem().get(0), profile, profile.getSnapshot().getElement().get(0), list, answerGroups);
// 
// NarrativeGenerator ngen = new NarrativeGenerator(context);
// ngen.generate(result);
// 
// if FResponse <> nil then
// FResponse.collapseAllContained;
}
Also used : QuestionnaireItemComponent(org.hl7.fhir.dstu2016may.model.Questionnaire.QuestionnaireItemComponent) Questionnaire(org.hl7.fhir.dstu2016may.model.Questionnaire) ArrayList(java.util.ArrayList) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) ElementDefinition(org.hl7.fhir.dstu2016may.model.ElementDefinition) QuestionnaireResponse(org.hl7.fhir.dstu2016may.model.QuestionnaireResponse) QuestionnaireItemComponent(org.hl7.fhir.dstu2016may.model.Questionnaire.QuestionnaireItemComponent)

Example 4 with NarrativeGenerator

use of org.hl7.fhir.r4.utils.NarrativeGenerator in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method addMarkdown.

private void addMarkdown(XhtmlNode x, String text) throws FHIRFormatError, IOException, DefinitionException {
    if (text != null) {
        // 1. custom FHIR extensions
        while (text.contains("[[[")) {
            String left = text.substring(0, text.indexOf("[[["));
            String link = text.substring(text.indexOf("[[[") + 3, text.indexOf("]]]"));
            String right = text.substring(text.indexOf("]]]") + 3);
            String url = link;
            String[] parts = link.split("\\#");
            StructureDefinition p = context.fetchResource(StructureDefinition.class, parts[0]);
            if (p == null)
                p = context.fetchTypeDefinition(parts[0]);
            if (p == null)
                p = context.fetchResource(StructureDefinition.class, link);
            if (p != null) {
                url = p.getUserString("path");
                if (url == null)
                    url = p.getUserString("filename");
            } else
                throw new DefinitionException("Unable to resolve markdown link " + link);
            text = left + "[" + link + "](" + url + ")" + right;
        }
        // 2. markdown
        String s = new MarkDownProcessor(Dialect.DARING_FIREBALL).process(Utilities.escapeXml(text), "NarrativeGenerator");
        XhtmlParser p = new XhtmlParser();
        XhtmlNode m = p.parse("<div>" + s + "</div>", "div");
        x.getChildNodes().addAll(m.getChildNodes());
    }
}
Also used : StructureDefinition(org.hl7.fhir.dstu2.model.StructureDefinition) XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) MarkDownProcessor(org.hl7.fhir.utilities.MarkDownProcessor) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 5 with NarrativeGenerator

use of org.hl7.fhir.r4.utils.NarrativeGenerator in project org.hl7.fhir.core by hapifhir.

the class QuestionnaireBuilder method build.

public void build() throws FHIRException {
    if (profile == null)
        throw new DefinitionException("QuestionnaireBuilder.build: no profile found");
    if (resource != null)
        if (!profile.getType().equals(resource.getResourceType().toString()))
            throw new DefinitionException("Wrong Type");
    if (prebuiltQuestionnaire != null)
        questionnaire = prebuiltQuestionnaire;
    else
        questionnaire = new Questionnaire();
    if (resource != null)
        response = new QuestionnaireResponse();
    processMetadata();
    List<ElementDefinition> list = new ArrayList<ElementDefinition>();
    List<QuestionnaireResponse.QuestionnaireResponseItemComponent> answerGroups = new ArrayList<QuestionnaireResponse.QuestionnaireResponseItemComponent>();
    if (resource != null)
        answerGroups.addAll(response.getItem());
    if (prebuiltQuestionnaire != null) {
        // give it a fake group to build
        Questionnaire.QuestionnaireItemComponent group = new Questionnaire.QuestionnaireItemComponent();
        group.setType(QuestionnaireItemType.GROUP);
        buildGroup(group, profile, profile.getSnapshot().getElement().get(0), list, answerGroups);
    } else
        buildGroup(questionnaire.getItem().get(0), profile, profile.getSnapshot().getElement().get(0), list, answerGroups);
// 
// NarrativeGenerator ngen = new NarrativeGenerator(context);
// ngen.generate(result);
// 
// if FResponse <> nil then
// FResponse.collapseAllContained;
}
Also used : QuestionnaireItemComponent(org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemComponent) Questionnaire(org.hl7.fhir.r4b.model.Questionnaire) ArrayList(java.util.ArrayList) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) QuestionnaireResponse(org.hl7.fhir.r4b.model.QuestionnaireResponse) QuestionnaireItemComponent(org.hl7.fhir.r4b.model.Questionnaire.QuestionnaireItemComponent)

Aggregations

DefinitionException (org.hl7.fhir.exceptions.DefinitionException)10 ArrayList (java.util.ArrayList)7 NarrativeGenerator (org.hl7.fhir.dstu3.utils.NarrativeGenerator)3 MarkDownProcessor (org.hl7.fhir.utilities.MarkDownProcessor)3 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)3 XhtmlParser (org.hl7.fhir.utilities.xhtml.XhtmlParser)3 FileOutputStream (java.io.FileOutputStream)2 XmlParser (org.hl7.fhir.dstu3.formats.XmlParser)2 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)2 XmlParser (org.hl7.fhir.r4.formats.XmlParser)2 NarrativeGenerator (org.hl7.fhir.r4.utils.NarrativeGenerator)2 Test (org.junit.jupiter.api.Test)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)1 Questionnaire (org.hl7.fhir.dstu2.model.Questionnaire)1