Java Code Examples for org.hl7.fhir.dstu3.model.Narrative

The following examples show how to use org.hl7.fhir.dstu3.model.Narrative. These examples are extracted from open source projects. 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 Project: cqf-ruler   Source File: LibraryOperationsProvider.java    License: Apache License 2.0 8 votes vote down vote up
@Operation(name = "$refresh-generated-content", type = Library.class)
public MethodOutcome refreshGeneratedContent(HttpServletRequest theRequest, RequestDetails theRequestDetails,
        @IdParam IdType theId) {
    Library theResource = this.libraryResourceProvider.getDao().read(theId);
    //this.formatCql(theResource);

    ModelManager modelManager = this.getModelManager();
    LibraryManager libraryManager = this.getLibraryManager(modelManager);

    CqlTranslator translator = this.dataRequirementsProvider.getTranslator(theResource, libraryManager, modelManager);
    if (translator.getErrors().size() > 0) {
        throw new RuntimeException("Errors during library compilation.");
    }
    
    this.dataRequirementsProvider.ensureElm(theResource, translator);
    this.dataRequirementsProvider.ensureRelatedArtifacts(theResource, translator, this);
    this.dataRequirementsProvider.ensureDataRequirements(theResource, translator);

    Narrative n = this.narrativeProvider.getNarrative(this.libraryResourceProvider.getContext(), theResource);
    theResource.setText(n);

    return this.libraryResourceProvider.update(theRequest, theResource, theId,
            theRequestDetails.getConditionalUrl(RestOperationTypeEnum.UPDATE), theRequestDetails);
}
 
Example 2
Source Project: org.hl7.fhir.core   Source File: ArgonautConverter.java    License: Apache License 2.0 5 votes vote down vote up
private void buildNarrative(DomainResource resource, Element child) {
	if (!Utilities.noString(child.getTextContent())) {
		XhtmlNode div = new XhtmlNode(NodeType.Element, "div");
		String s = child.getTextContent().trim();
		if (Utilities.noString(s))
		  div.addText("No Narrative provided in the source CDA document");
		else
		  div.addText(s);
		resource.setText(new Narrative().setStatus(NarrativeStatus.ADDITIONAL).setDiv(div));
	}
}
 
Example 3
Source Project: org.hl7.fhir.core   Source File: CCDAConverter.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 4
Source Project: org.hl7.fhir.core   Source File: NarrativeGenerator.java    License: 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 Project: cqf-ruler   Source File: LibraryOperationsProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Operation(name = "$get-narrative", idempotent = true, type = Library.class)
public Parameters getNarrative(@IdParam IdType theId) {
    Library theResource = this.libraryResourceProvider.getDao().read(theId);
    Narrative n = this.narrativeProvider.getNarrative(this.libraryResourceProvider.getContext(), theResource);
    Parameters p = new Parameters();
    p.addParameter().setValue(new StringType(n.getDivAsString()));
    return p;
}
 
Example 6
Source Project: cqf-ruler   Source File: MeasureOperationsProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Operation(name = "$get-narrative", idempotent = true, type = Measure.class)
public Parameters getNarrative(@IdParam IdType theId) {
    Measure theResource = this.measureResourceProvider.getDao().read(theId);
    CqfMeasure cqfMeasure = this.dataRequirementsProvider.createCqfMeasure(theResource, this.libraryResolutionProvider);
    Narrative n = this.narrativeProvider.getNarrative(this.measureResourceProvider.getContext(), cqfMeasure);
    Parameters p = new Parameters();
    p.addParameter().setValue(new StringType(n.getDivAsString()));
    return p;
}
 
Example 7
public Optional<String> getText(DomainResource resource){
	Narrative narrative = ((DomainResource) resource).getText();
	if (narrative != null && narrative.getDivAsString() != null) {
		return ModelUtil.getNarrativeAsString(narrative);
	}
	return Optional.empty();
}
 
Example 8
Source Project: elexis-3-core   Source File: AbstractHelper.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public Optional<String> getText(DomainResource domainResource){
	Narrative narrative = domainResource.getText();
	if (narrative != null && narrative.getDivAsString() != null) {
		return ModelUtil.getNarrativeAsString(narrative);
	}
	return Optional.empty();
}
 
Example 9
Source Project: elexis-3-core   Source File: ModelUtil.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public static Optional<String> getNarrativeAsString(Narrative narrative) {
	String text = narrative.getDivAsString();
	if (text != null) {
		String divDecodedText = text.replaceAll(
			"<div>|<div xmlns=\"http://www.w3.org/1999/xhtml\">|</div>|</ div>", "");
		divDecodedText = divDecodedText.replaceAll("<br/>|<br />", "\n")
			.replaceAll("&amp;", "&").replaceAll("&gt;", ">").replaceAll("&lt;", "<")
			.replaceAll("'&sect;'", "§");
		return Optional.of(divDecodedText);
	}
	return Optional.empty();
}
 
Example 10
Source Project: elexis-3-core   Source File: ModelUtil.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public static void setNarrativeFromString(Narrative narrative, String text){
	text = fixXhtmlContent(text);
	String divEncodedText =
		text.replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("§", "'&sect;'")
			.replaceAll("&", "&amp;").replaceAll("(\r\n|\r|\n)", "<br />");
	narrative.setDivAsString(divEncodedText);
}
 
Example 11
@Override
public Optional<String> getText(){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent() && resource.get() instanceof DomainResource) {
		Narrative narrative = ((DomainResource) resource.get()).getText();
		if (narrative != null && narrative.getDivAsString() != null) {
			return ModelUtil.getNarrativeAsString(narrative);
		}
	}
	return Optional.empty();
}
 
Example 12
Source Project: bunsen   Source File: TestData.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Returns a FHIR Condition for testing purposes.
 *
 * @return a FHIR Condition for testing.
 */
public static Condition newCondition() {

  Condition condition = new Condition();

  // Condition based on example from FHIR:
  // https://www.hl7.org/fhir/condition-example.json.html
  condition.setId("Condition/example");

  condition.setLanguage("en_US");

  // Narrative text
  Narrative narrative = new Narrative();
  narrative.setStatusAsString("generated");
  narrative.setDivAsString("This data was generated for test purposes.");
  XhtmlNode node = new XhtmlNode();
  node.setNodeType(NodeType.Text);
  node.setValue("Severe burn of left ear (Date: 24-May 2012)");
  condition.setText(narrative);

  condition.setSubject(new Reference("Patient/12345").setDisplay("Here is a display for you."));

  condition.setVerificationStatus(Condition.ConditionVerificationStatus.CONFIRMED);

  // Condition code
  CodeableConcept code = new CodeableConcept();
  code.addCoding()
      .setSystem("http://snomed.info/sct")
      .setCode("39065001")
      .setDisplay("Severe");
  condition.setSeverity(code);

  // Severity code
  CodeableConcept severity = new CodeableConcept();
  severity.addCoding()
      .setSystem("http://snomed.info/sct")
      .setCode("24484000")
      .setDisplay("Burn of ear")
      .setUserSelected(true);
  condition.setSeverity(severity);

  // Onset date time
  DateTimeType onset = new DateTimeType();
  onset.setValueAsString("2012-05-24");
  condition.setOnset(onset);

  return condition;
}
 
Example 13
Source Project: bunsen   Source File: TestData.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Returns a FHIR Condition for testing purposes.
 */
public static Condition newCondition() {

  Condition condition = new Condition();

  // Condition based on example from FHIR:
  // https://www.hl7.org/fhir/condition-example.json.html
  condition.setId("Condition/example");

  condition.setLanguage("en_US");

  // Narrative text
  Narrative narrative = new Narrative();
  narrative.setStatusAsString("generated");
  narrative.setDivAsString("This data was generated for test purposes.");
  XhtmlNode node = new XhtmlNode();
  node.setNodeType(NodeType.Text);
  node.setValue("Severe burn of left ear (Date: 24-May 2012)");
  condition.setText(narrative);

  condition.setSubject(new Reference("Patient/example").setDisplay("Here is a display for you."));

  condition.setVerificationStatus(Condition.ConditionVerificationStatus.CONFIRMED);

  // Condition code
  CodeableConcept code = new CodeableConcept();
  code.addCoding()
      .setSystem("http://snomed.info/sct")
      .setCode("39065001")
      .setDisplay("Severe");
  condition.setSeverity(code);

  // Severity code
  CodeableConcept severity = new CodeableConcept();
  severity.addCoding()
      .setSystem("http://snomed.info/sct")
      .setCode("24484000")
      .setDisplay("Burn of ear")
      .setUserSelected(true);
  condition.setSeverity(severity);

  // Onset date time
  DateTimeType onset = new DateTimeType();
  onset.setValueAsString("2012-05-24");
  condition.setOnset(onset);

  return condition;
}
 
Example 14
public Narrative.NarrativeStatus getNarrativeStatus() {
    return narrativeStatus;
}
 
Example 15
public void setNarrativeStatus(Narrative.NarrativeStatus narrativeStatus) {
    this.narrativeStatus = narrativeStatus;
}