Browse Source

医保对接

csx 3 years ago
parent
commit
86db3e510d

+ 58 - 56
controllers/base_api_controller.go View File

@@ -2,6 +2,8 @@ package controllers
2 2
 
3 3
 import (
4 4
 	"XT_New/enums"
5
+	"XT_New/models"
6
+
5 7
 	//"XT_New/models"
6 8
 
7 9
 	//"XT_New/models"
@@ -67,33 +69,33 @@ type BaseAuthAPIController struct {
67 69
 func (this *BaseAuthAPIController) Prepare() {
68 70
 	this.BaseAPIController.Prepare()
69 71
 	if this.GetAdminUserInfo() == nil {
70
-		//var userAdmin models.AdminUser
71
-		//userAdmin.Id = 1448
72
-		//userAdmin.Mobile = "13318599895"
73
-		//
74
-		////userAdmin.Id = 597
75
-		////userAdmin.Mobile = "19874122664"
76
-		//userAdmin.IsSuperAdmin = false
77
-		//userAdmin.Status = 1
78
-		//userAdmin.CreateTime = 1530786071
79
-		//userAdmin.ModifyTime = 1530786071
80
-		//var subscibe models.ServeSubscibe
81
-		//subscibe.ID = 1
82
-		//subscibe.OrgId = 4
83
-		//subscibe.PeriodStart = 1538035409
84
-		//subscibe.PeriodEnd = 1569571409
85
-		//subscibe.State = 1
86
-		//subscibe.Status = 1
87
-		//subscibe.CreatedTime = 1538035409
88
-		//subscibe.UpdatedTime = 1538035409
89
-		//subscibes := make(map[int64]*models.ServeSubscibe, 0)
90
-		//subscibes[4] = &subscibe
91
-		//var adminUserInfo service.AdminUserInfo
92
-		//adminUserInfo.CurrentOrgId = 4
93
-		//adminUserInfo.CurrentAppId = 4
94
-		//adminUserInfo.AdminUser = &userAdmin
95
-		//adminUserInfo.Subscibes = subscibes
96
-		//this.SetSession("admin_user_info", &adminUserInfo)
72
+		var userAdmin models.AdminUser
73
+		userAdmin.Id = 1448
74
+		userAdmin.Mobile = "13318599895"
75
+
76
+		//userAdmin.Id = 597
77
+		//userAdmin.Mobile = "19874122664"
78
+		userAdmin.IsSuperAdmin = false
79
+		userAdmin.Status = 1
80
+		userAdmin.CreateTime = 1530786071
81
+		userAdmin.ModifyTime = 1530786071
82
+		var subscibe models.ServeSubscibe
83
+		subscibe.ID = 1
84
+		subscibe.OrgId = 3877
85
+		subscibe.PeriodStart = 1538035409
86
+		subscibe.PeriodEnd = 1569571409
87
+		subscibe.State = 1
88
+		subscibe.Status = 1
89
+		subscibe.CreatedTime = 1538035409
90
+		subscibe.UpdatedTime = 1538035409
91
+		subscibes := make(map[int64]*models.ServeSubscibe, 0)
92
+		subscibes[4] = &subscibe
93
+		var adminUserInfo service.AdminUserInfo
94
+		adminUserInfo.CurrentOrgId = 3877
95
+		adminUserInfo.CurrentAppId = 4
96
+		adminUserInfo.AdminUser = &userAdmin
97
+		adminUserInfo.Subscibes = subscibes
98
+		this.SetSession("admin_user_info", &adminUserInfo)
97 99
 
98 100
 		//this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
99 101
 		//this.StopRun()
@@ -313,35 +315,35 @@ type BaseServeAPIController struct {
313 315
 func (this *BaseServeAPIController) Prepare() {
314 316
 	this.BaseAPIController.Prepare()
315 317
 	if this.GetAdminUserInfo() == nil {
316
-		//var userAdmin models.AdminUser
317
-		//userAdmin.Id = 1448
318
-		//userAdmin.Mobile = "13318599895"
319
-		//
320
-		////userAdmin.Id = 597
321
-		////userAdmin.Mobile = "19874122664"
322
-		//userAdmin.IsSuperAdmin = false
323
-		//userAdmin.Status = 1
324
-		//userAdmin.CreateTime = 1530786071
325
-		//userAdmin.ModifyTime = 1530786071
326
-		//var subscibe models.ServeSubscibe
327
-		//subscibe.ID = 1
328
-		//subscibe.OrgId = 10106
329
-		//subscibe.PeriodStart = 1538035409
330
-		//subscibe.PeriodEnd = 1569571409
331
-		//subscibe.State = 1
332
-		//subscibe.Status = 1
333
-		//subscibe.CreatedTime = 1538035409
334
-		//subscibe.UpdatedTime = 1538035409
335
-		//subscibes := make(map[int64]*models.ServeSubscibe, 0)
336
-		//subscibes[4] = &subscibe
337
-		//var adminUserInfo service.AdminUserInfo
338
-		//adminUserInfo.CurrentOrgId = 4
339
-		//adminUserInfo.CurrentAppId = 4
340
-		//adminUserInfo.AdminUser = &userAdmin
341
-		//adminUserInfo.Subscibes = subscibes
342
-		//this.SetSession("admin_user_info", &adminUserInfo)
343
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
344
-		this.StopRun()
318
+		var userAdmin models.AdminUser
319
+		userAdmin.Id = 1448
320
+		userAdmin.Mobile = "13318599895"
321
+
322
+		//userAdmin.Id = 597
323
+		//userAdmin.Mobile = "19874122664"
324
+		userAdmin.IsSuperAdmin = false
325
+		userAdmin.Status = 1
326
+		userAdmin.CreateTime = 1530786071
327
+		userAdmin.ModifyTime = 1530786071
328
+		var subscibe models.ServeSubscibe
329
+		subscibe.ID = 1
330
+		subscibe.OrgId = 3877
331
+		subscibe.PeriodStart = 1538035409
332
+		subscibe.PeriodEnd = 1569571409
333
+		subscibe.State = 1
334
+		subscibe.Status = 1
335
+		subscibe.CreatedTime = 1538035409
336
+		subscibe.UpdatedTime = 1538035409
337
+		subscibes := make(map[int64]*models.ServeSubscibe, 0)
338
+		subscibes[4] = &subscibe
339
+		var adminUserInfo service.AdminUserInfo
340
+		adminUserInfo.CurrentOrgId = 3877
341
+		adminUserInfo.CurrentAppId = 4
342
+		adminUserInfo.AdminUser = &userAdmin
343
+		adminUserInfo.Subscibes = subscibes
344
+		this.SetSession("admin_user_info", &adminUserInfo)
345
+		//this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
346
+		//this.StopRun()
345 347
 	}
346 348
 
347 349
 	//if adminUserInfo.AppRole != nil {

+ 1 - 1
controllers/doctors_api_controller.go View File

@@ -103,7 +103,7 @@ func (c *DoctorsApiController) GetAllDoctorAndNurse() {
103 103
 func (c *DoctorsApiController) GetAllAdminUsers() {
104 104
 
105 105
 	adminUserInfo := c.GetAdminUserInfo()
106
-	users, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
106
+	users, _ := service.GetAllAdminUsersTwo(adminUserInfo.CurrentOrgId)
107 107
 	c.ServeSuccessJSON(map[string]interface{}{
108 108
 		"users": users,
109 109
 	})

+ 420 - 141
controllers/his_api_controller.go View File

@@ -9,6 +9,7 @@ import (
9 9
 	"fmt"
10 10
 	"github.com/astaxie/beego"
11 11
 	"github.com/jinzhu/gorm"
12
+	"github.com/shopspring/decimal"
12 13
 	"math/rand"
13 14
 	"reflect"
14 15
 	"strconv"
@@ -25,6 +26,8 @@ type HisApiController struct {
25 26
 func HisManagerApiRegistRouters() {
26 27
 
27 28
 	beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
29
+	//beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
30
+
28 31
 	beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
29 32
 	beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
30 33
 
@@ -42,13 +45,17 @@ func HisManagerApiRegistRouters() {
42 45
 	beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
43 46
 	beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
44 47
 	beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
48
+
45 49
 	beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
50
+
46 51
 	beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
47 52
 
48 53
 	beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
54
+
49 55
 	beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
50 56
 
51 57
 	beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
58
+
52 59
 	beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
53 60
 
54 61
 	beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
@@ -58,31 +65,24 @@ func HisManagerApiRegistRouters() {
58 65
 	beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
59 66
 
60 67
 	//beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
61
-
62 68
 	//新增附加费用
63 69
 	//beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
64
-
65 70
 	//beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
66
-
67 71
 	beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
68
-
69 72
 	beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
70
-
71 73
 	beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
72
-
73 74
 	beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
74 75
 	beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
75
-
76 76
 	beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
77
-
78 77
 	beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
79 78
 	beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
80
-
81 79
 	beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
82
-
83 80
 	beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
84 81
 
85
-	//beego.Router("/api/export/template", &HisApiController{}, "get:ExportOrderTemplate")
82
+	beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
83
+	beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
84
+
85
+	beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
86 86
 
87 87
 }
88 88
 
@@ -135,11 +135,9 @@ func StrPtr(s string) uintptr {
135 135
 }
136 136
 
137 137
 func (c *HisApiController) GetHisPatientList() {
138
-	types, _ := c.GetInt64("type", 0)
139 138
 	record_date := c.GetString("record_date")
140 139
 	timeLayout := "2006-01-02"
141 140
 	loc, _ := time.LoadLocation("Local")
142
-
143 141
 	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
144 142
 	if err != nil {
145 143
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -147,83 +145,29 @@ func (c *HisApiController) GetHisPatientList() {
147 145
 	}
148 146
 	recordDateTime := theTime.Unix()
149 147
 	adminInfo := c.GetAdminUserInfo()
150
-	patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
148
+	patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
151 149
 	patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, 0)
152
-	patients = append(patients, patients_two...)
153
-	patients = RemoveRepeatedPatient(patients)
154
-
155
-	var total_one int64
156
-	var total_two int64
157
-
158 150
 	//获取当前用户的信息
159 151
 	adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
160 152
 	doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
161 153
 	//获取所有科室信息
162 154
 	department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
163
-
164
-	for _, item := range patients {
165
-
166
-		if item.HisPrescription == nil || len(item.HisPrescription) <= 0 {
167
-			total_one = total_one + 1
168
-		}
169
-		if item.HisPrescription != nil && len(item.HisPrescription) > 0 {
170
-			total_two = total_two + 1
171
-		}
172
-	}
173
-
174
-	if types == 0 {
175
-		c.ServeSuccessJSON(map[string]interface{}{
176
-			"list":       patients,
177
-			"total_one":  total_one,
178
-			"total_two":  total_two,
179
-			"info":       adminUserInfo,
180
-			"doctors":    doctors,
181
-			"department": department,
182
-		})
183
-
184
-	} else if types == 1 { //未就诊
185
-		var patientsOne []*service.Patients
186
-		for _, item := range patients {
187
-			if item.HisPrescription == nil || len(item.HisPrescription) <= 0 {
188
-				patientsOne = append(patientsOne, item)
189
-			}
190
-		}
191
-		c.ServeSuccessJSON(map[string]interface{}{
192
-			"list":       patientsOne,
193
-			"total_one":  total_one,
194
-			"total_two":  total_two,
195
-			"info":       adminUserInfo,
196
-			"doctors":    doctors,
197
-			"department": department,
198
-		})
199
-
200
-	} else if types == 2 { //已就诊
201
-		var patientsTwo []*service.Patients
202
-		for _, item := range patients {
203
-
204
-			if item.HisPrescription != nil && len(item.HisPrescription) > 0 {
205
-				patientsTwo = append(patientsTwo, item)
206
-			}
207
-		}
208
-		c.ServeSuccessJSON(map[string]interface{}{
209
-			"list":       patientsTwo,
210
-			"total_one":  total_one,
211
-			"total_two":  total_two,
212
-			"info":       adminUserInfo,
213
-			"doctors":    doctors,
214
-			"department": department,
215
-		})
216
-	}
155
+	c.ServeSuccessJSON(map[string]interface{}{
156
+		"list":       patients,
157
+		"list_two":   patients_two,
158
+		"info":       adminUserInfo,
159
+		"doctors":    doctors,
160
+		"department": department,
161
+	})
217 162
 
218 163
 }
219 164
 func (c *HisApiController) GetHisPatientInfo() {
220 165
 	patient_id, _ := c.GetInt64("patient_id")
166
+	his_patient_id, _ := c.GetInt64("his_patient_id")
221 167
 	record_date := c.GetString("record_date")
222 168
 	number := c.GetString("number")
223
-
224 169
 	start_time := c.GetString("start_time")
225 170
 	end_time := c.GetString("end_time")
226
-
227 171
 	timeLayout := "2006-01-02"
228 172
 	loc, _ := time.LoadLocation("Local")
229 173
 	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
@@ -232,32 +176,27 @@ func (c *HisApiController) GetHisPatientInfo() {
232 176
 		return
233 177
 	}
234 178
 	recordDateTime := theTime.Unix()
235
-
236 179
 	startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
237 180
 	if err != nil {
238 181
 
239 182
 	}
240 183
 	startRecordDateTime := startTime.Unix()
241
-
242 184
 	endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
243 185
 	if err != nil {
244 186
 
245 187
 	}
246 188
 	endRecordDateTime := endTime.Unix()
247
-
248 189
 	admin := c.GetAdminUserInfo()
249
-	his_patient_info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, recordDateTime)
190
+	his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
250 191
 	xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
251
-	prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime)
192
+	prescriptions, _ := service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
252 193
 	monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime)
253 194
 	case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
254 195
 	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
255 196
 	order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
256
-
257 197
 	doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
258 198
 	//获取所有科室信息
259 199
 	department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
260
-
261 200
 	c.ServeSuccessJSON(map[string]interface{}{
262 201
 		"his_info":            his_patient_info,
263 202
 		"xt_info":             xt_patient_info,
@@ -392,6 +331,7 @@ func (c *HisApiController) CreateHisPrescription() {
392 331
 	if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
393 332
 		prescriptions, _ := dataBody["prescriptions"].([]interface{})
394 333
 
334
+		var tempPrescription *models.HisPrescription
395 335
 		if len(prescriptions) > 0 {
396 336
 			for _, item := range prescriptions {
397 337
 				items := item.(map[string]interface{})
@@ -402,6 +342,8 @@ func (c *HisApiController) CreateHisPrescription() {
402 342
 				}
403 343
 				id := int64(items["id"].(float64))
404 344
 
345
+				new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
346
+				tempPrescription = &new_prescription
405 347
 				if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
406 348
 					utils.ErrorLog("type")
407 349
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -409,6 +351,15 @@ func (c *HisApiController) CreateHisPrescription() {
409 351
 				}
410 352
 				types := int64(items["type"].(float64))
411 353
 
354
+				if items["order_status"] == nil || reflect.TypeOf(items["order_status"]).String() != "float64" {
355
+					utils.ErrorLog("order_status")
356
+				}
357
+				order_status := int64(items["order_status"].(float64))
358
+
359
+				if order_status == 0 {
360
+					order_status = 1
361
+				}
362
+
412 363
 				if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
413 364
 					utils.ErrorLog("pre_time")
414 365
 				}
@@ -423,25 +374,39 @@ func (c *HisApiController) CreateHisPrescription() {
423 374
 				pTime := theTime2.Unix()
424 375
 
425 376
 				ctime := time.Now().Unix()
426
-				prescription := &models.HisPrescription{
427
-					ID:                 id,
428
-					PatientId:          patient_id,
429
-					UserOrgId:          adminInfo.CurrentOrgId,
430
-					RecordDate:         recordDateTime,
431
-					Ctime:              ctime,
432
-					Mtime:              ctime,
433
-					Type:               types,
434
-					Modifier:           adminInfo.AdminUser.Id,
435
-					Creator:            adminInfo.AdminUser.Id,
436
-					Status:             1,
437
-					Doctor:             role.UserName,
438
-					HisPatientId:       his_patient_id,
439
-					OrderStatus:        1,
440
-					BatchNumber:        "",
441
-					PrescriptionNumber: hpInfo.PrescriptionNumber,
442
-					PreTime:            pTime,
377
+
378
+				if tempPrescription.ID == 0 {
379
+					prescription := &models.HisPrescription{
380
+						ID:                 id,
381
+						PatientId:          patient_id,
382
+						UserOrgId:          adminInfo.CurrentOrgId,
383
+						RecordDate:         recordDateTime,
384
+						Ctime:              ctime,
385
+						Mtime:              ctime,
386
+						Type:               types,
387
+						Modifier:           adminInfo.AdminUser.Id,
388
+						Creator:            adminInfo.AdminUser.Id,
389
+						Status:             1,
390
+						Doctor:             role.UserName,
391
+						HisPatientId:       his_patient_id,
392
+						OrderStatus:        order_status,
393
+						BatchNumber:        "",
394
+						PrescriptionNumber: hpInfo.PrescriptionNumber,
395
+						PreTime:            pTime,
396
+					}
397
+					tempPrescription = prescription
398
+					service.SaveHisPrescription(tempPrescription)
399
+
400
+				} else {
401
+					tempPrescription.Type = types
402
+					tempPrescription.Modifier = adminInfo.AdminUser.Id
403
+					tempPrescription.Mtime = time.Now().Unix()
404
+					tempPrescription.Doctor = role.UserName
405
+					tempPrescription.OrderStatus = order_status
406
+					tempPrescription.PreTime = pTime
407
+					service.SaveHisPrescription(tempPrescription)
408
+
443 409
 				}
444
-				service.SaveHisPrescription(prescription)
445 410
 
446 411
 				//更改患者挂号状态
447 412
 				_, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
@@ -455,7 +420,7 @@ func (c *HisApiController) CreateHisPrescription() {
455 420
 					if len(advices) > 0 {
456 421
 						for _, advice := range advices {
457 422
 							var s models.HisDoctorAdviceInfo
458
-							s.PrescriptionId = prescription.ID
423
+							s.PrescriptionId = tempPrescription.ID
459 424
 							s.AdviceType = 2
460 425
 							s.AdviceDoctor = doctor_id
461 426
 							s.StopState = 2
@@ -464,7 +429,7 @@ func (c *HisApiController) CreateHisPrescription() {
464 429
 							s.Status = 1
465 430
 							s.UserOrgId = adminInfo.CurrentOrgId
466 431
 							s.RecordDate = recordDateTime
467
-							s.StartTime = prescription.PreTime
432
+							s.StartTime = tempPrescription.PreTime
468 433
 							s.Groupno = groupNo
469 434
 							s.CreatedTime = ctime
470 435
 							s.UpdatedTime = mtime
@@ -492,7 +457,7 @@ func (c *HisApiController) CreateHisPrescription() {
492 457
 					if len(projects) > 0 {
493 458
 						for _, project := range projects {
494 459
 							var p models.HisPrescriptionProject
495
-							p.PrescriptionId = prescription.ID
460
+							p.PrescriptionId = tempPrescription.ID
496 461
 							p.Ctime = time.Now().Unix()
497 462
 							p.Mtime = time.Now().Unix()
498 463
 							p.PatientId = patient_id
@@ -525,7 +490,7 @@ func (c *HisApiController) CreateHisPrescription() {
525 490
 					if len(addition) > 0 {
526 491
 						for _, item := range addition {
527 492
 							var s models.HisAdditionalCharge
528
-							s.PrescriptionId = prescription.ID
493
+							s.PrescriptionId = tempPrescription.ID
529 494
 							s.Status = 1
530 495
 							s.UserOrgId = adminInfo.CurrentOrgId
531 496
 							s.RecordDate = recordDateTime
@@ -2104,14 +2069,28 @@ func (c *HisApiController) GetRegisterInfo() {
2104 2069
 		return
2105 2070
 	}
2106 2071
 
2107
-	timeStr := time.Now().Format("2006-01-02")
2108
-	timeArr := strings.Split(timeStr, "-")
2109
-	var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
2072
+	his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
2073
+	if len(his) >= 1 {
2074
+		order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
2075
+		if len(his) >= 1 && order.ID == 0 {
2076
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
2077
+			return
2078
+		}
2079
+	}
2080
+
2081
+	timeStr := time.Now().Format("2006-01-02 15:04:05")
2082
+	fmt.Println(timeStr)
2083
+	timeArr := strings.Split(timeStr, " ")
2084
+	fmt.Println(timeArr)
2110 2085
 
2111
-	his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
2086
+	timeArrTwo := strings.Split(timeArr[0], "-")
2087
+	timeArrThree := strings.Split(timeArr[1], ":")
2088
+	var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
2112 2089
 
2113
-	var hisPatient models.XtHisPatient
2114
-	if err == gorm.ErrRecordNotFound || his.ID == 0 {
2090
+	lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
2091
+
2092
+	if len(lists) == 0 {
2093
+		var hisPatient models.XtHisPatient
2115 2094
 		hisPatient = models.XtHisPatient{
2116 2095
 			Name:                   name,
2117 2096
 			Age:                    age,
@@ -2144,19 +2123,68 @@ func (c *HisApiController) GetRegisterInfo() {
2144 2123
 			SickType:               sick_type,
2145 2124
 		}
2146 2125
 		service.CreateHisPatient(&hisPatient)
2126
+
2127
+		service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
2128
+
2147 2129
 		c.ServeSuccessJSON(map[string]interface{}{
2148 2130
 			"his_info": hisPatient,
2149 2131
 		})
2132
+
2150 2133
 	} else {
2151
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisRegisterException)
2152
-		return
2134
+
2135
+		//chrgBchno := rand.Intn(1000000) + 10000
2136
+		var hisPatient models.XtHisPatient
2137
+		hisPatient = models.XtHisPatient{
2138
+			Name:                   name,
2139
+			Age:                    age,
2140
+			Gender:                 gender,
2141
+			Birthday:               birthUnix,
2142
+			Phone:                  phone,
2143
+			MedicalTreatmentType:   medical_care,
2144
+			IdType:                 certificates,
2145
+			IdCardNo:               id_card,
2146
+			BalanceAccountsType:    settlementValue,
2147
+			SocialType:             social_type,
2148
+			MedicalInsuranceNumber: medical_insurance_card,
2149
+			RegisterType:           register_type,
2150
+			RegisterCost:           registration_fee,
2151
+			TreatmentCost:          medical_expenses,
2152
+			AdminUserId:            adminInfo.AdminUser.Id,
2153
+			UserOrgId:              adminInfo.CurrentOrgId,
2154
+			Status:                 1,
2155
+			RecordDate:             recordDateTime,
2156
+			IsReturn:               1,
2157
+			PatientId:              patient.ID,
2158
+			Ctime:                  time.Now().Unix(),
2159
+			Mtime:                  time.Now().Unix(),
2160
+			Number:                 str,
2161
+			IdCardType:             id_card_type,
2162
+			Departments:            department,
2163
+			Doctor:                 doctor,
2164
+			PType:                  reg_type,
2165
+			Diagnosis:              diagnosis_id,
2166
+			SickType:               sick_type,
2167
+		}
2168
+		service.CreateHisPatient(&hisPatient)
2169
+
2170
+		c.ServeSuccessJSON(map[string]interface{}{
2171
+			"his_info": hisPatient,
2172
+		})
2173
+
2153 2174
 	}
2175
+
2176
+	//timeStr := time.Now().Format("2006-01-02")
2177
+	//timeArr := strings.Split(timeStr, "-")
2178
+	//var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)+ ""
2179
+
2154 2180
 }
2155 2181
 
2156 2182
 //上传明细----结算
2157 2183
 func (c *HisApiController) GetUploadInfo() {
2158 2184
 	id, _ := c.GetInt64("id")
2159 2185
 	record_time := c.GetString("record_time")
2186
+	his_patient_id, _ := c.GetInt64("his_patient_id")
2187
+
2160 2188
 	pay_way, _ := c.GetInt64("pay_way")
2161 2189
 	pay_price, _ := c.GetFloat("pay_price")
2162 2190
 	pay_card_no := c.GetString("pay_card_no")
@@ -2183,7 +2211,7 @@ func (c *HisApiController) GetUploadInfo() {
2183 2211
 
2184 2212
 	if settle_accounts_type == 1 { //日结
2185 2213
 
2186
-		prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
2214
+		prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime)
2187 2215
 
2188 2216
 	} else { //月结
2189 2217
 		start_time_str := c.GetString("start_time")
@@ -2207,7 +2235,12 @@ func (c *HisApiController) GetUploadInfo() {
2207 2235
 		prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
2208 2236
 	}
2209 2237
 
2210
-	his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
2238
+	his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
2239
+
2240
+	fmt.Println("~~~~~~~~~")
2241
+	fmt.Println(his.Number)
2242
+	fmt.Println("~~~~~~~~~")
2243
+
2211 2244
 	timestamp := time.Now().Unix()
2212 2245
 	tempTime := time.Unix(timestamp, 0)
2213 2246
 	timeFormat := tempTime.Format("20060102150405")
@@ -2250,6 +2283,7 @@ func (c *HisApiController) GetUploadInfo() {
2250 2283
 		Mtime:                 time.Now().Unix(),
2251 2284
 		Status:                1,
2252 2285
 		OrderStatus:           2,
2286
+		MdtrtId:               his.Number,
2253 2287
 		Number:                chrg_bchno,
2254 2288
 		MedfeeSumamt:          totals,
2255 2289
 		PayWay:                pay_way,
@@ -2573,17 +2607,20 @@ func (c *HisApiController) GetHisChargePatientList() {
2573 2607
 	}
2574 2608
 	recordDateTime := theTime.Unix()
2575 2609
 	adminInfo := c.GetAdminUserInfo()
2576
-	tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
2577
-	var patients []*service.Patients
2578
-	var patients_two []*service.Patients
2610
+	//tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
2611
+	tempPatients, _ := service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
2612
+
2613
+	var patients []*service.NewTempPatients
2614
+	var patients_two []*service.NewTempPatients
2579 2615
 
2580 2616
 	for _, item := range tempPatients {
2581 2617
 		//过滤掉没挂号的和没开处方的
2582
-		if item.HisPatient.ID > 0 || len(item.HisPrescription) > 0 {
2618
+		if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
2583 2619
 			patients = append(patients, item)
2584 2620
 		}
2621
+
2585 2622
 		//过滤掉没挂号的
2586
-		if item.HisPatient.ID > 0 {
2623
+		if len(item.HisPatient) > 0 {
2587 2624
 			patients_two = append(patients_two, item)
2588 2625
 		}
2589 2626
 	}
@@ -2613,7 +2650,6 @@ func (c *HisApiController) GetHisUnRegisterPatientList() {
2613 2650
 			patients = append(patients, item)
2614 2651
 		}
2615 2652
 	}
2616
-
2617 2653
 	c.ServeSuccessJSON(map[string]interface{}{
2618 2654
 		"list": patients,
2619 2655
 		//"list_two":	patients_two,
@@ -2640,12 +2676,10 @@ func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patie
2640 2676
 
2641 2677
 func (c *HisApiController) GetHisChargePatientInfo() {
2642 2678
 	patient_id, _ := c.GetInt64("patient_id")
2679
+	his_patient_id, _ := c.GetInt64("his_patient_id")
2643 2680
 	record_date := c.GetString("record_date")
2644
-	number := c.GetString("number")
2645
-
2646 2681
 	start_time := c.GetString("start_time")
2647 2682
 	end_time := c.GetString("end_time")
2648
-
2649 2683
 	order_status, _ := c.GetInt64("type", 0)
2650 2684
 
2651 2685
 	timeLayout := "2006-01-02"
@@ -2670,30 +2704,26 @@ func (c *HisApiController) GetHisChargePatientInfo() {
2670 2704
 	endRecordDateTime := endTime.Unix()
2671 2705
 
2672 2706
 	admin := c.GetAdminUserInfo()
2673
-	his_patient_info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, recordDateTime)
2707
+	his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
2674 2708
 	xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
2675 2709
 
2676 2710
 	var prescriptions []*models.HisPrescription
2677 2711
 
2678 2712
 	if order_status == 1 || order_status == 0 {
2679
-		prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, recordDateTime)
2713
+		prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
2680 2714
 	} else if order_status == 2 {
2681
-		prescriptions, _ = service.GetChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, recordDateTime)
2715
+		prescriptions, _ = service.GetChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
2682 2716
 	}
2683 2717
 
2684 2718
 	var monthPrescriptions []*models.HisPrescription
2685
-
2686 2719
 	if order_status == 1 || order_status == 0 {
2687 2720
 		monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime)
2688 2721
 	} else if order_status == 2 {
2689 2722
 		monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFour(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime)
2690
-
2691 2723
 	}
2692
-
2693 2724
 	case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
2694 2725
 	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
2695
-	order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
2696
-
2726
+	order, _ := service.GetNewHisOrder(admin.CurrentOrgId, his_patient_info.Number, patient_id)
2697 2727
 	doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
2698 2728
 	//获取所有科室信息
2699 2729
 	department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
@@ -2758,6 +2788,24 @@ func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
2758 2788
 	page, _ := c.GetInt64("page")
2759 2789
 	limit, _ := c.GetInt64("limit")
2760 2790
 	keywords := c.GetString("keywords")
2791
+	start_time := c.GetString("start_time")
2792
+	end_time := c.GetString("end_time")
2793
+	//clr_type := c.GetString("clr_type")
2794
+	insutype := c.GetString("insutype")
2795
+
2796
+	timeLayout := "2006-01-02"
2797
+	loc, _ := time.LoadLocation("Local")
2798
+
2799
+	var theStartTIme int64
2800
+	if len(start_time) > 0 {
2801
+		theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
2802
+		theStartTIme = theTime.Unix()
2803
+	}
2804
+	var theEndtTIme int64
2805
+	if len(end_time) > 0 {
2806
+		theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
2807
+		theEndtTIme = theTime.Unix()
2808
+	}
2761 2809
 
2762 2810
 	if page <= 0 {
2763 2811
 		page = 1
@@ -2765,7 +2813,7 @@ func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
2765 2813
 	if limit <= 0 {
2766 2814
 		limit = 10
2767 2815
 	}
2768
-	list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords)
2816
+	list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
2769 2817
 	c.ServeSuccessJSON(map[string]interface{}{
2770 2818
 		"total": total,
2771 2819
 		"list":  list,
@@ -2795,11 +2843,242 @@ func (c *HisApiController) GetPutOnRecordList() {
2795 2843
 
2796 2844
 }
2797 2845
 
2798
-//func (c *HisApiController)ExportOrderTemplate(){
2799
-//	start_time := c.GetString("start_time")
2800
-//	end_time := c.GetString("end_time")
2801
-//
2802
-//
2803
-//
2804
-//
2805
-//}
2846
+func (c *HisApiController) GetCompareData() {
2847
+	start_time := c.GetString("start_time")
2848
+	end_time := c.GetString("end_time")
2849
+	insutype := c.GetString("insutype")
2850
+	timeLayout := "2006-01-02"
2851
+	loc, _ := time.LoadLocation("Local")
2852
+	var theStartTIme int64
2853
+	if len(start_time) > 0 {
2854
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
2855
+		if err != nil {
2856
+			theStartTIme = 0
2857
+		}
2858
+		theStartTIme = theTime.Unix()
2859
+	}
2860
+	var theEndtTIme int64
2861
+	if len(end_time) > 0 {
2862
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
2863
+		if err != nil {
2864
+			theEndtTIme = 0
2865
+		}
2866
+		theEndtTIme = theTime.Unix()
2867
+	}
2868
+	formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype)
2869
+	if err == nil {
2870
+		c.ServeSuccessJSON(map[string]interface{}{
2871
+			"list": formData,
2872
+		})
2873
+	} else {
2874
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2875
+		return
2876
+
2877
+	}
2878
+}
2879
+
2880
+func (c *HisApiController) GetFaPiaoData() {
2881
+	order_id, _ := c.GetInt64("order_id")
2882
+	patient_id, _ := c.GetInt64("patient_id")
2883
+
2884
+	adminUser := c.GetAdminUserInfo()
2885
+	order, _ := service.GetHisOrderByID(order_id)
2886
+	orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
2887
+
2888
+	patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
2889
+
2890
+	department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
2891
+
2892
+	his, _ := service.GetHisPatientInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
2893
+
2894
+	var bedCostTotal float64 = 0         //床位总费
2895
+	var bedCostSelfTotal float64 = 0     //床位自费
2896
+	var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
2897
+
2898
+	var operationCostTotal float64 = 0         //手术费
2899
+	var operationCostSelfTotal float64 = 0     //手术费
2900
+	var operationCostPartSelfTotal float64 = 0 //手术费
2901
+
2902
+	var otherCostTotal float64 = 0         //其他费用
2903
+	var otherCostSelfTotal float64 = 0     //其他费用
2904
+	var otherCostPartSelfTotal float64 = 0 //其他费用
2905
+
2906
+	var materialCostTotal float64 = 0         //材料费
2907
+	var materialCostSelfTotal float64 = 0     //材料费
2908
+	var materialCostPartSelfTotal float64 = 0 //材料费
2909
+
2910
+	var westernMedicineCostTotal float64 = 0         //西药费
2911
+	var westernMedicineCostSelfTotal float64 = 0     //西药费
2912
+	var westernMedicineCostPartSelfTotal float64 = 0 //西药费
2913
+
2914
+	var chineseTraditionalMedicineCostTotal float64 = 0         //中成药
2915
+	var chineseTraditionalMedicineCostSelfTotal float64 = 0     //中成药
2916
+	var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
2917
+
2918
+	var checkCostTotal float64 = 0         //检查费
2919
+	var checkCostSelfTotal float64 = 0     //检查费
2920
+	var checkCostPartSelfTotal float64 = 0 //检查费
2921
+
2922
+	var laboratoryCostTotal float64 = 0         //化验费
2923
+	var laboratoryCostSelfTotal float64 = 0     //化验费
2924
+	var laboratoryCostPartSelfTotal float64 = 0 //化验费
2925
+
2926
+	var treatCostTotal float64 = 0         //治疗费用
2927
+	var treatCostSelfTotal float64 = 0     //治疗费用
2928
+	var treatCostPartSelfTotal float64 = 0 //治疗费用
2929
+
2930
+	decimal.DivisionPrecision = 2
2931
+
2932
+	for _, item := range orderInfos {
2933
+		if item.MedChrgitmType == "01" { //床位费
2934
+			bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
2935
+			bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
2936
+			bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
2937
+		}
2938
+
2939
+		if item.MedChrgitmType == "03" { //检查费
2940
+			checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
2941
+			checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
2942
+			checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
2943
+		}
2944
+
2945
+		if item.MedChrgitmType == "04" { //化验费
2946
+			laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
2947
+			laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
2948
+			laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
2949
+		}
2950
+
2951
+		if item.MedChrgitmType == "05" { //治疗费
2952
+			treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
2953
+			treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
2954
+			treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
2955
+		}
2956
+
2957
+		if item.MedChrgitmType == "06" { //手术费
2958
+			operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
2959
+			operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
2960
+			operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
2961
+		}
2962
+
2963
+		if item.MedChrgitmType == "08" { //材料费
2964
+			materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
2965
+			materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
2966
+			materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
2967
+		}
2968
+
2969
+		if item.MedChrgitmType == "09" { //西药费
2970
+			westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
2971
+			westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
2972
+			westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
2973
+		}
2974
+
2975
+		if item.MedChrgitmType == "11" { //中成费
2976
+			chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
2977
+			chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
2978
+			chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
2979
+		}
2980
+
2981
+		if item.MedChrgitmType == "14" { //其他费
2982
+			otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
2983
+			otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
2984
+			otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
2985
+		}
2986
+
2987
+	}
2988
+
2989
+	admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
2990
+
2991
+	c.ServeSuccessJSON(map[string]interface{}{
2992
+		"order_number":    order.Number,             //业务流水号
2993
+		"id_card_no":      his.IdCardNo,             //社会保障号
2994
+		"department_name": department.Name,          //科室
2995
+		"number":          his.Number,               //门诊号
2996
+		"date":            order.SettleAccountsDate, //结算日期
2997
+		"name":            order.PsnName,            //姓名
2998
+		"gender":          order.Gend,               //性别
2999
+		"psn_cash_money":  order.PsnCashPay,         //个人支付
3000
+		"pay_way":         "门诊",                     //结算方式
3001
+		"medfee_sumamt":   order.MedfeeSumamt,       //总费用
3002
+		"admin_user_name": admin.UserName,           //收款员
3003
+
3004
+		"bedCostTotal":                                bedCostTotal,
3005
+		"bedCostSelfTotal":                            bedCostSelfTotal,
3006
+		"bedCostPartSelfTotal":                        bedCostPartSelfTotal,
3007
+		"operationCostTotal":                          operationCostTotal,
3008
+		"operationCostSelfTotal":                      operationCostSelfTotal,
3009
+		"operationCostPartSelfTotal":                  operationCostPartSelfTotal,
3010
+		"otherCostTotal":                              otherCostTotal,
3011
+		"otherCostSelfTotal":                          otherCostSelfTotal,
3012
+		"otherCostPartSelfTotal":                      otherCostPartSelfTotal,
3013
+		"materialCostTotal":                           materialCostTotal,
3014
+		"materialCostSelfTotal":                       materialCostSelfTotal,
3015
+		"materialCostPartSelfTotal":                   materialCostPartSelfTotal,
3016
+		"westernMedicineCostTotal":                    westernMedicineCostTotal,
3017
+		"westernMedicineCostSelfTotal":                westernMedicineCostSelfTotal,
3018
+		"westernMedicineCostPartSelfTotal":            westernMedicineCostPartSelfTotal,
3019
+		"chineseTraditionalMedicineCostTotal":         chineseTraditionalMedicineCostTotal,
3020
+		"chineseTraditionalMedicineCostSelfTotal":     chineseTraditionalMedicineCostSelfTotal,
3021
+		"chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
3022
+		"checkCostTotal":                              checkCostTotal,
3023
+		"checkCostSelfTotal":                          checkCostSelfTotal,
3024
+		"checkCostPartSelfTotal":                      checkCostPartSelfTotal,
3025
+		"laboratoryCostTotal":                         laboratoryCostTotal,
3026
+		"laboratoryCostSelfTotal":                     laboratoryCostSelfTotal,
3027
+		"laboratoryCostPartSelfTotal":                 laboratoryCostPartSelfTotal,
3028
+		"treatCostTotal":                              treatCostTotal,
3029
+		"treatCostSelfTotal":                          treatCostSelfTotal,
3030
+		"treatCostPartSelfTotal":                      treatCostPartSelfTotal,
3031
+	})
3032
+
3033
+}
3034
+
3035
+func (this *HisApiController) GetIncomeStatisticsData() {
3036
+	start_time := this.GetString("start_time")
3037
+	end_time := this.GetString("end_time")
3038
+	key_words := this.GetString("key_words")
3039
+	limit, _ := this.GetInt64("limit")
3040
+	page, _ := this.GetInt64("page")
3041
+
3042
+	if page <= 0 {
3043
+		page = 1
3044
+	}
3045
+	if limit <= 0 {
3046
+		limit = 10
3047
+	}
3048
+	statistics_type, _ := this.GetInt64("statistics_type")
3049
+	admin := this.GetAdminUserInfo()
3050
+	timeLayout := "2006-01-02"
3051
+	loc, _ := time.LoadLocation("Local")
3052
+	var theStartTIme int64
3053
+	if len(start_time) > 0 {
3054
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
3055
+		if err != nil {
3056
+			theStartTIme = 0
3057
+		}
3058
+		theStartTIme = theTime.Unix()
3059
+	}
3060
+	var theEndtTIme int64
3061
+	if len(end_time) > 0 {
3062
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
3063
+		if err != nil {
3064
+			theEndtTIme = 0
3065
+		}
3066
+		theEndtTIme = theTime.Unix()
3067
+	}
3068
+
3069
+	if statistics_type == 1 {
3070
+		list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
3071
+		this.ServeSuccessJSON(map[string]interface{}{
3072
+			"list":  list,
3073
+			"total": total,
3074
+		})
3075
+	} else {
3076
+		list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
3077
+		this.ServeSuccessJSON(map[string]interface{}{
3078
+			"list":  list,
3079
+			"total": total,
3080
+		})
3081
+
3082
+	}
3083
+
3084
+}

+ 57 - 47
controllers/his_project_api_controller.go View File

@@ -805,55 +805,65 @@ func (this *HisProjectApiController) SaveHisPatient() {
805 805
 		return
806 806
 	}
807 807
 
808
-	timeStr := time.Now().Format("2006-01-02")
809
-	timeArr := strings.Split(timeStr, "-")
810
-	var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
811
-
812
-	his, err := service.GetHisPatientInfo(adminUserInfo.CurrentOrgId, patient.ID, recordDate.Unix())
813
-
814
-	var hisPatient models.XtHisPatient
815
-	if err == gorm.ErrRecordNotFound || his.ID == 0 {
816
-		hisPatient = models.XtHisPatient{
817
-			PatientId:              patient_id,
818
-			Birthday:               birthUnix,
819
-			IdType:                 certificates,
820
-			CostOfProduction:       cost_float,
821
-			Departments:            department,
822
-			Doctor:                 doctor,
823
-			AdminUserId:            adminUserInfo.AdminUser.Id,
824
-			MedicalTreatmentType:   medicalcare,
825
-			IdCardNo:               idcard,
826
-			IsNeedCostOfProduction: cost_checked,
827
-			TreatmentCost:          medicalExpense_float,
828
-			MedicalInsuranceNumber: medicalinsurancecard,
829
-			Name:                name,
830
-			Age:                 age,
831
-			Number:              str,
832
-			RegisterType:        register,
833
-			RegisterCost:        registrationfees_float,
834
-			BalanceAccountsType: settlementValue,
835
-			Gender:              sex,
836
-			Total:               totals_float,
837
-			UserOrgId:           orgId,
838
-			Status:              1,
839
-			RecordDate:          nowtime,
840
-			IsReturn:            1,
841
-			Ctime:               time.Now().Unix(),
842
-			Phone:               phone,
843
-			SocialType:          social_type,
844
-			IdCardType:          id_card_type,
845
-			Diagnosis:           diagnosis_id,
846
-			PType:               reg_type,
847
-			SickType:            sick_type,
808
+	timeStr := time.Now().Format("2006-01-02 15:04:05")
809
+	fmt.Println(timeStr)
810
+	timeArr := strings.Split(timeStr, " ")
811
+	timeArrTwo := strings.Split(timeArr[0], "-")
812
+	timeArrThree := strings.Split(timeArr[1], ":")
813
+	var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
814
+
815
+	his, _ := service.GetHisPatientInfoTwo(adminUserInfo.CurrentOrgId, patient.ID, recordDate.Unix())
816
+	if len(his) >= 1 {
817
+		order, _ := service.GetNewHisOrderTwo(adminUserInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDate.Unix())
818
+		if len(his) >= 1 && order.ID == 0 {
819
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
820
+			return
848 821
 		}
849
-		service.CreateHisPatient(&hisPatient)
850
-		this.ServeSuccessJSON(map[string]interface{}{
851
-			"his_info": hisPatient,
852
-		})
853
-	} else {
854
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisRegisterException)
855
-		return
856 822
 	}
823
+	var hisPatient models.XtHisPatient
824
+	//if err == gorm.ErrRecordNotFound || his.ID == 0 {
825
+	hisPatient = models.XtHisPatient{
826
+		PatientId:              patient_id,
827
+		Birthday:               birthUnix,
828
+		IdType:                 certificates,
829
+		CostOfProduction:       cost_float,
830
+		Departments:            department,
831
+		Doctor:                 doctor,
832
+		AdminUserId:            adminUserInfo.AdminUser.Id,
833
+		MedicalTreatmentType:   medicalcare,
834
+		IdCardNo:               idcard,
835
+		IsNeedCostOfProduction: cost_checked,
836
+		TreatmentCost:          medicalExpense_float,
837
+		MedicalInsuranceNumber: medicalinsurancecard,
838
+		Name:                name,
839
+		Age:                 age,
840
+		Number:              str,
841
+		RegisterType:        register,
842
+		RegisterCost:        registrationfees_float,
843
+		BalanceAccountsType: settlementValue,
844
+		Gender:              sex,
845
+		Total:               totals_float,
846
+		UserOrgId:           orgId,
847
+		Status:              1,
848
+		RecordDate:          nowtime,
849
+		IsReturn:            1,
850
+		Ctime:               time.Now().Unix(),
851
+		Phone:               phone,
852
+		SocialType:          social_type,
853
+		IdCardType:          id_card_type,
854
+		Diagnosis:           diagnosis_id,
855
+		PType:               reg_type,
856
+		SickType:            sick_type,
857
+	}
858
+	service.CreateHisPatient(&hisPatient)
859
+	this.ServeSuccessJSON(map[string]interface{}{
860
+		"his_info": hisPatient,
861
+	})
862
+	//}
863
+	//else {
864
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisRegisterException)
865
+	//	return
866
+	//}
857 867
 
858 868
 }
859 869
 

+ 43 - 20
controllers/new_mobile_api_controllers/mobile_his_api_controller.go View File

@@ -248,6 +248,7 @@ func (c *MobileHisApiController) CreateHisPrescription() {
248 248
 
249 249
 	if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
250 250
 		prescriptions, _ := dataBody["prescriptions"].([]interface{})
251
+		var tempPrescription *models.HisPrescription
251 252
 
252 253
 		if len(prescriptions) > 0 {
253 254
 			for _, item := range prescriptions {
@@ -259,6 +260,9 @@ func (c *MobileHisApiController) CreateHisPrescription() {
259 260
 				}
260 261
 				id := int64(items["id"].(float64))
261 262
 
263
+				new_prescription, _ := service.GetPrescriptionById(id, adminInfo.Org.Id)
264
+				tempPrescription = &new_prescription
265
+
262 266
 				if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
263 267
 					utils.ErrorLog("type")
264 268
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -266,6 +270,15 @@ func (c *MobileHisApiController) CreateHisPrescription() {
266 270
 				}
267 271
 				types := int64(items["type"].(float64))
268 272
 
273
+				if items["order_status"] == nil || reflect.TypeOf(items["order_status"]).String() != "float64" {
274
+					utils.ErrorLog("order_status")
275
+				}
276
+				order_status := int64(items["order_status"].(float64))
277
+
278
+				if order_status == 0 {
279
+					order_status = 1
280
+				}
281
+
269 282
 				if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
270 283
 					utils.ErrorLog("pre_time")
271 284
 				}
@@ -283,25 +296,35 @@ func (c *MobileHisApiController) CreateHisPrescription() {
283 296
 				fmt.Println(pTime)
284 297
 
285 298
 				ctime := time.Now().Unix()
286
-				prescription := &models.HisPrescription{
287
-					ID:                 id,
288
-					PatientId:          patient_id,
289
-					UserOrgId:          adminInfo.Org.Id,
290
-					RecordDate:         recordDateTime,
291
-					Ctime:              ctime,
292
-					Mtime:              ctime,
293
-					Type:               types,
294
-					Modifier:           adminInfo.AdminUser.Id,
295
-					Creator:            adminInfo.AdminUser.Id,
296
-					Status:             1,
297
-					Doctor:             role.UserName,
298
-					HisPatientId:       his_patient_id,
299
-					OrderStatus:        1,
300
-					BatchNumber:        "",
301
-					PrescriptionNumber: hpInfo.PrescriptionNumber,
302
-					PreTime:            pTime,
299
+				if tempPrescription.ID == 0 {
300
+					prescription := &models.HisPrescription{
301
+						ID:                 id,
302
+						PatientId:          patient_id,
303
+						UserOrgId:          adminInfo.Org.Id,
304
+						RecordDate:         recordDateTime,
305
+						Ctime:              ctime,
306
+						Mtime:              ctime,
307
+						Type:               types,
308
+						Modifier:           adminInfo.AdminUser.Id,
309
+						Creator:            adminInfo.AdminUser.Id,
310
+						Status:             1,
311
+						Doctor:             role.UserName,
312
+						HisPatientId:       his_patient_id,
313
+						OrderStatus:        order_status,
314
+						BatchNumber:        "",
315
+						PrescriptionNumber: hpInfo.PrescriptionNumber,
316
+						PreTime:            pTime,
317
+					}
318
+					tempPrescription = prescription
319
+				} else {
320
+					tempPrescription.Type = types
321
+					tempPrescription.Modifier = adminInfo.AdminUser.Id
322
+					tempPrescription.Mtime = time.Now().Unix()
323
+					tempPrescription.Doctor = role.UserName
324
+					tempPrescription.OrderStatus = order_status
325
+					tempPrescription.PreTime = pTime
303 326
 				}
304
-				service.SaveHisPrescription(prescription)
327
+				service.SaveHisPrescription(tempPrescription)
305 328
 
306 329
 				//更改患者挂号状态
307 330
 				_, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.Org.Id)
@@ -315,7 +338,7 @@ func (c *MobileHisApiController) CreateHisPrescription() {
315 338
 					if len(advices) > 0 {
316 339
 						for _, advice := range advices {
317 340
 							var s models.HisDoctorAdviceInfo
318
-							s.PrescriptionId = prescription.ID
341
+							s.PrescriptionId = tempPrescription.ID
319 342
 							s.AdviceType = 2
320 343
 							s.AdviceDoctor = doctor_id
321 344
 							s.StopState = 2
@@ -352,7 +375,7 @@ func (c *MobileHisApiController) CreateHisPrescription() {
352 375
 					if len(projects) > 0 {
353 376
 						for _, project := range projects {
354 377
 							var p models.HisPrescriptionProject
355
-							p.PrescriptionId = prescription.ID
378
+							p.PrescriptionId = tempPrescription.ID
356 379
 							p.Ctime = time.Now().Unix()
357 380
 							p.Mtime = time.Now().Unix()
358 381
 							p.PatientId = patient_id

+ 4 - 0
enums/error_code.go View File

@@ -228,6 +228,8 @@ const ( // ErrorCode
228 228
 	ErrorCodeNoBloodPatientException = 300002
229 229
 
230 230
 	ErrorCodeOrderParamWrong = 300003
231
+
232
+	ErrorCodeHisPatientParamWrong = 300004
231 233
 )
232 234
 
233 235
 var ErrCodeMsgs = map[int]string{
@@ -446,6 +448,8 @@ var ErrCodeMsgs = map[int]string{
446 448
 	ErrorCodeNoBloodPatientException: "找不到该患者,请先在系统录入患者信息或检查患者身份证信息",
447 449
 
448 450
 	ErrorCodeOrderParamWrong: "结算记录不存在",
451
+
452
+	ErrorCodeHisPatientParamWrong: "订单正在结算、请先结算完成",
449 453
 }
450 454
 
451 455
 type SGJError struct {

+ 3 - 1
models/his_models.go View File

@@ -703,13 +703,15 @@ type HisOrder struct {
703 703
 	DoctorName            string    `gorm:"-" json:"doctor_name" form:"doctor_name"`
704 704
 	Creator               int64     `gorm:"column:creator" json:"creator" form:"creator"`
705 705
 
706
+	AdminUser AdminUser `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
707
+
706 708
 	SettleType      int64 `gorm:"column:settle_type" json:"settle_type" form:"settle_type"`
707 709
 	SettleStartTime int64 `gorm:"column:settle_start_time" json:"settle_start_time" form:"settle_start_time"`
708 710
 	SettleEndTime   int64 `gorm:"column:settle_end_time" json:"settle_end_time" form:"settle_end_time"`
709 711
 
710 712
 	HisOrderInfo        HisOrderInfo        `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
711 713
 	Patients            Patients            `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
712
-	HisPatient          HisPatient          `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
714
+	HisPatient          HisPatient          `gorm:"ForeignKey:MdtrtId,PatientId;AssociationForeignKey:Number,PatientId" json:"his_patient"`
713 715
 	HisPrescriptionInfo HisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"p_info"`
714 716
 }
715 717
 

+ 1 - 1
service/gobal_config_service.go View File

@@ -203,7 +203,7 @@ func GetExportHisOrderList(user_org_id int64, start_time int64, end_time int64)
203 203
 		db = db.Where("his_order.settle_accounts_date<=?", end_time)
204 204
 	}
205 205
 
206
-	db = db.Where("his_order.status = 1 AND his_order.user_org_id = ?", user_org_id)
206
+	db = db.Where("his_order.status = 1 AND his_order.user_org_id = ? AND his_order.order_status > 1 ", user_org_id)
207 207
 
208 208
 	db = db.Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
209 209
 		Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).

+ 6 - 3
service/his_project_service.go View File

@@ -262,6 +262,11 @@ func CreateHisPatient(patient *models.XtHisPatient) error {
262 262
 	return err
263 263
 }
264 264
 
265
+func UpdateHisPrescriptionHisID(his_patient_id int64, patient_id int64, record_time int64, org_id int64) {
266
+	XTWriteDB().Model(&models.HisPrescription{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ?", record_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
267
+	return
268
+}
269
+
265 270
 func GetBloodPatientByIdCard(idcard string, orgid int64) (*models.XtPatients, error) {
266 271
 	var patients models.XtPatients
267 272
 	var err error
@@ -290,8 +295,7 @@ func GetProjectListById(orgid int64, ids []string) (project []*models.XtHisProje
290 295
 func GetHisPatientHistory(keyword string, startime int64, endtime int64, registtype int64, limit int64, page int64, orgid int64) (hisPatient []*models.XtHisPatient, total int64, err error) {
291 296
 	offset := (page - 1) * limit
292 297
 	likeKey := "%" + keyword + "%"
293
-	db := XTReadDB().Table("his_patient as x").Where("x.status = 1")
294
-
298
+	db := XTReadDB().Table("his_patient as x")
295 299
 	if len(keyword) > 0 {
296 300
 		db = db.Where("x.name like ?", likeKey)
297 301
 	}
@@ -307,7 +311,6 @@ func GetHisPatientHistory(keyword string, startime int64, endtime int64, registt
307 311
 	if orgid > 0 {
308 312
 		db = db.Where("x.user_org_id = ?", orgid)
309 313
 	}
310
-	db = db.Preload("HisOrder", "status = 1 AND user_org_id = ?", orgid)
311 314
 	err = db.Select("x.id,x.balance_accounts_type,x.medical_insurance_number,x.name,x.gender,x.id_type,x.medical_treatment_type,x.birthday,x.record_date,x.age,x.phone_number,x.id_card_no,x.register_type,x.admin_user_id,x.departments,x.is_need_cost_of_production,x.register_cost,x.treatment_cost,x.cost_of_production,x.total,x.user_org_id,x.patient_id,x.number,x.is_return,x.doctor,x.ctime,x.social_type,x.phone,x.status").Count(&total).Offset(offset).Limit(limit).Order("x.id desc").Find(&hisPatient).Error
312 315
 	return hisPatient, total, err
313 316
 }

+ 308 - 13
service/his_service.go View File

@@ -35,6 +35,7 @@ type HisPatient struct {
35 35
 	HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"prescription"`
36 36
 	PatientId       int64              `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
37 37
 	Number          string             `gorm:"column:number" json:"number" form:"number"`
38
+	VMHisOrder      VMHisOrder         `gorm:"ForeignKey:MdtrtId,PatientId;AssociationForeignKey:Number,PatientId" json:"order"`
38 39
 }
39 40
 
40 41
 func (HisPatient) TableName() string {
@@ -103,6 +104,8 @@ type VMHisOrder struct {
103 104
 	MedicalInsurancePrice float64 `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
104 105
 	PrivatePrice          float64 `gorm:"column:private_price" json:"private_price" form:"private_price"`
105 106
 	Creator               int64   `gorm:"column:creator" json:"creator" form:"creator"`
107
+	MdtrtId               string  `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
108
+	MzNumber              string  `gorm:"column:mz_number" json:"mz_number" form:"mz_number"`
106 109
 }
107 110
 
108 111
 func (VMHisOrder) TableName() string {
@@ -191,6 +194,88 @@ func GetHisPatientList(org_id int64, keywords string, record_date int64) (patien
191 194
 	return
192 195
 }
193 196
 
197
+type PatientTwo struct {
198
+	ID                    int64                 `gorm:"column:id" json:"id" form:"id"`
199
+	UserOrgId             int64                 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
200
+	Name                  string                `gorm:"column:name" json:"name" form:"name"`
201
+	Status                int64                 `gorm:"column:status" json:"status" form:"status"`
202
+	IdCardNo              string                `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
203
+	ScheduleType          int64                 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
204
+	Schedule              Schedule              `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
205
+	HisPatient            []*HisPatientTwo      `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
206
+	VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
207
+}
208
+
209
+func (PatientTwo) TableName() string {
210
+	return "xt_patients"
211
+}
212
+
213
+type HisPatientTwo struct {
214
+	ID                 int64                 `gorm:"column:id" json:"id" form:"id"`
215
+	Name               string                `gorm:"column:name" json:"name" form:"name"`
216
+	Gender             int64                 `gorm:"column:gender" json:"gender" form:"gender"`
217
+	Total              float64               `gorm:"column:total" json:"total" form:"total"`
218
+	UserOrgId          int64                 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
219
+	Status             int64                 `gorm:"column:status" json:"status" form:"status"`
220
+	RecordDate         int64                 `gorm:"column:record_date" json:"record_date" form:"record_date"`
221
+	HisPrescriptionTwo []*HisPrescriptionTwo `gorm:"ForeignKey:PatientId,HisPatientId;AssociationForeignKey:PatientId,ID" json:"prescription"`
222
+	PatientId          int64                 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
223
+	Number             string                `gorm:"column:number" json:"number" form:"number"`
224
+}
225
+
226
+func (HisPatientTwo) TableName() string {
227
+	return "his_patient"
228
+}
229
+
230
+type HisPrescriptionTwo struct {
231
+	ID                 int64  `gorm:"column:id" json:"id" form:"id"`
232
+	UserOrgId          int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
233
+	RecordDate         int64  `gorm:"column:record_date" json:"record_date" form:"record_date"`
234
+	PatientId          int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
235
+	HisPatientId       int64  `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
236
+	Status             int64  `gorm:"column:status" json:"status" form:"status"`
237
+	Ctime              int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
238
+	Mtime              int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
239
+	Number             string `gorm:"column:number" json:"number" form:"number"`
240
+	Type               int64  `gorm:"column:type" json:"type" form:"type"`
241
+	Doctor             string `gorm:"column:doctor" json:"doctor" form:"doctor"`
242
+	Creator            int64  `gorm:"column:creator" json:"creator" form:"creator"`
243
+	Modifier           int64  `gorm:"column:modifier" json:"modifier" form:"modifier"`
244
+	OrderStatus        int64  `gorm:"column:order_status" json:"order_status" form:"order_status"`
245
+	PreTime            int64  `gorm:"column:pre_time" json:"pre_time" form:"pre_time"`
246
+	BatchNumber        string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
247
+	PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
248
+}
249
+
250
+func (HisPrescriptionTwo) TableName() string {
251
+	return "his_prescription"
252
+}
253
+
254
+func GetNewHisPatientList(org_id int64, record_date int64) (patients []*PatientTwo, err error) {
255
+	db := readDb.Model(&PatientTwo{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
256
+		Joins("join his_patient as hp ON hp.patient_id = xt_patients.id AND hp.record_date = ? AND hp.status = 1 AND hp.user_org_id = ?", record_date, org_id)
257
+	db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
258
+		return db.Preload("HisPrescriptionTwo", "status = 1 AND user_org_id = ?  AND record_date = ?", org_id, record_date).Where("user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
259
+	})
260
+	err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Group("id").Find(&patients).Error
261
+	return
262
+}
263
+
264
+func GetNewScheduleHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*Patients, err error) {
265
+	db := readDb.Model(&Patients{}).Select("xt_patients.id,xt_patients.user_org_id,xt_patients.name,xt_patients.status,xt_patients.id_card_no,sch.schedule_type as sch_type").Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
266
+
267
+	if sch_type != 0 {
268
+		db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? AND sch.schedule_type = ?", record_date, org_id, sch_type)
269
+	} else {
270
+		db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? ", record_date, org_id)
271
+	}
272
+
273
+	db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
274
+	db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
275
+	err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Group("xt_patients.id").Order("sch_type").Find(&patients).Error
276
+	return
277
+}
278
+
194 279
 func GetAllBaseDrugStockList(org_id int64) (drugs []*models.BaseDrugLib, err error) {
195 280
 	err = readDb.Model(&models.BaseDrugLib{}).Where("user_org_id = ? AND status = 1", org_id).Find(&drugs).Error
196 281
 	return
@@ -201,6 +286,21 @@ func GetHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info
201 286
 	return
202 287
 }
203 288
 
289
+func GetHisPatientInfoTwo(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
290
+	err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Find(&info).Error
291
+	return
292
+}
293
+
294
+func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
295
+	err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Find(&info).Error
296
+	return
297
+}
298
+
299
+func GetNewHisPatientInfoTwo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
300
+	err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND id = ?", org_id, record_date, id).First(&info).Error
301
+	return
302
+}
303
+
204 304
 func GetXTPatientInfo(org_id int64, patient_id int64) (info models.Patients, err error) {
205 305
 	err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1  AND id = ?", org_id, patient_id).First(&info).Error
206 306
 	return
@@ -308,7 +408,7 @@ func GetHisPrescription(org_id int64, patient_id int64, record_date int64) (pres
308 408
 	return
309 409
 }
310 410
 
311
-func GetChargeHisPrescriptionFive(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
411
+func GetNewHisPrescription(org_id int64, patient_id int64, his_patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
312 412
 	err = readDb.Model(&models.HisPrescription{}).
313 413
 		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
314 414
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
@@ -319,12 +419,12 @@ func GetChargeHisPrescriptionFive(org_id int64, patient_id int64, record_date in
319 419
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
320 420
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
321 421
 		}).
322
-		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status = 2", org_id, record_date, patient_id).
422
+		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND his_patient_id = ? ", org_id, record_date, patient_id, his_patient_id).
323 423
 		Find(&prescription).Error
324 424
 	return
325 425
 }
326 426
 
327
-func GetUnChargeHisPrescriptionFive(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
427
+func GetChargeHisPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
328 428
 	err = readDb.Model(&models.HisPrescription{}).
329 429
 		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
330 430
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
@@ -335,12 +435,12 @@ func GetUnChargeHisPrescriptionFive(org_id int64, patient_id int64, record_date
335 435
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
336 436
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
337 437
 		}).
338
-		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).
438
+		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status = 2 AND his_patient_id = ?", org_id, record_date, patient_id, his_patient_id).
339 439
 		Find(&prescription).Error
340 440
 	return
341 441
 }
342 442
 
343
-func GetSettleHisPrescription(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
443
+func GetUnChargeHisPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
344 444
 	err = readDb.Model(&models.HisPrescription{}).
345 445
 		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
346 446
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
@@ -351,7 +451,23 @@ func GetSettleHisPrescription(org_id int64, patient_id int64, record_date int64)
351 451
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
352 452
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
353 453
 		}).
354
-		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2", org_id, record_date, patient_id).
454
+		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND his_patient_id = ? AND order_status <> 2 AND order_status <> 3", org_id, record_date, patient_id, his_patient_id).
455
+		Find(&prescription).Error
456
+	return
457
+}
458
+
459
+func GetSettleHisPrescription(org_id int64, patient_id int64, his_patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
460
+	err = readDb.Model(&models.HisPrescription{}).
461
+		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
462
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
463
+		}).
464
+		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
465
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
466
+		}).
467
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
468
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
469
+		}).
470
+		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND his_patient_id = ?", org_id, record_date, patient_id, his_patient_id).
355 471
 		Find(&prescription).Error
356 472
 	return
357 473
 }
@@ -609,8 +725,8 @@ func CreateHisPatientTwo(patient *models.VMHisPatient) error {
609 725
 	return err
610 726
 }
611 727
 
612
-func GetVMHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.VMHisPatient, err error) {
613
-	err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
728
+func GetVMHisPatientInfo(org_id int64, id int64, record_date int64) (info models.VMHisPatient, err error) {
729
+	err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND id = ?", org_id, record_date, id).First(&info).Error
614 730
 	return
615 731
 }
616 732
 
@@ -669,7 +785,7 @@ func GetHisOrderList(user_org_id int64, page int64, limit int64, start_time int6
669 785
 		Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id)
670 786
 
671 787
 	db = db.Count(&total)
672
-	err = db.Limit(limit).Offset(offset).Order("ctime desc").Find(&order).Error
788
+	err = db.Limit(limit).Offset(offset).Order("setl_time desc,ctime").Find(&order).Error
673 789
 	return
674 790
 }
675 791
 
@@ -1290,15 +1406,25 @@ func (MedicalInsuranceCostCompare) TableName() string {
1290 1406
 	return "medical_insurance_cost_compare"
1291 1407
 }
1292 1408
 
1293
-func GetMedicalInsuranceCostCompareList(orgID, page, limit int64, keywords string) (list []*MedicalInsuranceCostCompare, total int, err error) {
1409
+func GetMedicalInsuranceCostCompareList(orgID, page, limit int64, keywords string, insutype string, start_time int64, end_time int64) (list []*MedicalInsuranceCostCompare, total int, err error) {
1294 1410
 	offset := (page - 1) * limit
1295
-	db := readDb.Model(&MedicalInsuranceCostCompare{}).Where("user_org_id = ?", orgID)
1296
-
1411
+	db := readDb.Model(&MedicalInsuranceCostCompare{}).Where("medical_insurance_cost_compare.user_org_id = ?", orgID)
1297 1412
 	if len(keywords) == 0 {
1298 1413
 		db = db.Where("status=1")
1414
+		if len(insutype) != 0 {
1415
+			db = db.Where("insutype = ?", insutype)
1416
+		}
1417
+		if start_time != 0 {
1418
+			db = db.Where("ctime  >= ? ", start_time)
1419
+		}
1420
+		if end_time != 0 {
1421
+			db = db.Where("ctime  <= ? ", end_time)
1422
+		}
1299 1423
 		err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
1300 1424
 	} else {
1301
-		db = db.Where("status=1")
1425
+		keywords = "%" + keywords + "%"
1426
+		db = db.Joins("join sgj_users.sgj_user_admin_role role  on role.admin_user_id = medical_insurance_cost_compare.creator and role.user_name Like ?", keywords)
1427
+		db = db.Where("medical_insurance_cost_compare.status=1 ")
1302 1428
 		err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
1303 1429
 	}
1304 1430
 	return
@@ -1372,3 +1498,172 @@ func GetGdybPsnNcdsRecordList(orgID, page, limit int64, keywords string, is_canc
1372 1498
 
1373 1499
 	return
1374 1500
 }
1501
+
1502
+type CustomAccountFormData struct {
1503
+	MedfeeSumamt       float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
1504
+	PsnName            string  `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
1505
+	IdCardNo           string  `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
1506
+	PsnNo              string  `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
1507
+	MdtrtiId           string  `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
1508
+	SettleAccountsDate int64   `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
1509
+	ActPayDedc         float64 `gorm:"column:act_pay_dedc" json:"act_pay_dedc" form:"act_pay_dedc"`
1510
+	FundPaySumamt      float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
1511
+	PsnCashPay         float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
1512
+	AcctPay            float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
1513
+	CashPay            float64 `gorm:"column:cash_pay" json:"cash_pay" form:"cash_pay"`
1514
+	Sumamt             float64 `gorm:"column:sumamt" json:"sumamt" form:"sumamt"`
1515
+}
1516
+
1517
+func GetCheckAccountFormData(start_time int64, end_time int64, org_id int64, insutype string) (cus []*CustomAccountFormData, err error) {
1518
+	err = readDb.Raw("select o.medfee_sumamt as medfee_sumamt ,o.psn_name as psn_name ,p.id_card_no as id_card_no ,o.psn_no as psn_no, o.mdtrt_id as mdtrt_id, o.settle_accounts_date as settle_accounts_date,o.act_pay_dedc as act_pay_dedc,O.fund_pay_sumamt as fund_pay_sumamt,o.psn_cash_pay as psn_cash_pay ,o.acct_pay as acct_pay,o.psn_cash_pay as cash_pay,o.medfee_sumamt as sumamt  from his_order o Join his_patient p On o.patient_id = p.patient_id AND o.settle_accounts_date = p.record_date where o.user_org_id = ? AND o.status = 1 AND o.order_status = 2  AND o.settle_accounts_date >= ? AND o.settle_accounts_date <= ? AND insutype = ? Group by o.id", org_id, start_time, end_time, insutype).Scan(&cus).Error
1519
+	return
1520
+}
1521
+
1522
+func GetNewHisPatientInfo(his_patient_id int64) (info models.HisPatient, err error) {
1523
+	err = readDb.Model(&models.HisPatient{}).Where("id = ? AND status = 1 ", his_patient_id).First(&info).Error
1524
+	return
1525
+}
1526
+
1527
+func GetNewHisOrder(user_org_id int64, mdtrt_id string, patient_id int64) (order HisOrder, err error) {
1528
+	err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND mdtrt_id=? ", user_org_id, patient_id, mdtrt_id).
1529
+		Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
1530
+		Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
1531
+		Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
1532
+		Preload("HisPrescriptionInfo", "status = 1 AND user_org_id = ?", user_org_id).
1533
+		Order("ctime desc").
1534
+		Find(&order).Error
1535
+	return
1536
+}
1537
+
1538
+func GetNewHisOrderTwo(user_org_id int64, mdtrt_id string, patient_id int64, record_time int64) (order HisOrder, err error) {
1539
+	err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND mdtrt_id=? AND settle_accounts_date = ? ", user_org_id, patient_id, mdtrt_id, record_time).
1540
+		Order("ctime desc").
1541
+		Find(&order).Error
1542
+	return
1543
+}
1544
+
1545
+type NewCustomPatients struct {
1546
+	ID         int64      `gorm:"column:id" json:"id" form:"id"`
1547
+	UserOrgId  int64      `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1548
+	Status     int64      `gorm:"column:status" json:"status" form:"status"`
1549
+	Number     string     `gorm:"column:number" json:"number" form:"number"`
1550
+	PatientId  int64      `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1551
+	RecordDate int64      `gorm:"column:record_date" json:"record_date" form:"record_date"`
1552
+	VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId,MdtrtId;AssociationForeignKey:PatientId,Number" json:"order"`
1553
+}
1554
+
1555
+func (NewCustomPatients) TableName() string {
1556
+	return "his_patients"
1557
+}
1558
+
1559
+type NewSZCustomPatients struct {
1560
+	ID         int64      `gorm:"column:id" json:"id" form:"id"`
1561
+	UserOrgId  int64      `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1562
+	Status     int64      `gorm:"column:status" json:"status" form:"status"`
1563
+	Number     string     `gorm:"column:number" json:"number" form:"number"`
1564
+	PatientId  int64      `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1565
+	RecordDate int64      `gorm:"column:record_date" json:"record_date" form:"record_date"`
1566
+	VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId,MdtrtId;AssociationForeignKey:PatientId,MzNumber" json:"order"`
1567
+}
1568
+
1569
+func (NewSZCustomPatients) TableName() string {
1570
+	return "his_patients"
1571
+}
1572
+
1573
+//
1574
+//func GetNewAllChargeHisPatientList(org_id int64, record_date int64) (patients []*NewSZCustomPatients, err error) {
1575
+//	var tempPatients []*NewSZCustomPatients
1576
+//	db := readDb.Model(&NewSZCustomPatients{}).Where("his_patients.user_org_id = ? AND his_patients.status = 1", org_id)
1577
+//	db = db.Preload("VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
1578
+//	return tempPatients, err
1579
+//}
1580
+
1581
+type NewTempPatients struct {
1582
+	ID           int64  `gorm:"column:id" json:"id" form:"id"`
1583
+	UserOrgId    int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1584
+	Name         string `gorm:"column:name" json:"name" form:"name"`
1585
+	Status       int64  `gorm:"column:status" json:"status" form:"status"`
1586
+	IdCardNo     string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
1587
+	ScheduleType int64  `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
1588
+
1589
+	Schedule              Schedule              `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
1590
+	HisPatient            []*HisPatient         `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
1591
+	HisPrescription       []*HisPrescription    `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
1592
+	VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
1593
+}
1594
+
1595
+func (NewTempPatients) TableName() string {
1596
+	return "xt_patients"
1597
+}
1598
+
1599
+//"VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date
1600
+
1601
+func GetNewAllChargeHisPatientList(org_id int64, keywords string, record_date int64) (patients []*NewTempPatients, err error) {
1602
+	db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
1603
+	db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
1604
+		return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Preload("VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
1605
+	})
1606
+	db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
1607
+	err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
1608
+	return
1609
+}
1610
+
1611
+func GetPrescriptionById(id int64, org_id int64) (prescription models.HisPrescription, err error) {
1612
+	err = readDb.Model(&models.HisPrescription{}).Where("id = ? AND user_org_id = ? AND status = 1", id, org_id).First(&prescription).Error
1613
+	return
1614
+}
1615
+
1616
+type CustomInComeStatistics struct {
1617
+	PsnName            string  `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
1618
+	SetlTime           string  `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
1619
+	SettleAccountsDate string  `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
1620
+	MedfeeSumamt       float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
1621
+	FundPaySumamt      float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
1622
+	HifobPay           float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
1623
+	HifmiPay           float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
1624
+	HifesPay           float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
1625
+	MafPay             float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
1626
+	CvlservPay         float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
1627
+	PsnCashPay         float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
1628
+	DiscountPrice      float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
1629
+	PreferentialPrice  float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
1630
+	AcctPay            float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
1631
+}
1632
+
1633
+func (CustomInComeStatistics) TableName() string {
1634
+	return "his_order"
1635
+}
1636
+
1637
+func GetDayIncomeStatisticsData(org_id int64, keywords string, start_time int64, end_time int64, page int64, limit int64) (order []*CustomInComeStatistics, total int64, err error) {
1638
+	offset := (page - 1) * limit
1639
+	if len(keywords) != 0 {
1640
+
1641
+		err = readDb.Model(&CustomInComeStatistics{}).Select("sum(medfee_sumamt) as medfee_sumamt,sum(`fund_pay_sumamt`) as fund_pay_sumamt, sum(`hifob_pay`) as hifob_pay, sum(`hifmi_pay`) as hifmi_pay , sum(`hifes_pay`) as hifes_pay, sum(`maf_pay`) as maf_pay,sum(`cvlserv_pay`) as cvlserv_pay, sum(`discount_price`) as discount_price, sum(`preferential_price`) as preferential_price,sum(`acct_pay`)  as acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2  ", org_id).Group("settle_accounts_date").Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&order).Error
1642
+
1643
+	} else {
1644
+
1645
+		if start_time != 0 && end_time != 0 {
1646
+			err = readDb.Model(&CustomInComeStatistics{}).Select("sum(medfee_sumamt) as medfee_sumamt,sum(`fund_pay_sumamt`) as fund_pay_sumamt, sum(`hifob_pay`) as hifob_pay, sum(`hifmi_pay`) as hifmi_pay , sum(`hifes_pay`) as hifes_pay, sum(`maf_pay`) as maf_pay,sum(`cvlserv_pay`) as cvlserv_pay, sum(`discount_price`) as discount_price, sum(`preferential_price`) as preferential_price,sum(`acct_pay`)  as acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2  AND settle_accounts_date >= ? AND settle_accounts_date <= ?", org_id, start_time, end_time).Group("settle_accounts_date").Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&order).Error
1647
+		} else {
1648
+			err = readDb.Model(&CustomInComeStatistics{}).Select("sum(medfee_sumamt) as medfee_sumamt,sum(`fund_pay_sumamt`) as fund_pay_sumamt, sum(`hifob_pay`) as hifob_pay, sum(`hifmi_pay`) as hifmi_pay , sum(`hifes_pay`) as hifes_pay, sum(`maf_pay`) as maf_pay,sum(`cvlserv_pay`) as cvlserv_pay, sum(`discount_price`) as discount_price, sum(`preferential_price`) as preferential_price,sum(`acct_pay`)  as acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2  ", org_id).Group("settle_accounts_date").Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&order).Error
1649
+
1650
+		}
1651
+
1652
+	}
1653
+
1654
+	return
1655
+}
1656
+
1657
+func GetDayIncomeDetailStatisticsData(org_id int64, keywords string, start_time int64, end_time int64, page int64, limit int64) (cis []*CustomInComeStatistics, total int64, err error) {
1658
+	offset := (page - 1) * limit
1659
+	if len(keywords) != 0 {
1660
+		err = readDb.Model(&CustomInComeStatistics{}).Select("psn_name,setl_time,medfee_sumamt,fund_pay_sumamt, hifob_pay,  hifmi_pay ,  hifes_pay,  maf_pay, cvlserv_pay, discount_price,preferential_price,acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2  ", org_id).Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&cis).Error
1661
+	} else {
1662
+		if start_time != 0 && end_time != 0 {
1663
+			err = readDb.Model(&CustomInComeStatistics{}).Select("psn_name,setl_time,medfee_sumamt,fund_pay_sumamt, hifob_pay,  hifmi_pay ,  hifes_pay,  maf_pay, cvlserv_pay, discount_price,preferential_price,acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 AND  settle_accounts_date >= ? AND settle_accounts_date <= ?  ", org_id, start_time, end_time).Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&cis).Error
1664
+		} else {
1665
+			err = readDb.Model(&CustomInComeStatistics{}).Select("psn_name,setl_time,medfee_sumamt,fund_pay_sumamt, hifob_pay,  hifmi_pay ,  hifes_pay,  maf_pay, cvlserv_pay, discount_price,preferential_price,acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2", org_id).Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&cis).Error
1666
+		}
1667
+	}
1668
+	return
1669
+}

+ 8 - 0
service/user_service.go View File

@@ -55,6 +55,14 @@ func GetAllAdminUsers(orgId, appid int64) (list []*AdminUserList, err error) {
55 55
 	return
56 56
 }
57 57
 
58
+func GetAllAdminUsersTwo(orgId int64) (list []*AdminUserList, err error) {
59
+	//fmt.Println("orgid", orgId)
60
+	//fmt.Println("appid", appid)
61
+	err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1 and uar.org_id=?  and ua.status=1", orgId).Select("ua.id, uar.user_name as name, uar.user_type").Scan(&list).Error
62
+	//err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1  and ua.status=1").Select("ua.id, uar.user_name as name, uar.user_type").Scan(&list).Error
63
+	return
64
+}
65
+
58 66
 func GetAdminUser(orgId, appid, id int64) (*AdminUserList, error) {
59 67
 	var err error
60 68
 	var user AdminUserList