Skip to content

Commit ef78ec0

Browse files
committed
Additions and fixes to support advance directive section injection in IPS
1 parent 8e1b3d5 commit ef78ec0

File tree

4 files changed

+95
-31
lines changed

4 files changed

+95
-31
lines changed

src/lib/AddFile.svelte

+21
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@
7171
section: undefined,
7272
resources: undefined
7373
};
74+
let adData: {section: any|undefined; resources: any[]|undefined} = {
75+
section: undefined,
76+
resources: undefined
77+
};
7478
let resourcesToInject: Record<string, {section: any|undefined; resources: {[key: string]: ResourceHelper}}> = {};
7579
let patientName = "My";
7680
let patient: any | undefined;
@@ -107,6 +111,22 @@
107111
}
108112
}
109113
114+
$: {
115+
if (adData.resources || adData.section) {
116+
let adInjection: {section: any|undefined; resources: {[key: string]: ResourceHelper}} = {
117+
section: adData.section,
118+
resources: {}
119+
}
120+
adData.resources?.forEach((r) => {
121+
let rh = new ResourceHelper(r.resource);
122+
adInjection.resources[rh.tempId] = rh;
123+
});
124+
resourcesToInject["Advance Directives"] = adInjection;
125+
} else {
126+
delete resourcesToInject["Advance Directives"];
127+
}
128+
}
129+
110130
onMount(() => {
111131
if (sessionStorage.getItem('URL')) {
112132
let url = sessionStorage.getItem('URL') ?? '/create';
@@ -350,6 +370,7 @@
350370
<TabPane class="ad-tab" tabId="ad" style="padding-top:10px">
351371
<span class="ad-tab" slot="tab">Advance Directive Search</span>
352372
<FetchAD
373+
bind:adSection={adData.section} bind:adSectionResources={adData.resources}
353374
on:update-resources={ async ({ detail }) => { handleNewResources(detail) } }>
354375
</FetchAD>
355376
</TabPane>

src/lib/FetchAD.svelte

+65-27
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import type { ResourceRetrieveEvent } from './types';
1313
import { createEventDispatcher } from 'svelte';
1414
15+
export let adSection: any | undefined;
16+
export let adSectionResources: any[] | undefined;
17+
1518
const resourceDispatch = createEventDispatcher<{ 'update-resources': ResourceRetrieveEvent }>();
1619
1720
let selectedUrl = "https://qa-rr-fhir.maxmddirect.com";
@@ -49,6 +52,41 @@
4952
resources: undefined
5053
};
5154
55+
let adSectionTemplate = {
56+
title: "Advance Directives",
57+
code: {
58+
coding: [
59+
{
60+
system: "http://loinc.org",
61+
code: "42348-3",
62+
display: "Advance Directives"
63+
}
64+
]
65+
},
66+
entry: []
67+
};
68+
69+
function updateAdSection(resources: any[]) {
70+
if (adSection === undefined) {
71+
adSection = JSON.parse(JSON.stringify(adSectionTemplate));
72+
}
73+
if (adSectionResources) {
74+
adSectionResources = adSectionResources.concat(resources);
75+
} else {
76+
adSectionResources = resources.map((r, index) => {
77+
r.id = `advance-directive-document-${index+1}`;
78+
let entry = {resource: r, fullUrl: `urn:uuid:${r.id}`};
79+
return entry;
80+
});
81+
}
82+
adSection.entry = adSectionResources.map((r) => {
83+
return {
84+
reference: r.fullUrl
85+
}
86+
});
87+
console.log(adSectionResources);
88+
}
89+
5290
let summaryUrlValidated: URL | undefined = undefined;
5391
$: {
5492
setSummaryUrlValidated(selectedUrl);
@@ -114,6 +152,7 @@
114152
115153
function buildPatientSearchQuery() {
116154
let query = "?";
155+
query += 'active=true&';
117156
query += dob ? `birthdate=${dob}&` : '';
118157
query += first ? `given=${first}&` : '';
119158
query += last ? `family=${last}&` : '';
@@ -124,7 +163,7 @@
124163
query += city ? `address-city=${city}&` : '';
125164
query += state ? `address-state=${state}&` : '';
126165
query += zip ? `address-postalcode=${zip}&` : '';
127-
query += 'active=true';
166+
query = query.substring(0, query.length - 1);
128167
return query;
129168
}
130169
@@ -186,29 +225,29 @@
186225
});
187226
}
188227
189-
async function injectPdfIntoDocRef(url, attachment) {
190-
try {
191-
const response = await fetch(url);
192-
if (response.ok) {
193-
const blob = await response.blob();
194-
const reader = new FileReader();
195-
reader.onloadend = () => {
196-
console.log(reader.result); // Log the full data URL for debugging
197-
attachment.data = reader.result.split(',')[1]; // Base64 encoded data
198-
};
199-
reader.readAsDataURL(blob);
200-
/**
201-
const arrayBuffer = await response.arrayBuffer();
202-
const base64String = btoa(String.fromCharCode(...new Uint8Array(arrayBuffer)));
203-
attachment.data = base64String;
204-
*/
205-
} else {
206-
console.error(`Failed to fetch PDF from ${url}`);
228+
async function injectPdfIntoDocRef(url, attachment) {
229+
try {
230+
const response = await fetch(url);
231+
if (response.ok) {
232+
const blob = await response.blob();
233+
const reader = new FileReader();
234+
reader.onloadend = () => {
235+
console.log(reader.result); // Log the full data URL for debugging
236+
attachment.data = reader.result?.split(',')[1]; // Base64 encoded data
237+
};
238+
reader.readAsDataURL(blob);
239+
/**
240+
const arrayBuffer = await response.arrayBuffer();
241+
const base64String = btoa(String.fromCharCode(...new Uint8Array(arrayBuffer)));
242+
attachment.data = base64String;
243+
*/
244+
} else {
245+
console.error(`Failed to fetch PDF from ${url}`);
246+
}
247+
} catch (error) {
248+
console.error(`Error fetching PDF from ${url}:`, error);
207249
}
208-
} catch (error) {
209-
console.error(`Error fetching PDF from ${url}:`, error);
210250
}
211-
}
212251
213252
async function prepareIps() {
214253
fetchError = '';
@@ -245,14 +284,13 @@ async function injectPdfIntoDocRef(url, attachment) {
245284
}
246285
}
247286
});
248-
249-
resources.unshift(patient);
250-
287+
updateAdSection(resources);
288+
// resources.unshift(patient);
251289
result = {
252-
resources: resources,
290+
resources: [patient], // resources,
253291
source: hostname
254292
};
255-
console.log(resources);
293+
console.log([patient, ...resources]);
256294
resourceDispatch('update-resources', result);
257295
} catch (e) {
258296
processing = false;

src/lib/ResourceSelector.svelte

+5-4
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737
export let injectedResources: Record<string, {section: any|undefined; resources: { [key: string]: ResourceHelper }}>;
3838
3939
const components: Record<string, any> = {
40-
"DocumentReference": AdvanceDirective,
41-
"Consent": AdvanceDirective,
4240
"AllergyIntolerance": AllergyIntolerance,
4341
"Condition": Condition,
42+
"Consent": AdvanceDirective,
4443
"DiagnosticReport": DiagnosticReport,
44+
"DocumentReference": AdvanceDirective,
4545
"Immunization": Immunization,
4646
"Location": Location,
4747
"Medication": Medication,
@@ -53,7 +53,8 @@
5353
"Practitioner": Practitioner,
5454
"Problem": Problem,
5555
"Procedure": Procedure,
56-
"Occupational Data for Health": OccupationalDataForHealth
56+
"Occupational Data for Health": OccupationalDataForHealth,
57+
"Advance Directives": AdvanceDirective
5758
};
5859
5960
const ipsDispatch = createEventDispatcher<{ 'ips-retrieved': IPSRetrieveEvent }>();
@@ -305,7 +306,7 @@
305306
if (injectedResources[section].resources[rkeys[i]].include) {
306307
let entry = {
307308
resource: injectedResources[section].resources[rkeys[i]].resource,
308-
fullUrl: injectedResources[section].resources[rkeys[i]].resource.id
309+
fullUrl: `urn:uuid:${injectedResources[section].resources[rkeys[i]].resource.id}`
309310
}
310311
content.entry.push(entry);
311312
injectedResources[section].section.entry.push({

src/routes/create/+page.svelte

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
goto(`/view/${shl.id}`);
6262
} else {
6363
const newShl = await newShlFromShc(detail);
64+
newShl.files.map(f => {
65+
f.contentEncrypted = f.contentEncrypted.slice(0, 200);
66+
return f;
67+
});
6468
$shlStore = [...$shlStore, newShl];
6569
goto(`/view/${newShl.id}`);
6670
}

0 commit comments

Comments
 (0)