---
title: "Write a Medical Note"
description: "Create clinical medical notes on patient records using Leyr templates and the Medical Notes API."
canonical_url: "http://localhost/api/quickstart/write-medical-note"
---
# Write a Medical Note
> Create clinical medical notes on patient records using Leyr templates and the Medical Notes API.
Learn how to create medical notes for patient records. Medical notes are clinical documentation written by healthcare providers during or after consultations.
This guide requires `care_unit_id` and `resource_id` from [Show Doctor's Availability](http://localhost/api/quickstart/show-availability), and a valid `patient_id` from [Find or Get Patient](http://localhost/api/quickstart/find-patient) or [Create Patient](http://localhost/api/quickstart/create-patient). If the patient does not exist yet, create them first.
## Flow Overview

## Understanding Medical Notes
- **Medical Notes**: Clinical documentation written by healthcare providers (e.g., doctor's notes, consultation summaries)
- **vs Documents**: Medical notes are text-based clinical records; documents are files (PDFs, images)
- **Unsigned Status**: Notes are created unsigned and must be signed by a doctor later in the EHR
Medical Notes vs Documents
Medical notes are different from documents. Notes are text-based clinical records, while documents are files like PDFs or images. See [Attach a Document](http://localhost/api/quickstart/attach-document) for file uploads.
## Structured vs Unstructured Notes
Different EHR systems handle medical notes differently:
- **Structured Notes**: Some EHRs use templates with specific fields (e.g., Chief Complaint, History, Assessment, Plan)
- **Unstructured Notes**: Others only support a single free-text field
**Good news**: You don't need to worry about these differences. Send your note content to Leyr in a consistent format, and we'll automatically convert it to match each EHR's requirements. Whether the target EHR uses structured templates or a single text field, your integration code stays the same.
This example uses the simplest template, `LeyrUnstructured` (`leyr_unstructured`), with one free-text `unstructured` content field.
## Code Example
```python
import requests
CLIENT_ID = "your-client-id"
CLIENT_SECRET = "your-client-secret"
BASE_URL = "https://api.leyr.io/api"
EMR = "webdoc"
headers = {
"x-leyr-client-id": CLIENT_ID,
"x-leyr-client-secret": CLIENT_SECRET,
"Content-Type": "application/json"
}
care_unit_id = "care-unit-123"
patient_id = "se_personal_number:191212121212"
resource_id = "resource-123"
# 1. Prepare the medical note payload
note_data = {
"template_id": "leyr_unstructured",
"title": "Consultation Summary",
"created_by_id": resource_id,
"content": {
"unstructured": """Patient presents with mild headache and fatigue.
Symptoms:
- Headache (mild, frontal region)
- Fatigue for 2 days
- No fever
Assessment:
Likely tension headache, possibly related to stress and lack of sleep.
Plan:
- Recommend adequate rest and hydration
- Over-the-counter pain relief as needed
- Follow-up if symptoms persist beyond 1 week
"""
}
}
# 2. Create the medical note
response = requests.post(
f"{BASE_URL}/emrs/{EMR}/care-units/{care_unit_id}/patients/{patient_id}/medical-notes",
headers=headers,
json=note_data
)
note = response.json()
# 3. Read key values from the response
print("✓ Medical note created successfully!")
print(f" Note ID: {note['id']}")
print(f" Created: {note['created_at']}")
print(f" Created by: {note['created_by_id']}")
```
```javascript
const CLIENT_ID = "your-client-id";
const CLIENT_SECRET = "your-client-secret";
const BASE_URL = "https://api.leyr.io/api";
const EMR = "webdoc";
const headers = {
"x-leyr-client-id": CLIENT_ID,
"x-leyr-client-secret": CLIENT_SECRET,
"Content-Type": "application/json"
};
const careUnitId = "care-unit-123";
const patientId = "se_personal_number:191212121212";
const resourceId = "resource-123";
// 1. Prepare the medical note payload
const noteData = {
template_id: "leyr_unstructured",
title: "Consultation Summary",
created_by_id: resourceId,
content: {
unstructured: `Patient presents with mild headache and fatigue.
Symptoms:
- Headache (mild, frontal region)
- Fatigue for 2 days
- No fever
Assessment:
Likely tension headache, possibly related to stress and lack of sleep.
Plan:
- Recommend adequate rest and hydration
- Over-the-counter pain relief as needed
- Follow-up if symptoms persist beyond 1 week
`
}
};
// 2. Create the medical note
const response = await fetch(
`${BASE_URL}/emrs/${EMR}/care-units/${careUnitId}/patients/${patientId}/medical-notes`,
{
method: "POST",
headers,
body: JSON.stringify(noteData)
}
);
const note = await response.json();
// 3. Read key values from the response
console.log("✓ Medical note created successfully!");
console.log(` Note ID: ${note.id}`);
console.log(` Created: ${note.created_at}`);
console.log(` Created by: ${note.created_by_id}`);
```
### Shared setup
```python
import requests
CLIENT_ID = "your-client-id"
CLIENT_SECRET = "your-client-secret"
BASE_URL = "https://api.leyr.io/api"
EMR = "webdoc"
headers = {
"x-leyr-client-id": CLIENT_ID,
"x-leyr-client-secret": CLIENT_SECRET,
"Content-Type": "application/json"
}
care_unit_id = "care-unit-123"
patient_id = "se_personal_number:191212121212"
resource_id = "resource-123"
```
```javascript
const CLIENT_ID = "your-client-id";
const CLIENT_SECRET = "your-client-secret";
const BASE_URL = "https://api.leyr.io/api";
const EMR = "webdoc";
const headers = {
"x-leyr-client-id": CLIENT_ID,
"x-leyr-client-secret": CLIENT_SECRET,
"Content-Type": "application/json"
};
const careUnitId = "care-unit-123";
const patientId = "se_personal_number:191212121212";
const resourceId = "resource-123";
```
#### 1. Prepare the medical note payload
```python
note_data = {
"template_id": "leyr_unstructured",
"title": "Consultation Summary",
"created_by_id": resource_id,
"content": {
"unstructured": """Patient presents with mild headache and fatigue.
Symptoms:
- Headache (mild, frontal region)
- Fatigue for 2 days
- No fever
Assessment:
Likely tension headache, possibly related to stress and lack of sleep.
Plan:
- Recommend adequate rest and hydration
- Over-the-counter pain relief as needed
- Follow-up if symptoms persist beyond 1 week
"""
}
}
```
```javascript
const noteData = {
template_id: "leyr_unstructured",
title: "Consultation Summary",
created_by_id: resourceId,
content: {
unstructured: `Patient presents with mild headache and fatigue.
Symptoms:
- Headache (mild, frontal region)
- Fatigue for 2 days
- No fever
Assessment:
Likely tension headache, possibly related to stress and lack of sleep.
Plan:
- Recommend adequate rest and hydration
- Over-the-counter pain relief as needed
- Follow-up if symptoms persist beyond 1 week
`
}
};
```
#### 2. Create the medical note
```python
response = requests.post(
f"{BASE_URL}/emrs/{EMR}/care-units/{care_unit_id}/patients/{patient_id}/medical-notes",
headers=headers,
json=note_data
)
note = response.json()
```
```javascript
const response = await fetch(
`${BASE_URL}/emrs/${EMR}/care-units/${careUnitId}/patients/${patientId}/medical-notes`,
{
method: "POST",
headers,
body: JSON.stringify(noteData)
}
);
const note = await response.json();
```
#### 3. Read key values from the response
```python
print("✓ Medical note created successfully!")
print(f" Note ID: {note['id']}")
print(f" Created: {note['created_at']}")
print(f" Created by: {note['created_by_id']}")
```
```javascript
console.log("✓ Medical note created successfully!");
console.log(` Note ID: ${note.id}`);
console.log(` Created: ${note.created_at}`);
console.log(` Created by: ${note.created_by_id}`);
```
## 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.
## Retrieving Medical Notes
#### 1. Get all medical notes for a patient
```python
response = requests.get(
f"{BASE_URL}/emrs/{EMR}/care-units/{care_unit_id}/patients/{patient_id}/medical-notes",
headers=headers
)
notes_response = response.json()
notes = notes_response["items"]
print(f"Found {len(notes)} medical notes")
for note in notes:
print(f" - {note['id']}: {note['created_at']}")
```
```javascript
let response = await fetch(
`${BASE_URL}/emrs/${EMR}/care-units/${careUnitId}/patients/${patientId}/medical-notes`,
{ headers }
);
const notesResponse = await response.json();
const notes = notesResponse.items;
console.log(`Found ${notes.length} medical notes`);
notes.forEach(note => {
console.log(` - ${note.id}: ${note.created_at}`);
});
```
#### 2. Get one medical note
```python
note_id = notes[0]["id"]
response = requests.get(
f"{BASE_URL}/emrs/{EMR}/care-units/{care_unit_id}/patients/{patient_id}/medical-notes/{note_id}",
headers=headers
)
note = response.json()
print(f"\nNote content:\n{note['content']['unstructured']}")
```
```javascript
const noteId = notes[0].id;
response = await fetch(
`${BASE_URL}/emrs/${EMR}/care-units/${careUnitId}/patients/${patientId}/medical-notes/${noteId}`,
{ headers }
);
const note = await response.json();
console.log(`\nNote content:\n${note.content.unstructured}`);
```
## Best Practices
- **Be Specific**: Include relevant clinical details
- **Structure Content**: Use clear sections (Symptoms, Assessment, Plan)
- **Sign Notes**: Remember that notes are created unsigned and must be signed in the EHR
## Next steps
Upload files such as lab results or consent forms to a patient record.
Understand patient identifier formats.
## API Reference
For detailed API documentation, see:
- [Medical Notes API](https://api.leyr.io/docs#tag/Medical-Notes)
## Sitemap
See the full [sitemap](http://localhost/sitemap.md) for all pages.