|
@@ -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
|
}
|