"""FastAPI router for medical material generation endpoints.This module defines the API routes for generating necessary materialsfor a given medical simulation scenario. It includes an endpoint forgenerating a list of materials and another for retrieving availablepatient types."""importloggingfromtypingimportList,DictfromfastapiimportAPIRouterfromagentsimportgenerate_materialsfrommodelsimportMATModelRequest,MATModelResponselogger=logging.getLogger(__name__)router=APIRouter(prefix="/materials",tags=["Materials"])
[docs]@router.post("/generate-materials",response_model=List[MATModelResponse],summary="Generate Necessary Materials for Scenario")defgenerate_materials_endpoint(request:MATModelRequest)->List[MATModelResponse]:"""Generates a list of necessary materials for a medical simulation."""logger.info(f"Received request to generate materials: {request.model_dump()}")returngenerate_materials(request)
[docs]@router.get("/form-options",summary="Get Available Options for Forms")defget_form_options()->Dict[str,List[str]]:""" Retrieves the lists of available patient types dynamically from the request model to populate frontend selection inputs. The 'target' field is a free-text string and is not included here. """patient_type_field=MATModelRequest.model_fields['tipologia_paziente']allowed_patient_types=list(patient_type_field.annotation.__args__)ifpatient_type_field.annotationandhasattr(patient_type_field.annotation,'__args__')else[]return{"patient_types":allowed_patient_types,}