XMLWAN před 4 roky
rodič
revize
54dbb11a6c

+ 300 - 3
controllers/new_mobile_api_controllers/new_dialysis_api_controller.go Zobrazit soubor

@@ -1,17 +1,314 @@
1 1
 package new_mobile_api_controllers
2 2
 
3 3
 import (
4
+	"XT_New/enums"
5
+	"XT_New/models"
4 6
 	"XT_New/service"
7
+	"XT_New/utils"
8
+	"encoding/json"
5 9
 	"fmt"
10
+	"github.com/jinzhu/gorm"
11
+	"strconv"
12
+	"strings"
13
+	"time"
6 14
 )
7 15
 
8 16
 type NewDialysisApiController struct {
9 17
 	NewMobileBaseAPIAuthController
10 18
 }
11 19
 
20
+func (this *NewDialysisApiController) GetIllnesslist() {
21
+
22
+	illnesslist, err := service.GetIllnessListTwo()
23
+	if err != nil {
24
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
25
+		return
26
+	}
27
+	this.ServeSuccessJSON(map[string]interface{}{
28
+		"illnesslist": illnesslist,
29
+	})
30
+}
31
+
12 32
 func (this *NewDialysisApiController) GetPatient() {
13
-	patient, err := service.GetBloodDialysisPatient(7957)
14
-	fmt.Print(patient)
15
-	fmt.Print("报错------------------", err)
33
+	adminInfo := this.GetMobileAdminUserInfo()
34
+	orgid := adminInfo.Org.Id
35
+	page, _ := this.GetInt64("page")
36
+	limit, _ := this.GetInt64("limit")
37
+	patient, total, err := service.GetBloodDialysisPatient(orgid, page, limit)
38
+	if err != nil {
39
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
40
+		return
41
+	}
42
+	this.ServeSuccessJSON(map[string]interface{}{
43
+		"patient": patient,
44
+		"total":   total,
45
+	})
46
+}
47
+
48
+func (this *NewDialysisApiController) GetAllPatient() {
49
+	fmt.Print("--------------------触发了没有")
50
+	adminInfo := this.GetMobileAdminUserInfo()
51
+	orgid := adminInfo.Org.Id
52
+	page, _ := this.GetInt64("page")
53
+	fmt.Print("page", page)
54
+	limit, _ := this.GetInt64("limit")
55
+	fmt.Print("limit", limit)
56
+	patient, err := service.GetAllPatient(orgid)
57
+	fmt.Print("err--------------------", err)
58
+	if err != nil {
59
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
60
+		return
61
+	}
62
+	this.ServeSuccessJSON(map[string]interface{}{
63
+		"patient": patient,
64
+	})
65
+}
66
+
67
+func (this *NewDialysisApiController) GetGeneratedialysisno() {
68
+	adminInfo := this.GetMobileAdminUserInfo()
69
+	orgid := adminInfo.Org.Id
70
+	dialysisNo := service.ChechLastDialysisNoTwo(orgid)
71
+	//fmt.Print("机构ID",adminUserInfo.CurrentOrgId)
72
+	if dialysisNo == 0 {
73
+		dialysisNo = 1
74
+	} else {
75
+		dialysisNo++
76
+	}
77
+	no := strconv.FormatInt(dialysisNo, 10)
78
+
79
+	rep := 3 - len(no)
80
+
81
+	if rep > 0 {
82
+		no = strings.Repeat("0", rep) + no
83
+	}
84
+
85
+	this.ServeSuccessJSON(map[string]interface{}{
86
+		"no": no,
87
+	})
88
+	return
89
+}
90
+
91
+func (this *NewDialysisApiController) SavePatient() {
92
+	adminInfo := this.GetMobileAdminUserInfo()
93
+	orgid := adminInfo.Org.Id
94
+	dataBody := make(map[string]interface{}, 0)
95
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
96
+	fmt.Print("err", err)
97
+	name := dataBody["name"].(string)
98
+	fmt.Println("姓名", name)
99
+	sex := int64(dataBody["sex"].(float64))
100
+	fmt.Print("性别", sex)
101
+	idCard := dataBody["idCard"].(string)
102
+	fmt.Print("身份证", idCard)
103
+	birthday := dataBody["birthday"].(string)
104
+	births := strings.Split(birthday, "-")
105
+	fmt.Print("生日", birthday)
106
+	birYear, _ := strconv.Atoi(births[0])
107
+	age := time.Now().Year() - birYear
108
+	ages := int64(age)
109
+	fmt.Println("age是多少", ages)
110
+	timeLayout := "2006-01-02 15:04:05"
111
+	theTime, err := utils.ParseTimeStringToTime(timeLayout, birthday+" 00:00:00")
112
+	birth := theTime.Unix()
113
+	fmt.Print(birth)
114
+	phone := dataBody["phone"].(string)
115
+	fmt.Print("电话号码", phone)
116
+	patientType := dataBody["result"].([]interface{})
117
+	fmt.Print("患者标签", patientType)
118
+	dialysis := dataBody["dialysis"].(string)
119
+	fmt.Print("透析号", dialysis)
120
+	patientsoure := int64(dataBody["patientsoure"].(float64))
121
+	fmt.Print("患者来源", patientsoure)
122
+	lapseto := int64(dataBody["lapseto"].(float64))
123
+	fmt.Print("留置状态", lapseto)
124
+	contagions := dataBody["resultTwo"].([]interface{})
125
+	fmt.Print("传染病", contagions)
126
+	adminssionNumber := dataBody["admissionNumber"].(string)
127
+	fmt.Print("住院号", adminssionNumber)
128
+	fistdate := dataBody["fistDate"].(string)
129
+	fmt.Print("首次透析日期", fistdate)
130
+	times, err := utils.ParseTimeStringToTime(timeLayout, fistdate+"00:00:00")
131
+	fisttime := times.Unix()
132
+	fmt.Print(fisttime)
133
+	diagonse := dataBody["diagnose"].(string)
134
+	fmt.Print("诊断", diagonse)
135
+	avatar := dataBody["avatar"].(string)
136
+	fmt.Print("头像", avatar)
137
+	//慢性病
138
+	requipmentId := dataBody["requipmentId"].(string)
139
+	fmt.Print("设备ID", requipmentId)
140
+	slowContagions := dataBody["resultThree"].([]interface{})
141
+	fmt.Print("慢性传染病", slowContagions)
142
+	slowDisease := int64(dataBody["slowDisease"].(float64))
143
+	fmt.Print("slowDisease", slowDisease)
144
+	bloodPatient := int64(dataBody["bloodPatient"].(float64))
145
+	fmt.Print("血透病人", bloodPatient)
146
+	slowpatient := int64(dataBody["slowPatient"].(float64))
147
+	fmt.Print("慢病病人", slowpatient)
148
+	memberpatient := int64(dataBody["memberPatient"].(float64))
149
+	fmt.Print("会员病人", memberpatient)
150
+	//会员
151
+	memberFistDate := dataBody["memberFistDate"].(string)
152
+	fmt.Print("首次透析日期", memberFistDate)
153
+	membertimes, err := utils.ParseTimeStringToTime(timeLayout, memberFistDate+"00:00:00")
154
+	memtime := membertimes.Unix()
155
+	fmt.Print(memtime)
156
+	patient_type := int64(dataBody["patientType"].(float64))
157
+	fmt.Print("病种", patient_type)
158
+	treatmentmethod := int64(dataBody["treatmentMethod"].(float64))
159
+	fmt.Print("治疗方式", treatmentmethod)
160
+
161
+	_, errcode := service.GetPatientData(phone, orgid)
162
+	if errcode == gorm.ErrRecordNotFound {
163
+		patients := models.Patients{
164
+			Name:              name,
165
+			Gender:            sex,
166
+			Birthday:          birth,
167
+			Age:               ages,
168
+			Phone:             phone,
169
+			Lapseto:           lapseto,
170
+			AdmissionNumber:   adminssionNumber,
171
+			FirstDialysisDate: fisttime,
172
+			Diagnose:          diagonse,
173
+			Source:            patientsoure,
174
+			DialysisNo:        dialysis,
175
+			UserOrgId:         orgid,
176
+			Status:            1,
177
+			CreatedTime:       time.Now().Unix(),
178
+			Avatar:            avatar,
179
+		}
180
+		err := service.CreateOldPatient(&patients)
181
+		fmt.Print("报错-------------", err)
182
+		patient, err := service.GetLastOldPatient(7957)
183
+		fmt.Print("病人ID", patient.ID)
184
+		patientsNew := models.XtPatientsNew{
185
+			Name:              name,
186
+			Gender:            sex,
187
+			Birthday:          birth,
188
+			Age:               ages,
189
+			Phone:             phone,
190
+			Lapseto:           lapseto,
191
+			AdmissionNumber:   adminssionNumber,
192
+			FirstDialysisDate: fisttime,
193
+			Diagnose:          diagonse,
194
+			Source:            patientsoure,
195
+			DialysisNo:        dialysis,
196
+			UserOrgId:         orgid,
197
+			Status:            1,
198
+			CreatedTime:       time.Now().Unix(),
199
+			Avatar:            avatar,
200
+			MemberPatients:    memberpatient,
201
+			BloodPatients:     bloodPatient,
202
+			SlowPatients:      slowpatient,
203
+			BloodId:           patient.ID,
204
+		}
205
+		err = service.CreateNewPatient(&patientsNew)
206
+		fmt.Print("报错", err)
207
+		if err != nil {
208
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
209
+			return
210
+		}
211
+		this.ServeSuccessJSON(map[string]interface{}{
212
+			"patient": patientsNew,
213
+		})
214
+	} else if errcode == nil {
215
+		fmt.Print("病人已存在")
216
+		return
217
+	} else {
218
+
219
+	}
220
+}
221
+
222
+func (this *NewDialysisApiController) GetPatientDetail() {
223
+	id, _ := this.GetInt64("id")
224
+	//获取病人详情信息
225
+	detail, err := service.GetPatientDetailTwo(id)
226
+	//获取血透医嘱管理
227
+	if err != nil {
228
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
229
+		return
230
+	}
231
+	this.ServeSuccessJSON(map[string]interface{}{
232
+		"patientDetail": detail,
233
+	})
234
+}
235
+
236
+func (this *NewDialysisApiController) GetDoctorAdvices() {
237
+	timeLayout := "2006-01-02"
238
+	loc, _ := time.LoadLocation("Local")
239
+	adminInfo := this.GetMobileAdminUserInfo()
240
+	orgid := adminInfo.Org.Id
241
+	id, _ := this.GetInt64("id")
242
+	fmt.Print("id", id)
243
+	//跟据新表id获取老表id
244
+	newPatientInfo, _ := service.GetPatientDetailTwo(id)
245
+	//获取病人ID
246
+	doctor_type, _ := this.GetInt64("type")
247
+	fmt.Print("医嘱内型", doctor_type)
248
+	start := this.GetString("startime")
249
+	fmt.Print("start", start)
250
+	startTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", start+" 00:00:00", loc)
251
+	startime := startTimes.Unix()
252
+	fmt.Print("开始时间", startime)
253
+	end := this.GetString("endtime")
254
+	fmt.Print("end", end)
255
+	endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end+" 00:00:00", loc)
256
+	endtime := endTimes.Unix()
257
+	fmt.Print("结束时间", endtime)
258
+	limit, _ := this.GetInt64("limit")
259
+	page, _ := this.GetInt64("page")
260
+	advice, total, err := service.GetNewDoctorAdvice(newPatientInfo.BloodId, doctor_type, startime, endtime, limit, page, orgid)
261
+	if err != nil {
262
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
263
+		return
264
+	}
265
+	this.ServeSuccessJSON(map[string]interface{}{
266
+		"advice": advice,
267
+		"total":  total,
268
+	})
269
+}
270
+
271
+func (this *NewDialysisApiController) GetDryWeight() {
272
+	timeLayout := "2006-01-02"
273
+	loc, _ := time.LoadLocation("Local")
274
+	id, _ := this.GetInt64("id")
275
+	fmt.Print("id", id)
276
+	patient, _ := service.GetPatientDetailTwo(id)
277
+	start := this.GetString("startime")
278
+	startTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", start+" 00:00:00", loc)
279
+	startime := startTimes.Unix()
280
+	fmt.Print("startime", startime)
281
+	end := this.GetString("endtime")
282
+	endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end+" 00:00:00", loc)
283
+	endtime := endTimes.Unix()
284
+	fmt.Print("endtime", endtime)
285
+	limit, _ := this.GetInt64("limit")
286
+	fmt.Print("limit", limit)
287
+	page, _ := this.GetInt64("page")
288
+	fmt.Print("page", page)
289
+	adminInfo := this.GetMobileAdminUserInfo()
290
+	orgid := adminInfo.Org.Id
291
+	dryweight, total, err := service.GetDryWeight(patient.BloodId, startime, endtime, limit, page, orgid)
292
+	if err != nil {
293
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
294
+		return
295
+	}
296
+	this.ServeSuccessJSON(map[string]interface{}{
297
+		"dryweight": dryweight,
298
+		"total":     total,
299
+	})
300
+}
16 301
 
302
+func (this *NewDialysisApiController) ToSearch() {
303
+	adminUser := this.GetMobileAdminUserInfo()
304
+	orgId := adminUser.Org.Id
305
+	name := this.GetString("name")
306
+	search, err := service.ToSearch(orgId, name)
307
+	if err != nil {
308
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
309
+		return
310
+	}
311
+	this.ServeSuccessJSON(map[string]interface{}{
312
+		"search": search,
313
+	})
17 314
 }

+ 8 - 0
controllers/new_mobile_api_controllers/new_mobile_api_router_register.go Zobrazit soubor

@@ -5,5 +5,13 @@ import "github.com/astaxie/beego"
5 5
 // 平板端路由,以 /m/api 为前缀
6 6
 func NewMobileAPIControllersRegisterRouters() {
7 7
 
8
+	beego.Router("m/api/patient/getillnesslist", &NewDialysisApiController{}, "Get:GetIllnesslist")
9
+	beego.Router("/m/api/patients/generatedialysisnotwo", &NewDialysisApiController{}, "Get:GetGeneratedialysisno")
8 10
 	beego.Router("/m/api/patient/getbloodDialysisPatient", &NewDialysisApiController{}, "Get:GetPatient")
11
+	beego.Router("/m/api/patient/savepatient", &NewDialysisApiController{}, "Post:SavePatient")
12
+	beego.Router("/m/api/patient/getpatientdetail", &NewDialysisApiController{}, "Get:GetPatientDetail")
13
+	beego.Router("/m/api/patient/getdoctoradvices", &NewDialysisApiController{}, "Get:GetDoctorAdvices")
14
+	beego.Router("/m/api/paitent/getdryweight", &NewDialysisApiController{}, "Get:GetDryWeight")
15
+	beego.Router("m/api/patient/getbloodDialysisPatientwo", &NewDialysisApiController{}, "Get:GetAllPatient")
16
+	beego.Router("m/api/patient/tosearch", &NewDialysisApiController{}, "Get:ToSearch")
9 17
 }

+ 110 - 0
models/patient_models.go Zobrazit soubor

@@ -379,3 +379,113 @@ type FormItem struct {
379 379
 	RangeType   int64  `json:"range_type"`
380 380
 	Value       string `json:"value"`
381 381
 }
382
+
383
+type SgjUserIllness struct {
384
+	ID          int64  `gorm:"column:id" json:"id" form:"id"`
385
+	IllnessName string `gorm:"column:illness_name" json:"illness_name" form:"illness_name"`
386
+	Status      int64  `gorm:"column:status" json:"status" form:"status"`
387
+	CreatedTime int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
388
+	UpdatedTime int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
389
+}
390
+
391
+func (SgjUserIllness) TableName() string {
392
+	return "sgj_user_illness"
393
+}
394
+
395
+type XtPatientsNew struct {
396
+	ID                           int64   `gorm:"column:id" json:"id" form:"id"`
397
+	UserOrgId                    int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
398
+	UserId                       int64   `gorm:"column:user_id" json:"user_id" form:"user_id"`
399
+	Avatar                       string  `gorm:"column:avatar" json:"avatar" form:"avatar"`
400
+	PatientType                  int64   `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
401
+	DialysisNo                   string  `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
402
+	AdmissionNumber              string  `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
403
+	Source                       int64   `gorm:"column:source" json:"source" form:"source"`
404
+	Lapseto                      int64   `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
405
+	PartitionId                  int64   `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
406
+	BedId                        int64   `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
407
+	Name                         string  `gorm:"column:name" json:"name" form:"name"`
408
+	Alias                        string  `gorm:"column:alias" json:"alias" form:"alias"`
409
+	Gender                       int64   `gorm:"column:gender" json:"gender" form:"gender"`
410
+	MaritalStatus                int64   `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
411
+	IdCardNo                     string  `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
412
+	Birthday                     int64   `gorm:"column:birthday" json:"birthday" form:"birthday"`
413
+	ReimbursementWayId           int64   `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
414
+	HealthCareType               int64   `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
415
+	HealthCareNo                 string  `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
416
+	HealthCareDueDate            int64   `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
417
+	Height                       int64   `gorm:"column:height" json:"height" form:"height"`
418
+	BloodType                    int64   `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
419
+	Rh                           int64   `gorm:"column:rh" json:"rh" form:"rh"`
420
+	HealthCareDueAlertDate       int64   `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
421
+	EducationLevel               int64   `gorm:"column:education_level" json:"education_level" form:"education_level"`
422
+	Profession                   int64   `gorm:"column:profession" json:"profession" form:"profession"`
423
+	Phone                        string  `gorm:"column:phone" json:"phone" form:"phone"`
424
+	HomeTelephone                string  `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
425
+	RelativePhone                string  `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
426
+	RelativeRelations            string  `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
427
+	HomeAddress                  string  `gorm:"column:home_address" json:"home_address" form:"home_address"`
428
+	WorkUnit                     string  `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
429
+	UnitAddress                  string  `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
430
+	Children                     int64   `gorm:"column:children" json:"children" form:"children"`
431
+	ReceivingDate                int64   `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
432
+	IsHospitalFirstDialysis      int64   `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
433
+	FirstDialysisDate            int64   `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
434
+	FirstDialysisHospital        string  `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
435
+	PredialysisCondition         string  `gorm:"column:predialysis_condition" json:"predialysis_condition" form:"predialysis_condition"`
436
+	PreHospitalDialysisFrequency string  `gorm:"column:pre_hospital_dialysis_frequency" json:"pre_hospital_dialysis_frequency" form:"pre_hospital_dialysis_frequency"`
437
+	PreHospitalDialysisTimes     int64   `gorm:"column:pre_hospital_dialysis_times" json:"pre_hospital_dialysis_times" form:"pre_hospital_dialysis_times"`
438
+	HospitalFirstDialysisDate    int64   `gorm:"column:hospital_first_dialysis_date" json:"hospital_first_dialysis_date" form:"hospital_first_dialysis_date"`
439
+	InductionPeriod              int64   `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
440
+	InitialDialysis              int64   `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
441
+	TotalDialysis                int64   `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
442
+	AttendingDoctorId            int64   `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
443
+	HeadNurseId                  int64   `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
444
+	Evaluate                     string  `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
445
+	Diagnose                     string  `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
446
+	Remark                       string  `gorm:"column:remark" json:"remark" form:"remark"`
447
+	RegistrarsId                 int64   `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
448
+	Registrars                   string  `gorm:"column:registrars" json:"registrars" form:"registrars"`
449
+	QrCode                       string  `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
450
+	BindingState                 int64   `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
451
+	PatientComplains             string  `gorm:"column:patient_complains" json:"patient_complains" form:"patient_complains"`
452
+	PresentHistory               string  `gorm:"column:present_history" json:"present_history" form:"present_history"`
453
+	PastHistory                  string  `gorm:"column:past_history" json:"past_history" form:"past_history"`
454
+	Temperature                  float64 `gorm:"column:temperature" json:"temperature" form:"temperature"`
455
+	Pulse                        int64   `gorm:"column:pulse" json:"pulse" form:"pulse"`
456
+	Respiratory                  int64   `gorm:"column:respiratory" json:"respiratory" form:"respiratory"`
457
+	Sbp                          int64   `gorm:"column:sbp" json:"sbp" form:"sbp"`
458
+	Dbp                          int64   `gorm:"column:dbp" json:"dbp" form:"dbp"`
459
+	Status                       int64   `gorm:"column:status" json:"status" form:"status"`
460
+	CreatedTime                  int64   `gorm:"column:created_time" json:"created_time" form:"created_time"`
461
+	UpdatedTime                  int64   `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
462
+	Nation                       string  `gorm:"column:nation" json:"nation" form:"nation"`
463
+	NativePlace                  string  `gorm:"column:native_place" json:"native_place" form:"native_place"`
464
+	Age                          int64   `gorm:"column:age" json:"age" form:"age"`
465
+	InfectiousNextRecordTime     int64   `gorm:"column:infectious_next_record_time" json:"infectious_next_record_time" form:"infectious_next_record_time"`
466
+	IsInfectious                 int64   `gorm:"column:is_infectious" json:"is_infectious" form:"is_infectious"`
467
+	RemindCycle                  int64   `gorm:"column:remind_cycle" json:"remind_cycle" form:"remind_cycle"`
468
+	ResponseResult               string  `gorm:"column:response_result" json:"response_result" form:"response_result"`
469
+	IsOpenRemind                 int64   `gorm:"column:is_open_remind" json:"is_open_remind" form:"is_open_remind"`
470
+	FirstTreatmentDate           int64   `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
471
+	DialysisAge                  int64   `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
472
+	ExpenseKind                  int64   `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
473
+	TellPhone                    string  `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
474
+	ContactName                  string  `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
475
+	BloodPatients                int64   `gorm:"column:blood_patients" json:"blood_patients" form:"blood_patients"`
476
+	SlowPatients                 int64   `gorm:"column:slow_patients" json:"slow_patients" form:"slow_patients"`
477
+	MemberPatients               int64   `gorm:"column:member_patients" json:"member_patients" form:"member_patients"`
478
+	EcommerPatients              string  `gorm:"column:ecommer_patients" json:"ecommer_patients" form:"ecommer_patients"`
479
+	BloodId                      int64   `gorm:"column:blood_id" json:"blood_id" form:"blood_id"`
480
+	SlowId                       int64   `gorm:"column:slow_id" json:"slow_id" form:"slow_id"`
481
+	MemberId                     int64   `gorm:"column:member_id" json:"member_id" form:"member_id"`
482
+}
483
+
484
+func (XtPatientsNew) TableName() string {
485
+	return "xt_patients_new"
486
+}
487
+
488
+type PatientsNew struct {
489
+	ID   int64  `gorm:"column:id" json:"id" form:"id"`
490
+	Name string `gorm:"column:name" json:"name" form:"name"`
491
+}

+ 0 - 1
routers/router.go Zobrazit soubor

@@ -5,7 +5,6 @@ import (
5 5
 	//admin_api "XT_New/controllers/admin_api_controllers"
6 6
 	m_api "XT_New/controllers/mobile_api_controllers"
7 7
 	new_m_api "XT_New/controllers/new_mobile_api_controllers"
8
-
9 8
 	"github.com/astaxie/beego"
10 9
 	"github.com/astaxie/beego/plugins/cors"
11 10
 )

+ 248 - 4
service/patientmanage_service.go Zobrazit soubor

@@ -1,9 +1,253 @@
1 1
 package service
2 2
 
3
-import "XT_New/models"
3
+import (
4
+	"XT_New/models"
5
+	"fmt"
6
+	"github.com/jinzhu/gorm"
7
+	"strconv"
8
+	"strings"
9
+)
4 10
 
5
-func GetBloodDialysisPatient(orgid int64) (paitents []*models.Patients, err error) {
11
+func GetIllnessListTwo() (ills []*models.Illness, err error) {
12
+	err = readUserDb.Where("status=1").Find(&ills).Error
13
+	return
14
+}
15
+
16
+func GetBloodDialysisPatient(orgid int64, page int64, limit int64) (patients []*models.Patients, total int64, err error) {
17
+	db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1")
18
+	if orgid > 0 {
19
+		db = db.Where("x.user_org_id = ?", orgid)
20
+	}
21
+	offset := (page - 1) * limit
22
+	err = db.Count(&total).Order("x.created_time desc").Offset(offset).Limit(limit).
23
+		Select("x.id,x.user_org_id,x.user_id,x.avatar,x.patient_type,x.dialysis_no,x.admission_number,x.source,x.lapseto,x.partition_id,x.bed_id,x.name,x.alias,x.gender,x.marital_status,x.id_card_no,x.birthday,x.reimbursement_way_id,x.health_care_type,x.health_care_no,x.health_care_due_date,x.height,x.blood_type,x.rh,x.health_care_due_alert_date,x.education_level,x.profession,x.phone,x.home_telephone,x.relative_phone,x.relative_relations,x.home_address,x.work_unit,x.unit_address,x.children,x.receiving_date,x.is_hospital_first_dialysis,x.first_dialysis_date,x.first_dialysis_hospital,x.predialysis_condition,x.pre_hospital_dialysis_frequency,x.pre_hospital_dialysis_times,x.hospital_first_dialysis_date,x.induction_period,x.initial_dialysis,x.total_dialysis,x.attending_doctor_id,x.head_nurse_id,x.evaluate,x.diagnose,x.remark,x.registrars_id,x.registrars,x.qr_code,x.binding_state,x.patient_complains,x.present_history,x.past_history,x.temperature,x.pulse,x.respiratory,x.sbp,x.dbp,x.status,x.created_time,x.updated_time,x.nation,x.native_place,x.age,x.blood_patients,x.slow_patients,x.member_patients,x.ecommer_patients,x.blood_id,x.slow_id,x.member_id").Find(&patients).Error
24
+	fmt.Println("err是什么", err)
25
+	return
26
+}
27
+
28
+func GetAllPatient(orgid int64) (patients []*models.PatientsNew, err error) {
29
+	db := XTReadDB().Table("xt_patients_new as x")
30
+
31
+	err = db.Raw("select id,name from xt_patients_new where user_org_id = ? and status =1", orgid).Scan(&patients).Error
32
+	return
33
+}
34
+
35
+func ChechLastDialysisNoTwo(orgID int64) (dialysisNo int64) {
36
+	var patient models.Patients
37
+	err := readDb.Model(&models.Patients{}).Where("user_org_id=? and status = 1", orgID).Order("dialysis_no desc").First(&patient).Error
38
+	if err != nil {
39
+		return
40
+	}
41
+
42
+	if patient.ID == 0 {
43
+		return
44
+	}
45
+	dialysisNo, _ = strconv.ParseInt(patient.DialysisNo, 10, 64)
46
+	return
47
+}
48
+
49
+func CreateOldPatient(patients *models.Patients) error {
50
+
51
+	err := XTWriteDB().Create(&patients).Error
52
+	return err
53
+}
54
+
55
+func GetLastOldPatient(orgid int64) (models.Patients, error) {
56
+	patients := models.Patients{}
57
+	err := XTReadDB().Model(&patients).Where("user_org_id = ? and status =1", orgid).Last(&patients).Error
58
+	return patients, err
59
+}
60
+
61
+func CreateNewPatient(patientsNew *models.XtPatientsNew) error {
62
+	err := XTWriteDB().Create(&patientsNew).Error
63
+	return err
64
+}
65
+
66
+func GetPatientDetailTwo(id int64) (models.XtPatientsNew, error) {
67
+	patients := models.XtPatientsNew{}
68
+	err := XTReadDB().Where("id=? and status = 1", id).Find(&patients).Error
69
+	return patients, err
70
+}
71
+
72
+func CreatePatientTwo(patient *models.Patients, contagions []int64, diseases []int64) (err error) {
73
+
74
+	user, _ := GetSgjUserByMobild(patient.Phone)
75
+	customer, _ := GetSgjCoustomerByMobile(patient.UserOrgId, patient.Phone)
76
+
77
+	utx := writeDb.Begin()
78
+	btx := writeUserDb.Begin()
79
+
80
+	if user.ID == 0 {
81
+
82
+		user.Mobile = patient.Phone
83
+		user.Avatar = patient.Avatar
84
+		user.AvatarThumb = patient.Avatar
85
+		user.Birthday = patient.Birthday
86
+		user.Username = patient.Name
87
+		user.Gender = patient.Gender
88
+		user.Sources = 11
89
+		user.Introduce = patient.Remark
90
+		user.Status = 1
91
+		user.UpdatedTime = patient.UpdatedTime
92
+		user.CreatedTime = patient.CreatedTime
93
+		err = btx.Create(&user).Error
94
+		if err != nil {
95
+			utx.Rollback()
96
+			btx.Rollback()
97
+			return
98
+		}
99
+	}
100
+	patient.UserId = user.ID
101
+
102
+	if customer == nil {
103
+		err = btx.Create(&models.SgjCustomer{
104
+			UserOrgId:   patient.UserOrgId,
105
+			UserId:      user.ID,
106
+			Mobile:      patient.Phone,
107
+			Name:        patient.Name,
108
+			Gender:      patient.Gender,
109
+			Birthday:    patient.Birthday,
110
+			Sources:     11,
111
+			Status:      1,
112
+			CreatedTime: patient.CreatedTime,
113
+			UpdatedTime: patient.UpdatedTime,
114
+			Avatar:      patient.Avatar,
115
+			Remark:      patient.Remark,
116
+		}).Error
117
+		if err != nil {
118
+			utx.Rollback()
119
+			btx.Rollback()
120
+			return
121
+		}
122
+	}
123
+
124
+	err = utx.Create(patient).Error
125
+	if err != nil {
126
+		utx.Rollback()
127
+		btx.Rollback()
128
+		return
129
+	}
130
+
131
+	var lapseto models.PatientLapseto
132
+	lapseto.PatientId = patient.ID
133
+	lapseto.LapsetoType = patient.Lapseto
134
+	lapseto.CreatedTime = patient.CreatedTime
135
+	lapseto.UpdatedTime = patient.CreatedTime
136
+	lapseto.Status = 1
137
+	lapseto.LapsetoTime = patient.CreatedTime
138
+
139
+	err = utx.Create(&lapseto).Error
140
+	if err != nil {
141
+		utx.Rollback()
142
+		btx.Rollback()
143
+		return
144
+	}
145
+
146
+	if len(contagions) > 0 {
147
+		thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
148
+		insertParams := make([]string, 0)
149
+		insertData := make([]interface{}, 0)
150
+		for _, contagion := range contagions {
151
+			insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
152
+			insertData = append(insertData, patient.ID)
153
+			insertData = append(insertData, contagion)
154
+			insertData = append(insertData, 1)
155
+			insertData = append(insertData, patient.CreatedTime)
156
+			insertData = append(insertData, patient.UpdatedTime)
157
+		}
158
+		thisSQL += strings.Join(insertParams, ", ")
159
+		err = utx.Exec(thisSQL, insertData...).Error
160
+		if err != nil {
161
+			utx.Rollback()
162
+			btx.Rollback()
163
+			return
164
+		}
165
+	}
166
+	if len(diseases) > 0 {
167
+		thisSQL := "INSERT INTO xt_patients_chronic_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
168
+		insertParams := make([]string, 0)
169
+		insertData := make([]interface{}, 0)
170
+		for _, disease := range diseases {
171
+			insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
172
+			insertData = append(insertData, patient.ID)
173
+			insertData = append(insertData, disease)
174
+			insertData = append(insertData, 1)
175
+			insertData = append(insertData, patient.CreatedTime)
176
+			insertData = append(insertData, patient.UpdatedTime)
177
+		}
178
+		thisSQL += strings.Join(insertParams, ", ")
179
+		err = utx.Exec(thisSQL, insertData...).Error
180
+		if err != nil {
181
+			utx.Rollback()
182
+			btx.Rollback()
183
+			return
184
+		}
185
+	}
186
+	utx.Commit()
187
+	btx.Commit()
188
+
189
+	return
190
+}
191
+
192
+func GetPatientData(phone string, orgid int64) (*models.Patients, error) {
193
+	var patientnew models.Patients
194
+	var err error
195
+	err = XTReadDB().Model(&patientnew).Where("user_org_id = ? and phone = ? and status =?", orgid, phone, 1).Find(&patientnew).Error
196
+	if err == gorm.ErrRecordNotFound {
197
+		return nil, err
198
+	}
199
+	if err != nil {
200
+		return nil, err
201
+	}
202
+	return &patientnew, nil
203
+}
204
+
205
+func GetNewDoctorAdvice(patientid int64, doctype int64, startime int64, endtime int64, limit int64, page int64, orgId int64) (doctoradvice []*models.DoctorAdvices, total int64, err error) {
206
+	db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1")
207
+	if orgId > 0 {
208
+		db = db.Where("x.user_org_id = ?", orgId)
209
+	}
210
+
211
+	if patientid > 0 {
212
+		db = db.Where("x.patient_id = ?", patientid)
213
+	}
214
+	if startime != 0 {
215
+		db = db.Where("x.record_date>= ?", startime)
216
+	}
217
+	if endtime != 0 {
218
+		db = db.Where("x.record_date<=?", endtime)
219
+	}
220
+
221
+	if doctype > 0 {
222
+		db = db.Where("x.advice_type = ?", doctype)
223
+	}
224
+	offset := (page - 1) * limit
225
+	err = db.Count(&total).Order("x.record_date desc").Offset(offset).Limit(limit).Group("x.id").Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,r.user_name").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Scan(&doctoradvice).Error
226
+	return
227
+}
228
+
229
+func GetDryWeight(patientid int64, startime int64, endtime int64, limit int64, page int64, orgId int64) (dryWeight []*models.XtPatientDryweight, total int64, err error) {
230
+	db := XTReadDB().Table("xt_patient_dryweight as x").Where("x.status = 1")
231
+	if orgId > 0 {
232
+		db = db.Where("x.user_org_id = ?", orgId)
233
+	}
234
+	if patientid > 0 {
235
+		db = db.Where("x.patient_id = ?", patientid)
236
+	}
237
+	if startime > 0 {
238
+		db = db.Where("x.ctime >= ?", startime)
239
+	}
240
+	if endtime > 0 {
241
+		db = db.Where("x.ctime <=?", endtime)
242
+	}
243
+	offset := (page - 1) * limit
244
+	err = db.Count(&total).Order("x.ctime desc").Offset(offset).Limit(limit).Group("x.id").
245
+		Select("x.id,x.dry_weight,x.creator,x.remakes,x.patient_id,x.ctime,x.adjusted_value,x.user_id,x.user_org_id,r.user_name").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.creator").Scan(&dryWeight).Error
246
+	return dryWeight, total, err
247
+}
6 248
 
7
-	err = XTReadDB().Model(&paitents).Where("user_org_id = ? and status =1", orgid).Find(&paitents).Error
8
-	return paitents, err
249
+func ToSearch(orgId int64, name string) (patient []*models.XtPatientsNew, err error) {
250
+	likeKey := "%" + name + "%"
251
+	err = XTReadDB().Where("name like ? and user_org_id = ?", likeKey, orgId).Find(&patient).Error
252
+	return patient, err
9 253
 }