@nsshunt/stsappframework 3.1.145 → 3.1.147
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fhir/dalFhirManagerIORedisJson.js +130 -75
- package/dist/fhir/dalFhirManagerIORedisJson.js.map +1 -1
- package/dist/fhir/dalFhirManagerIORedisJson.test.js +25 -1
- package/dist/fhir/dalFhirManagerIORedisJson.test.js.map +1 -1
- package/dist/fhir/dalFhirManagerPGRes.js +53 -30
- package/dist/fhir/dalFhirManagerPGRes.js.map +1 -1
- package/dist/fhir/dalFhirManagerPGRes.test.js +25 -1
- package/dist/fhir/dalFhirManagerPGRes.test.js.map +1 -1
- package/dist/fhir/dalFhirManagerPGResEntity.js +54 -31
- package/dist/fhir/dalFhirManagerPGResEntity.js.map +1 -1
- package/dist/fhir/dalFhirManagerPGResEntity.test.js +25 -1
- package/dist/fhir/dalFhirManagerPGResEntity.test.js.map +1 -1
- package/dist/fhir/dalFhirManagerRedisJson.js +114 -59
- package/dist/fhir/dalFhirManagerRedisJson.js.map +1 -1
- package/dist/fhir/dalFhirManagerRedisJson.test.js +25 -1
- package/dist/fhir/dalFhirManagerRedisJson.test.js.map +1 -1
- package/dist/fhir/dalFhirTestHelpers.js +72 -0
- package/dist/fhir/dalFhirTestHelpers.js.map +1 -1
- package/package.json +1 -1
- package/src/fhir/STSFhirTypes.ts +8 -8
- package/src/fhir/dalFhirManagerIORedisJson.test.ts +34 -1
- package/src/fhir/dalFhirManagerIORedisJson.ts +132 -82
- package/src/fhir/dalFhirManagerPGRes.test.ts +34 -1
- package/src/fhir/dalFhirManagerPGRes.ts +64 -42
- package/src/fhir/dalFhirManagerPGResEntity.test.ts +34 -1
- package/src/fhir/dalFhirManagerPGResEntity.ts +65 -61
- package/src/fhir/dalFhirManagerRedisJson.test.ts +34 -1
- package/src/fhir/dalFhirManagerRedisJson.ts +117 -67
- package/src/fhir/dalFhirTestHelpers.ts +84 -0
- package/types/fhir/STSFhirTypes.d.ts +8 -8
- package/types/fhir/STSFhirTypes.d.ts.map +1 -1
- package/types/fhir/dalFhirManagerIORedisJson.d.ts +8 -8
- package/types/fhir/dalFhirManagerIORedisJson.d.ts.map +1 -1
- package/types/fhir/dalFhirManagerPGRes.d.ts +8 -8
- package/types/fhir/dalFhirManagerPGRes.d.ts.map +1 -1
- package/types/fhir/dalFhirManagerPGResEntity.d.ts +8 -8
- package/types/fhir/dalFhirManagerPGResEntity.d.ts.map +1 -1
- package/types/fhir/dalFhirManagerRedisJson.d.ts +8 -8
- package/types/fhir/dalFhirManagerRedisJson.d.ts.map +1 -1
- package/types/fhir/dalFhirTestHelpers.d.ts +3 -0
- package/types/fhir/dalFhirTestHelpers.d.ts.map +1 -1
package/src/fhir/STSFhirTypes.ts
CHANGED
|
@@ -497,14 +497,14 @@ export interface IPersonResource {
|
|
|
497
497
|
}
|
|
498
498
|
|
|
499
499
|
export interface IDALFhirDataAccessManager<T> {
|
|
500
|
-
GetFhirResource(fhir: Partial<T>, ecb?: (error: Error) => void): Promise<T | null>
|
|
501
|
-
GetFhirResources(filters: string[], ecb?: (error: Error) => void): Promise<T[] | null>
|
|
502
|
-
CreateFhirResource(fhir: T, ecb?: (error: Error) => void): Promise<T | null>
|
|
503
|
-
CreateFhirResources(fhir: T[], ecb?: (error: Error) => void): Promise<T
|
|
504
|
-
UpdateFhirResource(fhir: T, ecb?: (error: Error) => void): Promise<T | null>
|
|
505
|
-
UpdateFhirResources(fhir: T[], ecb?: (error: Error) => void): Promise<T
|
|
506
|
-
DeleteFhirResource(fhir: Partial<T>, ecb?: (error: Error) => void): Promise<T | null>
|
|
507
|
-
DeleteFhirResources(fhir: Partial<T>[], ecb?: (error: Error) => void): Promise<T
|
|
500
|
+
GetFhirResource(fhir: Partial<T>, ecb?: (fhir: Partial<T>, error: Error) => void): Promise<T | null>
|
|
501
|
+
GetFhirResources(filters: string[], ecb?: (filters: string[], error: Error) => void): Promise<T[] | null>
|
|
502
|
+
CreateFhirResource(fhir: T, ecb?: (fhir: T, error: Error) => void): Promise<T | null>
|
|
503
|
+
CreateFhirResources(fhir: T[], ecb?: (fhir: T, error: Error) => void): Promise<(T | null)[]>
|
|
504
|
+
UpdateFhirResource(fhir: T, ecb?: (fhir: T, error: Error) => void): Promise<T | null>
|
|
505
|
+
UpdateFhirResources(fhir: T[], ecb?: (fhir: T, error: Error) => void): Promise<(T | null)[]>
|
|
506
|
+
DeleteFhirResource(fhir: Partial<T>, ecb?: (fhir: Partial<T>, error: Error) => void): Promise<T | null>
|
|
507
|
+
DeleteFhirResources(fhir: Partial<T>[], ecb?: (fhir: Partial<T>, error: Error) => void): Promise<(T | null)[]>
|
|
508
508
|
Start(): Promise<void>
|
|
509
509
|
Stop(): Promise<void>
|
|
510
510
|
get options()
|
|
@@ -38,7 +38,7 @@ describe.skip("Test hl7 fhir resource data access layer - RedisJson", () =>
|
|
|
38
38
|
await testHelpers.TestFhirPerson(fhirManager.fhirDataAccessManager);
|
|
39
39
|
}, 30000);
|
|
40
40
|
|
|
41
|
-
test('Testing
|
|
41
|
+
test('Testing Persons with Search', async () => {
|
|
42
42
|
const iterations = 10;
|
|
43
43
|
expect.assertions(iterations + 1);
|
|
44
44
|
await testHelpers.AddFhirPersons(fhirManager.fhirDataAccessManager, iterations);
|
|
@@ -49,6 +49,39 @@ describe.skip("Test hl7 fhir resource data access layer - RedisJson", () =>
|
|
|
49
49
|
console.log(chalk.magenta(JSON.stringify(fhirResources)));
|
|
50
50
|
}, 30000);
|
|
51
51
|
|
|
52
|
+
test('Testing Persons with Bulk Insert', async () => {
|
|
53
|
+
const iterations = 10;
|
|
54
|
+
expect.assertions(2);
|
|
55
|
+
await testHelpers.AddFhirPersonsByArray(fhirManager.fhirDataAccessManager, iterations);
|
|
56
|
+
|
|
57
|
+
const fhirResources = await fhirManager.fhirDataAccessManager.GetFhirResources(['bulk_']);
|
|
58
|
+
expect(fhirResources?.length).toEqual(iterations);
|
|
59
|
+
|
|
60
|
+
console.log(chalk.rgb(133, 161, 142)(JSON.stringify(fhirResources)));
|
|
61
|
+
}, 30000);
|
|
62
|
+
|
|
63
|
+
test('Testing Persons with Bulk Update', async () => {
|
|
64
|
+
const iterations = 10;
|
|
65
|
+
expect.assertions(2);
|
|
66
|
+
await testHelpers.UpdateFhirPersonsByArray(fhirManager.fhirDataAccessManager, iterations);
|
|
67
|
+
|
|
68
|
+
const fhirResources = await fhirManager.fhirDataAccessManager.GetFhirResources(['bulk_']);
|
|
69
|
+
expect(fhirResources?.length).toEqual(iterations);
|
|
70
|
+
|
|
71
|
+
console.log(chalk.rgb(157, 133, 161)(JSON.stringify(fhirResources)));
|
|
72
|
+
}, 30000);
|
|
73
|
+
|
|
74
|
+
test('Testing Persons with Bulk Delete', async () => {
|
|
75
|
+
const iterations = 7;
|
|
76
|
+
expect.assertions(2);
|
|
77
|
+
await testHelpers.DeleteFhirPersonsByArray(fhirManager.fhirDataAccessManager, iterations);
|
|
78
|
+
|
|
79
|
+
const fhirResources = await fhirManager.fhirDataAccessManager.GetFhirResources(['bulk_']);
|
|
80
|
+
expect(fhirResources?.length).toEqual(10 - iterations);
|
|
81
|
+
|
|
82
|
+
console.log(chalk.rgb(105, 97, 50)(JSON.stringify(fhirResources)));
|
|
83
|
+
}, 30000);
|
|
84
|
+
|
|
52
85
|
afterAll(async () =>
|
|
53
86
|
{
|
|
54
87
|
await fhirManager.fhirDataAccessManager.Stop();
|
|
@@ -81,138 +81,188 @@ export class DALFhirManagerIORedisJson<T> implements IDALFhirDataAccessManager<T
|
|
|
81
81
|
return `${this.#options.resourceName}_${(fhir as Partial<IDomainResource>).id}`;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
async GetFhirResource(fhir: Partial<T>, ecb?: (error: Error) => void): Promise<T | null> {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
ecb
|
|
84
|
+
async GetFhirResource(fhir: Partial<T>, ecb?: (fhir: Partial<T>, error: Error) => void): Promise<T | null> {
|
|
85
|
+
try {
|
|
86
|
+
if (this.#redis) {
|
|
87
|
+
const retValRaw = await this.#redis.hgetall(this.GetResourceType(fhir))
|
|
88
|
+
if (retValRaw) {
|
|
89
|
+
try {
|
|
90
|
+
const { id, data } = retValRaw;
|
|
91
|
+
return JSON.parse(data) as T;
|
|
92
|
+
} catch (error: unknown) {
|
|
93
|
+
if (ecb) {
|
|
94
|
+
ecb(fhir, error as Error);
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
94
97
|
}
|
|
98
|
+
} else {
|
|
95
99
|
return null;
|
|
96
100
|
}
|
|
97
101
|
} else {
|
|
98
102
|
return null;
|
|
99
103
|
}
|
|
100
|
-
}
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (ecb) {
|
|
106
|
+
ecb(fhir, error as Error);
|
|
107
|
+
}
|
|
101
108
|
return null;
|
|
102
109
|
}
|
|
103
110
|
}
|
|
104
111
|
|
|
105
112
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
106
|
-
async CreateFhirResource(fhir: T, ecb?: (error: Error) => void): Promise<T | null> {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
113
|
+
async CreateFhirResource(fhir: T, ecb?: (fhir: T, error: Error) => void): Promise<T | null> {
|
|
114
|
+
try {
|
|
115
|
+
if (this.#redis) {
|
|
116
|
+
const record = {
|
|
117
|
+
id: this.GetResourceType(fhir),
|
|
118
|
+
data: JSON.stringify(fhir)
|
|
119
|
+
} as any;
|
|
112
120
|
|
|
113
|
-
|
|
121
|
+
const retVal = await this.#redis.hmset(this.GetResourceType(fhir), record);
|
|
114
122
|
|
|
115
|
-
|
|
116
|
-
|
|
123
|
+
if (retVal) {
|
|
124
|
+
return fhir;
|
|
125
|
+
} else {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
117
128
|
} else {
|
|
118
129
|
return null;
|
|
119
130
|
}
|
|
120
|
-
}
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (ecb) {
|
|
133
|
+
ecb(fhir, error as Error);
|
|
134
|
+
}
|
|
121
135
|
return null;
|
|
122
136
|
}
|
|
123
137
|
}
|
|
124
138
|
|
|
125
139
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
126
|
-
async UpdateFhirResource(fhir: T, ecb?: (error: Error) => void): Promise<T | null> {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
140
|
+
async UpdateFhirResource(fhir: T, ecb?: (fhir: T, error: Error) => void): Promise<T | null> {
|
|
141
|
+
try {
|
|
142
|
+
if (this.#redis) {
|
|
143
|
+
const record = {
|
|
144
|
+
id: this.GetResourceType(fhir),
|
|
145
|
+
data: JSON.stringify(fhir)
|
|
146
|
+
} as any;
|
|
132
147
|
|
|
133
|
-
|
|
148
|
+
const retVal = await this.#redis.hmset(this.GetResourceType(fhir), record);
|
|
134
149
|
|
|
135
|
-
|
|
136
|
-
|
|
150
|
+
if (retVal) {
|
|
151
|
+
return fhir;
|
|
152
|
+
} else {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
137
155
|
} else {
|
|
138
156
|
return null;
|
|
139
157
|
}
|
|
140
|
-
}
|
|
158
|
+
} catch (error) {
|
|
159
|
+
if (ecb) {
|
|
160
|
+
ecb(fhir, error as Error);
|
|
161
|
+
}
|
|
141
162
|
return null;
|
|
142
163
|
}
|
|
143
164
|
}
|
|
144
165
|
|
|
145
166
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
146
|
-
async DeleteFhirResource(fhir: Partial<T>, ecb?: (error: Error) => void): Promise<T | null> {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
167
|
+
async DeleteFhirResource(fhir: Partial<T>, ecb?: (fhir: Partial<T>, error: Error) => void): Promise<T | null> {
|
|
168
|
+
try {
|
|
169
|
+
if (this.#redis) {
|
|
170
|
+
const deleteResource = await this.GetFhirResource(fhir);
|
|
171
|
+
if (deleteResource) {
|
|
172
|
+
const retVal = await this.#redis.del(this.GetResourceType(fhir));
|
|
173
|
+
if (retVal) {
|
|
174
|
+
return deleteResource;
|
|
175
|
+
} else {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
153
178
|
} else {
|
|
154
179
|
return null;
|
|
155
180
|
}
|
|
156
181
|
} else {
|
|
157
182
|
return null;
|
|
158
183
|
}
|
|
159
|
-
}
|
|
184
|
+
} catch (error) {
|
|
185
|
+
if (ecb) {
|
|
186
|
+
ecb(fhir, error as Error);
|
|
187
|
+
}
|
|
160
188
|
return null;
|
|
161
189
|
}
|
|
162
190
|
}
|
|
163
191
|
|
|
164
|
-
async GetFhirResources(filters: string[], ecb?: (error: Error) => void): Promise<T[] | null> {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
192
|
+
async GetFhirResources(filters: string[], ecb?: (filters: string[], error: Error) => void): Promise<T[] | null> {
|
|
193
|
+
try {
|
|
194
|
+
const promArray: Promise<T[]>[] = [ ];
|
|
195
|
+
filters.forEach(filter => {
|
|
196
|
+
const prom = async (): Promise<T[]> => {
|
|
197
|
+
const retValArray: T[] = [ ];
|
|
198
|
+
const retVal = await this.#SearchBy(filter);
|
|
199
|
+
// First index is the total number of records in the search (does not consider limit)
|
|
200
|
+
//const listLength = retVal[0];
|
|
201
|
+
|
|
202
|
+
let index = 1;
|
|
203
|
+
const obj: JSONObject = { };
|
|
204
|
+
for (;;) {
|
|
205
|
+
if (index >= retVal.length) {
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
const id = retVal[index++];
|
|
209
|
+
obj[id] = { }
|
|
210
|
+
const values = retVal[index++];
|
|
211
|
+
let dataIndex = 0;
|
|
212
|
+
for (let j=0; j < values.length / 2; j++) {
|
|
213
|
+
const field = values[dataIndex++];
|
|
214
|
+
if ((field as string).localeCompare('data') === 0) {
|
|
215
|
+
const value = JSON.parse(values[dataIndex++]);
|
|
216
|
+
obj[id] = value;
|
|
217
|
+
} else {
|
|
218
|
+
dataIndex++;
|
|
219
|
+
}
|
|
190
220
|
}
|
|
221
|
+
retValArray.push(obj[id]);
|
|
191
222
|
}
|
|
192
|
-
retValArray
|
|
223
|
+
return retValArray;
|
|
193
224
|
}
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
promArray.push(prom());
|
|
197
|
-
});
|
|
225
|
+
promArray.push(prom());
|
|
226
|
+
});
|
|
198
227
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
228
|
+
const promRetVal = await Promise.all(promArray);
|
|
229
|
+
let retVal: T[] = [ ];
|
|
230
|
+
promRetVal.forEach(prv => {
|
|
231
|
+
retVal = retVal.concat(prv);
|
|
232
|
+
});
|
|
233
|
+
return retVal;
|
|
234
|
+
} catch (error) {
|
|
235
|
+
if (ecb) {
|
|
236
|
+
ecb(filters, error as Error);
|
|
237
|
+
}
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
205
240
|
}
|
|
206
241
|
|
|
207
|
-
async CreateFhirResources(fhir: T[], ecb?: (error: Error) => void): Promise<T
|
|
208
|
-
|
|
242
|
+
async CreateFhirResources(fhir: T[], ecb?: (fhir: T, error: Error) => void): Promise<(T | null)[]> {
|
|
243
|
+
const promArray: Promise<T | null>[] = [ ];
|
|
244
|
+
fhir.forEach(async (f) => {
|
|
245
|
+
promArray.push(this.CreateFhirResource(f, ecb));
|
|
246
|
+
})
|
|
247
|
+
const promRetVal = await Promise.all(promArray);
|
|
248
|
+
return promRetVal;
|
|
209
249
|
}
|
|
210
250
|
|
|
211
|
-
async UpdateFhirResources(fhir: T[], ecb?: (error: Error) => void): Promise<T
|
|
212
|
-
|
|
251
|
+
async UpdateFhirResources(fhir: T[], ecb?: (fhir: T, error: Error) => void): Promise<(T | null)[]> {
|
|
252
|
+
const promArray: Promise<T | null>[] = [ ];
|
|
253
|
+
fhir.forEach(async (f) => {
|
|
254
|
+
promArray.push(this.UpdateFhirResource(f, ecb));
|
|
255
|
+
})
|
|
256
|
+
const promRetVal = await Promise.all(promArray);
|
|
257
|
+
return promRetVal;
|
|
213
258
|
}
|
|
214
259
|
|
|
215
|
-
async DeleteFhirResources(fhir: Partial<T>[], ecb?: (error: Error) => void): Promise<T
|
|
216
|
-
|
|
260
|
+
async DeleteFhirResources(fhir: Partial<T>[], ecb?: (fhir: Partial<T>, error: Error) => void): Promise<(T | null)[]> {
|
|
261
|
+
const promArray: Promise<T | null>[] = [ ];
|
|
262
|
+
fhir.forEach(async (f) => {
|
|
263
|
+
promArray.push(this.DeleteFhirResource(f, ecb));
|
|
264
|
+
})
|
|
265
|
+
const promRetVal = await Promise.all(promArray);
|
|
266
|
+
return promRetVal;
|
|
217
267
|
}
|
|
218
268
|
}
|
|
@@ -38,7 +38,7 @@ describe("Test hl7 fhir resource data access layer - PGRes", () =>
|
|
|
38
38
|
await testHelpers.TestFhirPerson(fhirManager.fhirDataAccessManager);
|
|
39
39
|
}, 30000);
|
|
40
40
|
|
|
41
|
-
test('Testing
|
|
41
|
+
test('Testing Persons with Search', async () => {
|
|
42
42
|
const iterations = 10;
|
|
43
43
|
expect.assertions(iterations + 1);
|
|
44
44
|
await testHelpers.AddFhirPersons(fhirManager.fhirDataAccessManager, iterations);
|
|
@@ -49,6 +49,39 @@ describe("Test hl7 fhir resource data access layer - PGRes", () =>
|
|
|
49
49
|
console.log(chalk.yellow(JSON.stringify(fhirResources)));
|
|
50
50
|
}, 30000);
|
|
51
51
|
|
|
52
|
+
test('Testing Persons with Bulk Insert', async () => {
|
|
53
|
+
const iterations = 10;
|
|
54
|
+
expect.assertions(2);
|
|
55
|
+
await testHelpers.AddFhirPersonsByArray(fhirManager.fhirDataAccessManager, iterations);
|
|
56
|
+
|
|
57
|
+
const fhirResources = await fhirManager.fhirDataAccessManager.GetFhirResources(['bulk_']);
|
|
58
|
+
expect(fhirResources?.length).toEqual(iterations);
|
|
59
|
+
|
|
60
|
+
console.log(chalk.rgb(133, 161, 142)(JSON.stringify(fhirResources)));
|
|
61
|
+
}, 30000);
|
|
62
|
+
|
|
63
|
+
test('Testing Persons with Bulk Update', async () => {
|
|
64
|
+
const iterations = 10;
|
|
65
|
+
expect.assertions(2);
|
|
66
|
+
await testHelpers.UpdateFhirPersonsByArray(fhirManager.fhirDataAccessManager, iterations);
|
|
67
|
+
|
|
68
|
+
const fhirResources = await fhirManager.fhirDataAccessManager.GetFhirResources(['bulk_']);
|
|
69
|
+
expect(fhirResources?.length).toEqual(iterations);
|
|
70
|
+
|
|
71
|
+
console.log(chalk.rgb(157, 133, 161)(JSON.stringify(fhirResources)));
|
|
72
|
+
}, 30000);
|
|
73
|
+
|
|
74
|
+
test('Testing Persons with Bulk Delete', async () => {
|
|
75
|
+
const iterations = 7;
|
|
76
|
+
expect.assertions(2);
|
|
77
|
+
await testHelpers.DeleteFhirPersonsByArray(fhirManager.fhirDataAccessManager, iterations);
|
|
78
|
+
|
|
79
|
+
const fhirResources = await fhirManager.fhirDataAccessManager.GetFhirResources(['bulk_']);
|
|
80
|
+
expect(fhirResources?.length).toEqual(10 - iterations);
|
|
81
|
+
|
|
82
|
+
console.log(chalk.rgb(105, 97, 50)(JSON.stringify(fhirResources)));
|
|
83
|
+
}, 30000);
|
|
84
|
+
|
|
52
85
|
afterAll(async () =>
|
|
53
86
|
{
|
|
54
87
|
fhirManager.fhirDataAccessManager.Stop();
|
|
@@ -32,7 +32,7 @@ export class DALFhirManagerPGRes<T> implements IDALFhirDataAccessManager<T> {
|
|
|
32
32
|
return `${this.#options.resourceName}_${(fhir as Partial<IDomainResource>).id}`;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
async GetFhirResource(fhir: Partial<T>, ecb?: (error: Error) => void): Promise<T | null> {
|
|
35
|
+
async GetFhirResource(fhir: Partial<T>, ecb?: (fhir: Partial<T>, error: Error) => void): Promise<T | null> {
|
|
36
36
|
if (!this.#accessLayer) {
|
|
37
37
|
return null;
|
|
38
38
|
}
|
|
@@ -44,7 +44,7 @@ export class DALFhirManagerPGRes<T> implements IDALFhirDataAccessManager<T> {
|
|
|
44
44
|
});
|
|
45
45
|
if (retVal.error) {
|
|
46
46
|
if (ecb) {
|
|
47
|
-
ecb(retVal.error.error);
|
|
47
|
+
ecb(fhir, retVal.error.error);
|
|
48
48
|
}
|
|
49
49
|
return null;
|
|
50
50
|
} else {
|
|
@@ -52,7 +52,7 @@ export class DALFhirManagerPGRes<T> implements IDALFhirDataAccessManager<T> {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
async CreateFhirResource(fhir: T, ecb?: (error: Error) => void): Promise<T | null> {
|
|
55
|
+
async CreateFhirResource(fhir: T, ecb?: (fhir: T, error: Error) => void): Promise<T | null> {
|
|
56
56
|
if (!this.#accessLayer) {
|
|
57
57
|
return null;
|
|
58
58
|
}
|
|
@@ -65,7 +65,7 @@ export class DALFhirManagerPGRes<T> implements IDALFhirDataAccessManager<T> {
|
|
|
65
65
|
}, fhir);
|
|
66
66
|
if (retVal.error) {
|
|
67
67
|
if (ecb) {
|
|
68
|
-
ecb(retVal.error.error);
|
|
68
|
+
ecb(fhir, retVal.error.error);
|
|
69
69
|
}
|
|
70
70
|
return null;
|
|
71
71
|
} else {
|
|
@@ -73,7 +73,7 @@ export class DALFhirManagerPGRes<T> implements IDALFhirDataAccessManager<T> {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
async UpdateFhirResource(fhir: T, ecb?: (error: Error) => void): Promise<T | null> {
|
|
76
|
+
async UpdateFhirResource(fhir: T, ecb?: (fhir: T, error: Error) => void): Promise<T | null> {
|
|
77
77
|
if (!this.#accessLayer) {
|
|
78
78
|
return null;
|
|
79
79
|
}
|
|
@@ -86,7 +86,7 @@ export class DALFhirManagerPGRes<T> implements IDALFhirDataAccessManager<T> {
|
|
|
86
86
|
}, fhir);
|
|
87
87
|
if (retVal.error) {
|
|
88
88
|
if (ecb) {
|
|
89
|
-
ecb(retVal.error.error);
|
|
89
|
+
ecb(fhir, retVal.error.error);
|
|
90
90
|
}
|
|
91
91
|
return null;
|
|
92
92
|
} else {
|
|
@@ -94,7 +94,7 @@ export class DALFhirManagerPGRes<T> implements IDALFhirDataAccessManager<T> {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
async DeleteFhirResource(fhir: Partial<T>, ecb?: (error: Error) => void): Promise<T | null> {
|
|
97
|
+
async DeleteFhirResource(fhir: Partial<T>, ecb?: (fhir: Partial<T>, error: Error) => void): Promise<T | null> {
|
|
98
98
|
if (!this.#accessLayer) {
|
|
99
99
|
return null;
|
|
100
100
|
}
|
|
@@ -107,7 +107,7 @@ export class DALFhirManagerPGRes<T> implements IDALFhirDataAccessManager<T> {
|
|
|
107
107
|
});
|
|
108
108
|
if (retVal.error) {
|
|
109
109
|
if (ecb) {
|
|
110
|
-
ecb(retVal.error.error);
|
|
110
|
+
ecb(fhir, retVal.error.error);
|
|
111
111
|
}
|
|
112
112
|
return null;
|
|
113
113
|
} else {
|
|
@@ -115,50 +115,72 @@ export class DALFhirManagerPGRes<T> implements IDALFhirDataAccessManager<T> {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
async GetFhirResources(filters: string[], ecb?: (error: Error) => void): Promise<T[] | null> {
|
|
118
|
+
async GetFhirResources(filters: string[], ecb?: (filters: string[], error: Error) => void): Promise<T[] | null> {
|
|
119
119
|
if (!this.#accessLayer) {
|
|
120
120
|
return null;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
123
|
+
try {
|
|
124
|
+
const promArray: Promise<T[]>[] = [ ];
|
|
125
|
+
filters.forEach(filter => {
|
|
126
|
+
const prom = async (): Promise<T[]> => {
|
|
127
|
+
const retVal: T[] = [ ];
|
|
128
|
+
|
|
129
|
+
const resources = await this.#accessLayer.GetResources<T>({
|
|
130
|
+
filters: {
|
|
131
|
+
filter: `${this.#options.resourceName}_${filter}%`,
|
|
132
|
+
limit: '20',
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
const dbResources = (resources.detail as IDBResource<T>[]);
|
|
137
|
+
|
|
138
|
+
dbResources.forEach(dbResource => {
|
|
139
|
+
retVal.push(dbResource.resdesc);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
return retVal;
|
|
143
|
+
}
|
|
144
|
+
promArray.push(prom());
|
|
145
|
+
})
|
|
146
|
+
const promRetVal = await Promise.all(promArray);
|
|
147
|
+
let retVal: T[] = [ ];
|
|
148
|
+
promRetVal.forEach(prv => {
|
|
149
|
+
retVal = retVal.concat(prv);
|
|
150
|
+
});
|
|
151
|
+
return retVal;
|
|
152
|
+
} catch (error) {
|
|
153
|
+
if (ecb) {
|
|
154
|
+
ecb(filters, error as Error);
|
|
142
155
|
}
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
const promRetVal = await Promise.all(promArray);
|
|
146
|
-
let retVal: T[] = [ ];
|
|
147
|
-
promRetVal.forEach(prv => {
|
|
148
|
-
retVal = retVal.concat(prv);
|
|
149
|
-
});
|
|
150
|
-
return retVal;
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
151
158
|
}
|
|
152
159
|
|
|
153
|
-
async CreateFhirResources(fhir: T[], ecb?: (error: Error) => void): Promise<T
|
|
154
|
-
|
|
160
|
+
async CreateFhirResources(fhir: T[], ecb?: (fhir: T, error: Error) => void): Promise<(T | null)[]> {
|
|
161
|
+
const promArray: Promise<T | null>[] = [ ];
|
|
162
|
+
fhir.forEach(async (f) => {
|
|
163
|
+
promArray.push(this.CreateFhirResource(f, ecb));
|
|
164
|
+
})
|
|
165
|
+
const promRetVal = await Promise.all(promArray);
|
|
166
|
+
return promRetVal;
|
|
155
167
|
}
|
|
156
168
|
|
|
157
|
-
async UpdateFhirResources(fhir: T[], ecb?: (error: Error) => void): Promise<T
|
|
158
|
-
|
|
169
|
+
async UpdateFhirResources(fhir: T[], ecb?: (fhir: T, error: Error) => void): Promise<(T | null)[]> {
|
|
170
|
+
const promArray: Promise<T | null>[] = [ ];
|
|
171
|
+
fhir.forEach(async (f) => {
|
|
172
|
+
promArray.push(this.UpdateFhirResource(f, ecb));
|
|
173
|
+
})
|
|
174
|
+
const promRetVal = await Promise.all(promArray);
|
|
175
|
+
return promRetVal;
|
|
159
176
|
}
|
|
160
177
|
|
|
161
|
-
async DeleteFhirResources(fhir: Partial<T>[], ecb?: (error: Error) => void): Promise<T
|
|
162
|
-
|
|
178
|
+
async DeleteFhirResources(fhir: Partial<T>[], ecb?: (fhir: Partial<T>, error: Error) => void): Promise<(T | null)[]> {
|
|
179
|
+
const promArray: Promise<T | null>[] = [ ];
|
|
180
|
+
fhir.forEach(async (f) => {
|
|
181
|
+
promArray.push(this.DeleteFhirResource(f, ecb));
|
|
182
|
+
})
|
|
183
|
+
const promRetVal = await Promise.all(promArray);
|
|
184
|
+
return promRetVal;
|
|
163
185
|
}
|
|
164
186
|
}
|
|
@@ -40,7 +40,7 @@ describe("Test hl7 fhir resource data access layer - PGResEntity", () =>
|
|
|
40
40
|
await testHelpers.TestFhirPerson(fhirManager.fhirDataAccessManager);
|
|
41
41
|
}, 30000);
|
|
42
42
|
|
|
43
|
-
test('Testing
|
|
43
|
+
test('Testing Persons with Search', async () => {
|
|
44
44
|
const iterations = 10;
|
|
45
45
|
expect.assertions(iterations + 1);
|
|
46
46
|
await testHelpers.AddFhirPersons(fhirManager.fhirDataAccessManager, iterations);
|
|
@@ -51,6 +51,39 @@ describe("Test hl7 fhir resource data access layer - PGResEntity", () =>
|
|
|
51
51
|
console.log(chalk.cyan(JSON.stringify(fhirResources)));
|
|
52
52
|
}, 30000);
|
|
53
53
|
|
|
54
|
+
test('Testing Persons with Bulk Insert', async () => {
|
|
55
|
+
const iterations = 10;
|
|
56
|
+
expect.assertions(2);
|
|
57
|
+
await testHelpers.AddFhirPersonsByArray(fhirManager.fhirDataAccessManager, iterations);
|
|
58
|
+
|
|
59
|
+
const fhirResources = await fhirManager.fhirDataAccessManager.GetFhirResources(['bulk_']);
|
|
60
|
+
expect(fhirResources?.length).toEqual(iterations);
|
|
61
|
+
|
|
62
|
+
console.log(chalk.rgb(133, 161, 142)(JSON.stringify(fhirResources)));
|
|
63
|
+
}, 30000);
|
|
64
|
+
|
|
65
|
+
test('Testing Persons with Bulk Update', async () => {
|
|
66
|
+
const iterations = 10;
|
|
67
|
+
expect.assertions(2);
|
|
68
|
+
await testHelpers.UpdateFhirPersonsByArray(fhirManager.fhirDataAccessManager, iterations);
|
|
69
|
+
|
|
70
|
+
const fhirResources = await fhirManager.fhirDataAccessManager.GetFhirResources(['bulk_']);
|
|
71
|
+
expect(fhirResources?.length).toEqual(iterations);
|
|
72
|
+
|
|
73
|
+
console.log(chalk.rgb(157, 133, 161)(JSON.stringify(fhirResources)));
|
|
74
|
+
}, 30000);
|
|
75
|
+
|
|
76
|
+
test('Testing Persons with Bulk Delete', async () => {
|
|
77
|
+
const iterations = 7;
|
|
78
|
+
expect.assertions(2);
|
|
79
|
+
await testHelpers.DeleteFhirPersonsByArray(fhirManager.fhirDataAccessManager, iterations);
|
|
80
|
+
|
|
81
|
+
const fhirResources = await fhirManager.fhirDataAccessManager.GetFhirResources(['bulk_']);
|
|
82
|
+
expect(fhirResources?.length).toEqual(10 - iterations);
|
|
83
|
+
|
|
84
|
+
console.log(chalk.rgb(105, 97, 50)(JSON.stringify(fhirResources)));
|
|
85
|
+
}, 30000);
|
|
86
|
+
|
|
54
87
|
afterAll(async () =>
|
|
55
88
|
{
|
|
56
89
|
fhirManager.fhirDataAccessManager.Stop();
|