鸿蒙在线问诊预约(医生排班/视频问诊入口)详解
【摘要】 一、引言在医疗健康服务数字化转型的背景下,在线问诊已成为患者获取医疗服务的重要方式。鸿蒙操作系统(HarmonyOS)凭借其 分布式技术(分布式软总线、分布式数据管理、多设备协同)和 原子化服务能力,为在线问诊预约功能提供了 跨设备无缝体验 和 智能化服务集成 的技术基础。传统在线问诊应用存在 医生排班信息分散(不同科室/医生的排班数据孤立)、视频...
一、引言
二、技术背景
1. 鸿蒙分布式技术核心能力
-
分布式软总线:实现不同鸿蒙设备(手机、平板、车机、智能穿戴)之间的 低延迟、高带宽通信,无需依赖Wi-Fi直连或蓝牙配对,自动发现并连接周边设备,为跨设备数据同步和业务协同提供底层支持。 -
分布式数据管理(DDS):提供 跨设备数据同步 能力,通过统一的分布式数据库(如分布式偏好设置 Preferences、分布式关系型数据库 RelationalStore),将医生排班信息、用户预约记录等关键数据存储在云端或本地分布式节点,多设备实时共享最新状态。 -
原子化服务:在线问诊预约功能可封装为 鸿蒙原子化服务卡片,用户通过负一屏、桌面快捷入口快速访问医生排班信息或发起视频问诊预约,无需打开完整APP。 -
多设备协同:支持跨设备业务流转(如手机发起预约,车机接收提醒;平板查看医生详情),实现问诊预约流程的无缝衔接。
2. 在线问诊预约的业务挑战
-
医生排班数据的实时性与一致性:不同科室/医生的排班可能随时调整(如临时停诊、新增班次),需确保所有设备(手机、车机)展示的排班信息与医院后台同步。 -
视频问诊入口的统一接入:用户需通过简单的操作(如点击医生卡片)直接进入视频问诊界面,避免跳转多个页面或依赖第三方视频SDK。 -
跨设备状态同步:用户在手机端预约成功后,车机端应自动更新预约状态(如显示“已预约”),并在问诊时间到达时推送提醒。 -
安全性与隐私保护:问诊预约涉及患者个人信息(如姓名、病历)和医生资质信息,需通过鸿蒙的分布式安全框架(如设备认证、数据加密)保障数据安全。
三、应用使用场景
1. 医生排班查询(多设备实时查看)
2. 视频问诊入口集成(一键发起问诊)
3. 跨设备预约状态同步(预约记录全场景可见)
四、不同场景下详细代码实现
场景 1:医生排班查询(手机端)
1.1 核心代码实现(DoctorSchedule.ets)
// src/main/ets/pages/DoctorSchedule.ets
import { DistributedScheduleManager } from '../utils/DistributedScheduleManager.ets';
@Entry
@Component
struct DoctorSchedule {
@State private scheduleManager: DistributedScheduleManager = new DistributedScheduleManager(this.context);
@State private currentDepartment: string = '心内科'; // 当前选中的科室
@State private doctorList: Array<DoctorScheduleItem> = []; // 医生排班列表
// 医生排班数据结构
interface DoctorScheduleItem {
doctorId: string;
doctorName: string; // 医生姓名
title: string; // 职称(如主任医师、副主任医师)
availableSlots: Array<{ time: string; remaining: number }>; // 可预约时间段及剩余号源
}
aboutToAppear() {
this.loadDoctorSchedule();
}
// 加载当前科室的医生排班(从分布式数据库获取)
private loadDoctorSchedule() {
this.scheduleManager.getDoctorSchedule(this.currentDepartment).then((fetchedList) => {
this.doctorList = fetchedList || []; // 若无数据则显示空列表
}).catch((error) => {
console.error('加载医生排班失败:', error);
this.doctorList = []; // 错误时清空列表
});
}
// 切换科室(示例:点击科室标签触发)
private switchDepartment(dept: string) {
this.currentDepartment = dept;
this.loadDoctorSchedule();
}
build() {
Column() {
// 科室选择栏(简化实现)
Row() {
Text('当前科室: ')
.fontSize(16)
.fontColor('#333');
Text(this.currentDepartment)
.fontSize(16)
.fontWeight(FontWeight.Medium)
.onClick(() => {
// 实际项目中可弹出科室选择弹窗
this.switchDepartment('儿科'); // 示例:切换到儿科
});
}
.width('100%')
.margin({ bottom: 20 });
if (this.doctorList.length === 0) {
Text('暂无该科室排班信息')
.fontSize(16)
.fontColor('#999')
.margin({ top: 50 });
} else {
List() {
ForEach(this.doctorList, (doctor: DoctorScheduleItem) => {
ListItem() {
Column() {
// 医生基本信息
Row() {
Text(`${doctor.doctorName} (${doctor.title})`)
.fontSize(18)
.fontWeight(FontWeight.Bold)
.layoutWeight(1);
Text(`剩余号源: ${doctor.availableSlots.reduce((sum, slot) => sum + slot.remaining, 0)}`)
.fontSize(14)
.fontColor('#007bff');
}
.width('100%')
.margin({ bottom: 10 });
// 可预约时间段
ForEach(doctor.availableSlots, (slot: { time: string; remaining: number }) => {
if (slot.remaining > 0) {
Row() {
Text(`• ${slot.time}`)
.fontSize(14)
.fontColor('#333')
.layoutWeight(1);
Text(`(剩${slot.remaining}个)`)
.fontSize(14)
.fontColor('#28a745');
}
.width('100%')
.margin({ bottom: 5 });
}
});
// 预约入口按钮
Button('预约问诊')
.width('100%')
.margin({ top: 10 })
.onClick(() => {
// 跳转到视频问诊预约界面(传递医生ID)
router.pushUrl({
url: 'pages/VideoAppointment',
params: { doctorId: doctor.doctorId }
});
});
}
.width('100%')
.padding(15)
.backgroundColor('#f8f9fa')
.borderRadius(8)
.margin({ bottom: 10 });
}
});
}
.layoutWeight(1)
.padding(10);
}
}
.width('100%')
.height('100%')
.padding(20);
}
}
1.2 分布式排班管理工具类(DistributedScheduleManager.ets)
// src/main/ets/utils/DistributedScheduleManager.ets
import distributedData from '@ohos.data.distributedData';
import { BusinessError } from '@ohos.base';
export class DistributedScheduleManager {
private context: any; // 鸿蒙上下文
constructor(context: any) {
this.context = context;
}
// 获取指定科室的医生排班(从分布式数据库)
public async getDoctorSchedule(department: string): Promise<Array<DoctorSchedule.ets['DoctorScheduleItem']>> {
try {
// 打开或创建分布式数据库(数据标识符为 'EMR_DoctorSchedule_{department}')
const prefsKey = `EMR_DoctorSchedule_${department}`;
const preferences = await distributedData.getPreferences(this.context, prefsKey);
// 读取存储的排班数据(JSON 格式字符串)
const scheduleJson = await preferences.get('schedule', '[]');
// 解析 JSON 为对象数组
const scheduleList: Array<DoctorSchedule.ets['DoctorScheduleItem']> = JSON.parse(scheduleJson);
return scheduleList;
} catch (error) {
const err = error as BusinessError;
console.error(`获取${department}排班失败,错误码: ${err.code}, 消息: ${err.message}`);
throw new Error('分布式数据库读取排班失败');
}
}
// 更新医生排班(同步到分布式数据库,其他设备自动同步)
public async updateDoctorSchedule(department: string, schedule: Array<DoctorSchedule.ets['DoctorScheduleItem']>) {
try {
const prefsKey = `EMR_DoctorSchedule_${department}`;
const preferences = await distributedData.getPreferences(this.context, prefsKey);
// 将排班数据转换为 JSON 字符串存储
await preferences.put('schedule', JSON.stringify(schedule));
await preferences.flush(); // 确保数据写入磁盘并同步到分布式节点
} catch (error) {
const err = error as BusinessError;
console.error(`更新${department}排班失败,错误码: ${err.code}, 消息: ${err.message}`);
throw new Error('分布式数据库写入排班失败');
}
}
}
-
用户打开“医生排班”页面后,自动加载当前科室(如“心内科”)的医生排班列表,展示医生姓名、职称、可预约时间段及剩余号源; -
点击“预约问诊”按钮,跳转到视频问诊预约界面(传递医生ID); -
当医院后台更新排班信息(如新增号源),其他设备(如车机)通过分布式数据库自动同步最新数据。
场景 2:视频问诊入口(统一接入与设备适配)
2.1 核心代码实现(VideoAppointment.ets)
// src/main/ets/pages/VideoAppointment.ets
import { DistributedAppointmentManager } from '../utils/DistributedAppointmentManager.ets';
import media from '@ohos.multimedia.media';
import promptAction from '@ohos.promptAction';
@Entry
@Component
struct VideoAppointment {
@State private appointmentManager: DistributedAppointmentManager = new DistributedAppointmentManager(this.context);
@State private selectedDoctorId: string = ''; // 从路由参数获取
@State private selectedTimeSlot: string = ''; // 用户选择的问诊时间
@State private symptomDescription: string = ''; // 病情描述
@State private isBooking: boolean = false; // 是否正在预约中
aboutToAppear() {
// 从路由参数获取医生ID(实际项目中通过 router.getParams() 获取)
this.selectedDoctorId = 'doc_001'; // 示例:硬编码医生ID
}
// 选择问诊时间(示例:点击时间选项触发)
private selectTimeSlot(time: string) {
this.selectedTimeSlot = time;
}
// 提交视频问诊预约
private async submitAppointment() {
if (!this.selectedTimeSlot || !this.symptomDescription.trim()) {
promptAction.showToast({ message: '请选择问诊时间并填写病情描述' });
return;
}
this.isBooking = true;
try {
// 调用分布式预约管理工具类,保存预约信息
await this.appointmentManager.createVideoAppointment({
doctorId: this.selectedDoctorId,
timeSlot: this.selectedTimeSlot,
symptom: this.symptomDescription,
patientId: 'patient_001' // 示例:用户ID(实际从登录态获取)
});
// 预约成功后,启动视频问诊(调用鸿蒙的视频通话能力或第三方SDK)
this.startVideoConsultation();
} catch (error) {
console.error('预约失败:', error);
promptAction.showToast({ message: '预约失败,请重试' });
} finally {
this.isBooking = false;
}
}
// 启动视频问诊(简化实现:实际需集成视频SDK或调用鸿蒙媒体能力)
private startVideoConsultation() {
promptAction.showToast({ message: '正在连接医生视频问诊...' });
// 实际项目中:
// 1. 调用鸿蒙的 cameraManager 和 audioManager 初始化摄像头/麦克风
// 2. 集成视频通话SDK(如WebRTC)或使用鸿蒙原生视频能力
// 3. 跳转到视频通话界面(传递医生和患者信息)
console.log('视频问诊已启动(医生ID: ${this.selectedDoctorId}, 时间: ${this.selectedTimeSlot})');
}
build() {
Column() {
Text('视频问诊预约')
.fontSize(24)
.fontWeight(FontWeight.Bold)
.margin({ bottom: 20 });
// 医生信息(简化)
Text(`医生ID: ${this.selectedDoctorId}`)
.fontSize(16)
.fontColor('#666')
.margin({ bottom: 20 });
// 问诊时间选择
Text('选择问诊时间:')
.fontSize(16)
.margin({ bottom: 10 });
Column() {
ForEach(['3月20日 14:00-14:30', '3月20日 15:00-15:30', '3月21日 09:00-09:30'], (time: string) => {
Row() {
Text(time)
.fontSize(14)
.fontColor(this.selectedTimeSlot === time ? '#007bff' : '#333')
.layoutWeight(1);
if (this.selectedTimeSlot === time) {
Text('✓')
.fontSize(14)
.fontColor('#007bff');
}
}
.width('100%')
.padding(10)
.backgroundColor(this.selectedTimeSlot === time ? '#e3f2fd' : '#f8f9fa')
.borderRadius(4)
.margin({ bottom: 5 })
.onClick(() => {
this.selectTimeSlot(time);
});
});
}
.layoutWeight(1)
.padding(10);
// 病情描述
Text('病情描述:')
.fontSize(16)
.margin({ bottom: 10 });
TextInput({ placeholder: '请简要描述您的症状(可选)', text: this.symptomDescription })
.layoutWeight(1)
.onChange((value: string) => {
this.symptomDescription = value;
})
.margin({ bottom: 20 });
// 预约按钮
Button('确认预约')
.width('100%')
.enabled(!this.isBooking)
.onClick(() => {
this.submitAppointment();
})
.margin({ top: 20 });
}
.width('100%')
.height('100%')
.padding(20);
}
}
2.2 分布式预约管理工具类(DistributedAppointmentManager.ets)
// src/main/ets/utils/DistributedAppointmentManager.ets
import distributedData from '@ohos.data.distributedData';
import { BusinessError } from '@ohos.base';
export class DistributedAppointmentManager {
private context: any;
constructor(context: any) {
this.context = context;
}
// 创建视频问诊预约(保存到分布式数据库)
public async createVideoAppointment(appointment: {
doctorId: string;
timeSlot: string;
symptom: string;
patientId: string;
}) {
try {
// 打开或创建分布式数据库(数据标识符为 'EMR_VideoAppointments')
const preferences = await distributedData.getPreferences(this.context, 'EMR_VideoAppointments');
// 读取现有预约记录
const existingAppointmentsJson = await preferences.get('appointments', '[]');
const existingAppointments: Array<any> = JSON.parse(existingAppointmentsJson);
// 添加新预约(生成唯一ID)
const newAppointment = {
id: `apt_${Date.now()}`,
...appointment,
createTime: new Date().toISOString()
};
existingAppointments.push(newAppointment);
// 保存更新后的预约记录
await preferences.put('appointments', JSON.stringify(existingAppointments));
await preferences.flush();
} catch (error) {
const err = error as BusinessError;
console.error('创建视频预约失败,错误码: ${err.code}, 消息: ${err.message}');
throw new Error('分布式数据库写入预约失败');
}
}
}
-
用户点击医生排班列表中的“预约问诊”按钮后,进入视频问诊预约界面,选择问诊时间(如“3月20日 14:00-14:30”)并填写病情描述; -
点击“确认预约”后,系统保存预约信息到分布式数据库,并提示“正在连接医生视频问诊...”(实际项目中启动视频通话); -
预约成功后,其他设备(如车机)通过分布式数据库同步显示“已预约”状态。
五、原理解释
1. 鸿蒙在线问诊预约的核心流程
-
医生排班数据管理: -
医院后台或管理员通过分布式数据库(如 EMR_DoctorSchedule_心内科
)存储各科室医生的排班信息(医生ID、姓名、职称、可预约时间段、剩余号源)。 -
鸿蒙应用通过 DistributedScheduleManager
工具类从分布式数据库读取排班数据,展示在“医生排班”页面;当排班信息更新时,其他设备自动同步最新数据。
-
-
视频问诊入口集成: -
用户在医生排班列表中点击“预约问诊”按钮,跳转到视频问诊预约界面,选择问诊时间并填写病情描述。 -
预约信息(医生ID、问诊时间、病情描述、患者ID)通过 DistributedAppointmentManager
工具类保存到分布式数据库(如EMR_VideoAppointments
),确保多设备可访问该预约记录。
-
-
跨设备状态同步: -
所有设备(手机、车机、平板)通过分布式数据库监听同一数据标识符(如 EMR_DoctorSchedule_心内科
和EMR_VideoAppointments
),当数据变更时(如新增排班、创建预约),自动更新本地展示内容。 -
车机端可展示用户的预约记录(如“已预约:张医生,3月20日 14:00”),并在问诊时间到达前推送提醒通知。
-
-
视频问诊能力适配: -
视频问诊的实际实现依赖鸿蒙的 媒体能力(如摄像头、麦克风管理)或第三方视频SDK(如WebRTC)。 -
通过鸿蒙的分布式软总线,不同设备的摄像头/麦克风资源可被统一调度(如车机使用后置摄像头,手机使用前置摄像头),确保视频通话质量。
-
2. 关键技术点
-
分布式数据同步:医生排班和预约记录通过分布式数据库实现多设备实时同步,避免数据不一致(如手机端显示有号源,车机端显示无号源)。 -
原子化服务集成:医生排班和视频问诊功能可封装为鸿蒙原子化服务卡片,用户通过负一屏快速查看今日可预约医生或待问诊提醒。 -
设备适配与媒体管理:视频问诊支持多设备摄像头/麦克风适配(如手机、车机、平板),通过鸿蒙的媒体API(如 media
模块)统一管理硬件资源。 -
安全性保障:通过鸿蒙的分布式安全框架(如数据加密、设备认证),确保只有授权设备(如患者本人的手机、车机)可访问敏感的排班和预约数据。
六、核心特性
|
|
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
七、原理流程图及原理解释
原理流程图(在线问诊预约的整体流程)
+-----------------------+ +-----------------------+ +-----------------------+
| 用户操作(手机/车机)| | 分布式数据库(DDS) | | 医院后台/管理员 |
| (查询排班/预约问诊)| ----> | (存储排班/预约信息)| ----> | (更新排班数据) |
+-----------------------+ +-----------------------+ +-----------------------+
| | |
| 读取排班数据请求 | 数据持久化与同步 | 排班信息变更推送
|--------------------------->| |
| | 通过分布式软总线广播 | 其他设备监听并更新
| 返回排班数据(展示) | |
| | 保存预约记录 |
| 提交预约请求 | |
|--------------------------->| 同步至所有设备 |
| | 确保数据一致性 |
原理解释
-
数据存储:医生排班信息(科室、医生、时间段、号源)和预约记录(医生ID、问诊时间、患者信息)通过分布式数据库(Preferences/RelationalStore)存储,数据标识符(如 EMR_DoctorSchedule_心内科
)唯一标识不同类型的数据集合。 -
排班查询:用户在手机或车机上打开“医生排班”页面,组件通过 DistributedScheduleManager
从分布式数据库读取对应科室的排班数据(JSON 格式解析为对象数组),展示医生姓名、职称、可预约时间段及剩余号源。 -
预约提交:用户在视频问诊预约界面选择时间并填写病情描述后,点击“确认预约”, DistributedAppointmentManager
将预约信息(医生ID、问诊时间、病情描述、患者ID)保存到分布式数据库(如EMR_VideoAppointments
),其他设备自动同步该预约记录。 -
跨设备同步:分布式软总线确保所有鸿蒙设备(手机、车机、平板)实时获取最新的排班和预约数据,当医院后台更新排班或用户新增预约时,所有设备自动更新本地展示内容。 -
视频问诊触发:预约成功后,系统调用鸿蒙的媒体能力(或第三方视频SDK)启动视频通话,实现患者与医生的高清视频问诊(适配不同设备的摄像头/麦克风)。
八、环境准备
1. 开发环境
-
操作系统:Windows 10/11 或 macOS(推荐)。 -
开发工具:DevEco Studio(鸿蒙官方IDE,版本 ≥ 3.1)。 -
SDK:HarmonyOS SDK(版本 ≥ 3.2),包含分布式软总线、分布式数据库、媒体能力等相关模块。 -
设备:支持鸿蒙操作系统的手机(如华为P50)、车机(如问界M5)、平板(如MatePad)(用于真机测试)。
2. 项目创建
# 通过 DevEco Studio 创建鸿蒙应用项目
- 选择模板:Empty Ability(空能力模板)
- 设备类型:支持 Phone、Car、Tablet(多设备适配)
- HarmonyOS SDK 版本:≥ 3.2
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)