Skip to main content
POST
/
patients
/
add_and_link
curl -X POST /patients/add_and_link?uid=doctor_uid_123 \
  -H "Authorization: Bearer your_jwt_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "appointment_id": "65f8a1b2c3d4e5f6789012ef",
    "firstName": "Jane",
    "lastName": "Smith",
    "dateOfBirth": "1990-03-20",
    "address": {
      "street": "456 Oak St",
      "city": "Boston",
      "state": "MA",
      "zipCode": "02101"
    },
    "insurance": {
      "provider": "Aetna",
      "policyNumber": "AET789012"
    },
    "medicalHistory": "No significant medical history",
    "currentMedications": "Multivitamin daily",
    "contact": {
      "phone": "+1234567892",
      "email": "[email protected]"
    }
  }'
{
  "success": true,
  "data": {
    "_id": "65f8a1b2c3d4e5f6789012cd",
    "doctor_id": "doctor_uid_123",
    "firstName": "Jane",
    "lastName": "Smith",
    "dateOfBirth": "1990-03-20",
    "address": {
      "street": "456 Oak St",
      "city": "Boston",
      "state": "MA",
      "zipCode": "02101"
    },
    "insurance": {
      "provider": "Aetna",
      "policyNumber": "AET789012"
    },
    "medicalHistory": "No significant medical history",
    "currentMedications": "Multivitamin daily",
    "contact": {
      "phone": "+1234567892",
      "email": "[email protected]"
    }
  }
}

Overview

Creates a new patient record and links them to an existing appointment. This endpoint is useful when an appointment was created without a patient and you need to add patient details later.

Authentication

Authorization
string
required
Bearer token for authenticated access
Authorization: Bearer your_jwt_token_here

Query Parameters

uid
string
required
Doctor’s user ID

Body Parameters

appointment_id
string
required
ID of the existing appointment to link the patient to
firstName
string
required
Patient’s first name
lastName
string
required
Patient’s last name
dateOfBirth
string
Patient’s date of birth
address
object
Patient’s address information
insurance
object
Patient’s insurance information
medicalHistory
string
Patient’s medical history
currentMedications
string
Patient’s current medications
contact
object
Patient’s contact information

Response

success
boolean
Whether the request was successful
data
object
The created patient object
error
string
Error message (only present when success is false)

Example Request

curl -X POST /patients/add_and_link?uid=doctor_uid_123 \
  -H "Authorization: Bearer your_jwt_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "appointment_id": "65f8a1b2c3d4e5f6789012ef",
    "firstName": "Jane",
    "lastName": "Smith",
    "dateOfBirth": "1990-03-20",
    "address": {
      "street": "456 Oak St",
      "city": "Boston",
      "state": "MA",
      "zipCode": "02101"
    },
    "insurance": {
      "provider": "Aetna",
      "policyNumber": "AET789012"
    },
    "medicalHistory": "No significant medical history",
    "currentMedications": "Multivitamin daily",
    "contact": {
      "phone": "+1234567892",
      "email": "[email protected]"
    }
  }'

Example Response

{
  "success": true,
  "data": {
    "_id": "65f8a1b2c3d4e5f6789012cd",
    "doctor_id": "doctor_uid_123",
    "firstName": "Jane",
    "lastName": "Smith",
    "dateOfBirth": "1990-03-20",
    "address": {
      "street": "456 Oak St",
      "city": "Boston",
      "state": "MA",
      "zipCode": "02101"
    },
    "insurance": {
      "provider": "Aetna",
      "policyNumber": "AET789012"
    },
    "medicalHistory": "No significant medical history",
    "currentMedications": "Multivitamin daily",
    "contact": {
      "phone": "+1234567892",
      "email": "[email protected]"
    }
  }
}

Error Responses

{
  "success": false,
  "error": "Missing appointment_id"
}
{
  "success": false,
  "error": "Missing doctor_id (uid)"
}
{
  "success": false,
  "error": "Missing required patient fields (firstName, lastName)"
}
{
  "success": false,
  "error": "Appointment not found (patient created but not linked)"
}
{
  "success": false,
  "error": "Appointment already linked to a patient"
}
{
  "success": false,
  "error": "Doctor does not own this appointment"
}

Business Logic

This endpoint performs the following steps:
  1. Create Patient: Creates a new patient record with the provided details
  2. Find Appointment: Locates the appointment by the provided ID
  3. Verify Ownership: Ensures the doctor owns the appointment
  4. Check Availability: Verifies the appointment doesn’t already have a patient linked
  5. Link Patient: Updates the appointment with the new patient ID

Use Cases

  • Adding patient details to appointments created without patient information
  • Linking walk-in patients to previously scheduled appointment slots
  • Correcting appointments that were created with incomplete patient data