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;
}
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);
}
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;
}
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());
}
}
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;
}
Aggregations