新增患者详情

This commit is contained in:
2023-09-18 14:17:40 +08:00
parent ce3168867f
commit dbe0e24241
13 changed files with 496 additions and 57 deletions
+48
View File
@@ -0,0 +1,48 @@
package service
import (
"fmt"
"hospital-admin-api/api/dao"
"hospital-admin-api/api/responses/patientFamilyResponse"
)
type PatientFamilyService struct {
}
// GetPatientFamilyListByPatientId 获取患者家庭成员-患者id
func (r *PatientFamilyService) GetPatientFamilyListByPatientId(patientId int64) (u []*patientFamilyResponse.GetUserPatient, err error) {
patientFamilyDao := dao.PatientFamilyDao{}
patientFamilys, err := patientFamilyDao.GetPatientFamilyListByPatientId(patientId)
if len(patientFamilys) == 0 {
return nil, nil
}
// 处理返回值
items := make([]*patientFamilyResponse.GetUserPatient, len(patientFamilys))
if len(patientFamilys) > 0 {
for i, v := range patientFamilys {
// 将原始结构体转换为新结构体
item := &patientFamilyResponse.GetUserPatient{
FamilyId: fmt.Sprintf("%d", v.FamilyId),
PatientId: fmt.Sprintf("%d", v.PatientId),
Relation: &v.Relation,
Status: &v.Status,
IsDefault: &v.IsDefault,
CardNameMask: v.CardNameMask,
MobileMask: v.MobileMask,
IdNumberMask: v.IdNumberMask,
Sex: &v.Sex,
Age: v.Age,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 将转换后的结构体添加到新切片中
items[i] = item
}
}
return items, nil
}
+54
View File
@@ -1,4 +1,58 @@
package service
import (
"errors"
"fmt"
"hospital-admin-api/api/dao"
"hospital-admin-api/api/responses/patientFamilyResponse"
"hospital-admin-api/api/responses/userPatientResponse"
"hospital-admin-api/api/responses/userResponse"
"hospital-admin-api/api/responses/userShipAddressResponse"
"hospital-admin-api/utils"
)
type UserPatientService struct {
}
// GetUserPatient 患者详情
func (r *UserPatientService) GetUserPatient(patientId int64) (getUserPatientResponse *userPatientResponse.GetUserPatient, err error) {
// 获取患者数据
userPatientDao := dao.UserPatientDao{}
userPatient, err := userPatientDao.GetUserPatientPreloadById(patientId)
if err != nil || userPatient == nil {
return nil, errors.New("患者错误")
}
// 患者收货地址
var userShipAddress []*userShipAddressResponse.UserShipAddress
if userPatient.UserShipAddress != nil {
userShipAddress = userShipAddressResponse.GetUserShipAddressListResponse(userPatient.UserShipAddress)
}
// 获取家庭成员数据
var patientFamilysResponse []*patientFamilyResponse.GetUserPatient
if userPatient.PatientFamily != nil {
patientFamilysResponse = patientFamilyResponse.GetUserPatientResponse(userPatient.PatientFamily)
}
// 获取用户数据
var user *userResponse.User
if userPatient.User != nil {
user = userResponse.UserResponse(userPatient.User)
}
getUserPatientResponse = &userPatientResponse.GetUserPatient{
PatientId: fmt.Sprintf("%d", userPatient.PatientId),
UserId: fmt.Sprintf("%d", userPatient.UserId),
UserName: userPatient.UserName,
Status: &userPatient.Status,
Avatar: utils.AddOssDomain(userPatient.Avatar),
Mobile: user.Mobile,
PatientFamily: patientFamilysResponse,
UserShipAddress: userShipAddress,
CreatedAt: userPatient.CreatedAt,
UpdatedAt: userPatient.UpdatedAt,
}
return getUserPatientResponse, nil
}
+57
View File
@@ -0,0 +1,57 @@
package service
import (
"fmt"
"hospital-admin-api/api/dao"
"hospital-admin-api/api/responses/userShipAddressResponse"
)
type UserShipAddressService struct {
}
// GetUserShipAddressByUserId 获取用户收货地址-用户id
func (r *UserShipAddressService) GetUserShipAddressByUserId(userId int64) (u []*userShipAddressResponse.UserShipAddress, err error) {
userShipAddressDao := dao.UserShipAddressDao{}
orderProductLogistics, err := userShipAddressDao.GetUserShipAddressListByOrderUserId(userId)
if len(orderProductLogistics) == 0 {
return nil, nil
}
// 处理返回值
items := make([]*userShipAddressResponse.UserShipAddress, len(orderProductLogistics))
if len(orderProductLogistics) > 0 {
for i, v := range orderProductLogistics {
// 将原始结构体转换为新结构体
item := &userShipAddressResponse.UserShipAddress{
AddressId: fmt.Sprintf("%d", v.AddressId),
UserId: fmt.Sprintf("%d", v.AddressId),
ProvinceId: fmt.Sprintf("%d", v.AddressId),
Province: v.Province,
CityId: fmt.Sprintf("%d", v.CityId),
City: v.City,
CountyId: fmt.Sprintf("%d", v.CountyId),
County: v.County,
ConsigneeTownId: fmt.Sprintf("%d", v.ConsigneeTownId),
ConsigneeTown: v.ConsigneeTown,
Address: v.Address,
AddressMask: v.AddressMask,
ConsigneeName: v.ConsigneeName,
ConsigneeNameMask: v.ConsigneeNameMask,
ConsigneeTel: v.ConsigneeTel,
ConsigneeTelMask: v.ConsigneeTelMask,
ConsigneeZipCode: v.ConsigneeZipCode,
IsDefault: &v.IsDefault,
Tag: &v.Tag,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 将转换后的结构体添加到新切片中
items[i] = item
}
}
return items, nil
}