Note Generation¶
The NoteManager
class handles all operations related to generating medical notes from audio recordings.
Note Manager Class¶
notedx_sdk.core.note_manager.NoteManager ¶
Manages medical note generation from audio files using the NoteDx API.
This class provides a high-level interface for:
- Converting audio recordings to medical notes
- Managing note generation jobs
- Retrieving generated notes and transcripts
- Monitoring system status
The NoteManager handles all API authentication and error handling, making it easy to integrate medical note generation into your application.
Example
>>> from notedx_sdk import NoteDxClient
>>> client = NoteDxClient(api_key="your-api-key")
>>> note_manager = client.notes
>>>
>>> # Generate a medical note from an audio file
>>> response = note_manager.process_audio(
... file_path="patient_visit.mp3",
... visit_type="initialEncounter",
... recording_type="dictation",
... template="primaryCare"
... )
>>> job_id = response["job_id"]
>>>
>>> # Check status and get the note when ready
>>> status = note_manager.fetch_status(job_id)
>>> if status["status"] == "completed":
... note = note_manager.fetch_note(job_id)
... print(note["note"])
Initialize the NoteManager.
PARAMETER | DESCRIPTION |
---|---|
client |
The NoteDxClient instance.
TYPE:
|
Functions¶
set_logger ¶
Set the logger level and handler.
PARAMETER | DESCRIPTION |
---|---|
level |
The logging level (e.g., logging.INFO).
TYPE:
|
handler |
Optional logging handler.
TYPE:
|
configure_logging
classmethod
¶
configure_logging(
level: Union[int, str] = logging.INFO,
handler: Optional[Handler] = None,
) -> None
Configure logging for the SDK.
PARAMETER | DESCRIPTION |
---|---|
level |
The logging level (e.g., logging.DEBUG, logging.INFO)
TYPE:
|
handler |
Optional logging handler to add. If None, logs to console.
TYPE:
|
process_audio ¶
process_audio(
file_path: str,
visit_type: Optional[
Literal["initialEncounter", "followUp"]
] = None,
recording_type: Optional[
Literal["dictation", "conversation"]
] = None,
patient_consent: Optional[bool] = None,
lang: Literal["en", "fr"] = "en",
output_language: Optional[Literal["en", "fr"]] = None,
template: Optional[
Literal[
"primaryCare",
"er",
"psychiatry",
"surgicalSpecialties",
"medicalSpecialties",
"nursing",
"radiology",
"procedures",
"letter",
"pharmacy",
"social",
"wfw",
"smartInsert",
]
] = None,
documentation_style: Optional[
Literal["soap", "problemBased"]
] = None,
custom: Optional[Dict[str, Any]] = None,
chunk_size: Optional[int] = None,
) -> Dict[str, Any]
Converts an audio recording into a medical note using the specified template.
This method handles the complete flow of audio processing and note generation:
- Validates the audio file format and parameters
- Securely uploads the file
- Initiates the note generation process
- Returns a job ID for tracking progress
PARAMETER | DESCRIPTION |
---|---|
file_path |
Path to the audio file.
TYPE:
|
visit_type |
Type of medical visit (optional).
TYPE:
|
recording_type |
Type of audio recording (optional).
TYPE:
|
patient_consent |
Whether patient consent was obtained (optional).
TYPE:
|
lang |
Source language of the audio. Defaults to 'en'.
TYPE:
|
output_language |
Target language for the note (optional).
TYPE:
|
template |
Medical note template to use.
TYPE:
|
documentation_style |
Style of the documentation (optional).
TYPE:
|
Note
- If left empty, the default documentation style of the template is used, i.e.
structured
- Common sections are: Identification, Chief complaint, Past medical and surgical history, Past investigations, Medication and allergies, Lifestyle habits, Family history, Social history, HPI, Physical exam, Assessment, Plan.
Standard templates (require visit_type and recording_type):
primaryCare
- Primary care visit for a general practitionerer
- Emergency room visitpsychiatry
- Psychiatric evaluationsurgicalSpecialties
- Surgical specialties (Any)medicalSpecialties
- Medical specialties (Any)nursing
- Nursing notespharmacy
- Pharmacy notesradiology
- Radiology reportsprocedures
- Procedure notes (small procedures, biopsies, outpatient surgeries, etc.)letter
- Medical letter to the referring physiciansocial
- Social worker notes
Special templates (only require file_path and lang):
wfw
- Word for word transcription, supports inclusion of formatting and punctuation during dictationsmartInsert
- Smart insertion mode
custom: Additional parameters for note generation (optional).
Dictionary that can contain:
* `context`: Additional patient context (history, demographics, medication, etc.)
* `template`: A complete custom template as a string (SOAP note, other etc...)
chunk_size: Size of upload chunks in bytes (optional).
Defaults to 1MB. Adjust for large files or slow connections.
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary containing:
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValidationError
|
If parameters are invalid or missing |
UploadError
|
If file upload fails |
AuthenticationError
|
If API key is invalid |
PaymentRequiredError
|
If:
|
AuthorizationError
|
If API key lacks permissions |
InactiveAccountError
|
If account is inactive or pending setup |
NetworkError
|
If connection issues occur |
BadRequestError
|
If API rejects the request |
InternalServerError
|
If server error occurs |
Examples:
Standard template usage:
response = note_manager.process_audio(
file_path="visit.mp3",
visit_type="initialEncounter",
recording_type="dictation",
template="primaryCare"
)
job_id = response["job_id"]
Word-for-word transcription:
Notes
The custom
object provides powerful customization capabilities:
- It accepts a dictionary with
context
andtemplate
keys (both must be strings) - The
template
value replaces the default note template -
Example custom object:
custom = { "context": "Past medical history: ACL tear 10 years ago on the right knee.", "template": '''A new custom SOAP note template. IDENTIFICATION AND CHIEF COMPLAINT: - Include the patient's identification and chief complaint here. PAST MEDICAL HISTORY: - Include the patient's past medical history here and past investigations. SUBJECTIVE: - Include the patient's subjective information here. Order by system. (Do not repeat the same information in the Identification and Chief complaint, Past medical history and Past investigations sections) OBJECTIVE: - Include the patient's objective information here. ASSESSMENT: - Include the patient's assessment here. PLAN: - Include the patient's plan here.''' }
-
You can create multiple custom templates and pass them in the
custom
object. - The custom object can be used in
regenerate_note()
to generate new notes from existing transcripts - The
context
key adds patient information not in the audio recording smartInsert
mode allows adding text snippets within a note (e.g., "Include a normal right knee exam")
Note
- Each language need its own custom template if you want the note to be generated accurately.
- For example, if you pass a custom template in english, but use
lang
andoutput_language
as french, the note will be generated in french but the custom template but the sections might be in english. - Free trial users get 100 jobs before requiring payment
- Job processing typically takes 20-30 seconds
- Maximum file size is 500MB
regenerate_note ¶
regenerate_note(
job_id: str,
template: Optional[
Literal[
"primaryCare",
"er",
"psychiatry",
"surgicalSpecialties",
"medicalSpecialties",
"nursing",
"radiology",
"procedures",
"letter",
"social",
"wfw",
"smartInsert",
]
] = None,
output_language: Optional[Literal["en", "fr"]] = None,
documentation_style: Optional[
Literal["soap", "problemBased"]
] = None,
custom: Optional[Dict[str, Any]] = None,
) -> Dict[str, Any]
Generates a new medical note from an existing transcript with different parameters.
This method allows you to:
- Generate a new note using a different template
- Translate the note to another language
- Modify generation parameters without re-uploading audio
PARAMETER | DESCRIPTION |
---|---|
job_id |
ID of the original job to regenerate from. Must be a completed job with a transcript.
TYPE:
|
template |
New template to use for generation. See process_audio() for available templates. If not specified, uses the original template.
TYPE:
|
output_language |
Target language for the new note:
TYPE:
|
custom |
Additional parameters for note generation:
TYPE:
|
documentation_style |
Style of the documentation (optional):
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary containing:
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValidationError
|
If job_id is invalid |
JobNotFoundError
|
If source job is not found |
JobError
|
If source job has no transcript or had errors |
AuthenticationError
|
If API key is invalid |
PaymentRequiredError
|
If account payment is required |
NetworkError
|
If connection issues occur |
Example
fetch_status ¶
Gets the current status and progress of a note generation job.
The job can be in one of these states:
- 'pending': Job created, waiting for file upload
- 'queued': File uploaded, waiting for processing
- 'transcribing': Audio file is being transcribed
- 'transcribed': Transcript ready, generating note
- 'completed': Note generation finished successfully
- 'error': Job failed with an error
PARAMETER | DESCRIPTION |
---|---|
job_id |
The ID of the job to check. Obtained from process_audio() or regenerate_note().
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary containing:
TYPE:
|
RAISES | DESCRIPTION |
---|---|
JobNotFoundError
|
If job_id is not found |
AuthenticationError
|
If API key is invalid |
NetworkError
|
If connection issues occur |
Example
Note
- Poll at least 5 seconds apart if you chose this method. Webhooks are HIGHLY recommended.
- The full Job typically complete within 20-30 seconds.
- Status history is preserved for 48 hours
fetch_note ¶
Retrieves the generated medical note for a completed job.
The note includes:
- Patient consent statement (if applicable)
- Structured medical note based on template
- Optional note title
- Source/target language information
PARAMETER | DESCRIPTION |
---|---|
job_id |
The ID of the job to fetch the note for. Job must be in 'completed' status.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary containing:
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValidationError
|
If job_id is invalid |
JobNotFoundError
|
If job or note is not found |
JobError
|
If note generation is not completed |
AuthenticationError
|
If API key is invalid |
NetworkError
|
If connection issues occur |
Example
Note
- Always check job status before fetching note
- Notes are available for 48 hours after completion
- Notes include patient consent if provided
- The note format follows the selected template
fetch_transcript ¶
Retrieves the raw transcript for a job after audio processing.
The transcript represents the raw text from audio processing, before any medical note generation. Useful for:
- Verifying audio processing accuracy
- Debugging note generation issues
- Keeping raw transcripts for records
PARAMETER | DESCRIPTION |
---|---|
job_id |
The ID of the job to fetch the transcript for. Job must be in 'transcribed' or 'completed' status.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary containing:
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValidationError
|
If job_id is invalid |
JobNotFoundError
|
If job or transcript is not found |
JobError
|
If transcription is not completed |
AuthenticationError
|
If API key is invalid |
NetworkError
|
If connection issues occur |
Example
Note
- Available after transcription, before note generation
- Preserved for 48 hours after job completion
- Includes all recognized speech from audio
- May contain speaker labels in conversation mode
get_system_status ¶
Retrieves system status and health information.
Useful for:
- Monitoring API availability
- Checking processing latencies
- Debugging connection issues
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary containing:
TYPE:
|
RAISES | DESCRIPTION |
---|---|
AuthenticationError
|
If API key is invalid |
NetworkError
|
If connection issues occur |
ServiceUnavailableError
|
If status check fails |
Example
Note
- Updated every minute
- Includes all system components
- Useful for monitoring and debugging
- No authentication required
Templates¶
The SDK supports various medical note templates:
primaryCare
: Primary care visit noteser
: Emergency room visit notespsychiatry
: Psychiatric evaluation notessurgicalSpecialties
: Surgical specialties notesmedicalSpecialties
: Medical specialties notesnursing
: Nursing notesradiology
: Radiology reportsprocedures
: Procedure notesletter
: Medical letterssocial
: Social worker noteswfw
: Word-for-word transcriptionsmartInsert
: Smart insertion mode
Usage Examples¶
Basic Note Generation¶
# Initialize client
client = NoteDxClient(api_key="your-api-key")
# Step 1: Process audio request - get job_id and upload URL
response = client.notes.process_audio(
template="primaryCare",
visit_type="initialEncounter",
recording_type="dictation",
lang="en"
)
# Get job ID and presigned URL
job_id = response["job_id"]
presigned_url = response["presigned_url"]
# Step 2: Upload the audio file using presigned URL
client.notes.upload_audio(
presigned_url=presigned_url,
file_path="visit_recording.mp3"
)
# Step 3: Check status until complete
while True:
status = client.notes.fetch_status(job_id)
if status["status"] == "completed":
# Step 4: Get the note
note = client.notes.fetch_note(job_id)
print(note["note"])
break
elif status["status"] == "error":
print(f"Error: {status['message']}")
break
time.sleep(5) # Wait 5 seconds before checking again
Word-for-Word Transcription¶
# Get job_id and upload URL
response = client.notes.process_audio(
template="wfw",
lang="en"
)
# Upload the audio file
client.notes.upload_audio(
presigned_url=response["presigned_url"],
file_path="dictation.mp3"
)
Note Regeneration¶
# Regenerate with different template
new_response = client.notes.regenerate_note(
job_id="original-job-id",
template="er"
)
# Translate to French
translated = client.notes.regenerate_note(
job_id="original-job-id",
output_language="fr"
)
Error Handling¶
from notedx_sdk.exceptions import ValidationError, JobError
try:
response = client.notes.process_audio(
file_path="recording.mp3",
template="invalid-template"
)
except ValidationError as e:
print(f"Invalid parameters: {e}")
except JobError as e:
print(f"Job failed: {e}")
REST API Equivalent¶
# Step 1: Initialize processing and get upload URL
curl -X POST "https://api.notedx.io/v1/process-audio" \
-H "x-api-key: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"template": "primaryCare",
"visit_type": "initialEncounter",
"recording_type": "dictation",
"lang": "en"
}'
# Response contains job_id and presigned_url
# Step 2: Upload audio file using presigned URL
curl -X PUT "${presigned_url}" \
-H "Content-Type: audio/mpeg" \
--data-binary "@recording.mp3"
# Step 3: Check processing status
curl "https://api.notedx.io/v1/status/{job_id}" \
-H "x-api-key: your-api-key"
# Step 4: Get the generated note
curl "https://api.notedx.io/v1/fetch-note/{job_id}" \
-H "x-api-key: your-api-key"