diff --git a/src/Data.js b/src/Data.js index 8c2bf55..4be045e 100644 --- a/src/Data.js +++ b/src/Data.js @@ -92,13 +92,13 @@ export default function Data({ shx }) { const bundle = shxResult.bundles[bundleIndex]; const organized = (bundle.contentOK() ? bundle.organized : undefined); - + let elt = undefined; if (organized) { - + switch (organized.typeInfo.btype) { - + case res.BTYPE_COVERAGE: elt = ; break; @@ -112,13 +112,13 @@ export default function Data({ shx }) { break; // >>> ADD MORE RENDERERS HERE <<< - + default: - elt =
{JSON.stringify(bundle.fhir, null, 2)}
; + elt =
{JSON.stringify(bundle.fhir, null, 2)}
; break; } } - + return( <> { renderBundleChooser() } @@ -147,12 +147,12 @@ export default function Data({ shx }) { shxResult.bundles[bundleIndex].organized && shxResult.bundles[bundleIndex].organized.typeInfo && shxResult.bundles[bundleIndex].organized.typeInfo.label - + ? shxResult.bundles[bundleIndex].organized.typeInfo.label : "Shared Information"); const div = document.getElementById("bundle-contents"); - + if (toFile) { saveDivToPdfFile(div, baseName); } @@ -164,7 +164,7 @@ export default function Data({ shx }) { const onBundleChange = (evt) => { setBundleIndex(parseInt(evt.target.value)); } - + const renderBundleChooser = () => { if (shxResult.bundles.length <= 1) return(undefined); @@ -185,18 +185,18 @@ export default function Data({ shx }) { value={bundleIndex} sx={{ mb: 2 }} onChange={ onBundleChange } > - + { elts } - + ); } - + // +-------------+ // | Main Render | // +-------------+ - + useEffect(() => { verifySHX(shx, passcode) @@ -231,4 +231,4 @@ export default function Data({ shx }) { } return(renderBundle()); -} +} \ No newline at end of file diff --git a/src/PatientSummary.js b/src/PatientSummary.js index 6ab02ba..dcc457d 100644 --- a/src/PatientSummary.js +++ b/src/PatientSummary.js @@ -1,14 +1,13 @@ -import * as futil from './lib/fhirUtil.js'; +import * as futil from './lib/fhirUtil.js'; import PatientSummarySection from './PatientSummarySection.js'; - import styles from './PatientSummary.module.css'; +import IFrameSandbox from './IFrameSandbox.js'; +import DOMPurify from 'dompurify'; export default function PatientSummary({ organized, dcr }) { - // +----------------+ // | renderSections | // +----------------+ - const renderSections = () => { return comp.section.flatMap((s) => { return [ @@ -17,36 +16,47 @@ export default function PatientSummary({ organized, dcr }) { ,
-
+ , ]; }); - } - + }; // +-------------+ // | Main Render | // +-------------+ - const comp = organized.byType.Composition[0]; const rmap = organized.byId; const authors = comp.author.map((a) => futil.renderOrgOrPerson(a, rmap)); + const compositionDivTextContent = comp.text && comp.text.div ? comp.text.div : ''; + + // Conditionally render Composition row + const compositionRow = compositionDivTextContent ? ( + <> +
Composition
+
+ +
+ + ) : null; return ( -
-

{comp.title}

-
-
Patient
-
{futil.renderPerson(comp.subject, rmap)}
- -
Summary prepared by
-
{authors}
- - {renderSections()} -
-
+
+

{comp.title}

+
+
Patient
+
{futil.renderPerson(comp.subject, rmap)}
+ + {renderSections()} + + {compositionRow} +
Summary prepared by
+
{authors}
+
+
); } + diff --git a/src/PatientSummary.module.css b/src/PatientSummary.module.css index d512974..16e5bb7 100644 --- a/src/PatientSummary.module.css +++ b/src/PatientSummary.module.css @@ -87,3 +87,10 @@ margin-top: 0px; } } + +.compositionSourceList { + padding-left: 0; + border: none; + margin: 0; + padding: 0; +} \ No newline at end of file diff --git a/src/lib/SHX.js b/src/lib/SHX.js index e441376..f8955f3 100644 --- a/src/lib/SHX.js +++ b/src/lib/SHX.js @@ -92,6 +92,16 @@ class ExpiredError extends Error { constructor(msg) { super(msg); this.name = "ExpiredError"; } } + +class DataMissingError extends Error { + constructor(message) { + super(message); + this.name = "DataMissingError"; + } +} + + + // +--------------+ // | looksLikeSH* | // +--------------+ @@ -127,7 +137,10 @@ export async function verifySHX(shx, passcode = undefined) { if (err instanceof ExpiredError) { return(status(SHX_STATUS_EXPIRED, err.message)); } - + // Handle DataMissingError + if (err instanceof DataMissingError) { + return status(SHX_STATUS_ERROR, err.message); + } const reasons = (err ? err.toString() : "unexpected"); return(status(SHX_STATUS_ERROR, reasons)); } @@ -227,6 +240,10 @@ async function resolveSHX(shx, passcode) { // wasn't JSON, so assume it's an SHC... we'll error on verification if not resolved.verifiableCredentials.push(target); } + // Throw DataMissingError if no data found + if (resolved.verifiableCredentials.length === 0 && resolved.rawBundles.length === 0) { + throw new DataMissingError("No data found in the SHL content."); + } return(resolved); }