{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/affinityrx-com/json-schema/affinityrx-com-order-schema.json",
  "title": "Order",
  "x-generated": "2026-11-23",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/affinityrx-com-openapi.json#/components/schemas/Order",
  "type": "object",
  "properties": {
    "cancelRequestedAt": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ],
      "description": "When cancellation was requested, or null when no cancellation is waiting."
    },
    "createdAt": {
      "type": "string",
      "description": "When the record was created.",
      "format": "date-time"
    },
    "externalOrderId": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "Your order identifier, unique within the practice and mode. A failed or cancelled order keeps it."
    },
    "failureReason": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "Why the order failed, for a person to read. Null unless the order failed; a refused cancel leaves it null."
    },
    "id": {
      "type": "string",
      "pattern": "^ord_[0-7][0-9a-hjkmnp-tv-z]{25}$",
      "description": "The public record identifier."
    },
    "mode": {
      "type": "string",
      "description": "The Test or Live mode of this record.",
      "x-extensible-enum": [
        "test",
        "live"
      ]
    },
    "patient": {
      "$ref": "#/$defs/Patient"
    },
    "patientId": {
      "type": "string",
      "pattern": "^pat_[0-7][0-9a-hjkmnp-tv-z]{25}$",
      "description": "The patient's public identifier."
    },
    "practice": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "address": {
              "$ref": "#/$defs/Address"
            },
            "name": {
              "type": "string",
              "description": "The name."
            },
            "phone": {
              "type": "string",
              "description": "The contact phone number."
            },
            "archivedAt": {
              "anyOf": [
                {
                  "type": "string",
                  "format": "date-time"
                },
                {
                  "type": "null"
                }
              ],
              "description": "When the practice was archived, or null while it is active."
            }
          },
          "required": [
            "address",
            "name",
            "phone",
            "archivedAt"
          ],
          "additionalProperties": {
            "description": "A field that this API version can add. Ignore fields that you do not know."
          }
        },
        {
          "type": "null"
        }
      ],
      "description": "The practice contact details saved when the order was signed, or null for historical orders without a snapshot."
    },
    "practiceId": {
      "type": "string",
      "pattern": "^prac_[0-7][0-9a-hjkmnp-tv-z]{25}$",
      "description": "The practice's public identifier."
    },
    "prescriber": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "firstName": {
              "type": "string",
              "description": "The first name."
            },
            "lastName": {
              "type": "string",
              "description": "The last name."
            },
            "npi": {
              "type": "string",
              "description": "The prescribing clinician's 10-digit National Provider Identifier (NPI)."
            },
            "phone": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "description": "The contact phone number."
            },
            "address": {
              "anyOf": [
                {
                  "$ref": "#/$defs/Address"
                },
                {
                  "type": "null"
                }
              ],
              "description": "The US mailing address."
            }
          },
          "required": [
            "firstName",
            "lastName",
            "npi",
            "phone",
            "address"
          ],
          "additionalProperties": {
            "description": "A field that this API version can add. Ignore fields that you do not know."
          }
        },
        {
          "type": "null"
        }
      ],
      "description": "The prescribing clinician's details saved when the order was signed."
    },
    "prescriptions": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Prescription"
      },
      "description": "The prescriptions for this order's patient."
    },
    "shipping": {
      "type": "object",
      "properties": {
        "option": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "pattern": "^shp_[0-7][0-9a-hjkmnp-tv-z]{25}$",
                  "description": "The public record identifier."
                },
                "name": {
                  "type": "string",
                  "description": "The name."
                },
                "price": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 9007199254740991,
                  "description": "The shipping price charged, in integer cents."
                }
              },
              "required": [
                "id",
                "name",
                "price"
              ],
              "additionalProperties": {
                "description": "A field that this API version can add. Ignore fields that you do not know."
              }
            },
            {
              "type": "null"
            }
          ],
          "description": "The shipping option saved at signing, or null for historical orders without an option."
        },
        "destination": {
          "$ref": "#/$defs/ShippingDestination"
        }
      },
      "required": [
        "option",
        "destination"
      ],
      "description": "The shipping option and destination.",
      "additionalProperties": {
        "description": "A field that this API version can add. Ignore fields that you do not know."
      }
    },
    "shipments": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Shipment"
      },
      "description": "The shipped packages, oldest first; a split shipment or reshipment adds a package."
    },
    "status": {
      "type": "string",
      "description": "The current fulfillment status.",
      "x-extensible-enum": [
        "awaiting_approval",
        "submitted",
        "processing",
        "shipped",
        "delivered",
        "cancelled",
        "failed"
      ]
    },
    "trackingUrl": {
      "anyOf": [
        {
          "type": "string",
          "format": "uri"
        },
        {
          "type": "null"
        }
      ],
      "description": "The carrier's tracking page for the newest package. Null when there is no package yet or the carrier has no tracking page."
    },
    "statusHistory": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/StatusHistoryEntry"
      },
      "description": "The order's status changes, oldest first."
    },
    "total": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991,
      "description": "The total order price in integer cents, including medication and shipping."
    },
    "updatedAt": {
      "type": "string",
      "description": "When the record was last updated.",
      "format": "date-time"
    }
  },
  "required": [
    "cancelRequestedAt",
    "createdAt",
    "externalOrderId",
    "failureReason",
    "id",
    "mode",
    "patient",
    "patientId",
    "practice",
    "practiceId",
    "prescriber",
    "prescriptions",
    "shipping",
    "shipments",
    "status",
    "trackingUrl",
    "statusHistory",
    "total",
    "updatedAt"
  ],
  "additionalProperties": {
    "description": "A field that this API version can add. Ignore fields that you do not know."
  },
  "$defs": {
    "Address": {
      "type": "object",
      "properties": {
        "line1": {
          "type": "string",
          "description": "The street address."
        },
        "line2": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "The apartment or suite, or null when there is none."
        },
        "city": {
          "type": "string",
          "description": "The city name."
        },
        "state": {
          "type": "string",
          "description": "The two-letter US state code."
        },
        "postalCode": {
          "type": "string",
          "description": "The US ZIP code."
        }
      },
      "required": [
        "line1",
        "line2",
        "city",
        "state",
        "postalCode"
      ],
      "description": "The US mailing address.",
      "additionalProperties": {
        "description": "A field that this API version can add. Ignore fields that you do not know."
      }
    },
    "Allergy": {
      "type": "object",
      "properties": {
        "category": {
          "type": "string",
          "description": "The allergy category.",
          "x-extensible-enum": [
            "drug",
            "food",
            "insect",
            "latex",
            "mold",
            "pet",
            "pollen"
          ]
        },
        "display": {
          "type": "string",
          "description": "The reported allergy name."
        }
      },
      "required": [
        "category",
        "display"
      ],
      "additionalProperties": {
        "description": "A field that this API version can add. Ignore fields that you do not know."
      }
    },
    "Fill": {
      "type": "object",
      "properties": {
        "amount": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991,
          "description": "How much one fill holds, in `unit`."
        },
        "container": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "What holds one fill, such as `vial`. Null when the pharmacy does not say."
        },
        "ingredients": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "amount": {
                "type": "number",
                "description": "The amount in the specified unit."
              },
              "name": {
                "type": "string",
                "description": "The name."
              },
              "unit": {
                "type": "string",
                "description": "The unit used to measure the amount."
              }
            },
            "required": [
              "amount",
              "name",
              "unit"
            ],
            "additionalProperties": {
              "description": "A field that this API version can add. Ignore fields that you do not know."
            }
          },
          "description": "Each active ingredient's total in one fill: a 2 mL vial of 30 mg/mL is 60 mg."
        },
        "unit": {
          "type": "string",
          "description": "The unit of `amount`, the same as `quantityUnit`: `vial` for a vial product."
        },
        "volume": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "amount": {
                  "type": "number",
                  "description": "The amount in the specified unit."
                },
                "unit": {
                  "type": "string",
                  "description": "The unit used to measure the amount."
                }
              },
              "required": [
                "amount",
                "unit"
              ],
              "additionalProperties": {
                "description": "A field that this API version can add. Ignore fields that you do not know."
              }
            },
            {
              "type": "null"
            }
          ],
          "description": "What one vial holds, such as 2 mL. Null for a product that is not a vial."
        }
      },
      "required": [
        "amount",
        "container",
        "ingredients",
        "unit",
        "volume"
      ],
      "description": "What the pharmacy dispenses for one price. A quantity counts `unit`, not fills, and is a whole number of fills: for a fill of 30 tablets, quantity 60 is two fills and costs twice the price. For a vial product, one fill is one vial and quantity counts vials.",
      "additionalProperties": {
        "description": "A field that this API version can add. Ignore fields that you do not know."
      }
    },
    "Kit": {
      "type": "object",
      "properties": {
        "days": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991,
          "description": "How many days the kit lasts."
        },
        "vials": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "ingredients": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "amount": {
                      "type": "number",
                      "description": "The amount in the specified unit."
                    },
                    "name": {
                      "type": "string",
                      "description": "The name."
                    },
                    "unit": {
                      "type": "string",
                      "description": "The unit used to measure the amount."
                    }
                  },
                  "required": [
                    "amount",
                    "name",
                    "unit"
                  ],
                  "additionalProperties": {
                    "description": "A field that this API version can add. Ignore fields that you do not know."
                  }
                },
                "description": "Each active ingredient's total in this vial."
              },
              "strength": {
                "type": "string",
                "description": "This vial's strength, such as 5 mg/mL."
              }
            },
            "required": [
              "ingredients",
              "strength"
            ],
            "additionalProperties": {
              "description": "A field that this API version can add. Ignore fields that you do not know."
            }
          },
          "description": "Each vial or bottle in the order it is used. `fill.volume` is what one holds."
        }
      },
      "required": [
        "days",
        "vials"
      ],
      "description": "Vials or bottles shipped together as one product and used in order.",
      "additionalProperties": {
        "description": "A field that this API version can add. Ignore fields that you do not know."
      }
    },
    "Patient": {
      "type": "object",
      "properties": {
        "address": {
          "$ref": "#/$defs/Address"
        },
        "allergies": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Allergy"
          },
          "description": "The reported allergies; an empty list means no new allergies reported."
        },
        "dateOfBirth": {
          "type": "string",
          "description": "The patient's birth date in YYYY-MM-DD format.",
          "format": "date"
        },
        "email": {
          "type": "string",
          "description": "The patient's email address."
        },
        "firstName": {
          "type": "string",
          "description": "The first name."
        },
        "sex": {
          "type": "string",
          "description": "The patient's sex as sent to the pharmacy.",
          "x-extensible-enum": [
            "female",
            "male",
            "unknown"
          ]
        },
        "lastName": {
          "type": "string",
          "description": "The last name."
        },
        "middleName": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "The patient's middle name, or null when there is none."
        },
        "phone": {
          "type": "string",
          "description": "The contact phone number."
        }
      },
      "required": [
        "address",
        "allergies",
        "dateOfBirth",
        "email",
        "firstName",
        "sex",
        "lastName",
        "middleName",
        "phone"
      ],
      "description": "The patient details saved when the order was signed.",
      "additionalProperties": {
        "description": "A field that this API version can add. Ignore fields that you do not know."
      }
    },
    "PharmacyReference": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^pharm_[0-7][0-9a-hjkmnp-tv-z]{25}$",
          "description": "The public record identifier."
        },
        "name": {
          "type": "string",
          "description": "The name."
        }
      },
      "required": [
        "id",
        "name"
      ],
      "description": "The dispensing pharmacy.",
      "additionalProperties": {
        "description": "A field that this API version can add. Ignore fields that you do not know."
      }
    },
    "Prescription": {
      "type": "object",
      "properties": {
        "compoundingReason": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "The reason for compounding, required when the medication's requirements include it."
        },
        "daysSupply": {
          "type": "integer",
          "minimum": 1,
          "maximum": 365,
          "description": "The number of days the prescribed quantity lasts. Absent when the order sent none."
        },
        "directions": {
          "type": "string",
          "description": "The prescriber's directions for use."
        },
        "id": {
          "type": "string",
          "pattern": "^rx_[0-7][0-9a-hjkmnp-tv-z]{25}$",
          "description": "The public record identifier."
        },
        "pharmacy": {
          "$ref": "#/$defs/PharmacyReference"
        },
        "status": {
          "type": "string",
          "description": "The order's current status; every prescription of the order has the same value.",
          "x-extensible-enum": [
            "awaiting_approval",
            "submitted",
            "processing",
            "shipped",
            "delivered",
            "cancelled",
            "failed"
          ]
        },
        "failureReason": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "Why the order failed, for a person to read; every prescription of the order has the same value. Null unless the order failed; a refused cancel leaves it null."
        },
        "medication": {
          "type": "object",
          "properties": {
            "fill": {
              "anyOf": [
                {
                  "$ref": "#/$defs/Fill"
                },
                {
                  "type": "null"
                }
              ],
              "description": "What the pharmacy dispenses for one price, or null when the complete fill is unknown."
            },
            "form": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "description": "The dosage form, or null when it is unknown."
            },
            "id": {
              "type": "string",
              "pattern": "^med_[0-7][0-9a-hjkmnp-tv-z]{25}$",
              "description": "The public record identifier."
            },
            "kit": {
              "anyOf": [
                {
                  "$ref": "#/$defs/Kit"
                },
                {
                  "type": "null"
                }
              ],
              "description": "The vials or bottles a kit holds, in the order they are used; null for anything that is not a kit."
            },
            "name": {
              "type": "string",
              "description": "The name."
            },
            "quantityUnit": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "description": "The unit used to count the prescribed quantity, or null when it is unknown."
            },
            "strength": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "description": "The pharmacy's strength text, or null when it is unknown."
            }
          },
          "required": [
            "fill",
            "form",
            "id",
            "kit",
            "name",
            "quantityUnit",
            "strength"
          ],
          "description": "The medication details saved when the order was signed.",
          "additionalProperties": {
            "description": "A field that this API version can add. Ignore fields that you do not know."
          }
        },
        "notes": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "The prescriber's additional notes to the pharmacy."
        },
        "price": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991,
          "description": "The prescription's price in integer cents: with a fill, the price per fill times the number of fills."
        },
        "quantity": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991,
          "description": "The prescribed quantity in quantityUnit, not a count of fills. With a fill, it is a whole number of fills in units: two fills of 30 tablets is 60. A vial's unit is vial, so 2 is two vials."
        },
        "refills": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991,
          "description": "The number of authorized refills in addition to the first fill."
        },
        "substitutionPermitted": {
          "type": "boolean",
          "description": "Whether the prescriber permits substitution; defaults to true when omitted."
        }
      },
      "required": [
        "compoundingReason",
        "directions",
        "id",
        "pharmacy",
        "status",
        "failureReason",
        "medication",
        "notes",
        "price",
        "quantity",
        "refills",
        "substitutionPermitted"
      ],
      "additionalProperties": {
        "description": "A field that this API version can add. Ignore fields that you do not know."
      }
    },
    "Shipment": {
      "type": "object",
      "properties": {
        "carrier": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "The carrier name, or null when it is unknown."
        },
        "trackingNumber": {
          "type": "string",
          "description": "The package tracking number."
        },
        "trackingUrl": {
          "anyOf": [
            {
              "type": "string",
              "format": "uri"
            },
            {
              "type": "null"
            }
          ],
          "description": "The carrier's tracking page for this package, or null when the carrier has none."
        }
      },
      "required": [
        "carrier",
        "trackingNumber",
        "trackingUrl"
      ],
      "additionalProperties": {
        "description": "A field that this API version can add. Ignore fields that you do not know."
      }
    },
    "ShippingDestination": {
      "oneOf": [
        {
          "$ref": "#/$defs/ShippingDestinationPatient"
        },
        {
          "$ref": "#/$defs/ShippingDestinationPractice"
        },
        {
          "$ref": "#/$defs/ShippingDestinationAddress"
        }
      ],
      "description": "The shipping destination; defaults to the patient's address when omitted."
    },
    "ShippingDestinationAddress": {
      "type": "object",
      "properties": {
        "type": {
          "$ref": "#/$defs/ShippingDestinationAddressType"
        },
        "address": {
          "$ref": "#/$defs/Address"
        }
      },
      "required": [
        "type",
        "address"
      ],
      "additionalProperties": {
        "description": "A field that this API version can add. Ignore fields that you do not know."
      }
    },
    "ShippingDestinationAddressType": {
      "type": "string",
      "enum": [
        "address"
      ],
      "description": "Use patient, practice or address to select the shipping destination."
    },
    "ShippingDestinationPatient": {
      "type": "object",
      "properties": {
        "type": {
          "$ref": "#/$defs/ShippingDestinationPatientType"
        }
      },
      "required": [
        "type"
      ],
      "additionalProperties": {
        "description": "A field that this API version can add. Ignore fields that you do not know."
      }
    },
    "ShippingDestinationPatientType": {
      "type": "string",
      "enum": [
        "patient"
      ],
      "description": "Use patient, practice or address to select the shipping destination."
    },
    "ShippingDestinationPractice": {
      "type": "object",
      "properties": {
        "type": {
          "$ref": "#/$defs/ShippingDestinationPracticeType"
        }
      },
      "required": [
        "type"
      ],
      "additionalProperties": {
        "description": "A field that this API version can add. Ignore fields that you do not know."
      }
    },
    "ShippingDestinationPracticeType": {
      "type": "string",
      "enum": [
        "practice"
      ],
      "description": "Use patient, practice or address to select the shipping destination."
    },
    "StatusHistoryEntry": {
      "type": "object",
      "properties": {
        "createdAt": {
          "type": "string",
          "description": "When the record was created.",
          "format": "date-time"
        },
        "status": {
          "type": "string",
          "description": "The current fulfillment status.",
          "x-extensible-enum": [
            "awaiting_approval",
            "submitted",
            "processing",
            "shipped",
            "delivered",
            "cancelled",
            "failed"
          ]
        }
      },
      "required": [
        "createdAt",
        "status"
      ],
      "additionalProperties": {
        "description": "A field that this API version can add. Ignore fields that you do not know."
      }
    }
  }
}