csx пре 3 година
родитељ
комит
32aad4a42a

+ 290 - 205
controllers/his_hospital_api_controller.go Прегледај датотеку

@@ -28,6 +28,7 @@ func HisHospitalManagerApiRegistRouters() {
28 28
 	beego.Router("/api/hospital/inthopitaluncheck/get", &HisHospitalApiController{}, "get:GetZHInHospitalUnCheck")
29 29
 	beego.Router("/api/hospital/outhopitaluncheck/get", &HisHospitalApiController{}, "get:GetZHOutHospitalUnCheck")
30 30
 	beego.Router("/api/hospital/refund", &HisHospitalApiController{}, "get:ZHRefund")
31
+	beego.Router("/api/hospital/upload", &HisHospitalApiController{}, "get:GetUploadInfo")
31 32
 
32 33
 	beego.Router("/api/hospitaldetail/list", &HisHospitalApiController{}, "get:GetHisHospitalDetailPatientList")
33 34
 	beego.Router("/api/hospitaldetail/info", &HisHospitalApiController{}, "get:GetHisHospitalDetailInfo")
@@ -36,6 +37,237 @@ func HisHospitalManagerApiRegistRouters() {
36 37
 
37 38
 }
38 39
 
40
+func (c *HisHospitalApiController) GetUploadInfo() {
41
+	id, _ := c.GetInt64("id")
42
+	record_time := c.GetString("record_time")
43
+	in_hospital_id, _ := c.GetInt64("in_hospital_id")
44
+	settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
45
+
46
+	timeLayout := "2006-01-02"
47
+	loc, _ := time.LoadLocation("Local")
48
+	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
49
+	if err != nil {
50
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
51
+		return
52
+	}
53
+	recordDateTime := theTime.Unix()
54
+	adminUser := c.GetAdminUserInfo()
55
+
56
+	var prescriptions []*models.HisPrescription
57
+
58
+	if settle_accounts_type == 1 { //日结
59
+		prescriptions, _ = service.GetZHHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
60
+
61
+	} else { //月结
62
+		start_time_str := c.GetString("start_time")
63
+		end_time_str := c.GetString("end_time")
64
+		timeLayout := "2006-01-02"
65
+		loc, _ := time.LoadLocation("Local")
66
+		theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
67
+		if err != nil {
68
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
69
+			return
70
+		}
71
+		recordStartTime := theStartTime.Unix()
72
+		theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
73
+		if err != nil {
74
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
75
+			return
76
+		}
77
+		recordEndTime := theEndTime.Unix()
78
+		prescriptions, _ = service.GetZHMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
79
+
80
+	}
81
+
82
+	record, _ := service.GetInHospitalRecord(in_hospital_id)
83
+
84
+	if record.ID == 0 {
85
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
86
+		return
87
+	}
88
+
89
+	var ids []int64
90
+
91
+	for _, item := range prescriptions {
92
+		ids = append(ids, item.ID)
93
+	}
94
+	config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
95
+	if config.IsOpen == 1 { //对接了医保,走医保流程
96
+
97
+		var customs []*models.NewCustom
98
+
99
+		for _, item := range prescriptions {
100
+			tm := time.Unix(item.PreTime, 0)
101
+			if item.Type == 1 { //药品
102
+				for _, subItem := range item.HisDoctorAdviceInfo {
103
+					if len(subItem.Drug.MedicalInsuranceNumber) > 0 && subItem.Drug.IsUser != 1 {
104
+						//var randNum int
105
+						//randNum = rand.Intn(10000) + 1000
106
+						cus := &models.NewCustom{
107
+							DetItemFeeSumamt: subItem.Price * subItem.PrescribingNumber,
108
+							Cut:              subItem.PrescribingNumber,
109
+							FeedetlSn:        subItem.FeedetlSn,
110
+							Price:            subItem.Price,
111
+							MedListCodg:      subItem.Drug.MedicalInsuranceNumber,
112
+							HospApprFlag:     subItem.Drug.HospApprFlag,
113
+							FeeOcurTime:      tm.Format("2006-01-02 15:04:05"),
114
+						}
115
+
116
+						customs = append(customs, cus)
117
+					}
118
+				}
119
+			}
120
+
121
+			if item.Type == 2 { //项目
122
+				for _, subItem := range item.HisPrescriptionProject {
123
+					if subItem.Type == 2 {
124
+						if len(subItem.HisProject.MedicalCode) > 0 {
125
+							cnt, _ := strconv.ParseFloat(subItem.Count, 64)
126
+							cus := &models.NewCustom{
127
+								DetItemFeeSumamt: subItem.Price * cnt,
128
+								Cut:              cnt,
129
+								FeedetlSn:        subItem.FeedetlSn,
130
+								Price:            float64(subItem.Price),
131
+								MedListCodg:      subItem.HisProject.MedicalCode,
132
+								HospApprFlag:     -1,
133
+								FeeOcurTime:      tm.Format("2006-01-02 15:04:05"),
134
+							}
135
+							customs = append(customs, cus)
136
+						}
137
+					} else if subItem.Type == 3 {
138
+						if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 && subItem.GoodInfo.IsUser != 1 {
139
+							cnt, _ := strconv.ParseFloat(subItem.Count, 64)
140
+
141
+							cus := &models.NewCustom{
142
+								DetItemFeeSumamt: subItem.Price * cnt,
143
+								Cut:              cnt,
144
+								FeedetlSn:        subItem.FeedetlSn,
145
+								Price:            float64(subItem.Price),
146
+								MedListCodg:      subItem.GoodInfo.MedicalInsuranceNumber,
147
+								HospApprFlag:     -1,
148
+								FeeOcurTime:      tm.Format("2006-01-02 15:04:05"),
149
+							}
150
+							customs = append(customs, cus)
151
+						}
152
+					}
153
+				}
154
+			}
155
+
156
+		}
157
+
158
+		if settle_accounts_type == 1 {
159
+			for _, subItem := range customs {
160
+				temp := strings.Split(subItem.FeedetlSn, "-")
161
+				var advice_id int64 = 0
162
+				var project_id int64 = 0
163
+				var types int64 = 0
164
+
165
+				id, _ := strconv.ParseInt(temp[2], 10, 64)
166
+				types, _ = strconv.ParseInt(temp[1], 10, 64)
167
+
168
+				if temp[1] == "1" {
169
+					advice_id = id
170
+					project_id = 0
171
+				} else if temp[1] == "2" {
172
+					advice_id = 0
173
+					project_id = id
174
+				}
175
+				info := &models.HisOrderInfo{
176
+					OrderNumber:      record.Number,
177
+					FeedetlSn:        subItem.FeedetlSn,
178
+					UploadDate:       recordDateTime,
179
+					AdviceId:         advice_id,
180
+					DetItemFeeSumamt: subItem.DetItemFeeSumamt,
181
+					Cnt:              subItem.Cut,
182
+					Pric:             float64(subItem.Price),
183
+					PatientId:        record.PatientId,
184
+					PricUplmtAmt:     0,
185
+					SelfpayProp:      0,
186
+					FulamtOwnpayAmt:  0,
187
+					OverlmtAmt:       0,
188
+					PreselfpayAmt:    0,
189
+					Status:           1,
190
+					Mtime:            time.Now().Unix(),
191
+					Ctime:            time.Now().Unix(),
192
+					UserOrgId:        adminUser.CurrentOrgId,
193
+					HisPatientId:     record.ID,
194
+					OrderId:          0,
195
+					ProjectId:        project_id,
196
+					Type:             types,
197
+					SettleType:       settle_accounts_type,
198
+				}
199
+				service.CreateOrderInfo(info)
200
+			}
201
+
202
+			err := service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
203
+			service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
204
+			service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, record.PatientId, record.Number, recordDateTime)
205
+			if err == nil {
206
+				c.ServeSuccessJSON(map[string]interface{}{
207
+					"msg": "上传费用明细成功",
208
+				})
209
+				return
210
+			} else {
211
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
212
+				return
213
+			}
214
+
215
+		} else {
216
+
217
+			for _, subItem := range customs {
218
+				temp := strings.Split(subItem.FeedetlSn, "-")
219
+				var advice_id int64 = 0
220
+				var project_id int64 = 0
221
+				var types int64 = 0
222
+
223
+				id, _ := strconv.ParseInt(temp[2], 10, 64)
224
+				types, _ = strconv.ParseInt(temp[1], 10, 64)
225
+
226
+				if temp[1] == "1" {
227
+					advice_id = id
228
+					project_id = 0
229
+				} else if temp[1] == "2" {
230
+					advice_id = 0
231
+					project_id = id
232
+				}
233
+				info := &models.HisOrderInfo{
234
+					OrderNumber:      record.Number,
235
+					FeedetlSn:        subItem.FeedetlSn,
236
+					UploadDate:       recordDateTime,
237
+					AdviceId:         advice_id,
238
+					DetItemFeeSumamt: subItem.DetItemFeeSumamt,
239
+					Cnt:              subItem.Cut,
240
+					Pric:             float64(subItem.Price),
241
+					PatientId:        record.PatientId,
242
+					PricUplmtAmt:     0,
243
+					SelfpayProp:      0,
244
+					FulamtOwnpayAmt:  0,
245
+					OverlmtAmt:       0,
246
+					PreselfpayAmt:    0,
247
+					Status:           1,
248
+					Mtime:            time.Now().Unix(),
249
+					Ctime:            time.Now().Unix(),
250
+					UserOrgId:        adminUser.CurrentOrgId,
251
+					HisPatientId:     record.ID,
252
+					OrderId:          0,
253
+					ProjectId:        project_id,
254
+					Type:             types,
255
+					SettleType:       settle_accounts_type,
256
+				}
257
+				service.CreateOrderInfo(info)
258
+			}
259
+
260
+			service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
261
+			service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
262
+			service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, record.PatientId, record.Number, recordDateTime)
263
+			c.ServeSuccessJSON(map[string]interface{}{
264
+				"msg": "上传费用明细成功",
265
+			})
266
+
267
+		}
268
+	}
269
+}
270
+
39 271
 func (c *HisHospitalApiController) GetHisHospitalPatientList() {
40 272
 	record_date := c.GetString("record_date")
41 273
 	types, _ := c.GetInt64("type", 0)
@@ -51,7 +283,7 @@ func (c *HisHospitalApiController) GetHisHospitalPatientList() {
51 283
 	recordDateTime := theTime.Unix()
52 284
 	adminInfo := c.GetAdminUserInfo()
53 285
 	//var patients []*service.HospitalPatient
54
-	tempPatients, _ := service.GetHisHospitalPatientList(adminInfo.CurrentOrgId, recordDateTime)
286
+	tempPatients, _ := service.GetHisHospitalPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
55 287
 	tempPatients_two, _ := service.GetHisHospitalSchPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
56 288
 
57 289
 	//当天有登记住院的和排班同时存在的话,删除掉排班的记录
@@ -375,12 +607,20 @@ func (c *HisHospitalApiController) GetZHInHospitalCheck() {
375 607
 }
376 608
 func (this *HisHospitalApiController) GetZHOutHospitalCheck() {
377 609
 	id, _ := this.GetInt64("id")
610
+	record_date := this.GetString("record_date")
611
+
378 612
 	record, _ := service.GetInHospitalRecord(id)
379 613
 	if record.ID == 0 {
380 614
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
381 615
 		return
382 616
 	}
383 617
 
618
+	timeLayout := "2006-01-02"
619
+	loc, _ := time.LoadLocation("Local")
620
+	theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
621
+
622
+	recordDateTime := theTime.Unix()
623
+
384 624
 	timestamp := time.Now().Unix()
385 625
 	tempTime := time.Unix(timestamp, 0)
386 626
 	timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
@@ -388,18 +628,48 @@ func (this *HisHospitalApiController) GetZHOutHospitalCheck() {
388 628
 	record.OutHosptialTime = timeFormatOne
389 629
 	record.OutWay = 1
390 630
 	service.CreateHospitalRecord(&record)
631
+
632
+	orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
633
+	var total float64
634
+	for _, item := range orders {
635
+		total = total + item.DetItemFeeSumamt
636
+	}
637
+
638
+	order := &models.HisOrder{
639
+		UserOrgId:           this.GetAdminUserInfo().CurrentOrgId,
640
+		HisPatientId:        record.ID,
641
+		PatientId:           record.PatientId,
642
+		SettleAccountsDate:  recordDateTime,
643
+		Ctime:               time.Now().Unix(),
644
+		Mtime:               time.Now().Unix(),
645
+		Status:              1,
646
+		Number:              record.Number,
647
+		Infcode:             0,
648
+		WarnMsg:             "",
649
+		Cainfo:              "",
650
+		ErrMsg:              "",
651
+		RespondTime:         "",
652
+		InfRefmsgid:         "",
653
+		OrderStatus:         1,
654
+		MdtrtId:             record.Number,
655
+		IsMedicineInsurance: 1,
656
+		PType:               1,
657
+		MedfeeSumamt:        total,
658
+	}
659
+	err := service.CreateOrder(order)
660
+	if err != nil {
661
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
662
+		return
663
+	}
664
+
391 665
 	this.ServeSuccessJSON(map[string]interface{}{
392 666
 		"msg": "出院成功",
393 667
 	})
394 668
 
395 669
 }
396 670
 func (c *HisHospitalApiController) GetSettleInfo() {
397
-	id, _ := c.GetInt64("id")
398
-	record_time := c.GetString("record_time")
671
+	order_id, _ := c.GetInt64("order_id")
399 672
 	in_hospital_id, _ := c.GetInt64("in_hospital_id")
400
-	settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
401
-
402
-	patient_id, _ := c.GetInt64("patient_id")
403 673
 	pay_way, _ := c.GetInt64("pay_way")
404 674
 	pay_price, _ := c.GetFloat("pay_price")
405 675
 	pay_card_no := c.GetString("pay_card_no")
@@ -411,107 +681,18 @@ func (c *HisHospitalApiController) GetSettleInfo() {
411 681
 	private_price, _ := c.GetFloat("private_price")
412 682
 	fapiao_code := c.GetString("fapiao_code")
413 683
 	fapiao_number := c.GetString("fapiao_number")
414
-
415
-	timeLayout := "2006-01-02"
416
-	loc, _ := time.LoadLocation("Local")
417
-	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
418
-	if err != nil {
419
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
420
-		return
421
-	}
422
-	recordDateTime := theTime.Unix()
423
-	adminUser := c.GetAdminUserInfo()
424
-
425
-	var prescriptions []*models.HisPrescription
426
-
427
-	var start_time int64
428
-	var end_time int64
429
-
430
-	if settle_accounts_type == 1 { //日结
431
-		//prescriptions, _ = service.GetZHHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
432
-
433
-	} else { //月结
434
-		start_time_str := c.GetString("start_time")
435
-		end_time_str := c.GetString("end_time")
436
-		timeLayout := "2006-01-02"
437
-		loc, _ := time.LoadLocation("Local")
438
-		theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
439
-		if err != nil {
440
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
441
-			return
442
-		}
443
-		recordStartTime := theStartTime.Unix()
444
-		start_time = recordStartTime
445
-		theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
446
-		if err != nil {
447
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
448
-			return
449
-		}
450
-		recordEndTime := theEndTime.Unix()
451
-		end_time = recordEndTime
452
-		prescriptions, _ = service.GetHospitalMonthHisPrescription(adminUser.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
453
-
454
-	}
455
-
456 684
 	record, _ := service.GetInHospitalRecord(in_hospital_id)
457
-
685
+	order, _ := service.GetHisOrderByID(order_id)
686
+	chrg_bchno := order.Number
458 687
 	if record.ID == 0 {
459 688
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
460 689
 		return
461 690
 	}
462
-
463
-	timestamp := time.Now().Unix()
464
-	tempTime := time.Unix(timestamp, 0)
465
-	timeFormat := tempTime.Format("20060102150405")
466
-	chrgBchno := rand.Intn(100000) + 10000
467
-	chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(record.PatientId, 10)
468
-
469
-	var ids []int64
470
-	fmt.Println(prescriptions)
471
-	for _, item := range prescriptions {
472
-		ids = append(ids, item.ID)
473
-	}
474
-	var total float64
475
-	fmt.Println(prescriptions)
476
-	for _, item := range prescriptions {
477
-		fmt.Println(item)
478
-		if item.Type == 1 { //药品
479
-			for _, subItem := range item.HisDoctorAdviceInfo {
480
-				total = total + (subItem.Price * subItem.PrescribingNumber)
481
-			}
482
-		}
483
-		if item.Type == 2 { //项目
484
-			for _, subItem := range item.HisPrescriptionProject {
485
-				cut, _ := strconv.ParseFloat(subItem.Count, 64)
486
-				total = total + (subItem.Price * cut)
487
-			}
488
-		}
489
-
490
-		for _, subItem := range item.HisAdditionalCharge {
491
-			total = total + (subItem.Price * float64(subItem.Count))
492
-		}
493
-	}
494
-
495
-	allTotal := fmt.Sprintf("%.2f", total)
496
-	totals, _ := strconv.ParseFloat(allTotal, 64)
497
-	order := &models.HisOrder{
498
-		UserOrgId:          adminUser.CurrentOrgId,
499
-		HisPatientId:       record.ID,
500
-		PatientId:          patient_id,
501
-		SettleAccountsDate: recordDateTime,
502
-		Ctime:              time.Now().Unix(),
503
-		Mtime:              time.Now().Unix(),
504
-		Status:             1,
505
-		OrderStatus:        2,
506
-		MdtrtId:            record.Number,
507
-		Number:             chrg_bchno,
508
-		MedfeeSumamt:       totals,
509
-		SettleEndTime:      end_time,
510
-		SettleStartTime:    start_time,
511
-		SettleType:         settle_accounts_type,
512
-		PType:              1,
513
-		Creator:            c.GetAdminUserInfo().AdminUser.Id,
691
+	if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
692
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
693
+		return
514 694
 	}
695
+	order.OrderStatus = 2
515 696
 	order.DiscountPrice = discount_price
516 697
 	order.MedicalInsurancePrice = medical_insurance_price
517 698
 	order.FaPiaoNumber = fapiao_number
@@ -523,115 +704,19 @@ func (c *HisHospitalApiController) GetSettleInfo() {
523 704
 	order.RealityPrice = reality_price
524 705
 	order.FoundPrice = found_price
525 706
 	order.PrivatePrice = private_price
526
-	err = service.CreateOrder(order)
527
-	if err != nil {
528
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
529
-		return
530
-	}
531
-
532
-	var customs []*Custom
533
-	for _, item := range prescriptions {
534
-		if item.Type == 1 { //药品
535
-			for _, subItem := range item.HisDoctorAdviceInfo {
536
-				cus := &Custom{
537
-					AdviceId:         subItem.ID,
538
-					ProjectId:        0,
539
-					DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
540
-					Cut:              fmt.Sprintf("%.2f", subItem.PrescribingNumber),
541
-					FeedetlSn:        subItem.FeedetlSn,
542
-					Price:            fmt.Sprintf("%.2f", subItem.Price),
543
-					MedListCodg:      subItem.MedListCodg,
544
-					Type:             1,
545
-				}
546
-				customs = append(customs, cus)
547
-			}
548
-		}
549
-		if item.Type == 2 { //项目
550
-
551
-			for _, subItem := range item.HisPrescriptionProject {
552
-				cut, _ := strconv.ParseFloat(subItem.Count, 64)
553
-
554
-				cus := &Custom{
555
-					AdviceId:         0,
556
-					ProjectId:        subItem.ID,
557
-					DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cut),
558
-					Cut:              fmt.Sprintf("%.2f", cut),
559
-					FeedetlSn:        subItem.FeedetlSn,
560
-					Price:            fmt.Sprintf("%.2f", float64(subItem.Price)),
561
-					MedListCodg:      subItem.MedListCodg,
562
-					Type:             2,
563
-				}
564
-				customs = append(customs, cus)
565
-			}
566
-		}
567
-		for _, item := range item.HisAdditionalCharge {
568
-			cus := &Custom{
569
-				ItemId:           item.ID,
570
-				AdviceId:         0,
571
-				ProjectId:        0,
572
-				DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
573
-				Cut:              fmt.Sprintf("%.2f", float64(item.Count)),
574
-				FeedetlSn:        item.FeedetlSn,
575
-				Price:            fmt.Sprintf("%.2f", float64(item.Price)),
576
-				MedListCodg:      item.XtHisAddtionConfig.Code,
577
-				Type:             3,
578
-			}
579
-			customs = append(customs, cus)
580
-		}
581
-	}
582
-	for _, item := range customs {
583
-		var advice_id int64 = 0
584
-		var project_id int64 = 0
585
-		var item_id int64 = 0
586
-
587
-		var types int64 = 0
588
-
589
-		if item.Type == 1 {
590
-			advice_id = item.AdviceId
591
-			project_id = 0
592
-			item_id = 0
593
-		} else if item.Type == 2 {
594
-			advice_id = 0
595
-			item_id = 0
596
-
597
-			project_id = item.ProjectId
598
-		} else if item.Type == 3 {
599
-			advice_id = 0
600
-			item_id = item.ItemId
601
-			project_id = 0
602
-		}
603
-		detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
604
-		cut, _ := strconv.ParseFloat(item.Cut, 32)
605
-		pric, _ := strconv.ParseFloat(item.Price, 32)
606
-		info := &models.HisOrderInfo{
607
-			OrderNumber:      order.Number,
608
-			UploadDate:       time.Now().Unix(),
609
-			AdviceId:         advice_id,
610
-			DetItemFeeSumamt: detItemFeeSumamt,
611
-			Cnt:              cut,
612
-			Pric:             pric,
613
-			PatientId:        id,
614
-			Status:           1,
615
-			Mtime:            time.Now().Unix(),
616
-			Ctime:            time.Now().Unix(),
617
-			UserOrgId:        adminUser.CurrentOrgId,
618
-			HisPatientId:     record.ID,
619
-			OrderId:          order.ID,
620
-			ProjectId:        project_id,
621
-			Type:             types,
622
-			ItemId:           item_id,
623
-		}
624
-		service.CreateOrderInfo(info)
625
-	}
626
-	err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
627
-	err = service.UpDateHospitalHisPrescriptionInfoNumber(adminUser.CurrentOrgId, chrg_bchno, start_time, end_time)
628
-	err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
707
+	order.MdtrtId = record.Number
708
+	order.MedfeeSumamt = order.MedfeeSumamt
709
+	//order.SetlTime =
710
+	err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
711
+	err = service.UpDateOrder(order)
629 712
 	if err == nil {
630 713
 		c.ServeSuccessJSON(map[string]interface{}{
631 714
 			"msg": "结算成功",
632 715
 		})
716
+	} else {
717
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
718
+		return
633 719
 	}
634
-
635 720
 }
636 721
 func (c *HisHospitalApiController) ZHRefund() {
637 722
 	order_id, _ := c.GetInt64("order_id")

+ 1 - 0
models/good_models.go Прегледај датотеку

@@ -83,6 +83,7 @@ type GoodInfo struct {
83 83
 	CancelStockInfo             []*CancelStockInfo   `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"cancel_stock_info"`
84 84
 	RegisterNumber              string               `gorm:"column:register_number" json:"register_number" form:"register_number"`
85 85
 	GoodSotckInfo               []*GoodSotckInfo     `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_stock_in"`
86
+	IsUser                      int64                `gorm:"column:is_user" json:"is_user" form:"is_user"`
86 87
 }
87 88
 
88 89
 func (GoodInfo) TableName() string {

+ 11 - 0
models/his_hospital_models.go Прегледај датотеку

@@ -82,3 +82,14 @@ type HisHospitalCheckRecord struct {
82 82
 func (HisHospitalCheckRecord) TableName() string {
83 83
 	return "his_hospital_check_record"
84 84
 }
85
+
86
+type NewCustom struct {
87
+	DetItemFeeSumamt float64
88
+	Cut              float64
89
+	FeedetlSn        string
90
+	Price            float64
91
+	MedListCodg      string
92
+	LmtUsedFlag      int64
93
+	HospApprFlag     int64
94
+	FeeOcurTime      string
95
+}

+ 2 - 0
models/his_models.go Прегледај датотеку

@@ -324,6 +324,7 @@ type Drug struct {
324 324
 	DrugDay                     string  `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
325 325
 	Total                       float64 `gorm:"column:total" json:"total" form:"total"`
326 326
 	PrescribingNumberUnit       string  `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
327
+	IsUser                      int64   `gorm:"column:is_user" json:"is_user" form:"is_user"`
327 328
 }
328 329
 
329 330
 func (Drug) TableName() string {
@@ -1022,6 +1023,7 @@ type HisOrderInfo struct {
1022 1023
 	ProjectId        int64   `gorm:"column:project_id" json:"project_id" form:"project_id"`
1023 1024
 	Type             int64   `gorm:"column:type" json:"type" form:"type"`
1024 1025
 	ItemId           int64   `gorm:"column:item_id" json:"item_id" form:"item_id"`
1026
+	SettleType       int64   `gorm:"column:settle_type" json:"settle_type" form:"settle_type"`
1025 1027
 
1026 1028
 	//HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
1027 1029
 	//HisDoctorAdviceInfo    HisDoctorAdviceInfo    `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`

+ 2 - 1
service/gobal_config_service.go Прегледај датотеку

@@ -240,11 +240,12 @@ func GetExportHisOrderList(user_org_id int64, start_time int64, end_time int64,
240 240
 		db = db.Where("his_order.settle_accounts_date<=?", end_time)
241 241
 	}
242 242
 
243
-	db = db.Where("his_order.status = 1 AND his_order.user_org_id = ? AND his_order.order_status > 1 AND p_type = ? ", user_org_id, p_type)
243
+	db = db.Where("his_order.status = 1 AND his_order.user_org_id = ? AND his_order.order_status = 2 AND p_type = ? ", user_org_id, p_type)
244 244
 
245 245
 	db = db.Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
246 246
 		Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
247 247
 		Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
248
+		Preload("HisHospitalCheckRecord", "status = 1 AND user_org_id = ? AND in_hospital_status = 1 AND out_hospital_status = 1 ", user_org_id).
248 249
 		Preload("HisPrescriptionInfo", func(db *gorm.DB) *gorm.DB {
249 250
 			return db.Where("status = 1 AND user_org_id = ?", user_org_id).Preload("XtHisDepartment", "status = 1")
250 251
 		})

+ 48 - 3
service/his_hospital_service.go Прегледај датотеку

@@ -3,6 +3,7 @@ package service
3 3
 import (
4 4
 	"XT_New/models"
5 5
 	"github.com/jinzhu/gorm"
6
+	"time"
6 7
 )
7 8
 
8 9
 type HospitalPatient struct {
@@ -70,9 +71,10 @@ func (HisHospitalOrder) TableName() string {
70 71
 	return "his_order"
71 72
 }
72 73
 
73
-func GetHisHospitalPatientList(org_id int64, record_date int64) (patients []*HospitalPatient, err error) {
74
+func GetHisHospitalPatientList(org_id int64, record_date int64, sch_type int64) (patients []*HospitalPatient, err error) {
74 75
 	db := readDb.Model(&HospitalPatient{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
75 76
 	db = db.Joins("join his_hospital_check_record as record ON record.patient_id = xt_patients.id AND record.status = 1 AND record.user_org_id = ? AND record.in_hospital_status = 1 AND record.record_date = ? ", org_id, record_date)
77
+	db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.status = 1 AND sch.user_org_id = ? AND sch.schedule_date = ? AND sch.schedule_type = ? ", org_id, record_date, sch_type)
76 78
 	db = db.Preload("HisHospitalCheckRecord", func(db *gorm.DB) *gorm.DB {
77 79
 		return db.Where("user_org_id = ? AND status = 1  AND in_hospital_status = 1 AND out_hospital_status = 0", org_id).Order("id desc")
78 80
 	})
@@ -321,7 +323,7 @@ func GetSettleHisHospitalPrescription(org_id int64, patient_id int64, his_patien
321 323
 func GetHisHospitalUnUploadPrescriptionDetailPatientList(org_id int64, record_date int64) (patients []*models.HisHospitalCheckRecord, err error) {
322 324
 	db := readDb.Model(&models.HisHospitalCheckRecord{})
323 325
 	db = db.Joins("inner join his_prescription pre On pre.patient_id = his_hospital_check_record.patient_id and pre.record_date = ? AND pre.p_type = 1 AND pre.user_org_id = ? AND pre.order_status <> 4 AND pre.order_status <> 2", record_date, org_id)
324
-	db = db.Where("his_hospital_check_record.user_org_id = ? AND his_hospital_check_record.status = 1 AND his_hospital_check_record.in_hospital_status = 1", org_id)
326
+	db = db.Where("his_hospital_check_record.user_org_id = ? AND his_hospital_check_record.status = 1 AND his_hospital_check_record.in_hospital_status = 1 AND his_hospital_check_record.out_hospital_status = 0", org_id)
325 327
 	err = db.Group("number").Find(&patients).Error
326 328
 	return
327 329
 }
@@ -329,7 +331,7 @@ func GetHisHospitalUnUploadPrescriptionDetailPatientList(org_id int64, record_da
329 331
 func GetHisHospitalUploadPrescriptionDetailPatientList(org_id int64, record_date int64) (patients []*models.HisHospitalCheckRecord, err error) {
330 332
 	db := readDb.Model(&models.HisHospitalCheckRecord{})
331 333
 	db = db.Joins("inner join his_prescription pre On pre.patient_id = his_hospital_check_record.patient_id and pre.record_date = ? AND pre.p_type = 1 AND pre.user_org_id = ? AND pre.order_status = 4", record_date, org_id)
332
-	db = db.Where("his_hospital_check_record.user_org_id = ? AND his_hospital_check_record.status = 1 AND his_hospital_check_record.in_hospital_status = 1", org_id)
334
+	db = db.Where("his_hospital_check_record.user_org_id = ? AND his_hospital_check_record.status = 1 AND his_hospital_check_record.in_hospital_status = 1  AND his_hospital_check_record.out_hospital_status = 0", org_id)
333 335
 	err = db.Group("number").Find(&patients).Error
334 336
 	return
335 337
 }
@@ -429,3 +431,46 @@ func GetSettleHisHospitalPrescriptionTwo(org_id int64, patient_id int64, number
429 431
 		Find(&prescription).Error
430 432
 	return
431 433
 }
434
+
435
+func GetZHHisPrescription(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
436
+	err = readDb.Model(&models.HisPrescription{}).
437
+		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
438
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
439
+		}).
440
+		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
441
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
442
+		}).
443
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
444
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status = 1")
445
+		}).
446
+		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND order_status <> 4 AND p_type = 1", org_id, record_date, patient_id).
447
+		Find(&prescription).Error
448
+	return
449
+}
450
+
451
+func GetZHMonthHisPrescription(org_id int64, patient_id int64, start_time int64, end_time int64) (prescription []*models.HisPrescription, err error) {
452
+	err = readDb.Model(&models.HisPrescription{}).
453
+		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
454
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
455
+		}).
456
+		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
457
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
458
+		}).
459
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
460
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status = 1")
461
+		}).
462
+		Where("user_org_id = ? AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND order_status <> 4 AND status = 1 AND p_type = 1 ", org_id, start_time, end_time, patient_id).
463
+		Find(&prescription).Error
464
+	return
465
+}
466
+
467
+func UpDatePrescriptionOrderStatus(user_org_id int64, ids []int64) (err error) {
468
+	err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"order_status": 4, "mtime": time.Now().Unix()}).Error
469
+	return
470
+}
471
+
472
+func GetHisOrderInfoByNumberFour(order_number string) (order []*models.HisOrderInfo, err error) {
473
+	db := readDb.Model(&models.HisOrderInfo{})
474
+	err = db.Where("order_number = ? AND status = 1", order_number).Find(&order).Error
475
+	return
476
+}