{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/propagator-health/json-schema/propagator-health-invoice-schema.json",
  "title": "Invoice",
  "description": "Canonical financial invoice. Supported by Gensolve, Cliniko, Nookal, Halaxy (limited). Note: unlike the other response models, the fields marked nullable here are returned as an explicit null when the PMS has no value, rather than being omitted — consumers may test for null. `id` is the exception: it is always present.",
  "x-generated": "2026-12-02",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/propagator-health-openapi.json#/components/schemas/Invoice",
  "type": "object",
  "required": [
    "id"
  ],
  "properties": {
    "id": {
      "type": "string"
    },
    "patientId": {
      "type": [
        "string",
        "null"
      ]
    },
    "locationId": {
      "type": [
        "string",
        "null"
      ]
    },
    "appointmentId": {
      "type": [
        "string",
        "null"
      ]
    },
    "practitionerId": {
      "type": [
        "string",
        "null"
      ]
    },
    "invoiceIdNumeric": {
      "type": "number",
      "description": "Nookal/others numeric invoice id when API uses number"
    },
    "invoiceNumber": {
      "type": [
        "string",
        "null"
      ]
    },
    "date": {
      "type": [
        "string",
        "null"
      ],
      "format": "date"
    },
    "dueDate": {
      "type": [
        "string",
        "null"
      ],
      "format": "date"
    },
    "total": {
      "type": "number"
    },
    "subtotal": {
      "type": "number"
    },
    "tax": {
      "type": "number"
    },
    "balance": {
      "type": "number"
    },
    "amountPaid": {
      "type": "number"
    },
    "discountedAmount": {
      "type": "number"
    },
    "status": {
      "type": [
        "string",
        "null"
      ]
    },
    "statusCode": {
      "type": "number",
      "description": "Cliniko 10=Open 20=Paid 30=Closed 40=Open credit"
    },
    "entries": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/InvoiceLineItem"
      }
    },
    "createdAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "updatedAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "closedAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "archivedAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "notes": {
      "type": [
        "string",
        "null"
      ]
    },
    "invoiceTo": {
      "type": [
        "string",
        "null"
      ]
    },
    "calculationMethod": {
      "type": "number"
    },
    "calculationMethodDescription": {
      "type": [
        "string",
        "null"
      ]
    },
    "onlinePaymentUrl": {
      "type": [
        "string",
        "null"
      ],
      "format": "uri"
    },
    "note": {
      "type": [
        "string",
        "null"
      ]
    }
  },
  "$defs": {
    "InvoiceLineItem": {
      "type": "object",
      "description": "Canonical invoice line item (single charge/entry). Supports Cliniko invoice_items, FHIR Invoice.lineItem, Nookal/Elixir line items. No property is ever null — unavailable values are omitted. This differs from the parent Invoice, several of whose fields ARE explicitly null.",
      "properties": {
        "id": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "code": {
          "type": "string"
        },
        "quantity": {
          "type": "number"
        },
        "unitPrice": {
          "type": "number"
        },
        "amount": {
          "type": "number"
        },
        "totalIncludingTax": {
          "type": "number"
        },
        "tax": {
          "type": "number"
        },
        "taxRate": {
          "type": "number"
        },
        "taxName": {
          "type": "string"
        },
        "serviceId": {
          "type": "string"
        },
        "chargeItemId": {
          "type": "string"
        },
        "productId": {
          "type": "string"
        },
        "sequence": {
          "type": "number"
        },
        "servicedDate": {
          "type": "string",
          "format": "date"
        },
        "servicedPeriodStart": {
          "type": "string",
          "format": "date-time"
        },
        "servicedPeriodEnd": {
          "type": "string",
          "format": "date-time"
        },
        "discountPercentage": {
          "type": "number"
        },
        "discountedAmount": {
          "type": "number"
        },
        "isMonetaryDiscount": {
          "type": "boolean"
        },
        "concessionTypeName": {
          "type": "string"
        },
        "createdAt": {
          "type": "string",
          "format": "date-time"
        },
        "updatedAt": {
          "type": "string",
          "format": "date-time"
        }
      }
    }
  }
}