|
32 | 32 | import OccupationalDataForHealth from './resource-templates/OccupationalDataForHealth.svelte';
|
33 | 33 |
|
34 | 34 | export let newResources: Array<any> | undefined;
|
35 |
| - export let submitSelections: boolean; |
| 35 | + export let submitting: boolean; |
36 | 36 | export let patient: any | undefined;
|
37 | 37 | export let injectedResources: Record<string, {section: any|undefined; resources: { [key: string]: ResourceHelper }}>;
|
38 | 38 |
|
39 | 39 | const components: Record<string, any> = {
|
40 | 40 | "DocumentReference": AdvanceDirective,
|
| 41 | + "Consent": AdvanceDirective, |
41 | 42 | "AllergyIntolerance": AllergyIntolerance,
|
42 | 43 | "Condition": Condition,
|
43 | 44 | "DiagnosticReport": DiagnosticReport,
|
|
57 | 58 |
|
58 | 59 | const ipsDispatch = createEventDispatcher<{ 'ips-retrieved': IPSRetrieveEvent }>();
|
59 | 60 | const statusDispatch = createEventDispatcher<{ 'status-update': string }>();
|
| 61 | + const errorDispatch = createEventDispatcher<{ 'error': string }>(); |
60 | 62 | let resources:{ [key: string]: ResourceHelper } = {};
|
61 | 63 | let resourcesByType:{ [key: string]: { [key: string]: ResourceHelper} } = {};
|
62 |
| - let submitting = false; |
63 | 64 | let reference: string;
|
64 | 65 | let patientReference: string;
|
65 | 66 | let patients: {[key: string]: ResourceHelper} = {};
|
|
78 | 79 | }
|
79 | 80 | }
|
80 | 81 | $: {
|
81 |
| - if (submitSelections) { |
82 |
| - confirm(); |
| 82 | + if (submitting) { |
| 83 | + confirm().catch(error => { |
| 84 | + submitting = false; |
| 85 | + console.error(error); |
| 86 | + errorDispatch("error", error.message); |
| 87 | + }); |
83 | 88 | }
|
84 | 89 | }
|
85 | 90 |
|
|
224 | 229 | statusDispatch("status-update", "Preparing");
|
225 | 230 | let preparedResources = prepareResources(getSelectedResources());
|
226 | 231 | statusDispatch("status-update", "Adding data");
|
227 |
| - reference = await uploadResources(preparedResources); |
| 232 | + try { |
| 233 | + reference = await uploadResources(preparedResources); |
| 234 | + } catch (e:any) { |
| 235 | + throw new Error("Unable to upload resources", {cause: e}); |
| 236 | + } |
228 | 237 |
|
229 | 238 | let content:any;
|
230 | 239 | statusDispatch("status-update", "Building IPS");
|
231 | 240 | const contentResponse = await fetch(reference!, {
|
232 | 241 | headers: { accept: 'application/fhir+json' }
|
233 | 242 | }).then(function(response) {
|
234 | 243 | if (!response.ok) {
|
235 |
| - // make the promise be rejected if we didn't get a 2xx response |
| 244 | + // reject the promise if we didn't get a 2xx response |
236 | 245 | throw new Error("Unable to fetch IPS", {cause: response});
|
237 | 246 | } else {
|
238 | 247 | return response;
|
|
0 commit comments