Skip to content

Commit

Permalink
Merge pull request #85 from the-commons-project/support-composition-r…
Browse files Browse the repository at this point in the history
…endering

Support Composition rendering
  • Loading branch information
edwardjcruz authored Dec 21, 2023
2 parents 7504198 + 753d183 commit b5862d3
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 35 deletions.
28 changes: 14 additions & 14 deletions src/Data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <Coverage organized={ organized } dcr={ dcr } />;
break;
Expand All @@ -112,13 +112,13 @@ export default function Data({ shx }) {
break;

// >>> ADD MORE RENDERERS HERE <<<

default:
elt = <pre><code>{JSON.stringify(bundle.fhir, null, 2)}</code></pre>;
elt = <pre><code>{JSON.stringify(bundle.fhir, null, 2)}</code></pre>;
break;
}
}

return(
<>
{ renderBundleChooser() }
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand All @@ -185,18 +185,18 @@ export default function Data({ shx }) {
value={bundleIndex}
sx={{ mb: 2 }}
onChange={ onBundleChange } >

{ elts }

</Select>
</>
);
}

// +-------------+
// | Main Render |
// +-------------+

useEffect(() => {

verifySHX(shx, passcode)
Expand Down Expand Up @@ -231,4 +231,4 @@ export default function Data({ shx }) {
}

return(renderBundle());
}
}
50 changes: 30 additions & 20 deletions src/PatientSummary.js
Original file line number Diff line number Diff line change
@@ -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 [
Expand All @@ -17,36 +16,47 @@ export default function PatientSummary({ organized, dcr }) {
</div>,
<div key={`${s.title}-content`} className={styles.sectionContent}>
<PatientSummarySection s={s} rmap={rmap} dcr={dcr} />
</div>
</div>,
];
});
}

};

// +-------------+
// | 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 ? (
<>
<div className={styles.sectionTitle}>Composition</div>
<div>
<IFrameSandbox html={DOMPurify.sanitize(compositionDivTextContent)} />
</div>
</>
) : null;

return (
<div className={styles.container}>
<h2>{comp.title}</h2>
<div className={styles.dataTable}>
<div className={styles.sectionTitle}>Patient</div>
<div className={styles.patCell}>{futil.renderPerson(comp.subject, rmap)}</div>

<div className={styles.sectionTitle}>Summary prepared by</div>
<div>{authors}</div>

{renderSections()}
</div>
</div>
<div className={styles.container}>
<h2>{comp.title}</h2>
<div className={styles.dataTable}>
<div className={styles.sectionTitle}>Patient</div>
<div className={styles.patCell}>{futil.renderPerson(comp.subject, rmap)}</div>

{renderSections()}

{compositionRow}
<div className={styles.sectionTitle}>Summary prepared by</div>
<div>{authors}</div>
</div>
</div>
);
}




7 changes: 7 additions & 0 deletions src/PatientSummary.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,10 @@
margin-top: 0px;
}
}

.compositionSourceList {
padding-left: 0;
border: none;
margin: 0;
padding: 0;
}
19 changes: 18 additions & 1 deletion src/lib/SHX.js
Original file line number Diff line number Diff line change
Expand Up @@ -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* |
// +--------------+
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit b5862d3

Please sign in to comment.