@metriport/commonwell-cert-runner 1.4.12 → 1.4.18

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License Copyright (c) 2022 Metriport Inc.
2
-
3
- Permission is hereby granted, free of
4
- charge, to any person obtaining a copy of this software and associated
5
- documentation files (the "Software"), to deal in the Software without
6
- restriction, including without limitation the rights to use, copy, modify, merge,
7
- publish, distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to the
9
- following conditions:
10
-
11
- The above copyright notice and this permission notice
12
- (including the next paragraph) shall be included in all copies or substantial
13
- portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
16
- ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
18
- EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19
- OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1
+ MIT License Copyright (c) 2022 Metriport Inc.
2
+
3
+ Permission is hereby granted, free of
4
+ charge, to any person obtaining a copy of this software and associated
5
+ documentation files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use, copy, modify, merge,
7
+ publish, distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to the
9
+ following conditions:
10
+
11
+ The above copyright notice and this permission notice
12
+ (including the next paragraph) shall be included in all copies or substantial
13
+ portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
16
+ ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
18
+ EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  THE SOFTWARE.
package/README.md CHANGED
@@ -1,124 +1,124 @@
1
- # `commonwell-cert-runner`
2
-
3
- CommonWell Certification Runner by Metriport Inc.
4
-
5
- Tool to run through Edge System CommonWell certification test cases.
6
-
7
- ## Install
8
-
9
- To install the program, execute the following command on your terminal:
10
-
11
- `npm i -g @metriport/commonwell-cert-runner`
12
-
13
- Note: you may have to run the command with `sudo`.
14
-
15
- ## Usage
16
-
17
- After installation, create a `.env` file defining the following variables:
18
-
19
- - `COMMONWELL_ORG_NAME`: the organization that will be making the requests.
20
- - `COMMONWELL_OID`: the organization ID.
21
- - `COMMONWELL_SANDBOX_ORG_NAME`: the organization on sandbox for patient management and document contribution
22
- - should be configured with your FHIR server and OAuth 2 data on Commonwell management portal
23
- - `COMMONWELL_SANDBOX_OID`: the ID of the organization above
24
- - `COMMONWELL_ORG_PRIVATE_KEY`: the RSA256 private key corresponding to the specified organization.
25
- - `COMMONWELL_ORG_CERTIFICATE`: the public certificate/key corresponding to the private key.
26
- - `COMMONWELL_MEMBER_OID`: the member ID for organization management
27
- - `COMMONWELL_MEMBER_PRIVATE_KEY`: the RSA256 private key corresponding to the specified member management organization.
28
- - `COMMONWELL_MEMBER_CERTIFICATE`: the public certificate/key corresponding to the private key.
29
- - `DOCUMENT_PATIENT_FIRST_NAME`: the first name of a patient created along with the sandbox that has a document associated
30
- - `DOCUMENT_PATIENT_LAST_NAME`: their last name
31
- - `DOCUMENT_PATIENT_DATE_OF_BIRTH`: their date of birth on the format YYYY-MM-DD
32
- - `DOCUMENT_PATIENT_GENDER`: their gender (M|F)
33
- - `DOCUMENT_PATIENT_ZIP`: their address zip code
34
- - `DOCUMENT_CONTRIBUTION_ORGANIZATION_ID`: organization suffix for the document contribution flow (usually in the format
35
- "2.dddddd", with 'd' being a digit)
36
- - `DOCUMENT_CONTRIBUTION_PATIENT_FIRST_NAME`: the first name of the patient to be created on the organization used for the
37
- document contribution flow - same for the properties below [optional, defaults to the same name from the document patient
38
- above]
39
- - `DOCUMENT_CONTRIBUTION_PATIENT_LAST_NAME`
40
- - `DOCUMENT_CONTRIBUTION_PATIENT_DATE_OF_BIRTH`
41
- - `DOCUMENT_CONTRIBUTION_PATIENT_GENDER`
42
- - `DOCUMENT_CONTRIBUTION_PATIENT_ZIP`
43
- - `DOCUMENT_CONTRIBUTION_URL`: the url of the server where the documents are stored
44
- - `DOCUMENT_CONTRIBUTION_FHIRURL`: the direct url of the FHIR server where the documents are stored, with no authentication required
45
- - `DOCUMENT_CONTRIBUTION_AUTH_URL`: the url of the server used to authenticate document contribution requests
46
- - `DOCUMENT_CONTRIBUTION_CLIENT_ID`: the client OAuth ID to authenticate document contribution requests
47
- - `DOCUMENT_CONTRIBUTION_CLIENT_SECRET`: the client OAuth secret to authenticate document contribution requests
48
-
49
- flow - must exist on the sandbox organization
50
-
51
- Example file content looks like:
52
-
53
- ```
54
- COMMONWELL_ORG_NAME=Metriport
55
- COMMONWELL_OID=2.16.840.1.113883.3.9621
56
- COMMONWELL_SANDBOX_ORG_NAME=Metriport-OrgA-1620
57
- COMMONWELL_SANDBOX_OID=2.16.840.1.113883.3.3330.8889429.1620.1
58
- COMMONWELL_ORG_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----
59
- ...
60
- -----END PRIVATE KEY-----"
61
- COMMONWELL_ORG_CERTIFICATE="-----BEGIN CERTIFICATE-----
62
- ...
63
- -----END CERTIFICATE-----"
64
- COMMONWELL_MEMBER_OID=1.3.6.1.4.1.18.12.29.2022.945
65
- COMMONWELL_ORG_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----
66
- ...
67
- -----END PRIVATE KEY-----"
68
- COMMONWELL_ORG_CERTIFICATE="-----BEGIN CERTIFICATE-----
69
- ...
70
- -----END CERTIFICATE-----"
71
- DOCUMENT_PATIENT_FIRST_NAME="Stephen"
72
- DOCUMENT_PATIENT_LAST_NAME="Pujols1234"
73
- DOCUMENT_PATIENT_DATE_OF_BIRTH="1955-10-23"
74
- DOCUMENT_PATIENT_GENDER="M"
75
- DOCUMENT_PATIENT_ZIP="62732"
76
- # This is optional, if not set the runner will attempt to create the patient above on the sandbox org
77
- DOCUMENT_CONTRIBUTION_PATIENT_ID=<patient-id>%5E%5E%5Eurn%3aoid%3a<org-id>
78
- ```
79
-
80
- After the file is created, you can run execute following command on your terminal to run the program:
81
-
82
- `cw-cert-runner --env-file "/path/to/created/env/file/.env"`
83
-
84
- ## Options
85
-
86
- `--env-file <file-path>`
87
-
88
- Absolute path to the .env file containing required config.
89
-
90
- `-V, --version`
91
-
92
- Output the version number.
93
-
94
- `-h, --help`
95
-
96
- Display help for command.
97
-
98
- ## Development
99
-
100
- `npm run build`: builds the package
101
-
102
- `npm start`: runs the local code pointing to `./.env`
103
-
104
- (optionally) `npm run install-local`: installs the package globally from the local source
105
-
106
- ```
107
- ,▄,
108
- ▄▓███▌
109
- ▄▀╙ ▀▓▀ ²▄
110
- ▄└ ╙▌
111
- ,▀ ╨▄
112
- ▌ ║
113
-
114
-
115
- ,▓██▄ ╔███▄
116
- ╙███▌ ▀███▀
117
- ▀▄
118
- ▀╗▄ ,▄
119
- '╙▀▀▀▀▀╙''
120
-
121
-
122
- by Metriport Inc.
123
-
124
- ```
1
+ # `commonwell-cert-runner`
2
+
3
+ CommonWell Certification Runner by Metriport Inc.
4
+
5
+ Tool to run through Edge System CommonWell certification test cases.
6
+
7
+ ## Install
8
+
9
+ To install the program, execute the following command on your terminal:
10
+
11
+ `npm i -g @metriport/commonwell-cert-runner`
12
+
13
+ Note: you may have to run the command with `sudo`.
14
+
15
+ ## Usage
16
+
17
+ After installation, create a `.env` file defining the following variables:
18
+
19
+ - `COMMONWELL_ORG_NAME`: the organization that will be making the requests.
20
+ - `COMMONWELL_OID`: the organization ID.
21
+ - `COMMONWELL_SANDBOX_ORG_NAME`: the organization on sandbox for patient management and document contribution
22
+ - should be configured with your FHIR server and OAuth 2 data on Commonwell management portal
23
+ - `COMMONWELL_SANDBOX_OID`: the ID of the organization above
24
+ - `COMMONWELL_ORG_PRIVATE_KEY`: the RSA256 private key corresponding to the specified organization.
25
+ - `COMMONWELL_ORG_CERTIFICATE`: the public certificate/key corresponding to the private key.
26
+ - `COMMONWELL_MEMBER_OID`: the member ID for organization management
27
+ - `COMMONWELL_MEMBER_PRIVATE_KEY`: the RSA256 private key corresponding to the specified member management organization.
28
+ - `COMMONWELL_MEMBER_CERTIFICATE`: the public certificate/key corresponding to the private key.
29
+ - `DOCUMENT_PATIENT_FIRST_NAME`: the first name of a patient created along with the sandbox that has a document associated
30
+ - `DOCUMENT_PATIENT_LAST_NAME`: their last name
31
+ - `DOCUMENT_PATIENT_DATE_OF_BIRTH`: their date of birth on the format YYYY-MM-DD
32
+ - `DOCUMENT_PATIENT_GENDER`: their gender (M|F)
33
+ - `DOCUMENT_PATIENT_ZIP`: their address zip code
34
+ - `DOCUMENT_CONTRIBUTION_ORGANIZATION_ID`: organization suffix for the document contribution flow (usually in the format
35
+ "2.dddddd", with 'd' being a digit)
36
+ - `DOCUMENT_CONTRIBUTION_PATIENT_FIRST_NAME`: the first name of the patient to be created on the organization used for the
37
+ document contribution flow - same for the properties below [optional, defaults to the same name from the document patient
38
+ above]
39
+ - `DOCUMENT_CONTRIBUTION_PATIENT_LAST_NAME`
40
+ - `DOCUMENT_CONTRIBUTION_PATIENT_DATE_OF_BIRTH`
41
+ - `DOCUMENT_CONTRIBUTION_PATIENT_GENDER`
42
+ - `DOCUMENT_CONTRIBUTION_PATIENT_ZIP`
43
+ - `DOCUMENT_CONTRIBUTION_URL`: the url of the server where the documents are stored
44
+ - `DOCUMENT_CONTRIBUTION_FHIRURL`: the direct url of the FHIR server where the documents are stored, with no authentication required
45
+ - `DOCUMENT_CONTRIBUTION_AUTH_URL`: the url of the server used to authenticate document contribution requests
46
+ - `DOCUMENT_CONTRIBUTION_CLIENT_ID`: the client OAuth ID to authenticate document contribution requests
47
+ - `DOCUMENT_CONTRIBUTION_CLIENT_SECRET`: the client OAuth secret to authenticate document contribution requests
48
+
49
+ flow - must exist on the sandbox organization
50
+
51
+ Example file content looks like:
52
+
53
+ ```
54
+ COMMONWELL_ORG_NAME=Metriport
55
+ COMMONWELL_OID=2.16.840.1.113883.3.9621
56
+ COMMONWELL_SANDBOX_ORG_NAME=Metriport-OrgA-1620
57
+ COMMONWELL_SANDBOX_OID=2.16.840.1.113883.3.3330.8889429.1620.1
58
+ COMMONWELL_ORG_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----
59
+ ...
60
+ -----END PRIVATE KEY-----"
61
+ COMMONWELL_ORG_CERTIFICATE="-----BEGIN CERTIFICATE-----
62
+ ...
63
+ -----END CERTIFICATE-----"
64
+ COMMONWELL_MEMBER_OID=1.3.6.1.4.1.18.12.29.2022.945
65
+ COMMONWELL_ORG_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----
66
+ ...
67
+ -----END PRIVATE KEY-----"
68
+ COMMONWELL_ORG_CERTIFICATE="-----BEGIN CERTIFICATE-----
69
+ ...
70
+ -----END CERTIFICATE-----"
71
+ DOCUMENT_PATIENT_FIRST_NAME="Stephen"
72
+ DOCUMENT_PATIENT_LAST_NAME="Pujols1234"
73
+ DOCUMENT_PATIENT_DATE_OF_BIRTH="1955-10-23"
74
+ DOCUMENT_PATIENT_GENDER="M"
75
+ DOCUMENT_PATIENT_ZIP="62732"
76
+ # This is optional, if not set the runner will attempt to create the patient above on the sandbox org
77
+ DOCUMENT_CONTRIBUTION_PATIENT_ID=<patient-id>%5E%5E%5Eurn%3aoid%3a<org-id>
78
+ ```
79
+
80
+ After the file is created, you can run execute following command on your terminal to run the program:
81
+
82
+ `cw-cert-runner --env-file "/path/to/created/env/file/.env"`
83
+
84
+ ## Options
85
+
86
+ `--env-file <file-path>`
87
+
88
+ Absolute path to the .env file containing required config.
89
+
90
+ `-V, --version`
91
+
92
+ Output the version number.
93
+
94
+ `-h, --help`
95
+
96
+ Display help for command.
97
+
98
+ ## Development
99
+
100
+ `npm run build`: builds the package
101
+
102
+ `npm start`: runs the local code pointing to `./.env`
103
+
104
+ (optionally) `npm run install-local`: installs the package globally from the local source
105
+
106
+ ```
107
+ ,▄,
108
+ ▄▓███▌
109
+ ▄▀╙ ▀▓▀ ²▄
110
+ ▄└ ╙▌
111
+ ,▀ ╨▄
112
+ ▌ ║
113
+
114
+
115
+ ,▓██▄ ╔███▄
116
+ ╙███▌ ▀███▀
117
+ ▀▄
118
+ ▀╗▄ ,▄
119
+ '╙▀▀▀▀▀╙''
120
+
121
+
122
+ by Metriport Inc.
123
+
124
+ ```
@@ -1,5 +1,5 @@
1
- #!/usr/bin/env node
2
- import { CommonWell, Document, RequestMetadata } from "@metriport/commonwell-sdk";
3
- export declare function documentConsumption(commonWell: CommonWell, queryMeta: RequestMetadata): Promise<void>;
4
- export declare function queryDocuments(commonWell: CommonWell, queryMeta: RequestMetadata): Promise<Document[]>;
5
- export declare function retrieveDocument(commonWell: CommonWell, queryMeta: RequestMetadata, doc: Document): Promise<void>;
1
+ #!/usr/bin/env node
2
+ import { CommonWell, Document, RequestMetadata } from "@metriport/commonwell-sdk";
3
+ export declare function documentConsumption(commonWell: CommonWell, queryMeta: RequestMetadata): Promise<void>;
4
+ export declare function queryDocuments(commonWell: CommonWell, queryMeta: RequestMetadata): Promise<Document[]>;
5
+ export declare function retrieveDocument(commonWell: CommonWell, queryMeta: RequestMetadata, doc: Document): Promise<void>;
@@ -1,85 +1,85 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || function (mod) {
20
- if (mod && mod.__esModule) return mod;
21
- var result = {};
22
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
- __setModuleDefault(result, mod);
24
- return result;
25
- };
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.retrieveDocument = exports.queryDocuments = exports.documentConsumption = void 0;
28
- const commonwell_sdk_1 = require("@metriport/commonwell-sdk");
29
- const fs = __importStar(require("fs"));
30
- const payloads_1 = require("./payloads");
31
- const shared_person_1 = require("./shared-person");
32
- const util_1 = require("./util");
33
- // Document Consumption
34
- // https://commonwellalliance.sharepoint.com/sites/ServiceAdopter/SitePages/Document-Consumption-(SOAP,-REST).aspx
35
- async function documentConsumption(commonWell, queryMeta) {
36
- const documents = await queryDocuments(commonWell, queryMeta);
37
- for (const doc of documents) {
38
- await retrieveDocument(commonWell, queryMeta, doc);
39
- }
40
- }
41
- exports.documentConsumption = documentConsumption;
42
- async function queryDocuments(commonWell, queryMeta) {
43
- // E1: Document Query
44
- console.log(`>>> E1c: Query for documents using FHIR (REST)`);
45
- const { personId, patientId } = await (0, shared_person_1.findOrCreatePerson)(commonWell, queryMeta, (0, payloads_1.makeDocPerson)({ facilityId: commonWell.oid }));
46
- if (!personId)
47
- throw new Error(`[E1c] personId is undefined before calling getNetworkLinks()`);
48
- const respLinks = await commonWell.getNetworkLinks(queryMeta, patientId);
49
- console.log(respLinks);
50
- const allLinks = respLinks._embedded.networkLink
51
- ? respLinks._embedded.networkLink.flatMap(util_1.filterTruthy)
52
- : [];
53
- const lola1Links = allLinks.filter(commonwell_sdk_1.isLOLA1);
54
- console.log(`Found ${allLinks.length} network links, ${lola1Links.length} are LOLA 1`);
55
- for (const link of lola1Links) {
56
- const upgradeURL = link._links?.upgrade?.href;
57
- if (!upgradeURL) {
58
- console.log(`[queryDocuments] missing upgrade URL for link `, link);
59
- continue;
60
- }
61
- const respUpgradeLink = await commonWell.upgradeOrDowngradeNetworkLink(queryMeta, upgradeURL);
62
- console.log(respUpgradeLink);
63
- }
64
- console.log(`>>> [E1c] Querying for docs...`);
65
- const respDocQuery = await commonWell.queryDocuments(queryMeta, patientId);
66
- return respDocQuery.entry;
67
- }
68
- exports.queryDocuments = queryDocuments;
69
- async function retrieveDocument(commonWell, queryMeta, doc) {
70
- // E2: Document Retrieve
71
- console.log(`>>> E2c: Retrieve documents using FHIR (REST)`);
72
- // store the query result as well
73
- const queryFileName = `./cw_consumption_${doc.id ?? "ID"}_${(0, payloads_1.makeId)()}.response.file`;
74
- fs.writeFileSync(queryFileName, JSON.stringify(doc));
75
- const fileName = `./cw_consumption_${doc.id ?? "ID"}_${(0, payloads_1.makeId)()}.contents.file`;
76
- // the default is UTF-8, avoid changing the encoding if we don't know the file we're downloading
77
- const outputStream = fs.createWriteStream(fileName, { encoding: undefined });
78
- console.log(`File being created at ${process.cwd()}/${fileName}`);
79
- const url = doc.content.location;
80
- if (!url)
81
- throw new Error(`[E2c] missing content.location in document ${doc.id}`);
82
- await commonWell.retrieveDocument(queryMeta, url, outputStream);
83
- }
84
- exports.retrieveDocument = retrieveDocument;
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.retrieveDocument = exports.queryDocuments = exports.documentConsumption = void 0;
28
+ const commonwell_sdk_1 = require("@metriport/commonwell-sdk");
29
+ const fs = __importStar(require("fs"));
30
+ const payloads_1 = require("./payloads");
31
+ const shared_person_1 = require("./shared-person");
32
+ const util_1 = require("./util");
33
+ // Document Consumption
34
+ // https://commonwellalliance.sharepoint.com/sites/ServiceAdopter/SitePages/Document-Consumption-(SOAP,-REST).aspx
35
+ async function documentConsumption(commonWell, queryMeta) {
36
+ const documents = await queryDocuments(commonWell, queryMeta);
37
+ for (const doc of documents) {
38
+ await retrieveDocument(commonWell, queryMeta, doc);
39
+ }
40
+ }
41
+ exports.documentConsumption = documentConsumption;
42
+ async function queryDocuments(commonWell, queryMeta) {
43
+ // E1: Document Query
44
+ console.log(`>>> E1c: Query for documents using FHIR (REST)`);
45
+ const { personId, patientId } = await (0, shared_person_1.findOrCreatePerson)(commonWell, queryMeta, (0, payloads_1.makeDocPerson)({ facilityId: commonWell.oid }));
46
+ if (!personId)
47
+ throw new Error(`[E1c] personId is undefined before calling getNetworkLinks()`);
48
+ const respLinks = await commonWell.getNetworkLinks(queryMeta, patientId);
49
+ console.log(respLinks);
50
+ const allLinks = respLinks._embedded.networkLink
51
+ ? respLinks._embedded.networkLink.flatMap(util_1.filterTruthy)
52
+ : [];
53
+ const lola1Links = allLinks.filter(commonwell_sdk_1.isLOLA1);
54
+ console.log(`Found ${allLinks.length} network links, ${lola1Links.length} are LOLA 1`);
55
+ for (const link of lola1Links) {
56
+ const upgradeURL = link._links?.upgrade?.href;
57
+ if (!upgradeURL) {
58
+ console.log(`[queryDocuments] missing upgrade URL for link `, link);
59
+ continue;
60
+ }
61
+ const respUpgradeLink = await commonWell.upgradeOrDowngradeNetworkLink(queryMeta, upgradeURL);
62
+ console.log(respUpgradeLink);
63
+ }
64
+ console.log(`>>> [E1c] Querying for docs...`);
65
+ const respDocQuery = await commonWell.queryDocuments(queryMeta, patientId);
66
+ return respDocQuery.entry;
67
+ }
68
+ exports.queryDocuments = queryDocuments;
69
+ async function retrieveDocument(commonWell, queryMeta, doc) {
70
+ // E2: Document Retrieve
71
+ console.log(`>>> E2c: Retrieve documents using FHIR (REST)`);
72
+ // store the query result as well
73
+ const queryFileName = `./cw_consumption_${doc.id ?? "ID"}_${(0, payloads_1.makeId)()}.response.file`;
74
+ fs.writeFileSync(queryFileName, JSON.stringify(doc));
75
+ const fileName = `./cw_consumption_${doc.id ?? "ID"}_${(0, payloads_1.makeId)()}.contents.file`;
76
+ // the default is UTF-8, avoid changing the encoding if we don't know the file we're downloading
77
+ const outputStream = fs.createWriteStream(fileName, { encoding: undefined });
78
+ console.log(`File being created at ${process.cwd()}/${fileName}`);
79
+ const url = doc.content.location;
80
+ if (!url)
81
+ throw new Error(`[E2c] missing content.location in document ${doc.id}`);
82
+ await commonWell.retrieveDocument(queryMeta, url, outputStream);
83
+ }
84
+ exports.retrieveDocument = retrieveDocument;
85
85
  //# sourceMappingURL=document-consumption.js.map
@@ -1,7 +1,7 @@
1
- #!/usr/bin/env node
2
- import { CommonWell, RequestMetadata } from "@metriport/commonwell-sdk";
3
- export declare function documentContribution({ memberManagementApi, api: apiDefaultOrg, queryMeta, }: {
4
- memberManagementApi: CommonWell;
5
- api: CommonWell;
6
- queryMeta: RequestMetadata;
7
- }): Promise<void>;
1
+ #!/usr/bin/env node
2
+ import { CommonWell, RequestMetadata } from "@metriport/commonwell-sdk";
3
+ export declare function documentContribution({ memberManagementApi, api: apiDefaultOrg, queryMeta, }: {
4
+ memberManagementApi: CommonWell;
5
+ api: CommonWell;
6
+ queryMeta: RequestMetadata;
7
+ }): Promise<void>;