Преглед на файлове

feat(patient): 实现患者健康档案管理功能

- 新增患者健康档案实体定义及API接口
- 实现健康档案的创建与更新功能
- 支持获取当前用户及指定患者的健康档案
- 在患者端档案页面集成健康档案数据加载与提交逻辑
- 添加吸烟史、饮酒史、疾病史等字段的表单处理
- 优化Snowflake ID字符串转换避免精度丢失
- 完善健康档案提交成功与失败的提示反馈
mcbaiyun преди 1 месец
родител
ревизия
ed18c84aa6
променени са 2 файла, в които са добавени 191 реда и са изтрити 13 реда
  1. 104 0
      src/api/patientHealthRecord.ts
  2. 87 13
      src/pages/patient/profile/infos/patient-filing.vue

+ 104 - 0
src/api/patientHealthRecord.ts

@@ -0,0 +1,104 @@
+import request from './request'
+
+// 患者健康档案实体
+export interface PatientHealthRecord {
+  id: string // Snowflake 64位ID 使用字符串保存以避免 JS Number 精度丢失
+  patientUserId: string
+  smokingHistory?: string // 吸烟史
+  drinkingHistory?: string // 饮酒史
+  diabetes?: boolean // 糖尿病
+  hypertension?: boolean // 高血压
+  dyslipidemia?: boolean // 血脂异常
+  coronaryHeartDisease?: boolean // 冠心病
+  cerebralInfarction?: boolean // 脑梗塞
+  allergyHistory?: string // 过敏史
+  familyHistory?: string // 家族史
+  createTime: string // 创建时间
+  updateTime: string // 更新时间
+  patientNickname?: string // 患者昵称
+}
+
+// 创建或更新健康档案请求参数
+export interface CreateOrUpdatePatientHealthRecordRequest {
+  smokingHistory?: string
+  drinkingHistory?: string
+  diabetes?: boolean
+  hypertension?: boolean
+  dyslipidemia?: boolean
+  coronaryHeartDisease?: boolean
+  cerebralInfarction?: boolean
+  allergyHistory?: string
+  familyHistory?: string
+}
+
+/**
+ * 保存健康档案
+ * @param payload 创建或更新健康档案请求参数
+ */
+export async function savePatientHealthRecord(payload: CreateOrUpdatePatientHealthRecordRequest) {
+  const res: any = await request({
+    url: 'https://wx.baiyun.work/patient-health-record/save',
+    method: 'POST',
+    header: { 'Content-Type': 'application/json' },
+    data: payload
+  })
+
+  return res
+}
+
+/**
+ * 获取当前用户健康档案
+ */
+export async function getMyHealthRecord() {
+  const res: any = await request({
+    url: 'https://wx.baiyun.work/patient-health-record/my-record',
+    method: 'GET',
+    header: { 'Content-Type': 'application/json' }
+  })
+
+  // 强制把 Snowflake ID 字段转换为字符串,避免后续使用 Number 导致精度丢失
+  try {
+    const parsed = res?.data as any
+    if (parsed && parsed.code === 200 && parsed.data) {
+      parsed.data = {
+        ...parsed.data,
+        id: String(parsed.data.id),
+        patientUserId: String(parsed.data.patientUserId)
+      }
+      res.data = parsed
+    }
+  } catch (e) {
+    // ignore
+  }
+
+  return res
+}
+
+/**
+ * 医生获取患者健康档案
+ * @param patientUserId 患者用户ID
+ */
+export async function getPatientHealthRecord(patientUserId: string | number) {
+  const res: any = await request({
+    url: `https://wx.baiyun.work/patient-health-record/patient/${encodeURIComponent(String(patientUserId))}`,
+    method: 'GET',
+    header: { 'Content-Type': 'application/json' }
+  })
+
+  // 强制把 Snowflake ID 字段转换为字符串,避免后续使用 Number 导致精度丢失
+  try {
+    const parsed = res?.data as any
+    if (parsed && parsed.code === 200 && parsed.data) {
+      parsed.data = {
+        ...parsed.data,
+        id: String(parsed.data.id),
+        patientUserId: String(parsed.data.patientUserId)
+      }
+      res.data = parsed
+    }
+  } catch (e) {
+    // ignore
+  }
+
+  return res
+}

+ 87 - 13
src/pages/patient/profile/infos/patient-filing.vue

@@ -70,7 +70,9 @@
 
 <script setup lang="ts">
 import { ref } from 'vue'
+import { onLoad } from '@dcloudio/uni-app'
 import CustomNav from '@/components/custom-nav.vue'
+import { savePatientHealthRecord, getMyHealthRecord } from '@/api/patientHealthRecord'
 
 // 吸烟选项
 const smokingOptions = [
@@ -114,6 +116,59 @@ const familyHistory = ref('')
 const hasAllergy = ref(false)
 const hasFamilyHistory = ref(false)
 
+// 加载现有健康档案数据
+const loadHealthRecord = async () => {
+  try {
+    const res = await getMyHealthRecord()
+    if (res.data.code === 200 && res.data.data) {
+      const record = res.data.data
+      // 设置吸烟史
+      if (record.smokingHistory) {
+        smokingHistory.value = record.smokingHistory
+        const index = smokingOptions.findIndex(opt => opt.value === record.smokingHistory)
+        if (index >= 0) {
+          smokingIndex.value = index
+          smokingSelected.value = true
+        }
+      }
+      // 设置饮酒史
+      if (record.drinkingHistory) {
+        drinkingHistory.value = record.drinkingHistory
+        const index = drinkingOptions.findIndex(opt => opt.value === record.drinkingHistory)
+        if (index >= 0) {
+          drinkingIndex.value = index
+          drinkingSelected.value = true
+        }
+      }
+      // 设置疾病史
+      diseaseHistory.value = {
+        diabetes: record.diabetes || false,
+        hypertension: record.hypertension || false,
+        dyslipidemia: record.dyslipidemia || false,
+        coronaryHeartDisease: record.coronaryHeartDisease || false,
+        cerebralInfarction: record.cerebralInfarction || false
+      }
+      // 设置过敏史
+      if (record.allergyHistory) {
+        allergyHistory.value = record.allergyHistory
+        hasAllergy.value = true
+      }
+      // 设置家族史
+      if (record.familyHistory) {
+        familyHistory.value = record.familyHistory
+        hasFamilyHistory.value = true
+      }
+    }
+  } catch (error) {
+    console.error('加载健康档案失败:', error)
+  }
+}
+
+// 页面加载时获取数据
+onLoad(() => {
+  loadHealthRecord()
+})
+
 // 切换疾病状态
 const toggleDisease = (key: string, value: boolean) => {
   diseaseHistory.value[key] = value
@@ -133,20 +188,39 @@ const onDrinkingChange = (e: any) => {
 }
 
 // 提交表单
-const submitForm = () => {
-  const formData = {
-    smokingHistory: smokingHistory.value,
-    drinkingHistory: drinkingHistory.value,
-    diseaseHistory: diseaseHistory.value,
-    allergyHistory: hasAllergy.value ? allergyHistory.value : '',
-    familyHistory: hasFamilyHistory.value ? familyHistory.value : ''
+const submitForm = async () => {
+  try {
+    const formData = {
+      smokingHistory: smokingHistory.value,
+      drinkingHistory: drinkingHistory.value,
+      diabetes: diseaseHistory.value.diabetes,
+      hypertension: diseaseHistory.value.hypertension,
+      dyslipidemia: diseaseHistory.value.dyslipidemia,
+      coronaryHeartDisease: diseaseHistory.value.coronaryHeartDisease,
+      cerebralInfarction: diseaseHistory.value.cerebralInfarction,
+      allergyHistory: hasAllergy.value ? allergyHistory.value : '',
+      familyHistory: hasFamilyHistory.value ? familyHistory.value : ''
+    }
+
+    const res = await savePatientHealthRecord(formData)
+    if (res.data.code === 200) {
+      uni.showToast({
+        title: '提交成功',
+        icon: 'success'
+      })
+    } else {
+      uni.showToast({
+        title: res.data.message || '提交失败',
+        icon: 'none'
+      })
+    }
+  } catch (error) {
+    console.error('提交健康档案失败:', error)
+    uni.showToast({
+      title: '提交失败,请重试',
+      icon: 'none'
+    })
   }
-  console.log('提交的表单数据:', formData)
-  // 这里可以添加提交逻辑,比如调用API
-  uni.showToast({
-    title: '提交成功',
-    icon: 'success'
-  })
 }
 </script>