Skip to main content

Overview

Update or create a medical document for a specific appointment in MediSync. This endpoint replaces any existing document for the appointment with a new PDF file, or creates a new document if none exists.
Document Replacement: This operation will permanently delete the existing document and replace it with the new one. Make sure you have the correct file before proceeding.

Authentication

curl -X PUT \
  'https://app.medisync.me/api/documents/65f1a2b3c4d5e6f7g8h9i0j1?uid=doc_abc123' \
  -H 'Authorization: Bearer YOUR_API_TOKEN' \
  -F 'document=@updated_medical_report.pdf'

Path Parameters

id
string
required
The appointment ID to update the document for

Query Parameters

uid
string
required
The doctor/user ID performing the update

Request Body

Response

success
boolean
Whether the update was successful
data
object
The updated document information
error
string
Error message if the update failed

Response Examples

Successful Update (Existing Document Replaced)

{
  "success": true,
  "data": {
    "_id": "65f1a2b3c4d5e6f7g8h9i0j2",
    "appointment_id": "65f1a2b3c4d5e6f7g8h9i0j1",
    "document_url": "https://storage.cloud.telekom.de/dokumente/65f1a2b3c4d5e6f7g8h9i0j1_updated_report.pdf",
    "document_key": "65f1a2b3c4d5e6f7g8h9i0j1_updated_report.pdf",
    "doctor_id": "doc_abc123",
    "createdAt": "2024-01-15T16:30:00.000Z",
    "updatedAt": "2024-01-15T16:30:00.000Z"
  }
}

Successful Creation (No Previous Document)

{
  "success": true,
  "data": {
    "_id": "65f1a2b3c4d5e6f7g8h9i0j2",
    "appointment_id": "65f1a2b3c4d5e6f7g8h9i0j1",
    "document_url": "https://storage.cloud.telekom.de/dokumente/65f1a2b3c4d5e6f7g8h9i0j1_new_report.pdf",
    "document_key": "65f1a2b3c4d5e6f7g8h9i0j1_new_report.pdf",
    "doctor_id": "doc_abc123",
    "createdAt": "2024-01-15T16:30:00.000Z",
    "updatedAt": "2024-01-15T16:30:00.000Z"
  }
}

Error Response

{
  "success": false,
  "error": "Error deleting old document"
}

Business Logic

  1. Replace or Create: If a document exists for the appointment, it will be completely replaced. If no document exists, a new one will be created.
  2. Complete Replacement: The old document is permanently deleted from both storage and database before the new one is uploaded.
  3. Atomic Operation: The update process ensures that either the entire operation succeeds or fails - you won’t be left with a partially updated state.
  4. New Document ID: Each update creates a completely new document record with a new ID.

Error Handling

  • 400 Bad Request:
    • Invalid file type (only PDF allowed)
    • Missing file in request
    • Error deleting old document
    • Error uploading new document
  • 401 Unauthorized: Invalid or missing authentication token
  • 500 Internal Server Error: Storage or database error

Notes

  • Only PDF files are currently supported
  • The old document is completely removed from storage - this operation cannot be undone
  • Maximum file size limit is 500MB
  • A new document ID is generated for each update
  • File naming follows the format: {appointment_id}_{original_filename}
  • Use this endpoint both for updating existing documents and creating new ones