@nsshunt/stsappframework 3.1.146 → 3.1.148
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/dalFhirManagerBase.js +63 -0
- package/dist/fhir/dalFhirManagerBase.js.map +1 -0
- package/dist/fhir/dalFhirManagerIORedisJson.js +137 -88
- package/dist/fhir/dalFhirManagerIORedisJson.js.map +1 -1
- package/dist/fhir/dalFhirManagerIORedisJson.test.js +27 -1
- package/dist/fhir/dalFhirManagerIORedisJson.test.js.map +1 -1
- package/dist/fhir/dalFhirManagerPGRes.js +43 -53
- 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 +50 -57
- 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 +104 -79
- package/dist/fhir/dalFhirManagerRedisJson.js.map +1 -1
- package/dist/fhir/dalFhirManagerRedisJson.test.js +27 -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 +14 -14
- package/src/fhir/dalFhirManagerBase.ts +77 -0
- package/src/fhir/dalFhirManagerIORedisJson.test.ts +37 -1
- package/src/fhir/dalFhirManagerIORedisJson.ts +139 -97
- package/src/fhir/dalFhirManagerPGRes.test.ts +34 -1
- package/src/fhir/dalFhirManagerPGRes.ts +52 -69
- package/src/fhir/dalFhirManagerPGResEntity.test.ts +34 -1
- package/src/fhir/dalFhirManagerPGResEntity.ts +57 -88
- package/src/fhir/dalFhirManagerRedisJson.test.ts +37 -1
- package/src/fhir/dalFhirManagerRedisJson.ts +103 -88
- package/src/fhir/dalFhirTestHelpers.ts +84 -0
- package/types/fhir/STSFhirTypes.d.ts +13 -14
- package/types/fhir/STSFhirTypes.d.ts.map +1 -1
- package/types/fhir/dalFhirManagerBase.d.ts +19 -0
- package/types/fhir/dalFhirManagerBase.d.ts.map +1 -0
- package/types/fhir/dalFhirManagerIORedisJson.d.ts +10 -11
- package/types/fhir/dalFhirManagerIORedisJson.d.ts.map +1 -1
- package/types/fhir/dalFhirManagerPGRes.d.ts +7 -12
- package/types/fhir/dalFhirManagerPGRes.d.ts.map +1 -1
- package/types/fhir/dalFhirManagerPGResEntity.d.ts +7 -11
- package/types/fhir/dalFhirManagerPGResEntity.d.ts.map +1 -1
- package/types/fhir/dalFhirManagerRedisJson.d.ts +7 -11
- 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
|
@@ -6,22 +6,14 @@ import { Redis, RedisOptions } from "ioredis";
|
|
|
6
6
|
|
|
7
7
|
import chalk from 'chalk'
|
|
8
8
|
import { JSONObject } from '@nsshunt/stsutils';
|
|
9
|
+
import { DALFhirManagerBase } from './dalFhirManagerBase';
|
|
9
10
|
|
|
10
|
-
export class DALFhirManagerIORedisJson<T> implements IDALFhirDataAccessManager<T> {
|
|
11
|
-
#options: IFhirManagerRedisJsonOptions;
|
|
11
|
+
export class DALFhirManagerIORedisJson<T> extends DALFhirManagerBase<T> implements IDALFhirDataAccessManager<T> {
|
|
12
12
|
#redis: Redis | null = null;
|
|
13
13
|
#indexName: string = 'idx:stsfhirresindex';
|
|
14
14
|
|
|
15
15
|
constructor(options: IFhirManagerRedisJsonOptions) {
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
get options() {
|
|
20
|
-
return this.#options;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
set options(options: IFhirManagerRedisJsonOptions) {
|
|
24
|
-
this.#options = options;
|
|
16
|
+
super(options);
|
|
25
17
|
}
|
|
26
18
|
|
|
27
19
|
async Start() {
|
|
@@ -30,7 +22,7 @@ export class DALFhirManagerIORedisJson<T> implements IDALFhirDataAccessManager<T
|
|
|
30
22
|
maxRetriesPerRequest: 20
|
|
31
23
|
}
|
|
32
24
|
|
|
33
|
-
this.#redis = new Redis(this
|
|
25
|
+
this.#redis = new Redis((this.options as IFhirManagerRedisJsonOptions).redisUrl, redisOptions);
|
|
34
26
|
await this.#CreateIndex();
|
|
35
27
|
}
|
|
36
28
|
|
|
@@ -56,7 +48,7 @@ export class DALFhirManagerIORedisJson<T> implements IDALFhirDataAccessManager<T
|
|
|
56
48
|
}
|
|
57
49
|
|
|
58
50
|
try {
|
|
59
|
-
const retVal = await this.#redis.call('FT.CREATE', this.#indexName, 'ON', 'HASH', 'PREFIX', '1', `${this
|
|
51
|
+
const retVal = await this.#redis.call('FT.CREATE', this.#indexName, 'ON', 'HASH', 'PREFIX', '1', `${this.options.resourceName}_`,
|
|
60
52
|
'SCHEMA', 'id', 'TEXT', 'SORTABLE');
|
|
61
53
|
console.log(retVal);
|
|
62
54
|
} catch (error) {
|
|
@@ -69,7 +61,7 @@ export class DALFhirManagerIORedisJson<T> implements IDALFhirDataAccessManager<T
|
|
|
69
61
|
return null;
|
|
70
62
|
}
|
|
71
63
|
|
|
72
|
-
const query = `@id:${this
|
|
64
|
+
const query = `@id:${this.options.resourceName}_${id}*`;
|
|
73
65
|
|
|
74
66
|
const retVal: any = await this.#redis.call('FT.SEARCH', this.#indexName, query,
|
|
75
67
|
'RETURN', '2', 'id', 'data', 'SORTBY', 'id', 'DESC', 'LIMIT', '0', '100');
|
|
@@ -78,141 +70,191 @@ export class DALFhirManagerIORedisJson<T> implements IDALFhirDataAccessManager<T
|
|
|
78
70
|
}
|
|
79
71
|
|
|
80
72
|
GetResourceType(fhir: Partial<T>): string {
|
|
81
|
-
return `${this
|
|
73
|
+
return `${this.options.resourceName}_${(fhir as Partial<IDomainResource>).id}`;
|
|
82
74
|
}
|
|
83
75
|
|
|
84
|
-
async GetFhirResource(fhir: Partial<T>, ecb?: (error: Error) => void): Promise<T | null> {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
ecb
|
|
76
|
+
async GetFhirResource(fhir: Partial<T>, ecb?: (fhir: Partial<T>, error: Error) => void): Promise<T | null> {
|
|
77
|
+
try {
|
|
78
|
+
if (this.#redis) {
|
|
79
|
+
const retValRaw = await this.#redis.hgetall(this.GetResourceType(fhir))
|
|
80
|
+
if (retValRaw) {
|
|
81
|
+
try {
|
|
82
|
+
const { id, data } = retValRaw;
|
|
83
|
+
return JSON.parse(data) as T;
|
|
84
|
+
} catch (error: unknown) {
|
|
85
|
+
if (ecb) {
|
|
86
|
+
ecb(fhir, error as Error);
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
94
89
|
}
|
|
90
|
+
} else {
|
|
95
91
|
return null;
|
|
96
92
|
}
|
|
97
93
|
} else {
|
|
98
94
|
return null;
|
|
99
95
|
}
|
|
100
|
-
}
|
|
96
|
+
} catch (error) {
|
|
97
|
+
if (ecb) {
|
|
98
|
+
ecb(fhir, error as Error);
|
|
99
|
+
}
|
|
101
100
|
return null;
|
|
102
101
|
}
|
|
103
102
|
}
|
|
104
103
|
|
|
105
104
|
// 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
|
-
|
|
105
|
+
async CreateFhirResource(fhir: T, ecb?: (fhir: T, error: Error) => void): Promise<T | null> {
|
|
106
|
+
try {
|
|
107
|
+
if (this.#redis) {
|
|
108
|
+
const record = {
|
|
109
|
+
id: this.GetResourceType(fhir),
|
|
110
|
+
data: JSON.stringify(fhir)
|
|
111
|
+
} as any;
|
|
112
112
|
|
|
113
|
-
|
|
113
|
+
const retVal = await this.#redis.hmset(this.GetResourceType(fhir), record);
|
|
114
114
|
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
if (retVal) {
|
|
116
|
+
return fhir;
|
|
117
|
+
} else {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
117
120
|
} else {
|
|
118
121
|
return null;
|
|
119
122
|
}
|
|
120
|
-
}
|
|
123
|
+
} catch (error) {
|
|
124
|
+
if (ecb) {
|
|
125
|
+
ecb(fhir, error as Error);
|
|
126
|
+
}
|
|
121
127
|
return null;
|
|
122
128
|
}
|
|
123
129
|
}
|
|
124
130
|
|
|
125
131
|
// 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
|
-
|
|
132
|
+
async UpdateFhirResource(fhir: T, ecb?: (fhir: T, error: Error) => void): Promise<T | null> {
|
|
133
|
+
try {
|
|
134
|
+
if (this.#redis) {
|
|
135
|
+
const record = {
|
|
136
|
+
id: this.GetResourceType(fhir),
|
|
137
|
+
data: JSON.stringify(fhir)
|
|
138
|
+
} as any;
|
|
132
139
|
|
|
133
|
-
|
|
140
|
+
const retVal = await this.#redis.hmset(this.GetResourceType(fhir), record);
|
|
134
141
|
|
|
135
|
-
|
|
136
|
-
|
|
142
|
+
if (retVal) {
|
|
143
|
+
return fhir;
|
|
144
|
+
} else {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
137
147
|
} else {
|
|
138
148
|
return null;
|
|
139
149
|
}
|
|
140
|
-
}
|
|
150
|
+
} catch (error) {
|
|
151
|
+
if (ecb) {
|
|
152
|
+
ecb(fhir, error as Error);
|
|
153
|
+
}
|
|
141
154
|
return null;
|
|
142
155
|
}
|
|
143
156
|
}
|
|
144
157
|
|
|
145
158
|
// 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
|
-
|
|
159
|
+
async DeleteFhirResource(fhir: Partial<T>, ecb?: (fhir: Partial<T>, error: Error) => void): Promise<T | null> {
|
|
160
|
+
try {
|
|
161
|
+
if (this.#redis) {
|
|
162
|
+
const deleteResource = await this.GetFhirResource(fhir);
|
|
163
|
+
if (deleteResource) {
|
|
164
|
+
const retVal = await this.#redis.del(this.GetResourceType(fhir));
|
|
165
|
+
if (retVal) {
|
|
166
|
+
return deleteResource;
|
|
167
|
+
} else {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
153
170
|
} else {
|
|
154
171
|
return null;
|
|
155
172
|
}
|
|
156
173
|
} else {
|
|
157
174
|
return null;
|
|
158
175
|
}
|
|
159
|
-
}
|
|
176
|
+
} catch (error) {
|
|
177
|
+
if (ecb) {
|
|
178
|
+
ecb(fhir, error as Error);
|
|
179
|
+
}
|
|
160
180
|
return null;
|
|
161
181
|
}
|
|
162
182
|
}
|
|
163
183
|
|
|
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
|
-
const id = retVal[index++];
|
|
180
|
-
obj[id] = { }
|
|
181
|
-
const values = retVal[index++];
|
|
182
|
-
let dataIndex = 0;
|
|
183
|
-
for (let j=0; j < values.length / 2; j++) {
|
|
184
|
-
const field = values[dataIndex++];
|
|
185
|
-
if ((field as string).localeCompare('data') === 0) {
|
|
186
|
-
const value = JSON.parse(values[dataIndex++]);
|
|
187
|
-
obj[id] = value;
|
|
188
|
-
} else {
|
|
189
|
-
dataIndex++;
|
|
184
|
+
async GetFhirResources(filters: string[], ecb?: (filters: string[], error: Error) => void): Promise<T[] | null> {
|
|
185
|
+
try {
|
|
186
|
+
const promArray: Promise<T[]>[] = [ ];
|
|
187
|
+
filters.forEach(filter => {
|
|
188
|
+
const prom = async (): Promise<T[]> => {
|
|
189
|
+
const retValArray: T[] = [ ];
|
|
190
|
+
const retVal = await this.#SearchBy(filter);
|
|
191
|
+
// First index is the total number of records in the search (does not consider limit)
|
|
192
|
+
//const listLength = retVal[0];
|
|
193
|
+
|
|
194
|
+
let index = 1;
|
|
195
|
+
const obj: JSONObject = { };
|
|
196
|
+
for (;;) {
|
|
197
|
+
if (index >= retVal.length) {
|
|
198
|
+
break;
|
|
190
199
|
}
|
|
200
|
+
const id = retVal[index++];
|
|
201
|
+
obj[id] = { }
|
|
202
|
+
const values = retVal[index++];
|
|
203
|
+
let dataIndex = 0;
|
|
204
|
+
for (let j=0; j < values.length / 2; j++) {
|
|
205
|
+
const field = values[dataIndex++];
|
|
206
|
+
if ((field as string).localeCompare('data') === 0) {
|
|
207
|
+
const value = JSON.parse(values[dataIndex++]);
|
|
208
|
+
obj[id] = value;
|
|
209
|
+
} else {
|
|
210
|
+
dataIndex++;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
retValArray.push(obj[id]);
|
|
191
214
|
}
|
|
192
|
-
retValArray
|
|
215
|
+
return retValArray;
|
|
193
216
|
}
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
promArray.push(prom());
|
|
197
|
-
});
|
|
217
|
+
promArray.push(prom());
|
|
218
|
+
});
|
|
198
219
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
220
|
+
const promRetVal = await Promise.all(promArray);
|
|
221
|
+
let retVal: T[] = [ ];
|
|
222
|
+
promRetVal.forEach(prv => {
|
|
223
|
+
retVal = retVal.concat(prv);
|
|
224
|
+
});
|
|
225
|
+
return retVal;
|
|
226
|
+
} catch (error) {
|
|
227
|
+
if (ecb) {
|
|
228
|
+
ecb(filters, error as Error);
|
|
229
|
+
}
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
205
232
|
}
|
|
206
233
|
|
|
207
|
-
async CreateFhirResources(fhir: T[], ecb?: (error: Error) => void): Promise<T
|
|
208
|
-
|
|
234
|
+
async CreateFhirResources(fhir: T[], ecb?: (fhir: T, error: Error) => void): Promise<(T | null)[]> {
|
|
235
|
+
const promArray: Promise<T | null>[] = [ ];
|
|
236
|
+
fhir.forEach(async (f) => {
|
|
237
|
+
promArray.push(this.CreateFhirResource(f, ecb));
|
|
238
|
+
})
|
|
239
|
+
const promRetVal = await Promise.all(promArray);
|
|
240
|
+
return promRetVal;
|
|
209
241
|
}
|
|
210
242
|
|
|
211
|
-
async UpdateFhirResources(fhir: T[], ecb?: (error: Error) => void): Promise<T
|
|
212
|
-
|
|
243
|
+
async UpdateFhirResources(fhir: T[], ecb?: (fhir: T, error: Error) => void): Promise<(T | null)[]> {
|
|
244
|
+
const promArray: Promise<T | null>[] = [ ];
|
|
245
|
+
fhir.forEach(async (f) => {
|
|
246
|
+
promArray.push(this.UpdateFhirResource(f, ecb));
|
|
247
|
+
})
|
|
248
|
+
const promRetVal = await Promise.all(promArray);
|
|
249
|
+
return promRetVal;
|
|
213
250
|
}
|
|
214
251
|
|
|
215
|
-
async DeleteFhirResources(fhir: Partial<T>[], ecb?: (error: Error) => void): Promise<T
|
|
216
|
-
|
|
252
|
+
async DeleteFhirResources(fhir: Partial<T>[], ecb?: (fhir: Partial<T>, error: Error) => void): Promise<(T | null)[]> {
|
|
253
|
+
const promArray: Promise<T | null>[] = [ ];
|
|
254
|
+
fhir.forEach(async (f) => {
|
|
255
|
+
promArray.push(this.DeleteFhirResource(f, ecb));
|
|
256
|
+
})
|
|
257
|
+
const promRetVal = await Promise.all(promArray);
|
|
258
|
+
return promRetVal;
|
|
217
259
|
}
|
|
218
260
|
}
|
|
@@ -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();
|
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
/* eslint @typescript-eslint/no-unused-vars: 0 */ // --> OFF
|
|
2
|
-
import { IDBAccessLayer, IDBResource
|
|
2
|
+
import { IDBAccessLayer, IDBResource } from '@nsshunt/stsdatamanagement'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { IDALFhirDataAccessManager, IFhirManagerPGResOptions } from './STSFhirTypes'
|
|
5
|
+
import { DALFhirManagerBase } from './dalFhirManagerBase';
|
|
5
6
|
|
|
6
|
-
export class DALFhirManagerPGRes<T> implements IDALFhirDataAccessManager<T> {
|
|
7
|
-
#options: IFhirManagerPGResOptions;
|
|
7
|
+
export class DALFhirManagerPGRes<T> extends DALFhirManagerBase<T> implements IDALFhirDataAccessManager<T> {
|
|
8
8
|
#accessLayer: IDBAccessLayer;
|
|
9
9
|
|
|
10
10
|
constructor(options: IFhirManagerPGResOptions) {
|
|
11
|
-
|
|
12
|
-
this.#accessLayer = this
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
get options() {
|
|
16
|
-
return this.#options;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
set options(options: IFhirManagerPGResOptions) {
|
|
20
|
-
this.#options = options;
|
|
11
|
+
super(options);
|
|
12
|
+
this.#accessLayer = (this.options as IFhirManagerPGResOptions).accessLayer;
|
|
21
13
|
}
|
|
22
14
|
|
|
23
15
|
async Start() {
|
|
@@ -28,11 +20,7 @@ export class DALFhirManagerPGRes<T> implements IDALFhirDataAccessManager<T> {
|
|
|
28
20
|
|
|
29
21
|
}
|
|
30
22
|
|
|
31
|
-
|
|
32
|
-
return `${this.#options.resourceName}_${(fhir as Partial<IDomainResource>).id}`;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async GetFhirResource(fhir: Partial<T>, ecb?: (error: Error) => void): Promise<T | null> {
|
|
23
|
+
async GetFhirResource(fhir: Partial<T>, ecb?: (fhir: Partial<T>, error: Error) => void): Promise<T | null> {
|
|
36
24
|
if (!this.#accessLayer) {
|
|
37
25
|
return null;
|
|
38
26
|
}
|
|
@@ -44,7 +32,7 @@ export class DALFhirManagerPGRes<T> implements IDALFhirDataAccessManager<T> {
|
|
|
44
32
|
});
|
|
45
33
|
if (retVal.error) {
|
|
46
34
|
if (ecb) {
|
|
47
|
-
ecb(retVal.error.error);
|
|
35
|
+
ecb(fhir, retVal.error.error);
|
|
48
36
|
}
|
|
49
37
|
return null;
|
|
50
38
|
} else {
|
|
@@ -52,20 +40,20 @@ export class DALFhirManagerPGRes<T> implements IDALFhirDataAccessManager<T> {
|
|
|
52
40
|
}
|
|
53
41
|
}
|
|
54
42
|
|
|
55
|
-
async CreateFhirResource(fhir: T, ecb?: (error: Error) => void): Promise<T | null> {
|
|
43
|
+
async CreateFhirResource(fhir: T, ecb?: (fhir: T, error: Error) => void): Promise<T | null> {
|
|
56
44
|
if (!this.#accessLayer) {
|
|
57
45
|
return null;
|
|
58
46
|
}
|
|
59
47
|
|
|
60
48
|
const retVal = await this.#accessLayer.CreateResource<T>({
|
|
61
49
|
filters: {
|
|
62
|
-
dbactionuser: this
|
|
50
|
+
dbactionuser: this.options.dbactionuser,
|
|
63
51
|
resname: this.GetResourceType(fhir)
|
|
64
52
|
}
|
|
65
53
|
}, fhir);
|
|
66
54
|
if (retVal.error) {
|
|
67
55
|
if (ecb) {
|
|
68
|
-
ecb(retVal.error.error);
|
|
56
|
+
ecb(fhir, retVal.error.error);
|
|
69
57
|
}
|
|
70
58
|
return null;
|
|
71
59
|
} else {
|
|
@@ -73,20 +61,20 @@ export class DALFhirManagerPGRes<T> implements IDALFhirDataAccessManager<T> {
|
|
|
73
61
|
}
|
|
74
62
|
}
|
|
75
63
|
|
|
76
|
-
async UpdateFhirResource(fhir: T, ecb?: (error: Error) => void): Promise<T | null> {
|
|
64
|
+
async UpdateFhirResource(fhir: T, ecb?: (fhir: T, error: Error) => void): Promise<T | null> {
|
|
77
65
|
if (!this.#accessLayer) {
|
|
78
66
|
return null;
|
|
79
67
|
}
|
|
80
68
|
|
|
81
69
|
const retVal = await this.#accessLayer.UpdateResource<T>({
|
|
82
70
|
filters: {
|
|
83
|
-
dbactionuser: this
|
|
71
|
+
dbactionuser: this.options.dbactionuser,
|
|
84
72
|
resname: this.GetResourceType(fhir)
|
|
85
73
|
}
|
|
86
74
|
}, fhir);
|
|
87
75
|
if (retVal.error) {
|
|
88
76
|
if (ecb) {
|
|
89
|
-
ecb(retVal.error.error);
|
|
77
|
+
ecb(fhir, retVal.error.error);
|
|
90
78
|
}
|
|
91
79
|
return null;
|
|
92
80
|
} else {
|
|
@@ -94,20 +82,20 @@ export class DALFhirManagerPGRes<T> implements IDALFhirDataAccessManager<T> {
|
|
|
94
82
|
}
|
|
95
83
|
}
|
|
96
84
|
|
|
97
|
-
async DeleteFhirResource(fhir: Partial<T>, ecb?: (error: Error) => void): Promise<T | null> {
|
|
85
|
+
async DeleteFhirResource(fhir: Partial<T>, ecb?: (fhir: Partial<T>, error: Error) => void): Promise<T | null> {
|
|
98
86
|
if (!this.#accessLayer) {
|
|
99
87
|
return null;
|
|
100
88
|
}
|
|
101
89
|
|
|
102
90
|
const retVal = await this.#accessLayer.DeleteResource<T>({
|
|
103
91
|
filters: {
|
|
104
|
-
dbactionuser: this
|
|
92
|
+
dbactionuser: this.options.dbactionuser,
|
|
105
93
|
resname: this.GetResourceType(fhir)
|
|
106
94
|
}
|
|
107
95
|
});
|
|
108
96
|
if (retVal.error) {
|
|
109
97
|
if (ecb) {
|
|
110
|
-
ecb(retVal.error.error);
|
|
98
|
+
ecb(fhir, retVal.error.error);
|
|
111
99
|
}
|
|
112
100
|
return null;
|
|
113
101
|
} else {
|
|
@@ -115,50 +103,45 @@ export class DALFhirManagerPGRes<T> implements IDALFhirDataAccessManager<T> {
|
|
|
115
103
|
}
|
|
116
104
|
}
|
|
117
105
|
|
|
118
|
-
async GetFhirResources(filters: string[], ecb?: (error: Error) => void): Promise<T[] | null> {
|
|
106
|
+
async GetFhirResources(filters: string[], ecb?: (filters: string[], error: Error) => void): Promise<T[] | null> {
|
|
119
107
|
if (!this.#accessLayer) {
|
|
120
108
|
return null;
|
|
121
109
|
}
|
|
122
110
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
111
|
+
try {
|
|
112
|
+
const promArray: Promise<T[]>[] = [ ];
|
|
113
|
+
filters.forEach(filter => {
|
|
114
|
+
const prom = async (): Promise<T[]> => {
|
|
115
|
+
const retVal: T[] = [ ];
|
|
116
|
+
|
|
117
|
+
const resources = await this.#accessLayer.GetResources<T>({
|
|
118
|
+
filters: {
|
|
119
|
+
filter: `${this.options.resourceName}_${filter}%`,
|
|
120
|
+
limit: '20',
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
const dbResources = (resources.detail as IDBResource<T>[]);
|
|
125
|
+
|
|
126
|
+
dbResources.forEach(dbResource => {
|
|
127
|
+
retVal.push(dbResource.resdesc);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
return retVal;
|
|
131
|
+
}
|
|
132
|
+
promArray.push(prom());
|
|
133
|
+
})
|
|
134
|
+
const promRetVal = await Promise.all(promArray);
|
|
135
|
+
let retVal: T[] = [ ];
|
|
136
|
+
promRetVal.forEach(prv => {
|
|
137
|
+
retVal = retVal.concat(prv);
|
|
138
|
+
});
|
|
139
|
+
return retVal;
|
|
140
|
+
} catch (error) {
|
|
141
|
+
if (ecb) {
|
|
142
|
+
ecb(filters, error as Error);
|
|
142
143
|
}
|
|
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;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
async CreateFhirResources(fhir: T[], ecb?: (error: Error) => void): Promise<T[] | null> {
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
async UpdateFhirResources(fhir: T[], ecb?: (error: Error) => void): Promise<T[] | null> {
|
|
158
|
-
return null
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
async DeleteFhirResources(fhir: Partial<T>[], ecb?: (error: Error) => void): Promise<T[] | null> {
|
|
162
|
-
return null;
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
163
146
|
}
|
|
164
147
|
}
|
|
@@ -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();
|