{
 "openapi": "3.1.0",
 "info": {
  "title": "CheckWaitingTimes API",
  "version": "1",
  "description": "See the real wait at every hospital near you, NHS and private, and know exactly what to do next. Every response includes provenance (source, source_url, licence, as_of). Data is republished under the Open Government Licence v3.0."
 },
 "servers": [
  {
   "url": "https://checkwaitingtimes.co.uk"
  }
 ],
 "paths": {
  "/api/hospital/{slug}.json": {
   "get": {
    "summary": "One provider's profile: type, ODS address, tags, the hospitals it runs, A&E summary with a 12-month trend, every specialty with the England typical median, shorter waits nearby",
    "parameters": [
     {
      "name": "slug",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Hospital"
        }
       }
      }
     },
     "404": {
      "description": "Unknown slug"
     }
    }
   }
  },
  "/api/hospital/{slug}/{specialty}.json": {
   "get": {
    "summary": "One specialty at one provider",
    "parameters": [
     {
      "name": "slug",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "specialty",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/HospitalSpecialty"
        }
       }
      }
     },
     "404": {
      "description": "Unknown slug"
     }
    }
   }
  },
  "/api/specialty/{specialty}.json": {
   "get": {
    "summary": "National table for one specialty",
    "parameters": [
     {
      "name": "specialty",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Specialty"
        }
       }
      }
     },
     "404": {
      "description": "Unknown slug"
     }
    }
   }
  },
  "/api/area/{area}/{specialty}.json": {
   "get": {
    "summary": "Providers within 25 miles of a council area ranked by the 9 in 10 waiting-now figure (wait_weeks) for one specialty, then distance; providers with fewer than 100 waiting or suppressed are listed unranked",
    "parameters": [
     {
      "name": "area",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "specialty",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AreaSpecialty"
        }
       }
      }
     },
     "404": {
      "description": "Unknown slug"
     }
    }
   }
  },
  "/api/a-and-e/{area}.json": {
   "get": {
    "summary": "A&E departments within 25 miles of a council area, nearest first, with last month's four-hour performance",
    "parameters": [
     {
      "name": "area",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AeArea"
        }
       }
      }
     },
     "404": {
      "description": "Unknown slug"
     }
    }
   }
  },
  "/api/a-and-e/hospital/{slug}.json": {
   "get": {
    "summary": "One A&E department: last month's four-hour performance, the live feed where the trust publishes one, and the ambulance service's response times",
    "parameters": [
     {
      "name": "slug",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AeDepartment"
        }
       }
      }
     },
     "404": {
      "description": "Unknown slug"
     }
    }
   }
  },
  "/api/tests/{test}.json": {
   "get": {
    "summary": "Scan and test waits (DM01) for one test at every provider, with the share waiting over six weeks",
    "parameters": [
     {
      "name": "test",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/DiagnosticTest"
        }
       }
      }
     },
     "404": {
      "description": "Unknown slug"
     }
    }
   }
  },
  "/api/this-month.json": {
   "get": {
    "summary": "What changed in the latest monthly file: England total, trusts whose median wait moved most (improved, worsened) and whose 9 in 10 waiting-now figure moved most (wait_improved, wait_worsened), every specialty",
    "parameters": [],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/ThisMonth"
        }
       }
      }
     },
     "404": {
      "description": "Unknown slug"
     }
    }
   }
  }
 },
 "components": {
  "schemas": {
   "Provenance": {
    "type": "object",
    "required": [
     "source",
     "source_url",
     "licence",
     "as_of"
    ],
    "properties": {
     "source": {
      "type": "string"
     },
     "source_url": {
      "type": "string"
     },
     "licence": {
      "type": "string"
     },
     "as_of": {
      "type": "string",
      "description": "YYYY-MM or YYYY-MM-DD"
     }
    }
   },
   "Band": {
    "type": "object",
    "properties": {
     "total": {
      "type": "integer"
     },
     "median_weeks": {
      "type": "number"
     },
     "p92_weeks": {
      "type": "number"
     }
    }
   },
   "Waiting": {
    "type": "object",
    "properties": {
     "total": {
      "type": "integer"
     },
     "median_weeks": {
      "type": "number"
     },
     "p92_weeks": {
      "type": "number"
     },
     "within_18_weeks": {
      "type": "integer"
     },
     "share_within_18_weeks": {
      "type": "number"
     },
     "over_52_weeks": {
      "type": "integer"
     }
    }
   },
   "SpecialtyAtHospital": {
    "type": "object",
    "properties": {
     "code": {
      "type": "string"
     },
     "slug": {
      "type": "string"
     },
     "name": {
      "type": "string"
     },
     "waiting": {
      "oneOf": [
       {
        "type": "object",
        "properties": {
         "total": {
          "type": "integer"
         },
         "median_weeks": {
          "type": "number"
         },
         "p92_weeks": {
          "type": "number"
         },
         "within_18_weeks": {
          "type": "integer"
         },
         "share_within_18_weeks": {
          "type": "number"
         },
         "over_52_weeks": {
          "type": "integer"
         }
        }
       },
       {
        "type": "null"
       }
      ]
     },
     "completed": {
      "oneOf": [
       {
        "type": "object",
        "properties": {
         "total": {
          "type": "integer"
         },
         "median_weeks": {
          "type": "number"
         },
         "p92_weeks": {
          "type": "number"
         }
        }
       },
       {
        "type": "null"
       }
      ]
     },
     "admitted": {
      "oneOf": [
       {
        "type": "object",
        "properties": {
         "total": {
          "type": "integer"
         },
         "median_weeks": {
          "type": "number"
         },
         "p92_weeks": {
          "type": "number"
         }
        }
       },
       {
        "type": "null"
       }
      ]
     },
     "non_admitted": {
      "oneOf": [
       {
        "type": "object",
        "properties": {
         "total": {
          "type": "integer"
         },
         "median_weeks": {
          "type": "number"
         },
         "p92_weeks": {
          "type": "number"
         }
        }
       },
       {
        "type": "null"
       }
      ]
     },
     "suppressed": {
      "type": "boolean",
      "description": "True when fewer than 20 people were waiting or fewer than 20 were treated for this provider, specialty and month; every band is then null."
     },
     "suppression_reason": {
      "type": [
       "string",
       "null"
      ]
     }
    }
   },
   "Hospital": {
    "type": "object",
    "properties": {
     "provenance": {
      "$ref": "#/components/schemas/Provenance"
     },
     "hospital": {
      "type": "object",
      "description": "code, names, url, type, group, address (ODS), tags, prices_url"
     },
     "sites": {
      "type": "array",
      "items": {
       "type": "object"
      }
     },
     "ae": {
      "oneOf": [
       {
        "type": "object",
        "description": "month, seen_within_4_hours, england_seen_within_4_hours, attendances, departments, trend"
       },
       {
        "type": "null"
       }
      ]
     },
     "total": {
      "type": "object"
     },
     "specialties": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/SpecialtyAtHospital"
      }
     },
     "main_specialty": {
      "type": "object"
     },
     "nearby_shorter_waits": {
      "type": "array",
      "items": {
       "type": "object"
      }
     }
    }
   },
   "PayOrWait": {
    "type": [
     "object",
     "null"
    ],
    "description": "Pay or wait comparison for one procedure: the NHS wait here, a faster NHS option nearby if one exists, and the private guide price and hospitals' own wait claims. Never a recommendation. null when no priced procedure applies.",
    "properties": {
     "procedure": {
      "type": "object",
      "properties": {
       "slug": {
        "type": "string"
       },
       "name": {
        "type": "string"
       }
      }
     },
     "other_procedures": {
      "type": "array",
      "items": {
       "type": "object"
      }
     },
     "nhs_here": {
      "type": "object",
      "description": "hospital, treated_median_weeks, treated_p92_weeks, band, miles, cost, as_of, source"
     },
     "faster_nhs_nearby": {
      "type": [
       "object",
       "null"
      ],
      "description": "Same fields as nhs_here, for a hospital within 25 miles with a median at least 4 weeks shorter"
     },
     "pay_privately": {
      "type": "object",
      "properties": {
       "wait_weeks": {
        "type": [
         "object",
         "null"
        ],
        "properties": {
         "low": {
          "type": "integer"
         },
         "high": {
          "type": "integer"
         }
        }
       },
       "wait_label": {
        "type": "string"
       },
       "wait_checked": {
        "type": "string",
        "format": "date"
       },
       "price_gbp": {
        "type": "object",
        "properties": {
         "low": {
          "type": "integer"
         },
         "typical": {
          "type": "integer"
         },
         "high": {
          "type": "integer"
         }
        }
       },
       "price_label": {
        "type": "string"
       },
       "price_checked": {
        "type": "string",
        "format": "date"
       },
       "sources": {
        "type": "string",
        "format": "uri"
       }
      }
     },
     "weeks_saved": {
      "type": [
       "integer",
       "null"
      ]
     },
     "weeks_saved_rule": {
      "type": "string"
     },
     "line": {
      "type": [
       "object",
       "null"
      ],
      "properties": {
       "rule": {
        "type": "string"
       },
       "text": {
        "type": "string"
       }
      }
     },
     "provenance": {
      "type": "object"
     }
    }
   },
   "HospitalSpecialty": {
    "type": "object",
    "properties": {
     "provenance": {
      "$ref": "#/components/schemas/Provenance"
     },
     "hospital": {
      "type": "object"
     },
     "specialty": {
      "type": "object"
     },
     "waiting": {
      "oneOf": [
       {
        "type": "object",
        "properties": {
         "total": {
          "type": "integer"
         },
         "median_weeks": {
          "type": "number"
         },
         "p92_weeks": {
          "type": "number"
         },
         "within_18_weeks": {
          "type": "integer"
         },
         "share_within_18_weeks": {
          "type": "number"
         },
         "over_52_weeks": {
          "type": "integer"
         }
        }
       },
       {
        "type": "null"
       }
      ]
     },
     "completed": {
      "oneOf": [
       {
        "type": "object",
        "properties": {
         "total": {
          "type": "integer"
         },
         "median_weeks": {
          "type": "number"
         },
         "p92_weeks": {
          "type": "number"
         }
        }
       },
       {
        "type": "null"
       }
      ]
     },
     "suppressed": {
      "type": "boolean",
      "description": "True when fewer than 20 people were waiting or fewer than 20 were treated for this provider, specialty and month; every band is then null."
     },
     "suppression_reason": {
      "type": [
       "string",
       "null"
      ]
     },
     "pay_or_wait": {
      "$ref": "#/components/schemas/PayOrWait"
     }
    }
   },
   "Specialty": {
    "type": "object",
    "properties": {
     "provenance": {
      "$ref": "#/components/schemas/Provenance"
     },
     "specialty": {
      "type": "object"
     },
     "hospitals": {
      "type": "array",
      "items": {
       "type": "object"
      }
     }
    }
   },
   "AreaSpecialty": {
    "type": "object",
    "properties": {
     "provenance": {
      "$ref": "#/components/schemas/Provenance"
     },
     "area": {
      "type": "object"
     },
     "specialty": {
      "type": "object"
     },
     "radius_miles": {
      "type": "integer"
     },
     "ranked": {
      "type": "array",
      "items": {
       "type": "object"
      }
     },
     "unranked": {
      "type": "array",
      "items": {
       "type": "object"
      }
     }
    }
   },
   "AeArea": {
    "type": "object",
    "properties": {
     "provenance": {
      "$ref": "#/components/schemas/Provenance"
     },
     "area": {
      "type": "object"
     },
     "live_feed": {
      "type": [
       "string",
       "null"
      ]
     },
     "departments": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "name": {
         "type": "string"
        },
        "miles": {
         "type": "number"
        },
        "attendances": {
         "type": "integer"
        },
        "share_within_4_hours": {
         "type": [
          "number",
          "null"
         ],
         "description": "null when withheld (under 100 visits)"
        },
        "publishes_live_waits": {
         "type": "boolean"
        }
       }
      }
     }
    }
   },
   "AeDepartment": {
    "type": "object",
    "properties": {
     "provenance": {
      "$ref": "#/components/schemas/Provenance"
     },
     "department": {
      "type": "object"
     },
     "month": {
      "type": "object"
     },
     "live": {
      "type": [
       "object",
       "null"
      ]
     },
     "ambulance": {
      "type": [
       "object",
       "null"
      ]
     }
    }
   },
   "DiagnosticTest": {
    "type": "object",
    "properties": {
     "provenance": {
      "$ref": "#/components/schemas/Provenance"
     },
     "test": {
      "type": "object"
     },
     "england": {
      "type": "object"
     },
     "providers": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "waiting": {
         "type": "integer"
        },
        "over_6_weeks": {
         "type": "integer"
        },
        "share_over_6_weeks": {
         "type": "number"
        },
        "tests_in_month": {
         "type": "integer"
        }
       }
      }
     }
    }
   },
   "ThisMonth": {
    "type": "object",
    "properties": {
     "provenance": {
      "$ref": "#/components/schemas/Provenance"
     },
     "next_release": {
      "type": "string"
     },
     "england": {
      "type": "object"
     },
     "improved": {
      "type": "array",
      "items": {
       "type": "object"
      }
     },
     "worsened": {
      "type": "array",
      "items": {
       "type": "object"
      }
     },
     "specialties": {
      "type": "array",
      "items": {
       "type": "object"
      }
     },
     "wait_measure": {
      "type": "string"
     },
     "wait_trusts_compared": {
      "type": "integer"
     },
     "wait_improved": {
      "type": "array",
      "items": {
       "type": "object"
      }
     },
     "wait_worsened": {
      "type": "array",
      "items": {
       "type": "object"
      }
     }
    }
   }
  }
 }
}