@medplum/core 5.1.13 → 5.1.14

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.
@@ -26,6 +26,8 @@ import type { HumanName } from '@medplum/fhirtypes';
26
26
  import type { Identifier } from '@medplum/fhirtypes';
27
27
  import type { ImagingStudy } from '@medplum/fhirtypes';
28
28
  import type { Media } from '@medplum/fhirtypes';
29
+ import type { Medication } from '@medplum/fhirtypes';
30
+ import type { MedicationRequest } from '@medplum/fhirtypes';
29
31
  import type { Meta } from '@medplum/fhirtypes';
30
32
  import type { Money } from '@medplum/fhirtypes';
31
33
  import type { Observation } from '@medplum/fhirtypes';
@@ -35,6 +37,7 @@ import type { ObservationDefinitionQualifiedInterval } from '@medplum/fhirtypes'
35
37
  import type { OperationOutcome } from '@medplum/fhirtypes';
36
38
  import type { OperationOutcomeIssue } from '@medplum/fhirtypes';
37
39
  import type { Organization } from '@medplum/fhirtypes';
40
+ import type { Parameters as Parameters_2 } from '@medplum/fhirtypes';
38
41
  import type { Patient } from '@medplum/fhirtypes';
39
42
  import type { Period } from '@medplum/fhirtypes';
40
43
  import type { Practitioner } from '@medplum/fhirtypes';
@@ -492,6 +495,20 @@ export declare function buildElementsContext({ parentContext, path, elements, pr
492
495
  accessPolicyResource?: AccessPolicyResource;
493
496
  }): ElementsContextType | undefined;
494
497
 
498
+ /**
499
+ * Builds the `statusReason` CodeableConcept used when soft-deleting a draft
500
+ * `MedicationRequest` whose vendor-side outcome is unknown (see
501
+ * {@link MEDICATION_REQUEST_STATUS_REASON_RESPONSE_NOT_RECEIVED}).
502
+ *
503
+ * Paired with `status: 'unknown'` (a valid FHIR R4 MedicationRequest status),
504
+ * this is the standard shape every order-medication caller should write when
505
+ * `orderMedication(...)` throws after the draft MR has been created.
506
+ *
507
+ * @returns A `CodeableConcept` carrying our canonical system + code and a
508
+ * human-readable `text` summary.
509
+ */
510
+ export declare function buildMedicationRequestResponseLostStatusReason(): CodeableConcept;
511
+
495
512
  export declare function buildTypeName(components: string[]): string;
496
513
 
497
514
  export declare function businessRule(key: string, message: string): OperationOutcome;
@@ -2172,6 +2189,14 @@ export declare function getImageSrc(resource: Resource): string | undefined;
2172
2189
 
2173
2190
  export declare function getInnerDerivedIdentifierExpression(expression: string): string | undefined;
2174
2191
 
2192
+ /**
2193
+ * Reads the medication-order iframe launch URL from MedicationRequest extensions.
2194
+ * @param medicationRequest - MR to read.
2195
+ * @param ext - Vendor extension URL configuration.
2196
+ * @returns The launch URL, if present.
2197
+ */
2198
+ export declare function getMedicationOrderIframeUrl(medicationRequest: MedicationRequest, ext: MedicationOrderExtensions): string | undefined;
2199
+
2175
2200
  export declare function getNestedProperty(value: TypedValueWithPath | undefined, key: string, options: {
2176
2201
  profileUrl?: string;
2177
2202
  withPath: true;
@@ -2203,6 +2228,22 @@ export declare function getPathDifference(parentPath: string, path: string): str
2203
2228
  */
2204
2229
  export declare function getPathDisplayName(path: string): string;
2205
2230
 
2231
+ /**
2232
+ * Reads the pending medication-order id from MedicationRequest identifiers.
2233
+ * @param medicationRequest - Draft or active MR carrying vendor identifiers.
2234
+ * @param ext - Vendor extension URL and identifier system configuration.
2235
+ * @returns The pending order id string, if present.
2236
+ */
2237
+ export declare function getPendingMedicationOrderId(medicationRequest: MedicationRequest, ext: MedicationOrderExtensions): string | undefined;
2238
+
2239
+ /**
2240
+ * Reads the pending medication-order status code from MedicationRequest extensions.
2241
+ * @param medicationRequest - MR to read.
2242
+ * @param ext - Vendor extension URL configuration.
2243
+ * @returns The status code (e.g. queued), if present.
2244
+ */
2245
+ export declare function getPendingMedicationOrderStatus(medicationRequest: MedicationRequest, ext: MedicationOrderExtensions): string | undefined;
2246
+
2206
2247
  /**
2207
2248
  * Extracts preferred pharmacies from a Patient resource's extensions.
2208
2249
  *
@@ -2904,6 +2945,21 @@ export declare interface InternalTypeSchema {
2904
2945
  mandatoryProperties?: Set<string>;
2905
2946
  }
2906
2947
 
2948
+ /**
2949
+ * Stable error when a bot response does not match {@link MedicationOrderResponse}.
2950
+ */
2951
+ export declare const INVALID_MEDICATION_ORDER_RESPONSE = "Invalid response from order medication bot";
2952
+
2953
+ /**
2954
+ * Stable error when an order-set widget-url response is missing `launchUrl`.
2955
+ */
2956
+ export declare const INVALID_MEDICATION_ORDER_SET_RESPONSE = "Invalid response from order-set bot";
2957
+
2958
+ /**
2959
+ * Stable error when a bot response is not a Medication array.
2960
+ */
2961
+ export declare const INVALID_MEDICATION_SEARCH_RESPONSE = "Invalid response from medication search bot";
2962
+
2907
2963
  export declare function invalidSearchOperator(operator: Operator, searchParameterCodeOrId: string): OperationOutcome;
2908
2964
 
2909
2965
  export declare interface InviteRequest {
@@ -3059,6 +3115,33 @@ export declare function isJwt(token: string): boolean;
3059
3115
 
3060
3116
  export declare function isLowerCase(c: string): boolean;
3061
3117
 
3118
+ /**
3119
+ * Type guard: validates an array of Medication resources (drug search bot output).
3120
+ *
3121
+ * Walks every entry rather than spot-checking the first so a tuple-shaped
3122
+ * payload like `[Medication, MedicationRequest]` is rejected (see PR
3123
+ * [#8999](https://github.com/medplum/medplum/pull/8999#discussion_r3276251617)).
3124
+ *
3125
+ * @param value - Unknown bot JSON payload.
3126
+ * @returns True when the value is an array (possibly empty) where every entry
3127
+ * passes `isResource<Medication>`.
3128
+ */
3129
+ export declare function isMedicationArray(value: unknown): value is Medication[];
3130
+
3131
+ /**
3132
+ * Type guard: validates an order-medication bot response.
3133
+ * @param value - Unknown bot JSON payload.
3134
+ * @returns True when the value matches MedicationOrderResponse.
3135
+ */
3136
+ export declare function isMedicationOrderResponse(value: unknown): value is MedicationOrderResponse;
3137
+
3138
+ /**
3139
+ * Type guard: validates an order-set widget-URL bot response.
3140
+ * @param value - Unknown bot JSON payload.
3141
+ * @returns True when the value matches {@link MedicationOrderSetResponse}.
3142
+ */
3143
+ export declare function isMedicationOrderSetResponse(value: unknown): value is MedicationOrderSetResponse;
3144
+
3062
3145
  /**
3063
3146
  * Returns true if the access token was issued by a Medplum server.
3064
3147
  * @param accessToken - An access token of unknown origin.
@@ -3588,6 +3671,198 @@ export declare function matchesRange(value: number, range: Range_2, precision?:
3588
3671
  */
3589
3672
  export declare function matchesSearchRequest(resource: Resource, searchRequest: SearchRequest): boolean;
3590
3673
 
3674
+ /**
3675
+ * Code stamped on `MedicationRequest.statusReason` when an order-medication
3676
+ * operation never returned a verifiable response — the vendor side may have
3677
+ * created (and sent) the prescription, or it may have rejected the request, and
3678
+ * we cannot tell from the client. Used in place of a hard `DELETE` so the
3679
+ * record stays addressable for later reconciliation against vendor webhooks.
3680
+ */
3681
+ export declare const MEDICATION_REQUEST_STATUS_REASON_RESPONSE_NOT_RECEIVED = "response-not-received";
3682
+
3683
+ /**
3684
+ * Canonical CodeSystem URL for `MedicationRequest.statusReason` values stamped
3685
+ * by Medplum-managed order flows when a draft MR has to be retired without a
3686
+ * confirmed vendor outcome.
3687
+ *
3688
+ * Downstream reconciliation (vendor webhook bots, audit reports) should match
3689
+ * `statusReason.coding[?(@.system==MEDICATION_REQUEST_STATUS_REASON_SYSTEM)]`
3690
+ * to recognize records that originated from this soft-delete path rather than
3691
+ * a clinician decision.
3692
+ */
3693
+ export declare const MEDICATION_REQUEST_STATUS_REASON_SYSTEM = "https://medplum.com/fhir/CodeSystem/medication-request-status-reason";
3694
+
3695
+ /**
3696
+ * Vendor-neutral drug line for {@link MedicationOrderRequest}.
3697
+ */
3698
+ export declare interface MedicationOrderDrugInput {
3699
+ readonly ndc?: string;
3700
+ readonly rxNorm?: string;
3701
+ readonly routedMedId?: number;
3702
+ readonly quantity: number;
3703
+ readonly quantityQualifier?: string;
3704
+ readonly refill?: number;
3705
+ readonly drugOrder?: number;
3706
+ readonly sigLine3?: string;
3707
+ readonly useSubstitution?: boolean;
3708
+ }
3709
+
3710
+ /**
3711
+ * Vendor-neutral mapping of the extension URLs / identifier systems used to read
3712
+ * pending medication-order state stamped on a `MedicationRequest`.
3713
+ */
3714
+ export declare interface MedicationOrderExtensions {
3715
+ readonly pendingOrderIdSystem: string;
3716
+ readonly pendingOrderStatusUrl: string;
3717
+ readonly iframeUrlExtension: string;
3718
+ }
3719
+
3720
+ /**
3721
+ * Vendor-neutral input for an order-medication bot (matches the ScriptSure bot shape).
3722
+ */
3723
+ export declare interface MedicationOrderRequest {
3724
+ readonly patientId: string;
3725
+ readonly medicationRequestId?: string;
3726
+ readonly combinationMed?: boolean;
3727
+ readonly drugs?: MedicationOrderDrugInput[];
3728
+ readonly compoundTitle?: string;
3729
+ readonly compoundQuantity?: number;
3730
+ readonly compoundQuantityQualifier?: string;
3731
+ readonly compoundSigs?: {
3732
+ readonly sigOrder: number;
3733
+ readonly line3: string;
3734
+ readonly drugId?: number;
3735
+ }[];
3736
+ readonly conditionIds?: string[];
3737
+ readonly coverageId?: string;
3738
+ readonly payerOrganizationId?: string;
3739
+ readonly pharmacyOrganizationId?: string;
3740
+ readonly diagnoses?: {
3741
+ readonly icdId: string;
3742
+ readonly name: string;
3743
+ }[];
3744
+ readonly pharmacyNcpdpId?: string;
3745
+ readonly pharmacyName?: string;
3746
+ readonly writtenDate?: string;
3747
+ readonly fillDate?: string;
3748
+ /** Days supply for ScriptSure pending order duration (used when no draft MR, e.g. compound). */
3749
+ readonly durationDays?: number;
3750
+ /** Notes to pharmacist (ScriptSure pending-order pharmacyNote); also stored on draft MR as `note`. */
3751
+ readonly pharmacyNote?: string;
3752
+ /** Free-text patient instructions (additional sig); maps to dosageInstruction[0].patientInstruction when using MR path. */
3753
+ readonly patientInstruction?: string;
3754
+ readonly appId?: string;
3755
+ }
3756
+
3757
+ /**
3758
+ * Encodes a {@link MedicationOrderRequest} as a FHIR `Parameters` body for the
3759
+ * vendor-neutral `$order-medication` custom operation.
3760
+ *
3761
+ * Nested arrays (`drugs`, `compoundSigs`, `diagnoses`) are emitted as one
3762
+ * `parameter` entry per element so the OperationDefinition's `max: '*'`
3763
+ * cardinality round-trips; primitive arrays (`conditionIds`) likewise emit
3764
+ * one entry per id. Optional fields are omitted entirely.
3765
+ *
3766
+ * @param req - The order-medication request (vendor-neutral).
3767
+ * @returns A `Parameters` resource ready to POST.
3768
+ */
3769
+ export declare function medicationOrderRequestToParameters(req: MedicationOrderRequest): Parameters_2;
3770
+
3771
+ /**
3772
+ * Vendor-neutral output from an order-medication bot.
3773
+ */
3774
+ export declare interface MedicationOrderResponse {
3775
+ readonly orderId: number;
3776
+ /**
3777
+ * Vendor-side patient id (numeric in ScriptSure today; other vendors may use a different
3778
+ * shape). Kept as `number` for backwards compatibility with the ScriptSure bot output.
3779
+ */
3780
+ readonly vendorPatientId: number;
3781
+ readonly launchUrl: string;
3782
+ readonly medicationRequestId?: string;
3783
+ readonly pendingOrderStatus?: 'queued' | 'reused';
3784
+ }
3785
+
3786
+ /**
3787
+ * Vendor-neutral input for an order-set widget-URL bot.
3788
+ *
3789
+ * One of `planDefinitionId` (Medplum reverse-lookup to the vendor's orderset id
3790
+ * via a cross-system identifier) or `vendorOrderSetId` (escape hatch when no
3791
+ * synced PD exists) is required. Bots reject input where both are set so the
3792
+ * intent is unambiguous on the wire.
3793
+ */
3794
+ export declare interface MedicationOrderSetRequest {
3795
+ readonly patientId: string;
3796
+ readonly planDefinitionId?: string;
3797
+ /**
3798
+ * Vendor-side order-set id. Numeric in ScriptSure today; kept as
3799
+ * `number | string` so vendors with non-numeric ids can adopt the operation
3800
+ * without a wire-format change.
3801
+ */
3802
+ readonly vendorOrderSetId?: number | string;
3803
+ readonly appId?: string;
3804
+ }
3805
+
3806
+ /**
3807
+ * Encodes a {@link MedicationOrderSetRequest} as a FHIR `Parameters` body for
3808
+ * the vendor-neutral `$order-set-url` custom operation
3809
+ * (`POST /fhir/R4/PlanDefinition/$order-set-url`). Optional fields are omitted
3810
+ * entirely so the wire payload mirrors the legacy `executeBot` plain-JSON
3811
+ * shape the bot's `parseInput` helper would otherwise have to coerce.
3812
+ *
3813
+ * `vendorOrderSetId` is encoded as `valueInteger` when numeric and
3814
+ * `valueString` otherwise — keeping the operation usable by future vendors
3815
+ * whose order-set ids are not numeric.
3816
+ *
3817
+ * @param req - Order-set request (vendor-neutral).
3818
+ * @returns A `Parameters` resource ready to POST.
3819
+ */
3820
+ export declare function medicationOrderSetRequestToParameters(req: MedicationOrderSetRequest): Parameters_2;
3821
+
3822
+ /**
3823
+ * Vendor-neutral output from an order-set widget-URL bot.
3824
+ *
3825
+ * The bot itself does not create FHIR resources — it just resolves the vendor
3826
+ * ids and returns an iframe URL the prescriber loads to review/sign the whole
3827
+ * order set in one pass. Optional echoes (`vendorPatientId`, `vendorOrderSetId`,
3828
+ * `planDefinitionId`) are surfaced for diagnostics and audit logging.
3829
+ */
3830
+ export declare interface MedicationOrderSetResponse {
3831
+ readonly launchUrl: string;
3832
+ readonly vendorPatientId?: number | string;
3833
+ readonly vendorOrderSetId?: number | string;
3834
+ readonly planDefinitionId?: string;
3835
+ }
3836
+
3837
+ /**
3838
+ * Parameters for a drug search bot used by {@link MedicationOrderRequest} flows.
3839
+ */
3840
+ export declare interface MedicationSearchParams {
3841
+ readonly term?: string;
3842
+ readonly ndc?: string;
3843
+ readonly rxNorm?: string;
3844
+ readonly routedMedId?: number;
3845
+ readonly searchOtc?: boolean;
3846
+ readonly searchSupply?: boolean;
3847
+ readonly searchBrand?: boolean;
3848
+ readonly searchGeneric?: boolean;
3849
+ readonly includeCode?: boolean;
3850
+ /** When true, drug-search bot returns quantity qualifiers from GET /v3/prescription/quantityqualifier instead of Medication[]. */
3851
+ readonly quantityQualifiers?: boolean;
3852
+ }
3853
+
3854
+ /**
3855
+ * Encodes a {@link MedicationSearchParams} as a FHIR `Parameters` body for the
3856
+ * vendor-neutral `$drug-search` (and `$drug-quantity-qualifiers`) custom
3857
+ * operations. Optional fields are omitted entirely so the wire payload stays
3858
+ * minimal and mirrors the legacy `executeBot` plain-JSON shape that the bot's
3859
+ * `parseInput` helper would otherwise have to coerce.
3860
+ *
3861
+ * @param params - Drug search parameters (vendor-neutral subset).
3862
+ * @returns A `Parameters` resource ready to POST.
3863
+ */
3864
+ export declare function medicationSearchParamsToParameters(params: MedicationSearchParams): Parameters_2;
3865
+
3591
3866
  export declare const MEDPLUM_CLI_CLIENT_ID = "medplum-cli";
3592
3867
 
3593
3868
  export declare const MEDPLUM_RELEASES_URL = "https://meta.medplum.com/releases";
@@ -4898,6 +5173,13 @@ export declare class MedplumClient extends TypedEventTarget<MedplumClientEventMa
4898
5173
  * @returns The response body.
4899
5174
  */
4900
5175
  startAsyncRequest<T>(url: string, options?: MedplumRequestOptions): Promise<T>;
5176
+ /**
5177
+ * Wraps `fetch` execution with token refresh and retry logic.
5178
+ * @param url - The URL to request
5179
+ * @param options - Optional fetch options
5180
+ * @returns The response
5181
+ */
5182
+ wrappedFetch(url: string, options: RequestInit): Promise<Response>;
4901
5183
  /**
4902
5184
  * Returns the key value client.
4903
5185
  * @returns The key value client.
@@ -4947,7 +5229,6 @@ export declare class MedplumClient extends TypedEventTarget<MedplumClientEventMa
4947
5229
  private deleteCacheEntry;
4948
5230
  /**
4949
5231
  * Makes an HTTP request.
4950
- * @param method - The HTTP method (GET, POST, etc).
4951
5232
  * @param url - The target URL.
4952
5233
  * @param options - Optional fetch request init options.
4953
5234
  * @param state - Optional request state.
@@ -5006,7 +5287,6 @@ export declare class MedplumClient extends TypedEventTarget<MedplumClientEventMa
5006
5287
  * Handles an unauthenticated response from the server.
5007
5288
  * First, tries to refresh the access token and retry the request.
5008
5289
  * Otherwise, calls unauthenticated callbacks and rejects.
5009
- * @param method - The HTTP method of the original request.
5010
5290
  * @param url - The URL of the original request.
5011
5291
  * @param options - Optional fetch request init options.
5012
5292
  * @returns The result of the retry.
@@ -6341,6 +6621,30 @@ export declare class OrAtom extends InfixOperatorAtom {
6341
6621
  */
6342
6622
  export declare type OutputRow = Record<string, any>;
6343
6623
 
6624
+ /**
6625
+ * Decodes the `Parameters` response from the `$order-medication` custom
6626
+ * operation into a typed {@link MedicationOrderResponse}. Throws
6627
+ * `INVALID_MEDICATION_ORDER_RESPONSE` when required fields are missing.
6628
+ *
6629
+ * @param params - The `Parameters` resource returned by the operation.
6630
+ * @returns A vendor-neutral {@link MedicationOrderResponse}.
6631
+ */
6632
+ export declare function parametersToMedicationOrderResponse(params: Parameters_2): MedicationOrderResponse;
6633
+
6634
+ /**
6635
+ * Decodes the `Parameters` response from the `$order-set-url` custom operation
6636
+ * into a typed {@link MedicationOrderSetResponse}. Throws
6637
+ * `INVALID_MEDICATION_ORDER_SET_RESPONSE` when `launchUrl` is missing or empty.
6638
+ *
6639
+ * Echoed vendor ids (`vendorPatientId`, `vendorOrderSetId`) are preserved as
6640
+ * the wire type — `number` when sent as `valueInteger`, `string` when sent as
6641
+ * `valueString` — so downstream code can read either without conversion.
6642
+ *
6643
+ * @param params - The `Parameters` resource returned by the operation.
6644
+ * @returns A vendor-neutral {@link MedicationOrderSetResponse}.
6645
+ */
6646
+ export declare function parametersToMedicationOrderSetResponse(params: Parameters_2): MedicationOrderSetResponse;
6647
+
6344
6648
  /**
6345
6649
  * Parses a FHIRPath expression into an AST.
6346
6650
  * The result can be used to evaluate the expression against a resource or other object.
@@ -7016,6 +7320,7 @@ export declare class ParserBuilder {
7016
7320
  readonly elementDefinitions?: InternalSchemaElement[];
7017
7321
  readonly parsedExpression: FhirPathAtom;
7018
7322
  readonly array?: boolean;
7323
+ readonly referenceTargetTypes?: ResourceType[];
7019
7324
  }
7020
7325
 
7021
7326
  export declare const SearchParameterType: {