@awell-health/awell-extensions 2.0.152 → 2.0.154
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/findAppointmentsByPrompt.js +33 -113
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/findAppointmentsByPrompt.js.map +1 -1
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/getAppoitnmentCountByStatus.d.ts +2 -0
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/getAppoitnmentCountByStatus.js +15 -0
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/getAppoitnmentCountByStatus.js.map +1 -0
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/lib/findAppointmentsByPromptWithLLM/findAppointmentsByPromptWithLLM.d.ts +14 -0
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/lib/findAppointmentsByPromptWithLLM/findAppointmentsByPromptWithLLM.js +36 -0
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/lib/findAppointmentsByPromptWithLLM/findAppointmentsByPromptWithLLM.js.map +1 -0
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/lib/findAppointmentsByPromptWithLLM/parser.d.ts +17 -0
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/lib/findAppointmentsByPromptWithLLM/parser.js +14 -0
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/lib/findAppointmentsByPromptWithLLM/parser.js.map +1 -0
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/lib/findAppointmentsByPromptWithLLM/prompt.d.ts +2 -0
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/lib/findAppointmentsByPromptWithLLM/prompt.js +24 -0
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/lib/findAppointmentsByPromptWithLLM/prompt.js.map +1 -0
- package/dist/extensions/elation/actions/findFutureAppointment/findFutureAppointment.d.ts +1 -1
- package/dist/extensions/elation/actions/findFutureAppointment/findFutureAppointment.js +32 -90
- package/dist/extensions/elation/actions/findFutureAppointment/findFutureAppointment.js.map +1 -1
- package/dist/extensions/elation/actions/findFutureAppointment/formatAppointments.d.ts +2 -0
- package/dist/extensions/elation/actions/findFutureAppointment/formatAppointments.js +18 -0
- package/dist/extensions/elation/actions/findFutureAppointment/formatAppointments.js.map +1 -0
- package/dist/extensions/elation/actions/findFutureAppointment/getFutureAppoitnments.d.ts +3 -0
- package/dist/extensions/elation/actions/findFutureAppointment/getFutureAppoitnments.js +15 -0
- package/dist/extensions/elation/actions/findFutureAppointment/getFutureAppoitnments.js.map +1 -0
- package/dist/extensions/elation/actions/findFutureAppointment/lib/findAppointmentWithLLM/findAppointmentWithLLM.d.ts +14 -0
- package/dist/extensions/elation/actions/findFutureAppointment/lib/findAppointmentWithLLM/findAppointmentWithLLM.js +29 -0
- package/dist/extensions/elation/actions/findFutureAppointment/lib/findAppointmentWithLLM/findAppointmentWithLLM.js.map +1 -0
- package/dist/extensions/elation/actions/findFutureAppointment/lib/findAppointmentWithLLM/parser.d.ts +17 -0
- package/dist/extensions/elation/actions/findFutureAppointment/lib/findAppointmentWithLLM/parser.js +16 -0
- package/dist/extensions/elation/actions/findFutureAppointment/lib/findAppointmentWithLLM/parser.js.map +1 -0
- package/dist/extensions/elation/actions/findFutureAppointment/lib/findAppointmentWithLLM/prompt.d.ts +2 -0
- package/dist/extensions/elation/actions/findFutureAppointment/lib/findAppointmentWithLLM/prompt.js +20 -0
- package/dist/extensions/elation/actions/findFutureAppointment/lib/findAppointmentWithLLM/prompt.js.map +1 -0
- package/dist/extensions/elation/actions/index.d.ts +0 -210
- package/dist/extensions/elation/actions/updatePatientTags/config/types.d.ts +29 -0
- package/dist/extensions/elation/actions/updatePatientTags/config/types.js +21 -0
- package/dist/extensions/elation/actions/updatePatientTags/config/types.js.map +1 -0
- package/dist/extensions/elation/actions/updatePatientTags/lib/getTagsFromLLM/getTagsFromLLM.d.ts +13 -0
- package/dist/extensions/elation/actions/updatePatientTags/lib/getTagsFromLLM/getTagsFromLLM.js +29 -0
- package/dist/extensions/elation/actions/updatePatientTags/lib/getTagsFromLLM/getTagsFromLLM.js.map +1 -0
- package/dist/extensions/elation/actions/updatePatientTags/lib/getTagsFromLLM/parser.d.ts +13 -0
- package/dist/extensions/elation/actions/updatePatientTags/lib/getTagsFromLLM/parser.js +7 -0
- package/dist/extensions/elation/actions/updatePatientTags/lib/getTagsFromLLM/parser.js.map +1 -0
- package/dist/extensions/elation/actions/updatePatientTags/lib/getTagsFromLLM/prompt.d.ts +2 -0
- package/dist/extensions/elation/actions/updatePatientTags/lib/getTagsFromLLM/prompt.js +22 -0
- package/dist/extensions/elation/actions/updatePatientTags/lib/getTagsFromLLM/prompt.js.map +1 -0
- package/dist/extensions/elation/actions/updatePatientTags/updatePatientTags.d.ts +8 -0
- package/dist/extensions/elation/actions/updatePatientTags/updatePatientTags.js +35 -77
- package/dist/extensions/elation/actions/updatePatientTags/updatePatientTags.js.map +1 -1
- package/dist/extensions/elation/actions/updatePatientTags/updateTags.d.ts +2 -0
- package/dist/extensions/elation/actions/updatePatientTags/updateTags.js +18 -0
- package/dist/extensions/elation/actions/updatePatientTags/updateTags.js.map +1 -0
- package/dist/extensions/elation/settings.d.ts +1 -10
- package/dist/extensions/elation/settings.js +0 -8
- package/dist/extensions/elation/settings.js.map +1 -1
- package/dist/extensions/shelly/actions/categorizeMessage/categorizeMessage.d.ts +10 -2
- package/dist/extensions/shelly/actions/categorizeMessage/categorizeMessage.js +32 -24
- package/dist/extensions/shelly/actions/categorizeMessage/categorizeMessage.js.map +1 -1
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.d.ts +22 -2
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.js +22 -7
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.js.map +1 -1
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/parser.d.ts +20 -0
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/parser.js +18 -0
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/parser.js.map +1 -0
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/prompt.d.ts +13 -0
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/prompt.js +35 -0
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/prompt.js.map +1 -0
- package/dist/extensions/shelly/actions/generateMessage/generateMessage.d.ts +10 -2
- package/dist/extensions/shelly/actions/generateMessage/generateMessage.js +33 -25
- package/dist/extensions/shelly/actions/generateMessage/generateMessage.js.map +1 -1
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/generateMessageWithLLM.d.ts +18 -2
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/generateMessageWithLLM.js +23 -10
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/generateMessageWithLLM.js.map +1 -1
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/parser.d.ts +28 -0
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/parser.js +17 -0
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/parser.js.map +1 -0
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/prompt.d.ts +10 -0
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/prompt.js +121 -0
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/prompt.js.map +1 -0
- package/dist/extensions/shelly/actions/index.d.ts +7 -63
- package/dist/extensions/shelly/actions/medicationFromImage/medicationFromImage.d.ts +1 -2
- package/dist/extensions/shelly/actions/medicationFromImage/medicationFromImage.js.map +1 -1
- package/dist/extensions/shelly/actions/reviewMedicationExtraction/reviewMedicationExtraction.d.ts +1 -2
- package/dist/extensions/shelly/actions/reviewMedicationExtraction/reviewMedicationExtraction.js.map +1 -1
- package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/{constants.js → prompt.js} +1 -1
- package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/prompt.js.map +1 -0
- package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.d.ts +22 -2
- package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.js +30 -8
- package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.js.map +1 -1
- package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlow.d.ts +1 -2
- package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlow.js +24 -21
- package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlow.js.map +1 -1
- package/dist/extensions/shelly/actions/summarizeForm/summarizeForm.d.ts +10 -2
- package/dist/extensions/shelly/actions/summarizeForm/summarizeForm.js +42 -28
- package/dist/extensions/shelly/actions/summarizeForm/summarizeForm.js.map +1 -1
- package/dist/extensions/shelly/actions/summarizeFormsInStep/summarizeFormsInStep.d.ts +1 -2
- package/dist/extensions/shelly/actions/summarizeFormsInStep/summarizeFormsInStep.js +29 -26
- package/dist/extensions/shelly/actions/summarizeFormsInStep/summarizeFormsInStep.js.map +1 -1
- package/dist/extensions/shelly/index.js +2 -3
- package/dist/extensions/shelly/index.js.map +1 -1
- package/dist/extensions/shelly/lib/summarizeFormWithLLM/{constants.js → prompt.js} +1 -1
- package/dist/extensions/shelly/lib/summarizeFormWithLLM/prompt.js.map +1 -0
- package/dist/extensions/shelly/lib/summarizeFormWithLLM/summarizeFormWithLLM.d.ts +23 -2
- package/dist/extensions/shelly/lib/summarizeFormWithLLM/summarizeFormWithLLM.js +33 -9
- package/dist/extensions/shelly/lib/summarizeFormWithLLM/summarizeFormWithLLM.js.map +1 -1
- package/dist/extensions/shelly/lib/validatePayloadAndCreateSdk.d.ts +1 -5
- package/dist/extensions/shelly/lib/validatePayloadAndCreateSdk.js +5 -20
- package/dist/extensions/shelly/lib/validatePayloadAndCreateSdk.js.map +1 -1
- package/dist/src/lib/llm/openai/constants.d.ts +28 -0
- package/dist/src/lib/llm/openai/constants.js +32 -0
- package/dist/src/lib/llm/openai/constants.js.map +1 -0
- package/dist/src/lib/llm/openai/createOpenAIModel.d.ts +23 -0
- package/dist/src/lib/llm/openai/createOpenAIModel.js +89 -0
- package/dist/src/lib/llm/openai/createOpenAIModel.js.map +1 -0
- package/dist/src/lib/llm/openai/index.d.ts +3 -0
- package/dist/src/lib/llm/openai/index.js +20 -0
- package/dist/src/lib/llm/openai/index.js.map +1 -0
- package/dist/src/lib/llm/openai/types.d.ts +63 -0
- package/dist/src/lib/llm/openai/types.js +3 -0
- package/dist/src/lib/llm/openai/types.js.map +1 -0
- package/package.json +5 -4
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/constants.d.ts +0 -24
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/constants.js +0 -33
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/constants.js.map +0 -1
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/constants.d.ts +0 -24
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/constants.js +0 -123
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/constants.js.map +0 -1
- package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/constants.js.map +0 -1
- package/dist/extensions/shelly/lib/summarizeFormWithLLM/constants.js.map +0 -1
- package/dist/extensions/shelly/settings.d.ts +0 -17
- package/dist/extensions/shelly/settings.js +0 -17
- package/dist/extensions/shelly/settings.js.map +0 -1
- /package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/{constants.d.ts → prompt.d.ts} +0 -0
- /package/dist/extensions/shelly/lib/summarizeFormWithLLM/{constants.d.ts → prompt.d.ts} +0 -0
package/dist/extensions/elation/actions/findAppointmentsByPrompt/findAppointmentsByPrompt.js
CHANGED
@@ -1,42 +1,25 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.findAppointmentsByPrompt = void 0;
|
4
|
+
const lodash_1 = require("lodash");
|
4
5
|
const extensions_core_1 = require("@awell-health/extensions-core");
|
6
|
+
const addEventLog_1 = require("../../../../src/lib/awell/addEventLog");
|
5
7
|
const client_1 = require("../../client");
|
8
|
+
const createOpenAIModel_1 = require("../../../../src/lib/llm/openai/createOpenAIModel");
|
6
9
|
const config_1 = require("./config");
|
7
|
-
const
|
8
|
-
const
|
9
|
-
const openai_1 = require("@langchain/openai");
|
10
|
-
const addEventLog_1 = require("../../../../src/lib/awell/addEventLog");
|
11
|
-
const appointment_zod_1 = require("../../validation/appointment.zod");
|
12
|
-
const lodash_1 = require("lodash");
|
10
|
+
const getAppoitnmentCountByStatus_1 = require("./getAppoitnmentCountByStatus");
|
11
|
+
const findAppointmentsByPromptWithLLM_1 = require("./lib/findAppointmentsByPromptWithLLM/findAppointmentsByPromptWithLLM");
|
13
12
|
exports.findAppointmentsByPrompt = {
|
14
13
|
key: 'findAppointmentsByPrompt',
|
15
14
|
category: extensions_core_1.Category.EHR_INTEGRATIONS,
|
16
|
-
title: '🪄 Find Appointments by Prompt',
|
15
|
+
title: '🪄 Find Appointments by Prompt (Beta)',
|
17
16
|
description: 'Find all appointments for a patient using natural language.',
|
18
17
|
fields: config_1.fields,
|
19
18
|
previewable: false,
|
20
19
|
dataPoints: config_1.dataPoints,
|
21
|
-
onEvent: async ({ payload, onComplete, onError }) => {
|
20
|
+
onEvent: async ({ payload, onComplete, onError, helpers }) => {
|
22
21
|
const { prompt, patientId } = config_1.FieldsValidationSchema.parse(payload.fields);
|
23
22
|
const api = (0, client_1.makeAPIClient)(payload.settings);
|
24
|
-
const openAiApiKey = payload.settings.openAiApiKey;
|
25
|
-
if (openAiApiKey === undefined || openAiApiKey === '') {
|
26
|
-
await onError({
|
27
|
-
events: [
|
28
|
-
{
|
29
|
-
date: new Date().toISOString(),
|
30
|
-
text: { en: 'OpenAI API key is required for this action.' },
|
31
|
-
error: {
|
32
|
-
category: 'SERVER_ERROR',
|
33
|
-
message: 'OpenAI API key is required for this action.',
|
34
|
-
},
|
35
|
-
},
|
36
|
-
],
|
37
|
-
});
|
38
|
-
return;
|
39
|
-
}
|
40
23
|
const appointments = await api.findAppointments({
|
41
24
|
patient: patientId,
|
42
25
|
});
|
@@ -44,117 +27,54 @@ exports.findAppointmentsByPrompt = {
|
|
44
27
|
await onComplete({
|
45
28
|
data_points: {
|
46
29
|
explanation: 'No appointments found',
|
47
|
-
appointments: JSON.stringify(
|
30
|
+
appointments: JSON.stringify([]),
|
48
31
|
appointmentCountsByStatus: JSON.stringify({}),
|
49
32
|
},
|
50
33
|
});
|
51
34
|
return;
|
52
35
|
}
|
53
|
-
const promptAppointments = appointments
|
54
|
-
.map((appointment) => {
|
55
|
-
const relevantInfo = {
|
56
|
-
id: appointment.id,
|
57
|
-
reason: appointment.reason,
|
58
|
-
scheduled_date: appointment.scheduled_date,
|
59
|
-
};
|
60
|
-
return JSON.stringify(relevantInfo);
|
61
|
-
})
|
62
|
-
.join('\n\n');
|
63
|
-
const ChatModelGPT4o = new openai_1.ChatOpenAI({
|
64
|
-
modelName: 'gpt-4o',
|
65
|
-
openAIApiKey: openAiApiKey,
|
66
|
-
temperature: 0,
|
67
|
-
maxRetries: 3,
|
68
|
-
timeout: 10000,
|
69
|
-
});
|
70
|
-
const systemPrompt = createSystemPrompt({
|
71
|
-
prompt,
|
72
|
-
appointments: promptAppointments,
|
73
|
-
});
|
74
|
-
const AppointmentIdSchema = zod_1.z.array(zod_1.z.string());
|
75
|
-
const parser = output_parsers_1.StructuredOutputParser.fromZodSchema(zod_1.z.object({
|
76
|
-
appointmentIds: AppointmentIdSchema,
|
77
|
-
explanation: zod_1.z
|
78
|
-
.string()
|
79
|
-
.describe('A readable explanation of how the appointments were found and why'),
|
80
|
-
}));
|
81
|
-
let result;
|
82
36
|
try {
|
83
|
-
const
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
37
|
+
const { model, metadata, callbacks } = await (0, createOpenAIModel_1.createOpenAIModel)({
|
38
|
+
settings: payload.settings,
|
39
|
+
helpers,
|
40
|
+
payload,
|
41
|
+
});
|
42
|
+
const { appointmentIds, explanation } = await (0, findAppointmentsByPromptWithLLM_1.findAppointmentsByPromptWithLLM)({
|
43
|
+
model,
|
44
|
+
appointments,
|
45
|
+
prompt,
|
46
|
+
metadata,
|
47
|
+
callbacks
|
48
|
+
});
|
49
|
+
const selectedAppointments = appointments.filter((appointment) => appointmentIds.includes(appointment.id));
|
50
|
+
const appointmentCountsByStatus = (0, getAppoitnmentCountByStatus_1.getAppointmentCountsByStatus)(selectedAppointments);
|
93
51
|
await onComplete({
|
94
52
|
data_points: {
|
95
|
-
|
53
|
+
appointments: JSON.stringify(selectedAppointments),
|
54
|
+
explanation,
|
55
|
+
appointmentCountsByStatus: JSON.stringify(appointmentCountsByStatus),
|
96
56
|
},
|
57
|
+
events: [
|
58
|
+
(0, addEventLog_1.addActivityEventLog)({
|
59
|
+
message: `Found ${selectedAppointments.length} appointments for patient ${patientId}`
|
60
|
+
}),
|
61
|
+
],
|
97
62
|
});
|
98
|
-
return;
|
99
63
|
}
|
100
|
-
|
101
|
-
console.log('Some appointments were not found');
|
102
|
-
const errorMessage = `Some appointments were not found. Found ${selectedAppointments.length} appointments, but the prompt resulted in ${result.appointmentIds.length} appointments.`;
|
64
|
+
catch (error) {
|
103
65
|
await onError({
|
104
66
|
events: [
|
105
67
|
{
|
106
68
|
date: new Date().toISOString(),
|
107
|
-
text: { en:
|
69
|
+
text: { en: 'Failed to find appointments' },
|
108
70
|
error: {
|
109
71
|
category: 'SERVER_ERROR',
|
110
|
-
message:
|
72
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
111
73
|
},
|
112
74
|
},
|
113
75
|
],
|
114
76
|
});
|
115
|
-
return;
|
116
77
|
}
|
117
|
-
const appointmentCountsByStatus = Object.values(appointment_zod_1.statusEnum.Values).reduce((acc, status) => {
|
118
|
-
const cnt = selectedAppointments.filter((appointment) => (appointment === null || appointment === void 0 ? void 0 : appointment.status.status) === status).length;
|
119
|
-
if (cnt > 0) {
|
120
|
-
acc[status] = cnt;
|
121
|
-
}
|
122
|
-
return acc;
|
123
|
-
}, {});
|
124
|
-
await onComplete({
|
125
|
-
data_points: {
|
126
|
-
appointments: JSON.stringify(selectedAppointments),
|
127
|
-
explanation: result.explanation,
|
128
|
-
appointmentCountsByStatus: JSON.stringify(appointmentCountsByStatus),
|
129
|
-
},
|
130
|
-
events: [
|
131
|
-
(0, addEventLog_1.addActivityEventLog)({
|
132
|
-
message: `Found ${selectedAppointments.length} appointments for patient ${patientId}\nExplanation: ${result.explanation}\nAppointment counts by status: ${JSON.stringify(appointmentCountsByStatus)}`,
|
133
|
-
}),
|
134
|
-
],
|
135
|
-
});
|
136
78
|
},
|
137
79
|
};
|
138
|
-
const createSystemPrompt = ({ prompt, appointments, }) => {
|
139
|
-
const currentDate = new Date().getDate();
|
140
|
-
return `You are a helpful medical assistant. You will receive a list (array) of appointments for a single patient and instructions about which types of appointments to find. You're supposed to use the information in the list to find appointments that match, if any exist. If no appointments exists that obviously match the instructions, that's a perfectly acceptable outcome. If multiple appointments exist that match the instructions, you should return all of them.
|
141
|
-
|
142
|
-
Important instructions:
|
143
|
-
- The appointment "reason" is the appointment type.
|
144
|
-
- Only include appointment ids that exist in the input array. If no appointments exist that match the instructions, return an empty array.
|
145
|
-
- Pay close attention to the instructions. They are intended to have been written by a clinician, for a clinician.
|
146
|
-
- Think like a clinician. In other words, "Rx" should match a prescription appointment or follow-up related to a prescription, and "PT" would matchphysical therapy.
|
147
|
-
- The current date is ${currentDate}.
|
148
|
-
----------
|
149
|
-
Input array:
|
150
|
-
${appointments}
|
151
|
-
----------
|
152
|
-
Instruction:
|
153
|
-
${prompt}
|
154
|
-
----------
|
155
|
-
|
156
|
-
Output a JSON object with the following keys:
|
157
|
-
1. appointmentIds: array of strings where each string is an appointment_id that matches the instructions (or an empty array if no appointments exist that match the instructions).
|
158
|
-
2. explanation: A readable explanation of how the appointments were found and why. Or, if no appointments exist that match the instructions, an explanation of why.`;
|
159
|
-
};
|
160
80
|
//# sourceMappingURL=findAppointmentsByPrompt.js.map
|
package/dist/extensions/elation/actions/findAppointmentsByPrompt/findAppointmentsByPrompt.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"findAppointmentsByPrompt.js","sourceRoot":"","sources":["../../../../../extensions/elation/actions/findAppointmentsByPrompt/findAppointmentsByPrompt.ts"],"names":[],"mappings":";;;AAAA,
|
1
|
+
{"version":3,"file":"findAppointmentsByPrompt.js","sourceRoot":"","sources":["../../../../../extensions/elation/actions/findAppointmentsByPrompt/findAppointmentsByPrompt.ts"],"names":[],"mappings":";;;AAAA,mCAA8B;AAC9B,mEAAqE;AACrE,uEAA2E;AAE3E,yCAA4C;AAC5C,wFAAoF;AACpF,qCAAqE;AACrE,+EAA4E;AAC5E,2HAAuH;AAE1G,QAAA,wBAAwB,GAIjC;IACF,GAAG,EAAE,0BAA0B;IAC/B,QAAQ,EAAE,0BAAQ,CAAC,gBAAgB;IACnC,KAAK,EAAE,uCAAuC;IAC9C,WAAW,EAAE,6DAA6D;IAC1E,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,MAAM,EAAE,SAAS,EAAE,GAAG,+BAAsB,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAC1E,MAAM,GAAG,GAAG,IAAA,sBAAa,EAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;QAE3C,MAAM,YAAY,GAAG,MAAM,GAAG,CAAC,gBAAgB,CAAC;YAC9C,OAAO,EAAE,SAAS;SACnB,CAAC,CAAA;QAEF,IAAI,IAAA,cAAK,EAAC,YAAY,CAAC,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACrD,MAAM,UAAU,CAAC;gBACf,WAAW,EAAE;oBACX,WAAW,EAAE,uBAAuB;oBACpC,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;oBAChC,yBAAyB,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;iBAC9C;aACF,CAAC,CAAA;YACF,OAAM;QACR,CAAC;QAED,IAAI,CAAC;YACH,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,MAAM,IAAA,qCAAiB,EAAC;gBAC7D,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,OAAO;gBACP,OAAO;aACR,CAAC,CAAA;YAEF,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,GAAG,MAAM,IAAA,iEAA+B,EAAC;gBAC5E,KAAK;gBACL,YAAY;gBACZ,MAAM;gBACN,QAAQ;gBACR,SAAS;aACV,CAAC,CAAA;YAEF,MAAM,oBAAoB,GAAG,YAAY,CAAC,MAAM,CAC9C,CAAC,WAAW,EAAE,EAAE,CAAC,cAAc,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,CACzD,CAAA;YAED,MAAM,yBAAyB,GAAG,IAAA,0DAA4B,EAAC,oBAAoB,CAAC,CAAA;YAEpF,MAAM,UAAU,CAAC;gBACf,WAAW,EAAE;oBACX,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC;oBAClD,WAAW;oBACX,yBAAyB,EAAE,IAAI,CAAC,SAAS,CAAC,yBAAyB,CAAC;iBACrE;gBACD,MAAM,EAAE;oBACN,IAAA,iCAAmB,EAAC;wBAClB,OAAO,EAAE,SAAS,oBAAoB,CAAC,MAAM,6BAA6B,SAAS,EAAE;qBACtF,CAAC;iBACH;aACF,CAAC,CAAA;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,OAAO,CAAC;gBACZ,MAAM,EAAE;oBACN;wBACE,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;wBAC9B,IAAI,EAAE,EAAE,EAAE,EAAE,6BAA6B,EAAE;wBAC3C,KAAK,EAAE;4BACL,QAAQ,EAAE,cAAc;4BACxB,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;yBAClE;qBACF;iBACF;aACF,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF,CAAA"}
|
package/dist/extensions/elation/actions/findAppointmentsByPrompt/getAppoitnmentCountByStatus.js
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getAppointmentCountsByStatus = void 0;
|
4
|
+
const appointment_zod_1 = require("../../validation/appointment.zod");
|
5
|
+
const getAppointmentCountsByStatus = (appointments) => {
|
6
|
+
return Object.values(appointment_zod_1.statusEnum.Values).reduce((acc, status) => {
|
7
|
+
const cnt = appointments.filter((appointment) => (appointment === null || appointment === void 0 ? void 0 : appointment.status.status) === status).length;
|
8
|
+
if (cnt > 0) {
|
9
|
+
acc[status] = cnt;
|
10
|
+
}
|
11
|
+
return acc;
|
12
|
+
}, {});
|
13
|
+
};
|
14
|
+
exports.getAppointmentCountsByStatus = getAppointmentCountsByStatus;
|
15
|
+
//# sourceMappingURL=getAppoitnmentCountByStatus.js.map
|
package/dist/extensions/elation/actions/findAppointmentsByPrompt/getAppoitnmentCountByStatus.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"getAppoitnmentCountByStatus.js","sourceRoot":"","sources":["../../../../../extensions/elation/actions/findAppointmentsByPrompt/getAppoitnmentCountByStatus.ts"],"names":[],"mappings":";;;AAGA,sEAA6D;AAEtD,MAAM,4BAA4B,GAAG,CACxC,YAAmC,EACX,EAAE;IAC1B,OAAO,MAAM,CAAC,MAAM,CAAC,4BAAU,CAAC,MAAM,CAAC,CAAC,MAAM,CAAyB,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;QACrF,MAAM,GAAG,GAAG,YAAY,CAAC,MAAM,CAC7B,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,MAAM,CAAC,MAAM,MAAK,MAAM,CACvD,CAAC,MAAM,CAAA;QACR,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;YACZ,GAAG,CAAC,MAAM,CAAC,GAAG,GAAG,CAAA;QACnB,CAAC;QACD,OAAO,GAAG,CAAA;IACZ,CAAC,EAAE,EAAE,CAAC,CAAA;AACR,CAAC,CAAA;AAZU,QAAA,4BAA4B,gCAYtC"}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { type ChatOpenAI } from '@langchain/openai';
|
2
|
+
import { type AIActionMetadata } from '../../../../../../src/lib/llm/openai/types';
|
3
|
+
import type { BaseCallbackHandler } from "@langchain/core/callbacks/base";
|
4
|
+
import { type AppointmentsFromAI } from './parser';
|
5
|
+
import { type AppointmentResponse } from '../../../../types';
|
6
|
+
interface FindAppointmentsByPromptWithLLMProps {
|
7
|
+
model: ChatOpenAI;
|
8
|
+
appointments: AppointmentResponse[];
|
9
|
+
prompt: string;
|
10
|
+
metadata: AIActionMetadata;
|
11
|
+
callbacks?: BaseCallbackHandler[];
|
12
|
+
}
|
13
|
+
export declare const findAppointmentsByPromptWithLLM: ({ model, appointments, prompt, metadata, callbacks, }: FindAppointmentsByPromptWithLLMProps) => Promise<AppointmentsFromAI>;
|
14
|
+
export {};
|
@@ -0,0 +1,36 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.findAppointmentsByPromptWithLLM = void 0;
|
4
|
+
const prompt_1 = require("./prompt");
|
5
|
+
const parser_1 = require("./parser");
|
6
|
+
const findAppointmentsByPromptWithLLM = async ({ model, appointments, prompt, metadata, callbacks, }) => {
|
7
|
+
const chain = model.pipe(parser_1.parser);
|
8
|
+
try {
|
9
|
+
const formattedAppointments = appointments
|
10
|
+
.map((appointment) => ({
|
11
|
+
id: appointment.id,
|
12
|
+
reason: appointment.reason,
|
13
|
+
scheduled_date: appointment.scheduled_date,
|
14
|
+
}))
|
15
|
+
.map((appointment) => JSON.stringify(appointment))
|
16
|
+
.join('\n\n');
|
17
|
+
const result = await chain.invoke(await prompt_1.systemPrompt.format({
|
18
|
+
currentDate: new Date().toISOString().split('T')[0],
|
19
|
+
appointments: formattedAppointments,
|
20
|
+
prompt,
|
21
|
+
}), {
|
22
|
+
metadata,
|
23
|
+
runName: 'ElationFindAppointmentsByPrompt',
|
24
|
+
callbacks
|
25
|
+
});
|
26
|
+
return {
|
27
|
+
appointmentIds: result.appointmentIds,
|
28
|
+
explanation: result.explanation
|
29
|
+
};
|
30
|
+
}
|
31
|
+
catch (error) {
|
32
|
+
throw new Error('Failed to find matching appointments.');
|
33
|
+
}
|
34
|
+
};
|
35
|
+
exports.findAppointmentsByPromptWithLLM = findAppointmentsByPromptWithLLM;
|
36
|
+
//# sourceMappingURL=findAppointmentsByPromptWithLLM.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"findAppointmentsByPromptWithLLM.js","sourceRoot":"","sources":["../../../../../../../extensions/elation/actions/findAppointmentsByPrompt/lib/findAppointmentsByPromptWithLLM/findAppointmentsByPromptWithLLM.ts"],"names":[],"mappings":";;;AAGA,qCAAuC;AACvC,qCAA0D;AAWnD,MAAM,+BAA+B,GAAG,KAAK,EAAE,EACpD,KAAK,EACL,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,SAAS,GAC4B,EAA+B,EAAE;IACtE,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,eAAM,CAAC,CAAA;IAEhC,IAAI,CAAC;QACH,MAAM,qBAAqB,GAAG,YAAY;aACvC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;YACrB,EAAE,EAAE,WAAW,CAAC,EAAE;YAClB,MAAM,EAAE,WAAW,CAAC,MAAM;YAC1B,cAAc,EAAE,WAAW,CAAC,cAAc;SAC3C,CAAC,CAAC;aACF,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;aACjD,IAAI,CAAC,MAAM,CAAC,CAAA;QAEf,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,MAAM,CAC/B,MAAM,qBAAY,CAAC,MAAM,CAAC;YACxB,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACnD,YAAY,EAAE,qBAAqB;YACnC,MAAM;SACP,CAAC,EACF;YACE,QAAQ;YACR,OAAO,EAAE,iCAAiC;YAC1C,SAAS;SACV,CACF,CAAA;QAED,OAAO;YACL,cAAc,EAAE,MAAM,CAAC,cAAc;YACrC,WAAW,EAAE,MAAM,CAAC,WAAW;SAChC,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAA;IAC1D,CAAC;AACH,CAAC,CAAA;AAvCY,QAAA,+BAA+B,mCAuC3C"}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { StructuredOutputParser } from '@langchain/core/output_parsers';
|
3
|
+
export declare const AppointmentsSchema: z.ZodArray<z.ZodNumber, "many">;
|
4
|
+
export declare const parser: StructuredOutputParser<z.ZodObject<{
|
5
|
+
appointmentIds: z.ZodArray<z.ZodNumber, "many">;
|
6
|
+
explanation: z.ZodString;
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
8
|
+
explanation: string;
|
9
|
+
appointmentIds: number[];
|
10
|
+
}, {
|
11
|
+
explanation: string;
|
12
|
+
appointmentIds: number[];
|
13
|
+
}>>;
|
14
|
+
export interface AppointmentsFromAI {
|
15
|
+
appointmentIds: number[];
|
16
|
+
explanation: string;
|
17
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.parser = exports.AppointmentsSchema = void 0;
|
4
|
+
const zod_1 = require("zod");
|
5
|
+
const output_parsers_1 = require("@langchain/core/output_parsers");
|
6
|
+
exports.AppointmentsSchema = zod_1.z.array(zod_1.z.coerce.number())
|
7
|
+
.describe('Array of appointment IDs that match the criteria');
|
8
|
+
exports.parser = output_parsers_1.StructuredOutputParser.fromZodSchema(zod_1.z.object({
|
9
|
+
appointmentIds: exports.AppointmentsSchema,
|
10
|
+
explanation: zod_1.z
|
11
|
+
.string()
|
12
|
+
.describe('A readable explanation of how the appointments were found and why'),
|
13
|
+
}));
|
14
|
+
//# sourceMappingURL=parser.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../../../../../../extensions/elation/actions/findAppointmentsByPrompt/lib/findAppointmentsByPromptWithLLM/parser.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AACvB,mEAAuE;AAE1D,QAAA,kBAAkB,GAAG,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;KACzD,QAAQ,CAAC,kDAAkD,CAAC,CAAA;AAElD,QAAA,MAAM,GAAG,uCAAsB,CAAC,aAAa,CACxD,OAAC,CAAC,MAAM,CAAC;IACP,cAAc,EAAE,0BAAkB;IAClC,WAAW,EAAE,OAAC;SACX,MAAM,EAAE;SACR,QAAQ,CACP,mEAAmE,CACpE;CACJ,CAAC,CACH,CAAA"}
|
@@ -0,0 +1,2 @@
|
|
1
|
+
import { ChatPromptTemplate } from '@langchain/core/prompts';
|
2
|
+
export declare const systemPrompt: ChatPromptTemplate<import("@langchain/core/prompts").ParamsFromFString<"You are a helpful medical assistant. You will receive a list (array) of appointments for a single patient and instructions about which types of appointments to find. You're supposed to use the information in the list to find appointments that match, if any exist. If no appointments exists that obviously match the instructions, that's a perfectly acceptable outcome. If multiple appointments exist that match the instructions, you should return all of them.\n \nImportant instructions:\n- The appointment \"reason\" is the appointment type.\n- Only include appointment ids that exist in the input array. If no appointments exist that match the instructions, return an empty array.\n- Pay close attention to the instructions. They are intended to have been written by a clinician, for a clinician.\n- Think like a clinician. In other words, \"Rx\" should match a prescription appointment or follow-up related to a prescription, and \"PT\" would match physical therapy.\n- The current date is {currentDate}.\n----------\nInput array: \n{appointments}\n----------\nInstruction: \n{prompt}\n----------\n\nOutput a JSON object with the following keys:\n1. appointmentIds: array of numbers representing appointment IDs that match the instructions (or an empty array if no appointments exist that match the instructions).\n2. explanation: A readable explanation of how the appointments were found and why. Or, if no appointments exist that match the instructions, an explanation of why.">, any>;
|
@@ -0,0 +1,24 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.systemPrompt = void 0;
|
4
|
+
const prompts_1 = require("@langchain/core/prompts");
|
5
|
+
exports.systemPrompt = prompts_1.ChatPromptTemplate.fromTemplate(`You are a helpful medical assistant. You will receive a list (array) of appointments for a single patient and instructions about which types of appointments to find. You're supposed to use the information in the list to find appointments that match, if any exist. If no appointments exists that obviously match the instructions, that's a perfectly acceptable outcome. If multiple appointments exist that match the instructions, you should return all of them.
|
6
|
+
|
7
|
+
Important instructions:
|
8
|
+
- The appointment "reason" is the appointment type.
|
9
|
+
- Only include appointment ids that exist in the input array. If no appointments exist that match the instructions, return an empty array.
|
10
|
+
- Pay close attention to the instructions. They are intended to have been written by a clinician, for a clinician.
|
11
|
+
- Think like a clinician. In other words, "Rx" should match a prescription appointment or follow-up related to a prescription, and "PT" would match physical therapy.
|
12
|
+
- The current date is {currentDate}.
|
13
|
+
----------
|
14
|
+
Input array:
|
15
|
+
{appointments}
|
16
|
+
----------
|
17
|
+
Instruction:
|
18
|
+
{prompt}
|
19
|
+
----------
|
20
|
+
|
21
|
+
Output a JSON object with the following keys:
|
22
|
+
1. appointmentIds: array of numbers representing appointment IDs that match the instructions (or an empty array if no appointments exist that match the instructions).
|
23
|
+
2. explanation: A readable explanation of how the appointments were found and why. Or, if no appointments exist that match the instructions, an explanation of why.`);
|
24
|
+
//# sourceMappingURL=prompt.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../../../../../extensions/elation/actions/findAppointmentsByPrompt/lib/findAppointmentsByPromptWithLLM/prompt.ts"],"names":[],"mappings":";;;AAAA,qDAA4D;AAE/C,QAAA,YAAY,GAAG,4BAAkB,CAAC,YAAY,CAAC;;;;;;;;;;;;;;;;;;oKAkBwG,CACnK,CAAA"}
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import { type Action } from '@awell-health/extensions-core';
|
2
|
-
import {
|
2
|
+
import type { settings } from '../../settings';
|
3
3
|
import { fields, dataPoints } from './config';
|
4
4
|
export declare const findFutureAppointment: Action<typeof fields, typeof settings, keyof typeof dataPoints>;
|
@@ -1,48 +1,29 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.findFutureAppointment = void 0;
|
4
|
+
const lodash_1 = require("lodash");
|
4
5
|
const extensions_core_1 = require("@awell-health/extensions-core");
|
5
|
-
const client_1 = require("../../client");
|
6
|
-
const config_1 = require("./config");
|
7
|
-
const output_parsers_1 = require("@langchain/core/output_parsers");
|
8
|
-
const zod_1 = require("zod");
|
9
|
-
const openai_1 = require("@langchain/openai");
|
10
6
|
const addEventLog_1 = require("../../../../src/lib/awell/addEventLog");
|
11
|
-
const
|
7
|
+
const config_1 = require("./config");
|
8
|
+
const getFutureAppoitnments_1 = require("./getFutureAppoitnments");
|
9
|
+
const parser_1 = require("./lib/findAppointmentWithLLM/parser");
|
10
|
+
const findAppointmentWithLLM_1 = require("./lib/findAppointmentWithLLM/findAppointmentWithLLM");
|
11
|
+
const createOpenAIModel_1 = require("../../../../src/lib/llm/openai/createOpenAIModel");
|
12
|
+
const constants_1 = require("../../../../src/lib/llm/openai/constants");
|
12
13
|
exports.findFutureAppointment = {
|
13
14
|
key: 'findFutureAppointment',
|
14
15
|
category: extensions_core_1.Category.EHR_INTEGRATIONS,
|
15
|
-
title: '🪄 Find future appointment',
|
16
|
+
title: '🪄 Find future appointment (Beta)',
|
16
17
|
description: 'Find a future appointment in Elation.',
|
17
18
|
fields: config_1.fields,
|
18
19
|
previewable: false,
|
19
20
|
dataPoints: config_1.dataPoints,
|
20
|
-
onEvent: async ({ payload, onComplete, onError }) => {
|
21
|
+
onEvent: async ({ payload, onComplete, onError, helpers }) => {
|
22
|
+
// 1. Validate input
|
21
23
|
const { prompt, patientId } = config_1.FieldsValidationSchema.parse(payload.fields);
|
22
|
-
|
23
|
-
const
|
24
|
-
if (
|
25
|
-
await onError({
|
26
|
-
events: [
|
27
|
-
{
|
28
|
-
date: new Date().toISOString(),
|
29
|
-
text: { en: 'OpenAI API key is required for this action.' },
|
30
|
-
error: {
|
31
|
-
category: 'SERVER_ERROR',
|
32
|
-
message: 'OpenAI API key is required for this action.',
|
33
|
-
},
|
34
|
-
},
|
35
|
-
],
|
36
|
-
});
|
37
|
-
return;
|
38
|
-
}
|
39
|
-
const appointments = await api.findAppointments({
|
40
|
-
patient: patientId,
|
41
|
-
from_date: new Date().toISOString(),
|
42
|
-
});
|
43
|
-
const scheduledOrConfirmedAppointments = appointments.filter((appointment) => appointment.status.status === 'Scheduled' ||
|
44
|
-
appointment.status.status === 'Confirmed');
|
45
|
-
if (scheduledOrConfirmedAppointments.length === 0) {
|
24
|
+
// 2. Get future appointments
|
25
|
+
const appointments = await (0, getFutureAppoitnments_1.getFutureAppointments)(payload.settings, patientId);
|
26
|
+
if (appointments.length === 0) {
|
46
27
|
await onComplete({
|
47
28
|
data_points: {
|
48
29
|
appointmentExists: 'false',
|
@@ -50,74 +31,35 @@ exports.findFutureAppointment = {
|
|
50
31
|
});
|
51
32
|
return;
|
52
33
|
}
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
scheduled_date: appointment.scheduled_date,
|
60
|
-
};
|
61
|
-
return JSON.stringify(relevantInfo);
|
62
|
-
})
|
63
|
-
.join('\n\n');
|
64
|
-
const ChatModelGPT4o = new openai_1.ChatOpenAI({
|
65
|
-
modelName: 'gpt-4o-2024-08-06',
|
66
|
-
openAIApiKey: openAiApiKey,
|
67
|
-
temperature: 0,
|
68
|
-
maxRetries: 3,
|
69
|
-
timeout: 10000,
|
34
|
+
// 3. Initialize OpenAI model with metadata and callbacks
|
35
|
+
const { model, metadata, callbacks } = await (0, createOpenAIModel_1.createOpenAIModel)({
|
36
|
+
settings: payload.settings,
|
37
|
+
helpers,
|
38
|
+
payload,
|
39
|
+
modelType: constants_1.OPENAI_MODELS.GPT4o
|
70
40
|
});
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
Instruction:
|
83
|
-
${prompt}
|
84
|
-
----------
|
85
|
-
|
86
|
-
Output a JSON object with two keys:
|
87
|
-
1. appointmentId: The id of the appointment that matches the instructions, if one exists. If no appointment exists that obviously matches, you should return null.
|
88
|
-
2. explanation: A readable explanation of how the appointment was found and why. Or, if no appointment exists that matches the instructions, an explanation of why.`;
|
89
|
-
const AppointmentIdSchema = zod_1.z.coerce
|
90
|
-
.number()
|
91
|
-
.nullable()
|
92
|
-
.describe('A single appointment');
|
93
|
-
const parser = output_parsers_1.StructuredOutputParser.fromZodSchema(zod_1.z.object({
|
94
|
-
appointmentId: AppointmentIdSchema,
|
95
|
-
explanation: zod_1.z
|
96
|
-
.string()
|
97
|
-
.describe('A readable explanation of how the appointment was found and why'),
|
98
|
-
}));
|
99
|
-
let result;
|
100
|
-
try {
|
101
|
-
const chain = ChatModelGPT4o.pipe(parser);
|
102
|
-
result = await chain.invoke(systemPrompt);
|
103
|
-
}
|
104
|
-
catch (invokeError) {
|
105
|
-
console.error('Error invoking ChatModelGPT4o for findFutureAppointment:', invokeError);
|
106
|
-
throw new Error('Failed to find future appointment.');
|
107
|
-
}
|
108
|
-
const matchedAppointmentId = AppointmentIdSchema.parse(result.appointmentId);
|
109
|
-
const foundAppointment = scheduledOrConfirmedAppointments.find((appointment) => appointment.id === Number(matchedAppointmentId));
|
41
|
+
// 4. Find matching appointment
|
42
|
+
const { appointmentId, explanation } = await (0, findAppointmentWithLLM_1.findAppointmentWithLLM)({
|
43
|
+
model,
|
44
|
+
appointments,
|
45
|
+
prompt,
|
46
|
+
metadata,
|
47
|
+
callbacks
|
48
|
+
});
|
49
|
+
const matchedAppointmentId = parser_1.AppointmentIdSchema.parse(appointmentId);
|
50
|
+
const foundAppointment = appointments.find((appointment) => appointment.id === Number(matchedAppointmentId));
|
51
|
+
// 5. Complete action with results
|
110
52
|
await onComplete({
|
111
53
|
data_points: {
|
112
54
|
appointment: !(0, lodash_1.isNil)(matchedAppointmentId)
|
113
55
|
? JSON.stringify(foundAppointment)
|
114
56
|
: undefined,
|
115
|
-
explanation
|
57
|
+
explanation,
|
116
58
|
appointmentExists: !(0, lodash_1.isNil)(matchedAppointmentId) ? 'true' : 'false',
|
117
59
|
},
|
118
60
|
events: [
|
119
61
|
(0, addEventLog_1.addActivityEventLog)({
|
120
|
-
message: `Number of future scheduled or confirmed appointments for patient ${patientId}: ${
|
62
|
+
message: `Number of future scheduled or confirmed appointments for patient ${patientId}: ${appointments.length}\nFound appointment: ${(0, lodash_1.isNil)(foundAppointment) ? 'none' : foundAppointment === null || foundAppointment === void 0 ? void 0 : foundAppointment.id}\nExplanation: ${explanation}`,
|
121
63
|
}),
|
122
64
|
],
|
123
65
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"findFutureAppointment.js","sourceRoot":"","sources":["../../../../../extensions/elation/actions/findFutureAppointment/findFutureAppointment.ts"],"names":[],"mappings":";;;AAAA,mEAAqE;AAErE,
|
1
|
+
{"version":3,"file":"findFutureAppointment.js","sourceRoot":"","sources":["../../../../../extensions/elation/actions/findFutureAppointment/findFutureAppointment.ts"],"names":[],"mappings":";;;AAAA,mCAA8B;AAC9B,mEAAqE;AAErE,uEAA2E;AAE3E,qCAAqE;AACrE,mEAA+D;AAC/D,gEAAyE;AACzE,gGAA4F;AAC5F,wFAAoF;AACpF,wEAAwE;AAE3D,QAAA,qBAAqB,GAI9B;IACF,GAAG,EAAE,uBAAuB;IAC5B,QAAQ,EAAE,0BAAQ,CAAC,gBAAgB;IACnC,KAAK,EAAE,mCAAmC;IAC1C,WAAW,EAAE,uCAAuC;IACpD,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,oBAAoB;QACpB,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,+BAAsB,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAE1E,6BAA6B;QAC7B,MAAM,YAAY,GAAG,MAAM,IAAA,6CAAqB,EAC9C,OAAO,CAAC,QAAwB,EAChC,SAAS,CACV,CAAA;QAED,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC9B,MAAM,UAAU,CAAC;gBACf,WAAW,EAAE;oBACX,iBAAiB,EAAE,OAAO;iBAC3B;aACF,CAAC,CAAA;YACF,OAAM;QACR,CAAC;QAED,yDAAyD;QACzD,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,MAAM,IAAA,qCAAiB,EAAC;YAC7D,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,OAAO;YACP,OAAO;YACP,SAAS,EAAE,yBAAa,CAAC,KAAK;SAC/B,CAAC,CAAA;QAEF,+BAA+B;QAC/B,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,MAAM,IAAA,+CAAsB,EAAC;YAClE,KAAK;YACL,YAAY;YACZ,MAAM;YACN,QAAQ;YACR,SAAS;SACV,CAAC,CAAA;QAEF,MAAM,oBAAoB,GAAG,4BAAmB,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;QACrE,MAAM,gBAAgB,GAAG,YAAY,CAAC,IAAI,CACxC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,KAAK,MAAM,CAAC,oBAAoB,CAAC,CACjE,CAAA;QAED,kCAAkC;QAClC,MAAM,UAAU,CAAC;YACf,WAAW,EAAE;gBACX,WAAW,EAAE,CAAC,IAAA,cAAK,EAAC,oBAAoB,CAAC;oBACvC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC;oBAClC,CAAC,CAAC,SAAS;gBACb,WAAW;gBACX,iBAAiB,EAAE,CAAC,IAAA,cAAK,EAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;aACnE;YACD,MAAM,EAAE;gBACN,IAAA,iCAAmB,EAAC;oBAClB,OAAO,EAAE,oEAAoE,SAAS,KAAK,YAAY,CAAC,MAAM,wBAAwB,IAAA,cAAK,EAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,EAAE,kBAAkB,WAAW,EAAE;iBAC7N,CAAC;aACH;SACF,CAAC,CAAA;IACJ,CAAC;CACF,CAAA"}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.formatAppointments = void 0;
|
4
|
+
const formatAppointments = (appointments) => {
|
5
|
+
return appointments
|
6
|
+
.map((appointment) => {
|
7
|
+
const relevantInfo = {
|
8
|
+
id: appointment.id,
|
9
|
+
reason: appointment.reason,
|
10
|
+
duration: appointment.duration,
|
11
|
+
scheduled_date: appointment.scheduled_date,
|
12
|
+
};
|
13
|
+
return JSON.stringify(relevantInfo);
|
14
|
+
})
|
15
|
+
.join('\n\n');
|
16
|
+
};
|
17
|
+
exports.formatAppointments = formatAppointments;
|
18
|
+
//# sourceMappingURL=formatAppointments.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"formatAppointments.js","sourceRoot":"","sources":["../../../../../extensions/elation/actions/findFutureAppointment/formatAppointments.ts"],"names":[],"mappings":";;;AAEO,MAAM,kBAAkB,GAAG,CAAC,YAAmC,EAAU,EAAE;IAC9E,OAAO,YAAY;SAChB,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE;QACnB,MAAM,YAAY,GAAG;YACnB,EAAE,EAAE,WAAW,CAAC,EAAE;YAClB,MAAM,EAAE,WAAW,CAAC,MAAM;YAC1B,QAAQ,EAAE,WAAW,CAAC,QAAQ;YAC9B,cAAc,EAAE,WAAW,CAAC,cAAc;SAC3C,CAAA;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAA;IACrC,CAAC,CAAC;SACD,IAAI,CAAC,MAAM,CAAC,CAAA;AACjB,CAAC,CAAA;AAZU,QAAA,kBAAkB,sBAY5B"}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getFutureAppointments = void 0;
|
4
|
+
const client_1 = require("../../client");
|
5
|
+
const getFutureAppointments = async (elationSettings, patientId) => {
|
6
|
+
const api = (0, client_1.makeAPIClient)(elationSettings);
|
7
|
+
const appointments = await api.findAppointments({
|
8
|
+
patient: patientId,
|
9
|
+
from_date: new Date().toISOString(),
|
10
|
+
});
|
11
|
+
return appointments.filter((appointment) => appointment.status.status === 'Scheduled' ||
|
12
|
+
appointment.status.status === 'Confirmed');
|
13
|
+
};
|
14
|
+
exports.getFutureAppointments = getFutureAppointments;
|
15
|
+
//# sourceMappingURL=getFutureAppoitnments.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"getFutureAppoitnments.js","sourceRoot":"","sources":["../../../../../extensions/elation/actions/findFutureAppointment/getFutureAppoitnments.ts"],"names":[],"mappings":";;;AAEA,yCAA4C;AAKrC,MAAM,qBAAqB,GAAG,KAAK,EAAE,eAA6B,EAAE,SAAiB,EAAkC,EAAE;IAC9H,MAAM,GAAG,GAAG,IAAA,sBAAa,EAAC,eAAe,CAAC,CAAA;IAE1C,MAAM,YAAY,GAAG,MAAM,GAAG,CAAC,gBAAgB,CAAC;QAC9C,OAAO,EAAE,SAAS;QAClB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACpC,CAAC,CAAA;IACF,OAAO,YAAY,CAAC,MAAM,CACxB,CAAC,WAAW,EAAE,EAAE,CACd,WAAW,CAAC,MAAM,CAAC,MAAM,KAAK,WAAW;QACzC,WAAW,CAAC,MAAM,CAAC,MAAM,KAAK,WAAW,CAC5C,CAAA;AACH,CAAC,CAAA;AAZY,QAAA,qBAAqB,yBAYjC"}
|