@awell-health/awell-extensions 2.0.22 → 2.0.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. package/dist/extensions/shelly/actions/categorizeMessage/{realTest.test.js → callingRealOpenAITest.test.js} +5 -3
  2. package/dist/extensions/shelly/actions/categorizeMessage/callingRealOpenAITest.test.js.map +1 -0
  3. package/dist/extensions/shelly/actions/categorizeMessage/categorizeMessage.js +8 -4
  4. package/dist/extensions/shelly/actions/categorizeMessage/categorizeMessage.js.map +1 -1
  5. package/dist/extensions/shelly/actions/categorizeMessage/categorizeMessage.test.js +21 -17
  6. package/dist/extensions/shelly/actions/categorizeMessage/categorizeMessage.test.js.map +1 -1
  7. package/dist/extensions/shelly/actions/categorizeMessage/config/datapoints.d.ts +4 -0
  8. package/dist/extensions/shelly/actions/categorizeMessage/config/datapoints.js +4 -0
  9. package/dist/extensions/shelly/actions/categorizeMessage/config/datapoints.js.map +1 -1
  10. package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.d.ts +7 -4
  11. package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.js +27 -9
  12. package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.js.map +1 -1
  13. package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.test.js +19 -17
  14. package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.test.js.map +1 -1
  15. package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/constants.d.ts +13 -7
  16. package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/constants.js +15 -5
  17. package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/constants.js.map +1 -1
  18. package/dist/extensions/shelly/actions/index.d.ts +19 -5
  19. package/dist/extensions/shelly/actions/medicationFromImage/medicationFromImage.js +37 -23
  20. package/dist/extensions/shelly/actions/medicationFromImage/medicationFromImage.js.map +1 -1
  21. package/dist/extensions/shelly/actions/medicationFromImage/medicationFromImage.test.js +123 -3
  22. package/dist/extensions/shelly/actions/medicationFromImage/medicationFromImage.test.js.map +1 -1
  23. package/dist/extensions/shelly/actions/summarizeCareFlow/config/fields.d.ts +15 -5
  24. package/dist/extensions/shelly/actions/summarizeCareFlow/config/fields.js +21 -6
  25. package/dist/extensions/shelly/actions/summarizeCareFlow/config/fields.js.map +1 -1
  26. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/constants.d.ts +2 -0
  27. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/constants.js +37 -0
  28. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/constants.js.map +1 -0
  29. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/index.d.ts +1 -0
  30. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/index.js +6 -0
  31. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/index.js.map +1 -0
  32. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.d.ts +7 -0
  33. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.js +22 -0
  34. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.js.map +1 -0
  35. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.test.d.ts +1 -0
  36. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.test.js +42 -0
  37. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.test.js.map +1 -0
  38. package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlow.js +23 -10
  39. package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlow.js.map +1 -1
  40. package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlow.test.js +57 -26
  41. package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlow.test.js.map +1 -1
  42. package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlowRealOpenAI.test.d.ts +1 -0
  43. package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlowRealOpenAI.test.js +58 -0
  44. package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlowRealOpenAI.test.js.map +1 -0
  45. package/dist/extensions/shelly/actions/summarizeForm/config/fields.d.ts +15 -5
  46. package/dist/extensions/shelly/actions/summarizeForm/config/fields.js +21 -6
  47. package/dist/extensions/shelly/actions/summarizeForm/config/fields.js.map +1 -1
  48. package/dist/extensions/shelly/actions/summarizeForm/lib/getResponseText/getResponseText.js +2 -1
  49. package/dist/extensions/shelly/actions/summarizeForm/lib/getResponseText/getResponseText.js.map +1 -1
  50. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/constants.d.ts +2 -0
  51. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/constants.js +37 -0
  52. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/constants.js.map +1 -0
  53. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/index.d.ts +1 -0
  54. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/index.js +6 -0
  55. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/index.js.map +1 -0
  56. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/summarizeFormWithLLM.d.ts +7 -0
  57. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/summarizeFormWithLLM.js +22 -0
  58. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/summarizeFormWithLLM.js.map +1 -0
  59. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/summarizeFormWithLLM.test.d.ts +1 -0
  60. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/summarizeFormWithLLM.test.js +54 -0
  61. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/summarizeFormWithLLM.test.js.map +1 -0
  62. package/dist/extensions/shelly/actions/summarizeForm/summarizeForm.js +25 -8
  63. package/dist/extensions/shelly/actions/summarizeForm/summarizeForm.js.map +1 -1
  64. package/dist/extensions/shelly/actions/summarizeForm/summarizeForm.test.js +69 -31
  65. package/dist/extensions/shelly/actions/summarizeForm/summarizeForm.test.js.map +1 -1
  66. package/dist/extensions/shelly/actions/summarizeForm/summarizeFormRealOpenAI.test.d.ts +1 -0
  67. package/dist/extensions/shelly/actions/summarizeForm/summarizeFormRealOpenAI.test.js +71 -0
  68. package/dist/extensions/shelly/actions/summarizeForm/summarizeFormRealOpenAI.test.js.map +1 -0
  69. package/dist/extensions/shelly/lib/api/index.d.ts +1 -0
  70. package/dist/extensions/shelly/lib/api/index.js +6 -0
  71. package/dist/extensions/shelly/lib/api/index.js.map +1 -0
  72. package/dist/extensions/shelly/lib/api/medicationExtractorApi.d.ts +19 -0
  73. package/dist/extensions/shelly/lib/api/medicationExtractorApi.js +60 -0
  74. package/dist/extensions/shelly/lib/api/medicationExtractorApi.js.map +1 -0
  75. package/dist/extensions/shelly/lib/constants.d.ts +1 -0
  76. package/dist/extensions/shelly/lib/constants.js +2 -1
  77. package/dist/extensions/shelly/lib/constants.js.map +1 -1
  78. package/dist/extensions/shelly/lib/validatePayloadAndCreateSdk.d.ts +3 -2
  79. package/dist/extensions/shelly/lib/validatePayloadAndCreateSdk.js +20 -3
  80. package/dist/extensions/shelly/lib/validatePayloadAndCreateSdk.js.map +1 -1
  81. package/dist/extensions/shelly/types.d.ts +16 -0
  82. package/dist/extensions/shelly/types.js +3 -0
  83. package/dist/extensions/shelly/types.js.map +1 -0
  84. package/package.json +3 -1
  85. package/dist/extensions/shelly/actions/categorizeMessage/realTest.test.js.map +0 -1
  86. /package/dist/extensions/shelly/actions/categorizeMessage/{realTest.test.d.ts → callingRealOpenAITest.test.d.ts} +0 -0
@@ -3,12 +3,38 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const extensions_core_1 = require("@awell-health/extensions-core");
4
4
  const tests_1 = require("@/tests");
5
5
  const _1 = require(".");
6
- describe('Shelly - Medication From Image', () => {
6
+ describe('Medication From Image', () => {
7
7
  const { onComplete, onError, helpers, extensionAction, clearMocks } = extensions_core_1.TestHelpers.fromAction(_1.medicationFromImage);
8
8
  beforeEach(() => {
9
9
  clearMocks();
10
+ jest.spyOn(global, 'fetch');
10
11
  });
11
- test('Should work', async () => {
12
+ afterEach(() => {
13
+ jest.restoreAllMocks();
14
+ });
15
+ test('Should handle successful medication extraction', async () => {
16
+ const mockResponse = {
17
+ status: 'OK',
18
+ medications: [
19
+ {
20
+ product_rxcui: '809854',
21
+ product_name: 'hydrochlorothiazide 12.5 MG / quinapril 10 MG Oral Tablet [Accuretic]',
22
+ brand_name: 'Accuretic',
23
+ dose_form_name: 'Oral Tablet',
24
+ prescribable_name: 'Accuretic 10 MG / 12.5 MG Oral Tablet',
25
+ extracted_medication_name: 'Accuretic',
26
+ extracted_brand_name: 'Accuretic',
27
+ extracted_dosage: '10 mg / 12.5 mg',
28
+ extracted_ndcg: '0006-0711-31',
29
+ },
30
+ ],
31
+ };
32
+ global.fetch.mockResolvedValue({
33
+ status: 200,
34
+ statusText: 'Ok',
35
+ ok: true,
36
+ json: jest.fn().mockResolvedValue(mockResponse),
37
+ });
12
38
  await extensionAction.onEvent({
13
39
  payload: (0, tests_1.generateTestPayload)({
14
40
  fields: {
@@ -22,12 +48,106 @@ describe('Shelly - Medication From Image', () => {
22
48
  onError,
23
49
  helpers,
24
50
  });
51
+ expect(global.fetch).toHaveBeenCalledWith('https://medication-extractor-390819626634.us-central1.run.app/medication_extractor/', expect.objectContaining({
52
+ method: 'POST',
53
+ headers: expect.any(Object),
54
+ body: expect.any(String),
55
+ }));
25
56
  expect(onError).not.toHaveBeenCalled();
26
57
  expect(onComplete).toHaveBeenCalledWith({
27
58
  data_points: {
28
- data: expect.any(String),
59
+ data: JSON.stringify({
60
+ medications: mockResponse.medications,
61
+ }),
29
62
  },
30
63
  });
31
64
  });
65
+ test('Should handle API error response', async () => {
66
+ const mockErrorResponse = {
67
+ status: 'ERROR',
68
+ medications: [],
69
+ error_explanation: 'Invalid image URL',
70
+ };
71
+ global.fetch.mockResolvedValue({
72
+ status: 200,
73
+ statusText: 'Ok',
74
+ ok: true,
75
+ json: jest.fn().mockResolvedValue(mockErrorResponse),
76
+ });
77
+ await extensionAction.onEvent({
78
+ payload: (0, tests_1.generateTestPayload)({
79
+ fields: {
80
+ imageUrl: 'https://res.cloudinary.com/da7x4rzl4/image/upload/v1726601981/hackathon-sep-2024/invalid-url.png',
81
+ },
82
+ settings: {
83
+ openAiApiKey: 'a',
84
+ },
85
+ }),
86
+ onComplete,
87
+ onError,
88
+ helpers,
89
+ });
90
+ expect(global.fetch).toHaveBeenCalledWith('https://medication-extractor-390819626634.us-central1.run.app/medication_extractor/', expect.objectContaining({
91
+ method: 'POST',
92
+ headers: expect.any(Object),
93
+ body: expect.any(String),
94
+ }));
95
+ expect(onError).toHaveBeenCalledWith({
96
+ events: [
97
+ {
98
+ date: expect.any(String),
99
+ text: {
100
+ en: '500 (ERROR): {"status":"ERROR","medications":[],"error_explanation":"Invalid image URL"}',
101
+ },
102
+ error: {
103
+ category: 'SERVER_ERROR',
104
+ message: '500 (ERROR): {"status":"ERROR","medications":[],"error_explanation":"Invalid image URL"}',
105
+ },
106
+ },
107
+ ],
108
+ });
109
+ expect(onComplete).not.toHaveBeenCalled();
110
+ });
111
+ test('Should handle native fetch errors', async () => {
112
+ ;
113
+ global.fetch.mockResolvedValue({
114
+ status: 404,
115
+ statusText: 'Not found',
116
+ ok: false,
117
+ });
118
+ await extensionAction.onEvent({
119
+ payload: (0, tests_1.generateTestPayload)({
120
+ fields: {
121
+ imageUrl: 'https://res.cloudinary.com/da7x4rzl4/image/upload/v1726601981/hackathon-sep-2024/invalid-url.png',
122
+ },
123
+ settings: {
124
+ openAiApiKey: 'a',
125
+ },
126
+ }),
127
+ onComplete,
128
+ onError,
129
+ helpers,
130
+ });
131
+ expect(global.fetch).toHaveBeenCalledWith('https://medication-extractor-390819626634.us-central1.run.app/medication_extractor/', expect.objectContaining({
132
+ method: 'POST',
133
+ headers: expect.any(Object),
134
+ body: expect.any(String),
135
+ }));
136
+ expect(onError).toHaveBeenCalledWith({
137
+ events: [
138
+ {
139
+ date: expect.any(String),
140
+ text: {
141
+ en: '404 (Not found): ',
142
+ },
143
+ error: {
144
+ category: 'SERVER_ERROR',
145
+ message: '404 (Not found): ',
146
+ },
147
+ },
148
+ ],
149
+ });
150
+ expect(onComplete).not.toHaveBeenCalled();
151
+ });
32
152
  });
33
153
  //# sourceMappingURL=medicationFromImage.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"medicationFromImage.test.js","sourceRoot":"","sources":["../../../../../extensions/shelly/actions/medicationFromImage/medicationFromImage.test.ts"],"names":[],"mappings":";;AAAA,mEAA2D;AAC3D,mCAA6C;AAC7C,wBAAuC;AAEvC,QAAQ,CAAC,gCAAgC,EAAE,GAAG,EAAE;IAC9C,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,GACjE,6BAAW,CAAC,UAAU,CAAC,sBAAmB,CAAC,CAAA;IAE7C,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,EAAE,CAAA;IACd,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,aAAa,EAAE,KAAK,IAAI,EAAE;QAC7B,MAAM,eAAe,CAAC,OAAO,CAAC;YAC5B,OAAO,EAAE,IAAA,2BAAmB,EAAC;gBAC3B,MAAM,EAAE;oBACN,QAAQ,EACN,2GAA2G;iBAC9G;gBACD,QAAQ,EAAE;oBACR,YAAY,EAAE,GAAG;iBAClB;aACF,CAAC;YACF,UAAU;YACV,OAAO;YACP,OAAO;SACR,CAAC,CAAA;QAEF,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAA;QACtC,MAAM,CAAC,UAAU,CAAC,CAAC,oBAAoB,CAAC;YACtC,WAAW,EAAE;gBACX,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;aACzB;SACF,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
1
+ {"version":3,"file":"medicationFromImage.test.js","sourceRoot":"","sources":["../../../../../extensions/shelly/actions/medicationFromImage/medicationFromImage.test.ts"],"names":[],"mappings":";;AAAA,mEAA2D;AAC3D,mCAA6C;AAC7C,wBAAuC;AAGvC,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,GACjE,6BAAW,CAAC,UAAU,CAAC,sBAAmB,CAAC,CAAA;IAE7C,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,EAAE,CAAA;QACZ,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,CAAC,CAAC,CAAA;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,eAAe,EAAE,CAAA;IACxB,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,gDAAgD,EAAE,KAAK,IAAI,EAAE;QAChE,MAAM,YAAY,GAA8B;YAC9C,MAAM,EAAE,IAAI;YACZ,WAAW,EAAE;gBACX;oBACE,aAAa,EAAE,QAAQ;oBACvB,YAAY,EACV,uEAAuE;oBACzE,UAAU,EAAE,WAAW;o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AE,KAAK,IAAI,EAAE;QACnD,CAAC;QAAC,MAAM,CAAC,KAAmB,CAAC,iBAAiB,CAAC;YAC7C,MAAM,EAAE,GAAG;YACX,UAAU,EAAE,WAAW;YACvB,EAAE,EAAE,KAAK;SACkB,CAAC,CAAA;QAE9B,MAAM,eAAe,CAAC,OAAO,CAAC;YAC5B,OAAO,EAAE,IAAA,2BAAmB,EAAC;gBAC3B,MAAM,EAAE;oBACN,QAAQ,EACN,kGAAkG;iBACrG;gBACD,QAAQ,EAAE;oBACR,YAAY,EAAE,GAAG;iBAClB;aACF,CAAC;YACF,UAAU;YACV,OAAO;YACP,OAAO;SACR,CAAC,CAAA;QAEF,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,oBAAoB,CACvC,qFAAqF,EACrF,MAAM,CAAC,gBAAgB,CAAC;YACtB,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;YAC3B,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;SACzB,CAAC,CACH,CAAA;QAED,MAAM,CAAC,OAAO,CAAC,CAAC,oBAAoB,CAAC;YACnC,MAAM,EAAE;gBACN;oBACE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;oBACxB,IAAI,EAAE;wBACJ,EAAE,EAAE,mBAAmB;qBACxB;oBACD,KAAK,EAAE;wBACL,QAAQ,EAAE,cAAc;wBACxB,OAAO,EAAE,mBAAmB;qBAC7B;iBACF;aACF;SACF,CAAC,CAAA;QACF,MAAM,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAA;IAC3C,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,18 +1,28 @@
1
1
  import { FieldType } from '@awell-health/extensions-core';
2
2
  import z from 'zod';
3
3
  export declare const fields: {
4
- prompt: {
4
+ additionalInstructions: {
5
5
  id: string;
6
6
  label: string;
7
7
  description: string;
8
- type: FieldType.TEXT;
8
+ type: FieldType.STRING;
9
+ required: false;
10
+ };
11
+ stakeholder: {
12
+ id: string;
13
+ label: string;
14
+ description: string;
15
+ type: FieldType.STRING;
9
16
  required: false;
10
17
  };
11
18
  };
12
19
  export declare const FieldsValidationSchema: z.ZodObject<{
13
- prompt: z.ZodOptional<z.ZodString>;
20
+ additionalInstructions: z.ZodDefault<z.ZodOptional<z.ZodString>>;
21
+ stakeholder: z.ZodEffects<z.ZodOptional<z.ZodString>, string, string | undefined>;
14
22
  }, "strip", z.ZodTypeAny, {
15
- prompt?: string | undefined;
23
+ additionalInstructions: string;
24
+ stakeholder: string;
16
25
  }, {
17
- prompt?: string | undefined;
26
+ additionalInstructions?: string | undefined;
27
+ stakeholder?: string | undefined;
18
28
  }>;
@@ -7,15 +7,30 @@ exports.FieldsValidationSchema = exports.fields = void 0;
7
7
  const extensions_core_1 = require("@awell-health/extensions-core");
8
8
  const zod_1 = __importDefault(require("zod"));
9
9
  exports.fields = {
10
- prompt: {
11
- id: 'prompt',
12
- label: 'Prompt',
13
- description: 'Leave blank to use the default prompt',
14
- type: extensions_core_1.FieldType.TEXT,
10
+ additionalInstructions: {
11
+ id: 'additionalInstructions',
12
+ label: 'Additional instructions',
13
+ description: 'Specify additional instructions for summarization, for example format, length, what to focus on etc. If not specified, default instructions will be used.',
14
+ type: extensions_core_1.FieldType.STRING,
15
+ required: false,
16
+ },
17
+ stakeholder: {
18
+ id: 'stakeholder',
19
+ label: 'Stakeholder',
20
+ description: 'Defaults to "Clinician"',
21
+ type: extensions_core_1.FieldType.STRING,
15
22
  required: false,
16
23
  },
17
24
  };
18
25
  exports.FieldsValidationSchema = zod_1.default.object({
19
- prompt: zod_1.default.string().optional(),
26
+ additionalInstructions: zod_1.default.string().optional().default(''),
27
+ stakeholder: zod_1.default
28
+ .string()
29
+ .optional()
30
+ .transform((val) => {
31
+ if (val === undefined || val === '')
32
+ return 'Clinician';
33
+ return val;
34
+ }),
20
35
  });
21
36
  //# sourceMappingURL=fields.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fields.js","sourceRoot":"","sources":["../../../../../../extensions/shelly/actions/summarizeCareFlow/config/fields.ts"],"names":[],"mappings":";;;;;;AAAA,mEAAqE;AACrE,8CAAwC;AAE3B,QAAA,MAAM,GAAG;IACpB,MAAM,EAAE;QACN,EAAE,EAAE,QAAQ;QACZ,KAAK,EAAE,QAAQ;QACf,WAAW,EAAE,uCAAuC;QACpD,IAAI,EAAE,2BAAS,CAAC,IAAI;QACpB,QAAQ,EAAE,KAAK;KAChB;CAC8B,CAAA;AAEpB,QAAA,sBAAsB,GAAG,aAAC,CAAC,MAAM,CAAC;IAC7C,MAAM,EAAE,aAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACoB,CAAC,CAAA"}
1
+ {"version":3,"file":"fields.js","sourceRoot":"","sources":["../../../../../../extensions/shelly/actions/summarizeCareFlow/config/fields.ts"],"names":[],"mappings":";;;;;;AAAA,mEAAqE;AACrE,8CAAwC;AAE3B,QAAA,MAAM,GAAG;IACpB,sBAAsB,EAAE;QACtB,EAAE,EAAE,wBAAwB;QAC5B,KAAK,EAAE,yBAAyB;QAChC,WAAW,EACT,2JAA2J;QAC7J,IAAI,EAAE,2BAAS,CAAC,MAAM;QACtB,QAAQ,EAAE,KAAK;KAChB;IACD,WAAW,EAAE;QACX,EAAE,EAAE,aAAa;QACjB,KAAK,EAAE,aAAa;QACpB,WAAW,EAAE,yBAAyB;QACtC,IAAI,EAAE,2BAAS,CAAC,MAAM;QACtB,QAAQ,EAAE,KAAK;KAChB;CAC8B,CAAA;AAEpB,QAAA,sBAAsB,GAAG,aAAC,CAAC,MAAM,CAAC;IAC7C,sBAAsB,EAAE,aAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;IACzD,WAAW,EAAE,aAAC;SACX,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,SAAS,CAAC,CAAC,GAAG,EAAU,EAAE;QACzB,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,EAAE;YAAE,OAAO,WAAW,CAAA;QAEvD,OAAO,GAAG,CAAA;IACZ,CAAC,CAAC;CAC6C,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ import { ChatPromptTemplate } from '@langchain/core/prompts';
2
+ export declare const systemPrompt: ChatPromptTemplate<import("@langchain/core/prompts").ParamsFromFString<"\n You are an assistant that provides summaries of activities performed in a care flow for different stakeholders in a healthcare setting.\n A care flow consists of tracks, steps, and actions that can be performed by a patient, a clinician, or the system itself. These actions may include patient tasks (e.g., form submissions), clinician interventions (e.g., messages sent), or system-triggered activities (e.g., API calls).\n \n Your job is to provide a clear, human-readable summary of these activities in chronological order, ensuring the summary is tailored for the specific stakeholder. Focus on activity names and descriptions, avoiding any mention of IDs or technical details.\n \n Instructions for summarizing:\n - Summarize the care flow activities in the order they were performed, maintaining the chronological sequence.\n - Ensure the summary is concise, clear, and relevant to the stakeholder's needs.\n - Focus on activity names, titles, and the nature of the actions (e.g., patient submitted a form, clinician responded to a message).\n - Do not include any IDs, internal codes, or technical jargon—only human-readable information.\n - Tailor the summary to the specific stakeholder, emphasizing the information most relevant to their role.\n - Avoid making assumptions about actions not explicitly mentioned in the input.\n - Provide the summary as a set of bullet points unless otherwise specified in the instructions. Make it as concise as possible. \n \n Format:\n - Provide the summary as a set of bullet points unless otherwise specified in the instructions. Make it as concise as possible.\n - Format it as an easy-to-grasp timeline with all important values and information. \n - Always mention track, step, and action names if applicable unless otherwise specified in the additional instructions.\n - Never format it in markdown with bold, italic, etc., unless otherwise specified in the additional instructions.\n - Do not list usign words like next, finally, just list sumamries in bullet points, concisely.\n\n Additional Instructions:\n {additionalInstructions}\n\n Stakeholder:\n {stakeholder}\n\n Content to summarize:\n {input}\n ">, any>;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.systemPrompt = void 0;
4
+ const prompts_1 = require("@langchain/core/prompts");
5
+ // TODO: move prompt to LangSmith + further tune
6
+ exports.systemPrompt = prompts_1.ChatPromptTemplate.fromTemplate(`
7
+ You are an assistant that provides summaries of activities performed in a care flow for different stakeholders in a healthcare setting.
8
+ A care flow consists of tracks, steps, and actions that can be performed by a patient, a clinician, or the system itself. These actions may include patient tasks (e.g., form submissions), clinician interventions (e.g., messages sent), or system-triggered activities (e.g., API calls).
9
+
10
+ Your job is to provide a clear, human-readable summary of these activities in chronological order, ensuring the summary is tailored for the specific stakeholder. Focus on activity names and descriptions, avoiding any mention of IDs or technical details.
11
+
12
+ Instructions for summarizing:
13
+ - Summarize the care flow activities in the order they were performed, maintaining the chronological sequence.
14
+ - Ensure the summary is concise, clear, and relevant to the stakeholder's needs.
15
+ - Focus on activity names, titles, and the nature of the actions (e.g., patient submitted a form, clinician responded to a message).
16
+ - Do not include any IDs, internal codes, or technical jargon—only human-readable information.
17
+ - Tailor the summary to the specific stakeholder, emphasizing the information most relevant to their role.
18
+ - Avoid making assumptions about actions not explicitly mentioned in the input.
19
+ - Provide the summary as a set of bullet points unless otherwise specified in the instructions. Make it as concise as possible.
20
+
21
+ Format:
22
+ - Provide the summary as a set of bullet points unless otherwise specified in the instructions. Make it as concise as possible.
23
+ - Format it as an easy-to-grasp timeline with all important values and information.
24
+ - Always mention track, step, and action names if applicable unless otherwise specified in the additional instructions.
25
+ - Never format it in markdown with bold, italic, etc., unless otherwise specified in the additional instructions.
26
+ - Do not list usign words like next, finally, just list sumamries in bullet points, concisely.
27
+
28
+ Additional Instructions:
29
+ {additionalInstructions}
30
+
31
+ Stakeholder:
32
+ {stakeholder}
33
+
34
+ Content to summarize:
35
+ {input}
36
+ `);
37
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../../extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/constants.ts"],"names":[],"mappings":";;;AAAA,qDAA4D;AAE5D,gDAAgD;AACnC,QAAA,YAAY,GAAG,4BAAkB,CAAC,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BzD,CAAC,CAAA"}
@@ -0,0 +1 @@
1
+ export { summarizeCareFlowWithLLM } from './summarizeCareFlowWithLLM';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.summarizeCareFlowWithLLM = void 0;
4
+ var summarizeCareFlowWithLLM_1 = require("./summarizeCareFlowWithLLM");
5
+ Object.defineProperty(exports, "summarizeCareFlowWithLLM", { enumerable: true, get: function () { return summarizeCareFlowWithLLM_1.summarizeCareFlowWithLLM; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/index.ts"],"names":[],"mappings":";;;AAAA,uEAAqE;AAA5D,oIAAA,wBAAwB,OAAA"}
@@ -0,0 +1,7 @@
1
+ import { type ChatOpenAI } from '@langchain/openai';
2
+ export declare const summarizeCareFlowWithLLM: ({ ChatModelGPT4o, careFlowActivities, stakeholder, additionalInstructions, }: {
3
+ ChatModelGPT4o: ChatOpenAI;
4
+ careFlowActivities: string;
5
+ stakeholder: string;
6
+ additionalInstructions: string;
7
+ }) => Promise<string>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.summarizeCareFlowWithLLM = void 0;
4
+ const constants_1 = require("./constants");
5
+ // TODO: remove console logs eventually
6
+ const summarizeCareFlowWithLLM = async ({ ChatModelGPT4o, careFlowActivities, stakeholder, additionalInstructions, }) => {
7
+ const prompt = await constants_1.systemPrompt.format({
8
+ stakeholder,
9
+ additionalInstructions,
10
+ input: careFlowActivities,
11
+ });
12
+ console.log('Prompt', prompt);
13
+ const summaryMessage = await ChatModelGPT4o.invoke(prompt);
14
+ console.log('Type', typeof summaryMessage.content);
15
+ // TODO: for some reason compiler doesn't know that content is a string
16
+ const summary = summaryMessage.content;
17
+ console.log('Type', typeof summary);
18
+ console.log('Summary', summary);
19
+ return summary;
20
+ };
21
+ exports.summarizeCareFlowWithLLM = summarizeCareFlowWithLLM;
22
+ //# sourceMappingURL=summarizeCareFlowWithLLM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"summarizeCareFlowWithLLM.js","sourceRoot":"","sources":["../../../../../../../extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.ts"],"names":[],"mappings":";;;AAAA,2CAA0C;AAG1C,uCAAuC;AAChC,MAAM,wBAAwB,GAAG,KAAK,EAAE,EAC7C,cAAc,EACd,kBAAkB,EAClB,WAAW,EACX,sBAAsB,GAMvB,EAAmB,EAAE;IACpB,MAAM,MAAM,GAAG,MAAM,wBAAY,CAAC,MAAM,CAAC;QACvC,WAAW;QACX,sBAAsB;QACtB,KAAK,EAAE,kBAAkB;KAC1B,CAAC,CAAA;IACF,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;IAC7B,MAAM,cAAc,GAAG,MAAM,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAE1D,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,cAAc,CAAC,OAAO,CAAC,CAAA;IAClD,uEAAuE;IACvE,MAAM,OAAO,GAAG,cAAc,CAAC,OAAiB,CAAA;IAChD,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,OAAO,CAAC,CAAA;IACnC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IAC/B,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAzBY,QAAA,wBAAwB,4BAyBpC"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("dotenv/config");
4
+ const summarizeCareFlowWithLLM_1 = require("./summarizeCareFlowWithLLM");
5
+ const messages_1 = require("@langchain/core/messages");
6
+ const pathwayActivitiesResponse_1 = require("../../__mocks__/pathwayActivitiesResponse");
7
+ // Describe the test suite
8
+ describe('summarizeCareFlowWithLLM', () => {
9
+ let ChatModelGPT4oMock;
10
+ beforeEach(() => {
11
+ // Define the 'invoke' method in the mock
12
+ ChatModelGPT4oMock = {
13
+ invoke: jest.fn(),
14
+ };
15
+ });
16
+ it('should return a mocked summary for the care flow activities', async () => {
17
+ const mockedSummary = 'On September 11, 2024, a form was completed, followed by a step completion in the care flow. The clinician reviewed and performed several actions to proceed.';
18
+ // Mock the 'invoke' method to return an AIMessage
19
+ ChatModelGPT4oMock.invoke.mockResolvedValueOnce(new messages_1.AIMessageChunk(mockedSummary));
20
+ const careFlowData = pathwayActivitiesResponse_1.mockPathwayActivitiesResponse.activities
21
+ .map((activity) => {
22
+ var _a;
23
+ const { date, status, object, context } = activity;
24
+ return `Date: ${date}\nStatus: ${status}\nType: ${object.type}\nStep ID: ${(_a = context.step_id) !== null && _a !== void 0 ? _a : 'N/A'}`;
25
+ })
26
+ .join('\n\n');
27
+ const stakeholder = 'Clinician';
28
+ const additionalInstructions = 'Summarize the care flow activities, ensuring they are in chronological order.';
29
+ // Call the function with the mocked data
30
+ const summary = await (0, summarizeCareFlowWithLLM_1.summarizeCareFlowWithLLM)({
31
+ ChatModelGPT4o: ChatModelGPT4oMock,
32
+ careFlowActivities: careFlowData,
33
+ stakeholder,
34
+ additionalInstructions,
35
+ });
36
+ console.log('Summary', summary);
37
+ // Check that the returned summary is as expected
38
+ expect(summary).toBe(mockedSummary);
39
+ expect(ChatModelGPT4oMock.invoke).toHaveBeenCalledTimes(1);
40
+ });
41
+ });
42
+ //# sourceMappingURL=summarizeCareFlowWithLLM.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"summarizeCareFlowWithLLM.test.js","sourceRoot":"","sources":["../../../../../../../extensions/shelly/actions/summarizeCareFlow/lib/summarizeCare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AC,IAAI,CAAC,aAAa,CAAC,CAAA;QACnC,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAA;IAC5D,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -4,6 +4,8 @@ exports.summarizeCareFlow = void 0;
4
4
  const extensions_core_1 = require("@awell-health/extensions-core");
5
5
  const lib_1 = require("../../lib");
6
6
  const config_1 = require("./config");
7
+ const constants_1 = require("../../lib/constants");
8
+ const summarizeCareFlowWithLLM_1 = require("./lib/summarizeCareFlowWithLLM");
7
9
  exports.summarizeCareFlow = {
8
10
  key: 'summarizeCareFlow',
9
11
  category: extensions_core_1.Category.WORKFLOW,
@@ -13,13 +15,13 @@ exports.summarizeCareFlow = {
13
15
  previewable: false,
14
16
  dataPoints: config_1.dataPoints,
15
17
  onEvent: async ({ payload, onComplete, onError, helpers }) => {
16
- const { pathway } = await (0, lib_1.validatePayloadAndCreateSdk)({
18
+ const { ChatModelGPT4o, fields: { additionalInstructions, stakeholder }, pathway, } = await (0, lib_1.validatePayloadAndCreateSdk)({
17
19
  fieldsSchema: config_1.FieldsValidationSchema,
18
20
  payload,
19
21
  });
20
22
  const awellSdk = await helpers.awellSdk();
21
23
  /**
22
- * Limitation: this query is paginated so we might not get all pathway activities
24
+ * Limitation: this query is paginated so we might not get all pathway activities - which is ok for now
23
25
  */
24
26
  const pathwayActivitesUntilNow = await awellSdk.orchestration.query({
25
27
  pathwayActivities: {
@@ -54,14 +56,25 @@ exports.summarizeCareFlow = {
54
56
  },
55
57
  },
56
58
  });
57
- console.log(JSON.stringify(pathwayActivitesUntilNow.pathwayActivities.activities, null, 2));
58
- // Call OpenAI
59
- // const res = await langChainOpenAiSdk.invoke()
60
- await onComplete({
61
- data_points: {
62
- summary: 'Hello world',
63
- },
64
- });
59
+ try {
60
+ const summary = await (0, summarizeCareFlowWithLLM_1.summarizeCareFlowWithLLM)({
61
+ ChatModelGPT4o,
62
+ careFlowActivities: JSON.stringify(pathwayActivitesUntilNow.pathwayActivities.activities, null, 2),
63
+ stakeholder,
64
+ additionalInstructions,
65
+ });
66
+ const finalSummary = `${constants_1.DISCLAIMER_MSG}\n\n${summary}`;
67
+ console.log(finalSummary);
68
+ await onComplete({
69
+ data_points: {
70
+ summary: finalSummary,
71
+ },
72
+ });
73
+ }
74
+ catch (error) {
75
+ console.error('Error summarizing care flow:', error);
76
+ throw new Error('Error summarizing care flow');
77
+ }
65
78
  },
66
79
  };
67
80
  //# sourceMappingURL=summarizeCareFlow.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"summarizeCareFlow.js","sourceRoot":"","sources":["../../../../../extensions/shelly/actions/summarizeCareFlow/summarizeCareFlow.ts"],"names":[],"mappings":";;;AAAA,mEAAqE;AACrE,mCAAuD;AAEvD,qCAAqE;AAExD,QAAA,iBAAiB,GAI1B;IACF,GAAG,EAAE,mBAAmB;IACxB,QAAQ,EAAE,0BAAQ,CAAC,QAAQ;IAC3B,KAAK,EAAE,qBAAqB;IAC5B,WAAW,EAAE,sCAAsC;IACnD,MAAM,EAAN,eAAM;IACN,WAAW,EAAE,KAAK;IAClB,UAAU,EAAV,mBAAU;IACV,OAAO,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,EAAiB,EAAE;QAC1E,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,IAAA,iCAA2B,EAAC;YACpD,YAAY,EAAE,+BAAsB;YACpC,OAAO;SACR,CAAC,CAAA;QAEF,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAA;QAEzC;;WAEG;QACH,MAAM,wBAAwB,GAAG,MAAM,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC;YAClE,iBAAiB,EAAE;gBACjB,MAAM,EAAE;oBACN,UAAU,EAAE,OAAO,CAAC,EAAE;oBACtB,UAAU,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE;oBACrC,OAAO,EAAE;wBACP,SAAS,EAAE,MAAM;wBACjB,KAAK,EAAE,MAAM;qBACd;iBACF;gBACD,UAAU,EAAE;oBACV,QAAQ,EAAE,IAAI;oBACd,OAAO,EAAE;wBACP,QAAQ,EAAE,IAAI;qBACf;oBACD,MAAM,EAAE;wBACN,QAAQ,EAAE,IAAI;qBACf;oBACD,eAAe,EAAE;wBACf,QAAQ,EAAE,IAAI;qBACf;oBACD,OAAO,EAAE;wBACP,QAAQ,EAAE,IAAI;qBACf;oBACD,KAAK,EAAE;wBACL,QAAQ,EAAE,IAAI;qBACf;oBACD,cAAc,EAAE;wBACd,QAAQ,EAAE,IAAI;qBACf;iBACF;aACF;SACF,CAAC,CAAA;QAEF,OAAO,CAAC,GAAG,CACT,IAAI,CAAC,SAAS,CACZ,wBAAwB,CAAC,iBAAiB,CAAC,UAAU,EACrD,IAAI,EACJ,CAAC,CACF,CACF,CAAA;QAED,cAAc;QACd,gDAAgD;QAEhD,MAAM,UAAU,CAAC;YACf,WAAW,EAAE;gBACX,OAAO,EAAE,aAAa;aACvB;SACF,CAAC,CAAA;IACJ,CAAC;CACF,CAAA"}
1
+ {"version":3,"file":"summarizeCareFlow.js","sourceRoot":"","sources":["../../../../../extensions/shelly/actions/summarizeCareFlow/summarizeCareFlow.ts"],"names":[],"mappings":";;;AAAA,mEAAqE;AACrE,mCAAuD;AAEvD,qCAAqE;AACrE,mDAAoD;AACpD,6EAAyE;AAC5D,QAAA,iBAAiB,GAI1B;IACF,GAAG,EAAE,mBAAmB;IACxB,QAAQ,EAAE,0BAAQ,CAAC,QAAQ;IAC3B,KAAK,EAAE,qBAAqB;IAC5B,WAAW,EAAE,sCAAsC;IACnD,MAAM,EAAN,eAAM;IACN,WAAW,EAAE,KAAK;IAClB,UAAU,EAAV,mBAAU;IACV,OAAO,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,EAAiB,EAA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,GAAG,CAAC,YAAY,CAAC,CAAA;YAEzB,MAAM,UAAU,CAAC;gBACf,WAAW,EAAE;oBACX,OAAO,EAAE,YAAY;iBACtB;aACF,CAAC,CAAA;SACH;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAA;YACpD,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;SAC/C;IACH,CAAC;CACF,CAAA"}
@@ -4,45 +4,76 @@ const extensions_core_1 = require("@awell-health/extensions-core");
4
4
  const tests_1 = require("@/tests");
5
5
  const _1 = require(".");
6
6
  const pathwayActivitiesResponse_1 = require("./__mocks__/pathwayActivitiesResponse");
7
- describe('Shelly - Summarize care flow', () => {
8
- const { onComplete, onError, helpers, extensionAction, clearMocks } = extensions_core_1.TestHelpers.fromAction(_1.summarizeCareFlow);
9
- const awellSdkMock = {
10
- orchestration: {
11
- mutation: jest.fn().mockResolvedValue({}),
12
- query: jest.fn().mockResolvedValue({
13
- pathwayActivities: pathwayActivitiesResponse_1.mockPathwayActivitiesResponse,
14
- }),
15
- },
7
+ const constants_1 = require("../../lib/constants");
8
+ // Mock the '@langchain/openai' module
9
+ jest.mock('@langchain/openai', () => {
10
+ // Mock the 'invoke' method to return a resolved value
11
+ const mockInvoke = jest.fn().mockResolvedValue({
12
+ content: 'Mocked care flow summary from LLM',
13
+ });
14
+ // Mock the ChatOpenAI class
15
+ const mockChatOpenAI = jest.fn().mockImplementation(() => ({
16
+ invoke: mockInvoke,
17
+ }));
18
+ return {
19
+ ChatOpenAI: mockChatOpenAI,
16
20
  };
17
- helpers.awellSdk = jest.fn().mockResolvedValue(awellSdkMock);
21
+ });
22
+ // Import ChatOpenAI after mocking
23
+ const openai_1 = require("@langchain/openai");
24
+ describe('summarizeCareFlow - Mocked LLM calls', () => {
25
+ const { onComplete, onError, helpers, extensionAction, clearMocks } = extensions_core_1.TestHelpers.fromAction(_1.summarizeCareFlow);
18
26
  beforeEach(() => {
19
27
  clearMocks();
28
+ jest.clearAllMocks();
20
29
  });
21
- test('Should work', async () => {
30
+ it('Should summarize care flow with LLM', async () => {
31
+ // Spy on the 'summarizeCareFlowWithLLM' function
32
+ const summarizeCareFlowWithLLMSpy = jest.spyOn(require('./lib/summarizeCareFlowWithLLM'), 'summarizeCareFlowWithLLM');
33
+ // Create the test payload
34
+ const payload = (0, tests_1.generateTestPayload)({
35
+ pathway: {
36
+ id: 'ai4rZaYEocjB',
37
+ definition_id: 'whatever',
38
+ },
39
+ fields: {
40
+ stakeholder: 'Clinician',
41
+ additionalInstructions: 'Summarize key activities.',
42
+ },
43
+ settings: {
44
+ openAiApiKey: 'a',
45
+ },
46
+ });
47
+ // Mock the Awell SDK
48
+ const awellSdkMock = {
49
+ orchestration: {
50
+ query: jest.fn().mockResolvedValue({
51
+ pathwayActivities: pathwayActivitiesResponse_1.mockPathwayActivitiesResponse,
52
+ }),
53
+ },
54
+ };
55
+ helpers.awellSdk = jest.fn().mockResolvedValue(awellSdkMock);
56
+ // Execute the action
22
57
  await extensionAction.onEvent({
23
- payload: (0, tests_1.generateTestPayload)({
24
- pathway: {
25
- id: 'whatever',
26
- },
27
- fields: {
28
- prompt: '',
29
- },
30
- settings: {
31
- openAiApiKey: 'a',
32
- },
33
- }),
58
+ payload,
34
59
  onComplete,
35
60
  onError,
36
61
  helpers,
37
62
  });
38
- expect(helpers.awellSdk).toHaveBeenCalledTimes(1);
39
- expect(awellSdkMock.orchestration.query).toHaveBeenCalledTimes(1);
40
- expect(onError).not.toHaveBeenCalled();
63
+ // Assertions
64
+ expect(openai_1.ChatOpenAI).toHaveBeenCalled();
65
+ expect(summarizeCareFlowWithLLMSpy).toHaveBeenCalledWith({
66
+ ChatModelGPT4o: expect.any(Object),
67
+ careFlowActivities: expect.any(String),
68
+ stakeholder: 'Clinician',
69
+ additionalInstructions: 'Summarize key activities.',
70
+ });
41
71
  expect(onComplete).toHaveBeenCalledWith({
42
72
  data_points: {
43
- summary: 'Hello world',
73
+ summary: `${constants_1.DISCLAIMER_MSG}\n\n${'Mocked care flow summary from LLM'}`,
44
74
  },
45
75
  });
76
+ expect(onError).not.toHaveBeenCalled();
46
77
  });
47
78
  });
48
79
  //# sourceMappingURL=summarizeCareFlow.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"summarizeCareFlow.test.js","sourceRoot":"","sources":["../../../../../extensions/shelly/actions/summarizeCareFlow/summarizeCareFlow.test.ts"],"names":[],"mappings":";;AAAA,mEAA2D;AAC3D,mCAA6C;AAC7C,wBAAqC;AACrC,qFAAqF;AAErF,QAAQ,CAAC,8BAA8B,EAAE,GAAG,EAAE;IAC5C,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,GACjE,6BAAW,CAAC,UAAU,CAAC,oBAAiB,CAAC,CAAA;IAE3C,MAAM,YAAY,GAAG;QACnB,aAAa,EAAE;YACb,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,EAAE,CAAC;YACzC,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC;gBACjC,iBAAiB,EAAE,yDAA6B;aACjD,CAAC;SACH;KACF,CAAA;IAED,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAA;IAE5D,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,EAAE,CAAA;IACd,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,aAAa,EAAE,KAAK,IAAI,EAAE;QAC7B,MAAM,eAAe,CAAC,OAAO,CAAC;YAC5B,OAAO,EAAE,IAAA,2BAAmB,EAAC;gBAC3B,OAAO,EAAE;oBACP,EAAE,EAAE,UAAU;iBACf;gBACD,MAAM,EAAE;oBACN,MAAM,EAAE,EAAE;iBACX;gBACD,QAAQ,EAAE;oBACR,YAAY,EAAE,GAAG;iBAClB;aACF,CAAC;YACF,UAAU;YACV,OAAO;YACP,OAAO;SACR,CAAC,CAAA;QAEF,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAA;QACjD,MAAM,CAAC,YAAY,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAA;QAEjE,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAA;QACtC,MAAM,CAAC,UAAU,CAAC,CAAC,oBAAoB,CAAC;YACtC,WAAW,EAAE;gBACX,OAAO,EAAE,aAAa;aACvB;SACF,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
1
+ {"version":3,"file":"summarizeCareFlow.test.js","sourceRoot":"","sources":["../../../../../extensions/shelly/actions/summarizeCareFlow/summarizeCareFlow.test.ts"],"names":[],"mappings":";;AAAA,mEAA2D;AAC3D,mCAA6C;AAC7C,wBAAqC;AACrC,qFAAqF;AACrF,mDAAoD;AAEpD,sCAAsC;AACtC,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,GAAG,EAAE;IAClC,sDAAsD;IACtD,MAAM,UAAU,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC;QAC7C,OAAO,EAAE,mCAAmC;KAC7C,CAAC,CAAA;IAEF,4BAA4B;IAC5B,MAAM,cAAc,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,GAAG,EAAE,CAAC,CAAC;QACzD,MAAM,EAAE,UAAU;KACnB,CAAC,CAAC,CAAA;IAEH,OAAO;QACL,UAAU,EAAE,cAAc;KAC3B,CAAA;AACH,CAAC,CAAC,CAAA;AAEF,kCAAkC;AAClC,8CAA8C;AAE9C,QAAQ,CAAC,sCAAsC,EAAE,GAAG,EAAE;IACpD,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,GACj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