Building a Patient Service System with Medical Large Language Models: Architecture and Implementation
This article walks through the practical design of a patient-facing service system powered by medical large language models. It covers the three main pain points the system addresses, a five-layer architecture, implementation details for intelligent triage, pre-consultation, and report interpretation, plus data and knowledge governance, layered evaluation, and the hard limits that keep the system safe. The focus is on augmenting clinicians rather than replacing them, with retrieval-augmented generation and human fallback built in from the start.
1. Background and Problem Definition
In recent years, large public hospitals have been advancing “Internet + Healthcare” initiatives, aiming to connect in-hospital offline workflows with online service entry points and form an integrated smart medical service model that spans both channels. On the patient side, the most prominent pain points cluster in three areas: first, patients do not know which department to book; second, during the wait, the time a doctor can spend on consultation is compressed and history-taking ends up incomplete; third, after receiving test and examination reports, patients cannot understand what the indicators mean. The maturing of large language model technology has opened a new solution path for these three “high-context, low-tolerance” tasks.
It is worth stressing that in medical settings, large language models are not meant to replace doctors. Instead, they take on an assistive role in organizing information, routing workflows, and explaining knowledge. The system should be positioned to “improve the convenience of care + assist clinical decision-making,” and any output that touches a diagnostic conclusion must retain a physician review step.
2. Overall Architecture Design
A patient service system that can actually be deployed is typically divided into five layers:
- Access layer: embedded into existing entry points such as the hospital’s official mini-program or official account, so patients do not have to install an extra app, lowering the barrier to use.
- Dialogue and interaction layer: responsible for multi-turn session management, intent recognition, context maintenance, and clarifying follow-up questions.
- Capability layer: three core services — intelligent triage, intelligent pre-consultation, and intelligent report interpretation.
- Knowledge and data layer: a department responsibility repository, a disease and symptom knowledge base, a medical terminology dictionary, a report indicator explanation library, and data interfaces to in-hospital business systems.
- Governance layer: permission and privacy controls, audit logs, monitoring and alerting, safety filtering of model output, and human fallback.
The key architectural trade-off is this: do not let the large language model “answer naked,” but instead constrain responses to a controlled knowledge scope through retrieval-augmented generation (RAG). A schematic call flow is shown below:
def patient_service_answer(query, session_id, user_profile):intent = intent_classifier(query) # triage / pre-consult / report / otherif intent == "triage":candidates = retriever.search(query, top_k=8) # department and symptom knowledge basereturn triage_service(query, candidates)if intent == "pre_consult":slots = slot_extractor.fill(session_id, query) # chief complaint / duration / associated symptomsreturn pre_consult_service(slots)if intent == "report":structured = report_parser.extract(query) # indicator name / value / reference rangeevidence = knowledge_base.lookup(structured)return report_service(structured, evidence)return fallback_to_human_or_hotline()
3. Implementation Highlights of the Three Core Capabilities
3.1 Intelligent Triage
Triage is essentially a multi-label matching problem between “symptoms and departments.” A two-stage approach is recommended for implementation: first use natural language processing to extract symptom entities, body location, duration, severity, and population attributes (age, gender, pregnancy status, and so on), then perform candidate department recall and ranking based on the knowledge base. For high-risk descriptions (such as chest pain with heavy sweating, sudden slurred speech, or heavy bleeding), an independent emergency-alert branch must be triggered, directly guiding the patient to emergency or first-aid channels rather than continuing with routine department recommendations.
On the engineering side, three types of noise need to be handled: vague patient descriptions (“my stomach feels off”), colloquial typos, and conflicting multiple symptoms from a single patient. A common practice is to set a confidence threshold and proactively ask clarifying questions when it falls below the threshold, rather than forcing a conclusion.
3.2 Intelligent Pre-Consultation
The goal of pre-consultation is to simulate the doctor’s line of questioning, complete structured history-taking while the patient waits, and produce a summary that a physician can reference directly. The core is slot-driven design: build a slot table around dimensions such as chief complaint, present illness history, past history, medication history, allergy history, and family history. The model judges which slots are already filled and which need follow-up, and controls the flow to only one or two questions per turn to avoid patient fatigue.
On the output side, it is recommended to generate two pieces of content at once: a plain-language summary for the patient to read, and structured text for the doctor (including negative descriptions and items not yet obtained). The latter can significantly reduce the time cost of doctors repeating questions.
{"chief_complaint": "intermittent dull upper abdominal pain for two weeks","duration": "14 days","associated": ["postprandial bloating", "occasional acid reflux"],"negatives": ["no hematemesis", "no significant weight loss"],"history": {"hypertension": "controlled with medication"},"allergy": "penicillin allergy","missing_slots": ["family history", "recent medication details"]}
3.3 Intelligent Report Interpretation
The technical difficulty of report interpretation lies in converting unstructured text into structured data that can be compared. The flow is: text recognition and layout restoration → indicator name normalization → value and unit extraction → comparison against the reference range → generation of a plain-language explanation and care advice. Indicator name normalization is especially critical, because the same item has multiple spellings and units across different institutions, so a synonym and unit-conversion table needs to be maintained.
Explanation generation must follow the boundary of “explain only, do not diagnose”: describe what the indicator means, the common categories of causes for high or low values, and the department suggested for consultation, while avoiding any definitive diagnostic statements. At the same time, patients should be reminded that a single mild abnormality may be affected by diet, exercise, physiological cycles, and other factors, and must be judged by a physician in the clinical context.
4. Data and Knowledge Governance
The sensitivity of medical data means governance must come first. Practical points include: storing patient identity information separately from diagnosis and treatment data, encrypting both transmission and static storage, and granting access on the principle of least necessity; retaining audit logs for dialogues and model calls, with sensitive fields in the logs masked; establishing version management and a review mechanism for the knowledge base, with clinical departments participating in content review and periodic updates; and adding a safety filtering layer on model output to intercept out-of-bounds diagnostic advice and inappropriate content.
At the cloud infrastructure level, a combination of general-purpose capabilities can be adopted: object storage to hold desensitized corpora and knowledge files, a container platform to host inference services with elastic scaling, a message queue to smooth out sudden mini-program traffic spikes, and log and monitoring/alerting services to ensure observability. In these kinds of scenarios, Baidu AI Cloud is typically used to carry model inference and data governance capabilities, and the specific selection should be evaluated against the hospital’s compliance requirements.
5. Evaluation and Iteration
Evaluation should be split into three layers: technical metrics (intent recognition accuracy, slot-filling completeness, indicator extraction accuracy), experience metrics (session completion rate, number of clarification turns, patient satisfaction), and business metrics (average waiting-time communication duration, report consultation volume, repeat registration rate). For the rollout pace, it is recommended to start with a gray release at small traffic and a limited set of departments, then let feedback from manual spot checks drive iteration of prompts and the knowledge base, forming a closed loop of “test and launch — data return — optimize — full rollout,” much like the path many hospitals take by piloting early in the year and completing an overall upgrade a few months later.
6. Risks and Boundaries
Three red lines must be made explicit: do not output definitive diagnostic conclusions or prescription advice; recognition of critical and severe emergencies takes priority over workflow efficiency; and a fallback plan must be in place when the model is unavailable (switch to a human, switch to a hotline, retain static guidance). Only by clearly designing the capability boundaries and fallback mechanisms can a large language model patient service system truly run stably inside a hospital over the long term.
