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;
}
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;
}
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.getConstrainedType().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.GroupComponent> answerGroups = new ArrayList<QuestionnaireResponse.GroupComponent>();
if (resource != null)
answerGroups.add(response.getGroup());
if (prebuiltQuestionnaire != null) {
// give it a fake group to build
Questionnaire.GroupComponent group = new Questionnaire.GroupComponent();
buildGroup(group, profile, profile.getSnapshot().getElement().get(0), list, answerGroups);
} else
buildGroup(questionnaire.getGroup(), 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;
try {
m = p.parse("<div>" + s + "</div>", "div");
} catch (org.hl7.fhir.exceptions.FHIRFormatError e) {
throw new FHIRFormatError(e.getMessage(), e);
}
x.getChildNodes().addAll(m.getChildNodes());
}
}
Aggregations