Generate SOAP Notes using LeMUR

The acronym SOAP stands for Subjective, Objective, Assessment, and Plan. This standardized method of documenting patient encounters allows providers to concisely record patient information. This guide walks through how to generate SOAP notes with AssemblyAI’s LLM, LeMUR.

Get Started

Before we begin, make sure you have an AssemblyAI account and an API key. You can sign up for an AssemblyAI account and get your API key from your dashboard. You will need to upgrade your account by adding a credit card to have access to LeMUR.

Find more details on the current LeMUR pricing in the AssemblyAI pricing page.

Step-by-Step Instructions

Install the SDK:

$pip install assemblyai

Import the SDK and set your AssemblyAI API key.

1import assemblyai as aai
2
3aai.settings.api_key = "API_KEY"

Initialize your Transcription Config variable.

1config = aai.TranscriptionConfig()

Optionally, enable the PII Redaction model. This will remove any personal info from the transcript & SOAP note.

1config.set_redact_pii = True
2config.set_redact_pii_policies = [
3 aai.PIIRedactionPolicy.banking_information,
4 aai.PIIRedactionPolicy.credit_card_cvv,
5 aai.PIIRedactionPolicy.credit_card_expiration,
6 aai.PIIRedactionPolicy.credit_card_number,
7 aai.PIIRedactionPolicy.date_of_birth,
8 aai.PIIRedactionPolicy.phone_number,
9 aai.PIIRedactionPolicy.us_social_security_number,
10 aai.PIIRedactionPolicy.drivers_license,
11 aai.PIIRedactionPolicy.location,
12 aai.PIIRedactionPolicy.political_affiliation,
13 aai.PIIRedactionPolicy.person_name,
14 aai.PIIRedactionPolicy.organization,
15 aai.PIIRedactionPolicy.email_address,
16 # aai.PIIRedactionPolicy.person_age,
17 # aai.PIIRedactionPolicy.religion,
18 # aai.PIIRedactionPolicy.occupation,
19 # aai.PIIRedactionPolicy.nationality,
20 # aai.PIIRedactionPolicy.medical_process,
21 # aai.PIIRedactionPolicy.medical_condition,
22 # aai.PIIRedactionPolicy.blood_type,
23 # aai.PIIRedactionPolicy.drug,
24 # aai.PIIRedactionPolicy.injury,
25]

Initialize your transcriber variable and transcribe your file.

1transcriber = aai.Transcriber(config=config)
2
3# Replace this with the path to your local file or your file URL.
4transcript = transcriber.transcribe("example.mp3")
5
6print(transcript.id)

Two different methods of generating SOAP notes

LeMUR Summary

This method uses the Summary endpoint to generate the SOAP note in its entirety. The LeMUR prompt includes some context about the audio file, a specific format for the SOAP note, and more context on what each category of the note should include.

1result = transcript.lemur.summarize(
2 context="this is a doctor appointment between patient and provider. the personal identification information has been redacted",
3 answer_format="""
4 Generate a SOAP note summary in the following format:
5
6 Subjective
7 This is typically the shortest section (only 2-3 sentences) and it describes the patient's affect, as the
8professional sees it. This information is all subjective (it isn't measureable).
9 - Include information that may have affected the patient's performance, such as if they were sick, tired,
10attentive, distractible, etc.
11 - Was the patient on time or did they come late?
12 - May include a quote of something the patient said, or how they reported feeling
13
14 Objective
15 This section includes factual, measurable, and objective information. This may include:
16 - Direct patient quotes
17 - Measurements
18 - Data on patient performance
19
20 Assessment
21 This section should be the meat of the SOAP note. It contains a narrative of what actually happened during the
22session. There may be information regarding:
23 - Whether improvements have been made since the last session
24 - Any potential barriers to success
25 - Clinician's interpretation of the results of the session
26
27 Plan
28 This is another short section that states the plan for future sessions. In most settings, this section may be
29 bulleted
30 """
31).response
32
33print(result.strip())

LeMUR Q&A

This method uses the Q&A endpoint to generate each section of the SOAP note separately. This makes it easy to regenerate one or more of the categories individually if the user chooses to. The LeMUR prompt includes a question, some context on the question (with an example) and a specified answer format.

1questions = [
2 aai.LemurQuestion(
3 question="What are the patient's current symptoms or concerns?",
4 context="""
5 Gather information about the patient's subjective experience.
6 Example: The patient reports experiencing persistent headaches and dizziness.
7 """,
8 answer_format="<patient's symptoms or concerns>, [exact quote from patient]"
9 ),
10 aai.LemurQuestion(
11 question="What are the measurable and observable findings from the examination?",
12 context="""
13 Collect data on the patient's objective signs and measurements.
14 Example: The examination reveals an elevated body temperature and increased heart rate.
15 """,
16 answer_format="<measurable and observable findings>"
17 ),
18 aai.LemurQuestion(
19 question="Based on the patient's history and examination, what is your assessment or diagnosis?",
20 context="""
21 Formulate a professional assessment based on the gathered information.
22 Example: Based on the patient's symptoms, examination, and medical history, the preliminary diagnosis is migraine.
23 """,
24 answer_format="<assessment or diagnosis>"
25 ),
26 aai.LemurQuestion(
27 question="What is the plan of action or treatment for the patient?",
28 context="""
29 Outline the intended course of action or treatment.
30 Example: The treatment plan includes prescribing medication, recommending rest, and scheduling a follow-up appointment in two weeks.
31 """,
32 answer_format="<plan of action or treatment>, [exact quote from provider]"
33 )
34]
35result = transcript.lemur.question(
36 questions=questions,
37 context="this is a doctor appointment between patient and provider. the personal identification information has been redacted",
38 max_output_size=4000
39).response
40
41for x in result:
42 print(x.question)
43 print(x.answer)
44 print()