소스 검색

医保对接

csx 2 년 전
부모
커밋
ed017fdcca

+ 639 - 0
controllers/coordinate_controller.go 파일 보기

@@ -0,0 +1,639 @@
1
+package controllers
2
+
3
+import (
4
+	"XT_New/enums"
5
+	"XT_New/models"
6
+	"XT_New/service"
7
+	"XT_New/utils"
8
+	"encoding/json"
9
+	"fmt"
10
+	"github.com/astaxie/beego"
11
+	"io/ioutil"
12
+	"math/rand"
13
+	"strconv"
14
+	"strings"
15
+	"time"
16
+)
17
+
18
+type CoordinateController struct {
19
+	BaseAPIController
20
+}
21
+
22
+type ResultReg struct {
23
+	ResultCode string `json:"resultCode"`
24
+	ResultDesc string `json:"resultDesc"`
25
+	InfoSeq    string `json:"infoSeq"`
26
+}
27
+
28
+type ResultSettle struct {
29
+	ResultCode string `json:"resultCode"`
30
+	ResultDesc string `json:"resultDesc"`
31
+	DocId      string `json:"docId"`
32
+	Amount     string `json:"amount"`
33
+}
34
+
35
+type ResultCancelSettle struct {
36
+	ResultCode string `json:"resultCode"`
37
+	ResultDesc string `json:"resultDesc"`
38
+}
39
+
40
+type Settle struct {
41
+	PatientId string `json:"resultCode"`
42
+	DocId     string `json:"docId"`
43
+	InfoSeq   string `json:"infoSeq"`
44
+}
45
+
46
+type Refund struct {
47
+	PatientId string `json:"resultCode"`
48
+	DocId     string `json:"docId"`
49
+	InfoSeq   string `json:"infoSeq"`
50
+}
51
+
52
+type RefundDetail struct {
53
+	Msg    string `json:"msg"`
54
+	Result []struct {
55
+		ResultMsg string `json:"resultMsg"`
56
+		Code      string `json:"code"`
57
+		Records   int    `json:"records"`
58
+		TotalPage int    `json:"totalPage"`
59
+		List      []struct {
60
+			Zae01 int64 `json:"ZAE01"`
61
+		} `json:"list"`
62
+		RecordsTotal  int    `json:"recordsTotal"`
63
+		Pagenumber    int    `json:"pagenumber"`
64
+		Result        string `json:"result"`
65
+		Total         int    `json:"total"`
66
+		RecordsFtered int    `json:"recordsFtered"`
67
+		Page          int    `json:"page"`
68
+	} `json:"result"`
69
+	Code string `json:"code"`
70
+}
71
+
72
+func CoordinateRegistRouters() {
73
+	beego.Router("/coordinate/check", &CoordinateController{}, "get:SavePatientMessageInfo")
74
+	//坐标挂号
75
+	beego.Router("/coordinate/register", &CoordinateController{}, "get:Register")
76
+	//beego.Router("/coordinate/getWaitPayDetail", &CoordinateController{}, "get:GetWaitPayDetail")
77
+	//坐标记账
78
+	beego.Router("/coordinate/opKeepAccounts", &CoordinateController{}, "get:OpKeepAccounts")
79
+	//坐标撤销记账
80
+	beego.Router("/coordinate/opCancelKeepAccounts", &CoordinateController{}, "get:OpCancelKeepAccounts")
81
+	//坐标结算回调
82
+	beego.Router("/coordinate/settle", &CoordinateController{}, "post:Settle")
83
+	//坐标退费回调
84
+	beego.Router("/coordinate/refund", &CoordinateController{}, "post:Refund")
85
+
86
+}
87
+
88
+func (c *CoordinateController) Settle() {
89
+	//参数1 patient_id
90
+	//参数2 就诊号
91
+	//参数3 单据id
92
+	fmt.Println(c.Ctx.Request.Body)
93
+
94
+	body, _ := ioutil.ReadAll(c.Ctx.Request.Body)
95
+	fmt.Println(string(body))
96
+
97
+	var respJSON map[string]interface{}
98
+	if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
99
+		utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
100
+		return
101
+	}
102
+	patien_id := respJSON["patientId"].(string)
103
+	infoSeq := respJSON["infoSeq"].(string)
104
+	docId := respJSON["docId"].(string)
105
+	fmt.Println(patien_id)
106
+	fmt.Println(infoSeq)
107
+	fmt.Println(docId)
108
+
109
+	order, _ := service.GetHisOrderFour(patien_id, infoSeq, docId)
110
+	if order.ID == 0 {
111
+		json := make(map[string]interface{})
112
+		json["msg"] = "结算记录不存在,请检查参数是否正确"
113
+		json["code"] = "-1"
114
+		c.Data["json"] = json
115
+		c.ServeJSON()
116
+		return
117
+	}
118
+	order.OrderStatus = 2
119
+	service.UpDateOrder(order)
120
+	service.UpdataOrderStatusTwo(order.Number, order.UserOrgId)
121
+	json := make(map[string]interface{})
122
+	json["msg"] = "结算成功"
123
+	json["code"] = "0"
124
+	c.Data["json"] = json
125
+	c.ServeJSON()
126
+	return
127
+}
128
+func (c *CoordinateController) Refund() {
129
+	//参数1 patient_id
130
+	//参数2 就诊号
131
+	//参数3 单据id
132
+	body, _ := ioutil.ReadAll(c.Ctx.Request.Body)
133
+	var respJSON map[string]interface{}
134
+	if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
135
+		utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
136
+		return
137
+	}
138
+	patien_id := respJSON["patientId"].(string)
139
+	infoSeq := respJSON["infoSeq"].(string)
140
+	docId := respJSON["docId"].(string)
141
+	order, _ := service.GetHisOrderFour(patien_id, infoSeq, docId)
142
+	if order.ID == 0 {
143
+		json := make(map[string]interface{})
144
+		json["msg"] = "结算记录不存在,请检查参数是否正确"
145
+		json["code"] = "-1"
146
+		c.Data["json"] = json
147
+		c.ServeJSON()
148
+		return
149
+	}
150
+	service.UpdataOrderStatus(order.ID, order.Number, order.UserOrgId)
151
+	json := make(map[string]interface{})
152
+	json["msg"] = "退费成功"
153
+	json["code"] = "0"
154
+	c.Data["json"] = json
155
+	c.ServeJSON()
156
+	return
157
+}
158
+
159
+func (c *CoordinateController) SavePatientMessageInfo() {
160
+	result, request_log := service.SavePatientMessageInfo()
161
+	fmt.Println(result)
162
+	fmt.Println(request_log)
163
+
164
+}
165
+
166
+func (c *CoordinateController) Register() {
167
+	patient_id, _ := c.GetInt64("patient_id")
168
+	diagnosis_time := c.GetString("diagnosis_time")
169
+	record_date := c.GetString("record_date")
170
+	admin_user_id, _ := c.GetInt64("admin_user_id")
171
+	org_id, _ := c.GetInt64("org_id")
172
+	org_id = 4
173
+	patient, _ := service.GetPatientByID(org_id, patient_id)
174
+
175
+	timeLayout := "2006-01-02"
176
+	loc, _ := time.LoadLocation("Local")
177
+	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
178
+	if err != nil {
179
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
180
+		return
181
+	}
182
+	recordDateTime := theTime.Unix()
183
+	patientPrescription, _ := service.FindPatientPrescriptionInfoTwo(org_id, patient.ID, recordDateTime, 2)
184
+	if patientPrescription.ID == 0 {
185
+		patientPrescription, _ = service.FindLastPatientPrescriptionInfo(org_id, patient.ID, recordDateTime)
186
+	}
187
+	//department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
188
+	doctor_info, _ := service.GetAdminUserInfoByID(org_id, patientPrescription.DoctorId)
189
+
190
+	//admin_user_info, _ := service.GetAdminUserInfoByID(org_id, admin_user_id)
191
+
192
+	reg := models.Reg{
193
+		DeptId:      "0112",
194
+		PatientId:   patient.ZbPatientId,
195
+		PatientName: patient.Name,
196
+		DoctorId:    doctor_info.DoctorNumber,
197
+		RegDate:     strings.Split(diagnosis_time, " ")[0],
198
+		RegFee:      "8",
199
+		TreatFee:    "10",
200
+		OperatorId:  "测试",
201
+		IdCardNo:    patient.IdCardNo,
202
+	}
203
+
204
+	result, request_log := service.SaveReg(reg)
205
+	fmt.Println(result)
206
+	fmt.Println(request_log)
207
+
208
+	var res ResultReg
209
+	//if err := json.Unmarshal([]byte(result), &res); err != nil {
210
+	//	utils.ErrorLog("解析失败:%v", err)
211
+	//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
212
+	//	return
213
+	//}
214
+	res.ResultCode = "0"
215
+	res.InfoSeq = "122333"
216
+	if res.ResultCode == "0" {
217
+		timestamp := time.Now().Unix()
218
+		tempTime := time.Unix(timestamp, 0)
219
+		timeFormat := tempTime.Format("20060102150405")
220
+		chrgBchno := rand.Intn(100000) + 10000
221
+		ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(patient.ID, 10)
222
+		his := models.VMHisPatient{
223
+			Name:                   patient.Name,
224
+			Gender:                 patient.Gender,
225
+			Birthday:               patient.Birthday,
226
+			MedicalTreatmentType:   0,
227
+			IdType:                 1,
228
+			IdCardNo:               patient.IdCardNo,
229
+			BalanceAccountsType:    1,
230
+			MedicalInsuranceNumber: "",
231
+			RegisterType:           0,
232
+			RegisterCost:           0,
233
+			TreatmentCost:          0,
234
+			Status:                 1,
235
+			Ctime:                  time.Now().Unix(),
236
+			Mtime:                  time.Now().Unix(),
237
+			PsnNo:                  patient.ZbPatientId,
238
+			PsnCertType:            "",
239
+			Certno:                 patient.IdCardNo,
240
+			PsnName:                patient.Name,
241
+			Gend:                   "",
242
+			Naty:                   "",
243
+			Brdy:                   "",
244
+			Age:                    0,
245
+			Iinfo:                  "",
246
+			Idetinfo:               "",
247
+			PatientId:              patient.ID,
248
+			RecordDate:             theTime.Unix(),
249
+			UserOrgId:              org_id,
250
+			AdminUserId:            admin_user_id,
251
+			IsReturn:               1,
252
+			Doctor:                 patientPrescription.DoctorId,
253
+			Departments:            patientPrescription.Departments,
254
+			IptOtpNo:               ipt_otp_no,
255
+			Number:                 res.InfoSeq,
256
+			PhoneNumber:            patient.Phone,
257
+		}
258
+		service.UpdateHisPatientStatus(&his)
259
+		service.UpdateHisPrescriptionHisID(his.ID, patient.ID, recordDateTime, org_id)
260
+		c.ServeSuccessJSON(map[string]interface{}{
261
+			"his_info": his,
262
+		})
263
+	} else {
264
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
265
+		return
266
+	}
267
+}
268
+
269
+//func (c *CoordinateController) GetWaitPayDetail() {
270
+//	result, request_log := service.GetWaitPayDetail()
271
+//	fmt.Println(result)
272
+//	fmt.Println(request_log)
273
+//
274
+//}
275
+
276
+func (c *CoordinateController) OpKeepAccounts() {
277
+	id, _ := c.GetInt64("id")
278
+	record_time := c.GetString("record_time")
279
+	his_patient_id, _ := c.GetInt64("his_patient_id")
280
+	timeLayout := "2006-01-02"
281
+	loc, _ := time.LoadLocation("Local")
282
+	settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
283
+	fapiao_code := c.GetString("fapiao_code")
284
+	fapiao_number := c.GetString("fapiao_number")
285
+	diagnosis_id := c.GetString("diagnosis")
286
+	sick_type, _ := c.GetInt64("sick_type")
287
+	reg_type, _ := c.GetInt64("p_type")
288
+	org_id, _ := c.GetInt64("org_id")
289
+	org_id = 4
290
+	his, _ := service.GetHisPatientByIdThree(his_patient_id)
291
+
292
+	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
293
+	if err != nil {
294
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
295
+		return
296
+	}
297
+	recordDateTime := theTime.Unix()
298
+	//adminUser := c.GetAdminUserInfo()
299
+	var prescriptions []*models.HisPrescription
300
+	var start_time int64
301
+	var end_time int64
302
+
303
+	//ids_str := c.GetString("ids")
304
+	//ids_arr := strings.Split(ids_str, ",")
305
+
306
+	if settle_accounts_type == 1 { //日结
307
+		//fmt.Println(reg_type)
308
+		prescriptions, _ = service.GetUnSettleHisPrescriptionFive(org_id, id, recordDateTime, 2)
309
+
310
+	} else { //月结
311
+
312
+		start_time_str := c.GetString("start_time")
313
+		end_time_str := c.GetString("end_time")
314
+		timeLayout := "2006-01-02"
315
+		loc, _ := time.LoadLocation("Local")
316
+		theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
317
+		if err != nil {
318
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
319
+			return
320
+		}
321
+		recordStartTime := theStartTime.Unix()
322
+		start_time = recordStartTime
323
+		theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
324
+		if err != nil {
325
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
326
+			return
327
+		}
328
+		recordEndTime := theEndTime.Unix()
329
+		end_time = recordEndTime
330
+		prescriptions, _ = service.GetUnSettleMonthHisPrescription(org_id, id, recordStartTime, recordEndTime)
331
+	}
332
+
333
+	timestamp := time.Now().Unix()
334
+	tempTime := time.Unix(timestamp, 0)
335
+	timeFormat := tempTime.Format("20060102150405")
336
+	chrgBchno := rand.Intn(100000) + 10000
337
+	chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
338
+	strconv.FormatInt(his.PatientId, 10)
339
+
340
+	var ids []int64
341
+
342
+	for _, item := range prescriptions {
343
+		ids = append(ids, item.ID)
344
+	}
345
+	var total float64
346
+
347
+	for _, item := range prescriptions {
348
+		fmt.Println(item)
349
+		if item.Type == 1 { //药品
350
+			for _, subItem := range item.HisDoctorAdviceInfo {
351
+				total = total + (subItem.Price * subItem.PrescribingNumber)
352
+			}
353
+		}
354
+		if item.Type == 2 { //项目
355
+			for _, subItem := range item.HisPrescriptionProject {
356
+				cnt, _ := strconv.ParseFloat(subItem.Count, 64)
357
+				total = total + (subItem.Price * cnt)
358
+			}
359
+		}
360
+
361
+		for _, subItem := range item.HisAdditionalCharge {
362
+			total = total + (subItem.Price * float64(subItem.Count))
363
+		}
364
+	}
365
+
366
+	tm := time.Unix(time.Now().Unix(), 0)
367
+
368
+	var customs []*models.NewCustomTwo
369
+	for _, item := range prescriptions {
370
+		if item.Type == 1 { //药品
371
+			for _, subItem := range item.HisDoctorAdviceInfo {
372
+				cus := &models.NewCustomTwo{
373
+					AdviceId:         subItem.ID,
374
+					ProjectId:        0,
375
+					DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
376
+					Cut:              fmt.Sprintf("%.4f", subItem.PrescribingNumber),
377
+					FeedetlSn:        subItem.FeedetlSn,
378
+					Price:            fmt.Sprintf("%.2f", subItem.Price),
379
+					MedListCodg:      subItem.Drug.MedicalInsuranceNumber,
380
+					Type:             1,
381
+				}
382
+				customs = append(customs, cus)
383
+			}
384
+		}
385
+		if item.Type == 2 { //项目
386
+			for _, subItem := range item.HisPrescriptionProject {
387
+				if subItem.Type == 2 {
388
+					cnt, _ := strconv.ParseFloat(subItem.Count, 64)
389
+					cus := &models.NewCustomTwo{
390
+						AdviceId:         0,
391
+						ProjectId:        subItem.ID,
392
+						DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
393
+						Cut:              fmt.Sprintf("%.4f", cnt),
394
+						FeedetlSn:        subItem.FeedetlSn,
395
+						Price:            fmt.Sprintf("%.4f", float64(subItem.Price)),
396
+						MedListCodg:      subItem.HisProject.MedicalCode,
397
+						Type:             2,
398
+					}
399
+					customs = append(customs, cus)
400
+
401
+				} else {
402
+					cnt, _ := strconv.ParseFloat(subItem.Count, 64)
403
+					cus := &models.NewCustomTwo{
404
+						AdviceId:         0,
405
+						ProjectId:        subItem.ID,
406
+						DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
407
+						Cut:              fmt.Sprintf("%.4f", cnt),
408
+						FeedetlSn:        subItem.FeedetlSn,
409
+						Price:            fmt.Sprintf("%.4f", float64(subItem.Price)),
410
+						MedListCodg:      subItem.GoodInfo.MedicalInsuranceNumber,
411
+						Type:             3,
412
+					}
413
+					customs = append(customs, cus)
414
+
415
+				}
416
+
417
+			}
418
+		}
419
+		for _, item := range item.HisAdditionalCharge {
420
+			cus := &models.NewCustomTwo{
421
+				ItemId:           item.ID,
422
+				AdviceId:         0,
423
+				ProjectId:        0,
424
+				DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
425
+				Cut:              fmt.Sprintf("%.4f", float64(item.Count)),
426
+				FeedetlSn:        item.FeedetlSn,
427
+				Price:            fmt.Sprintf("%.4f", float64(item.Price)),
428
+				MedListCodg:      item.XtHisAddtionConfig.Code,
429
+				Type:             3,
430
+			}
431
+			customs = append(customs, cus)
432
+		}
433
+	}
434
+	result, request_log := service.OpKeepAccounts(his.Number, customs)
435
+
436
+	fmt.Println(result)
437
+	fmt.Println(request_log)
438
+
439
+	var res ResultSettle
440
+	res.ResultCode = "0"
441
+	res.DocId = "708275799870021632"
442
+	res.Amount = "1088.00"
443
+	//if err := json.Unmarshal([]byte(result), &res); err != nil {
444
+	//	utils.ErrorLog("解析失败:%v", err)
445
+	//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
446
+	//	return
447
+	//}
448
+	if res.ResultCode == "0" {
449
+		//allTotal := fmt.Sprintf("%.4f", total)
450
+		totals, _ := strconv.ParseFloat(res.Amount, 64)
451
+		order := &models.HisOrder{
452
+			PsnNo:              his.PsnNo,
453
+			UserOrgId:          org_id,
454
+			HisPatientId:       his.ID,
455
+			PatientId:          id,
456
+			SettleAccountsDate: recordDateTime,
457
+			Ctime:              time.Now().Unix(),
458
+			Mtime:              time.Now().Unix(),
459
+			Status:             1,
460
+			OrderStatus:        1,
461
+			MdtrtId:            his.Number,
462
+			Number:             chrg_bchno,
463
+			SetlId:             res.DocId,
464
+			MedfeeSumamt:       totals,
465
+			MedType:            strconv.Itoa(int(reg_type)),
466
+			SettleEndTime:      end_time,
467
+			SettleStartTime:    start_time,
468
+			SettleType:         settle_accounts_type,
469
+			FaPiaoCode:         fapiao_code,
470
+			FaPiaoNumber:       fapiao_number,
471
+			Diagnosis:          diagnosis_id,
472
+			PType:              2,
473
+			SetlTime:           tm.Format("2006-01-02 15:04:05"),
474
+		}
475
+		err = service.CreateOrder(order)
476
+		if err != nil {
477
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
478
+			return
479
+		}
480
+
481
+		for _, item := range customs {
482
+			var advice_id int64 = 0
483
+			var project_id int64 = 0
484
+			var item_id int64 = 0
485
+
486
+			var types int64 = 0
487
+
488
+			if item.Type == 1 {
489
+				advice_id = item.AdviceId
490
+				project_id = 0
491
+				item_id = 0
492
+			} else if item.Type == 2 {
493
+				advice_id = 0
494
+				item_id = 0
495
+
496
+				project_id = item.ProjectId
497
+			} else if item.Type == 3 {
498
+				advice_id = 0
499
+				item_id = item.ItemId
500
+				project_id = 0
501
+			}
502
+			detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
503
+			cut, _ := strconv.ParseFloat(item.Cut, 32)
504
+			pric, _ := strconv.ParseFloat(item.Price, 32)
505
+			info := &models.HisOrderInfo{
506
+				OrderNumber:      order.Number,
507
+				UploadDate:       time.Now().Unix(),
508
+				AdviceId:         advice_id,
509
+				DetItemFeeSumamt: detItemFeeSumamt,
510
+				Cnt:              cut,
511
+				Pric:             pric,
512
+				PatientId:        id,
513
+				Status:           1,
514
+				Mtime:            time.Now().Unix(),
515
+				Ctime:            time.Now().Unix(),
516
+				UserOrgId:        org_id,
517
+				HisPatientId:     his.ID,
518
+				OrderId:          order.ID,
519
+				ProjectId:        project_id,
520
+				Type:             types,
521
+				ItemId:           item_id,
522
+			}
523
+			service.CreateOrderInfo(info)
524
+		}
525
+		his.Diagnosis = diagnosis_id
526
+		his.SickType = sick_type
527
+		his.RegisterType = reg_type
528
+		his.MedicalTreatmentType = reg_type
529
+		service.UpdataHisPateint(&his)
530
+		err = service.UpDatePrescriptionNumber(org_id, ids, chrg_bchno)
531
+		err = service.UpDateHisPrescriptionInfoNumber(org_id, id, chrg_bchno, recordDateTime, his_patient_id)
532
+		err = service.UpdataOrderStatusThree(chrg_bchno, org_id)
533
+		if err == nil {
534
+			c.ServeSuccessJSON(map[string]interface{}{
535
+				"msg": "记账成功",
536
+			})
537
+		}
538
+	}
539
+
540
+}
541
+
542
+func (c *CoordinateController) OpCancelKeepAccounts() {
543
+	order_id, _ := c.GetInt64("order_id")
544
+	admin_user_id, _ := c.GetInt64("admin_user_id")
545
+	org_id, _ := c.GetInt64("org_id")
546
+	org_id = 4
547
+	order, _ := service.GetHisOrderByID(order_id)
548
+	if order.ID == 0 {
549
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
550
+		return
551
+	}
552
+
553
+	role, _ := service.GetAdminUserInfoByID(org_id, admin_user_id)
554
+	result, request_log := service.OpCancelKeepAccounts(order.SetlId, role.UserName, role.DoctorNumber)
555
+
556
+	var res RefundDetail
557
+	if err := json.Unmarshal([]byte(result), &res); err != nil {
558
+		utils.ErrorLog("解析失败:%v", err)
559
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
560
+		return
561
+	}
562
+	fmt.Println(result)
563
+	fmt.Println(request_log)
564
+	fmt.Println(res)
565
+	flag := 0
566
+	isSuccess := false
567
+	for _, item := range res.Result {
568
+		if item.Code == "200" {
569
+			flag = flag + 1
570
+		}
571
+	}
572
+	if len(res.Result) == flag {
573
+		isSuccess = true
574
+	}
575
+
576
+	if isSuccess {
577
+		err := service.UpdataOrderStatus(order_id, order.Number, org_id)
578
+		if err == nil {
579
+			c.ServeSuccessJSON(map[string]interface{}{
580
+				"msg": "撤销记账成功",
581
+			})
582
+		} else {
583
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
584
+			return
585
+		}
586
+	} else {
587
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
588
+		return
589
+	}
590
+}
591
+
592
+//func saveLog(result string, request string, infno string, desc string) {
593
+//
594
+//	org_id, _ := beego.AppConfig.Int64("org_id")
595
+//	miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
596
+//	dir := miConfig.OrgName + "日志"
597
+//	utils.Mkdir(dir)
598
+//	month := time.Unix(1557042972, 0).Format("1")
599
+//	year := time.Now().Format("2006")
600
+//	month = time.Now().Format("01")
601
+//	day := time.Now().Format("02")
602
+//	hour := time.Now().Format("15")
603
+//	min := time.Now().Format("04")
604
+//	sec := time.Now().Format("05")
605
+//
606
+//	result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
607
+//
608
+//	file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
609
+//	file_name := file + ".txt"
610
+//	file_path := miConfig.OrgName + "日志" + "/" + file_name
611
+//	exist, _ := utils.PathExists(file_path)
612
+//	if exist { //存在
613
+//		fmt.Println("存在")
614
+//		f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
615
+//		if err != nil {
616
+//			fmt.Println("read fail")
617
+//		}
618
+//		content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
619
+//		n, _ := f.Seek(0, 2)
620
+//		_, err = f.WriteAt([]byte(content), n)
621
+//
622
+//	} else { //不存在
623
+//		fmt.Println("文件不存在,创建文件")
624
+//		f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
625
+//		defer f.Close()
626
+//		if err != nil {
627
+//		} else {
628
+//			_, err = f.Write([]byte("记录日志"))
629
+//		}
630
+//	}
631
+//
632
+//}
633
+
634
+type Charset string
635
+
636
+const (
637
+	UTF8    = Charset("UTF-8")
638
+	GB18030 = Charset("GB18030")
639
+)

+ 643 - 105
controllers/his_api_controller.go 파일 보기

@@ -1,6 +1,5 @@
1 1
 package controllers
2 2
 
3
-import "C"
4 3
 import (
5 4
 	"XT_New/enums"
6 5
 	"XT_New/models"
@@ -93,6 +92,10 @@ func HisManagerApiRegistRouters() {
93 92
 	beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
94 93
 	beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
95 94
 
95
+	beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
96
+
97
+	beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
98
+
96 99
 }
97 100
 
98 101
 func (c *PublicApiController) GetBaiLinExportData() {
@@ -168,6 +171,7 @@ func (c *HisApiController) GetPrivateExpensesOrder() {
168 171
 	his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
169 172
 
170 173
 	orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
174
+	miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
171 175
 
172 176
 	//var config []*models.HisXtDiagnoseConfig
173 177
 
@@ -199,6 +203,45 @@ func (c *HisApiController) GetPrivateExpensesOrder() {
199 203
 		}
200 204
 	}
201 205
 
206
+	var bedCostTotal float64 = 0 //床位总费
207
+	//var bedCostSelfTotal float64 = 0     //床位自费
208
+	var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
209
+
210
+	var operationCostTotal float64 = 0 //手术费
211
+	//var operationCostSelfTotal float64 = 0     //手术费
212
+	var operationCostPartSelfTotal float64 = 0 //手术费
213
+
214
+	var otherCostTotal float64 = 0 //其他费用
215
+	//var otherCostSelfTotal float64 = 0     //其他费用
216
+	var otherCostPartSelfTotal float64 = 0 //其他费用
217
+
218
+	var materialCostTotal float64 = 0 //材料费
219
+	//var materialCostSelfTotal float64 = 0     //材料费
220
+	var materialCostPartSelfTotal float64 = 0 //材料费
221
+
222
+	var westernMedicineCostTotal float64 = 0 //西药费
223
+	//var westernMedicineCostSelfTotal float64 = 0     //西药费
224
+	var westernMedicineCostPartSelfTotal float64 = 0 //西药费
225
+
226
+	var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
227
+	//var chineseTraditionalMedicineCostSelfTotal float64 = 0     //中成药
228
+	var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
229
+
230
+	var checkCostTotal float64 = 0 //检查费
231
+	//var checkCostSelfTotal float64 = 0     //检查费
232
+	var checkCostPartSelfTotal float64 = 0 //检查费
233
+
234
+	var laboratoryCostTotal float64 = 0 //化验费
235
+	//var laboratoryCostSelfTotal float64 = 0     //化验费
236
+	var laboratoryCostPartSelfTotal float64 = 0 //化验费
237
+
238
+	var treatCostTotal float64 = 0 //治疗费用
239
+	//var treatCostSelfTotal float64 = 0     //治疗费用
240
+	var treatCostPartSelfTotal float64 = 0 //治疗费用
241
+
242
+	var zhenChaCostTotal float64 = 0 //其他费用
243
+	//var zhenChaCostPartSelfTotal float64 = 0 //其他费用
244
+
202 245
 	decimal.DivisionPrecision = 2
203 246
 
204 247
 	for _, item := range orderInfos {
@@ -209,7 +252,12 @@ func (c *HisApiController) GetPrivateExpensesOrder() {
209 252
 		if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
210 253
 			if item.HisPrescriptionProject.Type == 2 {
211 254
 				if c.GetAdminUserInfo().CurrentOrgId == 10215 {
255
+					fmt.Println("CostClassify")
256
+					fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
212 257
 					switch item.HisPrescriptionProject.VMHisProject.CostClassify {
258
+					case 0:
259
+						item.MedChrgitmType = "0"
260
+						break
213 261
 					case 1:
214 262
 						item.MedChrgitmType = "14"
215 263
 						break
@@ -218,11 +266,11 @@ func (c *HisApiController) GetPrivateExpensesOrder() {
218 266
 
219 267
 						break
220 268
 					case 3:
221
-						item.MedChrgitmType = "04"
269
+						item.MedChrgitmType = "03"
222 270
 
223 271
 						break
224 272
 					case 4:
225
-						item.MedChrgitmType = "14"
273
+						item.MedChrgitmType = "03"
226 274
 
227 275
 						break
228 276
 					case 5:
@@ -231,9 +279,11 @@ func (c *HisApiController) GetPrivateExpensesOrder() {
231 279
 						break
232 280
 					case 6:
233 281
 						item.MedChrgitmType = "14"
282
+
234 283
 						break
235 284
 					case 7:
236 285
 						item.MedChrgitmType = "14"
286
+
237 287
 						break
238 288
 					case 8:
239 289
 						item.MedChrgitmType = "03"
@@ -241,18 +291,136 @@ func (c *HisApiController) GetPrivateExpensesOrder() {
241 291
 					case 9:
242 292
 						item.MedChrgitmType = "14"
243 293
 						break
294
+					case 10:
295
+						item.MedChrgitmType = "14"
296
+						break
297
+					case 11:
298
+						item.MedChrgitmType = "06"
299
+						break
300
+					case 12:
301
+						item.MedChrgitmType = "12"
302
+						break
303
+					case 13:
304
+						item.MedChrgitmType = "01"
305
+						break
306
+					case 14:
307
+						item.MedChrgitmType = "04"
308
+						break
309
+					case 15:
310
+						item.MedChrgitmType = "14"
311
+						break
244 312
 
245 313
 					}
246 314
 
247
-				}
315
+				} else {
316
+					switch item.HisPrescriptionProject.VMHisProject.CostClassify {
317
+					case 1:
318
+						item.MedChrgitmType = "14"
319
+						break
320
+					case 2:
321
+						item.MedChrgitmType = "05"
322
+
323
+						break
324
+					case 3:
325
+						item.MedChrgitmType = "04"
248 326
 
327
+						break
328
+					case 4:
329
+						item.MedChrgitmType = "14"
330
+
331
+						break
332
+					case 5:
333
+						item.MedChrgitmType = "08"
334
+
335
+						break
336
+					case 6:
337
+						item.MedChrgitmType = "14"
338
+						break
339
+					case 7:
340
+						item.MedChrgitmType = "14"
341
+						break
342
+					case 8:
343
+						item.MedChrgitmType = "03"
344
+						break
345
+					case 9:
346
+						item.MedChrgitmType = "14"
347
+						break
348
+					}
349
+				}
249 350
 			} else if item.HisPrescriptionProject.Type == 3 {
250 351
 				item.MedChrgitmType = "08"
251 352
 			}
252 353
 		}
253 354
 	}
355
+
254 356
 	order.PsnCashPay = order.MedfeeSumamt
255 357
 
358
+	for _, item := range orderInfos {
359
+		if item.MedChrgitmType == "01" { //床位费
360
+			bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
361
+			//bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
362
+			//bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
363
+		}
364
+		if item.MedChrgitmType == "02" { //诊察费
365
+			zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
366
+			//zhenChaCostSelfTotal = zhenChaCostTotal
367
+		}
368
+
369
+		if item.MedChrgitmType == "03" { //检查费
370
+			checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
371
+			//checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
372
+			//checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
373
+		}
374
+
375
+		if item.MedChrgitmType == "02" { //检查费
376
+			checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
377
+			//checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
378
+			//checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
379
+		}
380
+
381
+		if item.MedChrgitmType == "04" { //化验费
382
+			laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
383
+			//laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
384
+			//laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
385
+		}
386
+
387
+		if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
388
+			treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
389
+			//treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
390
+			//treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
391
+		}
392
+
393
+		if item.MedChrgitmType == "06" { //手术费
394
+			operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
395
+			//operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
396
+			//operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
397
+		}
398
+
399
+		if item.MedChrgitmType == "08" { //材料费
400
+			materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
401
+			//materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
402
+			//materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
403
+		}
404
+
405
+		if item.MedChrgitmType == "09" { //西药费
406
+			westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
407
+			//westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
408
+			//westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
409
+		}
410
+
411
+		if item.MedChrgitmType == "11" { //中成费
412
+			chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
413
+			//chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
414
+			//chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
415
+		}
416
+
417
+		if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
418
+			otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
419
+			//otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
420
+			//otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
421
+		}
422
+	}
423
+
256 424
 	org, _ := service.GetOrgById(adminUser.CurrentOrgId)
257 425
 	printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
258 426
 	charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
@@ -260,16 +428,48 @@ func (c *HisApiController) GetPrivateExpensesOrder() {
260 428
 	patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
261 429
 
262 430
 	c.ServeSuccessJSON(map[string]interface{}{
263
-		"org_name":      org.OrgName,
264
-		"name":          patient.Name,
265
-		"order_infos":   orderInfos,
266
-		"number":        order.MdtrtId,
267
-		"date":          order.SettleAccountsDate,
268
-		"charge_admin":  charge_admin,
269
-		"printor_admin": printor_admin,
270
-		"info":          order,
271
-		"his_hospital":  his_hospital,
272
-		"his":           his,
431
+		"patient":                                     patient,
432
+		"order_infos":                                 orderInfos,
433
+		"diagnosis":                                   name,
434
+		"bedCostTotal":                                bedCostTotal,
435
+		"bedCostSelfTotal":                            bedCostTotal,
436
+		"bedCostPartSelfTotal":                        bedCostPartSelfTotal,
437
+		"operationCostTotal":                          operationCostTotal,
438
+		"operationCostSelfTotal":                      operationCostTotal,
439
+		"operationCostPartSelfTotal":                  operationCostPartSelfTotal,
440
+		"otherCostTotal":                              otherCostTotal,
441
+		"otherCostSelfTotal":                          otherCostTotal,
442
+		"otherCostPartSelfTotal":                      otherCostPartSelfTotal,
443
+		"materialCostTotal":                           materialCostTotal,
444
+		"materialCostSelfTotal":                       materialCostTotal,
445
+		"materialCostPartSelfTotal":                   materialCostPartSelfTotal,
446
+		"westernMedicineCostTotal":                    westernMedicineCostTotal,
447
+		"westernMedicineCostSelfTotal":                westernMedicineCostTotal,
448
+		"westernMedicineCostPartSelfTotal":            westernMedicineCostPartSelfTotal,
449
+		"chineseTraditionalMedicineCostTotal":         chineseTraditionalMedicineCostTotal,
450
+		"chineseTraditionalMedicineCostSelfTotal":     chineseTraditionalMedicineCostTotal,
451
+		"chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
452
+		"checkCostTotal":                              checkCostTotal,
453
+		"checkCostSelfTotal":                          checkCostTotal,
454
+		"zhenChaCostTotal":                            zhenChaCostTotal,
455
+		"zhenChaCostSelfTotal":                        zhenChaCostTotal,
456
+		"checkCostPartSelfTotal":                      checkCostPartSelfTotal,
457
+		"laboratoryCostTotal":                         laboratoryCostTotal,
458
+		"laboratoryCostSelfTotal":                     laboratoryCostTotal,
459
+		"laboratoryCostPartSelfTotal":                 laboratoryCostPartSelfTotal,
460
+		"treatCostTotal":                              treatCostTotal,
461
+		"treatCostSelfTotal":                          treatCostTotal,
462
+		"treatCostPartSelfTotal":                      treatCostPartSelfTotal,
463
+		"charge_admin":                                charge_admin,
464
+		"printor_admin":                               printor_admin,
465
+		"org_name":                                    org.OrgName,
466
+		"org_code":                                    miConfig.Code,
467
+		"name":                                        patient.Name,
468
+		"number":                                      order.MdtrtId,
469
+		"date":                                        order.SettleAccountsDate,
470
+		"info":                                        order,
471
+		"his_hospital":                                his_hospital,
472
+		"his":                                         his,
273 473
 	})
274 474
 
275 475
 }
@@ -4390,6 +4590,8 @@ func (c *HisApiController) GetUploadInfo() {
4390 4590
 			reg_type = 11
4391 4591
 		}
4392 4592
 
4593
+		tm := time.Unix(time.Now().Unix(), 0)
4594
+
4393 4595
 		allTotal := fmt.Sprintf("%.4f", total)
4394 4596
 		totals, _ := strconv.ParseFloat(allTotal, 64)
4395 4597
 		order := &models.HisOrder{
@@ -4421,7 +4623,7 @@ func (c *HisApiController) GetUploadInfo() {
4421 4623
 			FaPiaoNumber:          fapiao_number,
4422 4624
 			Diagnosis:             diagnosis_id,
4423 4625
 			PType:                 2,
4424
-			//SetlTime:			t
4626
+			SetlTime:              tm.Format("2006-01-02 15:04:05"),
4425 4627
 		}
4426 4628
 		err = service.CreateOrder(order)
4427 4629
 		if err != nil {
@@ -4769,9 +4971,29 @@ func (this *HisApiController) GetHisDayPrescription() {
4769 4971
 
4770 4972
 	}
4771 4973
 
4974
+	var settle_total float64
4975
+	for _, item := range dayHisPrescription {
4976
+		if len(item.HisPrescriptionProject) > 0 {
4977
+			for _, subItem := range item.HisPrescriptionProject {
4978
+				count, _ := strconv.ParseFloat(subItem.Count, 64)
4979
+				total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
4980
+				settle_total = settle_total + total
4981
+			}
4982
+		}
4983
+		if len(item.HisDoctorAdviceInfo) > 0 {
4984
+			for _, subItem := range item.HisDoctorAdviceInfo {
4985
+				total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
4986
+				settle_total = settle_total + total
4987
+			}
4988
+		}
4989
+
4990
+	}
4991
+	settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
4992
+
4772 4993
 	if err == nil {
4773 4994
 		this.ServeSuccessJSON(map[string]interface{}{
4774 4995
 			"day_prescription": dayHisPrescription,
4996
+			"settle_total":     settle_total,
4775 4997
 		})
4776 4998
 		return
4777 4999
 	} else {
@@ -4901,6 +5123,7 @@ func (c *HisApiController) GetHisChargePatientInfo() {
4901 5123
 	xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
4902 5124
 
4903 5125
 	var prescriptions []*models.HisPrescription
5126
+	//var unChargeMonthPrescriptions []*models.HisPrescription
4904 5127
 
4905 5128
 	order, _ := service.GetHisOrderByID(order_id)
4906 5129
 
@@ -4908,15 +5131,9 @@ func (c *HisApiController) GetHisChargePatientInfo() {
4908 5131
 		prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
4909 5132
 	} else if order_status == 2 {
4910 5133
 		prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
5134
+		//unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
4911 5135
 	}
4912 5136
 
4913
-	//var monthPrescriptions []*models.HisPrescription
4914
-	//if order_status == 1 || order_status == 0 {
4915
-	//	monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
4916
-	//} else if order_status == 2 {
4917
-	//	monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
4918
-	//}
4919
-
4920 5137
 	case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
4921 5138
 	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
4922 5139
 
@@ -4933,13 +5150,11 @@ func (c *HisApiController) GetHisChargePatientInfo() {
4933 5150
 		"case_history": case_history,
4934 5151
 		"info":         patientPrescriptionInfo,
4935 5152
 		"last_info":    lastPatientPrescriptionInfo,
4936
-		//"month_prescriptions": monthPrescriptions,
4937
-		"order":      order,
4938
-		"doctors":    doctors,
4939
-		"department": department,
5153
+		"order":        order,
5154
+		"doctors":      doctors,
5155
+		"department":   department,
4940 5156
 	})
4941 5157
 	return
4942
-
4943 5158
 }
4944 5159
 
4945 5160
 func (c *HisApiController) GetAllOrderDetail() {
@@ -4981,13 +5196,121 @@ func (c *HisApiController) GetAllOrderDetailCollect() {
4981 5196
 	//his, _ := service.Get(order.UserOrgId, order.MdtrtId)
4982 5197
 	record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
4983 5198
 
5199
+	var bedCostTotal float64 = 0 //床位总费
5200
+	//var bedCostSelfTotal float64 = 0     //床位自费
5201
+
5202
+	var operationCostTotal float64 = 0 //手术费
5203
+	//var operationCostSelfTotal float64 = 0     //手术费
5204
+
5205
+	var otherCostTotal float64 = 0 //其他费用
5206
+	//var otherCostSelfTotal float64 = 0     //其他费用
5207
+
5208
+	var materialCostTotal float64 = 0 //材料费
5209
+	//var materialCostSelfTotal float64 = 0     //材料费
5210
+
5211
+	var westernMedicineCostTotal float64 = 0 //西药费
5212
+	//var westernMedicineCostSelfTotal float64 = 0     //西药费
5213
+
5214
+	var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
5215
+	//var chineseTraditionalMedicineCostSelfTotal float64 = 0     //中成药
5216
+
5217
+	var checkCostTotal float64 = 0 //检查费
5218
+	//var checkCostSelfTotal float64 = 0     //检查费
5219
+
5220
+	var laboratoryCostTotal float64 = 0 //化验费
5221
+	//var laboratoryCostSelfTotal float64 = 0     //化验费
5222
+
5223
+	var treatCostTotal float64 = 0 //治疗费用
5224
+	//var treatCostSelfTotal float64 = 0     //治疗费用
5225
+
5226
+	var zhenChaCostTotal float64 = 0 //其他费用
5227
+	//var zhenChaCostPartSelfTotal float64 = 0 //其他费用
5228
+
5229
+	decimal.DivisionPrecision = 2
5230
+
4984 5231
 	if his.BalanceAccountsType != 2 {
5232
+		for _, item := range order_info {
5233
+			if item.MedChrgitmType == "01" { //床位费
5234
+				bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5235
+				//bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5236
+				//bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5237
+			}
5238
+			if item.MedChrgitmType == "02" { //诊察费
5239
+				zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5240
+				//zhenChaCostSelfTotal = zhenChaCostTotal
5241
+			}
5242
+
5243
+			if item.MedChrgitmType == "03" { //检查费
5244
+				checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5245
+				//checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5246
+				//checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5247
+			}
5248
+
5249
+			if item.MedChrgitmType == "02" { //检查费
5250
+				checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5251
+				//checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5252
+				//checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5253
+			}
5254
+
5255
+			if item.MedChrgitmType == "04" { //化验费
5256
+				laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5257
+				//laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5258
+				//laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5259
+			}
5260
+
5261
+			if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
5262
+				treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5263
+				//treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5264
+				//treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5265
+			}
5266
+
5267
+			if item.MedChrgitmType == "06" { //手术费
5268
+				operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5269
+				//operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5270
+				//operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5271
+			}
5272
+
5273
+			if item.MedChrgitmType == "08" { //材料费
5274
+				materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5275
+				//materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5276
+				//materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5277
+			}
5278
+
5279
+			if item.MedChrgitmType == "09" { //西药费
5280
+				westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5281
+				//westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5282
+				//westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5283
+			}
5284
+
5285
+			if item.MedChrgitmType == "11" { //中成费
5286
+				chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5287
+				//chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5288
+				//chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5289
+			}
5290
+
5291
+			if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
5292
+				otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5293
+				//otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5294
+				//otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5295
+			}
5296
+		}
5297
+
4985 5298
 		c.ServeSuccessJSON(map[string]interface{}{
4986
-			"order":        order,
4987
-			"order_info":   order_info,
4988
-			"patient":      patient,
4989
-			"admin_info":   adminInfo,
4990
-			"his_hospital": record,
5299
+			"order":                               order,
5300
+			"order_info":                          order_info,
5301
+			"patient":                             patient,
5302
+			"admin_info":                          adminInfo,
5303
+			"his_hospital":                        record,
5304
+			"bedCostTotal":                        bedCostTotal,
5305
+			"operationCostTotal":                  operationCostTotal,
5306
+			"otherCostTotal":                      otherCostTotal,
5307
+			"materialCostTotal":                   materialCostTotal,
5308
+			"westernMedicineCostTotal":            westernMedicineCostTotal,
5309
+			"chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
5310
+			"checkCostTotal":                      checkCostTotal,
5311
+			"zhenChaCostTotal":                    zhenChaCostTotal,
5312
+			"laboratoryCostTotal":                 laboratoryCostTotal,
5313
+			"treatCostTotal":                      treatCostTotal,
4991 5314
 		})
4992 5315
 	} else {
4993 5316
 
@@ -4999,58 +5322,128 @@ func (c *HisApiController) GetAllOrderDetailCollect() {
4999 5322
 			}
5000 5323
 			if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
5001 5324
 				if item.HisPrescriptionProject.Type == 2 {
5002
-					switch item.HisPrescriptionProject.VMHisProject.CostClassify {
5003
-
5004
-					case 1:
5005
-						item.MedChrgitmType = "14"
5006
-						break
5007
-					case 2:
5008
-						item.MedChrgitmType = "05"
5009
-
5010
-						break
5011
-					case 3:
5012
-						item.MedChrgitmType = "04"
5013
-
5014
-						break
5015
-					case 4:
5016
-						item.MedChrgitmType = "14"
5017
-
5018
-						break
5019
-					case 5:
5020
-						item.MedChrgitmType = "08"
5021
-
5022
-						break
5023
-					case 6:
5024
-						item.MedChrgitmType = "14"
5325
+					if c.GetAdminUserInfo().CurrentOrgId == 10215 {
5326
+						switch item.HisPrescriptionProject.VMHisProject.CostClassify {
5327
+						case 0:
5328
+							item.MedChrgitmType = "0"
5329
+							break
5330
+						case 1:
5331
+							item.MedChrgitmType = "14"
5332
+							break
5333
+						case 2:
5334
+							item.MedChrgitmType = "05"
5335
+
5336
+							break
5337
+						case 3:
5338
+							item.MedChrgitmType = "03"
5339
+
5340
+							break
5341
+						case 4:
5342
+							item.MedChrgitmType = "03"
5343
+
5344
+							break
5345
+						case 5:
5346
+							item.MedChrgitmType = "08"
5347
+
5348
+							break
5349
+						case 6:
5350
+							item.MedChrgitmType = "14"
5351
+
5352
+							break
5353
+						case 7:
5354
+							item.MedChrgitmType = "14"
5355
+
5356
+							break
5357
+						case 8:
5358
+							item.MedChrgitmType = "03"
5359
+							break
5360
+						case 9:
5361
+							item.MedChrgitmType = "14"
5362
+							break
5363
+						case 10:
5364
+							item.MedChrgitmType = "14"
5365
+							break
5366
+						case 11:
5367
+							item.MedChrgitmType = "06"
5368
+							break
5369
+						case 12:
5370
+							item.MedChrgitmType = "12"
5371
+							break
5372
+						case 13:
5373
+							item.MedChrgitmType = "01"
5374
+							break
5375
+						case 14:
5376
+							item.MedChrgitmType = "04"
5377
+							break
5378
+						case 15:
5379
+							item.MedChrgitmType = "14"
5380
+							break
5025 5381
 
5026
-						break
5027
-					case 7:
5028
-						item.MedChrgitmType = "14"
5382
+						}
5029 5383
 
5030
-						break
5031
-					case 8:
5032
-						item.MedChrgitmType = "03"
5033
-						break
5034
-					case 9:
5035
-						item.MedChrgitmType = "14"
5036
-						break
5384
+					} else {
5385
+						switch item.HisPrescriptionProject.VMHisProject.CostClassify {
5386
+
5387
+						case 1:
5388
+							item.MedChrgitmType = "14"
5389
+							break
5390
+						case 2:
5391
+							item.MedChrgitmType = "05"
5392
+
5393
+							break
5394
+						case 3:
5395
+							item.MedChrgitmType = "04"
5396
+
5397
+							break
5398
+						case 4:
5399
+							item.MedChrgitmType = "14"
5400
+
5401
+							break
5402
+						case 5:
5403
+							item.MedChrgitmType = "08"
5404
+
5405
+							break
5406
+						case 6:
5407
+							item.MedChrgitmType = "14"
5408
+
5409
+							break
5410
+						case 7:
5411
+							item.MedChrgitmType = "14"
5412
+
5413
+							break
5414
+						case 8:
5415
+							item.MedChrgitmType = "03"
5416
+							break
5417
+						case 9:
5418
+							item.MedChrgitmType = "14"
5419
+							break
5420
+						}
5037 5421
 					}
5038 5422
 				} else if item.HisPrescriptionProject.Type == 3 {
5039 5423
 					item.MedChrgitmType = "08"
5040 5424
 				}
5041 5425
 			}
5042 5426
 		}
5427
+
5043 5428
 		c.ServeSuccessJSON(map[string]interface{}{
5044
-			"order":        order,
5045
-			"order_info":   order_info,
5046
-			"patient":      patient,
5047
-			"admin_info":   adminInfo,
5048
-			"his_hospital": record,
5429
+			"order":                               order,
5430
+			"order_info":                          order_info,
5431
+			"patient":                             patient,
5432
+			"admin_info":                          adminInfo,
5433
+			"his_hospital":                        record,
5434
+			"bedCostTotal":                        bedCostTotal,
5435
+			"operationCostTotal":                  operationCostTotal,
5436
+			"otherCostTotal":                      otherCostTotal,
5437
+			"materialCostTotal":                   materialCostTotal,
5438
+			"westernMedicineCostTotal":            westernMedicineCostTotal,
5439
+			"chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
5440
+			"checkCostTotal":                      checkCostTotal,
5441
+			"zhenChaCostTotal":                    zhenChaCostTotal,
5442
+			"laboratoryCostTotal":                 laboratoryCostTotal,
5443
+			"treatCostTotal":                      treatCostTotal,
5049 5444
 		})
5050 5445
 
5051 5446
 	}
5052
-
5053
-	return
5054 5447
 }
5055 5448
 
5056 5449
 func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
@@ -5165,6 +5558,7 @@ func (c *HisApiController) GetFaPiaoData() {
5165 5558
 	his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
5166 5559
 
5167 5560
 	his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
5561
+	miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
5168 5562
 
5169 5563
 	//prescriptions, _ := service.GetHisPrescriptionThree(adminUser.CurrentOrgId, patient_id, order.Number)
5170 5564
 
@@ -5211,50 +5605,124 @@ func (c *HisApiController) GetFaPiaoData() {
5211 5605
 	decimal.DivisionPrecision = 2
5212 5606
 	orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
5213 5607
 
5214
-	if his.BalanceAccountsType == 2 {
5608
+	var balanceAccountsType int64
5609
+	if his.ID > 0 {
5610
+
5611
+		balanceAccountsType = his.BalanceAccountsType
5612
+	} else {
5613
+
5614
+		balanceAccountsType = his_hospital_record.BalanceAccountsType
5615
+	}
5616
+
5617
+	if balanceAccountsType == 2 {
5215 5618
 		//orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
5216 5619
 		for _, item := range orderInfos_two {
5217 5620
 			item.FulamtOwnpayAmt = item.DetItemFeeSumamt
5218 5621
 			if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
5219 5622
 				item.MedChrgitmType = "09"
5220 5623
 			}
5624
+
5221 5625
 			if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
5222 5626
 				if item.HisPrescriptionProject.Type == 2 {
5223
-					switch item.HisPrescriptionProject.VMHisProject.CostClassify {
5224
-
5225
-					case 1:
5226
-						item.MedChrgitmType = "14"
5227
-						break
5228
-					case 2:
5229
-						item.MedChrgitmType = "05"
5230
-
5231
-						break
5232
-					case 3:
5233
-						item.MedChrgitmType = "04"
5627
+					if c.GetAdminUserInfo().CurrentOrgId == 10215 {
5628
+						fmt.Println("CostClassify")
5629
+						fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
5630
+						switch item.HisPrescriptionProject.VMHisProject.CostClassify {
5631
+						case 0:
5632
+							item.MedChrgitmType = "0"
5633
+							break
5634
+						case 1:
5635
+							item.MedChrgitmType = "14"
5636
+							break
5637
+						case 2:
5638
+							item.MedChrgitmType = "05"
5639
+
5640
+							break
5641
+						case 3:
5642
+							item.MedChrgitmType = "03"
5643
+
5644
+							break
5645
+						case 4:
5646
+							item.MedChrgitmType = "03"
5647
+
5648
+							break
5649
+						case 5:
5650
+							item.MedChrgitmType = "08"
5651
+
5652
+							break
5653
+						case 6:
5654
+							item.MedChrgitmType = "14"
5655
+
5656
+							break
5657
+						case 7:
5658
+							item.MedChrgitmType = "14"
5659
+
5660
+							break
5661
+						case 8:
5662
+							item.MedChrgitmType = "03"
5663
+							break
5664
+						case 9:
5665
+							item.MedChrgitmType = "14"
5666
+							break
5667
+						case 10:
5668
+							item.MedChrgitmType = "14"
5669
+							break
5670
+						case 11:
5671
+							item.MedChrgitmType = "06"
5672
+							break
5673
+						case 12:
5674
+							item.MedChrgitmType = "12"
5675
+							break
5676
+						case 13:
5677
+							item.MedChrgitmType = "01"
5678
+							break
5679
+						case 14:
5680
+							item.MedChrgitmType = "04"
5681
+							break
5682
+						case 15:
5683
+							item.MedChrgitmType = "02"
5684
+							break
5234 5685
 
5235
-						break
5236
-					case 4:
5237
-						item.MedChrgitmType = "14"
5238
-
5239
-						break
5240
-					case 5:
5241
-						item.MedChrgitmType = "08"
5242
-
5243
-						break
5244
-					case 6:
5245
-						item.MedChrgitmType = "14"
5686
+						}
5246 5687
 
5247
-						break
5248
-					case 7:
5249
-						item.MedChrgitmType = "14"
5688
+					} else {
5689
+						switch item.HisPrescriptionProject.VMHisProject.CostClassify {
5690
+
5691
+						case 1:
5692
+							item.MedChrgitmType = "14"
5693
+							break
5694
+						case 2:
5695
+							item.MedChrgitmType = "05"
5696
+
5697
+							break
5698
+						case 3:
5699
+							item.MedChrgitmType = "03"
5700
+
5701
+							break
5702
+						case 4:
5703
+							item.MedChrgitmType = "03"
5704
+
5705
+							break
5706
+						case 5:
5707
+							item.MedChrgitmType = "08"
5708
+
5709
+							break
5710
+						case 6:
5711
+							item.MedChrgitmType = "14"
5712
+
5713
+							break
5714
+						case 7:
5715
+							item.MedChrgitmType = "14"
5716
+
5717
+							break
5718
+						case 8:
5719
+							item.MedChrgitmType = "03"
5720
+							break
5721
+						case 9:
5722
+							item.MedChrgitmType = "14"
5723
+							break
5250 5724
 
5251
-						break
5252
-					case 8:
5253
-						item.MedChrgitmType = "03"
5254
-						break
5255
-					case 9:
5256
-						item.MedChrgitmType = "14"
5257
-						break
5725
+						}
5258 5726
 
5259 5727
 					}
5260 5728
 
@@ -5265,11 +5733,17 @@ func (c *HisApiController) GetFaPiaoData() {
5265 5733
 		}
5266 5734
 
5267 5735
 		for _, item := range orderInfos_two {
5736
+			fmt.Println(item.MedChrgitmType)
5268 5737
 			if item.MedChrgitmType == "01" { //床位费
5269 5738
 				bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5270 5739
 				bedCostSelfTotal = bedCostTotal
5271 5740
 			}
5272 5741
 
5742
+			if item.MedChrgitmType == "02" { //诊察费
5743
+				zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5744
+				zhenChaCostSelfTotal = zhenChaCostTotal
5745
+			}
5746
+
5273 5747
 			if item.MedChrgitmType == "03" { //检查费
5274 5748
 				checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5275 5749
 				checkCostSelfTotal = checkCostTotal
@@ -5426,6 +5900,7 @@ func (c *HisApiController) GetFaPiaoData() {
5426 5900
 		"zhenChaCostSelfTotal":        zhenChaCostSelfTotal,
5427 5901
 		"zhenChaCostPartSelfTotal":    zhenChaCostPartSelfTotal,
5428 5902
 		"his_hospital_record":         his_hospital_record,
5903
+		"org_name":                    miConfig.OrgName,
5429 5904
 	})
5430 5905
 
5431 5906
 }
@@ -6591,6 +7066,7 @@ func (c *HisApiController) GetHisMonthChargePatientInfo() {
6591 7066
 		}
6592 7067
 
6593 7068
 	}
7069
+	settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
6594 7070
 
6595 7071
 	case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
6596 7072
 	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
@@ -6650,6 +7126,25 @@ func (c *HisApiController) GetHisMonthPatientInfo() {
6650 7126
 	count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
6651 7127
 
6652 7128
 	monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
7129
+	var settle_total float64
7130
+	for _, item := range monthPrescriptions {
7131
+		if len(item.HisPrescriptionProject) > 0 {
7132
+			for _, subItem := range item.HisPrescriptionProject {
7133
+				count, _ := strconv.ParseFloat(subItem.Count, 64)
7134
+				total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
7135
+				settle_total = settle_total + total
7136
+			}
7137
+		}
7138
+		if len(item.HisDoctorAdviceInfo) > 0 {
7139
+			for _, subItem := range item.HisDoctorAdviceInfo {
7140
+				total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
7141
+				settle_total = settle_total + total
7142
+			}
7143
+		}
7144
+
7145
+	}
7146
+	settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
7147
+
6653 7148
 	case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
6654 7149
 	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
6655 7150
 	lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
@@ -6672,6 +7167,7 @@ func (c *HisApiController) GetHisMonthPatientInfo() {
6672 7167
 		"count":               count,
6673 7168
 		"drugStockConfig":     drugStockConfig,
6674 7169
 		"last_info":           lastPatientPrescriptionInfo,
7170
+		"settle_total":        settle_total,
6675 7171
 	})
6676 7172
 	return
6677 7173
 
@@ -6942,3 +7438,45 @@ func (c *HisApiController) GetHisDoctorAdviceInfo() {
6942 7438
 	})
6943 7439
 	return
6944 7440
 }
7441
+
7442
+func (c *HisApiController) GetHisMonthChargePatientList() {
7443
+	record_date := c.GetString("record_date")
7444
+	start_time := c.GetString("start_time")
7445
+	end_time := c.GetString("end_time")
7446
+	timeLayout := "2006-01-02"
7447
+	loc, _ := time.LoadLocation("Local")
7448
+	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
7449
+	if err != nil {
7450
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
7451
+		return
7452
+	}
7453
+
7454
+	if err != nil {
7455
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
7456
+		return
7457
+	}
7458
+	recordDateTime := theTime.Unix()
7459
+	startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
7460
+	if err != nil {
7461
+
7462
+	}
7463
+	startRecordDateTime := startTime.Unix()
7464
+	endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
7465
+	if err != nil {
7466
+
7467
+	}
7468
+	endRecordDateTime := endTime.Unix()
7469
+	adminInfo := c.GetAdminUserInfo()
7470
+	var tempMonthChargePatients []*service.MonthChargePatients
7471
+	tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
7472
+	for _, item := range tempPatients {
7473
+		//过滤没有处方的
7474
+		if len(item.HisPrescription) == 0 {
7475
+			tempMonthChargePatients = append(tempMonthChargePatients, item)
7476
+		}
7477
+	}
7478
+	c.ServeSuccessJSON(map[string]interface{}{
7479
+		"list": tempMonthChargePatients,
7480
+	})
7481
+
7482
+}

+ 90 - 0
controllers/his_charge_api_controller.go 파일 보기

@@ -17,6 +17,9 @@ func HisChargeApiRegistRouters() {
17 17
 	beego.Router("/api/his/chargestatistics/detail", &HisChargeApiController{}, "get:GetChargeStatisticsDetail")
18 18
 	beego.Router("/api/his/chargestatistics/settle", &HisChargeApiController{}, "get:GetChargeStatisticsSettle")
19 19
 
20
+	beego.Router("/api/his/patient", &HisChargeApiController{}, "get:GetAllPatient")
21
+	//beego.Router("/api/his/chargestatistics/settle", &HisChargeApiController{}, "get:GetChargeStatisticsSettle")
22
+
20 23
 	beego.Router("/api/his/inspectionlist/get", &HisChargeApiController{}, "get:GetHisInspectionList")
21 24
 	beego.Router("/api/his/inspectioninfo/get", &HisChargeApiController{}, "get:GetHisInspectionInfo")
22 25
 
@@ -316,3 +319,90 @@ func (c *HisChargeApiController) GetHisYidiClearRecord() {
316 319
 		return
317 320
 	}
318 321
 }
322
+
323
+func (c *HisChargeApiController) GetAllPatient() {
324
+	patients, err := service.GetAllPatientTwo(c.GetAdminUserInfo().CurrentOrgId)
325
+	if err == nil {
326
+		c.ServeSuccessJSON(map[string]interface{}{
327
+			"list": patients,
328
+		})
329
+		return
330
+	} else {
331
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
332
+		return
333
+	}
334
+}
335
+
336
+func (c *HisChargeApiController) GetStatisticsDetail() {
337
+	start_time := c.GetString("start_time")
338
+	end_time := c.GetString("end_time")
339
+	keyword := c.GetString("keyword")
340
+	item_type, _ := c.GetInt64("type")
341
+	p_type, _ := c.GetInt64("p_type")
342
+	patinet_id, _ := c.GetInt64("patinet_id")
343
+
344
+	adminUser := c.GetAdminUserInfo()
345
+
346
+	timeLayout := "2006-01-02"
347
+	loc, _ := time.LoadLocation("Local")
348
+	startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
349
+	if err != nil {
350
+
351
+	}
352
+	startRecordDateTime := startTime.Unix()
353
+
354
+	endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
355
+	if err != nil {
356
+
357
+	}
358
+	endRecordDateTime := endTime.Unix()
359
+
360
+	chargePatient, err := service.GetPatientChargeDetails(patinet_id, adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, keyword, item_type, p_type)
361
+
362
+	if err == nil {
363
+		c.ServeSuccessJSON(map[string]interface{}{
364
+			"patients": chargePatient,
365
+		})
366
+		return
367
+	} else {
368
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
369
+		return
370
+
371
+	}
372
+
373
+}
374
+
375
+func (c *HisChargeApiController) GetStatisticsGather() {
376
+	start_time := c.GetString("start_time")
377
+	end_time := c.GetString("end_time")
378
+	keyword := c.GetString("keyword")
379
+	item_type, _ := c.GetInt64("type")
380
+	adminUser := c.GetAdminUserInfo()
381
+	timeLayout := "2006-01-02"
382
+	loc, _ := time.LoadLocation("Local")
383
+	startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
384
+	if err != nil {
385
+
386
+	}
387
+	startRecordDateTime := startTime.Unix()
388
+
389
+	endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
390
+	if err != nil {
391
+
392
+	}
393
+	endRecordDateTime := endTime.Unix()
394
+
395
+	chargePatient, err := service.GetAllPatientChargeDetails(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, keyword, item_type)
396
+
397
+	if err == nil {
398
+		c.ServeSuccessJSON(map[string]interface{}{
399
+			"patients": chargePatient,
400
+		})
401
+		return
402
+	} else {
403
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
404
+		return
405
+
406
+	}
407
+
408
+}

+ 3 - 1
controllers/his_hospital_api_controller.go 파일 보기

@@ -504,7 +504,7 @@ func (c *HisHospitalApiController) GetHisHospitalChargePatientInfo() {
504 504
 	}
505 505
 
506 506
 	if order_status == 1 || order_status == 0 {
507
-		settle_prescriptions, _ = service.GetSettleHisHospitalPrescription(admin.CurrentOrgId, patient_id, his_patient_id, his_patient_info.RecordDate)
507
+		settle_prescriptions, _ = service.GetSettleHisHospitalPrescription(admin.CurrentOrgId, patient_id, his_patient_info.Number)
508 508
 	} else if order_status == 2 {
509 509
 		settle_prescriptions, _ = service.GetSettleHisHospitalPrescriptionTwo(admin.CurrentOrgId, patient_id, his_patient_info.Number)
510 510
 	}
@@ -526,6 +526,8 @@ func (c *HisHospitalApiController) GetHisHospitalChargePatientInfo() {
526 526
 		}
527 527
 
528 528
 	}
529
+	settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
530
+
529 531
 	case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
530 532
 	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
531 533
 	order, _ := service.GetNewHisOrder(admin.CurrentOrgId, his_patient_info.Number, patient_id)

+ 36 - 11
controllers/his_print_api_controller.go 파일 보기

@@ -2,6 +2,7 @@ package controllers
2 2
 
3 3
 import (
4 4
 	"XT_New/enums"
5
+	"XT_New/models"
5 6
 	"XT_New/service"
6 7
 	"github.com/astaxie/beego"
7 8
 	"strings"
@@ -38,25 +39,49 @@ func (c *HisPrintApiController) GetBatchHisPrescriptionData() {
38 39
 		})
39 40
 		break
40 41
 	case 2:
41
-		patients, _ := service.GetBatchProjectHisPrescription(ids, recordDateTime, adminInfo.CurrentOrgId)
42
-		for _, item := range patients {
43
-			for _, subItem := range item.HisPrintPrescription {
44
-				for _, subItemTwo := range subItem.HisPrescriptionProject {
45
-					if subItemTwo.HisProject.CostClassify == 3 {
46
-
47
-					}
48
-				}
49
-			}
50
-		}
42
+		//var newPatients []*models.PrintPatient
51 43
 
44
+		patients, _ := service.GetBatchProjectHisPrescription(ids, recordDateTime, adminInfo.CurrentOrgId)
45
+		//for _, item := range patients {
46
+		//	for _, subItem := range item.HisPrintPrescription {
47
+		//		for _, subItemTwo := range subItem.HisPrescriptionProject {
48
+		//			if subItemTwo.HisProject.CostClassify != 3 {
49
+		//
50
+		//			}
51
+		//		}
52
+		//	}
53
+		//}
52 54
 		c.ServeSuccessJSON(map[string]interface{}{
53 55
 			"patients": patients,
54 56
 		})
55 57
 		break
56 58
 	case 3:
59
+		var newPatients []*models.PrintPatient
60
+		var newPatientsTwo []*models.PrintPatient
61
+
57 62
 		patients, _ := service.GetBatchInspectionProjectHisPrescription(ids, recordDateTime, adminInfo.CurrentOrgId)
63
+		for _, item := range patients {
64
+			var newPatient *models.PrintPatient
65
+			newPatient = item
66
+			for index, subItem := range item.HisPrintPrescription {
67
+				if index > 0 {
68
+					item.HisPrintPrescription[0].HisPrescriptionProject = append(item.HisPrintPrescription[0].HisPrescriptionProject, subItem.HisPrescriptionProject...)
69
+				}
70
+			}
71
+			newPatients = append(newPatients, newPatient)
72
+		}
73
+
74
+		for _, item := range patients {
75
+			var newPatient *models.PrintPatient
76
+			newPatient = item
77
+			if len(item.HisPrintPrescription) > 0 {
78
+				newPatient.NewHisPrintPrescription = append(newPatient.NewHisPrintPrescription, item.HisPrintPrescription[0])
79
+				newPatientsTwo = append(newPatientsTwo, newPatient)
80
+			}
81
+		}
82
+
58 83
 		c.ServeSuccessJSON(map[string]interface{}{
59
-			"patients": patients,
84
+			"patients": newPatientsTwo,
60 85
 		})
61 86
 		break
62 87
 	}

+ 4 - 6
controllers/his_project_api_controller.go 파일 보기

@@ -1201,6 +1201,8 @@ func (this *HisProjectApiController) GetHisPatient() {
1201 1201
 func (this *HisProjectApiController) GetDoctorAdvicePrint() {
1202 1202
 
1203 1203
 	patient_id, _ := this.GetInt64("patient_id")
1204
+	his_patient_id, _ := this.GetInt64("his_patient_id")
1205
+
1204 1206
 	record_date := this.GetString("record_date")
1205 1207
 	schIDStr := this.GetString("ids")
1206 1208
 	p_type, _ := this.GetInt64("p_type")
@@ -1230,7 +1232,7 @@ func (this *HisProjectApiController) GetDoctorAdvicePrint() {
1230 1232
 	his, _ := service.GetLastHisPatient(patient_id, adminUserInfo.CurrentOrgId)
1231 1233
 	prescriptionInfo, _ := service.GetPrscriptionInfo(patient_id, recordDateTime)
1232 1234
 	//advicePrint, err := service.GetPre(patient_id, recordDateTime, idStrs, adminUserInfo.CurrentOrgId, temp_p_type)
1233
-	hisPatient, _ := service.GetHisPatientInfo(adminUserInfo.CurrentOrgId, patient_id, recordDateTime)
1235
+	hisPatient, _ := service.GetHisPatientInfoFour(adminUserInfo.CurrentOrgId, patient_id, recordDateTime, his_patient_id)
1234 1236
 	//hisPatient, _ := service.GetHisPatientById(patient_id)
1235 1237
 	hisHospitalRecord, _ := service.GetLastHospitalRecordTwo(patient_id, adminUserInfo.CurrentOrgId)
1236 1238
 
@@ -1553,14 +1555,10 @@ func (this *HisProjectApiController) GetTodaySchedulePatient() {
1553 1555
 func (this *HisProjectApiController) GetHisPatientDetail() {
1554 1556
 	patient_id, _ := this.GetInt64("patient_id")
1555 1557
 
1556
-	hisPatient, err := service.GetHisPatientById(patient_id)
1558
+	hisPatient, _ := service.GetHisPatientByIdFour(patient_id)
1557 1559
 	//service.GetLastHospitalRecordTwo(patient_id,this.GetAdminUserInfo().CurrentOrgId)
1558 1560
 	hisHospitalRecord, _ := service.GetLastHospitalRecordTwo(patient_id, this.GetAdminUserInfo().CurrentOrgId)
1559 1561
 
1560
-	if err != nil {
1561
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
1562
-		return
1563
-	}
1564 1562
 	this.ServeSuccessJSON(map[string]interface{}{
1565 1563
 		"hisPatient":        hisPatient,
1566 1564
 		"hisHospitalRecord": hisHospitalRecord,

+ 51 - 0
models/his_charge_models.go 파일 보기

@@ -241,3 +241,54 @@ type GdybPsnNcdsRecord struct {
241 241
 func (GdybPsnNcdsRecord) TableName() string {
242 242
 	return "gdyb_psn_ncds_record"
243 243
 }
244
+
245
+type ChargePatientTwo struct {
246
+	ID        int64  `gorm:"column:id" json:"id" form:"id"`
247
+	UserOrgId int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
248
+	Name      string `gorm:"column:name" json:"name" form:"name"`
249
+	Lapseto   int64  `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
250
+	Status    int64  `gorm:"column:status" json:"status" form:"status"`
251
+}
252
+
253
+func (ChargePatientTwo) TableName() string {
254
+	return "xt_patients"
255
+}
256
+
257
+type HisChargeOrderTwo struct {
258
+	ID                    int64                    `gorm:"column:id" json:"id" form:"id"`
259
+	UserOrgId             int64                    `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
260
+	HisPatientId          int64                    `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
261
+	SettleAccountsDate    int64                    `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
262
+	Status                int64                    `gorm:"column:status" json:"status" form:"status"`
263
+	Number                string                   `gorm:"column:number" json:"number" form:"number"`
264
+	OrderStatus           int64                    `gorm:"column:order_status" json:"order_status" form:"order_status"`
265
+	MdtrtId               string                   `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
266
+	PatientId             int64                    `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
267
+	HisChargeOrderInfoTwo []*HisChargeOrderInfoTwo `gorm:"ForeignKey:OrderNumber;AssociationForeignKey:Number" json:"order_info"`
268
+}
269
+
270
+func (HisChargeOrderTwo) TableName() string {
271
+	return "his_order"
272
+}
273
+
274
+type HisChargeOrderInfoTwo struct {
275
+	ID                           int64                        `gorm:"column:id" json:"id" form:"id"`
276
+	OrderNumber                  string                       `gorm:"column:order_number" json:"order_number" form:"order_number"`
277
+	AdviceId                     int64                        `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
278
+	DetItemFeeSumamt             float64                      `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
279
+	Cnt                          float64                      `gorm:"column:cnt" json:"cnt" form:"cnt"`
280
+	Pric                         float64                      `gorm:"column:pric" json:"pric" form:"pric"`
281
+	MedChrgitmType               string                       `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
282
+	Status                       int64                        `gorm:"column:status" json:"status" form:"status"`
283
+	ChldMedcFlag                 string                       `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
284
+	ChrgitmLv                    string                       `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
285
+	UserOrgId                    int64                        `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
286
+	ProjectId                    int64                        `gorm:"column:project_id" json:"project_id" form:"project_id"`
287
+	Type                         int64                        `gorm:"column:type" json:"type" form:"type"`
288
+	HisChargePrescriptionProject HisChargePrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
289
+	HisChargeDoctorAdviceInfo    HisChargeDoctorAdviceInfo    `gorm:"ForeignKey:AdviceId;AssociationForeignKey:ID" json:"advice"`
290
+}
291
+
292
+func (HisChargeOrderInfoTwo) TableName() string {
293
+	return "his_order_info"
294
+}

+ 48 - 0
models/his_hospital_models.go 파일 보기

@@ -83,6 +83,54 @@ func (HisHospitalCheckRecord) TableName() string {
83 83
 	return "his_hospital_check_record"
84 84
 }
85 85
 
86
+type HisHospitalCheckRecordTwo struct {
87
+	ID                   int64  `gorm:"column:id" json:"id" form:"id"`
88
+	Name                 string `gorm:"column:name" json:"name" form:"name"`
89
+	MedicalTreatmentType int64  `gorm:"column:medical_treatment_type" json:"medical_treatment_type" form:"medical_treatment_type"`
90
+	RecordDate           int64  `gorm:"column:record_date" json:"record_date" form:"record_date"`
91
+	IdCardNo             string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
92
+	AdminUserId          int64  `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
93
+	Departments          int64  `gorm:"column:departments" json:"departments" form:"departments"`
94
+	UserOrgId            int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
95
+	Status               int64  `gorm:"column:status" json:"status" form:"status"`
96
+	Ctime                int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
97
+	Mtime                int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
98
+	PatientId            int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
99
+	Number               string `gorm:"column:number" json:"number" form:"number"`
100
+	Doctor               int64  `gorm:"column:doctor" json:"doctor" form:"doctor"`
101
+	PsnNo                string `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
102
+	PsnCertType          string `gorm:"column:psn_cert_type" json:"psn_cert_type" form:"psn_cert_type"`
103
+	Certno               string `gorm:"column:certno" json:"certno" form:"certno"`
104
+	PsnName              string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
105
+	Gend                 string `gorm:"column:gend" json:"gend" form:"gend"`
106
+	Naty                 string `gorm:"column:naty" json:"naty" form:"naty"`
107
+	MedType              int64  `gorm:"column:med_type" json:"med_type" form:"med_type"`
108
+	Brdy                 string `gorm:"column:brdy" json:"brdy" form:"brdy"`
109
+	Iinfo                string `gorm:"column:iinfo" json:"iinfo" form:"iinfo"`
110
+	Idetinfo             string `gorm:"column:idetinfo" json:"idetinfo" form:"idetinfo"`
111
+	IptOtpNo             string `gorm:"column:ipt_otp_no" json:"ipt_otp_no" form:"ipt_otp_no"`
112
+	AdmBed               int64  `gorm:"column:adm_bed" json:"adm_bed" form:"adm_bed"`
113
+	IdCardType           int64  `gorm:"column:id_card_type" json:"id_card_type" form:"id_card_type"`
114
+	Diagnosis            string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
115
+	InsutypeType         string `gorm:"column:insutype_type" json:"insutype_type" form:"insutype_type"`
116
+	SickType             int64  `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
117
+	MdtrtCertType        string `gorm:"column:mdtrt_cert_type" json:"mdtrt_cert_type" form:"mdtrt_cert_type"`
118
+	InHosptialTime       string `gorm:"column:in_hosptial_time" json:"in_hosptial_time" form:"in_hosptial_time"`
119
+	OutHosptialTime      string `gorm:"column:out_hosptial_time" json:"out_hosptial_time" form:"out_hosptial_time"`
120
+	InHospitalStatus     int64  `gorm:"column:in_hospital_status" json:"in_hospital_status" form:"in_hospital_status"`
121
+	Certificates         int64  `gorm:"column:certificates" json:"certificates" form:"certificates"`
122
+	OutHospitalStatus    int64  `gorm:"column:out_hospital_status" json:"out_hospital_status" form:"out_hospital_status"`
123
+	OutWay               int64  `gorm:"column:out_way" json:"out_way" form:"out_way"`
124
+	Phone                string `gorm:"column:phone" json:"phone" form:"phone"`
125
+	BalanceAccountsType  int64  `gorm:"column:balance_accounts_type" json:"balance_accounts_type" form:"balance_accounts_type"`
126
+	PsnType              int64  `gorm:"column:psn_type" json:"psn_type" form:"psn_type"`
127
+	InsuplcAdmdvs        string `gorm:"column:insuplc_admdvs" json:"insuplc_admdvs" form:"insuplc_admdvs"`
128
+}
129
+
130
+func (HisHospitalCheckRecordTwo) TableName() string {
131
+	return "his_hospital_check_record"
132
+}
133
+
86 134
 type NewCustom struct {
87 135
 	DetItemFeeSumamt float64
88 136
 	Cut              float64

+ 25 - 2
models/his_models.go 파일 보기

@@ -519,7 +519,6 @@ type HisPrescription struct {
519 519
 	HisPrescriptionProject []*HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
520 520
 	HisAdditionalCharge    []*HisAdditionalCharge    `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"addition"`
521 521
 	HisPrescriptionInfo    HisPrescriptionInfo       `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,RecordDate" json:"info"`
522
-	HisOrder               HisOrder                  `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"addition"`
523 522
 	Total                  string                    `gorm:"-" json:"total" form:"total"`
524 523
 	PType                  int64                     `gorm:"column:p_type" json:"p_type" form:"p_type"`
525 524
 	MedType                string                    `gorm:"column:med_type" json:"med_type" form:"med_type"`
@@ -735,7 +734,7 @@ type HisDoctorAdviceTemplate struct {
735 734
 	UpdatedTime           int64   `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
736 735
 	TemplateId            int64   `gorm:"column:template_id" json:"template_id" form:"template_id"`
737 736
 	DrugSpec              string  `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
738
-	DrugSpecUnit          string  `gorm:"column:drug_spec_unit" json:"drug_spec_unit" form:"drug_spec_unit"`
737
+	DrugSpecUnit          string  `gorm:"column:drug_spec_unit" json:"drug_spechis_unit" form:"drug_spec_unit"`
739 738
 	ParentId              int64   `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
740 739
 	AdviceType            int64   `gorm:"column:advice_type" json:"advice_type" form:"advice_type"`
741 740
 	DayCount              int64   `gorm:"column:day_count" json:"day_count" form:"day_count"`
@@ -1970,3 +1969,27 @@ type HisPrescriptionProjectTwo struct {
1970 1969
 func (HisPrescriptionProjectTwo) TableName() string {
1971 1970
 	return "his_prescription_project"
1972 1971
 }
1972
+
1973
+type Reg struct {
1974
+	DeptId      string
1975
+	PatientId   string
1976
+	PatientName string
1977
+	DoctorId    string
1978
+	RegDate     string
1979
+	RegFee      string
1980
+	TreatFee    string
1981
+	OperatorId  string
1982
+	IdCardNo    string
1983
+}
1984
+
1985
+type NewCustomTwo struct {
1986
+	DetItemFeeSumamt string
1987
+	Cut              string
1988
+	FeedetlSn        string
1989
+	Price            string
1990
+	MedListCodg      string
1991
+	Type             int64
1992
+	AdviceId         int64
1993
+	ProjectId        int64
1994
+	ItemId           int64
1995
+}

+ 14 - 13
models/his_print_models.go 파일 보기

@@ -1,19 +1,20 @@
1 1
 package models
2 2
 
3 3
 type PrintPatient struct {
4
-	ID                     int64                   `gorm:"column:id" json:"id" form:"id"`
5
-	UserOrgId              int64                   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
6
-	Name                   string                  `gorm:"column:name" json:"name" form:"name"`
7
-	Age                    string                  `gorm:"column:age" json:"age" form:"age"`
8
-	Gender                 int64                   `gorm:"column:gender" json:"gender" form:"gender"`
9
-	HomeAddress            string                  `gorm:"column:home_address" json:"home_address" form:"home_address"`
10
-	Phone                  string                  `gorm:"column:phone" json:"phone" form:"phone"`
11
-	Lapseto                int64                   `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
12
-	Status                 int64                   `gorm:"column:status" json:"status" form:"status"`
13
-	HisPrintPatient        HisPrintPatient         `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
14
-	HisHospitalCheckRecord HisHospitalCheckRecord  `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_record_patient"`
15
-	HisPrescriptionInfoTwo HisPrescriptionInfoTwo  `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
16
-	HisPrintPrescription   []*HisPrintPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescriptions"`
4
+	ID                      int64                   `gorm:"column:id" json:"id" form:"id"`
5
+	UserOrgId               int64                   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
6
+	Name                    string                  `gorm:"column:name" json:"name" form:"name"`
7
+	Age                     string                  `gorm:"column:age" json:"age" form:"age"`
8
+	Gender                  int64                   `gorm:"column:gender" json:"gender" form:"gender"`
9
+	HomeAddress             string                  `gorm:"column:home_address" json:"home_address" form:"home_address"`
10
+	Phone                   string                  `gorm:"column:phone" json:"phone" form:"phone"`
11
+	Lapseto                 int64                   `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
12
+	Status                  int64                   `gorm:"column:status" json:"status" form:"status"`
13
+	HisPrintPatient         HisPrintPatient         `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
14
+	HisHospitalCheckRecord  HisHospitalCheckRecord  `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_record_patient"`
15
+	HisPrescriptionInfoTwo  HisPrescriptionInfoTwo  `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
16
+	HisPrintPrescription    []*HisPrintPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescriptions"`
17
+	NewHisPrintPrescription []*HisPrintPrescription `json:"new_prescriptions"`
17 18
 }
18 19
 
19 20
 func (PrintPatient) TableName() string {

+ 2 - 0
models/patient_models.go 파일 보기

@@ -188,6 +188,7 @@ type Patients struct {
188 188
 	DeathTime                int64   `gorm:"column:death_time" json:"death_time" form:"death_time"`
189 189
 	ContagionIds             []int64 `gorm:"-"`
190 190
 	DryWeight                float64 `gorm:"-"`
191
+	ZbPatientId              string  `gorm:"column:zb_patient_id" json:"zb_patient_id" form:"zb_patient_id"`
191 192
 }
192 193
 
193 194
 func (Patients) TableName() string {
@@ -539,6 +540,7 @@ type UserAdminRole struct {
539 540
 	Status          int64           `gorm:"column:status" json:"status"`
540 541
 	Ctime           int64           `gorm:"column:ctime" json:"ctime"`
541 542
 	Mtime           int64           `gorm:"column:mtime" json:"mtime"`
543
+	DoctorNumber    string          `gorm:"column:doctor_number" json:"doctor_number"`
542 544
 	Department      string          `gorm:"column:department" json:"department"`
543 545
 	DepartmentId    int64           `gorm:"column:department_id" json:"department_id"`
544 546
 	XtHisDepartment XtHisDepartment `json:"department" gorm:"foreignkey:DepartmentId;AssociationForeignKey:ID;"`

+ 327 - 0
service/coordinate_service.go 파일 보기

@@ -0,0 +1,327 @@
1
+package service
2
+
3
+import (
4
+	"XT_New/models"
5
+	"bytes"
6
+	"encoding/json"
7
+	"fmt"
8
+	"github.com/jinzhu/gorm"
9
+	"io/ioutil"
10
+	"net/http"
11
+)
12
+
13
+func SavePatientMessageInfo() (string, string) {
14
+
15
+	//input := make(map[string]interface{})
16
+	inputData := make(map[string]interface{})
17
+	inputData["patType"] = "1"                  // 就诊凭证编号
18
+	inputData["patIdNo"] = "440510199211080033" // 开始时间
19
+	inputData["patName"] = "测试患者"               // 人员姓名
20
+
21
+	inputData["patMobile"] = "13535547902" // 人员姓名
22
+	inputData["patSex"] = "M"              // 人员姓名
23
+	inputData["patMarriage"] = "1"         // 人员姓名
24
+	inputData["birthday"] = "1992-10-23"   // 人员姓名
25
+	inputData["patAddress"] = "11111"      // 人员姓名
26
+	inputData["thirdPartyID"] = "6933"     // 人员姓名
27
+	inputData["patAge"] = "30"             // 人员姓名
28
+	//input["req"] = inputData
29
+
30
+	var inputLog string
31
+	bytesData, err := json.Marshal(inputData)
32
+	inputLog = string(bytesData)
33
+	fmt.Println(string(bytesData))
34
+	if err != nil {
35
+		fmt.Println(err.Error())
36
+		return err.Error(), ""
37
+	}
38
+	reader := bytes.NewReader(bytesData)
39
+	var url string
40
+	gdyb_url := "http://218.104.146.179:9091/esb/listener/savePatientMessageInfo"
41
+	url = gdyb_url
42
+
43
+	//url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1101"
44
+	request, err := http.NewRequest("GET", url, reader)
45
+	if err != nil {
46
+		fmt.Println(err.Error())
47
+		return err.Error(), ""
48
+	}
49
+
50
+	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
51
+	request.Header.Set("code", "Xmrjyy")
52
+
53
+	client := http.Client{}
54
+	resp, err := client.Do(request)
55
+	if err != nil {
56
+		fmt.Println(err.Error())
57
+		return err.Error(), ""
58
+	}
59
+	respBytes, err := ioutil.ReadAll(resp.Body)
60
+	if err != nil {
61
+		fmt.Println(err.Error())
62
+		return err.Error(), ""
63
+	}
64
+	fmt.Println(string(respBytes))
65
+	str := string(respBytes)
66
+	return str, inputLog
67
+
68
+}
69
+
70
+func SaveReg(reg models.Reg) (string, string) {
71
+
72
+	//input := make(map[string]interface{})
73
+	inputData := make(map[string]interface{})
74
+
75
+	inputData["deptId"] = reg.DeptId
76
+	inputData["clinicUnitId"] = ""
77
+	inputData["healthCardNo"] = ""
78
+	fmt.Println(reg.PatientId)
79
+	inputData["patientId"] = reg.PatientId
80
+	inputData["patientName"] = reg.PatientName
81
+	inputData["idCardNo"] = reg.IdCardNo
82
+	inputData["phone"] = "13535547901"
83
+	inputData["doctorId"] = "1111"
84
+	inputData["doctorLevelCode"] = ""
85
+	inputData["regDate"] = reg.RegDate
86
+
87
+	inputData["shiftCode"] = ""
88
+	inputData["startTime"] = ""
89
+	inputData["endTime"] = ""
90
+
91
+	inputData["scheduleId"] = ""
92
+	inputData["periodId"] = ""
93
+
94
+	inputData["svObjectId"] = ""
95
+	inputData["diseaseId"] = ""
96
+	inputData["regFee"] = reg.RegFee
97
+
98
+	inputData["treatFee"] = reg.TreatFee
99
+	inputData["operatorId"] = reg.OperatorId
100
+	inputData["remark"] = "111111"
101
+
102
+	inputData["orderType"] = "0"
103
+	inputData["clinicCode"] = ""
104
+	inputData["infoSeq"] = ""
105
+
106
+	//input["Request"] = inputData
107
+
108
+	var inputLog string
109
+	bytesData, err := json.Marshal(inputData)
110
+	inputLog = string(bytesData)
111
+	fmt.Println(string(bytesData))
112
+	if err != nil {
113
+		fmt.Println(err.Error())
114
+		return err.Error(), ""
115
+	}
116
+	reader := bytes.NewReader(bytesData)
117
+	var url string
118
+	gdyb_url := "http://218.104.146.179:9091/esb/listener/saveReg"
119
+	url = gdyb_url
120
+
121
+	//url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1101"
122
+	request, err := http.NewRequest("POST", url, reader)
123
+	if err != nil {
124
+		fmt.Println(err.Error())
125
+		return err.Error(), ""
126
+	}
127
+
128
+	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
129
+	request.Header.Set("code", "Xmrjyy")
130
+
131
+	client := http.Client{}
132
+	resp, err := client.Do(request)
133
+	if err != nil {
134
+		fmt.Println(err.Error())
135
+		return err.Error(), ""
136
+	}
137
+	respBytes, err := ioutil.ReadAll(resp.Body)
138
+	if err != nil {
139
+		fmt.Println(err.Error())
140
+		return err.Error(), ""
141
+	}
142
+	fmt.Println(string(respBytes))
143
+	str := string(respBytes)
144
+	return str, inputLog
145
+
146
+}
147
+func GetWaitPayDetail() (string, string) {
148
+
149
+	//input := make(map[string]interface{})
150
+	inputData := make(map[string]interface{})
151
+
152
+	inputData["clinicSeq"] = "30445"              // 就诊凭证编号
153
+	inputData["prescriptionId"] = ""              // 开始时间
154
+	inputData["patientId"] = "701822660170096645" // 人员姓名
155
+
156
+	var inputLog string
157
+	bytesData, err := json.Marshal(inputData)
158
+	inputLog = string(bytesData)
159
+	fmt.Println(string(bytesData))
160
+	if err != nil {
161
+		fmt.Println(err.Error())
162
+		return err.Error(), ""
163
+	}
164
+	reader := bytes.NewReader(bytesData)
165
+	var url string
166
+	gdyb_url := "http://218.104.146.179:9091/esb/listener/getWaitPayDetail"
167
+	url = gdyb_url
168
+
169
+	//url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1101"
170
+	request, err := http.NewRequest("POST", url, reader)
171
+	if err != nil {
172
+		fmt.Println(err.Error())
173
+		return err.Error(), ""
174
+	}
175
+
176
+	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
177
+	request.Header.Set("code", "Xmrjyy")
178
+
179
+	client := http.Client{}
180
+	resp, err := client.Do(request)
181
+	if err != nil {
182
+		fmt.Println(err.Error())
183
+		return err.Error(), ""
184
+	}
185
+	respBytes, err := ioutil.ReadAll(resp.Body)
186
+	if err != nil {
187
+		fmt.Println(err.Error())
188
+		return err.Error(), ""
189
+	}
190
+	fmt.Println(string(respBytes))
191
+	str := string(respBytes)
192
+	return str, inputLog
193
+
194
+}
195
+func OpKeepAccounts(number string, cus []*models.NewCustomTwo) (string, string) {
196
+
197
+	inputData := make(map[string]interface{})
198
+	feedetail := make([]map[string]interface{}, 0)
199
+	for _, item := range cus {
200
+		feedetailInfo := make(map[string]interface{})
201
+		feedetailInfo["itemCode"] = item.MedListCodg
202
+		feedetailInfo["num"] = item.Cut
203
+		feedetail = append(feedetail, feedetailInfo)
204
+	}
205
+	inputData["item"] = feedetail
206
+	inputData["clinicSeq"] = number // 就诊凭证编号
207
+	var inputLog string
208
+	bytesData, err := json.Marshal(inputData)
209
+	inputLog = string(bytesData)
210
+	fmt.Println(string(bytesData))
211
+	if err != nil {
212
+		fmt.Println(err.Error())
213
+		return err.Error(), ""
214
+	}
215
+	reader := bytes.NewReader(bytesData)
216
+	var url string
217
+	gdyb_url := "http://218.104.146.179:9091/esb/listener/opKeepAccounts"
218
+	url = gdyb_url
219
+
220
+	request, err := http.NewRequest("POST", url, reader)
221
+	if err != nil {
222
+		fmt.Println(err.Error())
223
+		return err.Error(), ""
224
+	}
225
+
226
+	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
227
+	request.Header.Set("code", "Xmrjyy")
228
+
229
+	client := http.Client{}
230
+	resp, err := client.Do(request)
231
+	if err != nil {
232
+		fmt.Println(err.Error())
233
+		return err.Error(), ""
234
+	}
235
+	respBytes, err := ioutil.ReadAll(resp.Body)
236
+	if err != nil {
237
+		fmt.Println(err.Error())
238
+		return err.Error(), ""
239
+	}
240
+	fmt.Println(string(respBytes))
241
+	str := string(respBytes)
242
+	return str, inputLog
243
+
244
+}
245
+func OpCancelKeepAccounts(setl_id string, op_name string, op_code string) (string, string) {
246
+	inputData := make(map[string]interface{})
247
+	inputData["docId"] = setl_id
248
+	inputData["operCode"] = "111"
249
+	inputData["operName"] = "2222"
250
+	var inputLog string
251
+	bytesData, err := json.Marshal(inputData)
252
+	inputLog = string(bytesData)
253
+	fmt.Println(string(bytesData))
254
+	if err != nil {
255
+		fmt.Println(err.Error())
256
+		return err.Error(), ""
257
+	}
258
+	reader := bytes.NewReader(bytesData)
259
+	var url string
260
+	gdyb_url := "http://218.104.146.179:9091/esb/listener/opCancelKeepAccounts"
261
+	url = gdyb_url
262
+	request, err := http.NewRequest("POST", url, reader)
263
+	if err != nil {
264
+		fmt.Println(err.Error())
265
+		return err.Error(), ""
266
+	}
267
+	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
268
+	request.Header.Set("code", "Xmrjyy")
269
+	client := http.Client{}
270
+	resp, err := client.Do(request)
271
+	if err != nil {
272
+		fmt.Println(err.Error())
273
+		return err.Error(), ""
274
+	}
275
+	respBytes, err := ioutil.ReadAll(resp.Body)
276
+	if err != nil {
277
+		fmt.Println(err.Error())
278
+		return err.Error(), ""
279
+	}
280
+	fmt.Println(string(respBytes))
281
+	str := string(respBytes)
282
+	return str, inputLog
283
+
284
+}
285
+
286
+func UpdateHisPatientStatus(his *models.VMHisPatient) {
287
+	writeDb.Save(&his)
288
+}
289
+
290
+func GetUnSettleHisPrescriptionFive(org_id int64, patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
291
+	err = readDb.Model(&models.HisPrescription{}).
292
+		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
293
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
294
+		}).
295
+		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
296
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
297
+		}).
298
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
299
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
300
+		}).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
301
+		return db.Where("status = 1 AND user_org_id = ? AND order_status <> 3  AND order_status <> 2  ", org_id)
302
+	}).
303
+		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3 and order_status <> 5  AND p_type = ?", org_id, record_date, patient_id, p_type).
304
+		Find(&prescription).Error
305
+	return
306
+}
307
+
308
+func GetUnSettleMonthHisPrescription(org_id int64, patient_id int64, start_date int64, end_date int64) (prescription []*models.HisPrescription, err error) {
309
+	err = readDb.Model(&models.HisPrescription{}).
310
+		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
311
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
312
+		}).
313
+		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
314
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
315
+		}).
316
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
317
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
318
+		}).
319
+		Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND order_status <> 5 AND p_type <> 1", org_id, start_date, end_date, patient_id).
320
+		Find(&prescription).Error
321
+	return
322
+}
323
+
324
+func GetHisOrderFour(patient_id string, infoSeq string, docId string) (order models.HisOrder, err error) {
325
+	err = readDb.Model(&models.HisOrder{}).Where("mdtrt_id = ? AND psn_no = ? AND setl_id = ?", infoSeq, patient_id, docId).First(&order).Error
326
+	return
327
+}

+ 225 - 0
service/his_charge_service.go 파일 보기

@@ -311,3 +311,228 @@ func GetHisYidiClearRecordById(org_id int64, id int64) (record models.HisYidiCle
311 311
 	err = readDb.Model(&models.HisYidiClearRecord{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, id).First(&record).Error
312 312
 	return
313 313
 }
314
+
315
+func GetAllPatientTwo(org_id int64) (patients []*models.ChargePatientTwo, err error) {
316
+	err = readDb.Model(&models.ChargePatientTwo{}).Where("user_org_id = ? AND status = 1", org_id).Find(&patients).Error
317
+	return
318
+}
319
+
320
+func GetPatientChargeDetails(patient_id int64, org_id int64, start_time int64, end_time int64, keyword string, item_type int64, settle_type int64) (patients []*models.HisChargeOrderTwo, err error) {
321
+	if len(keyword) == 0 {
322
+		switch item_type {
323
+		case 0:
324
+			readDb2.Model(&models.HisChargeOrderTwo{}).Joins("join his_patient his on his.number = his_order.mdtrt_id AND his.patient_id = ").Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
325
+				return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
326
+					Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
327
+						return db.Preload("Drug", "status = 1").Where("status = 1")
328
+					}).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
329
+					return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
330
+						return db.Select("id,project_name,unit").Where("status = 1 ")
331
+					}).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
332
+						return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
333
+					}).Where("status = 1 ")
334
+				})
335
+			}).Where("status = 1  AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
336
+			break
337
+		case 1:
338
+			readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
339
+				return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
340
+					Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
341
+						return db.Preload("Drug", "status = 1").Where("status = 1")
342
+					}).Where("status = 1 AND advice_id > 0 AND project_id = 0")
343
+			}).Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2  AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
344
+
345
+			break
346
+		case 2:
347
+			readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
348
+				return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
349
+					Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
350
+						return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
351
+							return db.Select("id,project_name,unit").Where("status = 1 ")
352
+						}).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
353
+							return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
354
+						}).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
355
+					})
356
+			}).Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
357
+
358
+			break
359
+		case 3:
360
+			readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
361
+				return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
362
+					Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
363
+						return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
364
+							return db.Select("id,project_name,unit").Where("status = 1 ")
365
+						}).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
366
+							return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
367
+						}).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
368
+					})
369
+			}).Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
370
+			break
371
+		}
372
+
373
+	} else {
374
+		//keyword := "%" + keyword + "%"
375
+		switch item_type {
376
+		case 0:
377
+			readDb2.Model(&models.HisChargeOrderTwo{}).Joins("join his_patient his on his.number = his_order.mdtrt_id AND his.patient_id = ").Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
378
+				return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
379
+					Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
380
+						return db.Preload("Drug", "status = 1").Where("status = 1")
381
+					}).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
382
+					return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
383
+						return db.Select("id,project_name,unit").Where("status = 1 ")
384
+					}).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
385
+						return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
386
+					}).Where("status = 1 ")
387
+				})
388
+			}).Where("status = 1  AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
389
+			break
390
+		case 1:
391
+			readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
392
+				return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
393
+					Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
394
+						return db.Preload("Drug", "status = 1").Where("status = 1")
395
+					}).Where("status = 1 AND advice_id > 0 AND project_id = 0")
396
+			}).Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2  AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
397
+
398
+			break
399
+		case 2:
400
+			readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
401
+				return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
402
+					Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
403
+						return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
404
+							return db.Select("id,project_name,unit").Where("status = 1 ")
405
+						}).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
406
+							return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
407
+						}).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
408
+					})
409
+			}).Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
410
+
411
+			break
412
+		case 3:
413
+			readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
414
+				return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
415
+					Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
416
+						return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
417
+							return db.Select("id,project_name,unit").Where("status = 1 ")
418
+						}).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
419
+							return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
420
+						}).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
421
+					})
422
+			}).Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
423
+			break
424
+		}
425
+
426
+	}
427
+	return
428
+}
429
+
430
+func GetPatientGather(patient_id int64, org_id int64, start_time int64, end_time int64, keyword string, item_type int64, settle_type int64) (patients []*models.HisChargeOrderTwo, err error) {
431
+	if len(keyword) == 0 {
432
+		switch item_type {
433
+		case 0:
434
+			readDb2.Model(&models.HisChargeOrderTwo{}).Joins("join his_patient his on his.number = his_order.mdtrt_id AND his.patient_id = ").Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
435
+				return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
436
+					Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
437
+						return db.Preload("Drug", "status = 1").Where("status = 1")
438
+					}).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
439
+					return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
440
+						return db.Select("id,project_name,unit").Where("status = 1 ")
441
+					}).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
442
+						return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
443
+					}).Where("status = 1 ")
444
+				})
445
+			}).Where("status = 1  AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
446
+			break
447
+		case 1:
448
+			readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
449
+				return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
450
+					Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
451
+						return db.Preload("Drug", "status = 1").Where("status = 1")
452
+					}).Where("status = 1 AND advice_id > 0 AND project_id = 0")
453
+			}).Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2  AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
454
+
455
+			break
456
+		case 2:
457
+			readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
458
+				return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
459
+					Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
460
+						return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
461
+							return db.Select("id,project_name,unit").Where("status = 1 ")
462
+						}).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
463
+							return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
464
+						}).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
465
+					})
466
+			}).Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
467
+
468
+			break
469
+		case 3:
470
+			readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
471
+				return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
472
+					Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
473
+						return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
474
+							return db.Select("id,project_name,unit").Where("status = 1 ")
475
+						}).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
476
+							return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
477
+						}).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
478
+					})
479
+			}).Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
480
+			break
481
+		}
482
+
483
+	} else {
484
+		//keyword := "%" + keyword + "%"
485
+		switch item_type {
486
+		case 0:
487
+			readDb2.Model(&models.HisChargeOrderTwo{}).Joins("join his_patient his on his.number = his_order.mdtrt_id AND his.patient_id = ").Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
488
+				return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
489
+					Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
490
+						return db.Preload("Drug", "status = 1").Where("status = 1")
491
+					}).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
492
+					return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
493
+						return db.Select("id,project_name,unit").Where("status = 1 ")
494
+					}).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
495
+						return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
496
+					}).Where("status = 1 ")
497
+				})
498
+			}).Where("status = 1  AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
499
+			break
500
+		case 1:
501
+			readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
502
+				return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
503
+					Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
504
+						return db.Preload("Drug", "status = 1").Where("status = 1")
505
+					}).Where("status = 1 AND advice_id > 0 AND project_id = 0")
506
+			}).Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2  AND patient_id = ? AND p_type=?", start_time, end_time, org_id, patient_id, settle_type)
507
+
508
+			break
509
+		case 2:
510
+			readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
511
+				return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
512
+					Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
513
+						return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
514
+							return db.Select("id,project_name,unit").Where("status = 1 ")
515
+						}).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
516
+							return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
517
+						}).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
518
+					})
519
+			}).Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
520
+
521
+			break
522
+		case 3:
523
+			readDb2.Model(&models.HisChargeOrderTwo{}).Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
524
+				return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
525
+					Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
526
+						return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
527
+							return db.Select("id,project_name,unit").Where("status = 1 ")
528
+						}).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
529
+							return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
530
+						}).Where("status = 1 AND advice_id = 0 AND project_id > 0 ")
531
+					})
532
+			}).Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND patient_id = ? AND p_type = ?", start_time, end_time, org_id, patient_id, settle_type)
533
+			break
534
+		}
535
+
536
+	}
537
+	return
538
+}

+ 2 - 2
service/his_hospital_service.go 파일 보기

@@ -315,7 +315,7 @@ func GetHospitalMonthHisPrescription(org_id int64, patient_id int64, start_time
315 315
 	return
316 316
 }
317 317
 
318
-func GetSettleHisHospitalPrescription(org_id int64, patient_id int64, his_patient_id int64, record_date int64) (prescription []*models.HisHospitalPrescription, err error) {
318
+func GetSettleHisHospitalPrescription(org_id int64, patient_id int64, batch_number string) (prescription []*models.HisHospitalPrescription, err error) {
319 319
 	err = readDb.Model(&models.HisHospitalPrescription{}).
320 320
 		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
321 321
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
@@ -326,7 +326,7 @@ func GetSettleHisHospitalPrescription(org_id int64, patient_id int64, his_patien
326 326
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
327 327
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
328 328
 		}).
329
-		Where("user_org_id = ? AND status = 1 AND record_date >= ? AND patient_id = ? AND order_status = 4 ", org_id, record_date, patient_id).
329
+		Where("user_org_id = ? AND status = 1  AND patient_id = ? AND order_status = 4 AND batch_number = ? ", org_id, patient_id, batch_number).
330 330
 		Find(&prescription).Error
331 331
 	return
332 332
 }

+ 2 - 2
service/his_print_service.go 파일 보기

@@ -23,7 +23,7 @@ func GetBatchProjectHisPrescription(ids []string, record_time int64, user_org_id
23 23
 		Preload("HisPrintPrescription", func(db *gorm.DB) *gorm.DB {
24 24
 			return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND type <> 1 AND p_type = 2", user_org_id, record_time).
25 25
 				Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
26
-					return db.Where("status = 1 ").Preload("HisProject", "status = 1").Preload("GoodInfo", "status=1")
26
+					return db.Where("his_prescription_project.status = 1 AND his_prescription_project.user_org_id = ?", user_org_id).Where("his_prescription_project.status = 1 ").Preload("HisProject", "status = 1").Preload("GoodInfo", "status=1")
27 27
 				})
28 28
 		}).
29 29
 		Preload("HisPrescriptionInfoTwo", "status = 1 AND record_date = ?", record_time).
@@ -37,7 +37,7 @@ func GetBatchInspectionProjectHisPrescription(ids []string, record_time int64, u
37 37
 		Preload("HisPrintPrescription", func(db *gorm.DB) *gorm.DB {
38 38
 			return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND type <> 1 AND p_type = 2", user_org_id, record_time).
39 39
 				Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
40
-					return db.Where("status = 1 ").Preload("XtHisProjectTeam", "status = 1").Preload("HisProject", "status = 1 AND cost_classify = 3")
40
+					return db.Joins("Join xt_his_project p On p.id = his_prescription_project.project_id  AND p.cost_classify = 3").Where("his_prescription_project.status = 1 ").Preload("XtHisProjectTeam", "status = 1").Preload("HisProject", "status = 1")
41 41
 				})
42 42
 		}).
43 43
 		Preload("HisPrescriptionInfoTwo", "status = 1 AND record_date = ?", record_time).

+ 7 - 1
service/his_project_service.go 파일 보기

@@ -370,7 +370,7 @@ func GetBloodPatientByPatient(id int64) (models.XtPatients, error) {
370 370
 	return patients, err
371 371
 }
372 372
 
373
-func GetHisPatientByIdTwo(patientid int64) (models.XtHisPatient, error) {
373
+func GetHisPatientByIdFour(patientid int64) (models.XtHisPatient, error) {
374 374
 
375 375
 	patient := models.XtHisPatient{}
376 376
 	err := XTReadDB().Model(&patient).Where("patient_id = ? and status=1", patientid).Find(&patient).Error
@@ -383,6 +383,12 @@ func GetHisPatientById(patientid int64) (models.VMHisPatient, error) {
383 383
 	return patient, err
384 384
 }
385 385
 
386
+func GetHisPatientByIdTwo(patientid int64) (models.VMHisPatient, error) {
387
+	patient := models.VMHisPatient{}
388
+	err := XTReadDB().Model(&patient).Where("patient_id = ? and status = 1", patientid).Limit(&patient).Error
389
+	return patient, err
390
+}
391
+
386 392
 func GetTemplateDetail(id int64) (models.HisCaseHistoryTemplate, error) {
387 393
 
388 394
 	template := models.HisCaseHistoryTemplate{}

+ 56 - 5
service/his_service.go 파일 보기

@@ -285,7 +285,7 @@ func GetNewScheduleHisPatientList(org_id int64, keywords string, record_date int
285 285
 }
286 286
 
287 287
 func GetAllBaseDrugStockList(org_id int64) (drugs []*models.BaseDrugLib, err error) {
288
-	err = readDb.Model(&models.BaseDrugLib{}).Where("user_org_id = ? AND status = 1", org_id).Find(&drugs).Error
288
+	err = readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? AND status = 1", org_id).Find(&drugs).Error
289 289
 	return
290 290
 }
291 291
 
@@ -304,6 +304,11 @@ func GetHisPatientInfoThree(org_id int64, number string) (info models.HisPatient
304 304
 	return
305 305
 }
306 306
 
307
+func GetHisPatientInfoFour(org_id int64, patient_id int64, record_date int64, his_patient_id int64) (info models.HisPatient, err error) {
308
+	err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND id = ?", org_id, record_date, patient_id, his_patient_id).First(&info).Error
309
+	return
310
+}
311
+
307 312
 func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
308 313
 	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
309 314
 	return
@@ -587,6 +592,24 @@ func GetChargeMonthHisPrescriptionFour(org_id int64, patient_id int64, start_dat
587 592
 	return
588 593
 }
589 594
 
595
+func GetUnChargeMonthHisPrescriptionFour(org_id int64, patient_id int64, start_date int64, end_date int64) (prescription []*models.HisPrescription, err error) {
596
+	err = readDb.Model(&models.HisPrescription{}).
597
+		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
598
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
599
+		}).
600
+		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
601
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
602
+		}).
603
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
604
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
605
+		}).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
606
+		return db.Where("status = 1 AND user_org_id = ?", org_id)
607
+	}).
608
+		Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ?  AND  order_status <> 2 AND order_status <> 3 AND order_status <> 4", org_id, start_date, end_date, patient_id).
609
+		Find(&prescription).Error
610
+	return
611
+}
612
+
590 613
 type OtherDrugWarehouseInfo struct {
591 614
 	ID               int64   `gorm:"column:id" json:"id" form:"id"`
592 615
 	DrugId           int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
@@ -1841,11 +1864,9 @@ type CustomAccountFormData struct {
1841 1864
 
1842 1865
 func GetCheckAccountFormData(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (cus []*CustomAccountFormData, err error) {
1843 1866
 	if clr_type == "9903" {
1844
-
1845 1867
 		err = readDb.Raw("select o.setl_detail as setl_detail, o.maf_pay as maf_pay,  o.hifmi_pay  as hifmi_pay, o.hifob_pay as hifob_pay, o.cvlserv_pay as cvlserv_pay, o.hifes_pay as hifes_pay, o.patient_id as patient_id, p.diagnosis as diagnosis_id, p.iinfo as iinfo, 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,o.hifp_pay as hifp_pay  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 o.insutype = ? AND o.clr_type = ? Group by o.id", org_id, start_time, end_time, insutype, clr_type).Scan(&cus).Error
1846 1868
 	} else {
1847 1869
 		err = readDb.Raw("select o.setl_detail as setl_detail, o.maf_pay as maf_pay,  o.hifmi_pay  as hifmi_pay, o.hifob_pay as hifob_pay, o.cvlserv_pay as cvlserv_pay, o.hifes_pay as hifes_pay, o.patient_id as patient_id, p.diagnosis as diagnosis_id, p.iinfo as iinfo, 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,o.hifp_pay as hifp_pay  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 o.insutype = ? AND o.clr_type <> 9903 Group by o.id", org_id, start_time, end_time, insutype).Scan(&cus).Error
1848
-
1849 1870
 	}
1850 1871
 
1851 1872
 	for _, item := range cus {
@@ -2136,7 +2157,9 @@ func GetUnChargeMonthHisPrescriptionSix(org_id int64, patient_id int64, start_da
2136 2157
 		}).
2137 2158
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
2138 2159
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
2139
-		}).
2160
+		}).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
2161
+		return db.Where("status = 1 AND user_org_id = ?", org_id)
2162
+	}).
2140 2163
 		Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ?  AND p_type = ? AND order_status <> 2 ", org_id, start_date, end_date, patient_id, p_type).
2141 2164
 		Find(&prescription).Error
2142 2165
 	return
@@ -2152,7 +2175,9 @@ func GetChargeMonthHisPrescriptionSix(org_id int64, patient_id int64, start_date
2152 2175
 		}).
2153 2176
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
2154 2177
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
2155
-		}).
2178
+		}).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
2179
+		return db.Where("status = 1 AND user_org_id = ?", org_id)
2180
+	}).
2156 2181
 		Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ?  AND p_type = ? AND order_status = 2 ", org_id, start_date, end_date, patient_id, p_type).
2157 2182
 		Find(&prescription).Error
2158 2183
 	return
@@ -2335,3 +2360,29 @@ func GetGoodWarehoseInfoByGoodId(good_id int64, org_id int64) (info models.GoodS
2335 2360
 	err = readDb.Model(&models.GoodSotckInfo{}).Where("stock_count > 0 and status = 1 and good_id = ? and org_id = ?", good_id, org_id).First(&info).Error
2336 2361
 	return
2337 2362
 }
2363
+
2364
+type MonthChargePatients struct {
2365
+	ID              int64              `gorm:"column:id" json:"id" form:"id"`
2366
+	UserOrgId       int64              `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
2367
+	Name            string             `gorm:"column:name" json:"name" form:"name"`
2368
+	Status          int64              `gorm:"column:status" json:"status" form:"status"`
2369
+	PatientId       int64              `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
2370
+	Number          string             `gorm:"column:number" json:"number" form:"number"`
2371
+	HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
2372
+}
2373
+
2374
+func (MonthChargePatients) TableName() string {
2375
+	return "his_patient"
2376
+}
2377
+
2378
+func GetMonthUnChargeHisPatientList(org_id int64, record_date int64, start_time int64, end_time int64) (patients []*MonthChargePatients, err error) {
2379
+	db := readDb.Model(&MonthChargePatients{}).Where("his_patient.user_org_id = ? AND his_patient.status = 1 AND his_patient.record_date = ?", org_id, record_date)
2380
+	db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND p_type <> 1 AND order_status <> 2 AND order_status <> 3", org_id, start_time, end_time)
2381
+	return
2382
+}
2383
+
2384
+func UpdataOrderStatusThree(number string, user_org_id int64) (err error) {
2385
+	err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 5, "mtime": time.Now().Unix()}).Error
2386
+	err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 5, "mtime": time.Now().Unix()}).Error
2387
+	return
2388
+}