@metriport/shared 0.7.0 → 0.7.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.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Does not take into account subdomains (i.e. john@support.metriport.com)
3
+ */
4
+ export declare function getDomainFromEmailWithoutTld(email?: string): string | undefined;
5
+ //# sourceMappingURL=email.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../../src/common/email.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAK/E"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDomainFromEmailWithoutTld = void 0;
4
+ /**
5
+ * Does not take into account subdomains (i.e. john@support.metriport.com)
6
+ */
7
+ function getDomainFromEmailWithoutTld(email) {
8
+ if (!email) {
9
+ return;
10
+ }
11
+ return email.split("@")[1]?.split(".")[0];
12
+ }
13
+ exports.getDomainFromEmailWithoutTld = getDomainFromEmailWithoutTld;
14
+ //# sourceMappingURL=email.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email.js","sourceRoot":"","sources":["../../src/common/email.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,SAAgB,4BAA4B,CAAC,KAAc;IACzD,IAAI,CAAC,KAAK,EAAE;QACV,OAAO;KACR;IACD,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5C,CAAC;AALD,oEAKC"}
@@ -0,0 +1,3 @@
1
+ import { Organization } from "@medplum/fhirtypes";
2
+ export declare const metriportOrganization: Organization;
3
+ //# sourceMappingURL=metriport-organization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metriport-organization.d.ts","sourceRoot":"","sources":["../../src/common/metriport-organization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,eAAO,MAAM,qBAAqB,EAAE,YAmBnC,CAAC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.metriportOrganization = void 0;
4
+ exports.metriportOrganization = {
5
+ resourceType: "Organization",
6
+ name: "Metriport",
7
+ address: [
8
+ {
9
+ line: ["2261 Market St, #4818"],
10
+ city: "San Francisco",
11
+ state: "CA",
12
+ postalCode: "94114",
13
+ country: "US",
14
+ },
15
+ ],
16
+ telecom: [
17
+ {
18
+ system: "phone",
19
+ value: "+1-615-344-9551",
20
+ use: "work",
21
+ },
22
+ ],
23
+ };
24
+ //# sourceMappingURL=metriport-organization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metriport-organization.js","sourceRoot":"","sources":["../../src/common/metriport-organization.ts"],"names":[],"mappings":";;;AAEa,QAAA,qBAAqB,GAAiB;IACjD,YAAY,EAAE,cAAc;IAC5B,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE;QACP;YACE,IAAI,EAAE,CAAC,uBAAuB,CAAC;YAC/B,IAAI,EAAE,eAAe;YACrB,KAAK,EAAE,IAAI;YACX,UAAU,EAAE,OAAO;YACnB,OAAO,EAAE,IAAI;SACd;KACF;IACD,OAAO,EAAE;QACP;YACE,MAAM,EAAE,OAAO;YACf,KAAK,EAAE,iBAAiB;YACxB,GAAG,EAAE,MAAM;SACZ;KACF;CACF,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  export { optionalDateSchema } from "./common/date";
2
+ export { getDomainFromEmailWithoutTld } from "./common/email";
3
+ export { errorToString } from "./common/error";
2
4
  export { emptyFunction } from "./common/general";
3
5
  export { normalizeOid } from "./common/normalize-oid";
4
6
  export { PurposeOfUse } from "./common/purpose-of-use";
5
7
  export { executeWithRetries, executeWithRetriesOrFail } from "./common/retry";
6
8
  export { sleep } from "./common/sleep";
9
+ export { limitStringLength } from "./common/string";
7
10
  export { AtLeastOne, stringToBoolean } from "./common/types";
8
11
  export { validateNPI } from "./common/validate-npi";
9
- export { limitStringLength } from "./common/string";
10
- export { errorToString } from "./common/error";
11
12
  export { metriportCompanyDetails } from "./domain/metriport";
12
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.metriportCompanyDetails = exports.errorToString = exports.limitStringLength = exports.validateNPI = exports.stringToBoolean = exports.sleep = exports.executeWithRetriesOrFail = exports.executeWithRetries = exports.PurposeOfUse = exports.normalizeOid = exports.emptyFunction = exports.optionalDateSchema = void 0;
3
+ exports.metriportCompanyDetails = exports.validateNPI = exports.stringToBoolean = exports.limitStringLength = exports.sleep = exports.executeWithRetriesOrFail = exports.executeWithRetries = exports.PurposeOfUse = exports.normalizeOid = exports.emptyFunction = exports.errorToString = exports.getDomainFromEmailWithoutTld = exports.optionalDateSchema = void 0;
4
4
  var date_1 = require("./common/date");
5
5
  Object.defineProperty(exports, "optionalDateSchema", { enumerable: true, get: function () { return date_1.optionalDateSchema; } });
6
+ var email_1 = require("./common/email");
7
+ Object.defineProperty(exports, "getDomainFromEmailWithoutTld", { enumerable: true, get: function () { return email_1.getDomainFromEmailWithoutTld; } });
8
+ var error_1 = require("./common/error");
9
+ Object.defineProperty(exports, "errorToString", { enumerable: true, get: function () { return error_1.errorToString; } });
6
10
  var general_1 = require("./common/general");
7
11
  Object.defineProperty(exports, "emptyFunction", { enumerable: true, get: function () { return general_1.emptyFunction; } });
8
12
  var normalize_oid_1 = require("./common/normalize-oid");
@@ -14,14 +18,12 @@ Object.defineProperty(exports, "executeWithRetries", { enumerable: true, get: fu
14
18
  Object.defineProperty(exports, "executeWithRetriesOrFail", { enumerable: true, get: function () { return retry_1.executeWithRetriesOrFail; } });
15
19
  var sleep_1 = require("./common/sleep");
16
20
  Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return sleep_1.sleep; } });
21
+ var string_1 = require("./common/string");
22
+ Object.defineProperty(exports, "limitStringLength", { enumerable: true, get: function () { return string_1.limitStringLength; } });
17
23
  var types_1 = require("./common/types");
18
24
  Object.defineProperty(exports, "stringToBoolean", { enumerable: true, get: function () { return types_1.stringToBoolean; } });
19
25
  var validate_npi_1 = require("./common/validate-npi");
20
26
  Object.defineProperty(exports, "validateNPI", { enumerable: true, get: function () { return validate_npi_1.validateNPI; } });
21
- var string_1 = require("./common/string");
22
- Object.defineProperty(exports, "limitStringLength", { enumerable: true, get: function () { return string_1.limitStringLength; } });
23
- var error_1 = require("./common/error");
24
- Object.defineProperty(exports, "errorToString", { enumerable: true, get: function () { return error_1.errorToString; } });
25
27
  var metriport_1 = require("./domain/metriport");
26
28
  Object.defineProperty(exports, "metriportCompanyDetails", { enumerable: true, get: function () { return metriport_1.metriportCompanyDetails; } });
27
29
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,sCAAmD;AAA1C,0GAAA,kBAAkB,OAAA;AAC3B,4CAAiD;AAAxC,wGAAA,aAAa,OAAA;AACtB,wDAAsD;AAA7C,6GAAA,YAAY,OAAA;AACrB,0DAAuD;AAA9C,8GAAA,YAAY,OAAA;AACrB,wCAA8E;AAArE,2GAAA,kBAAkB,OAAA;AAAE,iHAAA,wBAAwB,OAAA;AACrD,wCAAuC;AAA9B,8FAAA,KAAK,OAAA;AACd,wCAA6D;AAAxC,wGAAA,eAAe,OAAA;AACpC,sDAAoD;AAA3C,2GAAA,WAAW,OAAA;AACpB,0CAAoD;AAA3C,2GAAA,iBAAiB,OAAA;AAC1B,wCAA+C;AAAtC,sGAAA,aAAa,OAAA;AACtB,gDAA6D;AAApD,oHAAA,uBAAuB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,sCAAmD;AAA1C,0GAAA,kBAAkB,OAAA;AAC3B,wCAA8D;AAArD,qHAAA,4BAA4B,OAAA;AACrC,wCAA+C;AAAtC,sGAAA,aAAa,OAAA;AACtB,4CAAiD;AAAxC,wGAAA,aAAa,OAAA;AACtB,wDAAsD;AAA7C,6GAAA,YAAY,OAAA;AACrB,0DAAuD;AAA9C,8GAAA,YAAY,OAAA;AACrB,wCAA8E;AAArE,2GAAA,kBAAkB,OAAA;AAAE,iHAAA,wBAAwB,OAAA;AACrD,wCAAuC;AAA9B,8FAAA,KAAK,OAAA;AACd,0CAAoD;AAA3C,2GAAA,iBAAiB,OAAA;AAC1B,wCAA6D;AAAxC,wGAAA,eAAe,OAAA;AACpC,sDAAoD;AAA3C,2GAAA,WAAW,OAAA;AACpB,gDAA6D;AAApD,oHAAA,uBAAuB,OAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=env-setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-setup.d.ts","sourceRoot":"","sources":["../../../src/__tests__/env-setup.ts"],"names":[],"mappings":""}
@@ -0,0 +1,35 @@
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
+ const dotenv = __importStar(require("dotenv"));
30
+ const path_1 = __importDefault(require("path"));
31
+ const cwd = process.cwd();
32
+ const paths = [cwd, ...(cwd.includes("packages") ? [] : ["packages", "shared"])];
33
+ dotenv.config({ path: path_1.default.resolve(...paths, ".env.test") });
34
+ // Keep dotenv import and config before everything else
35
+ //# sourceMappingURL=env-setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-setup.js","sourceRoot":"","sources":["../../../src/__tests__/env-setup.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AACjC,gDAAwB;AACxB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;AAC1B,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;AACjF,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,cAAI,CAAC,OAAO,CAAC,GAAG,KAAK,EAAE,WAAW,CAAC,EAAE,CAAC,CAAC;AAC7D,uDAAuD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=normalize-oid.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-oid.test.d.ts","sourceRoot":"","sources":["../../../../src/common/__tests__/normalize-oid.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const normalize_oid_1 = require("../normalize-oid");
4
+ const shorterValidOid = "1";
5
+ const validOid = "1.22.333.444";
6
+ const longerValidOid = "1.22.33.444.555.6677.889999.0001";
7
+ const validOidWithPrefix = "urn:oid:1.22.333.444";
8
+ const invalidOid = "notAnOid";
9
+ const consecutiveDotsInvalidOid = "1.22.333..444";
10
+ describe("normalizeOid", () => {
11
+ it("should return the same oid if it is already valid", () => {
12
+ expect((0, normalize_oid_1.normalizeOid)(validOid)).toBe(validOid);
13
+ expect((0, normalize_oid_1.normalizeOid)(shorterValidOid)).toBe(shorterValidOid);
14
+ expect((0, normalize_oid_1.normalizeOid)(longerValidOid)).toBe(longerValidOid);
15
+ });
16
+ it("should return the oid without the urn:oid: prefix", () => {
17
+ expect((0, normalize_oid_1.normalizeOid)(validOidWithPrefix)).toBe(validOid);
18
+ });
19
+ it("should throw an error if oid does not conform to the format", () => {
20
+ expect(() => (0, normalize_oid_1.normalizeOid)(invalidOid)).toThrow("OID is not valid");
21
+ expect(() => (0, normalize_oid_1.normalizeOid)(consecutiveDotsInvalidOid)).toThrow("OID is not valid");
22
+ });
23
+ });
24
+ //# sourceMappingURL=normalize-oid.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-oid.test.js","sourceRoot":"","sources":["../../../../src/common/__tests__/normalize-oid.test.ts"],"names":[],"mappings":";;AAAA,oDAAgD;AAEhD,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,MAAM,QAAQ,GAAG,cAAc,CAAC;AAChC,MAAM,cAAc,GAAG,kCAAkC,CAAC;AAC1D,MAAM,kBAAkB,GAAG,sBAAsB,CAAC;AAClD,MAAM,UAAU,GAAG,UAAU,CAAC;AAC9B,MAAM,yBAAyB,GAAG,eAAe,CAAC;AAElD,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;QAC3D,MAAM,CAAC,IAAA,4BAAY,EAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC9C,MAAM,CAAC,IAAA,4BAAY,EAAC,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAC5D,MAAM,CAAC,IAAA,4BAAY,EAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;QAC3D,MAAM,CAAC,IAAA,4BAAY,EAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6DAA6D,EAAE,GAAG,EAAE;QACrE,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,4BAAY,EAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;QACnE,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,4BAAY,EAAC,yBAAyB,CAAC,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACpF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function normalizeOid(oid: string): string;
2
+ //# sourceMappingURL=normalize-oid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-oid.d.ts","sourceRoot":"","sources":["../../../src/common/normalize-oid.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAOhD"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeOid = void 0;
4
+ const OID_REGEX = /^(urn:oid:)?([0-9]+(\.[0-9]+)*)$/;
5
+ function normalizeOid(oid) {
6
+ const match = OID_REGEX.exec(oid);
7
+ if (match && match[2]) {
8
+ return match[2];
9
+ }
10
+ throw new Error("OID is not valid");
11
+ }
12
+ exports.normalizeOid = normalizeOid;
13
+ //# sourceMappingURL=normalize-oid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-oid.js","sourceRoot":"","sources":["../../../src/common/normalize-oid.ts"],"names":[],"mappings":";;;AAAA,MAAM,SAAS,GAAG,kCAAkC,CAAC;AAErD,SAAgB,YAAY,CAAC,GAAW;IACtC,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE;QACrB,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;KACjB;IAED,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;AACtC,CAAC;AAPD,oCAOC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Checks if the specified 10 digit NPI is valid as per ISO standard mod 10 Luhn algorithm.
3
+ *
4
+ * See: https://www.cms.gov/Regulations-and-Guidance/Administrative-Simplification/NationalProvIdentStand/Downloads/NPIcheckdigit.pdf
5
+ *
6
+ * @param npi The npi number to validate, must be 10 digits.
7
+ * @returns true if valid; false otherwise.
8
+ */
9
+ export declare function validateNPI(npi: string): boolean;
10
+ //# sourceMappingURL=validate-npi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-npi.d.ts","sourceRoot":"","sources":["../../../src/common/validate-npi.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAiChD"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateNPI = void 0;
4
+ /**
5
+ * Checks if the specified 10 digit NPI is valid as per ISO standard mod 10 Luhn algorithm.
6
+ *
7
+ * See: https://www.cms.gov/Regulations-and-Guidance/Administrative-Simplification/NationalProvIdentStand/Downloads/NPIcheckdigit.pdf
8
+ *
9
+ * @param npi The npi number to validate, must be 10 digits.
10
+ * @returns true if valid; false otherwise.
11
+ */
12
+ function validateNPI(npi) {
13
+ if (!npi || npi.length !== 10) {
14
+ return false;
15
+ }
16
+ const firstNPIDigit = parseInt(npi.charAt(0), 10);
17
+ if (firstNPIDigit !== 1 && firstNPIDigit !== 2) {
18
+ return false;
19
+ }
20
+ let sum = 0;
21
+ let shouldDouble = true;
22
+ for (let i = 0; i < npi.length - 1; i++) {
23
+ let digit = parseInt(npi.charAt(i), 10);
24
+ if (shouldDouble) {
25
+ digit *= 2;
26
+ if (digit > 9) {
27
+ digit -= 9;
28
+ }
29
+ }
30
+ sum += digit;
31
+ shouldDouble = !shouldDouble;
32
+ }
33
+ // account for NPI prefix
34
+ sum += 24;
35
+ const diffFromNextTens = 10 - (sum % 10);
36
+ const checkDigit = diffFromNextTens % 10;
37
+ const lastNPIDigit = parseInt(npi.charAt(npi.length - 1), 10);
38
+ return checkDigit === lastNPIDigit;
39
+ }
40
+ exports.validateNPI = validateNPI;
41
+ //# 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;;;;;;;GAOG;AACH,SAAgB,WAAW,CAAC,GAAW;IACrC,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE,EAAE;QAC7B,OAAO,KAAK,CAAC;KACd;IACD,MAAM,aAAa,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAClD,IAAI,aAAa,KAAK,CAAC,IAAI,aAAa,KAAK,CAAC,EAAE;QAC9C,OAAO,KAAK,CAAC;KACd;IAED,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,YAAY,GAAG,IAAI,CAAC;IACxB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;QACvC,IAAI,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAExC,IAAI,YAAY,EAAE;YAChB,KAAK,IAAI,CAAC,CAAC;YACX,IAAI,KAAK,GAAG,CAAC,EAAE;gBACb,KAAK,IAAI,CAAC,CAAC;aACZ;SACF;QAED,GAAG,IAAI,KAAK,CAAC;QACb,YAAY,GAAG,CAAC,YAAY,CAAC;KAC9B;IAED,yBAAyB;IACzB,GAAG,IAAI,EAAE,CAAC;IAEV,MAAM,gBAAgB,GAAG,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC;IACzC,MAAM,UAAU,GAAG,gBAAgB,GAAG,EAAE,CAAC;IAEzC,MAAM,YAAY,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC9D,OAAO,UAAU,KAAK,YAAY,CAAC;AACrC,CAAC;AAjCD,kCAiCC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metriport/shared",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Common code shared across packages - by Metriport Inc.",
5
5
  "author": "Metriport Inc. <contact@metriport.com>",
6
6
  "homepage": "https://metriport.com/",
@@ -54,5 +54,5 @@
54
54
  "devDependencies": {
55
55
  "@faker-js/faker": "^8.0.2"
56
56
  },
57
- "gitHead": "16733fdbd44c3023a346011ffe35fab153fd18af"
57
+ "gitHead": "ddccef05522a635d18f453fe7ed13dd850f9e718"
58
58
  }