@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
|
@@ -2,23 +2,15 @@
|
|
|
2
2
|
import { IDBAccessLayer, IDBResource, IDBEntity } from '@nsshunt/stsdatamanagement'
|
|
3
3
|
|
|
4
4
|
import { IDomainResource, IFHIRResource, IDALFhirDataAccessManager, IFhirManagerPGResEntityOptions } from './STSFhirTypes'
|
|
5
|
+
import { DALFhirManagerBase } from './dalFhirManagerBase';
|
|
5
6
|
|
|
6
|
-
export class DALFhirManagerPGResEntity<T> implements IDALFhirDataAccessManager<T> {
|
|
7
|
-
#options: IFhirManagerPGResEntityOptions;
|
|
7
|
+
export class DALFhirManagerPGResEntity<T> extends DALFhirManagerBase<T> implements IDALFhirDataAccessManager<T> {
|
|
8
8
|
#fhirResource: IDBResource<IFHIRResource> | undefined;
|
|
9
9
|
#accessLayer: IDBAccessLayer;
|
|
10
10
|
|
|
11
11
|
constructor(options: IFhirManagerPGResEntityOptions) {
|
|
12
|
-
|
|
13
|
-
this.#accessLayer = this
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
get options() {
|
|
17
|
-
return this.#options;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
set options(options: IFhirManagerPGResEntityOptions) {
|
|
21
|
-
this.#options = options;
|
|
12
|
+
super(options);
|
|
13
|
+
this.#accessLayer = (this.options as IFhirManagerPGResEntityOptions).accessLayer;
|
|
22
14
|
}
|
|
23
15
|
|
|
24
16
|
async Start() {
|
|
@@ -33,20 +25,20 @@ export class DALFhirManagerPGResEntity<T> implements IDALFhirDataAccessManager<T
|
|
|
33
25
|
if (!this.#fhirResource) {
|
|
34
26
|
this.#fhirResource = ((await this.#accessLayer.GetResource<IFHIRResource>({
|
|
35
27
|
filters: {
|
|
36
|
-
resname: this
|
|
28
|
+
resname: this.options.resourceName
|
|
37
29
|
}
|
|
38
30
|
})).detail as IDBResource<IFHIRResource>);
|
|
39
31
|
|
|
40
32
|
if (!this.#fhirResource) {
|
|
41
33
|
const fhirResourceType: IFHIRResource = {
|
|
42
|
-
name: this
|
|
43
|
-
description: `${this
|
|
44
|
-
notes: `${this
|
|
34
|
+
name: this.options.resourceName,
|
|
35
|
+
description: `${this.options.resourceName} description`,
|
|
36
|
+
notes: `${this.options.resourceName} notes`,
|
|
45
37
|
}
|
|
46
38
|
this.#fhirResource = ((await this.#accessLayer.CreateResource<IFHIRResource>({
|
|
47
39
|
filters: {
|
|
48
|
-
dbactionuser: this
|
|
49
|
-
resname: this
|
|
40
|
+
dbactionuser: this.options.dbactionuser,
|
|
41
|
+
resname: this.options.resourceName
|
|
50
42
|
}
|
|
51
43
|
}, fhirResourceType)).detail as IDBResource<IFHIRResource>);
|
|
52
44
|
}
|
|
@@ -55,7 +47,7 @@ export class DALFhirManagerPGResEntity<T> implements IDALFhirDataAccessManager<T
|
|
|
55
47
|
return this.#fhirResource;
|
|
56
48
|
}
|
|
57
49
|
|
|
58
|
-
async GetFhirResource(fhir: Partial<T>, ecb?: (error: Error) => void): Promise<T | null> {
|
|
50
|
+
async GetFhirResource(fhir: Partial<T>, ecb?: (fhir: Partial<T>, error: Error) => void): Promise<T | null> {
|
|
59
51
|
if (!this.#accessLayer) {
|
|
60
52
|
return null;
|
|
61
53
|
}
|
|
@@ -69,7 +61,7 @@ export class DALFhirManagerPGResEntity<T> implements IDALFhirDataAccessManager<T
|
|
|
69
61
|
});
|
|
70
62
|
if (retVal.error) {
|
|
71
63
|
if (ecb) {
|
|
72
|
-
ecb(retVal.error.error);
|
|
64
|
+
ecb(fhir, retVal.error.error);
|
|
73
65
|
}
|
|
74
66
|
return null;
|
|
75
67
|
} else {
|
|
@@ -77,7 +69,7 @@ export class DALFhirManagerPGResEntity<T> implements IDALFhirDataAccessManager<T
|
|
|
77
69
|
}
|
|
78
70
|
}
|
|
79
71
|
|
|
80
|
-
async CreateFhirResource(fhir: T, ecb?: (error: Error) => void): Promise<T | null> {
|
|
72
|
+
async CreateFhirResource(fhir: T, ecb?: (fhir: T, error: Error) => void): Promise<T | null> {
|
|
81
73
|
if (!this.#accessLayer) {
|
|
82
74
|
return null;
|
|
83
75
|
}
|
|
@@ -85,14 +77,14 @@ export class DALFhirManagerPGResEntity<T> implements IDALFhirDataAccessManager<T
|
|
|
85
77
|
const fhirResource = await this.#GetSTSFhirBaseResource();
|
|
86
78
|
const retVal = await this.#accessLayer.CreateEntity<T>({
|
|
87
79
|
filters: {
|
|
88
|
-
dbactionuser: this
|
|
80
|
+
dbactionuser: this.options.dbactionuser,
|
|
89
81
|
resname: fhirResource.resname,
|
|
90
82
|
entname: (fhir as Partial<IDomainResource>).id
|
|
91
83
|
}
|
|
92
84
|
}, fhir);
|
|
93
85
|
if (retVal.error) {
|
|
94
86
|
if (ecb) {
|
|
95
|
-
ecb(retVal.error.error);
|
|
87
|
+
ecb(fhir, retVal.error.error);
|
|
96
88
|
}
|
|
97
89
|
return null;
|
|
98
90
|
} else {
|
|
@@ -100,7 +92,7 @@ export class DALFhirManagerPGResEntity<T> implements IDALFhirDataAccessManager<T
|
|
|
100
92
|
}
|
|
101
93
|
}
|
|
102
94
|
|
|
103
|
-
async UpdateFhirResource(fhir: T, ecb?: (error: Error) => void): Promise<T | null> {
|
|
95
|
+
async UpdateFhirResource(fhir: T, ecb?: (fhir: T, error: Error) => void): Promise<T | null> {
|
|
104
96
|
if (!this.#accessLayer) {
|
|
105
97
|
return null;
|
|
106
98
|
}
|
|
@@ -108,14 +100,14 @@ export class DALFhirManagerPGResEntity<T> implements IDALFhirDataAccessManager<T
|
|
|
108
100
|
const fhirResource = await this.#GetSTSFhirBaseResource();
|
|
109
101
|
const retVal = await this.#accessLayer.UpdateEntity<T>({
|
|
110
102
|
filters: {
|
|
111
|
-
dbactionuser: this
|
|
103
|
+
dbactionuser: this.options.dbactionuser,
|
|
112
104
|
resname: fhirResource.resname,
|
|
113
105
|
entname: (fhir as Partial<IDomainResource>).id
|
|
114
106
|
}
|
|
115
107
|
}, fhir);
|
|
116
108
|
if (retVal.error) {
|
|
117
109
|
if (ecb) {
|
|
118
|
-
ecb(retVal.error.error);
|
|
110
|
+
ecb(fhir, retVal.error.error);
|
|
119
111
|
}
|
|
120
112
|
return null;
|
|
121
113
|
} else {
|
|
@@ -123,7 +115,7 @@ export class DALFhirManagerPGResEntity<T> implements IDALFhirDataAccessManager<T
|
|
|
123
115
|
}
|
|
124
116
|
}
|
|
125
117
|
|
|
126
|
-
async DeleteFhirResource(fhir: Partial<T>, ecb?: (error: Error) => void): Promise<T | null> {
|
|
118
|
+
async DeleteFhirResource(fhir: Partial<T>, ecb?: (fhir: Partial<T>, error: Error) => void): Promise<T | null> {
|
|
127
119
|
if (!this.#accessLayer) {
|
|
128
120
|
return null;
|
|
129
121
|
}
|
|
@@ -131,14 +123,14 @@ export class DALFhirManagerPGResEntity<T> implements IDALFhirDataAccessManager<T
|
|
|
131
123
|
const fhirResource = await this.#GetSTSFhirBaseResource();
|
|
132
124
|
const retVal = await this.#accessLayer.DeleteEntity<T>({
|
|
133
125
|
filters: {
|
|
134
|
-
dbactionuser: this
|
|
126
|
+
dbactionuser: this.options.dbactionuser,
|
|
135
127
|
resname: fhirResource.resname,
|
|
136
128
|
entname: (fhir as Partial<IDomainResource>).id
|
|
137
129
|
}
|
|
138
130
|
});
|
|
139
131
|
if (retVal.error) {
|
|
140
132
|
if (ecb) {
|
|
141
|
-
ecb(retVal.error.error);
|
|
133
|
+
ecb(fhir, retVal.error.error);
|
|
142
134
|
}
|
|
143
135
|
return null;
|
|
144
136
|
} else {
|
|
@@ -146,69 +138,46 @@ export class DALFhirManagerPGResEntity<T> implements IDALFhirDataAccessManager<T
|
|
|
146
138
|
}
|
|
147
139
|
}
|
|
148
140
|
|
|
149
|
-
async GetFhirResources(filters: string[], ecb?: (error: Error) => void): Promise<T[] | null> {
|
|
141
|
+
async GetFhirResources(filters: string[], ecb?: (filters: string[], error: Error) => void): Promise<T[] | null> {
|
|
150
142
|
if (!this.#accessLayer) {
|
|
151
143
|
return null;
|
|
152
144
|
}
|
|
153
145
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
async UpdateFhirResources(fhir: T[], ecb?: (error: Error) => void): Promise<T[] | null> {
|
|
190
|
-
return null
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
async DeleteFhirResources(fhir: Partial<T>[], ecb?: (error: Error) => void): Promise<T[] | null> {
|
|
194
|
-
return null;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/*
|
|
198
|
-
|
|
199
|
-
const resources = await accessLayer.GetResources<IUserResourceType>({
|
|
200
|
-
filters: {
|
|
201
|
-
filter: 'RESCP-%',
|
|
202
|
-
limit: '10',
|
|
146
|
+
try {
|
|
147
|
+
const fhirResource = await this.#GetSTSFhirBaseResource();
|
|
148
|
+
const promArray: Promise<T[]>[] = [ ];
|
|
149
|
+
filters.forEach(filter => {
|
|
150
|
+
const prom = async (): Promise<T[]> => {
|
|
151
|
+
const retVal: T[] = [ ];
|
|
152
|
+
|
|
153
|
+
const entities = await this.#accessLayer.GetEntities<T>({
|
|
154
|
+
filters: {
|
|
155
|
+
resname: fhirResource.resname,
|
|
156
|
+
filter: `${filter}%`
|
|
157
|
+
}
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
const dbResources = (entities.detail as IDBEntity<T>[]);
|
|
161
|
+
|
|
162
|
+
dbResources.forEach(dbResource => {
|
|
163
|
+
retVal.push(dbResource.entvalue);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
return retVal;
|
|
167
|
+
}
|
|
168
|
+
promArray.push(prom());
|
|
169
|
+
})
|
|
170
|
+
const promRetVal = await Promise.all(promArray);
|
|
171
|
+
let retVal: T[] = [ ];
|
|
172
|
+
promRetVal.forEach(prv => {
|
|
173
|
+
retVal = retVal.concat(prv);
|
|
174
|
+
});
|
|
175
|
+
return retVal;
|
|
176
|
+
} catch (error) {
|
|
177
|
+
if (ecb) {
|
|
178
|
+
ecb(filters, error as Error);
|
|
203
179
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const entities = await accessLayer.GetEntities<IUserEntity>({
|
|
207
|
-
filters: {
|
|
208
|
-
resname: 'user-t2',
|
|
209
|
-
filter: '%'
|
|
180
|
+
return null;
|
|
210
181
|
}
|
|
211
|
-
}
|
|
212
|
-
*/
|
|
213
|
-
|
|
182
|
+
}
|
|
214
183
|
}
|
|
@@ -10,6 +10,8 @@ import { JestSleep } from '@nsshunt/stsutils'
|
|
|
10
10
|
import { DALFhirManager } from './dalFhirManager'
|
|
11
11
|
import chalk from 'chalk'
|
|
12
12
|
|
|
13
|
+
import { SYSTEM_USER_ID } from '@nsshunt/stsdatamanagement'
|
|
14
|
+
|
|
13
15
|
describe.skip("Test hl7 fhir resource data access layer - RedisJson", () =>
|
|
14
16
|
{
|
|
15
17
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -25,6 +27,7 @@ describe.skip("Test hl7 fhir resource data access layer - RedisJson", () =>
|
|
|
25
27
|
persistenceType: IFhirPersistenceType.redisJson,
|
|
26
28
|
persistenceTypeOptions: {
|
|
27
29
|
resourceName: 'STSFhirPerson',
|
|
30
|
+
dbactionuser: SYSTEM_USER_ID,
|
|
28
31
|
redisUrl: testHelpers.ioRedisMessageProcessorUrl
|
|
29
32
|
}
|
|
30
33
|
});
|
|
@@ -37,7 +40,7 @@ describe.skip("Test hl7 fhir resource data access layer - RedisJson", () =>
|
|
|
37
40
|
await testHelpers.TestFhirPerson(fhirManager.fhirDataAccessManager);
|
|
38
41
|
}, 30000);
|
|
39
42
|
|
|
40
|
-
test('Testing
|
|
43
|
+
test('Testing Persons with Search', async () => {
|
|
41
44
|
const iterations = 10;
|
|
42
45
|
expect.assertions(iterations + 1);
|
|
43
46
|
await testHelpers.AddFhirPersons(fhirManager.fhirDataAccessManager, iterations);
|
|
@@ -48,6 +51,39 @@ describe.skip("Test hl7 fhir resource data access layer - RedisJson", () =>
|
|
|
48
51
|
console.log(chalk.green(JSON.stringify(fhirResources)));
|
|
49
52
|
}, 30000);
|
|
50
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
|
+
|
|
51
87
|
afterAll(async () =>
|
|
52
88
|
{
|
|
53
89
|
await fhirManager.fhirDataAccessManager.Stop();
|
|
@@ -3,24 +3,16 @@
|
|
|
3
3
|
import { IDomainResource, IDALFhirDataAccessManager, IFhirManagerRedisJsonOptions } from './STSFhirTypes'
|
|
4
4
|
|
|
5
5
|
import { SchemaFieldTypes, createClient, RedisClientType, AggregateSteps, AggregateGroupByReducers } from 'redis';
|
|
6
|
+
import { DALFhirManagerBase } from './dalFhirManagerBase';
|
|
6
7
|
|
|
7
8
|
import chalk from 'chalk'
|
|
8
9
|
|
|
9
|
-
export class DALFhirManagerRedisJson<T> implements IDALFhirDataAccessManager<T> {
|
|
10
|
-
#options: IFhirManagerRedisJsonOptions;
|
|
10
|
+
export class DALFhirManagerRedisJson<T> extends DALFhirManagerBase<T> implements IDALFhirDataAccessManager<T> {
|
|
11
11
|
#redis: RedisClientType | null = null;
|
|
12
12
|
#indexName: string = 'idx:stsfhirresindex';
|
|
13
13
|
|
|
14
14
|
constructor(options: IFhirManagerRedisJsonOptions) {
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
get options() {
|
|
19
|
-
return this.#options;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
set options(options: IFhirManagerRedisJsonOptions) {
|
|
23
|
-
this.#options = options;
|
|
15
|
+
super(options);
|
|
24
16
|
}
|
|
25
17
|
|
|
26
18
|
#CreateIndex = async () => {
|
|
@@ -40,7 +32,7 @@ export class DALFhirManagerRedisJson<T> implements IDALFhirDataAccessManager<T>
|
|
|
40
32
|
'id': { type: SchemaFieldTypes.TEXT, SORTABLE: true }
|
|
41
33
|
}, {
|
|
42
34
|
ON: 'HASH',
|
|
43
|
-
PREFIX: `${this
|
|
35
|
+
PREFIX: `${this.options.resourceName}_`
|
|
44
36
|
});
|
|
45
37
|
console.log(retVal);
|
|
46
38
|
} catch (error) {
|
|
@@ -65,7 +57,7 @@ export class DALFhirManagerRedisJson<T> implements IDALFhirDataAccessManager<T>
|
|
|
65
57
|
}
|
|
66
58
|
} as any;
|
|
67
59
|
|
|
68
|
-
const query = `@id:${this
|
|
60
|
+
const query = `@id:${this.options.resourceName}_${id}*`;
|
|
69
61
|
|
|
70
62
|
const retVal = await this.#redis.ft.search(this.#indexName, query, queryOptions);
|
|
71
63
|
|
|
@@ -73,7 +65,7 @@ export class DALFhirManagerRedisJson<T> implements IDALFhirDataAccessManager<T>
|
|
|
73
65
|
}
|
|
74
66
|
|
|
75
67
|
async Start() {
|
|
76
|
-
this.#redis = await createClient({url: this
|
|
68
|
+
this.#redis = await createClient({url: (this.options as IFhirManagerRedisJsonOptions).redisUrl})
|
|
77
69
|
.on('error', error => console.error(chalk.red(`Error connecting to redis. Error: [${error}]`)))
|
|
78
70
|
.connect() as any
|
|
79
71
|
|
|
@@ -92,124 +84,147 @@ export class DALFhirManagerRedisJson<T> implements IDALFhirDataAccessManager<T>
|
|
|
92
84
|
}
|
|
93
85
|
|
|
94
86
|
GetResourceType(fhir: Partial<T>): string {
|
|
95
|
-
return `${this
|
|
87
|
+
return `${this.options.resourceName}_${(fhir as Partial<IDomainResource>).id}`;
|
|
96
88
|
}
|
|
97
89
|
|
|
98
|
-
async GetFhirResource(fhir: Partial<T>, ecb?: (error: Error) => void): Promise<T | null> {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
ecb
|
|
90
|
+
async GetFhirResource(fhir: Partial<T>, ecb?: (fhir: Partial<T>, error: Error) => void): Promise<T | null> {
|
|
91
|
+
try {
|
|
92
|
+
if (this.#redis) {
|
|
93
|
+
const retValRaw = await this.#redis.HGETALL(this.GetResourceType(fhir))
|
|
94
|
+
if (retValRaw) {
|
|
95
|
+
try {
|
|
96
|
+
const { id, data } = retValRaw;
|
|
97
|
+
return JSON.parse(data) as T;
|
|
98
|
+
} catch (error: unknown) {
|
|
99
|
+
if (ecb) {
|
|
100
|
+
ecb(fhir, error as Error);
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
108
103
|
}
|
|
104
|
+
} else {
|
|
109
105
|
return null;
|
|
110
106
|
}
|
|
111
107
|
} else {
|
|
112
108
|
return null;
|
|
113
109
|
}
|
|
114
|
-
}
|
|
110
|
+
} catch (error) {
|
|
111
|
+
if (ecb) {
|
|
112
|
+
ecb(fhir, error as Error);
|
|
113
|
+
}
|
|
115
114
|
return null;
|
|
116
115
|
}
|
|
117
116
|
}
|
|
118
117
|
|
|
119
118
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
120
|
-
async CreateFhirResource(fhir: T, ecb?: (error: Error) => void): Promise<T | null> {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
119
|
+
async CreateFhirResource(fhir: T, ecb?: (fhir: T, error: Error) => void): Promise<T | null> {
|
|
120
|
+
try {
|
|
121
|
+
if (this.#redis) {
|
|
122
|
+
const record = {
|
|
123
|
+
id: this.GetResourceType(fhir),
|
|
124
|
+
data: JSON.stringify(fhir)
|
|
125
|
+
} as any;
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
const keyValuePairs: any = Object.entries(record).flat();
|
|
128
128
|
|
|
129
|
-
|
|
129
|
+
const retVal = await this.#redis.HSET(this.GetResourceType(fhir), keyValuePairs);
|
|
130
130
|
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
if (retVal) {
|
|
132
|
+
return fhir;
|
|
133
|
+
} else {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
133
136
|
} else {
|
|
137
|
+
console.error(chalk.red(`this.#redis not defined.`))
|
|
134
138
|
return null;
|
|
135
139
|
}
|
|
136
|
-
}
|
|
137
|
-
|
|
140
|
+
} catch (error) {
|
|
141
|
+
if (ecb) {
|
|
142
|
+
ecb(fhir, error as Error);
|
|
143
|
+
}
|
|
138
144
|
return null;
|
|
139
145
|
}
|
|
140
146
|
}
|
|
141
147
|
|
|
142
148
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
143
|
-
async UpdateFhirResource(fhir: T, ecb?: (error: Error) => void): Promise<T | null> {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
+
async UpdateFhirResource(fhir: T, ecb?: (fhir: T, error: Error) => void): Promise<T | null> {
|
|
150
|
+
try {
|
|
151
|
+
if (this.#redis) {
|
|
152
|
+
const record = {
|
|
153
|
+
id: this.GetResourceType(fhir),
|
|
154
|
+
data: JSON.stringify(fhir)
|
|
155
|
+
} as any;
|
|
149
156
|
|
|
150
|
-
|
|
157
|
+
const keyValuePairs: any = Object.entries(record).flat();
|
|
151
158
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
159
|
+
const retVal = await this.#redis.HSET(this.GetResourceType(fhir), keyValuePairs);
|
|
160
|
+
if (retVal >= 0) {
|
|
161
|
+
return fhir;
|
|
162
|
+
} else {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
155
165
|
} else {
|
|
156
166
|
return null;
|
|
157
167
|
}
|
|
158
|
-
}
|
|
168
|
+
} catch (error) {
|
|
169
|
+
if (ecb) {
|
|
170
|
+
ecb(fhir, error as Error);
|
|
171
|
+
}
|
|
159
172
|
return null;
|
|
160
173
|
}
|
|
161
174
|
}
|
|
162
175
|
|
|
163
176
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
164
|
-
async DeleteFhirResource(fhir: Partial<T>, ecb?: (error: Error) => void): Promise<T | null> {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
177
|
+
async DeleteFhirResource(fhir: Partial<T>, ecb?: (fhir: Partial<T>, error: Error) => void): Promise<T | null> {
|
|
178
|
+
try {
|
|
179
|
+
if (this.#redis) {
|
|
180
|
+
const deleteResource = await this.GetFhirResource(fhir);
|
|
181
|
+
if (deleteResource) {
|
|
182
|
+
const retVal = await this.#redis.del(this.GetResourceType(fhir));
|
|
183
|
+
if (retVal > 0) {
|
|
184
|
+
return deleteResource;
|
|
185
|
+
} else {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
171
188
|
} else {
|
|
172
189
|
return null;
|
|
173
190
|
}
|
|
174
191
|
} else {
|
|
175
192
|
return null;
|
|
176
193
|
}
|
|
177
|
-
}
|
|
194
|
+
} catch (error) {
|
|
195
|
+
if (ecb) {
|
|
196
|
+
ecb(fhir, error as Error);
|
|
197
|
+
}
|
|
178
198
|
return null;
|
|
179
199
|
}
|
|
180
200
|
}
|
|
181
201
|
|
|
182
|
-
async GetFhirResources(filters: string[], ecb?: (error: Error) => void): Promise<T[] | null> {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
const promRetVal = await Promise.all(promArray);
|
|
197
|
-
let retVal: T[] = [ ];
|
|
198
|
-
promRetVal.forEach(prv => {
|
|
199
|
-
retVal = retVal.concat(prv);
|
|
200
|
-
});
|
|
201
|
-
return retVal;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
async CreateFhirResources(fhir: T[], ecb?: (error: Error) => void): Promise<T[] | null> {
|
|
205
|
-
return null;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
async UpdateFhirResources(fhir: T[], ecb?: (error: Error) => void): Promise<T[] | null> {
|
|
209
|
-
return null
|
|
210
|
-
}
|
|
202
|
+
async GetFhirResources(filters: string[], ecb?: (filters: string[], error: Error) => void): Promise<T[] | null> {
|
|
203
|
+
try {
|
|
204
|
+
const promArray: Promise<T[]>[] = [ ];
|
|
205
|
+
filters.forEach(filter => {
|
|
206
|
+
const prom = async (): Promise<T[]> => {
|
|
207
|
+
const retValArray: T[] = [ ];
|
|
208
|
+
const retVal = await this.#SearchBy(filter);
|
|
209
|
+
retVal?.documents.forEach(doc => {
|
|
210
|
+
retValArray.push(JSON.parse(doc.value.data as string) as T);
|
|
211
|
+
})
|
|
212
|
+
return retValArray;
|
|
213
|
+
}
|
|
214
|
+
promArray.push(prom());
|
|
215
|
+
});
|
|
211
216
|
|
|
212
|
-
|
|
213
|
-
|
|
217
|
+
const promRetVal = await Promise.all(promArray);
|
|
218
|
+
let retVal: T[] = [ ];
|
|
219
|
+
promRetVal.forEach(prv => {
|
|
220
|
+
retVal = retVal.concat(prv);
|
|
221
|
+
});
|
|
222
|
+
return retVal;
|
|
223
|
+
} catch (error) {
|
|
224
|
+
if (ecb) {
|
|
225
|
+
ecb(filters, error as Error);
|
|
226
|
+
}
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
214
229
|
}
|
|
215
230
|
}
|