Skip to main content

Overview

Generate an AI-powered diagnosis prediction for notes associated with a specific appointment in MediSync. This endpoint uses an external AI agent to analyze the clinical notes content and provide diagnostic suggestions with ICD codes and clinical reasoning.
AI-Powered Analysis: This endpoint sends the clinical notes to an external AI diagnosis agent service and processes the response to generate structured diagnostic predictions with ICD codes and clinical reasoning.

Authentication

curl -X POST \
  'https://api.medisync.com/notes/diagnosis/apt_abc123?uid=doc_xyz789' \
  -H 'Authorization: Bearer YOUR_JWT_TOKEN'

Path Parameters

id
string
required
The appointment ID to generate diagnosis prediction for

Query Parameters

uid
string
required
The user ID of the healthcare provider requesting the diagnosis generation

Response

success
boolean
Indicates if the operation was successful
data
object
Object containing the generated diagnosis prediction
error
string
Error message if the operation failed

Example Response

{
  "success": true,
  "data": {
    "diagnosis_prediction": {
      "status": "generated",
      "main_diagnosis": "Acute upper respiratory infection",
      "icd_code": "J06.9",
      "reason": "Based on patient symptoms of cough, sore throat, and nasal congestion with no fever, consistent with viral upper respiratory infection"
    }
  }
}

Process Flow

  1. Status Update: Initially sets diagnosis prediction status to “pending”
  2. AI Session: Establishes a session with the external AI diagnosis agent
  3. Analysis: Sends clinical notes content to the AI for analysis
  4. Response Processing: Parses and validates the AI response
  5. Database Update: Updates the notes with the generated prediction
  6. Error Handling: Sets status to “failed” with error message if any step fails

Behavior Notes

  • Two-Phase AI Interaction: First establishes a session with a “hello” message, then sends the actual clinical content
  • Response Validation: The AI response is parsed and validated for required fields (main_diagnosis, icd_code, reason)
  • Status Tracking: The prediction status is updated throughout the process (pending → generated/failed)
  • Error Recovery: If generation fails, the error is captured and stored in the diagnosis prediction
  • JSON Parsing: The AI response is expected to be in JSON format, with automatic cleanup of markdown code fences

Status Codes

  • 200 - Diagnosis prediction generated successfully
  • 400 - Invalid request, parsing error, or AI service failure
  • 404 - Notes not found for the specified appointment