@metriport/commonwell-sdk 0.30.0-alpha.1
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 +21 -0
- package/README.md +64 -0
- package/dist/__tests__/env-setup.d.ts +2 -0
- package/dist/__tests__/env-setup.d.ts.map +1 -0
- package/dist/__tests__/env-setup.js +35 -0
- package/dist/__tests__/env-setup.js.map +1 -0
- package/dist/client/common.d.ts +39 -0
- package/dist/client/common.d.ts.map +1 -0
- package/dist/client/common.js +15 -0
- package/dist/client/common.js.map +1 -0
- package/dist/client/commonwell-api.d.ts +103 -0
- package/dist/client/commonwell-api.d.ts.map +1 -0
- package/dist/client/commonwell-api.js +3 -0
- package/dist/client/commonwell-api.js.map +1 -0
- package/dist/client/commonwell-base.d.ts +47 -0
- package/dist/client/commonwell-base.d.ts.map +1 -0
- package/dist/client/commonwell-base.js +105 -0
- package/dist/client/commonwell-base.js.map +1 -0
- package/dist/client/commonwell-member-api.d.ts +29 -0
- package/dist/client/commonwell-member-api.d.ts.map +1 -0
- package/dist/client/commonwell-member-api.js +3 -0
- package/dist/client/commonwell-member-api.js.map +1 -0
- package/dist/client/commonwell-member.d.ts +168 -0
- package/dist/client/commonwell-member.d.ts.map +1 -0
- package/dist/client/commonwell-member.js +349 -0
- package/dist/client/commonwell-member.js.map +1 -0
- package/dist/client/commonwell.d.ts +245 -0
- package/dist/client/commonwell.d.ts.map +1 -0
- package/dist/client/commonwell.js +502 -0
- package/dist/client/commonwell.js.map +1 -0
- package/dist/common/__tests__/util.test.d.ts +2 -0
- package/dist/common/__tests__/util.test.d.ts.map +1 -0
- package/dist/common/__tests__/util.test.js +51 -0
- package/dist/common/__tests__/util.test.js.map +1 -0
- package/dist/common/__tests__/validate-npi.test.d.ts +2 -0
- package/dist/common/__tests__/validate-npi.test.d.ts.map +1 -0
- package/dist/common/__tests__/validate-npi.test.js +44 -0
- package/dist/common/__tests__/validate-npi.test.js.map +1 -0
- package/dist/common/certificate.d.ts +3 -0
- package/dist/common/certificate.d.ts.map +1 -0
- package/dist/common/certificate.js +11 -0
- package/dist/common/certificate.js.map +1 -0
- package/dist/common/commonwell-error.d.ts +23 -0
- package/dist/common/commonwell-error.d.ts.map +1 -0
- package/dist/common/commonwell-error.js +33 -0
- package/dist/common/commonwell-error.js.map +1 -0
- package/dist/common/fileDownload.d.ts +37 -0
- package/dist/common/fileDownload.d.ts.map +1 -0
- package/dist/common/fileDownload.js +53 -0
- package/dist/common/fileDownload.js.map +1 -0
- package/dist/common/make-jwt.d.ts +60 -0
- package/dist/common/make-jwt.d.ts.map +1 -0
- package/dist/common/make-jwt.js +124 -0
- package/dist/common/make-jwt.js.map +1 -0
- package/dist/common/util.d.ts +78 -0
- package/dist/common/util.d.ts.map +1 -0
- package/dist/common/util.js +104 -0
- package/dist/common/util.js.map +1 -0
- package/dist/common/validate-npi.d.ts +2 -0
- package/dist/common/validate-npi.d.ts.map +1 -0
- package/dist/common/validate-npi.js +6 -0
- package/dist/common/validate-npi.js.map +1 -0
- package/dist/common/zod.d.ts +13 -0
- package/dist/common/zod.d.ts.map +1 -0
- package/dist/common/zod.js +38 -0
- package/dist/common/zod.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/dist/models/__tests__/address.test.d.ts +2 -0
- package/dist/models/__tests__/address.test.d.ts.map +1 -0
- package/dist/models/__tests__/address.test.js +348 -0
- package/dist/models/__tests__/address.test.js.map +1 -0
- package/dist/models/__tests__/demographics.test.d.ts +2 -0
- package/dist/models/__tests__/demographics.test.d.ts.map +1 -0
- package/dist/models/__tests__/demographics.test.js +96 -0
- package/dist/models/__tests__/demographics.test.js.map +1 -0
- package/dist/models/address.d.ts +177 -0
- package/dist/models/address.d.ts.map +1 -0
- package/dist/models/address.js +94 -0
- package/dist/models/address.js.map +1 -0
- package/dist/models/certificates.d.ts +77 -0
- package/dist/models/certificates.d.ts.map +1 -0
- package/dist/models/certificates.js +27 -0
- package/dist/models/certificates.js.map +1 -0
- package/dist/models/contact.d.ts +47 -0
- package/dist/models/contact.d.ts.map +1 -0
- package/dist/models/contact.js +30 -0
- package/dist/models/contact.js.map +1 -0
- package/dist/models/date.d.ts +4 -0
- package/dist/models/date.d.ts.map +1 -0
- package/dist/models/date.js +10 -0
- package/dist/models/date.js.map +1 -0
- package/dist/models/demographics.d.ts +290 -0
- package/dist/models/demographics.d.ts.map +1 -0
- package/dist/models/demographics.js +57 -0
- package/dist/models/demographics.js.map +1 -0
- package/dist/models/document.d.ts +7823 -0
- package/dist/models/document.d.ts.map +1 -0
- package/dist/models/document.js +106 -0
- package/dist/models/document.js.map +1 -0
- package/dist/models/facility.d.ts +82 -0
- package/dist/models/facility.d.ts.map +1 -0
- package/dist/models/facility.js +11 -0
- package/dist/models/facility.js.map +1 -0
- package/dist/models/human-name.d.ts +56 -0
- package/dist/models/human-name.d.ts.map +1 -0
- package/dist/models/human-name.js +39 -0
- package/dist/models/human-name.js.map +1 -0
- package/dist/models/identifier.d.ts +110 -0
- package/dist/models/identifier.d.ts.map +1 -0
- package/dist/models/identifier.js +37 -0
- package/dist/models/identifier.js.map +1 -0
- package/dist/models/organization.d.ts +2390 -0
- package/dist/models/organization.d.ts.map +1 -0
- package/dist/models/organization.js +139 -0
- package/dist/models/organization.js.map +1 -0
- package/dist/models/patient-organization.d.ts +36 -0
- package/dist/models/patient-organization.d.ts.map +1 -0
- package/dist/models/patient-organization.js +10 -0
- package/dist/models/patient-organization.js.map +1 -0
- package/dist/models/patient.d.ts +5350 -0
- package/dist/models/patient.d.ts.map +1 -0
- package/dist/models/patient.js +94 -0
- package/dist/models/patient.js.map +1 -0
- package/dist/models/period.d.ts +13 -0
- package/dist/models/period.d.ts.map +1 -0
- package/dist/models/period.js +13 -0
- package/dist/models/period.js.map +1 -0
- package/dist/models/reference.d.ts +109 -0
- package/dist/models/reference.d.ts.map +1 -0
- package/dist/models/reference.js +12 -0
- package/dist/models/reference.js.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeCertificate = void 0;
|
|
4
|
+
function normalizeCertificate(certificate) {
|
|
5
|
+
return {
|
|
6
|
+
...certificate,
|
|
7
|
+
...(certificate.thumbprint && { thumbprint: certificate.thumbprint.replace(/:/g, "") }),
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
exports.normalizeCertificate = normalizeCertificate;
|
|
11
|
+
//# sourceMappingURL=certificate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"certificate.js","sourceRoot":"","sources":["../../src/common/certificate.ts"],"names":[],"mappings":";;;AAEA,SAAgB,oBAAoB,CAAC,WAAwB;IAC3D,OAAO;QACL,GAAG,WAAW;QACd,GAAG,CAAC,WAAW,CAAC,UAAU,IAAI,EAAE,UAAU,EAAE,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC;KACxF,CAAC;AACJ,CAAC;AALD,oDAKC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare class Response {
|
|
2
|
+
status: number | undefined;
|
|
3
|
+
}
|
|
4
|
+
export type AdditionalInfo = {
|
|
5
|
+
/**
|
|
6
|
+
* The CommonWell correlation/log code.
|
|
7
|
+
*/
|
|
8
|
+
cwReference?: string;
|
|
9
|
+
} & Record<string, string | number | undefined | null | Record<string, string>>;
|
|
10
|
+
export declare class CommonwellError extends Error {
|
|
11
|
+
readonly cause?: any;
|
|
12
|
+
readonly additionalInfo?: AdditionalInfo | undefined;
|
|
13
|
+
private _status;
|
|
14
|
+
private _code;
|
|
15
|
+
readonly cwReference: string | undefined;
|
|
16
|
+
constructor(message?: string | undefined, cause?: any, //eslint-disable-line @typescript-eslint/no-explicit-any
|
|
17
|
+
additionalInfo?: AdditionalInfo | undefined);
|
|
18
|
+
get status(): number | undefined;
|
|
19
|
+
get code(): string | undefined;
|
|
20
|
+
get response(): Response;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=commonwell-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commonwell-error.d.ts","sourceRoot":"","sources":["../../src/common/commonwell-error.ts"],"names":[],"mappings":"AAEA,cAAM,QAAQ;IACZ,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEhF,qBAAa,eAAgB,SAAQ,KAAK;IAOtC,QAAQ,CAAC,KAAK,CAAC;IACf,QAAQ,CAAC,cAAc,CAAC;IAP1B,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,KAAK,CAAqB;IAClC,SAAgB,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;gBAG9C,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,EACnB,KAAK,CAAC,KAAK,EAAE,wDAAwD;IACrE,cAAc,CAAC,4BAAgB;IAW1C,IAAI,MAAM,IAAI,MAAM,GAAG,SAAS,CAE/B;IACD,IAAI,IAAI,IAAI,MAAM,GAAG,SAAS,CAE7B;IACD,IAAI,QAAQ,IAAI,QAAQ,CAIvB;CACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommonwellError = void 0;
|
|
4
|
+
const shared_1 = require("@metriport/shared");
|
|
5
|
+
class Response {
|
|
6
|
+
}
|
|
7
|
+
class CommonwellError extends Error {
|
|
8
|
+
constructor(message, cause, //eslint-disable-line @typescript-eslint/no-explicit-any
|
|
9
|
+
additionalInfo) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.cause = cause;
|
|
12
|
+
this.additionalInfo = additionalInfo;
|
|
13
|
+
if (cause) {
|
|
14
|
+
const { code, status } = (0, shared_1.getNetworkErrorDetails)(cause);
|
|
15
|
+
this._status = status;
|
|
16
|
+
this._code = code;
|
|
17
|
+
}
|
|
18
|
+
this.cwReference = additionalInfo?.cwReference;
|
|
19
|
+
}
|
|
20
|
+
get status() {
|
|
21
|
+
return this._status;
|
|
22
|
+
}
|
|
23
|
+
get code() {
|
|
24
|
+
return this._code;
|
|
25
|
+
}
|
|
26
|
+
get response() {
|
|
27
|
+
return {
|
|
28
|
+
status: this._status,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.CommonwellError = CommonwellError;
|
|
33
|
+
//# sourceMappingURL=commonwell-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commonwell-error.js","sourceRoot":"","sources":["../../src/common/commonwell-error.ts"],"names":[],"mappings":";;;AAAA,8CAA2D;AAE3D,MAAM,QAAQ;CAEb;AASD,MAAa,eAAgB,SAAQ,KAAK;IAKxC,YACE,OAA4B,EACnB,KAAW,EAAE,wDAAwD;IACrE,cAA+B;QAExC,KAAK,CAAC,OAAO,CAAC,CAAC;QAHN,UAAK,GAAL,KAAK,CAAM;QACX,mBAAc,GAAd,cAAc,CAAiB;QAGxC,IAAI,KAAK,EAAE;YACT,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAA,+BAAsB,EAAC,KAAK,CAAC,CAAC;YACvD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;YACtB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;SACnB;QACD,IAAI,CAAC,WAAW,GAAG,cAAc,EAAE,WAAW,CAAC;IACjD,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IACD,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IACD,IAAI,QAAQ;QACV,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,OAAO;SACrB,CAAC;IACJ,CAAC;CACF;AA9BD,0CA8BC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { AxiosInstance } from "axios";
|
|
4
|
+
import * as stream from "stream";
|
|
5
|
+
export declare function downloadFileInMemory({ url, client, responseType, headers, }: {
|
|
6
|
+
url: string;
|
|
7
|
+
client?: AxiosInstance;
|
|
8
|
+
responseType: "arraybuffer";
|
|
9
|
+
headers?: {
|
|
10
|
+
[index: string]: string;
|
|
11
|
+
};
|
|
12
|
+
}): Promise<Buffer>;
|
|
13
|
+
export declare function downloadFileInMemory({ url, client, responseType, headers, }: {
|
|
14
|
+
url: string;
|
|
15
|
+
client?: AxiosInstance;
|
|
16
|
+
responseType: "text";
|
|
17
|
+
headers?: {
|
|
18
|
+
[index: string]: string;
|
|
19
|
+
};
|
|
20
|
+
}): Promise<string>;
|
|
21
|
+
export declare function downloadFileInMemory({ url, client, responseType, headers, }: {
|
|
22
|
+
url: string;
|
|
23
|
+
client?: AxiosInstance;
|
|
24
|
+
responseType: "json";
|
|
25
|
+
headers?: {
|
|
26
|
+
[index: string]: string;
|
|
27
|
+
};
|
|
28
|
+
}): Promise<any>;
|
|
29
|
+
export declare function downloadFileAsStream({ url, outputStream, client, headers, }: {
|
|
30
|
+
url: string;
|
|
31
|
+
outputStream: stream.Writable;
|
|
32
|
+
client?: AxiosInstance;
|
|
33
|
+
headers?: {
|
|
34
|
+
[index: string]: string;
|
|
35
|
+
};
|
|
36
|
+
}): Promise<boolean>;
|
|
37
|
+
//# sourceMappingURL=fileDownload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileDownload.d.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AM,CAAC,EAAE,aAAa,CAAC;IACvB,OAAO,CAAC,EAAE;QACR,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;KACzB,CAAC;CACH,GAAG,OAAO,CAAC,OAAO,CAAC,CAQnB"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.downloadFileAsStream = exports.downloadFileInMemory = void 0;
|
|
30
|
+
const axios_1 = __importDefault(require("axios"));
|
|
31
|
+
const stream = __importStar(require("stream"));
|
|
32
|
+
const util = __importStar(require("util"));
|
|
33
|
+
const pipeline = util.promisify(stream.pipeline);
|
|
34
|
+
async function downloadFileInMemory({ url, client, responseType, headers, }) {
|
|
35
|
+
const config = {
|
|
36
|
+
...(headers && { headers }),
|
|
37
|
+
responseType,
|
|
38
|
+
};
|
|
39
|
+
const response = await (client ?? axios_1.default).get(url, config);
|
|
40
|
+
return response.data;
|
|
41
|
+
}
|
|
42
|
+
exports.downloadFileInMemory = downloadFileInMemory;
|
|
43
|
+
async function downloadFileAsStream({ url, outputStream, client, headers, }) {
|
|
44
|
+
const config = {
|
|
45
|
+
responseType: "stream",
|
|
46
|
+
...(headers && { headers }),
|
|
47
|
+
};
|
|
48
|
+
const response = await (client ?? axios_1.default).get(url, config);
|
|
49
|
+
await pipeline(response.data, outputStream);
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
exports.downloadFileAsStream = downloadFileAsStream;
|
|
53
|
+
//# sourceMappingURL=fileDownload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileDownload.js","sourceRoot":"","sources":["../../src/common/fileDownload.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAAiE;AACjE,+CAAiC;AACjC,2CAA6B;AAE7B,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AA0C1C,KAAK,UAAU,oBAAoB,CAAC,EACzC,GAAG,EACH,MAAM,EACN,YAAY,EACZ,OAAO,GASR;IACC,MAAM,MAAM,GAAuB;QACjC,GAAG,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,CAAC;QAC3B,YAAY;KACb,CAAC;IACF,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,IAAI,eAAK,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC1D,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB,CAAC;AApBD,oDAoBC;AAEM,KAAK,UAAU,oBAAoB,CAAC,EACzC,GAAG,EACH,YAAY,EACZ,MAAM,EACN,OAAO,GAQR;IACC,MAAM,MAAM,GAAuB;QACjC,YAAY,EAAE,QAAQ;QACtB,GAAG,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,CAAC;KAC5B,CAAC;IACF,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,IAAI,eAAK,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC1D,MAAM,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAC5C,OAAO,IAAI,CAAC;AACd,CAAC;AApBD,oDAoBC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { PurposeOfUse } from "@metriport/shared";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a JWT Based on the specified parameters as per the CommonWell spec:
|
|
4
|
+
* @see https://www.commonwellalliance.org/specification/
|
|
5
|
+
*
|
|
6
|
+
* @returns The JWT token.
|
|
7
|
+
*/
|
|
8
|
+
export declare function makeJwt({ rsaPrivateKey, hmacSecret, role, subjectId, orgName, oid, homeCommunityId: homeCommunityIdParam, purposeOfUse, npi, authGrantorReference, }: {
|
|
9
|
+
/**
|
|
10
|
+
* The RSA256 private key corresponding to the specified organization's public key (certificate),
|
|
11
|
+
* used for signing the JWT.
|
|
12
|
+
* If set, the JWT will be signed with the RSA256 algorithm.
|
|
13
|
+
* If not set, hmacSecret must be set.
|
|
14
|
+
*/
|
|
15
|
+
rsaPrivateKey?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The HMAC secret to sign the JWT with the HS256 algorithm.
|
|
18
|
+
* If set, the JWT will be signed with the HS256 algorithm.
|
|
19
|
+
* If not set, rsaPrivateKey must be set.
|
|
20
|
+
*/
|
|
21
|
+
hmacSecret?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The practitioner role of the entity making this request.
|
|
24
|
+
* Valid role values: https://hl7.org/fhir/R4/valueset-practitioner-role.html
|
|
25
|
+
*/
|
|
26
|
+
role: string;
|
|
27
|
+
/**
|
|
28
|
+
* Free text field used for audit purposes. The value should be user ID or user name of staff
|
|
29
|
+
* using the CommonWell enabled system. Can be a system user if the API call is generated from an
|
|
30
|
+
* automated process instead of an actual user.
|
|
31
|
+
*/
|
|
32
|
+
subjectId: string;
|
|
33
|
+
/** The organization name for the request, should match the OID in the claims. */
|
|
34
|
+
orgName: string;
|
|
35
|
+
/**
|
|
36
|
+
* OID of the org making the request. CW uses this ID to certificate in order to validate the
|
|
37
|
+
* signature on the token.
|
|
38
|
+
*/
|
|
39
|
+
oid: string;
|
|
40
|
+
/**
|
|
41
|
+
* The Home Community OID assigned to the Organization that is initiating the request (the URN
|
|
42
|
+
* "urn:oid" will be automatically appended).
|
|
43
|
+
*
|
|
44
|
+
* If not set, it will be set to the OID of the org making the request.
|
|
45
|
+
*/
|
|
46
|
+
homeCommunityId?: string;
|
|
47
|
+
/** The purpose of use (POU) for this request - the reason for the request. */
|
|
48
|
+
purposeOfUse: PurposeOfUse;
|
|
49
|
+
/** Ten digit National Provider Identifier (optional) */
|
|
50
|
+
npi?: string | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* The value MUST be the Directory Entry assigned to the Principal for whom the Delegate is
|
|
53
|
+
* initiating the request, formatted using the FHIR (Fast Healthcare Interoperability Resources)
|
|
54
|
+
* Resource (Reference?) format.
|
|
55
|
+
*
|
|
56
|
+
* Example: "Organization/urn:oid:2.16.840.1.113883.3.7204.1"
|
|
57
|
+
*/
|
|
58
|
+
authGrantorReference?: string | undefined;
|
|
59
|
+
}): string;
|
|
60
|
+
//# sourceMappingURL=make-jwt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-jwt.d.ts","sourceRoot":"","sources":["../../src/common/make-jwt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AA4DjD;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,EACtB,aAAa,EACb,UAAU,EACV,IAAI,EACJ,SAAS,EACT,OAAO,EACP,GAAG,EACH,eAAe,EAAE,oBAAoB,EACrC,YAAY,EACZ,GAAG,EACH,oBAAoB,GACrB,EAAE;IACD;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,iFAAiF;IACjF,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,8EAA8E;IAC9E,YAAY,EAAE,YAAY,CAAC;IAC3B,wDAAwD;IACxD,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3C,GAAG,MAAM,CA0CT"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.makeJwt = void 0;
|
|
27
|
+
const jwt = __importStar(require("jsonwebtoken"));
|
|
28
|
+
const validate_npi_1 = require("./validate-npi");
|
|
29
|
+
/**
|
|
30
|
+
* For all items in this file:
|
|
31
|
+
* @see https://www.commonwellalliance.org/specification/
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* The SNOMED CT value representing the role that the user is playing when making the request.
|
|
35
|
+
*/
|
|
36
|
+
const roleClaim = "urn:oasis:names:tc:xacml:2.0:subject:role";
|
|
37
|
+
/**
|
|
38
|
+
* The name of the user as required by HIPAA Privacy Disclosure Accounting.
|
|
39
|
+
*/
|
|
40
|
+
const subjectIdClaim = "urn:oasis:names:tc:xspa:1.0:subject:subject-id";
|
|
41
|
+
/**
|
|
42
|
+
* In plain text, the organization that the user belongs to as required by HIPAA Privacy Disclosure
|
|
43
|
+
* Accounting.
|
|
44
|
+
*/
|
|
45
|
+
const orgNameClaim = "urn:oasis:names:tc:xspa:1.0:subject:organization";
|
|
46
|
+
/**
|
|
47
|
+
* A unique identifier for the organization that the user is representing in performing this
|
|
48
|
+
* transaction. The organization ID may be an Object Identifier (OID), or it may be a URL
|
|
49
|
+
* assigned to that organization
|
|
50
|
+
*/
|
|
51
|
+
const oidClaim = "urn:oasis:names:tc:xspa:1.0:subject:organization-id";
|
|
52
|
+
/**
|
|
53
|
+
* The coded representation of the reason for the request.
|
|
54
|
+
*/
|
|
55
|
+
const purposeOfUseClaim = "urn:oasis:names:tc:xspa:1.0:subject:purposeofuse";
|
|
56
|
+
/**
|
|
57
|
+
* Recommended: A National Provider Identifier (NPI) is a unique 10-digit identification number issued
|
|
58
|
+
* to healthcare providers in the United States by the Centers for Medicare and Medicaid Services (CMS).
|
|
59
|
+
* Edge System should send NPI if known.
|
|
60
|
+
*/
|
|
61
|
+
const npiClaim = "urn:oasis:names:tc:xspa:2.0:subject:npi";
|
|
62
|
+
// const payloadHashClaim = "urn:commonwell-alliance:payload-hash";
|
|
63
|
+
/**
|
|
64
|
+
* The value shall be the Home Community ID (an Object Identifier) assigned to the Organization
|
|
65
|
+
* that is initiating the request, using the urn format (that is, “urn:oid:” appended with the OID)
|
|
66
|
+
*/
|
|
67
|
+
const homeCommunityIdClaim = "urn:nhin:names:saml:homeCommunityId";
|
|
68
|
+
/**
|
|
69
|
+
* Required for Delegation of Authority (DOA) requests.
|
|
70
|
+
*
|
|
71
|
+
* When sending delegated requests, the delegate organization must include information about the
|
|
72
|
+
* principal organization.
|
|
73
|
+
*
|
|
74
|
+
* The value MUST be the Directory Entry assigned to the Principal for whom the Delegate is
|
|
75
|
+
* initiating the request, formatted using the FHIR (Fast Healthcare Interoperability Resources)
|
|
76
|
+
* Resource (Reference?) format.
|
|
77
|
+
*
|
|
78
|
+
* Example: "Organization/urn:oid:2.16.840.1.113883.3.7204.1"
|
|
79
|
+
*/
|
|
80
|
+
const authGrantorClaim = "QueryAuthGrantor";
|
|
81
|
+
const TOKEN_EXPIRY_SECONDS = 3600; // 1 hour
|
|
82
|
+
/**
|
|
83
|
+
* Creates a JWT Based on the specified parameters as per the CommonWell spec:
|
|
84
|
+
* @see https://www.commonwellalliance.org/specification/
|
|
85
|
+
*
|
|
86
|
+
* @returns The JWT token.
|
|
87
|
+
*/
|
|
88
|
+
function makeJwt({ rsaPrivateKey, hmacSecret, role, subjectId, orgName, oid, homeCommunityId: homeCommunityIdParam, purposeOfUse, npi, authGrantorReference, }) {
|
|
89
|
+
if (rsaPrivateKey && hmacSecret) {
|
|
90
|
+
throw new Error("Only one of rsaPrivateKey or hmacSecret must be set, not both");
|
|
91
|
+
}
|
|
92
|
+
const secret = rsaPrivateKey ?? hmacSecret;
|
|
93
|
+
if (!secret) {
|
|
94
|
+
throw new Error("Either rsaPrivateKey or hmacSecret must be set");
|
|
95
|
+
}
|
|
96
|
+
if (npi && !(0, validate_npi_1.validateNPI)(npi)) {
|
|
97
|
+
throw new Error(`NPI number ${npi} is not valid!`);
|
|
98
|
+
}
|
|
99
|
+
const urnPrefix = "urn:oid:";
|
|
100
|
+
const homeCommunityId = homeCommunityIdParam ?? oid;
|
|
101
|
+
const homeCommunityIdValue = homeCommunityId.includes(urnPrefix)
|
|
102
|
+
? homeCommunityId
|
|
103
|
+
: `${urnPrefix}${homeCommunityId}`;
|
|
104
|
+
const jwtToken = jwt.sign({
|
|
105
|
+
[roleClaim]: role,
|
|
106
|
+
[subjectIdClaim]: subjectId,
|
|
107
|
+
[orgNameClaim]: orgName,
|
|
108
|
+
[oidClaim]: oid,
|
|
109
|
+
[purposeOfUseClaim]: purposeOfUse.toString(),
|
|
110
|
+
...(npi && { [npiClaim]: npi }),
|
|
111
|
+
[homeCommunityIdClaim]: homeCommunityIdValue,
|
|
112
|
+
iss: "self",
|
|
113
|
+
aud: "urn:commonwellalliance.org",
|
|
114
|
+
nbf: Math.floor(Date.now() / 1000),
|
|
115
|
+
exp: Math.floor(Date.now() / 1000) + TOKEN_EXPIRY_SECONDS,
|
|
116
|
+
...(authGrantorReference && { [authGrantorClaim]: authGrantorReference }),
|
|
117
|
+
}, secret, {
|
|
118
|
+
algorithm: rsaPrivateKey ? "RS256" : "HS256",
|
|
119
|
+
noTimestamp: true, // Don't add the issuedAt claim
|
|
120
|
+
});
|
|
121
|
+
return jwtToken;
|
|
122
|
+
}
|
|
123
|
+
exports.makeJwt = makeJwt;
|
|
124
|
+
//# sourceMapping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
|
|
3
|
+
export type EncodePatientIdForDocumentExchangeParams = {
|
|
4
|
+
patientId: string;
|
|
5
|
+
assignAuthority: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Regex pattern to extract code, system, and optional assignAuthType from CommonWell patient ID
|
|
9
|
+
* Matches: code^^^&system&assignAuthType
|
|
10
|
+
* Where assignAuthType is optional
|
|
11
|
+
*/
|
|
12
|
+
export declare const CW_PATIENT_ID_REGEX_V2: RegExp;
|
|
13
|
+
/**
|
|
14
|
+
* Get the local Patient ID from the Patient Response Item's Links Self link.
|
|
15
|
+
* This ID is in the HL7 CX data type format, so it includes the system/assigninig authority's system.
|
|
16
|
+
*
|
|
17
|
+
* @param links - The Patient Links.
|
|
18
|
+
* @returns The Patient ID.
|
|
19
|
+
* @see Section "8.3.2 Get Patient" of the spec.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getCwPatientIdFromLinks(links: PatientLinks): string;
|
|
22
|
+
/**
|
|
23
|
+
* Decodes the patient ID in the HL7 CX data type format into its components.
|
|
24
|
+
*
|
|
25
|
+
* @param patientId - The patient's ID in the HL7 CX data type format.
|
|
26
|
+
* @returns The decoded patient ID, with the value, assignAuthority, and assignAuthorityType.
|
|
27
|
+
* @see Section "8.3.2 Get Patient" of the spec.
|
|
28
|
+
*/
|
|
29
|
+
export declare function decodeCwPatientIdV2(patientId: string): {
|
|
30
|
+
value: string | undefined;
|
|
31
|
+
assignAuthority: string | undefined;
|
|
32
|
+
assignAuthorityType: string | undefined;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Encodes the patient ID into the HL7 CX data type format.
|
|
36
|
+
*
|
|
37
|
+
* @param patientId - The patient's ID.
|
|
38
|
+
* @param assignAuthority - The assign authority of the patient.
|
|
39
|
+
* @param assignAuthorityType - The assign authority type of the patient.
|
|
40
|
+
* @returns The patient ID in the HL7 CX data type format.
|
|
41
|
+
* @see Section "8.3.2 Get Patient" of the spec.
|
|
42
|
+
*/
|
|
43
|
+
export declare function encodeCwPatientId({ patientId, assignAuthority, assignAuthorityType, }: {
|
|
44
|
+
patientId: string;
|
|
45
|
+
assignAuthority: string;
|
|
46
|
+
assignAuthorityType?: string | undefined;
|
|
47
|
+
}): string;
|
|
48
|
+
/**
|
|
49
|
+
* Converts the patient ID into subject ID, to be used during document query.
|
|
50
|
+
*
|
|
51
|
+
* @param cwPatientId - The patient's ID in the HL7 CX data type format.
|
|
52
|
+
* @returns The subject ID as defined by the specification: [system]|[code] where 'system'
|
|
53
|
+
* is the OID of the organization and 'code' is the first part of the patient ID.
|
|
54
|
+
* @see Sectin "10.2.1 Document Query" of the spec.
|
|
55
|
+
*/
|
|
56
|
+
export declare function encodePatientIdForDocumentExchange(cwPatientId: string): string | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Converts the patient ID into subject ID, to be used during document query.
|
|
59
|
+
*
|
|
60
|
+
* @param patientId - The patient's ID from the Edge System, unencoded.
|
|
61
|
+
* @param assignAuthority - The assign authority of the patient.
|
|
62
|
+
* @returns The subject ID as defined by the specification: [system]|[code] where 'system'
|
|
63
|
+
* is the OID of the organization and 'code' is the first part of the patient ID.
|
|
64
|
+
* @see Sectin "10.2.1 Document Query" of the spec.
|
|
65
|
+
*/
|
|
66
|
+
export declare function encodePatientIdForDocumentExchange({ patientId, assignAuthority, }: EncodePatientIdForDocumentExchangeParams): string;
|
|
67
|
+
/**
|
|
68
|
+
* Decodes the patient ID into its components.
|
|
69
|
+
*
|
|
70
|
+
* @param patientId - The patient's ID in the HL7 CX data type format.
|
|
71
|
+
* @returns The decoded patient ID, with the value and assignAuthority.
|
|
72
|
+
*/
|
|
73
|
+
export declare function decodeCwPatientIdV1(patientId: string): {
|
|
74
|
+
value: string | undefined;
|
|
75
|
+
assignAuthority: string | undefined;
|
|
76
|
+
};
|
|
77
|
+
export declare function buildBaseQueryMeta(orgName: string): BaseRequestMetadata;
|
|
78
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|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AAMD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,mBAAmB,CAMvE"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildBaseQueryMeta = exports.decodeCwPatientIdV1 = exports.encodePatientIdForDocumentExchange = exports.encodeCwPatientId = exports.decodeCwPatientIdV2 = exports.getCwPatientIdFromLinks = exports.CW_PATIENT_ID_REGEX_V2 = void 0;
|
|
4
|
+
const shared_1 = require("@metriport/shared");
|
|
5
|
+
/**
|
|
6
|
+
* Regex pattern to extract code, system, and optional assignAuthType from CommonWell patient ID
|
|
7
|
+
* Matches: code^^^&system&assignAuthType
|
|
8
|
+
* Where assignAuthType is optional
|
|
9
|
+
*/
|
|
10
|
+
exports.CW_PATIENT_ID_REGEX_V2 = /^([^^]+)\^\^\^&([^&]+)(?:&([^&]+))?$/i;
|
|
11
|
+
/**
|
|
12
|
+
* Get the local Patient ID from the Patient Response Item's Links Self link.
|
|
13
|
+
* This ID is in the HL7 CX data type format, so it includes the system/assigninig authority's system.
|
|
14
|
+
*
|
|
15
|
+
* @param links - The Patient Links.
|
|
16
|
+
* @returns The Patient ID.
|
|
17
|
+
* @see Section "8.3.2 Get Patient" of the spec.
|
|
18
|
+
*/
|
|
19
|
+
function getCwPatientIdFromLinks(links) {
|
|
20
|
+
const url = links.Self;
|
|
21
|
+
const isLastCharSlash = url.endsWith("/");
|
|
22
|
+
const removeTrailingSlash = isLastCharSlash ? url.substring(0, url.length - 1) : url;
|
|
23
|
+
return removeTrailingSlash.substring(removeTrailingSlash.lastIndexOf("/") + 1);
|
|
24
|
+
}
|
|
25
|
+
exports.getCwPatientIdFromLinks = getCwPatientIdFromLinks;
|
|
26
|
+
/**
|
|
27
|
+
* Decodes the patient ID in the HL7 CX data type format into its components.
|
|
28
|
+
*
|
|
29
|
+
* @param patientId - The patient's ID in the HL7 CX data type format.
|
|
30
|
+
* @returns The decoded patient ID, with the value, assignAuthority, and assignAuthorityType.
|
|
31
|
+
* @see Section "8.3.2 Get Patient" of the spec.
|
|
32
|
+
*/
|
|
33
|
+
function decodeCwPatientIdV2(patientId) {
|
|
34
|
+
const decoded = decodeURIComponent(decodeURI(patientId));
|
|
35
|
+
const match = decoded.match(exports.CW_PATIENT_ID_REGEX_V2) ?? undefined;
|
|
36
|
+
const value = match && match[1];
|
|
37
|
+
const assignAuthority = match && match[2];
|
|
38
|
+
const assignAuthorityType = match && match[3];
|
|
39
|
+
return { value, assignAuthority, assignAuthorityType };
|
|
40
|
+
}
|
|
41
|
+
exports.decodeCwPatientIdV2 = decodeCwPatientIdV2;
|
|
42
|
+
/**
|
|
43
|
+
* Encodes the patient ID into the HL7 CX data type format.
|
|
44
|
+
*
|
|
45
|
+
* @param patientId - The patient's ID.
|
|
46
|
+
* @param assignAuthority - The assign authority of the patient.
|
|
47
|
+
* @param assignAuthorityType - The assign authority type of the patient.
|
|
48
|
+
* @returns The patient ID in the HL7 CX data type format.
|
|
49
|
+
* @see Section "8.3.2 Get Patient" of the spec.
|
|
50
|
+
*/
|
|
51
|
+
function encodeCwPatientId({ patientId, assignAuthority, assignAuthorityType, }) {
|
|
52
|
+
return `${patientId}^^^&${assignAuthority}&${assignAuthorityType ?? "ISO"}`;
|
|
53
|
+
}
|
|
54
|
+
exports.encodeCwPatientId = encodeCwPatientId;
|
|
55
|
+
function encodePatientIdForDocumentExchange(params) {
|
|
56
|
+
if (typeof params === "string") {
|
|
57
|
+
const { value, assignAuthority } = decodeCwPatientIdV2(params);
|
|
58
|
+
if (value && assignAuthority) {
|
|
59
|
+
return encodePatientIdForDocumentExchange({
|
|
60
|
+
patientId: value,
|
|
61
|
+
assignAuthority,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return convertPatientIdToSubjectIdV1(params);
|
|
65
|
+
}
|
|
66
|
+
const { patientId, assignAuthority } = params;
|
|
67
|
+
return `${assignAuthority}|${patientId}`;
|
|
68
|
+
}
|
|
69
|
+
exports.encodePatientIdForDocumentExchange = encodePatientIdForDocumentExchange;
|
|
70
|
+
/**
|
|
71
|
+
* V1 only
|
|
72
|
+
* Matches: patientId^^^urn:oid:orgOid
|
|
73
|
+
*/
|
|
74
|
+
function convertPatientIdToSubjectIdV1(patientId) {
|
|
75
|
+
const { value, assignAuthority } = decodeCwPatientIdV1(patientId);
|
|
76
|
+
return value && assignAuthority ? buildPatiendIdToDocQuery(value, assignAuthority) : undefined;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Decodes the patient ID into its components.
|
|
80
|
+
*
|
|
81
|
+
* @param patientId - The patient's ID in the HL7 CX data type format.
|
|
82
|
+
* @returns The decoded patient ID, with the value and assignAuthority.
|
|
83
|
+
*/
|
|
84
|
+
function decodeCwPatientIdV1(patientId) {
|
|
85
|
+
const decoded = decodeURIComponent(decodeURI(patientId));
|
|
86
|
+
const regex = /(.+)\^\^\^(.+)/i;
|
|
87
|
+
const match = decoded.match(regex) ?? undefined;
|
|
88
|
+
const value = match && match[1];
|
|
89
|
+
const assignAuthority = match && match[2];
|
|
90
|
+
return { value, assignAuthority };
|
|
91
|
+
}
|
|
92
|
+
exports.decodeCwPatientIdV1 = decodeCwPatientIdV1;
|
|
93
|
+
function buildPatiendIdToDocQuery(code, system) {
|
|
94
|
+
return `${system}|${code}`;
|
|
95
|
+
}
|
|
96
|
+
function buildBaseQueryMeta(orgName) {
|
|
97
|
+
return {
|
|
98
|
+
purposeOfUse: shared_1.PurposeOfUse.TREATMENT,
|
|
99
|
+
role: "ict",
|
|
100
|
+
subjectId: `${orgName} System User`,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
exports.buildBaseQueryMeta = buildBaseQueryMeta;
|
|
104
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/common/util.ts"],"names":[],"mappings":";;;AAAA,8CAAiD;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C7B,CAAC;AAED,SAAgB,kBAAkB,CAAC,OAAe;IAChD,OAAO;QACL,YAAY,EAAE,qBAAY,CAAC,SAAS;QACpC,IAAI,EAAE,KAAK;QACX,SAAS,EAAE,GAAG,OAAO,cAAc;KACpC,CAAC;AACJ,CAAC;AAND,gDAMC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-npi.d.ts","sourceRoot":"","sources":["../../src/common/validate-npi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateNPI = void 0;
|
|
4
|
+
var shared_1 = require("@metriport/shared");
|
|
5
|
+
Object.defineProperty(exports, "validateNPI", { enumerable: true, get: function () { return shared_1.validateNPI; } });
|
|
6
|
+
//# sourceMappingURL=validate-npi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-npi.js","sourceRoot":"","sources":["../../src/common/validate-npi.ts"],"names":[],"mappings":";;;AAAA,4CAAgD;AAAvC,qGAAA,WAAW,OAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const emptyStringToUndefinedSchema: z.ZodEffects<z.ZodOptional<z.ZodNullable<z.ZodString>>, string | null | undefined, unknown>;
|
|
3
|
+
/**
|
|
4
|
+
* Note: this can't be used in PATCH endpoints because it will prevent us from identifying whether
|
|
5
|
+
* the field is to be left untouched (undefined) or to be removed (null).
|
|
6
|
+
*/
|
|
7
|
+
export declare function emptyStringToUndefined(arg: unknown): unknown;
|
|
8
|
+
export declare function literalStringToUndefined(arg: unknown): unknown;
|
|
9
|
+
export declare function trimString(arg: unknown): unknown;
|
|
10
|
+
export declare function trimAndEmptyToUndefined(arg: unknown): unknown;
|
|
11
|
+
export declare const trimStringSchema: z.ZodEffects<z.ZodString, string, unknown>;
|
|
12
|
+
export declare const trimAndEmptyToUndefinedSchema: z.ZodEffects<z.ZodOptional<z.ZodNullable<z.ZodString>>, string | null | undefined, unknown>;
|
|
13
|
+
//# sourceMappingURL=zod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../src/common/zod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,4BAA4B,6FAGxC,CAAC;AAEF;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAG5D;AAED,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAG9D;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAGhD;AAED,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAK7D;AAED,eAAO,MAAM,gBAAgB,4CAAuC,CAAC;AACrE,eAAO,MAAM,6BAA6B,6FAGzC,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.trimAndEmptyToUndefinedSchema = exports.trimStringSchema = exports.trimAndEmptyToUndefined = exports.trimString = exports.literalStringToUndefined = exports.emptyStringToUndefined = exports.emptyStringToUndefinedSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
// Custom Zod oriented functions and schemas to be used in addition to the ones from @metriport/shared
|
|
6
|
+
exports.emptyStringToUndefinedSchema = zod_1.z.preprocess(emptyStringToUndefined, zod_1.z.string().nullish());
|
|
7
|
+
/**
|
|
8
|
+
* Note: this can't be used in PATCH endpoints because it will prevent us from identifying whether
|
|
9
|
+
* the field is to be left untouched (undefined) or to be removed (null).
|
|
10
|
+
*/
|
|
11
|
+
function emptyStringToUndefined(arg) {
|
|
12
|
+
if (typeof arg === "string" && ["", "undefined", "null"].includes(arg.trim()))
|
|
13
|
+
return undefined;
|
|
14
|
+
return arg ?? undefined;
|
|
15
|
+
}
|
|
16
|
+
exports.emptyStringToUndefined = emptyStringToUndefined;
|
|
17
|
+
function literalStringToUndefined(arg) {
|
|
18
|
+
if (typeof arg === "string" && arg.trim().toLocaleLowerCase() === "string")
|
|
19
|
+
return undefined;
|
|
20
|
+
return arg ?? undefined;
|
|
21
|
+
}
|
|
22
|
+
exports.literalStringToUndefined = literalStringToUndefined;
|
|
23
|
+
function trimString(arg) {
|
|
24
|
+
if (typeof arg === "string")
|
|
25
|
+
return arg.trim();
|
|
26
|
+
return arg;
|
|
27
|
+
}
|
|
28
|
+
exports.trimString = trimString;
|
|
29
|
+
function trimAndEmptyToUndefined(arg) {
|
|
30
|
+
if (typeof arg === "string") {
|
|
31
|
+
return emptyStringToUndefined(arg.trim());
|
|
32
|
+
}
|
|
33
|
+
return arg ?? undefined;
|
|
34
|
+
}
|
|
35
|
+
exports.trimAndEmptyToUndefined = trimAndEmptyToUndefined;
|
|
36
|
+
exports.trimStringSchema = zod_1.z.preprocess(trimString, zod_1.z.string());
|
|
37
|
+
exports.trimAndEmptyToUndefinedSchema = zod_1.z.preprocess(trimAndEmptyToUndefined, zod_1.z.string().nullish());
|
|
38
|
+
//# sourceMappingURL=zod.js.map
|