135 lines
4.4 KiB
Go
135 lines
4.4 KiB
Go
package service
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"hospital-admin-api/api/dao"
|
|
"hospital-admin-api/api/model"
|
|
"hospital-admin-api/api/responses/patientFamilyResponse"
|
|
"hospital-admin-api/api/responses/userResponse"
|
|
"hospital-admin-api/utils"
|
|
)
|
|
|
|
type PatientFamilyService struct {
|
|
}
|
|
|
|
// GetPatientFamilyListByPatientId 获取患者家庭成员-患者id
|
|
func (r *PatientFamilyService) GetPatientFamilyListByPatientId(patientId int64) (u []*patientFamilyResponse.PatientFamily, err error) {
|
|
patientFamilyDao := dao.PatientFamilyDao{}
|
|
patientFamilys, err := patientFamilyDao.GetPatientFamilyListByPatientId(patientId)
|
|
|
|
if len(patientFamilys) == 0 {
|
|
return nil, nil
|
|
}
|
|
|
|
// 处理返回值
|
|
items := make([]*patientFamilyResponse.PatientFamily, len(patientFamilys))
|
|
|
|
if len(patientFamilys) > 0 {
|
|
for i, v := range patientFamilys {
|
|
// 将原始结构体转换为新结构体
|
|
item := &patientFamilyResponse.PatientFamily{
|
|
FamilyId: fmt.Sprintf("%d", v.FamilyId),
|
|
PatientId: fmt.Sprintf("%d", v.PatientId),
|
|
Relation: &v.Relation,
|
|
Status: &v.Status,
|
|
IsDefault: &v.IsDefault,
|
|
CardName: v.CardName,
|
|
CardNameMask: v.CardNameMask,
|
|
Mobile: v.Mobile,
|
|
MobileMask: v.MobileMask,
|
|
Type: &v.Type,
|
|
IdNumber: v.IdNumber,
|
|
IdNumberMask: v.IdNumberMask,
|
|
Sex: &v.Sex,
|
|
Age: v.Age,
|
|
ProvinceId: fmt.Sprintf("%d", v.ProvinceId),
|
|
Province: v.Province,
|
|
CityId: fmt.Sprintf("%d", v.CityId),
|
|
City: v.City,
|
|
CountyId: fmt.Sprintf("%d", v.CountyId),
|
|
County: v.County,
|
|
Height: v.Height,
|
|
Weight: v.Weight,
|
|
MaritalStatus: &v.MaritalStatus,
|
|
NationId: fmt.Sprintf("%d", v.NationId),
|
|
NationName: v.NationName,
|
|
JobId: fmt.Sprintf("%d", v.JobId),
|
|
JobName: v.JobName,
|
|
CreatedAt: v.CreatedAt,
|
|
UpdatedAt: v.UpdatedAt,
|
|
}
|
|
|
|
// 将转换后的结构体添加到新切片中
|
|
items[i] = item
|
|
}
|
|
}
|
|
|
|
return items, nil
|
|
}
|
|
|
|
// GetPatientFamily 家庭成员详情
|
|
func (r *PatientFamilyService) GetPatientFamily(familyId int64) (getPatientFamilyResponse *patientFamilyResponse.GetPatientFamily, err error) {
|
|
patientFamilyDao := dao.PatientFamilyDao{}
|
|
patientFamily, err := patientFamilyDao.GetPatientFamilyById(familyId)
|
|
if err != nil || patientFamily == nil {
|
|
return nil, errors.New("就诊人错误")
|
|
}
|
|
|
|
// 获取患者数据
|
|
userPatientDao := dao.UserPatientDao{}
|
|
userPatient, err := userPatientDao.GetUserPatientPreloadById(patientFamily.PatientId)
|
|
if err != nil || userPatient == nil {
|
|
return nil, errors.New("患者错误")
|
|
}
|
|
|
|
// 获取用户数据
|
|
userDao := dao.UserDao{}
|
|
user, err := userDao.GetUserById(userPatient.UserId)
|
|
if err != nil || user == nil {
|
|
return nil, errors.New("用户错误")
|
|
}
|
|
|
|
var userData *userResponse.User
|
|
if userPatient.User != nil {
|
|
userData = userResponse.UserResponse(user)
|
|
|
|
// 加密患者手机号
|
|
userData.Mobile = utils.MaskPhoneStr(userData.Mobile)
|
|
userData.WxMobile = utils.MaskPhoneStr(userData.WxMobile)
|
|
}
|
|
|
|
getPatientFamilyResponse = &patientFamilyResponse.GetPatientFamily{
|
|
FamilyId: fmt.Sprintf("%d", patientFamily.FamilyId),
|
|
PatientId: fmt.Sprintf("%d", patientFamily.PatientId),
|
|
Relation: &patientFamily.Relation,
|
|
Status: &patientFamily.Status,
|
|
IsDefault: &patientFamily.IsDefault,
|
|
CardName: patientFamily.CardName,
|
|
CardNameMask: patientFamily.CardNameMask,
|
|
MobileMask: patientFamily.MobileMask,
|
|
Type: &patientFamily.Type,
|
|
IdNumberMask: patientFamily.IdNumberMask,
|
|
Sex: &patientFamily.Sex,
|
|
Age: patientFamily.Age,
|
|
ProvinceId: fmt.Sprintf("%d", patientFamily.ProvinceId),
|
|
Province: patientFamily.Province,
|
|
CityId: fmt.Sprintf("%d", patientFamily.CityId),
|
|
City: patientFamily.City,
|
|
CountyId: fmt.Sprintf("%d", patientFamily.CountyId),
|
|
County: patientFamily.County,
|
|
Height: patientFamily.Height,
|
|
Weight: patientFamily.Weight,
|
|
MaritalStatus: &patientFamily.MaritalStatus,
|
|
NationId: fmt.Sprintf("%d", patientFamily.NationId),
|
|
NationName: patientFamily.NationName,
|
|
JobId: fmt.Sprintf("%d", patientFamily.JobId),
|
|
JobName: patientFamily.JobName,
|
|
User: userData,
|
|
CreatedAt: model.LocalTime{},
|
|
UpdatedAt: model.LocalTime{},
|
|
}
|
|
|
|
return getPatientFamilyResponse, nil
|
|
}
|