--- title: "Attach a Document" description: "Upload files such as lab results or consent forms and attach them to a patient's record." canonical_url: "http://localhost/api/quickstart/attach-document" --- # Attach a Document > Upload files such as lab results or consent forms and attach them to a patient's record. Learn how to upload files to patient records. Documents are files like lab results, imaging reports, consent forms, or any other files that need to be attached to a patient's medical record. ## Flow Overview ![Attach Document Flow](http://localhost/images/quickstart/attach-document.png) ## Understanding Documents - **Documents**: Files attached to patient records (PDFs, images, lab results, scans) - **vs Medical Notes**: Documents are binary files; medical notes are text-based clinical records - **Base64 Encoding**: Binary files must be encoded to text for JSON transmission - **MIME Types**: Specify file type (e.g., `application/pdf`, `image/jpeg`) - **Common Use Cases**: Lab reports, imaging results, consent forms, referral letters ## Code Example ### Shared setup #### 1. Read file and encode to base64 #### 2. Determine MIME type You will very often know file format beforehand, e.g. if you know your system generates PDF summaries of the measurements, so you can as well provide it directly. #### 3. Prepare document payload #### 4. Upload the document #### 5. Read key values from the response ## patient_id usage Use `patient_id` in path parameters with one of these formats: - `abc_12345` (treated as `emr_id`) - `emr_id:abc_12345` - `se_personal_number:191212121212` (when supported by the EHR) Use [Find or Get Patient](http://localhost/api/quickstart/find-patient) to discover identifiers and [Patient IDs](http://localhost/api/guides/patient-id) for full format support. ## Common MIME Types Here are common MIME types for medical documents:
File Type Extension MIME Type
PDF .pdf application/pdf
JPEG Image .jpg , .jpeg image/jpeg
PNG Image .png image/png
Word Document .doc application/msword
Word Document (new) .docx application/vnd.openxmlformats-officedocument.wordprocessingml.document
DICOM Image .dcm application/dicom
Text File .txt text/plain
## File Size Limits Be aware of file size limitations: ## Retrieving Documents #### 1. Get all documents for a patient #### 2. Get one document and decode content ## Best Practices - **Validate Files**: Check file size and type before uploading - **Use Descriptive Titles**: Help users identify documents easily - **Set Type When Useful**: Use `type` to categorize documents (e.g., Lab Result, Consent Form) - **Compress Large Files**: Consider compressing large documents before upload ## Next steps Look up a patient and choose the correct patient_id for your requests. Advanced topics and best practices. ## API Reference For detailed API documentation, see: - [Documents API](https://api.leyr.io/docs#tag/Documents) ## Sitemap See the full [sitemap](http://localhost/sitemap.md) for all pages.