@awell-health/awell-extensions 2.0.52 → 2.0.54
Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,7 @@ exports.addIdentifierToPatient = void 0;
|
|
4
4
|
const extensions_core_1 = require("@awell-health/extensions-core");
|
5
5
|
const config_1 = require("./config");
|
6
6
|
const zod_1 = require("zod");
|
7
|
+
const lodash_1 = require("lodash");
|
7
8
|
exports.addIdentifierToPatient = {
|
8
9
|
key: 'addIdentifierToPatient',
|
9
10
|
category: extensions_core_1.Category.WORKFLOW,
|
@@ -13,27 +14,26 @@ exports.addIdentifierToPatient = {
|
|
13
14
|
dataPoints: config_1.dataPoints,
|
14
15
|
previewable: false,
|
15
16
|
onEvent: async ({ payload, onComplete, onError, helpers }) => {
|
16
|
-
var _a, _b;
|
17
|
-
const { fields: { system, value },
|
17
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
18
|
+
const { fields: { system, value }, } = (0, extensions_core_1.validate)({
|
18
19
|
schema: zod_1.z.object({
|
19
20
|
fields: config_1.FieldsValidationSchema,
|
20
|
-
patient: config_1.PatientValidationSchema,
|
21
21
|
}),
|
22
22
|
payload,
|
23
23
|
});
|
24
|
+
const currentPatient = payload.patient;
|
24
25
|
const sdk = await helpers.awellSdk();
|
25
26
|
const { patientByIdentifier: { patient: existingPatient }, } = await sdk.orchestration.query({
|
26
27
|
patientByIdentifier: {
|
27
28
|
__args: { system, value },
|
28
29
|
patient: {
|
29
30
|
id: true,
|
30
|
-
profile: { identifier: { system: true, value: true } },
|
31
31
|
},
|
32
32
|
},
|
33
33
|
});
|
34
|
-
const patientExists =
|
35
|
-
const
|
36
|
-
if (patientExists && !
|
34
|
+
const patientExists = !(0, lodash_1.isEmpty)(existingPatient === null || existingPatient === void 0 ? void 0 : existingPatient.id);
|
35
|
+
const patientLookUpIsCurrentPatient = (existingPatient === null || existingPatient === void 0 ? void 0 : existingPatient.id) === currentPatient.id;
|
36
|
+
if (patientExists && !patientLookUpIsCurrentPatient) {
|
37
37
|
await onError({
|
38
38
|
events: [
|
39
39
|
{
|
@@ -46,8 +46,24 @@ exports.addIdentifierToPatient = {
|
|
46
46
|
});
|
47
47
|
return;
|
48
48
|
}
|
49
|
+
// Fetch from the API, had inconsitent results with using patient.payload (e.g. missing identifiers)
|
50
|
+
const currentPatientData = await sdk.orchestration.query({
|
51
|
+
patient: {
|
52
|
+
__args: {
|
53
|
+
id: currentPatient.id,
|
54
|
+
},
|
55
|
+
patient: {
|
56
|
+
profile: {
|
57
|
+
identifier: {
|
58
|
+
system: true,
|
59
|
+
value: true,
|
60
|
+
},
|
61
|
+
},
|
62
|
+
},
|
63
|
+
},
|
64
|
+
});
|
49
65
|
// Filter identifiers, excluding any with the current system
|
50
|
-
const existingIdentifiers = (_b = (_a =
|
66
|
+
const existingIdentifiers = (_d = (_c = (_b = (_a = currentPatientData === null || currentPatientData === void 0 ? void 0 : currentPatientData.patient) === null || _a === void 0 ? void 0 : _a.patient) === null || _b === void 0 ? void 0 : _b.profile) === null || _c === void 0 ? void 0 : _c.identifier) !== null && _d !== void 0 ? _d : [];
|
51
67
|
const otherIdentifiers = existingIdentifiers.filter((id) => id.system !== system);
|
52
68
|
const previousIdentifier = existingIdentifiers.find((id) => id.system === system);
|
53
69
|
const isUpdatingIdentifier = Boolean(previousIdentifier);
|
@@ -64,20 +80,30 @@ exports.addIdentifierToPatient = {
|
|
64
80
|
});
|
65
81
|
return;
|
66
82
|
}
|
83
|
+
const newIdentifiers = [...otherIdentifiers, { system, value }];
|
67
84
|
// Perform update or add the new identifier
|
68
|
-
await sdk.orchestration.mutation({
|
85
|
+
const result = await sdk.orchestration.mutation({
|
69
86
|
updatePatient: {
|
70
87
|
__args: {
|
71
88
|
input: {
|
72
|
-
patient_id:
|
89
|
+
patient_id: currentPatient.id,
|
73
90
|
profile: {
|
74
|
-
identifier:
|
91
|
+
identifier: newIdentifiers,
|
92
|
+
},
|
93
|
+
},
|
94
|
+
},
|
95
|
+
patient: {
|
96
|
+
id: true,
|
97
|
+
profile: {
|
98
|
+
identifier: {
|
99
|
+
system: true,
|
100
|
+
value: true,
|
75
101
|
},
|
76
102
|
},
|
77
103
|
},
|
78
|
-
patient: { id: true },
|
79
104
|
},
|
80
105
|
});
|
106
|
+
const updatedIdentifiers = (_h = (_g = (_f = (_e = result === null || result === void 0 ? void 0 : result.updatePatient) === null || _e === void 0 ? void 0 : _e.patient) === null || _f === void 0 ? void 0 : _f.profile) === null || _g === void 0 ? void 0 : _g.identifier) !== null && _h !== void 0 ? _h : [];
|
81
107
|
await onComplete({
|
82
108
|
events: [
|
83
109
|
{
|
@@ -88,6 +114,24 @@ exports.addIdentifierToPatient = {
|
|
88
114
|
: `The identifier with system ${system} and value ${value} has been added to the patient.`,
|
89
115
|
},
|
90
116
|
},
|
117
|
+
{
|
118
|
+
date: new Date().toISOString(),
|
119
|
+
text: {
|
120
|
+
en: `Old list of identifiers: ${existingIdentifiers.length === 0
|
121
|
+
? 'None'
|
122
|
+
: `${existingIdentifiers
|
123
|
+
.map((id) => `${id.system}|${id.value}`)
|
124
|
+
.join(';')}`}`,
|
125
|
+
},
|
126
|
+
},
|
127
|
+
{
|
128
|
+
date: new Date().toISOString(),
|
129
|
+
text: {
|
130
|
+
en: `Updated list of identifiers: ${updatedIdentifiers
|
131
|
+
.map((id) => `${id.system}|${id.value}`)
|
132
|
+
.join(';')}`,
|
133
|
+
},
|
134
|
+
},
|
91
135
|
],
|
92
136
|
});
|
93
137
|
},
|
package/dist/extensions/awell/v1/actions/addIdentifierToPatient/addIdentifierToPatient.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"addIdentifierToPatient.js","sourceRoot":"","sources":["../../../../../../extensions/awell/v1/actions/addIdentifierToPatient/addIdentifierToPatient.ts"],"names":[],"mappings":";;;AAEA,mEAAkE;AAClE,
|
1
|
+
{"version":3,"file":"addIdentifierToPatient.js","sourceRoot":"","sources":["../../../../../../extensions/awell/v1/actions/addIdentifierToPatient/addIdentifierToPatient.ts"],"names":[],"mappings":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