diff --git a/src/lib/components/template/TemplateTable.svelte b/src/lib/components/template/TemplateTable.svelte
index 02c2339..a40d2da 100644
--- a/src/lib/components/template/TemplateTable.svelte
+++ b/src/lib/components/template/TemplateTable.svelte
@@ -261,6 +261,29 @@
function toggleMenu(id) {
activeMenu = activeMenu === id ? null : id;
}
+
+ async function exportFormTemplate(templateId: string, templateTitle: string) {
+ const response = await fetch(`/api/server/template/export`, {
+ method: 'POST',
+ body: JSON.stringify({
+ // sessionId,
+ templateId: templateId,
+ }),
+ headers: { 'content-type': 'application/json' }
+ });
+ if (!response.ok) {
+ throw new Error(`Failed to export care plan: ${response.statusText}`);
+ }
+
+ const filename = `${templateTitle}.json`;
+ const blob = await response.blob();
+ const a = document.createElement('a');
+ a.href = URL.createObjectURL(blob);
+ a.download = filename;
+ document.body.appendChild(a);
+ a.click();
+ document.body.removeChild(a);
+ }
@@ -401,6 +424,17 @@
+
+
+
+
{
+ const request = event.request;
+ const data = await request.json();
+
+ try {
+ const blob = await exportFormTemplates(
+ // data.sessionId,
+ data.templateId,
+ );
+ return new Response(blob, {
+ headers: {
+ 'Content-Type': 'application/json'
+ }
+ });
+ } catch (err) {
+ console.error(`Error in exporting careplan: ${err.message}`);
+ return new Response(err.message);
+ }
+};
\ No newline at end of file
diff --git a/src/routes/api/services/form-template.ts b/src/routes/api/services/form-template.ts
index f5d09b0..e857b34 100644
--- a/src/routes/api/services/form-template.ts
+++ b/src/routes/api/services/form-template.ts
@@ -1,4 +1,4 @@
-import { BACKEND_API_URL } from '$env/static/private';
+import { BACKEND_API_URL, INTERNAL_API_KEY, TOKEN } from '$env/static/private';
import { delete_, get_, post_, put_ } from './common';
//////////////////////////////////////////////////////////////
@@ -133,3 +133,22 @@ export const deleteFormTemplate = async (formTemplateId: string) => {
const url = BACKEND_API_URL + `/form-templates/${formTemplateId}`;
return await delete_(url);
};
+
+export const exportFormTemplates = async (formTemplateIdId: string) => {
+ const url = BACKEND_API_URL + `/form-templates/${formTemplateIdId}/export`;
+ // const session = await SessionManager.getSession(sessionId);
+ // const accessToken = session.accessToken;
+ const headers = {};
+ headers['Content-Type'] = 'application/json';
+ headers['x-api-key'] = INTERNAL_API_KEY;
+ headers['Authorization'] = `Bearer ${TOKEN}`;
+ const res = await fetch(url, {
+ method: 'GET',
+ headers
+ });
+ if (!res.ok) {
+ throw new Error(`Failed to export care plan: ${res.statusText}`);
+ }
+ const blob = await res.blob();
+ return blob;
+};