@nsshunt/stsappframework 3.1.149 → 3.1.150
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/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/src/index.ts +0 -2
- package/types/index.d.ts +0 -2
- package/types/index.d.ts.map +1 -1
- package/dist/fhir/STSFhirTypes.js +0 -11
- package/dist/fhir/STSFhirTypes.js.map +0 -1
- package/dist/fhir/dalFhirManager.js +0 -34
- package/dist/fhir/dalFhirManager.js.map +0 -1
- package/dist/fhir/dalFhirManagerBase.js +0 -63
- package/dist/fhir/dalFhirManagerBase.js.map +0 -1
- package/dist/fhir/dalFhirManagerIORedisJson.js +0 -250
- package/dist/fhir/dalFhirManagerIORedisJson.js.map +0 -1
- package/dist/fhir/dalFhirManagerIORedisJson.test.js +0 -73
- package/dist/fhir/dalFhirManagerIORedisJson.test.js.map +0 -1
- package/dist/fhir/dalFhirManagerPGRes.js +0 -133
- package/dist/fhir/dalFhirManagerPGRes.js.map +0 -1
- package/dist/fhir/dalFhirManagerPGRes.test.js +0 -72
- package/dist/fhir/dalFhirManagerPGRes.test.js.map +0 -1
- package/dist/fhir/dalFhirManagerPGResEntity.js +0 -166
- package/dist/fhir/dalFhirManagerPGResEntity.js.map +0 -1
- package/dist/fhir/dalFhirManagerPGResEntity.test.js +0 -73
- package/dist/fhir/dalFhirManagerPGResEntity.test.js.map +0 -1
- package/dist/fhir/dalFhirManagerRedisJson.js +0 -226
- package/dist/fhir/dalFhirManagerRedisJson.js.map +0 -1
- package/dist/fhir/dalFhirManagerRedisJson.test.js +0 -73
- package/dist/fhir/dalFhirManagerRedisJson.test.js.map +0 -1
- package/dist/fhir/dalFhirTestHelpers.js +0 -227
- package/dist/fhir/dalFhirTestHelpers.js.map +0 -1
- package/src/fhir/STSFhirTypes.ts +0 -541
- package/src/fhir/dalFhirManager.ts +0 -33
- package/src/fhir/dalFhirManagerBase.ts +0 -77
- package/src/fhir/dalFhirManagerIORedisJson.test.ts +0 -94
- package/src/fhir/dalFhirManagerIORedisJson.ts +0 -260
- package/src/fhir/dalFhirManagerPGRes.test.ts +0 -91
- package/src/fhir/dalFhirManagerPGRes.ts +0 -147
- package/src/fhir/dalFhirManagerPGResEntity.test.ts +0 -93
- package/src/fhir/dalFhirManagerPGResEntity.ts +0 -183
- package/src/fhir/dalFhirManagerRedisJson.test.ts +0 -93
- package/src/fhir/dalFhirManagerRedisJson.ts +0 -230
- package/src/fhir/dalFhirTestHelpers.ts +0 -276
- package/types/fhir/STSFhirTypes.d.ts +0 -351
- package/types/fhir/STSFhirTypes.d.ts.map +0 -1
- package/types/fhir/dalFhirManager.d.ts +0 -7
- package/types/fhir/dalFhirManager.d.ts.map +0 -1
- package/types/fhir/dalFhirManagerBase.d.ts +0 -19
- package/types/fhir/dalFhirManagerBase.d.ts.map +0 -1
- package/types/fhir/dalFhirManagerIORedisJson.d.ts +0 -18
- package/types/fhir/dalFhirManagerIORedisJson.d.ts.map +0 -1
- package/types/fhir/dalFhirManagerIORedisJson.test.d.ts +0 -2
- package/types/fhir/dalFhirManagerIORedisJson.test.d.ts.map +0 -1
- package/types/fhir/dalFhirManagerPGRes.d.ts +0 -14
- package/types/fhir/dalFhirManagerPGRes.d.ts.map +0 -1
- package/types/fhir/dalFhirManagerPGRes.test.d.ts +0 -2
- package/types/fhir/dalFhirManagerPGRes.test.d.ts.map +0 -1
- package/types/fhir/dalFhirManagerPGResEntity.d.ts +0 -14
- package/types/fhir/dalFhirManagerPGResEntity.d.ts.map +0 -1
- package/types/fhir/dalFhirManagerPGResEntity.test.d.ts +0 -2
- package/types/fhir/dalFhirManagerPGResEntity.test.d.ts.map +0 -1
- package/types/fhir/dalFhirManagerRedisJson.d.ts +0 -15
- package/types/fhir/dalFhirManagerRedisJson.d.ts.map +0 -1
- package/types/fhir/dalFhirManagerRedisJson.test.d.ts +0 -2
- package/types/fhir/dalFhirManagerRedisJson.test.d.ts.map +0 -1
- package/types/fhir/dalFhirTestHelpers.d.ts +0 -20
- package/types/fhir/dalFhirTestHelpers.d.ts.map +0 -1
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
|
|
2
|
-
import { beforeAll, afterAll, test, describe, expect } from 'vitest';
|
|
3
|
-
|
|
4
|
-
import { IPerson, IFhirPersistenceType } from './STSFhirTypes'
|
|
5
|
-
|
|
6
|
-
import { TestHelpers } from './dalFhirTestHelpers'
|
|
7
|
-
|
|
8
|
-
import { JestSleep } from '@nsshunt/stsutils'
|
|
9
|
-
|
|
10
|
-
import { DALFhirManager } from './dalFhirManager'
|
|
11
|
-
|
|
12
|
-
import { SYSTEM_USER_ID } from '@nsshunt/stsdatamanagement'
|
|
13
|
-
|
|
14
|
-
import chalk from 'chalk'
|
|
15
|
-
|
|
16
|
-
describe.skip("Test hl7 fhir resource data access layer - RedisJson", () =>
|
|
17
|
-
{
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
-
let testHelpers: TestHelpers;
|
|
20
|
-
let fhirManager: DALFhirManager<IPerson>
|
|
21
|
-
|
|
22
|
-
beforeAll(async () =>
|
|
23
|
-
{
|
|
24
|
-
testHelpers = new TestHelpers();
|
|
25
|
-
await testHelpers.StartRedis();
|
|
26
|
-
|
|
27
|
-
fhirManager = new DALFhirManager({
|
|
28
|
-
persistenceType: IFhirPersistenceType.ioredisJson,
|
|
29
|
-
persistenceTypeOptions: {
|
|
30
|
-
resourceName: 'STSFhirPerson',
|
|
31
|
-
dbactionuser: SYSTEM_USER_ID,
|
|
32
|
-
redisUrl: testHelpers.ioRedisMessageProcessorUrl
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
await fhirManager.fhirDataAccessManager.Start();
|
|
37
|
-
}, 30000);
|
|
38
|
-
|
|
39
|
-
test('Testing Person', async () => {
|
|
40
|
-
expect.assertions(6);
|
|
41
|
-
await testHelpers.TestFhirPerson(fhirManager.fhirDataAccessManager);
|
|
42
|
-
}, 30000);
|
|
43
|
-
|
|
44
|
-
test('Testing Persons with Search', async () => {
|
|
45
|
-
const iterations = 10;
|
|
46
|
-
expect.assertions(iterations + 1);
|
|
47
|
-
await testHelpers.AddFhirPersons(fhirManager.fhirDataAccessManager, iterations);
|
|
48
|
-
|
|
49
|
-
const fhirResources = await fhirManager.fhirDataAccessManager.GetFhirResources(['']);
|
|
50
|
-
expect(fhirResources?.length).toEqual(iterations);
|
|
51
|
-
|
|
52
|
-
console.log(chalk.magenta(JSON.stringify(fhirResources)));
|
|
53
|
-
}, 30000);
|
|
54
|
-
|
|
55
|
-
test('Testing Persons with Bulk Insert', async () => {
|
|
56
|
-
const iterations = 10;
|
|
57
|
-
expect.assertions(2);
|
|
58
|
-
await testHelpers.AddFhirPersonsByArray(fhirManager.fhirDataAccessManager, iterations);
|
|
59
|
-
|
|
60
|
-
const fhirResources = await fhirManager.fhirDataAccessManager.GetFhirResources(['bulk_']);
|
|
61
|
-
expect(fhirResources?.length).toEqual(iterations);
|
|
62
|
-
|
|
63
|
-
console.log(chalk.rgb(133, 161, 142)(JSON.stringify(fhirResources)));
|
|
64
|
-
}, 30000);
|
|
65
|
-
|
|
66
|
-
test('Testing Persons with Bulk Update', async () => {
|
|
67
|
-
const iterations = 10;
|
|
68
|
-
expect.assertions(2);
|
|
69
|
-
await testHelpers.UpdateFhirPersonsByArray(fhirManager.fhirDataAccessManager, iterations);
|
|
70
|
-
|
|
71
|
-
const fhirResources = await fhirManager.fhirDataAccessManager.GetFhirResources(['bulk_']);
|
|
72
|
-
expect(fhirResources?.length).toEqual(iterations);
|
|
73
|
-
|
|
74
|
-
console.log(chalk.rgb(157, 133, 161)(JSON.stringify(fhirResources)));
|
|
75
|
-
}, 30000);
|
|
76
|
-
|
|
77
|
-
test('Testing Persons with Bulk Delete', async () => {
|
|
78
|
-
const iterations = 7;
|
|
79
|
-
expect.assertions(2);
|
|
80
|
-
await testHelpers.DeleteFhirPersonsByArray(fhirManager.fhirDataAccessManager, iterations);
|
|
81
|
-
|
|
82
|
-
const fhirResources = await fhirManager.fhirDataAccessManager.GetFhirResources(['bulk_']);
|
|
83
|
-
expect(fhirResources?.length).toEqual(10 - iterations);
|
|
84
|
-
|
|
85
|
-
console.log(chalk.rgb(105, 97, 50)(JSON.stringify(fhirResources)));
|
|
86
|
-
}, 30000);
|
|
87
|
-
|
|
88
|
-
afterAll(async () =>
|
|
89
|
-
{
|
|
90
|
-
await fhirManager.fhirDataAccessManager.Stop();
|
|
91
|
-
await JestSleep();
|
|
92
|
-
await testHelpers.StopRedis();
|
|
93
|
-
}, 5000);
|
|
94
|
-
});
|
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
/* eslint @typescript-eslint/no-unused-vars: 0 */ // --> OFF
|
|
2
|
-
/* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
|
|
3
|
-
import { IDomainResource, IDALFhirDataAccessManager, IFhirManagerRedisJsonOptions } from './STSFhirTypes'
|
|
4
|
-
|
|
5
|
-
import { Redis, RedisOptions } from "ioredis";
|
|
6
|
-
|
|
7
|
-
import chalk from 'chalk'
|
|
8
|
-
import { JSONObject } from '@nsshunt/stsutils';
|
|
9
|
-
import { DALFhirManagerBase } from './dalFhirManagerBase';
|
|
10
|
-
|
|
11
|
-
export class DALFhirManagerIORedisJson<T> extends DALFhirManagerBase<T> implements IDALFhirDataAccessManager<T> {
|
|
12
|
-
#redis: Redis | null = null;
|
|
13
|
-
#indexName: string = 'idx:stsfhirresindex';
|
|
14
|
-
|
|
15
|
-
constructor(options: IFhirManagerRedisJsonOptions) {
|
|
16
|
-
super(options);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async Start() {
|
|
20
|
-
const redisOptions: RedisOptions = {
|
|
21
|
-
showFriendlyErrorStack: true,
|
|
22
|
-
maxRetriesPerRequest: 20
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
this.#redis = new Redis((this.options as IFhirManagerRedisJsonOptions).redisUrl, redisOptions);
|
|
26
|
-
await this.#CreateIndex();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async Stop() {
|
|
30
|
-
if (this.#redis) {
|
|
31
|
-
this.#redis.quit();
|
|
32
|
-
this.#redis.disconnect();
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
#CreateIndex = async () => {
|
|
37
|
-
if (!this.#redis) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
//const retVal = await this.#redis.ft.dropIndex(this.#indexName);
|
|
43
|
-
const retVal = await this.#redis.call('FT.DROPINDEX', this.#indexName);
|
|
44
|
-
|
|
45
|
-
console.log(retVal);
|
|
46
|
-
} catch (error) {
|
|
47
|
-
console.log(chalk.red(error))
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
try {
|
|
51
|
-
const retVal = await this.#redis.call('FT.CREATE', this.#indexName, 'ON', 'HASH', 'PREFIX', '1', `${this.options.resourceName}_`,
|
|
52
|
-
'SCHEMA', 'id', 'TEXT', 'SORTABLE');
|
|
53
|
-
console.log(retVal);
|
|
54
|
-
} catch (error) {
|
|
55
|
-
console.log(chalk.red(error))
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
#SearchBy = async (id: string): Promise<any> => {
|
|
60
|
-
if (!this.#redis) {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const query = `@id:${this.options.resourceName}_${id}*`;
|
|
65
|
-
|
|
66
|
-
const retVal: any = await this.#redis.call('FT.SEARCH', this.#indexName, query,
|
|
67
|
-
'RETURN', '2', 'id', 'data', 'SORTBY', 'id', 'DESC', 'LIMIT', '0', '100');
|
|
68
|
-
|
|
69
|
-
return retVal;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
GetResourceType(fhir: Partial<T>): string {
|
|
73
|
-
return `${this.options.resourceName}_${(fhir as Partial<IDomainResource>).id}`;
|
|
74
|
-
}
|
|
75
|
-
|
|
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;
|
|
89
|
-
}
|
|
90
|
-
} else {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
} else {
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
} catch (error) {
|
|
97
|
-
if (ecb) {
|
|
98
|
-
ecb(fhir, error as Error);
|
|
99
|
-
}
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
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
|
-
|
|
113
|
-
const retVal = await this.#redis.hmset(this.GetResourceType(fhir), record);
|
|
114
|
-
|
|
115
|
-
if (retVal) {
|
|
116
|
-
return fhir;
|
|
117
|
-
} else {
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
} else {
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
} catch (error) {
|
|
124
|
-
if (ecb) {
|
|
125
|
-
ecb(fhir, error as Error);
|
|
126
|
-
}
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
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;
|
|
139
|
-
|
|
140
|
-
const retVal = await this.#redis.hmset(this.GetResourceType(fhir), record);
|
|
141
|
-
|
|
142
|
-
if (retVal) {
|
|
143
|
-
return fhir;
|
|
144
|
-
} else {
|
|
145
|
-
return null;
|
|
146
|
-
}
|
|
147
|
-
} else {
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
} catch (error) {
|
|
151
|
-
if (ecb) {
|
|
152
|
-
ecb(fhir, error as Error);
|
|
153
|
-
}
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
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
|
-
}
|
|
170
|
-
} else {
|
|
171
|
-
return null;
|
|
172
|
-
}
|
|
173
|
-
} else {
|
|
174
|
-
return null;
|
|
175
|
-
}
|
|
176
|
-
} catch (error) {
|
|
177
|
-
if (ecb) {
|
|
178
|
-
ecb(fhir, error as Error);
|
|
179
|
-
}
|
|
180
|
-
return null;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
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;
|
|
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]);
|
|
214
|
-
}
|
|
215
|
-
return retValArray;
|
|
216
|
-
}
|
|
217
|
-
promArray.push(prom());
|
|
218
|
-
});
|
|
219
|
-
|
|
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
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
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;
|
|
241
|
-
}
|
|
242
|
-
|
|
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;
|
|
250
|
-
}
|
|
251
|
-
|
|
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;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
|
|
2
|
-
import { beforeAll, afterAll, test, describe, expect } from 'vitest';
|
|
3
|
-
|
|
4
|
-
import { SYSTEM_USER_ID, IDBAccessLayer } from '@nsshunt/stsdatamanagement'
|
|
5
|
-
import { IPerson, IFhirPersistenceType } from './STSFhirTypes'
|
|
6
|
-
|
|
7
|
-
import { JestSleep } from '@nsshunt/stsutils'
|
|
8
|
-
|
|
9
|
-
import { TestHelpers } from './dalFhirTestHelpers'
|
|
10
|
-
|
|
11
|
-
import { DALFhirManager } from './dalFhirManager'
|
|
12
|
-
import chalk from 'chalk'
|
|
13
|
-
|
|
14
|
-
describe("Test hl7 fhir resource data access layer - PGRes", () =>
|
|
15
|
-
{
|
|
16
|
-
let testHelpers: TestHelpers;
|
|
17
|
-
let fhirManager: DALFhirManager<IPerson>
|
|
18
|
-
|
|
19
|
-
beforeAll(async () =>
|
|
20
|
-
{
|
|
21
|
-
testHelpers = new TestHelpers();
|
|
22
|
-
await testHelpers.StartDatabase();
|
|
23
|
-
|
|
24
|
-
fhirManager = new DALFhirManager({
|
|
25
|
-
persistenceType: IFhirPersistenceType.postgresResources,
|
|
26
|
-
persistenceTypeOptions: {
|
|
27
|
-
accessLayer: testHelpers.accessLayer as IDBAccessLayer,
|
|
28
|
-
resourceName: 'STSFhirPerson',
|
|
29
|
-
dbactionuser: SYSTEM_USER_ID
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
fhirManager.fhirDataAccessManager.Start();
|
|
34
|
-
}, 30000);
|
|
35
|
-
|
|
36
|
-
test('Testing Person', async () => {
|
|
37
|
-
expect.assertions(6);
|
|
38
|
-
await testHelpers.TestFhirPerson(fhirManager.fhirDataAccessManager);
|
|
39
|
-
}, 30000);
|
|
40
|
-
|
|
41
|
-
test('Testing Persons with Search', async () => {
|
|
42
|
-
const iterations = 10;
|
|
43
|
-
expect.assertions(iterations + 1);
|
|
44
|
-
await testHelpers.AddFhirPersons(fhirManager.fhirDataAccessManager, iterations);
|
|
45
|
-
|
|
46
|
-
const fhirResources = await fhirManager.fhirDataAccessManager.GetFhirResources(['']);
|
|
47
|
-
expect(fhirResources?.length).toEqual(iterations);
|
|
48
|
-
|
|
49
|
-
console.log(chalk.yellow(JSON.stringify(fhirResources)));
|
|
50
|
-
}, 30000);
|
|
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
|
-
|
|
85
|
-
afterAll(async () =>
|
|
86
|
-
{
|
|
87
|
-
fhirManager.fhirDataAccessManager.Stop();
|
|
88
|
-
await JestSleep();
|
|
89
|
-
await testHelpers.StopDatabase();
|
|
90
|
-
}, 5000);
|
|
91
|
-
});
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
/* eslint @typescript-eslint/no-unused-vars: 0 */ // --> OFF
|
|
2
|
-
import { IDBAccessLayer, IDBResource } from '@nsshunt/stsdatamanagement'
|
|
3
|
-
|
|
4
|
-
import { IDALFhirDataAccessManager, IFhirManagerPGResOptions } from './STSFhirTypes'
|
|
5
|
-
import { DALFhirManagerBase } from './dalFhirManagerBase';
|
|
6
|
-
|
|
7
|
-
export class DALFhirManagerPGRes<T> extends DALFhirManagerBase<T> implements IDALFhirDataAccessManager<T> {
|
|
8
|
-
#accessLayer: IDBAccessLayer;
|
|
9
|
-
|
|
10
|
-
constructor(options: IFhirManagerPGResOptions) {
|
|
11
|
-
super(options);
|
|
12
|
-
this.#accessLayer = (this.options as IFhirManagerPGResOptions).accessLayer;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async Start() {
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async Stop() {
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async GetFhirResource(fhir: Partial<T>, ecb?: (fhir: Partial<T>, error: Error) => void): Promise<T | null> {
|
|
24
|
-
if (!this.#accessLayer) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const retVal = await this.#accessLayer.GetResource<T>({
|
|
29
|
-
filters: {
|
|
30
|
-
resname: this.GetResourceType(fhir)
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
if (retVal.error) {
|
|
34
|
-
if (ecb) {
|
|
35
|
-
ecb(fhir, retVal.error.error);
|
|
36
|
-
}
|
|
37
|
-
return null;
|
|
38
|
-
} else {
|
|
39
|
-
return (retVal.detail as IDBResource<T>).resdesc;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async CreateFhirResource(fhir: T, ecb?: (fhir: T, error: Error) => void): Promise<T | null> {
|
|
44
|
-
if (!this.#accessLayer) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const retVal = await this.#accessLayer.CreateResource<T>({
|
|
49
|
-
filters: {
|
|
50
|
-
dbactionuser: this.options.dbactionuser,
|
|
51
|
-
resname: this.GetResourceType(fhir)
|
|
52
|
-
}
|
|
53
|
-
}, fhir);
|
|
54
|
-
if (retVal.error) {
|
|
55
|
-
if (ecb) {
|
|
56
|
-
ecb(fhir, retVal.error.error);
|
|
57
|
-
}
|
|
58
|
-
return null;
|
|
59
|
-
} else {
|
|
60
|
-
return (retVal.detail as IDBResource<T>).resdesc;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async UpdateFhirResource(fhir: T, ecb?: (fhir: T, error: Error) => void): Promise<T | null> {
|
|
65
|
-
if (!this.#accessLayer) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const retVal = await this.#accessLayer.UpdateResource<T>({
|
|
70
|
-
filters: {
|
|
71
|
-
dbactionuser: this.options.dbactionuser,
|
|
72
|
-
resname: this.GetResourceType(fhir)
|
|
73
|
-
}
|
|
74
|
-
}, fhir);
|
|
75
|
-
if (retVal.error) {
|
|
76
|
-
if (ecb) {
|
|
77
|
-
ecb(fhir, retVal.error.error);
|
|
78
|
-
}
|
|
79
|
-
return null;
|
|
80
|
-
} else {
|
|
81
|
-
return (retVal.detail as IDBResource<T>).resdesc;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async DeleteFhirResource(fhir: Partial<T>, ecb?: (fhir: Partial<T>, error: Error) => void): Promise<T | null> {
|
|
86
|
-
if (!this.#accessLayer) {
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const retVal = await this.#accessLayer.DeleteResource<T>({
|
|
91
|
-
filters: {
|
|
92
|
-
dbactionuser: this.options.dbactionuser,
|
|
93
|
-
resname: this.GetResourceType(fhir)
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
if (retVal.error) {
|
|
97
|
-
if (ecb) {
|
|
98
|
-
ecb(fhir, retVal.error.error);
|
|
99
|
-
}
|
|
100
|
-
return null;
|
|
101
|
-
} else {
|
|
102
|
-
return (retVal.detail as IDBResource<T>).resdesc;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async GetFhirResources(filters: string[], ecb?: (filters: string[], error: Error) => void): Promise<T[] | null> {
|
|
107
|
-
if (!this.#accessLayer) {
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
|
|
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);
|
|
143
|
-
}
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
|
|
2
|
-
import { beforeAll, afterAll, test, describe, expect } from 'vitest';
|
|
3
|
-
|
|
4
|
-
import { SYSTEM_USER_ID, IDBAccessLayer } from '@nsshunt/stsdatamanagement'
|
|
5
|
-
|
|
6
|
-
import { IPerson, IFhirPersistenceType } from './STSFhirTypes'
|
|
7
|
-
|
|
8
|
-
import { TestHelpers } from './dalFhirTestHelpers'
|
|
9
|
-
|
|
10
|
-
import { JestSleep } from '@nsshunt/stsutils'
|
|
11
|
-
|
|
12
|
-
import { DALFhirManager } from './dalFhirManager'
|
|
13
|
-
import chalk from 'chalk'
|
|
14
|
-
|
|
15
|
-
describe("Test hl7 fhir resource data access layer - PGResEntity", () =>
|
|
16
|
-
{
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
-
let testHelpers: TestHelpers;
|
|
19
|
-
let fhirManager: DALFhirManager<IPerson>
|
|
20
|
-
|
|
21
|
-
beforeAll(async () =>
|
|
22
|
-
{
|
|
23
|
-
testHelpers = new TestHelpers();
|
|
24
|
-
await testHelpers.StartDatabase();
|
|
25
|
-
|
|
26
|
-
fhirManager = new DALFhirManager({
|
|
27
|
-
persistenceType: IFhirPersistenceType.postgresResourcesEntities,
|
|
28
|
-
persistenceTypeOptions: {
|
|
29
|
-
accessLayer: testHelpers.accessLayer as IDBAccessLayer,
|
|
30
|
-
resourceName: 'STSFhirPerson',
|
|
31
|
-
dbactionuser: SYSTEM_USER_ID
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
fhirManager.fhirDataAccessManager.Start();
|
|
36
|
-
}, 30000);
|
|
37
|
-
|
|
38
|
-
test('Testing Person', async () => {
|
|
39
|
-
expect.assertions(6);
|
|
40
|
-
await testHelpers.TestFhirPerson(fhirManager.fhirDataAccessManager);
|
|
41
|
-
}, 30000);
|
|
42
|
-
|
|
43
|
-
test('Testing Persons with Search', async () => {
|
|
44
|
-
const iterations = 10;
|
|
45
|
-
expect.assertions(iterations + 1);
|
|
46
|
-
await testHelpers.AddFhirPersons(fhirManager.fhirDataAccessManager, iterations);
|
|
47
|
-
|
|
48
|
-
const fhirResources = await fhirManager.fhirDataAccessManager.GetFhirResources(['']);
|
|
49
|
-
expect(fhirResources?.length).toEqual(iterations);
|
|
50
|
-
|
|
51
|
-
console.log(chalk.cyan(JSON.stringify(fhirResources)));
|
|
52
|
-
}, 30000);
|
|
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
|
-
|
|
87
|
-
afterAll(async () =>
|
|
88
|
-
{
|
|
89
|
-
fhirManager.fhirDataAccessManager.Stop();
|
|
90
|
-
await JestSleep();
|
|
91
|
-
await testHelpers.StopDatabase();
|
|
92
|
-
}, 5000);
|
|
93
|
-
});
|