Skip to content

Commit 27bd7b7

Browse files
authored
Merge pull request #86 from the-commons-project/develop
Develop
2 parents 0cd875b + 3887419 commit 27bd7b7

File tree

4 files changed

+68
-34
lines changed

4 files changed

+68
-34
lines changed

src/Data.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ export default function Data({ shx }) {
9292

9393
const bundle = shxResult.bundles[bundleIndex];
9494
const organized = (bundle.contentOK() ? bundle.organized : undefined);
95-
95+
9696
let elt = undefined;
9797

9898
if (organized) {
99-
99+
100100
switch (organized.typeInfo.btype) {
101-
101+
102102
case res.BTYPE_COVERAGE:
103103
elt = <Coverage organized={ organized } dcr={ dcr } />;
104104
break;
@@ -112,13 +112,13 @@ export default function Data({ shx }) {
112112
break;
113113

114114
// >>> ADD MORE RENDERERS HERE <<<
115-
115+
116116
default:
117-
elt = <pre><code>{JSON.stringify(bundle.fhir, null, 2)}</code></pre>;
117+
elt = <pre><code>{JSON.stringify(bundle.fhir, null, 2)}</code></pre>;
118118
break;
119119
}
120120
}
121-
121+
122122
return(
123123
<>
124124
{ renderBundleChooser() }
@@ -147,12 +147,12 @@ export default function Data({ shx }) {
147147
shxResult.bundles[bundleIndex].organized &&
148148
shxResult.bundles[bundleIndex].organized.typeInfo &&
149149
shxResult.bundles[bundleIndex].organized.typeInfo.label
150-
150+
151151
? shxResult.bundles[bundleIndex].organized.typeInfo.label
152152
: "Shared Information");
153153

154154
const div = document.getElementById("bundle-contents");
155-
155+
156156
if (toFile) {
157157
saveDivToPdfFile(div, baseName);
158158
}
@@ -164,7 +164,7 @@ export default function Data({ shx }) {
164164
const onBundleChange = (evt) => {
165165
setBundleIndex(parseInt(evt.target.value));
166166
}
167-
167+
168168
const renderBundleChooser = () => {
169169

170170
if (shxResult.bundles.length <= 1) return(undefined);
@@ -185,18 +185,18 @@ export default function Data({ shx }) {
185185
value={bundleIndex}
186186
sx={{ mb: 2 }}
187187
onChange={ onBundleChange } >
188-
188+
189189
{ elts }
190-
190+
191191
</Select>
192192
</>
193193
);
194194
}
195-
195+
196196
// +-------------+
197197
// | Main Render |
198198
// +-------------+
199-
199+
200200
useEffect(() => {
201201

202202
verifySHX(shx, passcode)
@@ -231,4 +231,4 @@ export default function Data({ shx }) {
231231
}
232232

233233
return(renderBundle());
234-
}
234+
}

src/PatientSummary.js

+29-19
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import * as futil from './lib/fhirUtil.js';
1+
import * as futil from './lib/fhirUtil.js';
22
import PatientSummarySection from './PatientSummarySection.js';
3-
43
import styles from './PatientSummary.module.css';
4+
import IFrameSandbox from './IFrameSandbox.js';
5+
import DOMPurify from 'dompurify';
56

67
export default function PatientSummary({ organized, dcr }) {
7-
88
// +----------------+
99
// | renderSections |
1010
// +----------------+
11-
1211
const renderSections = () => {
1312
return comp.section.flatMap((s) => {
1413
return [
@@ -20,33 +19,44 @@ export default function PatientSummary({ organized, dcr }) {
2019
</div>
2120
];
2221
});
23-
}
24-
22+
};
2523

2624
// +-------------+
2725
// | Main Render |
2826
// +-------------+
29-
3027
const comp = organized.byType.Composition[0];
3128
const rmap = organized.byId;
3229

3330
const authors = comp.author.map((a) => futil.renderOrgOrPerson(a, rmap));
31+
const compositionDivTextContent = comp.text && comp.text.div ? comp.text.div : '';
32+
33+
// Conditionally render Composition row
34+
const compositionRow = compositionDivTextContent ? (
35+
<>
36+
<div className={styles.sectionTitle}>Composition</div>
37+
<div>
38+
<IFrameSandbox html={DOMPurify.sanitize(compositionDivTextContent)} />
39+
</div>
40+
</>
41+
) : null;
3442

3543
return (
36-
<div className={styles.container}>
37-
<h2>{comp.title}</h2>
38-
<div className={styles.dataTable}>
39-
<div className={styles.sectionTitle}>Patient</div>
40-
<div className={styles.patCell}>{futil.renderPerson(comp.subject, rmap)}</div>
41-
42-
<div className={styles.sectionTitle}>Summary prepared by</div>
43-
<div>{authors}</div>
44-
45-
{renderSections()}
46-
</div>
47-
</div>
44+
<div className={styles.container}>
45+
<h2>{comp.title}</h2>
46+
<div className={styles.dataTable}>
47+
<div className={styles.sectionTitle}>Patient</div>
48+
<div className={styles.patCell}>{futil.renderPerson(comp.subject, rmap)}</div>
49+
50+
{renderSections()}
51+
52+
{compositionRow}
53+
<div className={styles.sectionTitle}>Summary prepared by</div>
54+
<div>{authors}</div>
55+
</div>
56+
</div>
4857
);
4958
}
5059

5160

5261

62+

src/PatientSummary.module.css

+7
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,10 @@
8787
margin-top: 0px;
8888
}
8989
}
90+
91+
.compositionSourceList {
92+
padding-left: 0;
93+
border: none;
94+
margin: 0;
95+
padding: 0;
96+
}

src/lib/SHX.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ class ExpiredError extends Error {
9292
constructor(msg) { super(msg); this.name = "ExpiredError"; }
9393
}
9494

95+
96+
class DataMissingError extends Error {
97+
constructor(message) {
98+
super(message);
99+
this.name = "DataMissingError";
100+
}
101+
}
102+
103+
104+
95105
// +--------------+
96106
// | looksLikeSH* |
97107
// +--------------+
@@ -127,7 +137,10 @@ export async function verifySHX(shx, passcode = undefined) {
127137
if (err instanceof ExpiredError) {
128138
return(status(SHX_STATUS_EXPIRED, err.message));
129139
}
130-
140+
// Handle DataMissingError
141+
if (err instanceof DataMissingError) {
142+
return status(SHX_STATUS_ERROR, err.message);
143+
}
131144
const reasons = (err ? err.toString() : "unexpected");
132145
return(status(SHX_STATUS_ERROR, reasons));
133146
}
@@ -227,6 +240,10 @@ async function resolveSHX(shx, passcode) {
227240
// wasn't JSON, so assume it's an SHC... we'll error on verification if not
228241
resolved.verifiableCredentials.push(target);
229242
}
243+
// Throw DataMissingError if no data found
244+
if (resolved.verifiableCredentials.length === 0 && resolved.rawBundles.length === 0) {
245+
throw new DataMissingError("No data found in the SHL content.");
246+
}
230247

231248
return(resolved);
232249
}

0 commit comments

Comments
 (0)