Engineering an Intelligent Patient Service System for Hospitals: A Technical Practice Report
This article presents the engineering practice behind an intelligent patient service assistant deployed in a hospital setting. It explains how to constrain general-purpose LLM capabilities into verifiable, traceable, and fallback-protected business functions under strict compliance, latency, and fault-tolerance requirements. The content covers a five-layer decoupled architecture, engineering breakdowns of intelligent triage, pre-consultation intake, and report interpretation, retrieval-first knowledge augmentation, security and compliance controls, performance and cost strategies, a three-tier evaluation system, an implementation roadmap, and common pitfalls to avoid.
1. Background and Problem Definition
A tertiary hospital launched an intelligent patient service assistant embedded in its official mini program in February 2025, followed by a capability upgrade in May of the same year. The core problem was not “plugging in a large language model,” but how to constrain general generative capability into business functions that are verifiable, traceable, and backed by fallbacks in a healthcare setting with strict compliance, latency, and fault-tolerance requirements.
From an engineering perspective, a patient service system must resolve three tensions at once:
- Convenience vs. safety: the freer the answers, the more likely the system produces plausible but incorrect advice.
- Generality vs. specialty: general models lack knowledge of internal department structures, visit workflows, and report conventions.
- Peak concurrency vs. stability: heavy morning traffic for registration and inquiries requires elasticity and graceful degradation.
The first design principle is therefore “layered capability, tiered risk”: clearly separate what can be fully automated (workflow guidance, time and location, explanation of report terminology) from what requires human involvement (worsening symptoms, medication adjustments, critical values).
2. Overall Architecture: Five Decoupled Layers
A practical architecture typically consists of five layers that communicate through explicit contracts, allowing independent evolution.
- Access layer: the mini program or official account entry point, responsible for identity state, session state, and telemetry collection.
- Orchestration layer: intent recognition, task routing, context assembly, tool invocation, and result composition.
- Capability layer: LLM inference, retrieval service, structured extraction, terminology normalization, and a rules engine.
- Data layer: knowledge base, vector index, business databases, and object storage (for de-identified documents).
- Governance layer: logging, monitoring and alerting, evaluation and regression, permissions, and auditing.
Illustrative orchestration pseudocode, emphasizing “constrain first, generate second”:
def handle_patient_query(session, text):intent = router.classify(text) # triage / pre-consultation / report interpretation / otherif intent == "report":ctx = retriever.fetch(knowledge="report_glossary", query=text)draft = llm.generate(prompt=build_prompt(ctx, text),schema=ReportSchema) # enforce structured outputreturn safety.check(draft) or draftif intent == "triage":risk = rules.evaluate(session.symptoms) # rules take precedence over the modelif risk.level == "high":return escalate_to_human(session) # human-in-the-loop fallbackreturn llm.generate(prompt=build_prompt(risk, text))return fallback(session) # explicit fallback message and entry guidance
3. Engineering Breakdown of Three Core Capabilities
3.1 Intelligent Triage: From Q&A to Constraint Solving
Triage is essentially constraint matching across the department tree, physician schedules, available appointment slots, and the patient’s chief complaint. Key engineering points:
- Model departments as a knowledge graph: build a reasoning structure of “symptom - body part - specialty - subspecialty - examination item” so the model does not recommend departments out of thin air.
- Multi-turn slot filling: drive follow-up questions with slots (body part, duration, accompanying symptoms, age); always ask for missing slots to prevent premature convergence.
- Fallback strategy: when confidence falls below a threshold, output “please visit the triage desk or general practice clinic first” instead of forcing a specific department.
3.2 Intelligent Pre-Consultation: Structured Capture and Record Usability
The value of pre-consultation is turning natural language into a structured summary physicians can scan quickly. Key design decisions:
- Fixed templates first: capture chief complaint, present illness history, past history, allergy history, and medication history in separate sections; the model only merges and deduplicates.
- Fact-constrained generation: every output field must be traceable to the patient’s own words or selected options; filling in unknown information is prohibited.
- Dual-view summary: physicians get “key points + timeline,” while patients get a “confirm and supplement” interaction to reduce misstatement.
A simplified structured contract example:
{"chief_complaint": "Intermittent dull upper abdominal pain for 3 days","duration": "3 days","associated": ["worse after meals"],"red_flags": [],"confidence": 0.82,"need_human_review": false}
3.3 Intelligent Report Interpretation: Terminology Normalization and Boundary Control
Report interpretation is the easiest area to overstep, so it must be strictly limited to “explanatory” rather than “diagnostic”:
- Terminology normalization: map synonymous test names to a standard vocabulary, then explain high/low values against internal reference ranges.
- Layered output: first explain each indicator, then provide a path such as “recommend re-testing or consulting a specialist,” without conclusive judgments.
- Hard rules for critical values: when a critical-value rule is triggered, interrupt generation immediately and prompt the patient to seek in-person care or contact a physician as soon as possible.
4. Knowledge Augmentation: Retrieval First, Generation Second
Healthcare scenarios should adopt retrieval-augmented generation, externalizing “memory” into a knowledge base that is updatable and auditable:
- Knowledge tiers: authoritative standards, internal workflows, and common questions, fused by priority during retrieval.
- Chunking and metadata: split by section and entry, with metadata such as department, version, and effective date for filtering.
- Visible citations: answers include source entry IDs to support manual spot checks and clear accountability.
- Update loop: workflow changes trigger knowledge version switches, with old versions retained for traceability.
5. Security, Compliance, and Risk Control
- Identity and minimization: collect only the information required to complete the service; encrypt sensitive fields and audit access.
- Two-way input/output filtering: block leading questions on the input side; detect sensitive advice and add disclaimers on the output side.
- Human-in-the-loop: define escalation paths and response time limits; force high-risk sessions to human agents and keep records.
- Explainability and traceability: retain sessions, retrieval hits, model versions, and rule hits to form a closed-loop evidence chain.
6. Performance, Elasticity, and Cost
- Layered caching: cache high-frequency answers, retrieval results, and session summaries to reduce repeated inference overhead.
- Elastic scaling: the container platform scales automatically based on queue length and latency metrics, with a message queue for peak shaving.
- Degradation plan: when the model service is unavailable, switch to rules-based Q&A and static guidance to keep the entry point available.
- Cost control: small models handle intent and extraction, while the large model is used only for necessary generation; set maximum context and output length per scenario.
7. Evaluation System and Continuous Iteration
Without evaluation there is no sustainable iteration. A three-tier evaluation is recommended:
- Offline set: covers triage accuracy, slot completeness, report interpretation compliance rate, and out-of-bounds rate.
- Online canary: roll out small traffic by department and time window, monitoring human handoff rate and satisfaction.
- Regression gate: knowledge or prompt changes must pass the regression set; any metric regression blocks the release.
Common metrics can be organized as:
| Dimension | Metrics | Target Direction |
|---|---|---|
| Triage | Department hit rate, over-questioning rate | Hit rate up, questioning down |
| Pre-consultation | Field completeness, physician adoption rate | Both up |
| Report | Terminology accuracy, out-of-bounds rate | Accuracy up, out-of-bounds down |
| System | First-token latency, human handoff rate | Latency down, reasonable handoff |
8. Suggested Implementation Roadmap
- Weeks 1-2: organize department and workflow knowledge; define structured contracts and risk rules.
- Weeks 3-4: build the retrieval and orchestration pipeline; integrate mini program identity state and telemetry.
- Weeks 5-6: build the offline evaluation set; complete out-of-bounds and critical-value red-line testing.
- Weeks 7-8: launch a canary release, ramp up department by department, and establish on-call monitoring and alerting.
- Ongoing: use human handoff samples to drive knowledge completion and prompt optimization, forming a monthly regression cycle.
9. Common Pitfalls and How to Avoid Them
- Tuning prompts without retrieval: knowledge updates make it obsolete immediately, so always prioritize retrieval.
- Letting the model freely diagnose: output boundaries must be constrained by rules and templates.
- Missing fallbacks: any insufficient confidence should have a clear human or in-person path.
- Single-metric focus: looking only at satisfaction hides out-of-bounds risk, so compliance metrics must be introduced.
In summary, the key to an intelligent patient service system is treating the large language model as a “constrained component,” embedding it into existing healthcare workflows with a knowledge base, a rules engine, structured contracts, and evaluation gates, thereby improving convenience while holding the line on safety and compliance.
