org.hl7.fhir.r4.model.Narrative.NarrativeStatus Java Examples

The following examples show how to use org.hl7.fhir.r4.model.Narrative.NarrativeStatus. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public String generate(ResourceContext rcontext, org.hl7.fhir.r4.elementmodel.Element er, boolean showCodeDetails, ITypeParser parser) throws IOException, FHIRException {
  if (rcontext == null)
    rcontext = new ResourceContext(null, er);
  this.parser = parser;
  
  XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
  x.para().b().tx("Generated Narrative"+(showCodeDetails ? " with Details" : ""));
  try {
    ResourceWrapperMetaElement resw = new ResourceWrapperMetaElement(er);
    BaseWrapperMetaElement base = new BaseWrapperMetaElement(er, null, er.getProperty().getStructure(), er.getProperty().getDefinition());
    base.children();
    generateByProfile(resw, er.getProperty().getStructure(), base, er.getProperty().getStructure().getSnapshot().getElement(), er.getProperty().getDefinition(), base.children, x, er.fhirType(), showCodeDetails, 0, rcontext);

  } catch (Exception e) {
    e.printStackTrace();
    x.para().b().setAttribute("style", "color: maroon").tx("Exception generating Narrative: "+e.getMessage());
  }
  inject(er, x,  NarrativeStatus.GENERATED);
  return new XhtmlComposer(XhtmlComposer.XML, pretty).compose(x);
}
 
Example #2
Source File: StructureMapUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public StructureMap generateMapFromMappings(StructureDefinition sd) throws IOException, FHIRException {
  String id = getLogicalMappingId(sd);
  if (id == null) 
      return null;
  String prefix = ToolingExtensions.readStringExtension(sd,  ToolingExtensions.EXT_MAPPING_PREFIX);
  String suffix = ToolingExtensions.readStringExtension(sd,  ToolingExtensions.EXT_MAPPING_SUFFIX);
  if (prefix == null || suffix == null)
    return null;
  // we build this by text. Any element that has a mapping, we put it's mappings inside it....
  StringBuilder b = new StringBuilder();
  b.append(prefix);

  ElementDefinition root = sd.getSnapshot().getElementFirstRep();
  String m = getMapping(root, id);
  if (m != null)
    b.append(m+"\r\n");
  addChildMappings(b, id, "", sd, root, false);
  b.append("\r\n");
  b.append(suffix);
  b.append("\r\n");
  StructureMap map = parse(b.toString(), sd.getUrl());
  map.setId(tail(map.getUrl()));
  if (!map.hasStatus())
    map.setStatus(PublicationStatus.DRAFT);
  map.getText().setStatus(NarrativeStatus.GENERATED);
  map.getText().setDiv(new XhtmlNode(NodeType.Element, "div"));
  map.getText().getDiv().addTag("pre").addText(render(map));
  return map;
}
 
Example #3
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private boolean generateByProfile(ResourceContext rc, StructureDefinition profile, boolean showCodeDetails) {
  XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
  x.para().b().tx("Generated Narrative"+(showCodeDetails ? " with Details" : ""));
  try {
    generateByProfile(rc.resourceResource, profile, rc.resourceResource, profile.getSnapshot().getElement(), profile.getSnapshot().getElement().get(0), getChildrenForPath(profile.getSnapshot().getElement(), rc.resourceResource.getResourceType().toString()), x, rc.resourceResource.getResourceType().toString(), showCodeDetails, rc);
  } catch (Exception e) {
    e.printStackTrace();
    x.para().b().setAttribute("style", "color: maroon").tx("Exception generating Narrative: "+e.getMessage());
  }
  inject(rc.resourceResource, x,  NarrativeStatus.GENERATED);
  return true;
}
 
Example #4
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void inject(DomainResource r, XhtmlNode x, NarrativeStatus status) {
  if (!x.hasAttribute("xmlns"))
    x.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  if (!r.hasText() || !r.getText().hasDiv() || r.getText().getDiv().getChildNodes().isEmpty()) {
    r.setText(new Narrative());
    r.getText().setDiv(x);
    r.getText().setStatus(status);
  } else {
    XhtmlNode n = r.getText().getDiv();
    n.hr();
    n.getChildNodes().addAll(x.getChildNodes());
  }
}
 
Example #5
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void inject(org.hl7.fhir.r4.elementmodel.Element er, XhtmlNode x, NarrativeStatus status) throws IOException, FHIRException {
  if (!x.hasAttribute("xmlns"))
    x.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  org.hl7.fhir.r4.elementmodel.Element txt = er.getNamedChild("text");
  if (txt == null) {
    txt = new org.hl7.fhir.r4.elementmodel.Element("text", er.getProperty().getChild(null, "text"));
    int i = 0;
    while (i < er.getChildren().size() && (er.getChildren().get(i).getName().equals("id") || er.getChildren().get(i).getName().equals("meta") || er.getChildren().get(i).getName().equals("implicitRules") || er.getChildren().get(i).getName().equals("language")))
      i++;
    if (i >= er.getChildren().size())
      er.getChildren().add(txt);
    else
      er.getChildren().add(i, txt);
  }
  org.hl7.fhir.r4.elementmodel.Element st = txt.getNamedChild("status");
  if (st == null) {
    st = new org.hl7.fhir.r4.elementmodel.Element("status", txt.getProperty().getChild(null, "status"));
    txt.getChildren().add(0, st);
  }
  st.setValue(status.toCode());
  org.hl7.fhir.r4.elementmodel.Element div = txt.getNamedChild("div");
  if (div == null) {
    div = new org.hl7.fhir.r4.elementmodel.Element("div", txt.getProperty().getChild(null, "div"));
    txt.getChildren().add(div);
    div.setValue(new XhtmlComposer(XhtmlComposer.XML, pretty).compose(x));
  }
  div.setXhtml(x);
}
 
Example #6
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public void generate(ResourceContext rcontext, ValueSet vs, ValueSet src, boolean header) throws FHIRException, IOException {
  List<UsedConceptMap> maps = findReleventMaps(vs);
  
  XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
  boolean hasExtensions;
  if (vs.hasExpansion()) {
    // for now, we just accept an expansion if there is one
    hasExtensions = generateExpansion(x, vs, src, header, maps);
  } else {
    hasExtensions = generateComposition(rcontext, x, vs, header, maps);
  }
  inject(vs, x, hasExtensions ? NarrativeStatus.EXTENSIONS :  NarrativeStatus.GENERATED);
}
 
Example #7
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public boolean generate(ResourceContext rcontext, StructureDefinition sd, Set<String> outputTracker) throws EOperationOutcome, FHIRException, IOException {
  ProfileUtilities pu = new ProfileUtilities(context, null, pkp);
  XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
  x.getChildNodes().add(pu.generateTable(definitionsTarget, sd, true, destDir, false, sd.getId(), false, corePath, "", false, false, outputTracker));
  inject(sd, x, NarrativeStatus.GENERATED);
  return true;
}
 
Example #8
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public boolean generate(ResourceContext rcontext, ImplementationGuide ig) throws EOperationOutcome, FHIRException, IOException {
  XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
  x.h2().addText(ig.getName());
  x.para().tx("The official URL for this implementation guide is: ");
  x.pre().tx(ig.getUrl());
  addMarkdown(x, ig.getDescription());
  inject(ig, x, NarrativeStatus.GENERATED);
  return true;
}
 
Example #9
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public boolean generate(ResourceContext rcontext, OperationDefinition opd) throws EOperationOutcome, FHIRException, IOException {
   XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
   x.h2().addText(opd.getName());
   x.para().addText(Utilities.capitalize(opd.getKind().toString())+": "+opd.getName());
   x.para().tx("The official URL for this operation definition is: ");
   x.pre().tx(opd.getUrl());
   addMarkdown(x, opd.getDescription());

   if (opd.getSystem())
     x.para().tx("URL: [base]/$"+opd.getCode());
   for (CodeType c : opd.getResource()) {
     if (opd.getType())
       x.para().tx("URL: [base]/"+c.getValue()+"/$"+opd.getCode());
     if (opd.getInstance())
       x.para().tx("URL: [base]/"+c.getValue()+"/[id]/$"+opd.getCode());
   }

   x.para().tx("Parameters");
   XhtmlNode tbl = x.table( "grid");
   XhtmlNode tr = tbl.tr();
   tr.td().b().tx("Use");
   tr.td().b().tx("Name");
   tr.td().b().tx("Cardinality");
   tr.td().b().tx("Type");
   tr.td().b().tx("Binding");
   tr.td().b().tx("Documentation");
   for (OperationDefinitionParameterComponent p : opd.getParameter()) {
     genOpParam(rcontext, tbl, "", p);
   }
   addMarkdown(x, opd.getComment());
   inject(opd, x, NarrativeStatus.GENERATED);
   return true;
}
 
Example #10
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
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;
  }
}
 
Example #11
Source File: Factory.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static Narrative newNarrative(NarrativeStatus status, String html) throws IOException, FHIRException {
	Narrative n = new Narrative();
	n.setStatus(status);
	try {
		n.setDiv(new XhtmlParser().parseFragment("<div>"+Utilities.escapeXml(html)+"</div>"));
	} catch (org.hl7.fhir.exceptions.FHIRException e) {
		throw new FHIRException(e.getMessage(), e);
	}
	return n;
}
 
Example #12
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public boolean generate(ResourceContext rcontext, DomainResource r, Set<String> outputTracker) throws EOperationOutcome, FHIRException, IOException {
  if (rcontext == null)
    rcontext = new ResourceContext(null, r);
  
  if (templateProvider != null) {
    String liquidTemplate = templateProvider.findTemplate(rcontext, r);
    if (liquidTemplate != null) {
      return generateByLiquid(rcontext, r, liquidTemplate, outputTracker);
    }
  }
  if (r instanceof ConceptMap) {
    return generate(rcontext, (ConceptMap) r); // Maintainer = Grahame
  } else if (r instanceof ValueSet) {
    return generate(rcontext, (ValueSet) r, true); // Maintainer = Grahame
  } else if (r instanceof CodeSystem) {
    return generate(rcontext, (CodeSystem) r, true, null); // Maintainer = Grahame
  } else if (r instanceof OperationOutcome) {
    return generate(rcontext, (OperationOutcome) r); // Maintainer = Grahame
  } else if (r instanceof CapabilityStatement) {
    return generate(rcontext, (CapabilityStatement) r);   // Maintainer = Grahame
  } else if (r instanceof CompartmentDefinition) {
    return generate(rcontext, (CompartmentDefinition) r);   // Maintainer = Grahame
  } else if (r instanceof OperationDefinition) {
    return generate(rcontext, (OperationDefinition) r);   // Maintainer = Grahame
  } else if (r instanceof StructureDefinition) {
    return generate(rcontext, (StructureDefinition) r, outputTracker);   // Maintainer = Grahame
  } else if (r instanceof ImplementationGuide) {
    return generate(rcontext, (ImplementationGuide) r);   // Maintainer = Lloyd (until Grahame wants to take over . . . :))
  } else if (r instanceof DiagnosticReport) {
    inject(r, generateDiagnosticReport(new ResourceWrapperDirect(r)),  NarrativeStatus.GENERATED);   // Maintainer = Grahame
    return true;
  } else {
    StructureDefinition p = null;
    if (r.hasMeta())
      for (UriType pu : r.getMeta().getProfile())
        if (p == null)
          p = context.fetchResource(StructureDefinition.class, pu.getValue());
    if (p == null)
      p = context.fetchResource(StructureDefinition.class, r.getResourceType().toString());
    if (p == null)
      p = context.fetchTypeDefinition(r.getResourceType().toString().toLowerCase());
    if (p != null)
      return generateByProfile(rcontext, p, true);
    else
      return false;
  }
}
 
Example #13
Source File: GeneratorTestFragments.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private void test() throws FHIRFormatError, IOException {

    Observation res = new Observation();
    res.setId("example");
    Narrative n = new Narrative();
    res.setText(n);
    n.setStatus(NarrativeStatus.GENERATED);
    n.setDiv(new XhtmlParser().parse("<div xmlns=\"http://www.w3.org/1999/xhtml\"><p><b>Generated Narrative with Details</b></p><p><b>id</b>: example</p><p><b>status</b>: final</p><p><b>category</b>: Vital Signs <span>(Details : {http://hl7.org/fhir/observation-category code &#39;vital-signs&#39; = &#39;Vital Signs&#39;, given as &#39;Vital Signs&#39;})</span></p><p><b>code</b>: Body Weight <span>(Details : {LOINC code &#39;29463-7&#39; = &#39;Body weight&#39;, given as &#39;Body Weight&#39;}; {LOINC code &#39;3141-9&#39; = &#39;Body weight Measured&#39;, given as &#39;Body weight Measured&#39;}; {SNOMED CT code &#39;27113001&#39; = &#39;Body weight&#39;, given as &#39;Body weight&#39;}; {http://acme.org/devices/clinical-codes code &#39;body-weight&#39; = &#39;body-weight&#39;, given as &#39;Body Weight&#39;})</span></p><p><b>subject</b>: <a>Patient/example</a></p><p><b>context</b>: <a>Encounter/example</a></p><p><b>effective</b>: 28/03/2016</p><p><b>value</b>: 185 lbs<span> (Details: UCUM code [lb_av] = &#39;lb_av&#39;)</span></p></div>", "div"));
    res.setStatus(ObservationStatus.FINAL);
    CodeableConcept cc = res.addCategory();
    Coding c = cc.addCoding();
    c.setSystem("http://hl7.org/fhir/observation-category");
    c.setCode("vital-signs");
    c.setDisplay("Vital Signs");
    cc = new CodeableConcept();
    res.setCode(cc);
    c = cc.addCoding();
    c.setSystem("http://loinc.org");
    c.setCode("29463-7");
    c.setDisplay("Body Weight");
    c = cc.addCoding();
    c.setSystem("http://loinc.org");
    c.setCode("3141-9");
    c.setDisplay("Body weight Measured");
    c = cc.addCoding();
    c.setSystem("http://snomed.info/sct");
    c.setCode("27113001");
    c.setDisplay("Body weight");
    c = cc.addCoding();
    c.setSystem("http://acme.org/devices/clinical-codes");
    c.setCode("body-weight");
    c.setDisplay("Body Weight");
    Reference r = new Reference();
    res.setSubject(r);
    r.setReference("Patient/example");
    r = new Reference();
    res.setEncounter(r);
    r.setReference("Encounter/example");
    res.setEffective(new DateTimeType("2016-03-28"));
    Quantity q = new Quantity();
    res.setValue(q);
    q.setValue(185);
    q.setUnit("lbs");
    q.setSystem("http://unitsofmeasure.org");
    q.setCode("[lb_av]");


  }
 
Example #14
Source File: IdentifiableDomainResourceAttributeMapper.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
default void mapNarrative(Identifiable source, DomainResource target) {
	Narrative narrative = new Narrative();
	narrative.setStatus(NarrativeStatus.GENERATED);
	narrative.setDivAsString(source.getLabel());
	target.setText(narrative);
}
 
Example #15
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 3 votes vote down vote up
/**
 * This generate is optimised for the FHIR build process itself in as much as it
 * generates hyperlinks in the narrative that are only going to be correct for
 * the purposes of the build. This is to be reviewed in the future.
 *
 * @param vs
 * @param codeSystems
 * @throws IOException
 * @throws DefinitionException
 * @throws FHIRFormatError
 * @throws Exception
 */
public boolean generate(ResourceContext rcontext, CodeSystem cs, boolean header, String lang) throws FHIRFormatError, DefinitionException, IOException {
  XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
  boolean hasExtensions = false;
  hasExtensions = generateDefinition(x, cs, header, lang);
  inject(cs, x, hasExtensions ? NarrativeStatus.EXTENSIONS :  NarrativeStatus.GENERATED);
  return true;
}