ndhm-hrp 2.2.38 → 3.0.0

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.
@@ -1,24 +1,57 @@
1
1
  import Header from "./header";
2
+ declare type HI_TYPES = "OPConsultation" | "DiagnosticReport" | "Prescription" | "ImmunizationRecord" | "DischargeSummary" | "HealthDocumentRecord" | "WellnessRecord" | "InitialAssessment" | "DietaryRecord";
2
3
  export default class Discovery extends Header {
3
4
  constructor(_baseUrl: string, _accessToken: string);
4
5
  /**
5
- * Result of patient care-context discovery request at HIP end. If a matching patient found with zero or more care contexts associated, it is specified as result attribute. If the prior discovery request, resulted in errors then it is specified in the error attribute. Reasons of errors can be
6
- * @param config body
7
- * @returns
6
+ * HMIS/LMIS response to the HIE-CM discovery callback (User Initiated Linking v3).
7
+ *
8
+ * Called by the HIP after receiving the discovery callback at
9
+ * `{callback_url}/api/v3/hip/patient/care-context/discover` (section 5.3.2).
10
+ * The HIP searches its records and returns matching patients with their
11
+ * associated care contexts, HI type, and count. If no match is found, an
12
+ * error is returned instead.
13
+ *
14
+ * Uses the v3 endpoint per ABDM M2 Sandbox Documentation v2.8 (section 5.3.3):
15
+ * `POST /api/hiecm/user-initiated-linking/v3/patient/care-context/on-discover`
16
+ *
17
+ * @param config - Configuration object
18
+ * @param config.healthId - Patient's ABHA address (e.g. "user@sbx") used to derive X-CM-ID
19
+ * @param config.transactionId - Transaction ID from the HIE-CM discovery callback, used for correlation
20
+ * @param config.patients - Array of matched patient entries, each with:
21
+ * - referenceNumber - Patient reference in HIP system
22
+ * - display - Display name for the patient
23
+ * - careContexts - Array of { referenceNumber, display }
24
+ * - hiType - Type of health information (HI_TYPES)
25
+ * - count - Number of care contexts
26
+ * @param config.matchedBy - Array of matching criteria used (e.g. ["MR", "NAME", "DOB"])
27
+ * @param config.callbackRequestId - The `requestId` from the HIE-CM discovery callback, sent in `response.requestId`
28
+ * @param config.error - Optional error object if no matching patient was found (code, message)
29
+ * @param config.requestId - Optional UUID for REQUEST-ID header (auto-generated if omitted)
30
+ * @param config.timestamp - Optional ISO timestamp for TIMESTAMP header (auto-generated if omitted)
31
+ * @returns The request body that was sent (for logging/reference)
8
32
  */
9
33
  onDiscovery: (config: {
34
+ healthId: string;
10
35
  transactionId: string;
11
- patientReferenceNumber: string;
12
- patientDisplay: string;
13
- careContexts: {
36
+ patients?: Array<{
14
37
  referenceNumber: string;
15
38
  display: string;
16
- }[];
17
- matchedBy: string[];
18
- errCode?: string;
19
- errMessage?: string;
20
- requestId: string;
21
- healthId: string;
39
+ careContexts: Array<{
40
+ referenceNumber: string;
41
+ display: string;
42
+ }>;
43
+ hiType: HI_TYPES;
44
+ count: number;
45
+ }>;
46
+ matchedBy?: string[];
47
+ callbackRequestId: string;
48
+ error?: {
49
+ code: string;
50
+ message: string;
51
+ };
52
+ requestId?: string;
53
+ timestamp?: string;
22
54
  }) => Promise<any>;
23
55
  }
56
+ export {};
24
57
  //# sourceMappingURL=discovery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../src/classes/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,UAAU,CAAC;AAI9B,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,MAAM;gBAC/B,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;IAGlD;;;;OAIG;IACH,WAAW,WAAkB;QAC3B,aAAa,EAAE,MAAM,CAAC;QACtB,sBAAsB,EAAE,MAAM,CAAC;QAC/B,cAAc,EAAE,MAAM,CAAC;QACvB,YAAY,EAAE;YAAE,eAAe,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;QAC7D,SAAS,EAAE,MAAM,EAAE,CAAC;QACpB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;KAClB,kBAiCC;CACH"}
1
+ {"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../src/classes/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,UAAU,CAAC;AAI9B,aAAK,QAAQ,GACT,gBAAgB,GAChB,kBAAkB,GAClB,cAAc,GACd,oBAAoB,GACpB,kBAAkB,GAClB,sBAAsB,GACtB,gBAAgB,GAChB,mBAAmB,GACnB,eAAe,CAAC;AAEpB,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,MAAM;gBAC/B,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;IAIlD;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,WAAW,WAAkB;QAC3B,QAAQ,EAAE,MAAM,CAAC;QACjB,aAAa,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,EAAE,MAAM;YACf,eAAe,EAAE,MAAM,CAAC;YACxB,OAAO,EAAE,MAAM,CAAC;YAChB,YAAY,EAAE,MAAM;gBAClB,eAAe,EAAE,MAAM,CAAC;gBACxB,OAAO,EAAE,MAAM,CAAC;aACjB,CAAC,CAAC;YACH,MAAM,EAAE,QAAQ,CAAC;YACjB,KAAK,EAAE,MAAM,CAAC;SACf,CAAC,CAAC;QACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QACrB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,KAAK,CAAC,EAAE;YACN,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,EAAE,MAAM,CAAC;SACjB,CAAC;QACF,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,kBAiCC;CACH"}
@@ -19,38 +19,62 @@ class Discovery extends header_1.default {
19
19
  constructor(_baseUrl, _accessToken) {
20
20
  super(_baseUrl, _accessToken);
21
21
  /**
22
- * Result of patient care-context discovery request at HIP end. If a matching patient found with zero or more care contexts associated, it is specified as result attribute. If the prior discovery request, resulted in errors then it is specified in the error attribute. Reasons of errors can be
23
- * @param config body
24
- * @returns
22
+ * HMIS/LMIS response to the HIE-CM discovery callback (User Initiated Linking v3).
23
+ *
24
+ * Called by the HIP after receiving the discovery callback at
25
+ * `{callback_url}/api/v3/hip/patient/care-context/discover` (section 5.3.2).
26
+ * The HIP searches its records and returns matching patients with their
27
+ * associated care contexts, HI type, and count. If no match is found, an
28
+ * error is returned instead.
29
+ *
30
+ * Uses the v3 endpoint per ABDM M2 Sandbox Documentation v2.8 (section 5.3.3):
31
+ * `POST /api/hiecm/user-initiated-linking/v3/patient/care-context/on-discover`
32
+ *
33
+ * @param config - Configuration object
34
+ * @param config.healthId - Patient's ABHA address (e.g. "user@sbx") used to derive X-CM-ID
35
+ * @param config.transactionId - Transaction ID from the HIE-CM discovery callback, used for correlation
36
+ * @param config.patients - Array of matched patient entries, each with:
37
+ * - referenceNumber - Patient reference in HIP system
38
+ * - display - Display name for the patient
39
+ * - careContexts - Array of { referenceNumber, display }
40
+ * - hiType - Type of health information (HI_TYPES)
41
+ * - count - Number of care contexts
42
+ * @param config.matchedBy - Array of matching criteria used (e.g. ["MR", "NAME", "DOB"])
43
+ * @param config.callbackRequestId - The `requestId` from the HIE-CM discovery callback, sent in `response.requestId`
44
+ * @param config.error - Optional error object if no matching patient was found (code, message)
45
+ * @param config.requestId - Optional UUID for REQUEST-ID header (auto-generated if omitted)
46
+ * @param config.timestamp - Optional ISO timestamp for TIMESTAMP header (auto-generated if omitted)
47
+ * @returns The request body that was sent (for logging/reference)
25
48
  */
26
49
  this.onDiscovery = (config) => __awaiter(this, void 0, void 0, function* () {
27
- const headers = this.headers(config.healthId);
28
- const url = `${this.baseUrl}v0.5/care-contexts/on-discover`;
50
+ var _a, _b;
51
+ this.setXCmId(config.healthId);
52
+ const headers = {
53
+ "REQUEST-ID": (_a = config.requestId) !== null && _a !== void 0 ? _a : (0, uuid_1.v4)(),
54
+ TIMESTAMP: (_b = config.timestamp) !== null && _b !== void 0 ? _b : new Date().toISOString(),
55
+ "X-CM-ID": this.xCmId,
56
+ "Content-Type": "application/json",
57
+ Authorization: `Bearer ${this.accessToken}`,
58
+ };
59
+ const url = `${this.baseUrl}api/hiecm/user-initiated-linking/v3/patient/care-context/on-discover`;
29
60
  const body = {
30
- requestId: (0, uuid_1.v4)(),
31
- timestamp: new Date().toISOString(),
32
61
  transactionId: config.transactionId,
33
- patient: {
34
- referenceNumber: config.patientReferenceNumber,
35
- display: config.patientDisplay,
36
- careContexts: config.careContexts,
37
- matchedBy: config.matchedBy,
38
- },
39
- resp: {
40
- requestId: config.requestId,
62
+ response: {
63
+ requestId: config.callbackRequestId,
41
64
  },
42
65
  };
43
- if (config.errCode) {
44
- body.error = {
45
- code: config.errCode,
46
- message: config.errMessage || "Error occured",
47
- };
66
+ if (config.error) {
67
+ body.error = config.error;
68
+ }
69
+ else {
70
+ body.patient = config.patients;
71
+ body.matchedBy = config.matchedBy;
48
72
  }
49
73
  yield new request_1.default().request({
50
- headers: headers,
74
+ headers,
51
75
  method: "POST",
52
76
  requestBody: body,
53
- url: url,
77
+ url,
54
78
  });
55
79
  return body;
56
80
  });
@@ -1 +1 @@
1
- {"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../src/classes/discovery.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,sDAA8B;AAC9B,+BAAoC;AACpC,wDAAgC;AAEhC,MAAqB,SAAU,SAAQ,gBAAM;IAC3C,YAAY,QAAgB,EAAE,YAAoB;QAChD,KAAK,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QAEhC;;;;WAIG;QACH,gBAAW,GAAG,CAAO,MAUpB,EAAE,EAAE;YACH,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC9C,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,gCAAgC,CAAC;YACxD,MAAM,IAAI,GAAQ;gBACpB,SAAS,EAAE,IAAA,SAAM,GAAE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SAAS,mCAAI,IAAA,SAAM,GAAE;gBAC1C,SAAS,EAAE,MAAA,MAAM,CAAC,SAAS,mCAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;gBACvD,SAAS,EAAE,IAAI,CAAC,KAAK;gBACrB,cAAc,EAAE,kBAAkB;gBAClC,aAAa,EAAE,UAAU,IAAI,CAAC,WAAW,EAAE;aAC5C,CAAC;YACF,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,sEAAsE,CAAC;YAElG,MAAM,IAAI,GAAQ;gBAChB,aAAa,EAAE,MAAM,CAAC,aAAa;gBACnC,QAAQ,EAAE;oBACR,SAAS,EAAE,MAAM,CAAC,iBAAiB;iBACpC;aACF,CAAC;YAEF,IAAI,MAAM,CAAC,KAAK,EAAE;gBAChB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;aAC3B;iBAAM;gBACL,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC;gBAC/B,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;aACnC;YAED,MAAM,IAAI,iBAAO,EAAE,CAAC,OAAO,CAAC;gBAC1B,OAAO;gBACP,MAAM,EAAE,MAAM;gBACd,WAAW,EAAE,IAAI;gBACjB,GAAG;aACJ,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC;QACd,CAAC,CAAA,CAAC;IApFF,CAAC;CAqFF;AAxFD,4BAwFC"}
@@ -3,105 +3,195 @@ declare type HI_TYPES = "OPConsultation" | "DiagnosticReport" | "Prescription" |
3
3
  export default class Link extends Header {
4
4
  constructor(_baseUrl: string, _accessToken: string);
5
5
  /**
6
+ * Adds care contexts to a patient's ABHA account using the v3 HIE-CM endpoint.
6
7
  *
7
- * @param config healthis with Xcmid
8
- * @returns
8
+ * This replaces the deprecated v0.5 `AddContext` method. It requires a
9
+ * `linkToken` (obtained via `generateToken`) and sends patient care-context
10
+ * data with `hiType` and `count` fields.
11
+ *
12
+ * Headers are built inline following the existing `generateToken` v3 pattern.
13
+ *
14
+ * @param config - Configuration object
15
+ * @param config.healthId - Patient's health ID used to derive X-CM-ID header
16
+ * @param config.hipId - HIP ID sent as X-HIP-ID header
17
+ * @param config.linkToken - Link token obtained from HIE-CM token generation
18
+ * @param config.abhaNumber - Patient's ABHA number
19
+ * @param config.abhaAddress - Patient's ABHA address
20
+ * @param config.patients - Array of patient care-context entries, each with:
21
+ * - referenceNumber - Patient reference (encounter ID) in HIP system
22
+ * - display - Display name for the patient
23
+ * - careContexts - Array of { referenceNumber, display }
24
+ * - hiType - Type of health information (HI_TYPES)
25
+ * - count - Number of care contexts
26
+ * @param config.requestId - Optional UUID for REQUEST-ID header (auto-generated if omitted)
27
+ * @param config.timestamp - Optional ISO timestamp for TIMESTAMP header (auto-generated if omitted)
28
+ * @returns The parsed API response
9
29
  */
10
- AddContext: (config: {
30
+ addCareContext: (config: {
11
31
  healthId: string;
12
- careContextAccessToken: string;
13
- patientId: string;
14
- patinetDisplay: string;
15
- careContextId: string;
16
- careContextDisplay: string;
17
- }) => Promise<{
18
- requestId: string;
19
- timestamp: string;
20
- link: {
21
- accessToken: string;
22
- patient: {
32
+ hipId: string;
33
+ linkToken: string;
34
+ abhaNumber: string;
35
+ abhaAddress: string;
36
+ patients: Array<{
37
+ referenceNumber: string;
38
+ display: string;
39
+ careContexts: Array<{
23
40
  referenceNumber: string;
24
41
  display: string;
25
- careContexts: {
26
- referenceNumber: string;
27
- display: string;
28
- }[];
29
- };
30
- };
31
- }>;
42
+ }>;
43
+ hiType: HI_TYPES;
44
+ count: number;
45
+ }>;
46
+ requestId?: string;
47
+ timestamp?: string;
48
+ }) => Promise<any>;
32
49
  /**
33
- * Result of patient care-context link request from HIP end. This happens in context of previous discovery of patient found at HIP end, therefore the link requests ought to be in reference to the patient reference and care-context references previously returned by the HIP. The correlation of discovery and link request is maintained through the transactionId. HIP should have
34
- * @param config
35
- *
36
- * Validated transactionId in the request to check whether there was a discovery done previously, and the link request corresponds to returned patient care care context references
37
- Before returning the response, HIP should have sent an authentication request to the patient(eg: OTP verification)
38
- HIP should communicate the mode of authentication of a successful request
39
- HIP subsequently should expect the token passed via /link/confirm against the link.referenceNumber passed in this call
40
- The error section in the body, represents the potential errors that may have occurred. Possible reasons:
41
-
42
- Patient reference number is invalid
43
- Care context reference numbers are invalid
50
+ * HMIS/LMIS response to the HIE-CM callback for user-initiated linking (v3).
51
+ *
52
+ * This is called by the HIP in response to the discovery callback (section 5.3.2).
53
+ * The HIP validates the transactionId against a previous discovery, sends an
54
+ * authentication request to the patient (e.g. OTP), and returns the link
55
+ * reference number with authentication metadata. The patient subsequently passes
56
+ * the token via `/link/care-context/confirm` against the `link.referenceNumber`.
57
+ *
58
+ * Uses the v3 HIE-CM endpoint per ABDM M2 Sandbox Documentation v2.8 (section 5.3.7):
59
+ * `POST /api/hiecm/user-initiated-linking/v3/link/care-context/on-init`
60
+ *
61
+ * Possible errors returned:
62
+ * - Patient reference number is invalid
63
+ * - Care context reference numbers are invalid
64
+ *
65
+ * @param config - Configuration object
66
+ * @param config.healthId - Patient's ABHA address (e.g. "user@sbx") used to derive X-CM-ID
67
+ * @param config.transactionId - Transaction ID from the discovery callback, used for correlation
68
+ * @param config.referenceNumber - Link reference number generated by the HIP for this linking attempt
69
+ * @param config.authenticationType - Authentication type: "DIRECT" or "MEDIATE"
70
+ * @param config.communicationMedium - Medium for patient communication (e.g. "MOBILE")
71
+ * @param config.communicationHint - Hint for the communication (e.g. "OTP")
72
+ * @param config.communicationExpiry - ISO timestamp for communication expiry (defaults to 10 min from now)
73
+ * @param config.requestId - Optional UUID for REQUEST-ID header (auto-generated if omitted)
74
+ * @param config.timestamp - Optional ISO timestamp for TIMESTAMP header (auto-generated if omitted)
75
+ * @param config.callbackRequestId - The `requestId` from the HIE-CM discovery callback, sent in `response.requestId`
76
+ * @param config.error - Optional error object if the HIP cannot process the link request
77
+ * @returns The request body that was sent (for logging/reference)
44
78
  */
45
79
  onInit: (config: {
46
80
  healthId: string;
47
81
  transactionId: string;
48
82
  referenceNumber: string;
83
+ authenticationType: "DIRECT" | "MEDIATE";
84
+ communicationMedium: string;
49
85
  communicationHint: string;
50
86
  communicationExpiry?: string;
51
- requestId: string;
87
+ requestId?: string;
88
+ timestamp?: string;
89
+ callbackRequestId: string;
52
90
  error?: {
53
91
  code: number;
54
92
  message: string;
55
93
  };
56
94
  }) => Promise<any>;
57
- /***
58
- * Returns a list of linked care contexts with patient reference number.
59
- Validated and linked account reference number
60
- Validated that the token sent from Consent Manager is same as the one generated by HIP
61
- Verified that same Consent Manager which made the link request is sending the token
62
- Results of unmasked linked care contexts with patient reference number
95
+ /**
96
+ * HMIS/LMIS response on confirm called by HIP after the patient confirms
97
+ * the link via OTP/token (User Initiated Linking v3).
98
+ *
99
+ * This is the HIP's response to the HIE-CM callback at
100
+ * `{callback_url}/api/v3/hip/link/care-context/confirm` (section 5.3.10).
101
+ * The HIP returns the confirmed care contexts that have been linked to the
102
+ * patient's ABHA account.
103
+ *
104
+ * Uses the v3 endpoint per ABDM M2 Sandbox Documentation v2.8 (section 5.3.11):
105
+ * `POST /api/hiecm/user-initiated-linking/v3/link/care-context/on-confirm`
106
+ *
107
+ * @param config - Configuration object
108
+ * @param config.healthId - Patient's ABHA address (e.g. "user@sbx") used to derive X-CM-ID
109
+ * @param config.patients - Array of patient care-context entries that were confirmed, each with:
110
+ * - referenceNumber - Patient reference in HIP system
111
+ * - display - Display name for the patient
112
+ * - careContexts - Array of { referenceNumber, display }
113
+ * - hiType - Type of health information (HI_TYPES)
114
+ * - count - Number of care contexts
115
+ * @param config.callbackRequestId - The `requestId` from the HIE-CM confirm callback, sent in `response.requestId`
116
+ * @param config.requestId - Optional UUID for REQUEST-ID header (auto-generated if omitted)
117
+ * @param config.timestamp - Optional ISO timestamp for TIMESTAMP header (auto-generated if omitted)
118
+ * @returns The request body that was sent (for logging/reference)
63
119
  */
64
120
  onConfirm: (config: {
65
121
  healthId: string;
66
- careContextAccessToken: string;
67
- requestId: string;
68
- patientReferenceNumber: string;
69
- patinetDisplay: string;
70
- careContexts: {
122
+ patients: Array<{
123
+ referenceNumber: string;
124
+ display: string;
125
+ careContexts: Array<{
126
+ referenceNumber: string;
127
+ display: string;
128
+ }>;
129
+ hiType: HI_TYPES;
130
+ count: number;
131
+ }>;
132
+ callbackRequestId: string;
133
+ requestId?: string;
134
+ timestamp?: string;
135
+ }) => Promise<{
136
+ patient: {
71
137
  referenceNumber: string;
72
138
  display: string;
139
+ careContexts: Array<{
140
+ referenceNumber: string;
141
+ display: string;
142
+ }>;
143
+ hiType: HI_TYPES;
144
+ count: number;
73
145
  }[];
74
- error?: {
75
- code: number;
76
- message: string;
146
+ response: {
147
+ requestId: string;
77
148
  };
78
- }) => Promise<any>;
149
+ }>;
79
150
  /**
80
- *This API is called by HIP only when there is new health data is added/created for a patient and under a care context that is already linked with patient's Health Account. HIP can send following things in this API to notify the Consent Manager about the new health data added:
81
- * @param config
82
- * @healthId Patient's Identifier for which the new health data is added (It can be ABDM address or phr address)
83
- * @careContextReference Care Context reference under which the new health data is added
84
- * @patientReference Patient's reference (An identifier with which the patient is registered on HIP)
85
- * @hiTypes Types of health information documents that have been added ("DiagnosticReportRecord" | "DischargeSummaryRecord" | "HealthDocumentRecord" | "ImmunizationRecord" | "OPConsultRecord" | "PrescriptionRecord" | "WellnessRecord")
86
- * @date in iso format at UTC A date when the health information was created/added on the HIP Note: This API shouldn't be called if the new heath data of is added/created under new care context.
151
+ * Notifies the ABDM Consent Manager about new health data added/created for a patient
152
+ * under an already-linked care context (HIP Initiated Linking v3).
153
+ *
154
+ * Called by HIP when new health information is added under a care context that
155
+ * is already linked with the patient's ABHA account. This API should NOT be called
156
+ * if the new health data is added under a new (unlinked) care context.
157
+ *
158
+ * Uses the v3 HIE-CM endpoint `/api/hiecm/hip/v3/link/context/notify` per the
159
+ * ABDM M2 Sandbox Documentation v2.8 (section 4.3.6).
160
+ *
161
+ * Headers are built inline following the v3 pattern used by `generateToken` and
162
+ * `addCareContext`, including `X-HIP-ID`, `X-LINK-TOKEN`, `REQUEST-ID`, and
163
+ * `TIMESTAMP` as required by the v3 API.
164
+ *
165
+ * @param config - Configuration object
166
+ * @param config.healthId - Patient's identifier (ABHA address, e.g. "user@sbx") used to derive X-CM-ID
167
+ * @param config.hipId - HIP facility ID sent as X-HIP-ID header (e.g. "IN2910000004")
168
+ * @param config.linkToken - Link token (JWT) obtained from token generation, sent as X-LINK-TOKEN header
169
+ * @param config.patientReference - Patient's reference number in the HIP system (e.g. ABHA number)
170
+ * @param config.careContextReference - Care context reference under which new health data was added
171
+ * @param config.hiTypes - Array of HI types for the new health data (e.g. ["Prescription", "DischargeSummary"])
172
+ * @param config.date - ISO 8601 UTC date when the health information was created/added on the HIP
173
+ * @param config.requestId - Optional UUID for REQUEST-ID header (auto-generated if omitted)
174
+ * @param config.timestamp - Optional ISO timestamp for TIMESTAMP header (auto-generated if omitted)
175
+ * @returns The request body that was sent (for logging/reference)
87
176
  */
88
177
  notify: (config: {
89
178
  healthId: string;
90
- patientReference: any;
91
- careContextReference: any;
179
+ hipId: string;
180
+ linkToken: string;
181
+ patientReference: string;
182
+ careContextReference: string;
92
183
  hiTypes: HI_TYPES[];
93
184
  date: string;
94
- hipId: string;
185
+ requestId?: string;
186
+ timestamp?: string;
95
187
  }) => Promise<{
96
- requestId: string;
97
- timestamp: string;
98
188
  notification: {
99
189
  patient: {
100
190
  id: string;
101
191
  };
102
192
  careContext: {
103
- patientReference: any;
104
- careContextReference: any;
193
+ patientReference: string;
194
+ careContextReference: string;
105
195
  };
106
196
  hiTypes: HI_TYPES[];
107
197
  date: string;
@@ -110,6 +200,36 @@ export default class Link extends Header {
110
200
  };
111
201
  };
112
202
  }>;
203
+ /**
204
+ * Generates a patient token (ABDM HIE-CM v3 endpoint) required for HIE (Health Information Exchange) operations.
205
+ *
206
+ * This token is needed to authorize subsequent HIE transactions such as data push and data pull requests.
207
+ * The API uses the v3 endpoint `/api/hiecm/v3/token/generate-token` which requires custom headers
208
+ * (REQUEST-ID, TIMESTAMP, X-HIP-ID) not present in the standard v0.5 header set.
209
+ *
210
+ * @param config - Configuration object for token generation
211
+ * @param config.healthId - Patient's health ID used to derive the X-CM-ID header (e.g., "user@abdm")
212
+ * @param config.hipId - Health Information Provider ID sent as X-HIP-ID header
213
+ * @param config.abhaNumber - Patient's ABHA number (can be numeric or string)
214
+ * @param config.abhaAddress - Patient's ABHA address (e.g., "user@sbx")
215
+ * @param config.name - Patient's full name
216
+ * @param config.gender - Patient's gender
217
+ * @param config.yearOfBirth - Patient's year of birth
218
+ * @param config.requestId - Optional UUID for REQUEST-ID header (auto-generated if omitted)
219
+ * @param config.timestamp - Optional ISO timestamp for TIMESTAMP header (auto-generated if omitted)
220
+ * @returns The parsed API response containing the generated patient token
221
+ */
222
+ generateToken: (config: {
223
+ healthId: string;
224
+ hipId: string;
225
+ abhaNumber: number | string;
226
+ abhaAddress: string;
227
+ name: string;
228
+ gender: string;
229
+ yearOfBirth: number;
230
+ requestId?: string;
231
+ timestamp?: string;
232
+ }) => Promise<any>;
113
233
  }
114
234
  export {};
115
235
  //# sourceMappingURL=link.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../src/classes/link.ts"],"names":[],"mappings":"AAEA,OAAO,MAAM,MAAM,UAAU,CAAC;AAE9B,aAAK,QAAQ,GACT,gBAAgB,GAChB,kBAAkB,GAClB,cAAc,GACd,oBAAoB,GACpB,kBAAkB,GAClB,sBAAsB,GACtB,gBAAgB,GAChB,mBAAmB,GACnB,eAAe,CAAA;AAGnB,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,MAAM;gBAC1B,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;IAIlD;;;;OAIG;IACH,UAAU,WAAkB;QAC1B,QAAQ,EAAE,MAAM,CAAC;QACjB,sBAAsB,EAAE,MAAM,CAAC;QAC/B,SAAS,EAAE,MAAM,CAAC;QAClB,cAAc,EA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,EAAE,MAAM,GAAG,MAAM,CAAC;QAC5B,WAAW,EAAE,MAAM,CAAC;QACpB,MAAM,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,WAAW,EAAE,MAAM,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,kBA2BC;CACH"}
@@ -19,131 +19,214 @@ class Link extends header_1.default {
19
19
  constructor(_baseUrl, _accessToken) {
20
20
  super(_baseUrl, _accessToken);
21
21
  /**
22
+ * Adds care contexts to a patient's ABHA account using the v3 HIE-CM endpoint.
22
23
  *
23
- * @param config healthis with Xcmid
24
- * @returns
24
+ * This replaces the deprecated v0.5 `AddContext` method. It requires a
25
+ * `linkToken` (obtained via `generateToken`) and sends patient care-context
26
+ * data with `hiType` and `count` fields.
27
+ *
28
+ * Headers are built inline following the existing `generateToken` v3 pattern.
29
+ *
30
+ * @param config - Configuration object
31
+ * @param config.healthId - Patient's health ID used to derive X-CM-ID header
32
+ * @param config.hipId - HIP ID sent as X-HIP-ID header
33
+ * @param config.linkToken - Link token obtained from HIE-CM token generation
34
+ * @param config.abhaNumber - Patient's ABHA number
35
+ * @param config.abhaAddress - Patient's ABHA address
36
+ * @param config.patients - Array of patient care-context entries, each with:
37
+ * - referenceNumber - Patient reference (encounter ID) in HIP system
38
+ * - display - Display name for the patient
39
+ * - careContexts - Array of { referenceNumber, display }
40
+ * - hiType - Type of health information (HI_TYPES)
41
+ * - count - Number of care contexts
42
+ * @param config.requestId - Optional UUID for REQUEST-ID header (auto-generated if omitted)
43
+ * @param config.timestamp - Optional ISO timestamp for TIMESTAMP header (auto-generated if omitted)
44
+ * @returns The parsed API response
25
45
  */
26
- this.AddContext = (config) => __awaiter(this, void 0, void 0, function* () {
27
- const headers = this.headers(config.healthId);
28
- const url = `${this.baseUrl}v0.5/links/link/add-contexts`;
46
+ this.addCareContext = (config) => __awaiter(this, void 0, void 0, function* () {
47
+ var _a, _b;
48
+ this.setXCmId(config.healthId);
49
+ const headers = {
50
+ "REQUEST-ID": (_a = config.requestId) !== null && _a !== void 0 ? _a : (0, uuid_1.v4)(),
51
+ TIMESTAMP: (_b = config.timestamp) !== null && _b !== void 0 ? _b : new Date().toISOString(),
52
+ "X-HIP-ID": config.hipId,
53
+ "X-LINK-TOKEN": config.linkToken,
54
+ "X-CM-ID": this.xCmId,
55
+ "Content-Type": "application/json",
56
+ Authorization: `Bearer ${this.accessToken}`,
57
+ };
58
+ const url = `${this.baseUrl}api/hiecm/hip/v3/link/carecontext`;
29
59
  const body = {
30
- requestId: (0, uuid_1.v4)(),
31
- timestamp: new Date().toISOString(),
32
- link: {
33
- accessToken: config.careContextAccessToken,
34
- patient: {
35
- referenceNumber: config.patientId,
36
- display: config.patinetDisplay,
37
- careContexts: [
38
- {
39
- referenceNumber: config.careContextId,
40
- display: config.careContextDisplay,
41
- },
42
- ],
43
- },
44
- },
60
+ abhaNumber: config.abhaNumber,
61
+ abhaAddress: config.abhaAddress,
62
+ patient: config.patients,
45
63
  };
46
- yield new request_1.default().request({
47
- headers: headers,
64
+ const response = yield new request_1.default().request({
65
+ headers,
48
66
  method: "POST",
49
67
  requestBody: body,
50
- url: url,
68
+ url,
51
69
  });
52
- return body;
70
+ return JSON.parse(response.body);
53
71
  });
54
72
  /**
55
- * Result of patient care-context link request from HIP end. This happens in context of previous discovery of patient found at HIP end, therefore the link requests ought to be in reference to the patient reference and care-context references previously returned by the HIP. The correlation of discovery and link request is maintained through the transactionId. HIP should have
56
- * @param config
57
- *
58
- * Validated transactionId in the request to check whether there was a discovery done previously, and the link request corresponds to returned patient care care context references
59
- Before returning the response, HIP should have sent an authentication request to the patient(eg: OTP verification)
60
- HIP should communicate the mode of authentication of a successful request
61
- HIP subsequently should expect the token passed via /link/confirm against the link.referenceNumber passed in this call
62
- The error section in the body, represents the potential errors that may have occurred. Possible reasons:
63
-
64
- Patient reference number is invalid
65
- Care context reference numbers are invalid
73
+ * HMIS/LMIS response to the HIE-CM callback for user-initiated linking (v3).
74
+ *
75
+ * This is called by the HIP in response to the discovery callback (section 5.3.2).
76
+ * The HIP validates the transactionId against a previous discovery, sends an
77
+ * authentication request to the patient (e.g. OTP), and returns the link
78
+ * reference number with authentication metadata. The patient subsequently passes
79
+ * the token via `/link/care-context/confirm` against the `link.referenceNumber`.
80
+ *
81
+ * Uses the v3 HIE-CM endpoint per ABDM M2 Sandbox Documentation v2.8 (section 5.3.7):
82
+ * `POST /api/hiecm/user-initiated-linking/v3/link/care-context/on-init`
83
+ *
84
+ * Possible errors returned:
85
+ * - Patient reference number is invalid
86
+ * - Care context reference numbers are invalid
87
+ *
88
+ * @param config - Configuration object
89
+ * @param config.healthId - Patient's ABHA address (e.g. "user@sbx") used to derive X-CM-ID
90
+ * @param config.transactionId - Transaction ID from the discovery callback, used for correlation
91
+ * @param config.referenceNumber - Link reference number generated by the HIP for this linking attempt
92
+ * @param config.authenticationType - Authentication type: "DIRECT" or "MEDIATE"
93
+ * @param config.communicationMedium - Medium for patient communication (e.g. "MOBILE")
94
+ * @param config.communicationHint - Hint for the communication (e.g. "OTP")
95
+ * @param config.communicationExpiry - ISO timestamp for communication expiry (defaults to 10 min from now)
96
+ * @param config.requestId - Optional UUID for REQUEST-ID header (auto-generated if omitted)
97
+ * @param config.timestamp - Optional ISO timestamp for TIMESTAMP header (auto-generated if omitted)
98
+ * @param config.callbackRequestId - The `requestId` from the HIE-CM discovery callback, sent in `response.requestId`
99
+ * @param config.error - Optional error object if the HIP cannot process the link request
100
+ * @returns The request body that was sent (for logging/reference)
66
101
  */
67
102
  this.onInit = (config) => __awaiter(this, void 0, void 0, function* () {
68
- const headers = this.headers(config.healthId);
69
- const url = `${this.baseUrl}v0.5/links/link/on-init`;
103
+ var _c, _d, _e;
104
+ this.setXCmId(config.healthId);
105
+ const headers = {
106
+ "REQUEST-ID": (_c = config.requestId) !== null && _c !== void 0 ? _c : (0, uuid_1.v4)(),
107
+ TIMESTAMP: (_d = config.timestamp) !== null && _d !== void 0 ? _d : new Date().toISOString(),
108
+ "X-CM-ID": this.xCmId,
109
+ "Content-Type": "application/json",
110
+ Authorization: `Bearer ${this.accessToken}`,
111
+ };
112
+ const url = `${this.baseUrl}api/hiecm/user-initiated-linking/v3/link/care-context/on-init`;
70
113
  const body = {
71
- requestId: (0, uuid_1.v4)(),
72
- timestamp: new Date().toISOString(),
73
114
  transactionId: config.transactionId,
74
115
  link: {
75
116
  referenceNumber: config.referenceNumber,
76
- authenticationType: "DIRECT",
117
+ authenticationType: config.authenticationType,
77
118
  meta: {
78
- communicationMedium: "MOBILE",
119
+ communicationMedium: config.communicationMedium,
79
120
  communicationHint: config.communicationHint,
80
- communicationExpiry: config.communicationExpiry ||
81
- new Date(new Date().getTime() + 10 * 60000).toISOString(),
121
+ communicationExpiry: (_e = config.communicationExpiry) !== null && _e !== void 0 ? _e : new Date(new Date().getTime() + 10 * 60000).toISOString(),
82
122
  },
83
123
  },
84
- resp: {
85
- requestId: config.requestId,
124
+ response: {
125
+ requestId: config.callbackRequestId,
86
126
  },
87
127
  };
88
128
  if (config.error) {
89
129
  body.error = config.error;
90
130
  }
91
131
  yield new request_1.default().request({
92
- headers: headers,
132
+ headers,
93
133
  method: "POST",
94
134
  requestBody: body,
95
- url: url,
135
+ url,
96
136
  });
97
137
  return body;
98
138
  });
99
- /***
100
- * Returns a list of linked care contexts with patient reference number.
101
- Validated and linked account reference number
102
- Validated that the token sent from Consent Manager is same as the one generated by HIP
103
- Verified that same Consent Manager which made the link request is sending the token
104
- Results of unmasked linked care contexts with patient reference number
139
+ /**
140
+ * HMIS/LMIS response on confirm called by HIP after the patient confirms
141
+ * the link via OTP/token (User Initiated Linking v3).
142
+ *
143
+ * This is the HIP's response to the HIE-CM callback at
144
+ * `{callback_url}/api/v3/hip/link/care-context/confirm` (section 5.3.10).
145
+ * The HIP returns the confirmed care contexts that have been linked to the
146
+ * patient's ABHA account.
147
+ *
148
+ * Uses the v3 endpoint per ABDM M2 Sandbox Documentation v2.8 (section 5.3.11):
149
+ * `POST /api/hiecm/user-initiated-linking/v3/link/care-context/on-confirm`
150
+ *
151
+ * @param config - Configuration object
152
+ * @param config.healthId - Patient's ABHA address (e.g. "user@sbx") used to derive X-CM-ID
153
+ * @param config.patients - Array of patient care-context entries that were confirmed, each with:
154
+ * - referenceNumber - Patient reference in HIP system
155
+ * - display - Display name for the patient
156
+ * - careContexts - Array of { referenceNumber, display }
157
+ * - hiType - Type of health information (HI_TYPES)
158
+ * - count - Number of care contexts
159
+ * @param config.callbackRequestId - The `requestId` from the HIE-CM confirm callback, sent in `response.requestId`
160
+ * @param config.requestId - Optional UUID for REQUEST-ID header (auto-generated if omitted)
161
+ * @param config.timestamp - Optional ISO timestamp for TIMESTAMP header (auto-generated if omitted)
162
+ * @returns The request body that was sent (for logging/reference)
105
163
  */
106
164
  this.onConfirm = (config) => __awaiter(this, void 0, void 0, function* () {
107
- const headers = this.headers(config.healthId);
108
- const url = `${this.baseUrl}v0.5/links/link/on-confirm`;
165
+ var _f, _g;
166
+ this.setXCmId(config.healthId);
167
+ const headers = {
168
+ "REQUEST-ID": (_f = config.requestId) !== null && _f !== void 0 ? _f : (0, uuid_1.v4)(),
169
+ TIMESTAMP: (_g = config.timestamp) !== null && _g !== void 0 ? _g : new Date().toISOString(),
170
+ "X-CM-ID": this.xCmId,
171
+ "Content-Type": "application/json",
172
+ Authorization: `Bearer ${this.accessToken}`,
173
+ };
174
+ const url = `${this.baseUrl}api/hiecm/user-initiated-linking/v3/link/care-context/on-confirm`;
109
175
  const body = {
110
- requestId: (0, uuid_1.v4)(),
111
- timestamp: new Date().toISOString(),
112
- patient: {
113
- referenceNumber: config.patientReferenceNumber,
114
- display: config.patinetDisplay,
115
- careContexts: config.careContexts,
116
- },
117
- resp: {
118
- requestId: config.requestId,
176
+ patient: config.patients,
177
+ response: {
178
+ requestId: config.callbackRequestId,
119
179
  },
120
180
  };
121
- if (config.error) {
122
- body.error = config.error;
123
- }
124
181
  yield new request_1.default().request({
125
- headers: headers,
182
+ headers,
126
183
  method: "POST",
127
184
  requestBody: body,
128
- url: url,
185
+ url,
129
186
  });
130
187
  return body;
131
188
  });
132
189
  /**
133
- *This API is called by HIP only when there is new health data is added/created for a patient and under a care context that is already linked with patient's Health Account. HIP can send following things in this API to notify the Consent Manager about the new health data added:
134
- * @param config
135
- * @healthId Patient's Identifier for which the new health data is added (It can be ABDM address or phr address)
136
- * @careContextReference Care Context reference under which the new health data is added
137
- * @patientReference Patient's reference (An identifier with which the patient is registered on HIP)
138
- * @hiTypes Types of health information documents that have been added ("DiagnosticReportRecord" | "DischargeSummaryRecord" | "HealthDocumentRecord" | "ImmunizationRecord" | "OPConsultRecord" | "PrescriptionRecord" | "WellnessRecord")
139
- * @date in iso format at UTC A date when the health information was created/added on the HIP Note: This API shouldn't be called if the new heath data of is added/created under new care context.
190
+ * Notifies the ABDM Consent Manager about new health data added/created for a patient
191
+ * under an already-linked care context (HIP Initiated Linking v3).
192
+ *
193
+ * Called by HIP when new health information is added under a care context that
194
+ * is already linked with the patient's ABHA account. This API should NOT be called
195
+ * if the new health data is added under a new (unlinked) care context.
196
+ *
197
+ * Uses the v3 HIE-CM endpoint `/api/hiecm/hip/v3/link/context/notify` per the
198
+ * ABDM M2 Sandbox Documentation v2.8 (section 4.3.6).
199
+ *
200
+ * Headers are built inline following the v3 pattern used by `generateToken` and
201
+ * `addCareContext`, including `X-HIP-ID`, `X-LINK-TOKEN`, `REQUEST-ID`, and
202
+ * `TIMESTAMP` as required by the v3 API.
203
+ *
204
+ * @param config - Configuration object
205
+ * @param config.healthId - Patient's identifier (ABHA address, e.g. "user@sbx") used to derive X-CM-ID
206
+ * @param config.hipId - HIP facility ID sent as X-HIP-ID header (e.g. "IN2910000004")
207
+ * @param config.linkToken - Link token (JWT) obtained from token generation, sent as X-LINK-TOKEN header
208
+ * @param config.patientReference - Patient's reference number in the HIP system (e.g. ABHA number)
209
+ * @param config.careContextReference - Care context reference under which new health data was added
210
+ * @param config.hiTypes - Array of HI types for the new health data (e.g. ["Prescription", "DischargeSummary"])
211
+ * @param config.date - ISO 8601 UTC date when the health information was created/added on the HIP
212
+ * @param config.requestId - Optional UUID for REQUEST-ID header (auto-generated if omitted)
213
+ * @param config.timestamp - Optional ISO timestamp for TIMESTAMP header (auto-generated if omitted)
214
+ * @returns The request body that was sent (for logging/reference)
140
215
  */
141
216
  this.notify = (config) => __awaiter(this, void 0, void 0, function* () {
142
- const headers = this.headers(config.healthId);
143
- const url = `${this.baseUrl}v0.5/links/context/notify`;
217
+ var _h, _j;
218
+ this.setXCmId(config.healthId);
219
+ const headers = {
220
+ "REQUEST-ID": (_h = config.requestId) !== null && _h !== void 0 ? _h : (0, uuid_1.v4)(),
221
+ TIMESTAMP: (_j = config.timestamp) !== null && _j !== void 0 ? _j : new Date().toISOString(),
222
+ "X-HIP-ID": config.hipId,
223
+ "X-LINK-TOKEN": config.linkToken,
224
+ "X-CM-ID": this.xCmId,
225
+ "Content-Type": "application/json",
226
+ Authorization: `Bearer ${this.accessToken}`,
227
+ };
228
+ const url = `${this.baseUrl}api/hiecm/hip/v3/link/context/notify`;
144
229
  const body = {
145
- requestId: (0, uuid_1.v4)(),
146
- timestamp: new Date().toISOString(),
147
230
  notification: {
148
231
  patient: {
149
232
  id: config.healthId,
@@ -160,13 +243,59 @@ class Link extends header_1.default {
160
243
  },
161
244
  };
162
245
  yield new request_1.default().request({
163
- headers: headers,
246
+ headers,
164
247
  method: "POST",
165
248
  requestBody: body,
166
- url: url,
249
+ url,
167
250
  });
168
251
  return body;
169
252
  });
253
+ /**
254
+ * Generates a patient token (ABDM HIE-CM v3 endpoint) required for HIE (Health Information Exchange) operations.
255
+ *
256
+ * This token is needed to authorize subsequent HIE transactions such as data push and data pull requests.
257
+ * The API uses the v3 endpoint `/api/hiecm/v3/token/generate-token` which requires custom headers
258
+ * (REQUEST-ID, TIMESTAMP, X-HIP-ID) not present in the standard v0.5 header set.
259
+ *
260
+ * @param config - Configuration object for token generation
261
+ * @param config.healthId - Patient's health ID used to derive the X-CM-ID header (e.g., "user@abdm")
262
+ * @param config.hipId - Health Information Provider ID sent as X-HIP-ID header
263
+ * @param config.abhaNumber - Patient's ABHA number (can be numeric or string)
264
+ * @param config.abhaAddress - Patient's ABHA address (e.g., "user@sbx")
265
+ * @param config.name - Patient's full name
266
+ * @param config.gender - Patient's gender
267
+ * @param config.yearOfBirth - Patient's year of birth
268
+ * @param config.requestId - Optional UUID for REQUEST-ID header (auto-generated if omitted)
269
+ * @param config.timestamp - Optional ISO timestamp for TIMESTAMP header (auto-generated if omitted)
270
+ * @returns The parsed API response containing the generated patient token
271
+ */
272
+ this.generateToken = (config) => __awaiter(this, void 0, void 0, function* () {
273
+ var _k, _l;
274
+ this.setXCmId(config.healthId);
275
+ const headers = {
276
+ "REQUEST-ID": (_k = config.requestId) !== null && _k !== void 0 ? _k : (0, uuid_1.v4)(),
277
+ TIMESTAMP: (_l = config.timestamp) !== null && _l !== void 0 ? _l : new Date().toISOString(),
278
+ "X-HIP-ID": config.hipId,
279
+ "X-CM-ID": this.xCmId,
280
+ "Content-Type": "application/json",
281
+ Authorization: `Bearer ${this.accessToken}`,
282
+ };
283
+ const url = `${this.baseUrl}api/hiecm/v3/token/generate-token`;
284
+ const body = {
285
+ abhaNumber: config.abhaNumber,
286
+ abhaAddress: config.abhaAddress,
287
+ name: config.name,
288
+ gender: config.gender,
289
+ yearOfBirth: config.yearOfBirth,
290
+ };
291
+ const response = yield new request_1.default().request({
292
+ headers,
293
+ method: "POST",
294
+ requestBody: body,
295
+ url,
296
+ });
297
+ return JSON.parse(response.body);
298
+ });
170
299
  }
171
300
  }
172
301
  exports.default = Link;
@@ -1 +1 @@
1
- {"version":3,"file":"link.js","sourceRoot":"","sources":["../../src/classes/link.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+BAAoC;AACpC,wDAAgC;AAChC,sDAA8B;AAc9B,MAAqB,IAAK,SAAQ,gBAAM;IACtC,YAAY,QAAgB,E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vD,UAAU,EAAE,MAAM,CAAC,KAAK;gBACxB,SAAS,EAAE,IAAI,CAAC,KAAK;gBACrB,cAAc,EAAE,kBAAkB;gBAClC,aAAa,EAAE,UAAU,IAAI,CAAC,WAAW,EAAE;aAC5C,CAAC;YACF,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,mCAAmC,CAAC;YAC/D,MAAM,IAAI,GAAG;gBACX,UAAU,EAAE,MAAM,CAAC,UAAU;gBAC7B,WAAW,EAAE,MAAM,CAAC,WAAW;gBAC/B,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,WAAW,EAAE,MAAM,CAAC,WAAW;aAChC,CAAC;YAEF,MAAM,QAAQ,GAAG,MAAM,IAAI,iBAAO,EAAE,CAAC,OAAO,CAAC;gBAC3C,OAAO;gBACP,MAAM,EAAE,MAAM;gBACd,WAAW,EAAE,IAAI;gBACjB,GAAG;aACJ,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACnC,CAAC,CAAA,CAAC;IAzWF,CAAC;CA0WF;AA7WD,uBA6WC"}
@@ -16,22 +16,30 @@ export interface PATIENT_FIND {
16
16
  export default class Patients extends Header {
17
17
  constructor(_baseUrl: string, _accessToken: string);
18
18
  /**
19
- * This API is called by HIP as acknowledgement to notification of consents, in cases of consent revocation and expiration.
20
- * @param config.healthId: string; phradddress or ABHA addrress of patient
21
- * @param config.consentId: string; consent id recive by notify callback
22
- * @param config.requestId: string; request id as recived by notify callback
23
- * @returns
19
+ * Sends an SMS notification to a patient about linked care contexts using the v3 HIE-CM endpoint.
20
+ *
21
+ * This replaces the deprecated v0.5 `smsNotify2` endpoint. It requires the v3 inline header
22
+ * pattern (REQUEST-ID, TIMESTAMP, X-CM-ID) and sends a simplified notification payload
23
+ * containing the patient's phone number and HIP details.
24
+ *
25
+ * Headers are built inline following the existing v3 pattern used by `generateToken` and `addCareContext`.
26
+ *
27
+ * @param config - Configuration object
28
+ * @param config.healthId - Patient's health ID used to derive X-CM-ID header (e.g., "unknown@sbx" or "unknown@abdm")
29
+ * @param config.phoneNo - Patient's phone number for SMS notification
30
+ * @param config.hipName - Display name of the Health Information Provider (HIP)
31
+ * @param config.hipId - HIP identifier (e.g., "IN2910000004")
32
+ * @param config.requestId - Optional UUID for REQUEST-ID header and body (auto-generated if omitted)
33
+ * @param config.timestamp - Optional ISO timestamp for TIMESTAMP header and body (auto-generated if omitted)
34
+ * @returns The parsed API response
24
35
  */
25
36
  smsNotify2: (config: {
26
37
  healthId: "unknown@sbx" | "unknown@abdm";
27
38
  phoneNo: string;
28
- patientName?: string;
29
- careContextInfo: string;
30
- deeplinkUrl?: string;
31
- facilityName?: string;
32
- hipid: string;
33
- errCode?: string;
34
- errMessage?: string;
39
+ hipName: string;
40
+ hipId: string;
41
+ requestId?: string;
42
+ timestamp?: string;
35
43
  }) => Promise<any>;
36
44
  /**
37
45
  * This API is meant for identify to patient given her consent-manager-user-id
@@ -1 +1 @@
1
- {"version":3,"file":"patients.d.ts","sourceRoot":"","sources":["../../src/classes/patients.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,UAAU,CAAC;AAI9B,aAAK,aAAa,GAAG,KAAK,GAAE,KAAK,CAAA;AACjC,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE;QACL,OAAO,EAAG;YACR,EAAE,EAAE,MAAM,CAAA;SACX,CAAA;QAED,SAAS,EAAE;YACT,IAAI,EAAG,aAAa,CAAA;YACpB,EAAE,EAAE,MAAM,CAAA;SACX,CAAA;KACF,CAAA;CACF;AAID,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,MAAM;gBAC9B,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;IAGlD;;;;;;OAMG;IACH,UAAU,WAAkB;QAC1B,QAAQ,EA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H"}
@@ -19,47 +19,54 @@ class Patients extends header_1.default {
19
19
  constructor(_baseUrl, _accessToken) {
20
20
  super(_baseUrl, _accessToken);
21
21
  /**
22
- * This API is called by HIP as acknowledgement to notification of consents, in cases of consent revocation and expiration.
23
- * @param config.healthId: string; phradddress or ABHA addrress of patient
24
- * @param config.consentId: string; consent id recive by notify callback
25
- * @param config.requestId: string; request id as recived by notify callback
26
- * @returns
22
+ * Sends an SMS notification to a patient about linked care contexts using the v3 HIE-CM endpoint.
23
+ *
24
+ * This replaces the deprecated v0.5 `smsNotify2` endpoint. It requires the v3 inline header
25
+ * pattern (REQUEST-ID, TIMESTAMP, X-CM-ID) and sends a simplified notification payload
26
+ * containing the patient's phone number and HIP details.
27
+ *
28
+ * Headers are built inline following the existing v3 pattern used by `generateToken` and `addCareContext`.
29
+ *
30
+ * @param config - Configuration object
31
+ * @param config.healthId - Patient's health ID used to derive X-CM-ID header (e.g., "unknown@sbx" or "unknown@abdm")
32
+ * @param config.phoneNo - Patient's phone number for SMS notification
33
+ * @param config.hipName - Display name of the Health Information Provider (HIP)
34
+ * @param config.hipId - HIP identifier (e.g., "IN2910000004")
35
+ * @param config.requestId - Optional UUID for REQUEST-ID header and body (auto-generated if omitted)
36
+ * @param config.timestamp - Optional ISO timestamp for TIMESTAMP header and body (auto-generated if omitted)
37
+ * @returns The parsed API response
27
38
  */
28
39
  this.smsNotify2 = (config) => __awaiter(this, void 0, void 0, function* () {
29
- try {
30
- const headers = this.headers(config.healthId);
31
- const url = `${this.baseUrl}v0.5/patients/sms/notify2`;
32
- const body = {
33
- requestId: (0, uuid_1.v4)(),
34
- timestamp: new Date().toISOString(),
35
- "notification": {
36
- "phoneNo": config.phoneNo,
37
- "receiverName": config.patientName,
38
- "careContextInfo": config.careContextInfo,
39
- "deeplinkUrl": config.deeplinkUrl,
40
- "hip": {
41
- "name": config.facilityName,
42
- "id": config.hipid
43
- }
44
- }
45
- };
46
- if (config.errCode) {
47
- body.error = {
48
- code: config.errCode,
49
- message: config.errMessage || "Error occured",
50
- };
51
- }
52
- const res = yield new request_1.default().request({
53
- headers: headers,
54
- method: "POST",
55
- requestBody: body,
56
- url: url,
57
- });
58
- return body;
59
- }
60
- catch (error) {
61
- console.log(error);
62
- }
40
+ var _a, _b;
41
+ this.setXCmId(config.healthId);
42
+ const requestId = (_a = config.requestId) !== null && _a !== void 0 ? _a : (0, uuid_1.v4)();
43
+ const timestamp = (_b = config.timestamp) !== null && _b !== void 0 ? _b : new Date().toISOString();
44
+ const headers = {
45
+ "REQUEST-ID": requestId,
46
+ TIMESTAMP: timestamp,
47
+ "X-CM-ID": this.xCmId,
48
+ "Content-Type": "application/json",
49
+ Authorization: `Bearer ${this.accessToken}`,
50
+ };
51
+ const url = `${this.baseUrl}api/hiecm/hip/v3/link/patient/links/sms/notify2`;
52
+ const body = {
53
+ requestId,
54
+ timestamp,
55
+ notification: {
56
+ phoneNo: config.phoneNo,
57
+ hip: {
58
+ name: config.hipName,
59
+ id: config.hipId,
60
+ },
61
+ },
62
+ };
63
+ const response = yield new request_1.default().request({
64
+ headers,
65
+ method: "POST",
66
+ requestBody: body,
67
+ url,
68
+ });
69
+ return JSON.parse(response.body);
63
70
  });
64
71
  /**
65
72
  * This API is meant for identify to patient given her consent-manager-user-id
@@ -1 +1 @@
1
- {"version":3,"file":"patients.js","sourceRoot":"","sources":["../../src/classes/patients.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,sDAA8B;AAC9B,+BAAoC;AACpC,wDAAgC;AAoBhC,MAAqB,QAAS,SAAQ,gBAAM;IAC1C,YAAY,QAAgB,EAAE,YAAoB;QAChD,KAAK,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QAEhC;;;;;;WAMG;QACH,eAAU,GAAG,CAAO,MAUnB,EAAE,EAAE;YACH,IAAI;gBACF,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;gBAChD,MAAM,GAAG,GAAG,GAAG,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-hrp",
3
- "version": "2.2.38",
3
+ "version": "3.0.0",
4
4
  "description": "This is ndhm-hpr",
5
5
  "main": "lib/index.js",
6
6
  "directories": {