"""# Summary Treatments route handlers — names must match openapi.yaml operationIds. Notes: ``list_treatments`` returns a plain array (the catalogue is small and unpaginated by contract). """ from fastapi import Request, Response from interfaces._common import delete_or_404, dump, read_or_404, svc async def list_treatments(request: Request) -> list[dict]: """List treatments (catalogue, unpaginated). Args: request (Request): Incoming request. Returns: list[dict]: All treatment documents. """ docs = await svc(request, "treatment").search({}) return [dump(d) for d in docs] async def create_treatment(request: Request, body: dict, response: Response) -> dict: """Add a treatment (admin only). Args: request (Request): Incoming request. body (dict): Treatment fields (``id`` ignored). response (Response): Response object; set to 201 on success. Returns: dict: The created treatment. """ response.status_code = 201 body.pop("id", None) doc = await svc(request, "treatment").create(body) return dump(doc) async def get_treatment(request: Request, id: int) -> dict: """Fetch one treatment by id. Args: request (Request): Incoming request. id (int): Treatment identifier. Returns: dict: The treatment document. Raises: HTTPException: 404 when the treatment does not exist. """ return dump(await read_or_404(svc(request, "treatment"), id, "treatment")) async def update_treatment(request: Request, id: int, body: dict) -> dict: """Replace a treatment by id. Args: request (Request): Incoming request. id (int): Treatment identifier. body (dict): Full replacement payload. Returns: dict: The updated treatment. Raises: HTTPException: 404 when the treatment does not exist. """ await read_or_404(svc(request, "treatment"), id, "treatment") body.pop("id", None) doc = await svc(request, "treatment").update(id, body) return dump(doc) async def delete_treatment(request: Request, id: int, response: Response) -> None: """Delete a treatment by id. Args: request (Request): Incoming request. id (int): Treatment identifier. response (Response): Response object; set to 204 on success. Raises: HTTPException: 404 when the treatment does not exist. """ await delete_or_404(svc(request, "treatment"), id, "treatment") response.status_code = 204