|
12 | 12 | import type { ResourceRetrieveEvent } from './types';
|
13 | 13 | import { createEventDispatcher } from 'svelte';
|
14 | 14 |
|
| 15 | + export let adSection: any | undefined; |
| 16 | + export let adSectionResources: any[] | undefined; |
| 17 | +
|
15 | 18 | const resourceDispatch = createEventDispatcher<{ 'update-resources': ResourceRetrieveEvent }>();
|
16 | 19 |
|
17 | 20 | let selectedUrl = "https://qa-rr-fhir.maxmddirect.com";
|
|
49 | 52 | resources: undefined
|
50 | 53 | };
|
51 | 54 |
|
| 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 | +
|
52 | 90 | let summaryUrlValidated: URL | undefined = undefined;
|
53 | 91 | $: {
|
54 | 92 | setSummaryUrlValidated(selectedUrl);
|
|
114 | 152 |
|
115 | 153 | function buildPatientSearchQuery() {
|
116 | 154 | let query = "?";
|
| 155 | + query += 'active=true&'; |
117 | 156 | query += dob ? `birthdate=${dob}&` : '';
|
118 | 157 | query += first ? `given=${first}&` : '';
|
119 | 158 | query += last ? `family=${last}&` : '';
|
|
124 | 163 | query += city ? `address-city=${city}&` : '';
|
125 | 164 | query += state ? `address-state=${state}&` : '';
|
126 | 165 | query += zip ? `address-postalcode=${zip}&` : '';
|
127 |
| - query += 'active=true'; |
| 166 | + query = query.substring(0, query.length - 1); |
128 | 167 | return query;
|
129 | 168 | }
|
130 | 169 |
|
|
186 | 225 | });
|
187 | 226 | }
|
188 | 227 |
|
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); |
207 | 249 | }
|
208 |
| - } catch (error) { |
209 |
| - console.error(`Error fetching PDF from ${url}:`, error); |
210 | 250 | }
|
211 |
| -} |
212 | 251 |
|
213 | 252 | async function prepareIps() {
|
214 | 253 | fetchError = '';
|
@@ -245,14 +284,13 @@ async function injectPdfIntoDocRef(url, attachment) {
|
245 | 284 | }
|
246 | 285 | }
|
247 | 286 | });
|
248 |
| -
|
249 |
| - resources.unshift(patient); |
250 |
| -
|
| 287 | + updateAdSection(resources); |
| 288 | + // resources.unshift(patient); |
251 | 289 | result = {
|
252 |
| - resources: resources, |
| 290 | + resources: [patient], // resources, |
253 | 291 | source: hostname
|
254 | 292 | };
|
255 |
| - console.log(resources); |
| 293 | + console.log([patient, ...resources]); |
256 | 294 | resourceDispatch('update-resources', result);
|
257 | 295 | } catch (e) {
|
258 | 296 | processing = false;
|
|
0 commit comments