Browse Source

医保对接

csx 4 years ago
parent
commit
20afd15fd0

+ 21 - 2
controllers/his_api_controller.go View File

@@ -130,6 +130,7 @@ func (c *HisApiController) GetHisPatientList() {
130 130
 	record_date := c.GetString("record_date")
131 131
 	timeLayout := "2006-01-02"
132 132
 	loc, _ := time.LoadLocation("Local")
133
+
133 134
 	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
134 135
 	if err != nil {
135 136
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -2620,6 +2621,8 @@ func (c *HisApiController) GetHisChargePatientInfo() {
2620 2621
 	start_time := c.GetString("start_time")
2621 2622
 	end_time := c.GetString("end_time")
2622 2623
 
2624
+	order_status, _ := c.GetInt64("type", 0)
2625
+
2623 2626
 	timeLayout := "2006-01-02"
2624 2627
 	loc, _ := time.LoadLocation("Local")
2625 2628
 	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
@@ -2644,8 +2647,24 @@ func (c *HisApiController) GetHisChargePatientInfo() {
2644 2647
 	admin := c.GetAdminUserInfo()
2645 2648
 	his_patient_info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, recordDateTime)
2646 2649
 	xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
2647
-	prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime)
2648
-	monthPrescriptions, _ := service.GetMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime)
2650
+
2651
+	var prescriptions []*models.HisPrescription
2652
+
2653
+	if order_status == 1 || order_status == 0 {
2654
+		prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, recordDateTime)
2655
+	} else if order_status == 2 {
2656
+		prescriptions, _ = service.GetChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, recordDateTime)
2657
+	}
2658
+
2659
+	var monthPrescriptions []*models.HisPrescription
2660
+
2661
+	if order_status == 1 || order_status == 0 {
2662
+		monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime)
2663
+	} else if order_status == 2 {
2664
+		monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFour(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime)
2665
+
2666
+	}
2667
+
2649 2668
 	case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
2650 2669
 	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
2651 2670
 	order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)

+ 647 - 0
controllers/new_mobile_api_controllers/mobile_his_api_controller.go View File

@@ -0,0 +1,647 @@
1
+package new_mobile_api_controllers
2
+
3
+import (
4
+	"XT_New/enums"
5
+	"XT_New/models"
6
+	"XT_New/service"
7
+	"XT_New/utils"
8
+	"encoding/json"
9
+	"fmt"
10
+	"math/rand"
11
+	"reflect"
12
+	"strconv"
13
+	"time"
14
+)
15
+
16
+type MobileHisApiController struct {
17
+	NewMobileBaseAPIAuthController
18
+}
19
+
20
+func (c *MobileHisApiController) GetHisPrescriptionConfig() {
21
+	adminInfo := c.GetMobileAdminUserInfo()
22
+	//获取医嘱模版
23
+	advices, _ := service.FindAllHisAdviceTemplate(adminInfo.Org.Id)
24
+	//获取所有基础药
25
+	drugs, _ := service.GetAllDrugLibList(adminInfo.Org.Id)
26
+	drugways, _, _ := service.GetDrugWayDics(adminInfo.Org.Id)
27
+	efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.Org.Id)
28
+	doctors, _ := service.GetHisAdminUserDoctors(adminInfo.Org.Id)
29
+	team, _ := service.GetAllProjectTeam(adminInfo.Org.Id)
30
+	projects, _ := service.GetHisProject(adminInfo.Org.Id)
31
+	//获取所有科室信息
32
+	department, _ := service.GetAllDepartMent(adminInfo.Org.Id)
33
+
34
+	c.ServeSuccessJSON(map[string]interface{}{
35
+		"drugs":            drugs,
36
+		"advices_template": advices,
37
+		"drugways":         drugways,
38
+		"efs":              efs,
39
+		"doctors":          doctors,
40
+		"department":       department,
41
+		"projects":         projects,
42
+		"team":             team,
43
+	})
44
+}
45
+func (c *MobileHisApiController) GetHisPatientInfo() {
46
+	patient_id, _ := c.GetInt64("patient_id")
47
+	record_date := c.GetString("record_date")
48
+	number := c.GetString("number")
49
+	start_time := c.GetString("start_time")
50
+	end_time := c.GetString("end_time")
51
+	timeLayout := "2006-01-02"
52
+	loc, _ := time.LoadLocation("Local")
53
+	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
54
+	if err != nil {
55
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
56
+		return
57
+	}
58
+	recordDateTime := theTime.Unix()
59
+
60
+	startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
61
+	if err != nil {
62
+
63
+	}
64
+	startRecordDateTime := startTime.Unix()
65
+
66
+	endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
67
+	if err != nil {
68
+
69
+	}
70
+	endRecordDateTime := endTime.Unix()
71
+
72
+	admin := c.GetMobileAdminUserInfo()
73
+	his_patient_info, _ := service.GetHisPatientInfo(admin.Org.Id, patient_id, recordDateTime)
74
+	xt_patient_info, _ := service.GetXTPatientInfo(admin.Org.Id, patient_id)
75
+	prescriptions, _ := service.GetHisPrescription(admin.Org.Id, patient_id, recordDateTime)
76
+	monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.Org.Id, patient_id, startRecordDateTime, endRecordDateTime)
77
+	case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.Org.Id, patient_id, recordDateTime)
78
+	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.Org.Id, patient_id, recordDateTime)
79
+	order, _ := service.GetHisOrder(admin.Org.Id, number, patient_id)
80
+
81
+	doctors, _ := service.GetHisAdminUserDoctors(admin.Org.Id)
82
+	//获取所有科室信息
83
+	department, _ := service.GetAllDepartMent(admin.Org.Id)
84
+
85
+	c.ServeSuccessJSON(map[string]interface{}{
86
+		"his_info":            his_patient_info,
87
+		"xt_info":             xt_patient_info,
88
+		"prescription":        prescriptions,
89
+		"case_history":        case_history,
90
+		"info":                patientPrescriptionInfo,
91
+		"month_prescriptions": monthPrescriptions,
92
+		"order":               order,
93
+		"doctors":             doctors,
94
+		"department":          department,
95
+	})
96
+	return
97
+
98
+}
99
+func (this *MobileHisApiController) GetCallHisPrescription() {
100
+	patient_id, _ := this.GetInt64("patient_id", 0)
101
+	timeLayout := "2006-01-02"
102
+	loc, _ := time.LoadLocation("Local")
103
+	start_time := this.GetString("start_time")
104
+	startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
105
+	end_time := this.GetString("end_time")
106
+	endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
107
+	adminUserInfo := this.GetMobileAdminUserInfo()
108
+	prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.Org.Id, patient_id)
109
+	if err == nil {
110
+		this.ServeSuccessJSON(map[string]interface{}{
111
+			"prescriptions": prescriptions,
112
+		})
113
+		return
114
+	} else {
115
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
116
+		return
117
+	}
118
+}
119
+func (c *MobileHisApiController) DeletePrescription() {
120
+	prescription_id, _ := c.GetInt64("id")
121
+	err := service.DelelteHisPrescription(prescription_id, c.GetMobileAdminUserInfo().Org.Id)
122
+	if err == nil {
123
+		c.ServeSuccessJSON(map[string]interface{}{
124
+			"msg": "删除成功",
125
+		})
126
+		return
127
+	} else {
128
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
129
+		return
130
+	}
131
+}
132
+func (c *MobileHisApiController) DeleteDoctorAdvice() {
133
+	id, _ := c.GetInt64("id")
134
+	//TODO 需要判断是否已经结算
135
+	err := service.DelelteDoctorAdvice(id, c.GetMobileAdminUserInfo().Org.Id)
136
+	if err == nil {
137
+		c.ServeSuccessJSON(map[string]interface{}{
138
+			"msg": "删除成功",
139
+		})
140
+		return
141
+	} else {
142
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
143
+		return
144
+	}
145
+}
146
+func (c *MobileHisApiController) DeleteProject() {
147
+	id, _ := c.GetInt64("id")
148
+	//TODO 需要判断是否已经结算
149
+	err := service.DelelteProject(id, c.GetMobileAdminUserInfo().Org.Id)
150
+	if err == nil {
151
+		c.ServeSuccessJSON(map[string]interface{}{
152
+			"msg": "删除成功",
153
+		})
154
+		return
155
+	} else {
156
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
157
+		return
158
+	}
159
+}
160
+func (c *MobileHisApiController) CreateHisPrescription() {
161
+	record_date := c.GetString("record_date")
162
+	patient_id, _ := c.GetInt64("patient_id")
163
+	reg_type, _ := c.GetInt64("reg_type")
164
+	diagnose, _ := c.GetInt64("diagnose")
165
+	sick_type, _ := c.GetInt64("sick_type")
166
+	sick_history := c.GetString("sick_history")
167
+	doctor_id, _ := c.GetInt64("doctor", 0)
168
+	department, _ := c.GetInt64("department", 0)
169
+	his_patient_id, _ := c.GetInt64("his_patient_id")
170
+	dataBody := make(map[string]interface{}, 0)
171
+	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
172
+	if err != nil {
173
+		utils.ErrorLog(err.Error())
174
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
175
+		return
176
+	}
177
+
178
+	timeLayout := "2006-01-02"
179
+	loc, _ := time.LoadLocation("Local")
180
+	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
181
+	if err != nil {
182
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
183
+		return
184
+	}
185
+	adminInfo := c.GetMobileAdminUserInfo()
186
+	recordDateTime := theTime.Unix()
187
+
188
+	role, _ := service.GetAdminUserInfoByID(adminInfo.Org.Id, doctor_id)
189
+
190
+	info, _ := service.FindPatientPrescriptionInfo(adminInfo.Org.Id, patient_id, recordDateTime)
191
+	var hpInfo models.HisPrescriptionInfo
192
+	if info.ID == 0 {
193
+		var randNum int
194
+		randNum = rand.Intn(10000) + 1000
195
+		timestamp := time.Now().Unix()
196
+		tempTime := time.Unix(timestamp, 0)
197
+		timeFormat := tempTime.Format("20060102150405")
198
+		p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.Org.Id), 10) + strconv.FormatInt(int64(patient_id), 10)
199
+
200
+		hpInfo = models.HisPrescriptionInfo{
201
+			UserOrgId:          adminInfo.Org.Id,
202
+			RecordDate:         theTime.Unix(),
203
+			PatientId:          patient_id,
204
+			Status:             1,
205
+			Ctime:              time.Now().Unix(),
206
+			Mtime:              time.Now().Unix(),
207
+			Creator:            adminInfo.AdminUser.Id,
208
+			Modifier:           adminInfo.AdminUser.Id,
209
+			Diagnosis:          diagnose,
210
+			SickHistory:        sick_history,
211
+			Departments:        department,
212
+			RegisterType:       reg_type,
213
+			PrescriptionNumber: p_number,
214
+			PrescriptionStatus: 1,
215
+			Doctor:             role.UserName,
216
+			DoctorId:           doctor_id,
217
+			SickType:           sick_type,
218
+		}
219
+		service.SavePatientPrescriptionInfo(hpInfo)
220
+
221
+	} else {
222
+		hpInfo = models.HisPrescriptionInfo{
223
+			ID:                 info.ID,
224
+			UserOrgId:          adminInfo.Org.Id,
225
+			RecordDate:         info.RecordDate,
226
+			PatientId:          info.PatientId,
227
+			Status:             1,
228
+			Ctime:              info.Ctime,
229
+			Mtime:              time.Now().Unix(),
230
+			Creator:            info.Creator,
231
+			Modifier:           adminInfo.AdminUser.Id,
232
+			Diagnosis:          diagnose,
233
+			SickHistory:        sick_history,
234
+			Departments:        department,
235
+			RegisterType:       reg_type,
236
+			PrescriptionNumber: info.PrescriptionNumber,
237
+			Doctor:             role.UserName,
238
+			PrescriptionStatus: info.PrescriptionStatus,
239
+			DoctorId:           doctor_id,
240
+			SickType:           sick_type,
241
+		}
242
+		service.SavePatientPrescriptionInfo(hpInfo)
243
+	}
244
+
245
+	if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
246
+		prescriptions, _ := dataBody["prescriptions"].([]interface{})
247
+
248
+		if len(prescriptions) > 0 {
249
+			for _, item := range prescriptions {
250
+				items := item.(map[string]interface{})
251
+				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
252
+					utils.ErrorLog("id")
253
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
254
+					return
255
+				}
256
+				id := int64(items["id"].(float64))
257
+
258
+				if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
259
+					utils.ErrorLog("type")
260
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
261
+					return
262
+				}
263
+				types := int64(items["type"].(float64))
264
+
265
+				if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
266
+					utils.ErrorLog("pre_time")
267
+				}
268
+				preTime, _ := items["pre_time"].(string)
269
+				timeLayout := "2006-01-02"
270
+				loc, _ := time.LoadLocation("Local")
271
+				theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
272
+				if err != nil {
273
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
274
+					return
275
+				}
276
+				pTime := theTime2.Unix()
277
+
278
+				ctime := time.Now().Unix()
279
+				prescription := &models.HisPrescription{
280
+					ID:                 id,
281
+					PatientId:          patient_id,
282
+					UserOrgId:          adminInfo.Org.Id,
283
+					RecordDate:         recordDateTime,
284
+					Ctime:              ctime,
285
+					Mtime:              ctime,
286
+					Type:               types,
287
+					Modifier:           adminInfo.AdminUser.Id,
288
+					Creator:            adminInfo.AdminUser.Id,
289
+					Status:             1,
290
+					Doctor:             role.UserName,
291
+					HisPatientId:       his_patient_id,
292
+					OrderStatus:        1,
293
+					BatchNumber:        "",
294
+					PrescriptionNumber: hpInfo.PrescriptionNumber,
295
+					PreTime:            pTime,
296
+				}
297
+				service.SaveHisPrescription(prescription)
298
+
299
+				//更改患者挂号状态
300
+				_, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.Org.Id)
301
+				fmt.Println("更改失败", err2)
302
+				if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
303
+					advices := items["advices"].([]interface{})
304
+					//group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
305
+					groupNo := int64(0)
306
+					ctime := time.Now().Unix()
307
+					mtime := ctime
308
+					if len(advices) > 0 {
309
+						for _, advice := range advices {
310
+							var s models.HisDoctorAdviceInfo
311
+							s.PrescriptionId = prescription.ID
312
+							s.AdviceType = 2
313
+							s.AdviceDoctor = adminInfo.AdminUser.Id
314
+							s.StopState = 2
315
+							s.ExecutionState = 2
316
+							s.AdviceDate = recordDateTime
317
+							s.Status = 1
318
+							s.UserOrgId = adminInfo.Org.Id
319
+							s.RecordDate = recordDateTime
320
+							s.StartTime = prescription.PreTime
321
+							s.Groupno = groupNo
322
+							s.CreatedTime = ctime
323
+							s.UpdatedTime = mtime
324
+							s.PatientId = patient_id
325
+							s.HisPatientId = his_patient_id
326
+							errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
327
+							if errcode > 0 {
328
+								c.ServeFailJSONWithSGJErrorCode(errcode)
329
+								return
330
+							}
331
+							service.CreateHisDoctorAdvice(&s)
332
+							var randNum int
333
+							randNum = rand.Intn(10000) + 1000
334
+							timestamp := time.Now().Unix()
335
+							tempTime := time.Unix(timestamp, 0)
336
+							timeFormat := tempTime.Format("20060102150405")
337
+							s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
338
+							service.CreateHisDoctorAdvice(&s)
339
+
340
+						}
341
+					}
342
+				}
343
+				if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
344
+					projects := items["project"].([]interface{})
345
+					if len(projects) > 0 {
346
+						for _, project := range projects {
347
+							var p models.HisPrescriptionProject
348
+							p.PrescriptionId = prescription.ID
349
+							p.Ctime = time.Now().Unix()
350
+							p.Mtime = time.Now().Unix()
351
+							p.PatientId = patient_id
352
+							p.RecordDate = recordDateTime
353
+							p.UserOrgId = adminInfo.Org.Id
354
+							p.HisPatientId = his_patient_id
355
+							p.Status = 1
356
+							errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
357
+							if errcode > 0 {
358
+								c.ServeFailJSONWithSGJErrorCode(errcode)
359
+								return
360
+							}
361
+							service.CreateHisProjectTwo(&p)
362
+							var randNum int
363
+							randNum = rand.Intn(10000) + 1000
364
+							timestamp := time.Now().Unix()
365
+							tempTime := time.Unix(timestamp, 0)
366
+							timeFormat := tempTime.Format("20060102150405")
367
+							p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
368
+							service.SaveHisProjectTwo(&p)
369
+
370
+						}
371
+					}
372
+				}
373
+
374
+			}
375
+		}
376
+	}
377
+	if err == nil {
378
+		c.ServeSuccessJSON(map[string]interface{}{
379
+			"msg": "保存成功",
380
+		})
381
+		return
382
+
383
+	} else {
384
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
385
+		return
386
+	}
387
+}
388
+func (this *MobileHisApiController) GetLastOrNextHisPrescription() {
389
+	change_type, _ := this.GetInt64("type", 0)
390
+	record_date := this.GetString("record_time")
391
+	patient_id, _ := this.GetInt64("patient_id", 0)
392
+
393
+	timeLayout := "2006-01-02"
394
+	loc, _ := time.LoadLocation("Local")
395
+	theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
396
+	record_time := theAdviceRecordTime.Unix()
397
+	adminUserInfo := this.GetMobileAdminUserInfo()
398
+	prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
399
+	if err == nil {
400
+		if len(prescriptions) == 0 {
401
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
402
+			return
403
+		} else {
404
+			this.ServeSuccessJSON(map[string]interface{}{
405
+				"prescriptions": prescriptions,
406
+			})
407
+			return
408
+		}
409
+	} else {
410
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
411
+		return
412
+	}
413
+}
414
+func (c *MobileHisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
415
+
416
+	if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
417
+		utils.ErrorLog("drug_name")
418
+		return enums.ErrorCodeParamWrong
419
+	}
420
+	adviceName, _ := json["drug_name"].(string)
421
+	if len(adviceName) == 0 {
422
+		utils.ErrorLog("len(advice_name) == 0")
423
+		return enums.ErrorCodeParamWrong
424
+	}
425
+	advice.AdviceName = adviceName
426
+	adviceDesc, _ := json["advice_desc"].(string)
427
+	advice.AdviceDesc = adviceDesc
428
+	if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
429
+		drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
430
+		advice.DrugSpec = drugSpec
431
+	}
432
+	if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
433
+		remark, _ := json["remark"].(string)
434
+		advice.Remark = remark
435
+	}
436
+	if json["id"] == nil {
437
+		advice.DrugId = 0
438
+	} else {
439
+		if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
440
+			drug_id := int64(json["id"].(float64))
441
+			advice.DrugId = drug_id
442
+		}
443
+	}
444
+	if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
445
+		advice_id := int64(json["advice_id"].(float64))
446
+		advice.ID = advice_id
447
+		if advice.ID > 0 {
448
+			hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
449
+			if err == nil {
450
+				if hisAdvice.ID > 0 {
451
+					advice.ExecutionTime = hisAdvice.ExecutionTime
452
+					advice.ExecutionStaff = hisAdvice.ExecutionStaff
453
+					advice.ExecutionState = hisAdvice.ExecutionState
454
+					advice.CheckTime = hisAdvice.CheckTime
455
+					advice.Checker = hisAdvice.Checker
456
+					advice.CheckState = hisAdvice.CheckState
457
+					advice.StartTime = hisAdvice.StartTime
458
+
459
+				}
460
+			}
461
+		}
462
+	}
463
+
464
+	//
465
+	//if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
466
+	//	execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
467
+	//	advice.ExecutionTime = execution_time
468
+	//}
469
+	//
470
+	//
471
+	//
472
+	//if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
473
+	//	execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
474
+	//	advice.ExecutionStaff = execution_staff
475
+	//}
476
+	//
477
+	//
478
+	//
479
+	//if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
480
+	//	execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
481
+	//	advice.ExecutionState = execution_state
482
+	//}
483
+	//
484
+	//
485
+	//if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
486
+	//	check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
487
+	//	advice.CheckTime = check_time
488
+	//}
489
+	//
490
+	//
491
+	//if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
492
+	//	check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
493
+	//	advice.CheckState = check_state
494
+	//}
495
+	//
496
+	//
497
+	//if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
498
+	//	checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
499
+	//	advice.Checker = checker
500
+	//}
501
+	//
502
+	//if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
503
+	//	start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
504
+	//	advice.StartTime = start_time
505
+	//}
506
+
507
+	if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
508
+		drugSpecUnit, _ := json["min_unit"].(string)
509
+		advice.DrugSpecUnit = drugSpecUnit
510
+	}
511
+	if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
512
+		singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
513
+		advice.SingleDose = singleDose
514
+	}
515
+	if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
516
+		singleDoseUnit, _ := json["single_dose_unit"].(string)
517
+		advice.SingleDoseUnit = singleDoseUnit
518
+	}
519
+	if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
520
+		prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
521
+		advice.PrescribingNumber = prescribingNumber
522
+	}
523
+	if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
524
+		prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
525
+		advice.PrescribingNumberUnit = prescribingNumberUnit
526
+	}
527
+	if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
528
+		deliveryWay, _ := json["delivery_way"].(string)
529
+		advice.DeliveryWay = deliveryWay
530
+	}
531
+	if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
532
+		executionFrequency, _ := json["execution_frequency"].(string)
533
+		advice.ExecutionFrequency = executionFrequency
534
+	}
535
+
536
+	if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
537
+		price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
538
+		advice.Price = price
539
+	}
540
+	if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
541
+		med_list_codg, _ := json["medical_insurance_number"].(string)
542
+		advice.MedListCodg = med_list_codg
543
+	}
544
+	if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
545
+		day := int64(json["day"].(float64))
546
+		advice.Day = day
547
+	}
548
+	return 0
549
+}
550
+func (c *MobileHisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
551
+	if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
552
+		id := int64(json["id"].(float64))
553
+		project.ID = id
554
+	}
555
+	if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
556
+		project_id := int64(json["project_id"].(float64))
557
+		project.ProjectId = project_id
558
+		fmt.Println(project_id)
559
+		fmt.Println(project.ProjectId)
560
+	}
561
+	// if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
562
+	// 	price := int64(json["price"].(float64))
563
+	// 	formatInt_price := strconv.FormatInt(price, 10)
564
+	// 	float_price, _ := strconv.ParseFloat(formatInt_price, 64)
565
+	// 	project.Price = float_price
566
+	// }
567
+	if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
568
+		price, _ := strconv.ParseFloat(json["price"].(string), 64)
569
+		project.Price = price
570
+	}
571
+
572
+	if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
573
+		total, _ := json["total"].(string)
574
+		totals, _ := strconv.ParseInt(total, 10, 64)
575
+		project.Count = totals
576
+	}
577
+
578
+	if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
579
+		medical_code, _ := json["medical_code"].(string)
580
+		project.MedListCodg = medical_code
581
+	}
582
+	if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
583
+		single_dose, _ := json["single_dose"].(string)
584
+		project.SingleDose = single_dose
585
+	}
586
+
587
+	if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
588
+		delivery_way, _ := json["delivery_way"].(string)
589
+		project.DeliveryWay = delivery_way
590
+	}
591
+	if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
592
+		execution_frequency, _ := json["execution_frequency"].(string)
593
+		project.ExecutionFrequency = execution_frequency
594
+	}
595
+	if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
596
+		remark, _ := json["remark"].(string)
597
+		project.Remark = remark
598
+	}
599
+	if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
600
+		day, _ := json["number_days"].(string)
601
+		project.Day = day
602
+	}
603
+
604
+	if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
605
+		unit, _ := json["unit"].(string)
606
+		project.Unit = unit
607
+	}
608
+	return 0
609
+}
610
+func (c *MobileHisApiController) GetHisPatientList() {
611
+	record_date := c.GetString("record_date")
612
+	timeLayout := "2006-01-02"
613
+	loc, _ := time.LoadLocation("Local")
614
+
615
+	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
616
+	if err != nil {
617
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
618
+		return
619
+	}
620
+	recordDateTime := theTime.Unix()
621
+	adminInfo := c.GetMobileAdminUserInfo()
622
+	patients, _ := service.GetScheduleHisPatientList(adminInfo.Org.Id, "", recordDateTime)
623
+	patients_two, _ := service.GetHisPatientList(adminInfo.Org.Id, "", recordDateTime)
624
+	patients = append(patients, patients_two...)
625
+	patients = RemoveRepeatedPatient(patients)
626
+	c.ServeSuccessJSON(map[string]interface{}{
627
+		"list": patients,
628
+	})
629
+
630
+}
631
+
632
+func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
633
+	newArr = make([]*service.Patients, 0)
634
+	for i := 0; i < len(patient); i++ {
635
+		repeat := false
636
+		for j := i + 1; j < len(patient); j++ {
637
+			if patient[i].ID == patient[j].ID {
638
+				repeat = true
639
+				break
640
+			}
641
+		}
642
+		if !repeat {
643
+			newArr = append(newArr, patient[i])
644
+		}
645
+	}
646
+	return
647
+}

+ 12 - 0
controllers/new_mobile_api_controllers/new_mobile_api_router_register.go View File

@@ -162,4 +162,16 @@ func NewMobileAPIControllersRegisterRouters() {
162 162
 	beego.Router("/m/api/patient/deletemanagementtwo", &NewDialysisApiController{}, "Delete:DeleteManageMentTwo")
163 163
 	beego.Router("/m/api/patient/savecouresemanagement", &NewDialysisApiController{}, "Get:SaveCourseManageMent")
164 164
 	beego.Router("/m/api/patient/savecoursemanagementtwo", &NewDialysisApiController{}, "Get:SaveCourseManageMentTwo")
165
+
166
+	//His相关
167
+	beego.Router("/m/api/hispatientlist/get", &MobileHisApiController{}, "Get:GetHisPatientList")
168
+	beego.Router("/m/api/prescriptionconfig/get", &MobileHisApiController{}, "Get:GetHisPrescriptionConfig")
169
+	beego.Router("/m/api/prescriptioninfo/get", &MobileHisApiController{}, "Get:GetHisPatientInfo")
170
+	beego.Router("/m/api/prescription/cell", &MobileHisApiController{}, "Get:GetCallHisPrescription")
171
+	beego.Router("/m/api/lastornextprescription/get", &MobileHisApiController{}, "Get:GetLastOrNextHisPrescription")
172
+	beego.Router("/m/api/prescription/delete", &MobileHisApiController{}, "Post:DeletePrescription")
173
+	beego.Router("/m/api/hisdoctoradvice/delete", &MobileHisApiController{}, "Post:DeletePrescription")
174
+	beego.Router("/m/api/hisproject/delete", &MobileHisApiController{}, "Post:DeleteDoctorAdvice")
175
+	beego.Router("/m/api/prescription/create", &MobileHisApiController{}, "Post:CreateHisPrescription")
176
+
165 177
 }

+ 68 - 2
service/his_service.go View File

@@ -291,6 +291,38 @@ func GetHisPrescription(org_id int64, patient_id int64, record_date int64) (pres
291 291
 	return
292 292
 }
293 293
 
294
+func GetChargeHisPrescriptionFive(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
295
+	err = readDb.Model(&models.HisPrescription{}).
296
+		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
297
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
298
+		}).
299
+		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
300
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
301
+		}).
302
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
303
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
304
+		}).
305
+		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status = 2", org_id, record_date, patient_id).
306
+		Find(&prescription).Error
307
+	return
308
+}
309
+
310
+func GetUnChargeHisPrescriptionFive(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
311
+	err = readDb.Model(&models.HisPrescription{}).
312
+		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
313
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
314
+		}).
315
+		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
316
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
317
+		}).
318
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
319
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
320
+		}).
321
+		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3", org_id, record_date, patient_id).
322
+		Find(&prescription).Error
323
+	return
324
+}
325
+
294 326
 func GetSettleHisPrescription(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
295 327
 	err = readDb.Model(&models.HisPrescription{}).
296 328
 		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
@@ -334,7 +366,7 @@ func GetMonthHisPrescriptionTwo(org_id int64, patient_id int64, start_date int64
334 366
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
335 367
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
336 368
 		}).
337
-		Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 ", org_id, start_date, end_date, patient_id).
369
+		Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ?", org_id, start_date, end_date, patient_id).
338 370
 		Find(&prescription).Error
339 371
 	return
340 372
 }
@@ -350,7 +382,41 @@ func GetMonthHisPrescriptionThree(org_id int64, patient_id int64, start_date int
350 382
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
351 383
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
352 384
 		}).
353
-		Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND  order_status <> 2  ", org_id, start_date, end_date, patient_id).
385
+		Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ?  ", org_id, start_date, end_date, patient_id).
386
+		Find(&prescription).Error
387
+	return
388
+}
389
+
390
+//未收费
391
+func GetUnChargeMonthHisPrescriptionThree(org_id int64, patient_id int64, start_date int64, end_date int64) (prescription []*models.HisPrescription, err error) {
392
+	err = readDb.Model(&models.HisPrescription{}).
393
+		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
394
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
395
+		}).
396
+		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
397
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
398
+		}).
399
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
400
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
401
+		}).
402
+		Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ?  AND  order_status <> 2 AND order_status <> 3 ", org_id, start_date, end_date, patient_id).
403
+		Find(&prescription).Error
404
+	return
405
+}
406
+
407
+//已收费
408
+func GetChargeMonthHisPrescriptionFour(org_id int64, patient_id int64, start_date int64, end_date int64) (prescription []*models.HisPrescription, err error) {
409
+	err = readDb.Model(&models.HisPrescription{}).
410
+		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
411
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
412
+		}).
413
+		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
414
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
415
+		}).
416
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
417
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
418
+		}).
419
+		Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status = 2", org_id, start_date, end_date, patient_id).
354 420
 		Find(&prescription).Error
355 421
 	return
356 422
 }