@medplum/fhir-router 5.1.7 → 5.1.9

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.
@@ -143,6 +143,16 @@ export declare abstract class FhirRepository<TClient = unknown> {
143
143
  * @returns The search results.
144
144
  */
145
145
  abstract search<T extends Resource>(searchRequest: SearchRequest<T>): Promise<Bundle<WithId<T>>>;
146
+ /**
147
+ * Searches for FHIR resources by reference.
148
+ *
149
+ * This is an advanced operation that is primarily used to optimize GraphQL resolvers that need to search for resources by reference.
150
+ *
151
+ * @param searchRequest - The FHIR search request.
152
+ * @param referenceField - The name of the reference field to search by (e.g. "patient" or "subject").
153
+ * @param references - The reference values to search for (e.g. ["Patient/123", "Patient/456"]).
154
+ * @returns A record mapping reference values to the resources that reference them (e.g. { "Patient/123": [Observation1, Observation2], "Patient/456": [Observation3] }).
155
+ */
146
156
  abstract searchByReference<T extends Resource>(searchRequest: SearchRequest<T>, referenceField: string, references: string[]): Promise<Record<string, WithId<T>[]>>;
147
157
  /**
148
158
  * Runs a callback function within a transaction.
@@ -176,14 +186,61 @@ export declare abstract class FhirRepository<TClient = unknown> {
176
186
  * @returns Promise to the array of search results.
177
187
  */
178
188
  searchResources<T extends Resource>(searchRequest: SearchRequest<T>): Promise<WithId<T>[]>;
189
+ /**
190
+ * Conditionally creates a FHIR resource.
191
+ *
192
+ * The action it takes depends on how many matches are found:
193
+ *
194
+ * 1. No matches: The server processes the create as above
195
+ * 2. One Match: The server ignores the post and returns 200 OK
196
+ * 3. Multiple matches: The server returns a 412 Precondition Failed error indicating the client's criteria were not selective enough
197
+ *
198
+ * See: https://hl7.org/fhir/R4/http.html#ccreate
199
+ *
200
+ * @param resource - The FHIR resource to create.
201
+ * @param search - The "If-None-Exist" search criteria to determine if the resource already exists.
202
+ * @param options - Additional options for resource creation.
203
+ * @returns A promise resolving to the created resource and the operation outcome.
204
+ */
179
205
  conditionalCreate<T extends Resource>(resource: T, search: SearchRequest<T>, options?: CreateResourceOptions): Promise<{
180
206
  resource: WithId<T>;
181
207
  outcome: OperationOutcome;
182
208
  }>;
209
+ /**
210
+ * Conditionally updates a FHIR resource.
211
+ *
212
+ * The action it takes depends on how many matches are found:
213
+ *
214
+ * 1. No matches, no id provided: The server creates the resource.
215
+ * 2. No matches, id provided: The server treats the interaction as an Update as Create interaction (or rejects it, if it does not support Update as Create)
216
+ * 3. One Match, no resource id provided OR (resource id provided and it matches the found resource): The server performs the update against the matching resource
217
+ * 4. One Match, resource id provided but does not match resource found: The server returns a 400 Bad Request error indicating the client id specification was a problem preferably with an OperationOutcome
218
+ * 5. Multiple matches: The server returns a 412 Precondition Failed error indicating the client's criteria were not selective enough preferably with an OperationOutcome
219
+ *
220
+ * See: https://hl7.org/fhir/R4/http.html#cond-update
221
+ *
222
+ * @param resource - The FHIR resource to update.
223
+ * @param search - The "If-Exist" search criteria to determine if the resource already exists.
224
+ * @param options - Additional options for resource update.
225
+ * @returns A promise resolving to the updated resource and the operation outcome.
226
+ */
183
227
  conditionalUpdate<T extends Resource>(resource: T, search: SearchRequest, options?: CreateResourceOptions & UpdateResourceOptions): Promise<{
184
228
  resource: WithId<T>;
185
229
  outcome: OperationOutcome;
186
230
  }>;
231
+ /**
232
+ * Conditionally deletes a FHIR resource.
233
+ *
234
+ * The action it takes depends on how many matches are found:
235
+ *
236
+ * 1. No matches or One Match: The server performs an ordinary delete on the matching resource
237
+ * 2. Multiple matches: A server may choose to delete all the matching resources, or it may choose to return a 412 Precondition Failed error indicating the client's criteria were not selective enough.
238
+ *
239
+ * See: https://hl7.org/fhir/R4/http.html#3.1.0.7.1
240
+ *
241
+ * @param search - The "If-Exist" search criteria to determine which resource(s) to delete.
242
+ * @returns A promise that resolves when the operation is complete.
243
+ */
187
244
  conditionalDelete(search: SearchRequest): Promise<void>;
188
245
  conditionalPatch(search: SearchRequest, patch: Operation[]): Promise<WithId<Resource>>;
189
246
  }
@@ -143,6 +143,16 @@ export declare abstract class FhirRepository<TClient = unknown> {
143
143
  * @returns The search results.
144
144
  */
145
145
  abstract search<T extends Resource>(searchRequest: SearchRequest<T>): Promise<Bundle<WithId<T>>>;
146
+ /**
147
+ * Searches for FHIR resources by reference.
148
+ *
149
+ * This is an advanced operation that is primarily used to optimize GraphQL resolvers that need to search for resources by reference.
150
+ *
151
+ * @param searchRequest - The FHIR search request.
152
+ * @param referenceField - The name of the reference field to search by (e.g. "patient" or "subject").
153
+ * @param references - The reference values to search for (e.g. ["Patient/123", "Patient/456"]).
154
+ * @returns A record mapping reference values to the resources that reference them (e.g. { "Patient/123": [Observation1, Observation2], "Patient/456": [Observation3] }).
155
+ */
146
156
  abstract searchByReference<T extends Resource>(searchRequest: SearchRequest<T>, referenceField: string, references: string[]): Promise<Record<string, WithId<T>[]>>;
147
157
  /**
148
158
  * Runs a callback function within a transaction.
@@ -176,14 +186,61 @@ export declare abstract class FhirRepository<TClient = unknown> {
176
186
  * @returns Promise to the array of search results.
177
187
  */
178
188
  searchResources<T extends Resource>(searchRequest: SearchRequest<T>): Promise<WithId<T>[]>;
189
+ /**
190
+ * Conditionally creates a FHIR resource.
191
+ *
192
+ * The action it takes depends on how many matches are found:
193
+ *
194
+ * 1. No matches: The server processes the create as above
195
+ * 2. One Match: The server ignores the post and returns 200 OK
196
+ * 3. Multiple matches: The server returns a 412 Precondition Failed error indicating the client's criteria were not selective enough
197
+ *
198
+ * See: https://hl7.org/fhir/R4/http.html#ccreate
199
+ *
200
+ * @param resource - The FHIR resource to create.
201
+ * @param search - The "If-None-Exist" search criteria to determine if the resource already exists.
202
+ * @param options - Additional options for resource creation.
203
+ * @returns A promise resolving to the created resource and the operation outcome.
204
+ */
179
205
  conditionalCreate<T extends Resource>(resource: T, search: SearchRequest<T>, options?: CreateResourceOptions): Promise<{
180
206
  resource: WithId<T>;
181
207
  outcome: OperationOutcome;
182
208
  }>;
209
+ /**
210
+ * Conditionally updates a FHIR resource.
211
+ *
212
+ * The action it takes depends on how many matches are found:
213
+ *
214
+ * 1. No matches, no id provided: The server creates the resource.
215
+ * 2. No matches, id provided: The server treats the interaction as an Update as Create interaction (or rejects it, if it does not support Update as Create)
216
+ * 3. One Match, no resource id provided OR (resource id provided and it matches the found resource): The server performs the update against the matching resource
217
+ * 4. One Match, resource id provided but does not match resource found: The server returns a 400 Bad Request error indicating the client id specification was a problem preferably with an OperationOutcome
218
+ * 5. Multiple matches: The server returns a 412 Precondition Failed error indicating the client's criteria were not selective enough preferably with an OperationOutcome
219
+ *
220
+ * See: https://hl7.org/fhir/R4/http.html#cond-update
221
+ *
222
+ * @param resource - The FHIR resource to update.
223
+ * @param search - The "If-Exist" search criteria to determine if the resource already exists.
224
+ * @param options - Additional options for resource update.
225
+ * @returns A promise resolving to the updated resource and the operation outcome.
226
+ */
183
227
  conditionalUpdate<T extends Resource>(resource: T, search: SearchRequest, options?: CreateResourceOptions & UpdateResourceOptions): Promise<{
184
228
  resource: WithId<T>;
185
229
  outcome: OperationOutcome;
186
230
  }>;
231
+ /**
232
+ * Conditionally deletes a FHIR resource.
233
+ *
234
+ * The action it takes depends on how many matches are found:
235
+ *
236
+ * 1. No matches or One Match: The server performs an ordinary delete on the matching resource
237
+ * 2. Multiple matches: A server may choose to delete all the matching resources, or it may choose to return a 412 Precondition Failed error indicating the client's criteria were not selective enough.
238
+ *
239
+ * See: https://hl7.org/fhir/R4/http.html#3.1.0.7.1
240
+ *
241
+ * @param search - The "If-Exist" search criteria to determine which resource(s) to delete.
242
+ * @returns A promise that resolves when the operation is complete.
243
+ */
187
244
  conditionalDelete(search: SearchRequest): Promise<void>;
188
245
  conditionalPatch(search: SearchRequest, patch: Operation[]): Promise<WithId<Resource>>;
189
246
  }