@medplum/core 5.1.13 → 5.1.15

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