{
  "openapi": "3.1.0",
  "info": {
    "title": "rt-PA Stroke Dose Calculation & Protocol API (ED-MNRH)",
    "description": "Public clinical decision support API for acute ischemic stroke intravenous rt-PA (Alteplase) dosage calculations and standing order protocols at Maharat Nakhon Ratchasima Hospital (โรงพยาบาลมหาราชนครราชสีมา).",
    "version": "1.0.0",
    "contact": {
      "name": "Emergency Department, Maharat Nakhon Ratchasima Hospital",
      "url": "https://rtpamnrh.vercel.app"
    },
    "license": {
      "name": "MIT"
    }
  },
  "servers": [
    {
      "url": "https://rtpamnrh.vercel.app",
      "description": "Production Server"
    }
  ],
  "paths": {
    "/api/calculate": {
      "get": {
        "summary": "Calculate rt-PA dose via query parameters",
        "description": "Calculates total dose, IV push (bolus), and IV drip based on patient weight and dosage regimen.",
        "operationId": "calculateRtpaDoseGet",
        "parameters": [
          {
            "name": "weight",
            "in": "query",
            "required": true,
            "description": "Patient weight in kilograms (kg), e.g., 70.5",
            "schema": {
              "type": "number",
              "minimum": 10,
              "maximum": 250
            }
          },
          {
            "name": "regimen",
            "in": "query",
            "required": false,
            "description": "Dosing regimen: 0.9 for standard AHA/ASA dose (max 90mg) or 0.6 for ENCHANTED low-dose (max 60mg). Default is 0.9.",
            "schema": {
              "type": "number",
              "enum": [0.9, 0.6],
              "default": 0.9
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful calculation result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DoseCalculationResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input parameters",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Calculate rt-PA dose via JSON payload",
        "description": "Calculates total dose, IV push (bolus), and IV drip based on patient weight and dosage regimen.",
        "operationId": "calculateRtpaDosePost",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["weight"],
                "properties": {
                  "weight": {
                    "type": "number",
                    "minimum": 10,
                    "maximum": 250,
                    "description": "Patient weight in kilograms (kg)"
                  },
                  "regimen": {
                    "type": "number",
                    "enum": [0.9, 0.6],
                    "default": 0.9,
                    "description": "0.9 for standard dose (0.9 mg/kg, max 90mg) or 0.6 for low-dose (0.6 mg/kg, max 60mg)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful calculation result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DoseCalculationResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input parameters",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/protocols": {
      "get": {
        "summary": "Get stroke clinical protocols and regimens",
        "description": "Returns standard and low-dose rt-PA administration guidelines, Door-to-Needle timeline targets (<= 45 min), and standing order page metadata.",
        "operationId": "getStrokeProtocols",
        "responses": {
          "200": {
            "description": "Clinical protocols documentation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProtocolsResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/health": {
      "get": {
        "summary": "API health check and capabilities",
        "description": "Returns service status, version, and agent discovery links.",
        "operationId": "getHealthStatus",
        "responses": {
          "200": {
            "description": "System health status",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "DoseCalculationResult": {
        "type": "object",
        "required": ["patientWeight", "regimen", "totalDose", "pushDose", "dripDose", "pushPercent", "dripPercent", "maxDoseCap", "units", "administration", "clinicalGuideline"],
        "properties": {
          "patientWeight": {
            "type": "number",
            "example": 70.0
          },
          "regimen": {
            "type": "number",
            "example": 0.9
          },
          "totalDose": {
            "type": "number",
            "example": 63.0
          },
          "pushDose": {
            "type": "number",
            "example": 6.3
          },
          "dripDose": {
            "type": "number",
            "example": 56.7
          },
          "pushPercent": {
            "type": "integer",
            "example": 10
          },
          "dripPercent": {
            "type": "integer",
            "example": 90
          },
          "maxDoseCap": {
            "type": "number",
            "example": 90
          },
          "units": {
            "type": "string",
            "example": "mg"
          },
          "administration": {
            "type": "object",
            "required": ["push", "drip"],
            "properties": {
              "push": {
                "type": "string",
                "example": "IV push over 1 minute (10% of total dose)"
              },
              "drip": {
                "type": "string",
                "example": "IV drip over 60 minutes (90% of total dose)"
              }
            }
          },
          "clinicalGuideline": {
            "type": "string",
            "example": "AHA/ASA Early Management of Acute Ischemic Stroke Guideline"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["error", "message", "code"],
        "properties": {
          "error": {
            "type": "string",
            "example": "Bad Request"
          },
          "message": {
            "type": "string",
            "example": "Invalid weight: must be a positive number between 10 and 250 kg"
          },
          "code": {
            "type": "string",
            "example": "INVALID_WEIGHT"
          }
        }
      },
      "ProtocolsResponse": {
        "type": "object",
        "required": ["hospital", "department", "drug", "regimens", "timelineBenchmarks", "orderPages"],
        "properties": {
          "hospital": {
            "type": "string",
            "example": "Maharat Nakhon Ratchasima Hospital (โรงพยาบาลมหาราชนครราชสีมา)"
          },
          "department": {
            "type": "string",
            "example": "Emergency Medicine (ED-MNRH) & Stroke Fast Track"
          },
          "drug": {
            "type": "object",
            "required": ["genericName", "brandName", "rxNormCode", "snomedConcept"],
            "properties": {
              "genericName": {
                "type": "string",
                "example": "Alteplase (recombinant tissue plasminogen activator / rt-PA)"
              },
              "brandName": {
                "type": "string",
                "example": "Actilyse"
              },
              "rxNormCode": {
                "type": "string",
                "example": "8410"
              },
              "snomedConcept": {
                "type": "string",
                "example": "387463004"
              }
            }
          },
          "regimens": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["name", "doseMultiplier", "units", "maxDose", "maxDoseUnits", "pushRatio", "pushPercent", "pushDuration", "dripRatio", "dripPercent", "dripDuration"],
              "properties": {
                "name": {
                  "type": "string",
                  "example": "Standard Dose (AHA/ASA Guideline)"
                },
                "doseMultiplier": {
                  "type": "number",
                  "example": 0.9
                },
                "units": {
                  "type": "string",
                  "example": "mg/kg"
                },
                "maxDose": {
                  "type": "number",
                  "example": 90
                },
                "maxDoseUnits": {
                  "type": "string",
                  "example": "mg"
                },
                "pushRatio": {
                  "type": "number",
                  "example": 0.1
                },
                "pushPercent": {
                  "type": "integer",
                  "example": 10
                },
                "pushDuration": {
                  "type": "string",
                  "example": "1 minute"
                },
                "dripRatio": {
                  "type": "number",
                  "example": 0.9
                },
                "dripPercent": {
                  "type": "integer",
                  "example": 90
                },
                "dripDuration": {
                  "type": "string",
                  "example": "60 minutes"
                }
              }
            }
          },
          "timelineBenchmarks": {
            "type": "object",
            "required": ["doorToDoctor", "doorToCtScan", "doorToCtInterpretation", "doorToNeedle"],
            "properties": {
              "doorToDoctor": {
                "type": "string",
                "example": "<= 10 minutes"
              },
              "doorToCtScan": {
                "type": "string",
                "example": "<= 25 minutes"
              },
              "doorToCtInterpretation": {
                "type": "string",
                "example": "<= 45 minutes"
              },
              "doorToNeedle": {
                "type": "string",
                "example": "<= 45 minutes (standard AHA/ASA target <= 60 minutes)"
              }
            }
          },
          "orderPages": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["page", "title"],
              "properties": {
                "page": {
                  "type": "integer",
                  "example": 1
                },
                "title": {
                  "type": "string",
                  "example": "Doctor Order & Progress Note (Dose + Pharmacist monitoring + Post-admit continuation)"
                }
              }
            }
          }
        }
      },
      "HealthResponse": {
        "type": "object",
        "required": ["status", "service", "hospital", "version", "uptime", "timestamp", "agentCapabilities"],
        "properties": {
          "status": {
            "type": "string",
            "example": "ok"
          },
          "service": {
            "type": "string",
            "example": "rt-PA Standing Order Generator (ED-MNRH)"
          },
          "hospital": {
            "type": "string",
            "example": "Maharat Nakhon Ratchasima Hospital"
          },
          "version": {
            "type": "string",
            "example": "1.0.0"
          },
          "uptime": {
            "type": "number",
            "example": 123.45
          },
          "timestamp": {
            "type": "string",
            "format": "date-time",
            "example": "2026-03-31T04:30:00.000Z"
          },
          "agentCapabilities": {
            "type": "object",
            "required": ["openapiSpec", "llmsGuide", "calculateEndpoint", "protocolsEndpoint", "sitemap", "agentMode"],
            "properties": {
              "openapiSpec": {
                "type": "string",
                "example": "/openapi.json"
              },
              "llmsGuide": {
                "type": "string",
                "example": "/llms.txt"
              },
              "calculateEndpoint": {
                "type": "string",
                "example": "/api/calculate"
              },
              "protocolsEndpoint": {
                "type": "string",
                "example": "/api/protocols"
              },
              "sitemap": {
                "type": "string",
                "example": "/sitemap.xml"
              },
              "agentMode": {
                "type": "string",
                "example": "/?mode=agent"
              }
            }
          }
        }
      }
    }
  }
}
