diff --git a/api/controller/base.go b/api/controller/base.go index 5eb14b5..014a493 100644 --- a/api/controller/base.go +++ b/api/controller/base.go @@ -2,11 +2,13 @@ package controller // Api api接口 type Api struct { - sysSetting // 系统设置 - userDoctorManage // 医生管理 - Admin // 公共方法 - basic // 基础数据 - order // 订单管理 + sysSetting // 系统设置 + userDoctorManage // 医生管理 + Admin // 公共方法 + basic // 基础数据 + order // 订单管理 + userPatientManage // 患者管理 + caseManage // 病例管理 } // SysSetting 系统设置 @@ -39,3 +41,13 @@ type order struct { OrderInquiry // 问诊订单 OrderProduct // 药品订单 } + +// 患者管理 +type userPatientManage struct { + UserPatient // 患者列表 +} + +// 病例管理 +type caseManage struct { + Case // 患者列表 +} diff --git a/api/controller/case.go b/api/controller/case.go new file mode 100644 index 0000000..0c4e772 --- /dev/null +++ b/api/controller/case.go @@ -0,0 +1,37 @@ +// Package controller 病例管理 +package controller + +import ( + "github.com/gin-gonic/gin" + "hospital-admin-api/api/responses" + "hospital-admin-api/api/service" + "strconv" +) + +type Case struct{} + +// GetOrderInquiryCase 问诊病例详情 +func (r *Case) GetOrderInquiryCase(c *gin.Context) { + id := c.Param("inquiry_case_id") + if id == "" { + responses.FailWithMessage("缺少参数", c) + return + } + + // 将 id 转换为 int64 类型 + InquiryCaseId, err := strconv.ParseInt(id, 10, 64) + if err != nil { + responses.Fail(c) + return + } + + // 业务处理 + caseService := service.CaseService{} + getUserDoctorResponses, err := caseService.GetOrderInquiryCaseByInquiryCaseId(InquiryCaseId) + if err != nil { + responses.FailWithMessage(err.Error(), c) + return + } + + responses.OkWithData(getUserDoctorResponses, c) +} diff --git a/api/controller/userPatient.go b/api/controller/userPatient.go index 0dc5e57..3e78e14 100644 --- a/api/controller/userPatient.go +++ b/api/controller/userPatient.go @@ -1,3 +1,54 @@ package controller +import ( + "github.com/gin-gonic/gin" + "hospital-admin-api/api/dao" + "hospital-admin-api/api/requests" + "hospital-admin-api/api/responses" + "hospital-admin-api/api/responses/userPatientResponse" + "hospital-admin-api/global" + "hospital-admin-api/utils" +) + type UserPatient struct{} + +// GetUserPatientPage 获取患者列表-分页 +func (r *UserPatient) GetUserPatientPage(c *gin.Context) { + userPatientRequest := requests.UserPatientRequest{} + if err := c.ShouldBind(&userPatientRequest.GetUserPatientPage); err != nil { + responses.FailWithMessage(err.Error(), c) + return + } + + // 参数验证 + if err := global.Validate.Struct(userPatientRequest.GetUserPatientPage); err != nil { + responses.FailWithMessage(utils.Translate(err), c) + return + } + + if userPatientRequest.GetUserPatientPage.Page == 0 { + userPatientRequest.GetUserPatientPage.Page = 1 + } + + if userPatientRequest.GetUserPatientPage.PageSize == 0 { + userPatientRequest.GetUserPatientPage.PageSize = 20 + } + + userPatientDao := dao.UserPatientDao{} + userPatient, total, err := userPatientDao.GetUserPatientPageSearch(userPatientRequest.GetUserPatientPage, userPatientRequest.GetUserPatientPage.Page, userPatientRequest.GetUserPatientPage.PageSize) + + if err != nil { + responses.FailWithMessage(err.Error(), c) + return + } + + // 处理返回值 + getUserDoctorPageResponses := userPatientResponse.GetUserPatientPageResponse(userPatient) + + result := make(map[string]interface{}) + result["page"] = userPatientRequest.GetUserPatientPage.Page + result["page_size"] = userPatientRequest.GetUserPatientPage.PageSize + result["total"] = total + result["data"] = getUserDoctorPageResponses + responses.OkWithData(result, c) +} diff --git a/api/dao/patientFamilyHealth.go b/api/dao/patientFamilyHealth.go new file mode 100644 index 0000000..e6251cf --- /dev/null +++ b/api/dao/patientFamilyHealth.go @@ -0,0 +1,81 @@ +package dao + +import ( + "gorm.io/gorm" + "hospital-admin-api/api/model" + "hospital-admin-api/global" +) + +type PatientFamilyHealthDao struct { +} + +func (r *PatientFamilyHealthDao) GetPatientFamilyHealthById(familyHealthId int64) (m *model.PatientFamilyHealth, err error) { + err = global.Db.First(&m, familyHealthId).Error + if err != nil { + return nil, err + } + return m, nil +} + +func (r *PatientFamilyHealthDao) DeletePatientFamilyHealth(tx *gorm.DB, maps interface{}) error { + err := tx.Where(maps).Delete(&model.PatientFamilyHealth{}).Error + if err != nil { + return err + } + return nil +} + +func (r *PatientFamilyHealthDao) GetPatientFamilyHealthByFamilyId(familyId int64) (m *model.PatientFamilyHealth, err error) { + err = global.Db.Where("family_id = ?", familyId).First(&m).Error + if err != nil { + return nil, err + } + return m, nil +} + +func (r *PatientFamilyHealthDao) GetPatientFamilyHealthByPatientId(patientId int64) (m *model.PatientFamilyHealth, err error) { + err = global.Db.Where("patient_id = ?", patientId).First(&m).Error + if err != nil { + return nil, err + } + return m, nil +} + +func (r *PatientFamilyHealthDao) EditPatientFamilyHealth(tx *gorm.DB, maps interface{}, data interface{}) error { + err := tx.Model(&model.PatientFamilyHealth{}).Where(maps).Updates(data).Error + if err != nil { + return err + } + return nil +} + +func (r *PatientFamilyHealthDao) EditPatientFamilyHealthById(tx *gorm.DB, familyHealthId int64, data interface{}) error { + err := tx.Model(&model.PatientFamilyHealth{}).Where("family_health_id = ?", familyHealthId).Updates(data).Error + if err != nil { + return err + } + return nil +} + +func (r *PatientFamilyHealthDao) GetPatientFamilyHealthList(maps interface{}) (m []*model.PatientFamilyHealth, err error) { + err = global.Db.Where(maps).Find(&m).Error + if err != nil { + return nil, err + } + return m, nil +} + +func (r *PatientFamilyHealthDao) AddPatientFamilyHealth(tx *gorm.DB, model *model.PatientFamilyHealth) (*model.PatientFamilyHealth, error) { + if err := tx.Create(model).Error; err != nil { + return nil, err + } + return model, nil +} + +func (r *PatientFamilyHealthDao) AddPatientFamilyHealthByMap(tx *gorm.DB, data map[string]interface{}) (*model.PatientFamilyHealth, error) { + userDoctorInfo := &model.PatientFamilyHealth{} + if err := tx.Model(&model.PatientFamilyHealth{}).Create(data).Error; err != nil { + return nil, err + } + return userDoctorInfo, nil +} diff --git a/api/dao/patientFamilyPersonal.go b/api/dao/patientFamilyPersonal.go new file mode 100644 index 0000000..81b3c42 --- /dev/null +++ b/api/dao/patientFamilyPersonal.go @@ -0,0 +1,81 @@ +package dao + +import ( + "gorm.io/gorm" + "hospital-admin-api/api/model" + "hospital-admin-api/global" +) + +type PatientFamilyPersonalDao struct { +} + +func (r *PatientFamilyPersonalDao) GetPatientFamilyPersonalById(familyPersonalId int64) (m *model.PatientFamilyPersonal, err error) { + err = global.Db.First(&m, familyPersonalId).Error + if err != nil { + return nil, err + } + return m, nil +} + +func (r *PatientFamilyPersonalDao) DeletePatientFamilyPersonal(tx *gorm.DB, maps interface{}) error { + err := tx.Where(maps).Delete(&model.PatientFamilyPersonal{}).Error + if err != nil { + return err + } + return nil +} + +func (r *PatientFamilyPersonalDao) GetPatientFamilyPersonalByFamilyId(familyId int64) (m *model.PatientFamilyPersonal, err error) { + err = global.Db.Where("family_id = ?", familyId).First(&m).Error + if err != nil { + return nil, err + } + return m, nil +} + +func (r *PatientFamilyPersonalDao) GetPatientFamilyPersonalByPatientId(patientId int64) (m *model.PatientFamilyPersonal, err error) { + err = global.Db.Where("patient_id = ?", patientId).First(&m).Error + if err != nil { + return nil, err + } + return m, nil +} + +func (r *PatientFamilyPersonalDao) EditPatientFamilyPersonal(tx *gorm.DB, maps interface{}, data interface{}) error { + err := tx.Model(&model.PatientFamilyPersonal{}).Where(maps).Updates(data).Error + if err != nil { + return err + } + return nil +} + +func (r *PatientFamilyPersonalDao) EditPatientFamilyPersonalById(tx *gorm.DB, familyPersonalId int64, data interface{}) error { + err := tx.Model(&model.PatientFamilyPersonal{}).Where("family_personal_id = ?", familyPersonalId).Updates(data).Error + if err != nil { + return err + } + return nil +} + +func (r *PatientFamilyPersonalDao) GetPatientFamilyPersonalList(maps interface{}) (m []*model.PatientFamilyPersonal, err error) { + err = global.Db.Where(maps).Find(&m).Error + if err != nil { + return nil, err + } + return m, nil +} + +func (r *PatientFamilyPersonalDao) AddPatientFamilyPersonal(tx *gorm.DB, model *model.PatientFamilyPersonal) (*model.PatientFamilyPersonal, error) { + if err := tx.Create(model).Error; err != nil { + return nil, err + } + return model, nil +} + +func (r *PatientFamilyPersonalDao) AddPatientFamilyPersonalByMap(tx *gorm.DB, data map[string]interface{}) (*model.PatientFamilyPersonal, error) { + userDoctorInfo := &model.PatientFamilyPersonal{} + if err := tx.Model(&model.PatientFamilyPersonal{}).Create(data).Error; err != nil { + return nil, err + } + return userDoctorInfo, nil +} diff --git a/api/dao/userPatient.go b/api/dao/userPatient.go new file mode 100644 index 0000000..b4ff51e --- /dev/null +++ b/api/dao/userPatient.go @@ -0,0 +1,140 @@ +package dao + +import ( + "gorm.io/gorm" + "gorm.io/gorm/clause" + "hospital-admin-api/api/model" + "hospital-admin-api/api/requests" + "hospital-admin-api/global" +) + +type UserPatientDao struct { +} + +// GetUserPatientById 获取患者数据-患者id +func (r *UserPatientDao) GetUserPatientById(patientId int64) (m *model.UserPatient, err error) { + err = global.Db.First(&m, patientId).Error + if err != nil { + return nil, err + } + return m, nil +} + +// GetUserPatientPreloadById 获取患者数据-加载全部关联-患者id +func (r *UserPatientDao) GetUserPatientPreloadById(patientId int64) (m *model.UserPatient, err error) { + err = global.Db.Preload(clause.Associations).First(&m, patientId).Error + if err != nil { + return nil, err + } + return m, nil +} + +// DeleteUserPatient 删除患者 +func (r *UserPatientDao) DeleteUserPatient(tx *gorm.DB, maps interface{}) error { + err := tx.Where(maps).Delete(&model.UserPatient{}).Error + if err != nil { + return err + } + return nil +} + +// DeleteUserPatientById 删除患者-患者id +func (r *UserPatientDao) DeleteUserPatientById(tx *gorm.DB, patientId int64) error { + if err := tx.Delete(&model.UserPatient{}, patientId).Error; err != nil { + return err + } + return nil +} + +// EditUserPatient 修改患者 +func (r *UserPatientDao) EditUserPatient(tx *gorm.DB, maps interface{}, data interface{}) error { + err := tx.Model(&model.UserPatient{}).Where(maps).Updates(data).Error + if err != nil { + return err + } + return nil +} + +// EditUserPatientById 修改患者-患者id +func (r *UserPatientDao) EditUserPatientById(tx *gorm.DB, patientId int64, data interface{}) error { + err := tx.Model(&model.UserPatient{}).Where("patient_id = ?", patientId).Updates(data).Error + if err != nil { + return err + } + return nil +} + +// GetUserPatientList 获取患者列表 +func (r *UserPatientDao) GetUserPatientList(maps interface{}) (m []*model.UserPatient, err error) { + err = global.Db.Where(maps).Find(&m).Error + if err != nil { + return nil, err + } + return m, nil +} + +// GetUserPatientPageSearch 获取患者列表-分页 +func (r *UserPatientDao) GetUserPatientPageSearch(req requests.GetUserPatientPage, page, pageSize int) (m []*model.UserPatient, total int64, err error) { + var totalRecords int64 + + // 构建查询条件 + query := global.Db.Model(&model.UserPatient{}).Omit("open_id", "union_id", "wx_session_key") + + // 用户表 + query = query.Preload("User", func(db *gorm.DB) *gorm.DB { + return db.Omit("user_password", "salt") + }) + + // 家庭成员表 + query = query.Preload("PatientFamily") + + // 手机号 + if req.Mobile != "" { + subQuery := global.Db.Model(&model.User{}). + Select("user_id"). + Where("mobile LIKE ?", "%"+req.Mobile+"%") + + query = query.Where(gorm.Expr("user_id IN (?)", subQuery)) + } + + // 用户名称-用户-就诊人 + if req.UserName != "" { + // 用户 + query = query.Where("user_name LIKE ?", "%"+req.UserName+"%") + + // 就诊人 + patientFamilySubQuery := global.Db.Model(&model.PatientFamily{}). + Select("patient_id"). + Where("card_name LIKE ?", "%"+req.UserName+"%") + + query = query.Or("patient_id IN (?)", patientFamilySubQuery).Or(query) + } + + // 用户状态 + if req.Status != nil { + query = query.Where("status = ?", req.Status) + } + + // 排序 + query = query.Order("created_at desc") + + // 查询总数量 + if err := query.Count(&totalRecords).Error; err != nil { + return nil, 0, err + } + + err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error + if err != nil { + return nil, 0, err + } + + return m, totalRecords, nil +} + +// AddUserPatient 新增患者 +func (r *UserPatientDao) AddUserPatient(tx *gorm.DB, model *model.UserPatient) (*model.UserPatient, error) { + if err := tx.Create(model).Error; err != nil { + return nil, err + } + return model, nil +} diff --git a/api/model/orderInquiryCase.go b/api/model/orderInquiryCase.go index 3327e31..c8fb67e 100644 --- a/api/model/orderInquiryCase.go +++ b/api/model/orderInquiryCase.go @@ -13,11 +13,11 @@ type OrderInquiryCase struct { PatientId int64 `gorm:"column:patient_id;type:bigint(19);comment:患者id" json:"patient_id"` OrderInquiryId int64 `gorm:"column:order_inquiry_id;type:bigint(19);comment:订单-问诊id;NOT NULL" json:"order_inquiry_id"` FamilyId int64 `gorm:"column:family_id;type:bigint(19);comment:家庭成员id" json:"family_id"` - Relation int `gorm:"column:relation;type:tinyint(1);default:1;comment:与患者关系(1:本人 2:父母 3:爱人 4:子女 5:亲戚 6:其他 )" json:"relation"` - Status int `gorm:"column:status;type:tinyint(1);default:1;comment:状态(1:正常 2:删除)" json:"status"` + Relation *int `gorm:"column:relation;type:tinyint(1);default:1;comment:与患者关系(1:本人 2:父母 3:爱人 4:子女 5:亲戚 6:其他 )" json:"relation"` + Status *int `gorm:"column:status;type:tinyint(1);default:1;comment:状态(1:正常 2:删除)" json:"status"` Name string `gorm:"column:name;type:varchar(50);comment:患者名称" json:"name"` - Sex int `gorm:"column:sex;type:tinyint(1);default:0;comment:患者性别(0:未知 1:男 2:女)" json:"sex"` - Age int `gorm:"column:age;type:int(11);comment:患者年龄" json:"age"` + Sex *int `gorm:"column:sex;type:tinyint(1);default:0;comment:患者性别(0:未知 1:男 2:女)" json:"sex"` + Age *int `gorm:"column:age;type:int(11);comment:患者年龄" json:"age"` Height string `gorm:"column:height;type:varchar(100);comment:身高(cm)" json:"height"` Weight string `gorm:"column:weight;type:varchar(100);comment:体重(kg)" json:"weight"` DiseaseClassId int64 `gorm:"column:disease_class_id;type:bigint(19);comment:疾病分类id-系统" json:"disease_class_id"` @@ -25,13 +25,13 @@ type OrderInquiryCase struct { DiagnosisDate LocalTime `gorm:"column:diagnosis_date;type:datetime;comment:确诊日期" json:"diagnosis_date"` DiseaseDesc string `gorm:"column:disease_desc;type:text;comment:病情描述(主诉)" json:"disease_desc"` DiagnoseImages string `gorm:"column:diagnose_images;type:varchar(1000);comment:复诊凭证(多个使用逗号分隔)" json:"diagnose_images"` - IsAllergyHistory int `gorm:"column:is_allergy_history;type:tinyint(1);comment:是否存在过敏史(0:否 1:是)" json:"is_allergy_history"` + IsAllergyHistory *int `gorm:"column:is_allergy_history;type:tinyint(1);comment:是否存在过敏史(0:否 1:是)" json:"is_allergy_history"` AllergyHistory string `gorm:"column:allergy_history;type:varchar(255);comment:过敏史描述" json:"allergy_history"` - IsFamilyHistory int `gorm:"column:is_family_history;type:tinyint(1);comment:是否存在家族病史(0:否 1:是)" json:"is_family_history"` + IsFamilyHistory *int `gorm:"column:is_family_history;type:tinyint(1);comment:是否存在家族病史(0:否 1:是)" json:"is_family_history"` FamilyHistory string `gorm:"column:family_history;type:varchar(255);comment:家族病史描述" json:"family_history"` - IsPregnant int `gorm:"column:is_pregnant;type:tinyint(1);comment:是否备孕、妊娠、哺乳期(0:否 1:是)" json:"is_pregnant"` + IsPregnant *int `gorm:"column:is_pregnant;type:tinyint(1);comment:是否备孕、妊娠、哺乳期(0:否 1:是)" json:"is_pregnant"` Pregnant string `gorm:"column:pregnant;type:varchar(255);comment:备孕、妊娠、哺乳期描述" json:"pregnant"` - IsTaboo int `gorm:"column:is_taboo;type:tinyint(1);comment:是否服用过禁忌药物,且无相关禁忌(0:否 1:是)问诊购药时存在" json:"is_taboo"` + IsTaboo *int `gorm:"column:is_taboo;type:tinyint(1);comment:是否服用过禁忌药物,且无相关禁忌(0:否 1:是)问诊购药时存在" json:"is_taboo"` Model } diff --git a/api/model/patientFamilyHealth.go b/api/model/patientFamilyHealth.go new file mode 100644 index 0000000..6f3d325 --- /dev/null +++ b/api/model/patientFamilyHealth.go @@ -0,0 +1,39 @@ +package model + +import ( + "gorm.io/gorm" + "hospital-admin-api/global" + "time" +) + +// PatientFamilyHealth 患者家庭成员信息表-健康情况 +type PatientFamilyHealth struct { + FamilyHealthId int64 `gorm:"column:family_health_id;type:bigint(19);primary_key;comment:主键id" json:"family_health_id"` + FamilyId int64 `gorm:"column:family_id;type:bigint(19);comment:家庭成员id" json:"family_id"` + PatientId int64 `gorm:"column:patient_id;type:bigint(19);comment:患者id" json:"patient_id"` + DiseaseClassId int64 `gorm:"column:disease_class_id;type:bigint(19);comment:疾病分类id-系统" json:"disease_class_id"` + DiseaseClassName string `gorm:"column:disease_class_name;type:varchar(255);comment:疾病名称-系统" json:"disease_class_name"` + DiagnosisDate LocalTime `gorm:"column:diagnosis_date;type:date;comment:确诊日期" json:"diagnosis_date"` + DiagnosisHospital string `gorm:"column:diagnosis_hospital;type:varchar(255);comment:确诊医院" json:"diagnosis_hospital"` + IsTakeMedicine *int `gorm:"column:is_take_medicine;type:tinyint(1);comment:正在服药(0:否 1:是)" json:"is_take_medicine"` + DrugsName string `gorm:"column:drugs_name;type:varchar(255);comment:正在服药名称" json:"drugs_name"` + Model +} + +func (m *PatientFamilyHealth) TableName() string { + return "gdxz_patient_family_health" +} + +func (m *PatientFamilyHealth) BeforeCreate(tx *gorm.DB) error { + if m.FamilyHealthId == 0 { + m.FamilyHealthId = global.Snowflake.Generate().Int64() + } + + m.CreatedAt = LocalTime(time.Now()) + tx.Statement.SetColumn("CreatedAt", m.CreatedAt) + + m.UpdatedAt = LocalTime(time.Now()) + tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt) + + return nil +} diff --git a/api/model/patientFamilyPersonal.go b/api/model/patientFamilyPersonal.go new file mode 100644 index 0000000..6019b96 --- /dev/null +++ b/api/model/patientFamilyPersonal.go @@ -0,0 +1,45 @@ +package model + +import ( + "gorm.io/gorm" + "hospital-admin-api/global" + "time" +) + +// PatientFamilyPersonal 患者家庭成员信息表-个人情况 +type PatientFamilyPersonal struct { + FamilyPersonalId int64 `gorm:"column:family_personal_id;type:bigint(19);primary_key;comment:主键id" json:"family_personal_id"` + FamilyId int64 `gorm:"column:family_id;type:bigint(19);comment:信息表id" json:"family_id"` + PatientId int64 `gorm:"column:patient_id;type:bigint(19);comment:患者id" json:"patient_id"` + IsAllergyHistory *int `gorm:"column:is_allergy_history;type:tinyint(1);comment:是否存在过敏史(0:否 1:是)" json:"is_allergy_history"` + AllergyHistory string `gorm:"column:allergy_history;type:varchar(255);comment:过敏史描述" json:"allergy_history"` + IsFamilyHistory *int `gorm:"column:is_family_history;type:tinyint(1);comment:是否存在家族病史(0:否 1:是)" json:"is_family_history"` + FamilyHistory string `gorm:"column:family_history;type:varchar(255);comment:家族病史描述" json:"family_history"` + IsPregnant *int `gorm:"column:is_pregnant;type:tinyint(1);comment:是否备孕、妊娠、哺乳期(0:否 1:是)" json:"is_pregnant"` + Pregnant string `gorm:"column:pregnant;type:varchar(255);comment:备孕、妊娠、哺乳期描述" json:"pregnant"` + IsOperation *int `gorm:"column:is_operation;type:tinyint(1);comment:是否存在手术(0:否 1:是)" json:"is_operation"` + Operation string `gorm:"column:operation;type:varchar(255);comment:手术描述" json:"operation"` + DrinkWineStatus *int `gorm:"column:drink_wine_status;type:tinyint(1);comment:饮酒状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒酒)" json:"drink_wine_status"` + SmokeStatus *int `gorm:"column:smoke_status;type:tinyint(1);comment:吸烟状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒烟)" json:"smoke_status"` + ChemicalCompoundStatus *int `gorm:"column:chemical_compound_status;type:tinyint(1);comment:化合物状态(1:从不 2:偶尔 3:经常 4:每天)" json:"chemical_compound_status"` + ChemicalCompoundDescribe string `gorm:"column:chemical_compound_describe;type:varchar(255);comment:化合物描述" json:"chemical_compound_describe"` + Model +} + +func (m *PatientFamilyPersonal) TableName() string { + return "gdxz_patient_family_personal" +} + +func (m *PatientFamilyPersonal) BeforeCreate(tx *gorm.DB) error { + if m.FamilyPersonalId == 0 { + m.FamilyPersonalId = global.Snowflake.Generate().Int64() + } + + m.CreatedAt = LocalTime(time.Now()) + tx.Statement.SetColumn("CreatedAt", m.CreatedAt) + + m.UpdatedAt = LocalTime(time.Now()) + tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt) + + return nil +} diff --git a/api/model/userPatient.go b/api/model/userPatient.go index 23815f0..98142a1 100644 --- a/api/model/userPatient.go +++ b/api/model/userPatient.go @@ -8,16 +8,17 @@ import ( // UserPatient 用户-患者表 type UserPatient struct { - PatientId int64 `gorm:"column:patient_id;type:bigint(19);primary_key;comment:主键id" json:"patient_id"` - UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"` - UserName string `gorm:"column:user_name;type:varchar(100);comment:用户名称" json:"user_name"` - OpenId string `gorm:"column:open_id;type:varchar(100);comment:微信open_id" json:"open_id"` - UnionId string `gorm:"column:union_id;type:varchar(100);comment:微信开放平台唯一标识" json:"union_id"` - WxSessionKey string `gorm:"column:wx_session_key;type:varchar(255);comment:微信会话密钥" json:"wx_session_key"` - Status int `gorm:"column:status;type:tinyint(1);default:1;comment:状态(0:禁用 1:正常 2:删除)" json:"status"` - IdcardStatus int `gorm:"column:idcard_status;type:tinyint(1);default:0;comment:实名认证状态(0:未认证 1:认证通过 2:认证失败)" json:"idcard_status"` - Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"` - User *User `gorm:"foreignKey:UserId;references:user_id" json:"user"` // 用户 + PatientId int64 `gorm:"column:patient_id;type:bigint(19);primary_key;comment:主键id" json:"patient_id"` + UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"` + UserName string `gorm:"column:user_name;type:varchar(100);comment:用户名称" json:"user_name"` + OpenId string `gorm:"column:open_id;type:varchar(100);comment:微信open_id" json:"open_id"` + UnionId string `gorm:"column:union_id;type:varchar(100);comment:微信开放平台唯一标识" json:"union_id"` + WxSessionKey string `gorm:"column:wx_session_key;type:varchar(255);comment:微信会话密钥" json:"wx_session_key"` + Status int `gorm:"column:status;type:tinyint(1);default:1;comment:状态(0:禁用 1:正常 2:删除)" json:"status"` + IdcardStatus int `gorm:"column:idcard_status;type:tinyint(1);default:0;comment:实名认证状态(0:未认证 1:认证通过 2:认证失败)" json:"idcard_status"` + Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"` + User *User `gorm:"foreignKey:UserId;references:user_id" json:"user"` // 用户 + PatientFamily []*PatientFamily `gorm:"foreignKey:PatientId;references:patient_id" json:"patient_family"` // 家庭成员 Model } diff --git a/api/requests/userPatient.go b/api/requests/userPatient.go new file mode 100644 index 0000000..30a0379 --- /dev/null +++ b/api/requests/userPatient.go @@ -0,0 +1,15 @@ +package requests + +type UserPatientRequest struct { + GetUserPatientPage // 获取患者列表-分页 +} + +// GetUserPatientPage 获取患者列表-分页 +type GetUserPatientPage struct { + Page int `json:"page" form:"page" label:"页码"` + PageSize int `json:"page_size" form:"page_size" label:"每页个数"` + UserName string `json:"user_name" form:"user_name" label:"用户名称"` + Status *int `json:"status" form:"status" label:"状态"` // (0:禁用 1:正常 2:删除) + Mobile string `json:"mobile" form:"mobile" label:"手机号"` + CreatedAt string `json:"created_at" form:"created_at" label:"订单创建时间"` // 时间区间,数组形式,下标0为开始时间,下标1为结束时间 +} diff --git a/api/responses/orderInquiryCaseResponse/orderInquiryCase.go b/api/responses/orderInquiryCaseResponse/orderInquiryCase.go index 556c333..d42df9f 100644 --- a/api/responses/orderInquiryCaseResponse/orderInquiryCase.go +++ b/api/responses/orderInquiryCaseResponse/orderInquiryCase.go @@ -6,30 +6,39 @@ import ( // OrderInquiryCase 问诊病例详情 type OrderInquiryCase struct { - InquiryCaseId string `json:"inquiry_case_id"` // 主键id - UserId string `json:"user_id"` // 用户id - PatientId string `json:"patient_id"` // 患者id - OrderInquiryId string `json:"order_inquiry_id"` // 订单-问诊id;NOT NULL - FamilyId string `json:"family_id"` // 家庭成员id - Relation int `json:"relation"` // 与患者关系(1:本人 2:父母 3:爱人 4:子女 5:亲戚 6:其他) - Status int `json:"status"` // 状态(1:正常 2:删除) - Name string `json:"name"` // 患者名称 - Sex int `json:"sex"` // 患者性别(0:未知 1:男 2:女) - Age int `json:"age"` // 患者年龄 - Height string `json:"height"` // 身高(cm) - Weight string `json:"weight"` // 体重(kg) - DiseaseClassId string `json:"disease_class_id"` // 疾病分类id-系统 - DiseaseClassName string `json:"disease_class_name"` // 疾病名称-系统 - DiagnosisDate model.LocalTime `json:"diagnosis_date"` // 确诊日期 - DiseaseDesc string `json:"disease_desc"` // 病情描述(主诉) - DiagnoseImages string `json:"diagnose_images"` // 复诊凭证(多个使用逗号分隔) - IsAllergyHistory int `json:"is_allergy_history"` // 是否存在过敏史(0:否 1:是) - AllergyHistory string `json:"allergy_history"` // 过敏史描述 - IsFamilyHistory int `json:"is_family_history"` // 是否存在家族病史(0:否 1:是) - FamilyHistory string `json:"family_history"` // 家族病史描述 - IsPregnant int `json:"is_pregnant"` // 是否备孕、妊娠、哺乳期(0:否 1:是) - Pregnant string `json:"pregnant"` // 备孕、妊娠、哺乳期描述 - IsTaboo int `json:"is_taboo"` // 是否服用过禁忌药物,且无相关禁忌(0:否 1:是)问诊购药时存在 - CreatedAt model.LocalTime `json:"created_at"` // 创建时间 - UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间 + InquiryCaseId string `json:"inquiry_case_id"` // 主键id + UserId string `json:"user_id"` // 用户id + PatientId string `json:"patient_id"` // 患者id + OrderInquiryId string `json:"order_inquiry_id"` // 订单-问诊id;NOT NULL + FamilyId string `json:"family_id"` // 家庭成员id + Relation *int `json:"relation"` // 与患者关系(1:本人 2:父母 3:爱人 4:子女 5:亲戚 6:其他) + Status *int `json:"status"` // 状态(1:正常 2:删除) + Name string `json:"name"` // 患者名称 + Sex *int `json:"sex"` // 患者性别(0:未知 1:男 2:女) + Age *int `json:"age"` // 患者年龄 + Height string `json:"height"` // 身高(cm) + Weight string `json:"weight"` // 体重(kg) + DiseaseClassId string `json:"disease_class_id"` // 疾病分类id-系统 + DiseaseClassName string `json:"disease_class_name"` // 疾病名称-系统 + DiagnosisDate model.LocalTime `json:"diagnosis_date"` // 确诊日期 + DiseaseDesc string `json:"disease_desc"` // 病情描述(主诉) + DiagnoseImages string `json:"diagnose_images"` // 复诊凭证(多个使用逗号分隔) + IsAllergyHistory *int `json:"is_allergy_history"` // 是否存在过敏史(0:否 1:是) + AllergyHistory string `json:"allergy_history"` // 过敏史描述 + IsFamilyHistory *int `json:"is_family_history"` // 是否存在家族病史(0:否 1:是) + FamilyHistory string `json:"family_history"` // 家族病史描述 + IsPregnant *int `json:"is_pregnant"` // 是否备孕、妊娠、哺乳期(0:否 1:是) + Pregnant string `json:"pregnant"` // 备孕、妊娠、哺乳期描述 + IsTaboo *int `json:"is_taboo"` // 是否服用过禁忌药物,且无相关禁忌(0:否 1:是)问诊购药时存在 + DiagnosisHospital string `json:"diagnosis_hospital"` // 确诊医院 + IsTakeMedicine *int `json:"is_take_medicine"` // 正在服药(0:否 1:是) + DrugsName string `json:"drugs_name"` // 正在服药名称 + DrinkWineStatus *int `json:"drink_wine_status"` // 饮酒状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒酒) + SmokeStatus *int `json:"smoke_status"` // 吸烟状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒烟) + ChemicalCompoundStatus *int `json:"chemical_compound_status"` // 化合物状态(1:从不 2:偶尔 3:经常 4:每天) + ChemicalCompoundDescribe string `json:"chemical_compound_describe"` // 化合物描述 + IsOperation *int `json:"is_operation"` // 是否存在手术(0:否 1:是) + Operation string `json:"operation"` // 手术描述 + CreatedAt model.LocalTime `json:"created_at"` // 创建时间 + UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间 } diff --git a/api/responses/userPatientResponse/userPatient.go b/api/responses/userPatientResponse/userPatient.go new file mode 100644 index 0000000..278dc6a --- /dev/null +++ b/api/responses/userPatientResponse/userPatient.go @@ -0,0 +1,54 @@ +package userPatientResponse + +import ( + "fmt" + "hospital-admin-api/api/model" + "hospital-admin-api/utils" +) + +// getUserPatientPage 获取医生列表-分页 +type getUserPatientPage struct { + PatientId string `json:"patient_id"` // 主键id + UserId string `json:"user_id"` // 用户id;NOT NULL + UserName string `json:"user_name"` // 用户名称 + Status int `json:"status"` // 状态(0:禁用 1:正常 2:删除) + Avatar string `json:"avatar"` // 头像 + Mobile string `json:"mobile"` // 手机号 + PatientFamilyCount int `json:"patient_family_count"` // 家庭成员数量 + CreatedAt model.LocalTime `json:"created_at"` // 创建时间 + UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间 +} + +// GetUserPatientPageResponse 获取用户列表-分页 +func GetUserPatientPageResponse(userPatient []*model.UserPatient) []getUserPatientPage { + // 处理返回值 + responses := make([]getUserPatientPage, len(userPatient)) + + if len(userPatient) > 0 { + for i, v := range userPatient { + // 将原始结构体转换为新结构体 + response := getUserPatientPage{ + PatientId: fmt.Sprintf("%d", v.PatientId), + UserId: fmt.Sprintf("%d", v.UserId), + UserName: v.UserName, + Status: v.Status, + Avatar: utils.AddOssDomain(v.Avatar), + CreatedAt: v.CreatedAt, + UpdatedAt: v.UpdatedAt, + } + + if v.PatientFamily != nil { + response.PatientFamilyCount = len(v.PatientFamily) + } + + if v.User != nil { + response.Mobile = utils.MaskPhoneStr(v.User.Mobile) + } + + // 将转换后的结构体添加到新切片中 + responses[i] = response + } + } + + return responses +} diff --git a/api/router/router.go b/api/router/router.go index 3d9467c..34a31d3 100644 --- a/api/router/router.go +++ b/api/router/router.go @@ -397,11 +397,26 @@ func privateRouter(r *gin.Engine, api controller.Api) { } } + // 病例管理 + caseGroup := adminGroup.Group("/case") + { + // 问诊病例 + caseInquiryGroup := caseGroup.Group("/inquiry") + { + // 问诊病例详情 + caseInquiryGroup.GET("/:inquiry_case_id", api.Case.GetOrderInquiryCase) + + // 上报监管平台 + } + + // 检测病例 + } + // 患者管理 patientGroup := adminGroup.Group("/patient") { // 获取患者列表-分页 - patientGroup.GET("", api.UserDoctor.GetUserDoctorPage) + patientGroup.GET("", api.UserPatient.GetUserPatientPage) // 患者详情 patientGroup.GET("/:patient_id", api.UserDoctor.GetUserDoctor) diff --git a/api/service/case.go b/api/service/case.go new file mode 100644 index 0000000..ed9ecf6 --- /dev/null +++ b/api/service/case.go @@ -0,0 +1,75 @@ +package service + +import ( + "errors" + "hospital-admin-api/api/dao" + "hospital-admin-api/api/responses/orderInquiryCaseResponse" + "strconv" +) + +// CaseService 病例 +type CaseService struct { +} + +// GetOrderInquiryCaseByInquiryCaseId 获取病例-问诊订单 +func (r *CaseService) GetOrderInquiryCaseByInquiryCaseId(inquiryCaseId int64) (u *orderInquiryCaseResponse.OrderInquiryCase, err error) { + orderInquiryCaseDao := dao.OrderInquiryCaseDao{} + orderInquiryCase, err := orderInquiryCaseDao.GetOrderInquiryCaseById(inquiryCaseId) + if orderInquiryCase == nil { + return nil, errors.New("数据错误,无问诊病例") + } + + // 获取患者家庭成员信息-健康情况 + patientFamilyHealthDao := dao.PatientFamilyHealthDao{} + patientFamilyHealth, err := patientFamilyHealthDao.GetPatientFamilyHealthByFamilyId(orderInquiryCase.FamilyId) + + // 获取患者家庭成员信息表-个人情况 + patientFamilyPersonalDao := dao.PatientFamilyPersonalDao{} + patientFamilyPersonal, err := patientFamilyPersonalDao.GetPatientFamilyPersonalByFamilyId(orderInquiryCase.FamilyId) + + // 处理返回数据 + u = &orderInquiryCaseResponse.OrderInquiryCase{ + InquiryCaseId: strconv.FormatInt(orderInquiryCase.InquiryCaseId, 10), + UserId: strconv.FormatInt(orderInquiryCase.UserId, 10), + PatientId: strconv.FormatInt(orderInquiryCase.PatientId, 10), + OrderInquiryId: strconv.FormatInt(orderInquiryCase.OrderInquiryId, 10), + FamilyId: strconv.FormatInt(orderInquiryCase.FamilyId, 10), + Relation: orderInquiryCase.Relation, + Status: orderInquiryCase.Status, + Name: orderInquiryCase.Name, + Sex: orderInquiryCase.Sex, + Age: orderInquiryCase.Age, + Height: orderInquiryCase.Height, + Weight: orderInquiryCase.Weight, + DiseaseClassId: strconv.FormatInt(orderInquiryCase.DiseaseClassId, 10), + DiseaseClassName: orderInquiryCase.DiseaseClassName, + DiagnosisDate: orderInquiryCase.DiagnosisDate, + DiseaseDesc: orderInquiryCase.DiseaseDesc, + DiagnoseImages: orderInquiryCase.DiagnoseImages, + IsAllergyHistory: orderInquiryCase.IsAllergyHistory, + AllergyHistory: orderInquiryCase.AllergyHistory, + IsFamilyHistory: orderInquiryCase.IsFamilyHistory, + FamilyHistory: orderInquiryCase.FamilyHistory, + IsPregnant: orderInquiryCase.IsPregnant, + Pregnant: orderInquiryCase.Pregnant, + IsTaboo: orderInquiryCase.IsTaboo, + CreatedAt: orderInquiryCase.CreatedAt, + UpdatedAt: orderInquiryCase.UpdatedAt, + } + + if patientFamilyHealth != nil { + u.DiagnosisHospital = patientFamilyHealth.DiagnosisHospital + u.IsTakeMedicine = patientFamilyHealth.IsTakeMedicine + u.DrugsName = patientFamilyHealth.DrugsName + } + + if patientFamilyPersonal != nil { + u.DrinkWineStatus = patientFamilyPersonal.DrinkWineStatus + u.SmokeStatus = patientFamilyPersonal.SmokeStatus + u.ChemicalCompoundStatus = patientFamilyPersonal.ChemicalCompoundStatus + u.ChemicalCompoundDescribe = patientFamilyPersonal.ChemicalCompoundDescribe + u.IsOperation = patientFamilyPersonal.IsOperation + u.Operation = patientFamilyPersonal.Operation + } + return u, nil +}