{
  "openapi": "3.1.0",
  "info": {
    "title": "Pieraksts — Latvia Medical Availability",
    "version": "1.0.0",
    "description": "Public read-only observations, no credentials. Partial source coverage; no bookings, private subscriptions or notification dispatch. Slot results are future observations at most 2 hours old, not reservations. Always cite source url and last_seen. State contracts and insurance conditions do not confirm an appointment or payment. Empty results do not prove no availability. Poll the same query at most hourly; reads do not trigger collection. Source rights remain with their owners."
  },
  "servers": [
    {
      "url": "https://latvia-med-monitor.pantropov.chatgpt.site"
    }
  ],
  "security": [],
  "externalDocs": {
    "url": "https://latvia-med-monitor.pantropov.chatgpt.site/agents"
  },
  "paths": {
    "/api/v1/availability": {
      "get": {
        "operationId": "searchAvailability",
        "summary": "Search future observed slots or public catalog data",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": false,
            "description": "Doctor, specialty or procedure; LV/RU/EN, common typos and transliteration",
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          },
          {
            "name": "doctor_id",
            "in": "query",
            "required": false,
            "description": "Exact source/provider-scoped ID from the doctor directory",
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          },
          {
            "name": "funding",
            "in": "query",
            "required": false,
            "description": "State/self pay/unknown; insurance must be checked with the source",
            "schema": {
              "type": "string",
              "enum": [
                "",
                "state",
                "self_pay",
                "unknown"
              ],
              "default": ""
            }
          },
          {
            "name": "kind",
            "in": "query",
            "required": false,
            "description": "slot means observed availability; catalog and coverage are not appointments",
            "schema": {
              "type": "string",
              "enum": [
                "slot",
                "catalog",
                "coverage",
                ""
              ],
              "default": "slot"
            }
          },
          {
            "name": "page",
            "in": "query",
            "required": false,
            "description": "Zero-based; follow next_page",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 10000,
              "default": 0
            }
          },
          {
            "name": "days",
            "in": "query",
            "required": false,
            "description": "Rolling future horizon; omit for any date",
            "schema": {
              "type": "integer",
              "enum": [
                1,
                3,
                7,
                14,
                30
              ]
            }
          },
          {
            "name": "period",
            "in": "query",
            "required": false,
            "description": "Europe/Riga; evening means today after 17:00",
            "schema": {
              "type": "string",
              "enum": [
                "any",
                "today",
                "evening"
              ]
            }
          },
          {
            "name": "excludeRemote",
            "in": "query",
            "required": false,
            "description": "Exclude explicitly remote appointments; unknown formats remain visible and labelled. A postal address alone does not prove in-person mode.",
            "schema": {
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Public observations with partial coverage and per-record timestamps",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AvailabilityResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid query; correct it before retrying",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "searchAvailabilityByLocation",
        "summary": "Read-only search with optional location in JSON body",
        "x-openai-isConsequential": false,
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Search"
              },
              "example": {
                "q": "Psihiatrs",
                "availability": {
                  "days": 3,
                  "area": {
                    "lat": 56.949,
                    "lon": 24.105,
                    "radiusKm": 30,
                    "label": "Rīga"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Public observations with partial coverage and per-record timestamps",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AvailabilityResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid query; correct it before retrying",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/doctors": {
      "get": {
        "operationId": "findDoctors",
        "summary": "Find public profiles and exact IDs",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": false,
            "description": "Doctor, specialty or procedure; LV/RU/EN, common typos and transliteration",
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          },
          {
            "name": "page",
            "in": "query",
            "required": false,
            "description": "Zero-based; follow next_page",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 10000,
              "default": 0
            }
          },
          {
            "name": "available",
            "in": "query",
            "required": false,
            "description": "1 limits profiles to those with fresh observed slots",
            "schema": {
              "type": "string",
              "enum": [
                "0",
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Public observations with partial coverage and per-record timestamps",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DoctorsResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid query; correct it before retrying",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/doctors/{id}": {
      "get": {
        "operationId": "getDoctorProfile",
        "summary": "Read a source-scoped doctor profile",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Public observations with partial coverage and per-record timestamps",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DoctorResult"
                }
              }
            }
          },
          "404": {
            "description": "Unknown source-scoped profile ID"
          }
        }
      }
    },
    "/api/v1/sources": {
      "get": {
        "operationId": "getSourceHealth",
        "summary": "Check failures, freshness and partial coverage",
        "responses": {
          "200": {
            "description": "Public observations with partial coverage and per-record timestamps",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SourcesResult"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Area": {
        "type": "object",
        "required": [
          "lat",
          "lon",
          "radiusKm"
        ],
        "properties": {
          "lat": {
            "type": "number",
            "minimum": 55,
            "maximum": 59
          },
          "lon": {
            "type": "number",
            "minimum": 20,
            "maximum": 29
          },
          "radiusKm": {
            "type": "number",
            "minimum": 1,
            "maximum": 300
          },
          "label": {
            "type": "string",
            "maxLength": 100
          }
        },
        "description": "Explicitly chosen point; straight-line distance, rounded to 3 decimal places. Unknown clinic coordinates are excluded."
      },
      "AvailabilityFilters": {
        "type": "object",
        "properties": {
          "excludeRemote": {
            "type": "boolean"
          },
          "area": {
            "$ref": "#/components/schemas/Area"
          },
          "days": {
            "type": "integer",
            "enum": [
              1,
              3,
              7,
              14,
              30
            ]
          },
          "period": {
            "type": "string",
            "enum": [
              "any",
              "today",
              "evening"
            ]
          }
        }
      },
      "Search": {
        "type": "object",
        "properties": {
          "q": {
            "type": "string",
            "maxLength": 200
          },
          "doctor_id": {
            "type": "string",
            "maxLength": 200
          },
          "funding": {
            "type": "string",
            "enum": [
              "",
              "state",
              "self_pay",
              "unknown"
            ],
            "default": ""
          },
          "kind": {
            "type": "string",
            "enum": [
              "slot",
              "catalog",
              "coverage",
              ""
            ],
            "default": "slot"
          },
          "page": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10000,
            "default": 0
          },
          "availability": {
            "$ref": "#/components/schemas/AvailabilityFilters"
          }
        }
      },
      "Observation": {
        "type": "object",
        "required": [
          "id",
          "source_id",
          "kind",
          "title",
          "url",
          "funding",
          "status",
          "last_seen"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "source_id": {
            "type": "string"
          },
          "person_id": {
            "type": "string"
          },
          "person_name": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "enum": [
              "slot",
              "catalog",
              "coverage"
            ]
          },
          "title": {
            "type": "string"
          },
          "provider": {
            "type": "string"
          },
          "specialty": {
            "type": "string"
          },
          "address": {
            "type": "string"
          },
          "city": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "profile_url": {
            "type": "string",
            "format": "uri"
          },
          "funding": {
            "type": "string",
            "enum": [
              "",
              "state",
              "self_pay",
              "unknown"
            ],
            "default": ""
          },
          "status": {
            "type": "string"
          },
          "starts_at": {
            "type": "string",
            "format": "date-time"
          },
          "last_seen": {
            "type": "string",
            "format": "date-time"
          },
          "detail": {
            "type": "string"
          },
          "consultation_mode": {
            "type": "string",
            "enum": [
              "in_person",
              "remote",
              "unknown"
            ]
          },
          "distance_km": {
            "type": "number"
          },
          "latitude": {
            "type": "number"
          },
          "longitude": {
            "type": "number"
          },
          "location_precision": {
            "type": "string"
          }
        }
      },
      "Source": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "category": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "checked_at": {
            "type": "string",
            "format": "date-time"
          },
          "last_success": {
            "type": "string",
            "format": "date-time"
          },
          "every_hours": {
            "type": "number"
          },
          "note": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "name",
          "url",
          "status"
        ]
      },
      "Doctor": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "provider": {
            "type": "string"
          },
          "city": {
            "type": "string"
          },
          "address": {
            "type": "string"
          },
          "specialties": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "source_id": {
            "type": "string"
          },
          "source_name": {
            "type": "string"
          },
          "source_url": {
            "type": "string",
            "format": "uri"
          },
          "profile_url": {
            "type": "string",
            "format": "uri"
          },
          "identity_scope": {
            "type": "string"
          },
          "last_seen": {
            "type": "string",
            "format": "date-time"
          },
          "has_state_contract": {
            "type": "boolean"
          },
          "fresh_slots": {
            "type": "integer"
          },
          "stale_slots": {
            "type": "integer"
          },
          "next_slot": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "name",
          "source_id",
          "profile_url",
          "fresh_slots"
        ]
      },
      "AvailabilityResult": {
        "type": "object",
        "properties": {
          "api_version": {
            "type": "string"
          },
          "snapshot_generated_at": {
            "type": "string",
            "format": "date-time"
          },
          "served_at": {
            "type": "string",
            "format": "date-time"
          },
          "timezone": {
            "type": "string",
            "const": "Europe/Riga"
          },
          "freshness_window_seconds": {
            "type": "integer"
          },
          "coverage": {
            "type": "string",
            "const": "partial"
          },
          "booking_supported": {
            "type": "boolean",
            "const": false
          },
          "payment_confirmation": {
            "type": "string"
          },
          "empty_result_meaning": {
            "type": "string"
          },
          "total": {
            "type": "integer"
          },
          "page": {
            "type": "integer"
          },
          "page_size": {
            "type": "integer"
          },
          "next_page": {
            "type": [
              "integer",
              "null"
            ]
          },
          "records": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Observation"
            }
          },
          "unknown_location": {
            "type": "integer"
          },
          "unknown_modality": {
            "type": "integer"
          },
          "matching_sources": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Source"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Source"
            }
          }
        },
        "required": [
          "records",
          "total",
          "page",
          "page_size",
          "next_page",
          "snapshot_generated_at",
          "sources"
        ]
      },
      "DoctorsResult": {
        "type": "object",
        "properties": {
          "api_version": {
            "type": "string"
          },
          "snapshot_generated_at": {
            "type": "string",
            "format": "date-time"
          },
          "served_at": {
            "type": "string",
            "format": "date-time"
          },
          "timezone": {
            "type": "string",
            "const": "Europe/Riga"
          },
          "freshness_window_seconds": {
            "type": "integer"
          },
          "coverage": {
            "type": "string",
            "const": "partial"
          },
          "booking_supported": {
            "type": "boolean",
            "const": false
          },
          "payment_confirmation": {
            "type": "string"
          },
          "empty_result_meaning": {
            "type": "string"
          },
          "total": {
            "type": "integer"
          },
          "page": {
            "type": "integer"
          },
          "page_size": {
            "type": "integer"
          },
          "next_page": {
            "type": [
              "integer",
              "null"
            ]
          },
          "doctors": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Doctor"
            }
          },
          "all_profiles": {
            "type": "integer"
          }
        },
        "required": [
          "doctors",
          "total",
          "page",
          "next_page"
        ]
      },
      "DoctorResult": {
        "type": "object",
        "properties": {
          "api_version": {
            "type": "string"
          },
          "snapshot_generated_at": {
            "type": "string",
            "format": "date-time"
          },
          "served_at": {
            "type": "string",
            "format": "date-time"
          },
          "timezone": {
            "type": "string",
            "const": "Europe/Riga"
          },
          "freshness_window_seconds": {
            "type": "integer"
          },
          "coverage": {
            "type": "string",
            "const": "partial"
          },
          "booking_supported": {
            "type": "boolean",
            "const": false
          },
          "payment_confirmation": {
            "type": "string"
          },
          "empty_result_meaning": {
            "type": "string"
          },
          "doctor": {
            "$ref": "#/components/schemas/Doctor"
          },
          "availability_url": {
            "type": "string",
            "format": "uri"
          },
          "identity_note": {
            "type": "string"
          }
        },
        "required": [
          "doctor",
          "availability_url"
        ]
      },
      "SourcesResult": {
        "type": "object",
        "properties": {
          "api_version": {
            "type": "string"
          },
          "snapshot_generated_at": {
            "type": "string",
            "format": "date-time"
          },
          "served_at": {
            "type": "string",
            "format": "date-time"
          },
          "timezone": {
            "type": "string",
            "const": "Europe/Riga"
          },
          "freshness_window_seconds": {
            "type": "integer"
          },
          "coverage": {
            "type": "string",
            "const": "partial"
          },
          "booking_supported": {
            "type": "boolean",
            "const": false
          },
          "payment_confirmation": {
            "type": "string"
          },
          "empty_result_meaning": {
            "type": "string"
          },
          "sources": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Source"
            }
          }
        },
        "required": [
          "sources",
          "snapshot_generated_at"
        ]
      }
    }
  }
}
