@awell-health/awell-extensions 2.0.130 → 2.0.131
Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,7 @@ const addEventLog_1 = require("../../../../src/lib/awell/addEventLog");
|
|
11
11
|
exports.updatePatientTags = {
|
12
12
|
key: 'updatePatientTags',
|
13
13
|
category: extensions_core_1.Category.EHR_INTEGRATIONS,
|
14
|
-
title: 'Update patient tags',
|
14
|
+
title: '🪄 Update patient tags',
|
15
15
|
description: 'Update patient tags in Elation.',
|
16
16
|
fields: config_1.fields,
|
17
17
|
previewable: false,
|
@@ -35,19 +35,18 @@ exports.updatePatientTags = {
|
|
35
35
|
});
|
36
36
|
return;
|
37
37
|
}
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
Important Instructions:
|
38
|
+
const { tags } = await api.getPatient(patientId);
|
39
|
+
const existingTags = tags !== null && tags !== void 0 ? tags : [];
|
40
|
+
const ChatModelGPT4o = new openai_1.ChatOpenAI({
|
41
|
+
modelName: 'gpt-4o-2024-08-06',
|
42
|
+
openAIApiKey: openAiApiKey,
|
43
|
+
temperature: 0,
|
44
|
+
maxRetries: 3,
|
45
|
+
timeout: 10000,
|
46
|
+
});
|
47
|
+
const systemPrompt = `You are a clinical data manager. You will receive a list (array) of patient tags for a single patient and instructions about which tags to add, update, or remove. These tags are used to assign particular attributes to patients which can help with patient care, like grouping of patients, categorizing patients for reporting, or identifying patients for care.
|
48
|
+
|
49
|
+
Important instructions:
|
51
50
|
- The maximum number of tags is 10.
|
52
51
|
- The max length of a single tag is 100 characters.
|
53
52
|
- Ensure tags are unique.
|
@@ -56,43 +55,45 @@ Input array: ${JSON.stringify(existingTags)}
|
|
56
55
|
Instruction: ${prompt}
|
57
56
|
|
58
57
|
Output a JSON object with two keys:
|
59
|
-
1. updatedTags: The updated array of tags
|
58
|
+
1. updatedTags: The updated array of tags. If the input array is empty, the output should be an empty array.
|
60
59
|
2. explanation: A readable explanation of the changes made to the tags and why`;
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
60
|
+
const SingleTagSchema = zod_1.z.string().max(100).describe('A single tag');
|
61
|
+
const TagsSchema = zod_1.z
|
62
|
+
.array(SingleTagSchema)
|
63
|
+
.max(10)
|
64
|
+
.refine((items) => new Set(items).size === items.length, {
|
65
|
+
message: 'All items must be unique, no duplicate values allowed',
|
66
|
+
})
|
67
|
+
.describe('The updated array of tags');
|
68
|
+
const parser = output_parsers_1.StructuredOutputParser.fromZodSchema(zod_1.z.object({
|
69
|
+
updatedTags: TagsSchema,
|
70
|
+
explanation: zod_1.z
|
71
|
+
.string()
|
72
|
+
.describe('A readable explanation of the changes made to the tags and why'),
|
73
|
+
}));
|
74
|
+
let result;
|
75
|
+
try {
|
65
76
|
const chain = ChatModelGPT4o.pipe(parser);
|
66
|
-
|
67
|
-
await api.updatePatient(patientId, {
|
68
|
-
tags: result.updatedTags,
|
69
|
-
});
|
70
|
-
await onComplete({
|
71
|
-
data_points: {
|
72
|
-
updatedTags: result.updatedTags.join(', '),
|
73
|
-
},
|
74
|
-
events: [
|
75
|
-
(0, addEventLog_1.addActivityEventLog)({
|
76
|
-
message: `Previous patient tags: ${(existingTags === null || existingTags === void 0 ? void 0 : existingTags.length) > 0 ? existingTags === null || existingTags === void 0 ? void 0 : existingTags.join(', ') : 'No tags'}\nUpdated patient tags: ${result.updatedTags.join(', ')}\nExplanation: ${result.explanation}`,
|
77
|
-
}),
|
78
|
-
],
|
79
|
-
});
|
77
|
+
result = await chain.invoke(systemPrompt);
|
80
78
|
}
|
81
|
-
catch (
|
82
|
-
console.error(
|
83
|
-
|
84
|
-
events: [
|
85
|
-
{
|
86
|
-
date: new Date().toISOString(),
|
87
|
-
text: { en: 'Unable to update patient tags' },
|
88
|
-
error: {
|
89
|
-
category: 'SERVER_ERROR',
|
90
|
-
message: 'Unable to update patient tags',
|
91
|
-
},
|
92
|
-
},
|
93
|
-
],
|
94
|
-
});
|
79
|
+
catch (invokeError) {
|
80
|
+
console.error('Error invoking ChatModelGPT4o for updatePatientTags:', invokeError);
|
81
|
+
throw new Error('Failed to update patient tags.');
|
95
82
|
}
|
83
|
+
const validatedTags = TagsSchema.parse(result.updatedTags);
|
84
|
+
await api.updatePatient(patientId, {
|
85
|
+
tags: validatedTags,
|
86
|
+
});
|
87
|
+
await onComplete({
|
88
|
+
data_points: {
|
89
|
+
updatedTags: validatedTags.join(', '),
|
90
|
+
},
|
91
|
+
events: [
|
92
|
+
(0, addEventLog_1.addActivityEventLog)({
|
93
|
+
message: `Previous patient tags: ${(existingTags === null || existingTags === void 0 ? void 0 : existingTags.length) > 0 ? existingTags === null || existingTags === void 0 ? void 0 : existingTags.join(', ') : 'No tags'}\nUpdated patient tags: ${validatedTags.join(', ')}\nExplanation: ${result.explanation}`,
|
94
|
+
}),
|
95
|
+
],
|
96
|
+
});
|
96
97
|
},
|
97
98
|
};
|
98
99
|
//# sourceMappingURL=updatePatientTags.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"updatePatientTags.js","sourceRoot":"","sources":["../../../../../extensions/elation/actions/updatePatientTags/updatePatientTags.ts"],"names":[],"mappings":";;;AAAA,mEAAqE;AAErE,yCAA4C;AAC5C,qCAAqE;AACrE,mEAAuE;AACvE,6BAAuB;AACvB,8CAA8C;AAC9C,uEAA2E;AAE9D,QAAA,iBAAiB,GAI1B;IACF,GAAG,EAAE,mBAAmB;IACxB,QAAQ,EAAE,0BAAQ,CAAC,gBAAgB;IACnC,KAAK,EAAE,
|
1
|
+
{"version":3,"file":"updatePatientTags.js","sourceRoot":"","sources":["../../../../../extensions/elation/actions/updatePatientTags/updatePatientTags.ts"],"names":[],"mappings":";;;AAAA,mEAAqE;AAErE,yCAA4C;AAC5C,qCAAqE;AACrE,mEAAuE;AACvE,6BAAuB;AACvB,8CAA8C;AAC9C,uEAA2E;AAE9D,QAAA,iBAAiB,GAI1B;IACF,GAAG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