fix issues with rendering example scenario

This commit is contained in:
Grahame Grieve 2024-10-06 15:22:26 +08:00
parent 4a1aa461a9
commit 88d0cc8a68
2 changed files with 26 additions and 17 deletions

View File

@ -441,8 +441,9 @@ public class ExampleScenario40_50 {
tgt.setPauseElement(Boolean40_50.convertBoolean(src.getPauseElement())); tgt.setPauseElement(Boolean40_50.convertBoolean(src.getPauseElement()));
if (src.hasOperation()) if (src.hasOperation())
tgt.setOperation(convertExampleScenarioProcessStepOperationComponent(src.getOperation(), src.getNumber())); tgt.setOperation(convertExampleScenarioProcessStepOperationComponent(src.getOperation(), src.getNumber()));
else else if (src.hasNumber()) {
tgt.addExtension(PROCESS_STEP_NUMBER, String40_50.convertString(src.getNumberElement())); tgt.addExtension(PROCESS_STEP_NUMBER, String40_50.convertString(src.getNumberElement()));
}
for (org.hl7.fhir.r5.model.ExampleScenario.ExampleScenarioProcessStepAlternativeComponent t : src.getAlternative()) for (org.hl7.fhir.r5.model.ExampleScenario.ExampleScenarioProcessStepAlternativeComponent t : src.getAlternative())
tgt.addAlternative(convertExampleScenarioProcessStepAlternativeComponent(t)); tgt.addAlternative(convertExampleScenarioProcessStepAlternativeComponent(t));
return tgt; return tgt;

View File

@ -30,6 +30,7 @@ import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.RenderingContext.KnownLinkType; import org.hl7.fhir.r5.renderers.utils.RenderingContext.KnownLinkType;
import org.hl7.fhir.r5.renderers.utils.ResourceWrapper; import org.hl7.fhir.r5.renderers.utils.ResourceWrapper;
import org.hl7.fhir.r5.utils.EOperationOutcome; import org.hl7.fhir.r5.utils.EOperationOutcome;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.xhtml.XhtmlDocument; import org.hl7.fhir.utilities.xhtml.XhtmlDocument;
import org.hl7.fhir.utilities.xhtml.XhtmlNode; import org.hl7.fhir.utilities.xhtml.XhtmlNode;
@ -80,19 +81,24 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
} }
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
throw new FHIRException(context.formatPhrase(RenderingContext.EX_SCEN_ERR_REN, scen.getUrl(), e) + " "); throw new FHIRException(context.formatPhrase(RenderingContext.EX_SCEN_ERR_REN, scen.getUrl(), e) + " ");
} }
} }
public String renderDiagram(RenderingStatus status, ResourceWrapper res, ExampleScenario scen) throws IOException { public String renderDiagram(RenderingStatus status, ResourceWrapper res, ExampleScenario scen) throws IOException {
String plantUml = toPlantUml(status, res, scen); try {
SourceStringReader reader = new SourceStringReader(plantUml); String plantUml = toPlantUml(status, res, scen);
final ByteArrayOutputStream os = new ByteArrayOutputStream(); SourceStringReader reader = new SourceStringReader(plantUml);
reader.outputImage(os, new FileFormatOption(FileFormat.SVG)); final ByteArrayOutputStream os = new ByteArrayOutputStream();
os.close(); reader.outputImage(os, new FileFormatOption(FileFormat.SVG));
os.close();
final String svg = new String(os.toByteArray(), Charset.forName("UTF-8")); final String svg = new String(os.toByteArray(), Charset.forName("UTF-8"));
return svg; return svg;
} catch (Exception e) {
return "<p style=\"color: maroon\"><b>"+Utilities.escapeXml(e.getMessage())+"</b></p>";
}
} }
protected String toPlantUml(RenderingStatus status, ResourceWrapper res, ExampleScenario scen) throws IOException { protected String toPlantUml(RenderingStatus status, ResourceWrapper res, ExampleScenario scen) throws IOException {
@ -197,12 +203,14 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
private String handleDeactivation(String actorId, boolean active, Map<String,Boolean> actorsActive, Map<String, String> actorKeys) { private String handleDeactivation(String actorId, boolean active, Map<String,Boolean> actorsActive, Map<String, String> actorKeys) {
String plantUml = ""; String plantUml = "";
Boolean actorWasActive = actorsActive.get(actorId); Boolean actorWasActive = actorsActive.get(actorId);
if (!active && actorWasActive) { if (actorWasActive != null) {
plantUml += "deactivate " + actorKeys.get(actorId) + "\r\n"; if (!active && actorWasActive) {
} plantUml += "deactivate " + actorKeys.get(actorId) + "\r\n";
if (active != actorWasActive) { }
actorsActive.remove(actorId); if (active != actorWasActive) {
actorsActive.put(actorId, Boolean.valueOf(active)); actorsActive.remove(actorId);
actorsActive.put(actorId, Boolean.valueOf(active));
}
} }
return plantUml; return plantUml;
} }
@ -505,9 +513,9 @@ public class ExampleScenarioRenderer extends TerminologyRenderer {
if (instanceRef==null || instanceRef.getInstanceReference()==null) if (instanceRef==null || instanceRef.getInstanceReference()==null)
return; return;
ExampleScenarioInstanceComponent instance = instances.get(instanceRef.getInstanceReference()); ExampleScenarioInstanceComponent instance = instances.get(instanceRef.getInstanceReference());
if (instance==null) if (instance==null) {
throw new FHIRException(context.formatPhrase(RenderingContext.EX_SCEN_UN_INST, instanceRef.getInstanceReference())+" "); instanceCell.b().tx("Bad reference: "+instanceRef.getInstanceReference());
if (instanceRef.hasVersionReference()) { } else if (instanceRef.hasVersionReference()) {
ExampleScenarioInstanceVersionComponent theVersion = null; ExampleScenarioInstanceVersionComponent theVersion = null;
for (ExampleScenarioInstanceVersionComponent version: instance.getVersion()) { for (ExampleScenarioInstanceVersionComponent version: instance.getVersion()) {
if (version.getKey().equals(instanceRef.getVersionReference())) { if (version.getKey().equals(instanceRef.getVersionReference())) {