{
  "openapi": "3.1.0",
  "info": {
    "title": "MyRX Dosage Recommendation API",
    "description": "Batch dosage recommendation API",
    "version": "1.0.0"
  },
  "paths": {
    "/api/v1/drugs/dosage/prefetch": {
      "post": {
        "summary": "Prefetch Medicines",
        "description": "Prefetch medicines: checks DB and triggers Gemini lookup for unknown medicines\nin the background. Returns 204 immediately.\n\nCall this as soon as medicine names are available, then call\n/recommendation to get the full response.",
        "operationId": "prefetch_medicines_api_v1_drugs_dosage_prefetch_post",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PrefetchRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "204": {
            "description": "Successful Response"
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/drugs/dosage/recommendation": {
      "post": {
        "summary": "Get Batch Dosage Recommendation",
        "description": "BATCH Dosage Recommendation API\n\nQuery Parameters:\n- include_metadata: include validation warnings, confidence scores, metadata\n- include_details: include extended medical info (benefits, side_effects, safety_advice,\n  allergens, interactions, age_group_dosages)\n- ai_enhanced: enable Gemini AI fallback for low-confidence extractions",
        "operationId": "get_batch_dosage_recommendation_api_v1_drugs_dosage_recommendation_post",
        "parameters": [
          {
            "name": "include_metadata",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean",
              "default": false,
              "title": "Include Metadata"
            }
          },
          {
            "name": "include_details",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean",
              "default": false,
              "title": "Include Details"
            }
          },
          {
            "name": "ai_enhanced",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean",
              "default": false,
              "title": "Ai Enhanced"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BatchDosageRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/drugs/dosage/health": {
      "get": {
        "summary": "Health Check",
        "description": "Check database connectivity",
        "operationId": "health_check_api_v1_drugs_dosage_health_get",
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          }
        }
      }
    },
    "/api/v1/drugs/search": {
      "get": {
        "summary": "Search Medicines",
        "description": "Autosuggest API: search medicines by product_name. Returns up to `limit` results, prioritising prefix matches over partial matches.",
        "operationId": "search_medicines_api_v1_drugs_search_get",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "title": "Q",
              "description": "Search query for product name"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 10,
              "minimum": 1,
              "maximum": 50,
              "title": "Limit"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SearchResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/": {
      "get": {
        "summary": "Root",
        "description": "Health check",
        "operationId": "root__get",
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "BatchDosageRequest": {
        "properties": {
          "age": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Age"
          },
          "gender": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Gender"
          },
          "medications": {
            "items": {
              "type": "string"
            },
            "type": "array",
            "title": "Medications"
          }
        },
        "type": "object",
        "required": [
          "medications"
        ],
        "title": "BatchDosageRequest",
        "description": "Request model for batch dosage recommendations"
      },
      "HTTPValidationError": {
        "properties": {
          "detail": {
            "items": {
              "$ref": "#/components/schemas/ValidationError"
            },
            "type": "array",
            "title": "Detail"
          }
        },
        "type": "object",
        "title": "HTTPValidationError"
      },
      "PrefetchRequest": {
        "properties": {
          "medications": {
            "items": {
              "type": "string"
            },
            "type": "array",
            "title": "Medications"
          }
        },
        "type": "object",
        "required": [
          "medications"
        ],
        "title": "PrefetchRequest",
        "description": "Request model for medicine prefetch"
      },
      "SearchItem": {
        "properties": {
          "id": {
            "type": "integer",
            "title": "Id"
          },
          "name": {
            "type": "string",
            "title": "Name"
          },
          "composition": {
            "type": "string",
            "title": "Composition"
          },
          "category": {
            "type": "string",
            "title": "Category",
            "description": "Product form (e.g., Tablet, Capsule, Syrup)"
          },
          "dosage": {
            "type": "string",
            "title": "Dosage",
            "description": "Frequency code: OD, BD, TDS, QDS"
          },
          "frequency": {
            "type": "string",
            "title": "Frequency",
            "description": "Human readable frequency (e.g., Twice daily)"
          },
          "dose_schedule": {
            "type": "string",
            "title": "Dose Schedule",
            "description": "Morning-Afternoon-Night schedule (e.g., 1-0-1)"
          },
          "preference": {
            "type": "string",
            "title": "Preference",
            "description": "Meal preference (e.g., After Meal, Empty Stomach)"
          }
        },
        "type": "object",
        "required": ["id", "name", "composition", "category", "dosage", "frequency", "dose_schedule", "preference"],
        "title": "SearchItem"
      },
      "SearchResponse": {
        "properties": {
          "data": {
            "items": {
              "$ref": "#/components/schemas/SearchItem"
            },
            "type": "array",
            "title": "Data"
          },
          "error": {
            "anyOf": [
              {
                "type": "object"
              },
              {
                "type": "null"
              }
            ],
            "title": "Error"
          }
        },
        "type": "object",
        "required": ["data", "error"],
        "title": "SearchResponse"
      },
      "ValidationError": {
        "properties": {
          "loc": {
            "items": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "integer"
                }
              ]
            },
            "type": "array",
            "title": "Location"
          },
          "msg": {
            "type": "string",
            "title": "Message"
          },
          "type": {
            "type": "string",
            "title": "Error Type"
          }
        },
        "type": "object",
        "required": [
          "loc",
          "msg",
          "type"
        ],
        "title": "ValidationError"
      }
    }
  }
}