Gemini enables healthcare organizations to automate medical coding, enhance clinical documentation, and improve patient care workflows. This guide demonstrates how to build healthcare AI applications using the Healthcare NL API, LangChain, and ReAct (Reasoning + Acting) patterns.
Important: AI-generated healthcare information should always be reviewed by qualified medical professionals. Maintain a human-in-the-loop approach for all clinical applications.
Medical coding errors lead to denied claims, delayed payments, and potential patient safety issues. AI can help by suggesting accurate codes and automating repetitive tasks.
from langchain.tools import Tool# Tool 1: Extract entities from clinical notesentity_extraction_tool = Tool( name="ExtractMedicalEntities", func=extract_medical_entities, description="""Extract medical entities (diagnoses, procedures, medications, symptoms) from clinical text using Healthcare NL API. Input: clinical text string. Output: JSON with categorized entities and confidence scores.""")# Tool 2: Search medical code databasedef search_medical_codes(entity: str, code_type: str) -> list[dict]: """Search for relevant medical codes. Args: entity: Medical term to search code_type: 'ICD10', 'CPT', 'HCPCS' Returns: List of matching codes with descriptions """ # In production, query your medical code database # This is a simplified example code_database = { "diabetes": [ {"code": "E11.9", "type": "ICD10", "description": "Type 2 diabetes mellitus without complications"}, {"code": "E11.65", "type": "ICD10", "description": "Type 2 diabetes mellitus with hyperglycemia"}, ], "hypertension": [ {"code": "I10", "type": "ICD10", "description": "Essential (primary) hypertension"}, ], } return code_database.get(entity.lower(), [])code_search_tool = Tool( name="SearchMedicalCodes", func=lambda x: search_medical_codes(x, "ICD10"), description="""Search for ICD-10 diagnosis codes for a medical condition or symptom. Input: medical term (e.g., 'diabetes', 'hypertension'). Output: List of relevant ICD-10 codes with descriptions.""")# Tool 3: Validate code combinationsdef validate_code_combination(codes: list[str]) -> dict: """Validate that code combinations are appropriate. Args: codes: List of medical codes Returns: Validation results with warnings """ # Implement your validation logic return { "valid": True, "warnings": [], "suggestions": ["Consider adding secondary diagnosis codes"], }validation_tool = Tool( name="ValidateCodes", func=validate_code_combination, description="""Validate medical code combinations for accuracy and completeness. Input: comma-separated list of codes. Output: Validation results with warnings and suggestions.""")
tools = [entity_extraction_tool, code_search_tool, validation_tool]# System prompt for medical coding agentsystem_prompt = """You are an expert medical coding specialist assistant.Your role:1. Analyze clinical notes to identify diagnoses, procedures, and symptoms2. Suggest appropriate ICD-10, CPT, and HCPCS codes3. Validate code combinations for accuracy4. Explain your reasoning clearlyIMPORTANT:- Always use tools to extract entities and search codes- Provide confidence levels for code suggestions- Flag any ambiguous or unclear clinical documentation- Recommend additional documentation when needed- Remember: Final coding decisions require human review"""# Initialize ReAct agentagent = initialize_agent( tools=tools, llm=llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True, max_iterations=5, system_message=system_prompt,)
clinical_note = """Patient: 65-year-old maleChief Complaint: Shortness of breath and chest discomfortHistory of Present Illness:Patient presents with worsening shortness of breath over the past 3 days.Reports chest tightness and fatigue. Known history of Type 2 diabetes mellitusand hypertension, both currently managed with medication.Vital Signs:- BP: 145/92 mmHg- HR: 88 bpm- O2 Saturation: 94% on room airAssessment:1. Acute exacerbation of congestive heart failure2. Poorly controlled hypertension3. Type 2 diabetes mellitusPlan:- Admit for observation- Increase diuretic dose- Adjust antihypertensive medications- Monitor blood glucose"""prompt = f"""Analyze this clinical note and suggest appropriate medical codes.Clinical Note:{clinical_note}Provide:1. Extracted medical entities2. Recommended ICD-10 diagnosis codes3. Confidence levels for each code4. Any documentation concerns or recommendations"""result = agent.run(prompt)print(result)
def generate_physician_queries(note: str, codes: list[str]) -> list[str]: """Generate queries for physicians to improve documentation.""" prompt = f"""Based on this clinical note and suggested codes, generate specific questionsfor the physician to clarify documentation:Note: {note}Suggested Codes: {', '.join(codes)}Format each query as:- Clear, specific question- Why the information is needed- How it affects coding/reimbursement """ response = llm.invoke(prompt) # Parse queries from response queries = response.content.split("\n\n") return queries
Disclaimer: This guide is for educational purposes. Medical coding and clinical decision-making require qualified healthcare professionals. Always comply with HIPAA and other healthcare regulations.