Browse Source

Merge branch '20230223_xt_api_new_branch' of http://git.shengws.com/csx/XT_New into 20230223_xt_api_new_branch

28169 1 year ago
parent
commit
cea7c6af1b

+ 123 - 13
controllers/his_charge_api_controller.go View File

@@ -5,7 +5,11 @@ import (
5 5
 	"XT_New/models"
6 6
 	"XT_New/service"
7 7
 	"XT_New/utils"
8
+	"bytes"
9
+	"compress/gzip"
10
+	"encoding/json"
8 11
 	"github.com/astaxie/beego"
12
+	"net/http"
9 13
 	"time"
10 14
 )
11 15
 
@@ -16,6 +20,7 @@ type HisChargeApiController struct {
16 20
 func HisChargeApiRegistRouters() {
17 21
 	beego.Router("/api/his/chargestatistics/detail", &HisChargeApiController{}, "get:GetChargeStatisticsDetail")
18 22
 	beego.Router("/api/his/chargestatistics/settle", &HisChargeApiController{}, "get:GetChargeStatisticsSettle")
23
+	//beego.InsertFilter("/api/his/chargestatistics/detail", beego.BeforeRouter, GzipFilter)
19 24
 
20 25
 	beego.Router("/api/his/patient", &HisChargeApiController{}, "get:GetAllPatient")
21 26
 	//beego.Router("/api/his/chargestatistics/settle", &HisChargeApiController{}, "get:GetChargeStatisticsSettle")
@@ -226,10 +231,10 @@ func (c *HisChargeApiController) GetFaPiaoRecord() {
226 231
 }
227 232
 
228 233
 func (c *HisChargeApiController) GetChargeStatisticsDetail() {
229
-	c.ServeSuccessJSON(map[string]interface{}{
230
-		"msg": "接口优化升级,如有数据需要,请联系客服!",
231
-	})
232
-	return
234
+	//c.ServeSuccessJSON(map[string]interface{}{
235
+	//	"msg": "接口优化升级,如有数据需要,请联系客服!",
236
+	//})
237
+	//return
233 238
 
234 239
 	start_time := c.GetString("start_time")
235 240
 	end_time := c.GetString("end_time")
@@ -252,19 +257,124 @@ func (c *HisChargeApiController) GetChargeStatisticsDetail() {
252 257
 	}
253 258
 	endRecordDateTime := endTime.Unix()
254 259
 
255
-	chargePatient, err := service.GetAllPatientChargeDetails(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, keyword, item_type)
260
+	switch item_type {
261
+	case 0:
262
+		chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
263
+		chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
264
+		chargeDrug = append(chargeDrug, chargeProject...)
265
+		b, _ := structToBytes(chargeDrug)
266
+		//cd, _ := compressData(b)
267
+		// 使用 Gzip 压缩数据
268
+		var compressedData bytes.Buffer
269
+		writer := gzip.NewWriter(&compressedData)
270
+		_, err = writer.Write(b)
271
+		if err != nil {
272
+			c.Ctx.ResponseWriter.WriteHeader(http.StatusInternalServerError)
273
+			c.Ctx.WriteString(err.Error())
274
+			return
275
+		}
276
+		writer.Close()
277
+
278
+		// 设置响应头,表明数据经过了 Gzip 压缩
279
+		c.Ctx.Output.Header("Content-Encoding", "gzip")
280
+		// 发送压缩后的数据
281
+		c.Ctx.ResponseWriter.Write(compressedData.Bytes())
282
+		break
283
+	case 1:
284
+		chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
285
+		//chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
286
+		//chargeDrug = append(chargeDrug, chargeProject...)
287
+		b, _ := structToBytes(chargeDrug)
288
+		//cd, _ := compressData(b)
289
+		// 使用 Gzip 压缩数据
290
+		var compressedData bytes.Buffer
291
+		writer := gzip.NewWriter(&compressedData)
292
+		_, err = writer.Write(b)
293
+		if err != nil {
294
+			c.Ctx.ResponseWriter.WriteHeader(http.StatusInternalServerError)
295
+			c.Ctx.WriteString(err.Error())
296
+			return
297
+		}
298
+		writer.Close()
299
+
300
+		// 设置响应头,表明数据经过了 Gzip 压缩
301
+		c.Ctx.Output.Header("Content-Encoding", "gzip")
302
+		// 发送压缩后的数据
303
+		c.Ctx.ResponseWriter.Write(compressedData.Bytes())
304
+		break
305
+	case 2:
306
+		//chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
307
+		chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
308
+		//chargeDrug = append(chargeDrug, chargeProject...)
309
+		b, _ := structToBytes(chargeProject)
310
+		//cd, _ := compressData(b)
311
+		// 使用 Gzip 压缩数据
312
+		var compressedData bytes.Buffer
313
+		writer := gzip.NewWriter(&compressedData)
314
+		_, err = writer.Write(b)
315
+		if err != nil {
316
+			c.Ctx.ResponseWriter.WriteHeader(http.StatusInternalServerError)
317
+			c.Ctx.WriteString(err.Error())
318
+			return
319
+		}
320
+		writer.Close()
321
+
322
+		// 设置响应头,表明数据经过了 Gzip 压缩
323
+		c.Ctx.Output.Header("Content-Encoding", "gzip")
324
+		// 发送压缩后的数据
325
+		c.Ctx.ResponseWriter.Write(compressedData.Bytes())
326
+		break
327
+
328
+	case 3:
329
+		//chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
330
+		chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
331
+		//chargeDrug = append(chargeDrug, chargeProject...)
332
+		b, _ := structToBytes(chargeProject)
333
+		//cd, _ := compressData(b)
334
+		// 使用 Gzip 压缩数据
335
+		var compressedData bytes.Buffer
336
+		writer := gzip.NewWriter(&compressedData)
337
+		_, err = writer.Write(b)
338
+		if err != nil {
339
+			c.Ctx.ResponseWriter.WriteHeader(http.StatusInternalServerError)
340
+			c.Ctx.WriteString(err.Error())
341
+			return
342
+		}
343
+		writer.Close()
344
+
345
+		// 设置响应头,表明数据经过了 Gzip 压缩
346
+		c.Ctx.Output.Header("Content-Encoding", "gzip")
347
+		// 发送压缩后的数据
348
+		c.Ctx.ResponseWriter.Write(compressedData.Bytes())
349
+		break
256 350
 
257
-	if err == nil {
258
-		c.ServeSuccessJSON(map[string]interface{}{
259
-			"patients": chargePatient,
260
-		})
261
-		return
262
-	} else {
263
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
264
-		return
351
+	}
265 352
 
353
+}
354
+
355
+func structToBytes(p []*models.NewChargeDetail) ([]byte, error) {
356
+	data, err := json.Marshal(p)
357
+	if err != nil {
358
+		return nil, err
359
+	}
360
+	return data, nil
361
+}
362
+
363
+func compressData(data []byte) ([]byte, error) {
364
+	var compressedData bytes.Buffer
365
+	writer := gzip.NewWriter(&compressedData)
366
+
367
+	_, err := writer.Write(data)
368
+	if err != nil {
369
+		return nil, err
370
+	}
371
+
372
+	err = writer.Close()
373
+	if err != nil {
374
+		return nil, err
266 375
 	}
267 376
 
377
+	return compressedData.Bytes(), nil
268 378
 }
269 379
 
270 380
 func (c *HisChargeApiController) GetChargeStatisticsSettle() {

+ 36 - 0
controllers/schedule_api_controller.go View File

@@ -131,6 +131,11 @@ func (c *ScheduleApiController) CoverSch() {
131 131
 	if err == nil {
132 132
 		err2 := service.SaveSch(&new_sch)
133 133
 		if err2 == nil {
134
+			//去除当天患者排班中重复数据,保留最后一条数据
135
+			service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
136
+			service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
137
+			service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
138
+
134 139
 			c.ServeSuccessJSON(map[string]interface{}{
135 140
 				"msg":     "覆盖成功",
136 141
 				"new_sch": new_sch,
@@ -177,6 +182,11 @@ func (c *ScheduleApiController) ExchangeSch() {
177 182
 
178 183
 	err := service.UpdateScheduleThree(sch, sch_two)
179 184
 	if err == nil {
185
+
186
+		//去除当天患者排班中重复数据,保留最后一条数据
187
+		service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
188
+		service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
189
+
180 190
 		c.ServeSuccessJSON(map[string]interface{}{
181 191
 			"msg": "交换成功",
182 192
 		})
@@ -685,8 +695,13 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
685 695
 					service.SaveSch(&schedule)
686 696
 				}
687 697
 				HandleRedis(adminInfo.CurrentOrgId, schedule.ScheduleDate)
698
+				//去除当天患者排班中重复数据,保留最后一条数据
699
+				service.UpdateRepeatSchStatus(adminInfo.CurrentOrgId, schedule.ScheduleDate)
700
+
688 701
 			}
702
+
689 703
 		}
704
+
690 705
 	}
691 706
 	////修改或保存数据
692 707
 	if dataBody["smart_schs"] != nil && reflect.TypeOf(dataBody["smart_schs"]).String() == "[]interface {}" {
@@ -836,6 +851,10 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
836 851
 					schedule.DialysisMachineName = DialysisMachineName
837 852
 					schedule.IsExport = 3000
838 853
 					service.SaveSch(&schedule)
854
+
855
+					//去除当天患者排班中重复数据,保留最后一条数据
856
+					service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
857
+
839 858
 				} else { //新的排班信息
840 859
 
841 860
 					if items["schedule_date"] == nil || reflect.TypeOf(items["schedule_date"]).String() != "string" {
@@ -1025,6 +1044,9 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
1025 1044
 					}
1026 1045
 				}
1027 1046
 
1047
+				//去除当天患者排班中重复数据,保留最后一条数据
1048
+				service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
1049
+
1028 1050
 				c.ServeSuccessJSON(map[string]interface{}{
1029 1051
 					"msg": "保存成功",
1030 1052
 				})
@@ -1609,6 +1631,8 @@ func (c *ScheduleApiController) CreateSchedule() {
1609 1631
 	}
1610 1632
 	schedule.Patient = patientInfo.Name
1611 1633
 
1634
+	service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
1635
+
1612 1636
 	c.ServeSuccessJSON(map[string]interface{}{
1613 1637
 		"msg":      "ok",
1614 1638
 		"schedule": schedule,
@@ -1868,6 +1892,10 @@ func (c *ScheduleApiController) CreateScheduleTwo() {
1868 1892
 		redis.Set(keySeven, "", time.Second)
1869 1893
 		defer redis.Close()
1870 1894
 		schedule.Patient = patientInfo.Name
1895
+
1896
+		//去除当天患者排班中重复数据,保留最后一条数据
1897
+		service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
1898
+
1871 1899
 		c.ServeSuccessJSON(map[string]interface{}{
1872 1900
 			"msg":          "ok",
1873 1901
 			"schedule":     schedule,
@@ -2198,6 +2226,8 @@ func (c *ScheduleApiController) ChangeSchedule() {
2198 2226
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
2199 2227
 			return
2200 2228
 		}
2229
+		service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
2230
+
2201 2231
 		c.ServeSuccessJSON(map[string]interface{}{
2202 2232
 			"msg":      "ok",
2203 2233
 			"schedule": &schedule,
@@ -2209,6 +2239,8 @@ func (c *ScheduleApiController) ChangeSchedule() {
2209 2239
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
2210 2240
 			return
2211 2241
 		}
2242
+		service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
2243
+
2212 2244
 		c.ServeSuccessJSON(map[string]interface{}{
2213 2245
 			"msg":      "ok",
2214 2246
 			"schedule": &schedule,
@@ -5236,7 +5268,11 @@ func (c *ScheduleApiController) ChangeScheduleTen() {
5236 5268
 
5237 5269
 		}
5238 5270
 	}
5271
+	//去除当天患者排班中重复数据,保留最后一条数据
5272
+	service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
5273
+
5239 5274
 	scheduletwo, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
5275
+
5240 5276
 	c.ServeSuccessJSON(map[string]interface{}{
5241 5277
 		"msg":      "ok",
5242 5278
 		"schedule": scheduletwo,

+ 125 - 0
models/his_charge_models.go View File

@@ -340,3 +340,128 @@ type HisChargeOrderInfoTwo struct {
340 340
 func (HisChargeOrderInfoTwo) TableName() string {
341 341
 	return "his_order_info"
342 342
 }
343
+
344
+type NewChargePatient struct {
345
+	ID             int64                `gorm:"column:id" json:"id" form:"id"`
346
+	UserOrgId      int64                `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
347
+	Name           string               `gorm:"column:name" json:"name" form:"name"`
348
+	Lapseto        int64                `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
349
+	Status         int64                `gorm:"column:status" json:"status" form:"status"`
350
+	HisChargeOrder []*NewHisChargeOrder `gorm:"ForeignKey:PatientID;AssociationForeignKey:ID" json:"orders"`
351
+}
352
+
353
+func (NewChargePatient) TableName() string {
354
+	return "xt_patients"
355
+}
356
+
357
+type NewChargeDetail struct {
358
+	Cnt               float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
359
+	Pric              float64 `gorm:"column:pric" json:"pric" form:"pric"`
360
+	PName             string  `gorm:"column:p_name" json:"p_name" form:"p_name"`
361
+	ItemName          string  `gorm:"column:item_name" json:"item_name" form:"item_name"`
362
+	Dose              string  `gorm:"column:dose" json:"dose" form:"dose"`
363
+	DoseUnit          string  `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
364
+	MinNumber         int64   `gorm:"column:min_number" json:"min_number" form:"min_number"`
365
+	MinUnit           string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
366
+	MaxUnit           string  `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
367
+	DetItemFeeSumamt  string  `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
368
+	PId               int64   `gorm:"column:p_id" json:"p_id" form:"p_id"`
369
+	AdviceId          int64   `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
370
+	ProjectId         int64   `gorm:"column:project_id" json:"project_id" form:"project_id"`
371
+	PType             string  `gorm:"column:p_type" json:"p_type" form:"p_type"`
372
+	SpecificationName string  `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
373
+	ItemId            int64   `gorm:"column:item_id" json:"item_id" form:"item_id"`
374
+}
375
+
376
+type NewHisChargeOrder struct {
377
+	ID                  int64                       `gorm:"column:id" json:"id" form:"id"`
378
+	UserOrgId           int64                       `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
379
+	HisPatientId        int64                       `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
380
+	SettleAccountsDate  int64                       `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
381
+	Status              int64                       `gorm:"column:status" json:"status" form:"status"`
382
+	Number              string                      `gorm:"column:number" json:"number" form:"number"`
383
+	OrderStatus         int64                       `gorm:"column:order_status" json:"order_status" form:"order_status"`
384
+	MdtrtId             string                      `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
385
+	PatientId           int64                       `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
386
+	HifesPay            float64                     `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
387
+	MafPay              float64                     `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
388
+	FundPaySumamt       float64                     `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
389
+	AcctPay             float64                     `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
390
+	MedfeeSumamt        float64                     `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
391
+	HifpPay             float64                     `gorm:"column:hifp_pay" json:"hifp_pay" form:"hifp_pay"`
392
+	HifmiPay            float64                     `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
393
+	IsUploadDiagnose    int64                       `gorm:"column:is_upload_diagnose" json:"is_upload_diagnose" form:"is_upload_diagnose"`
394
+	IsUploadOrderInfo   int64                       `gorm:"column:is_upload_order_info" json:"is_upload_order_info" form:"is_upload_order_info"`
395
+	IsUploadSuccess     int64                       `gorm:"column:is_upload_success" json:"is_upload_success" form:"is_upload_success"`
396
+	SetlTime            string                      `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
397
+	PsnCashPay          float64                     `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
398
+	IsMedicineInsurance int64                       `gorm:"column:is_medicine_insurance" json:"is_medicine_insurance" form:"is_medicine_insurance"`
399
+	HisChargeOrderInfo  []*NewHisChargeOrderInfoTwo `gorm:"ForeignKey:OrderNumber;AssociationForeignKey:Number" json:"order_info"`
400
+}
401
+
402
+func (NewHisChargeOrder) TableName() string {
403
+	return "his_order"
404
+}
405
+
406
+type NewHisChargeOrderInfoTwo struct {
407
+	ID                           int64                        `gorm:"column:id" json:"id" form:"id"`
408
+	OrderNumber                  string                       `gorm:"column:order_number" json:"order_number" form:"order_number"`
409
+	AdviceId                     int64                        `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
410
+	DetItemFeeSumamt             float64                      `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
411
+	Cnt                          float64                      `gorm:"column:cnt" json:"cnt" form:"cnt"`
412
+	Pric                         float64                      `gorm:"column:pric" json:"pric" form:"pric"`
413
+	MedChrgitmType               string                       `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
414
+	Status                       int64                        `gorm:"column:status" json:"status" form:"status"`
415
+	ChldMedcFlag                 string                       `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
416
+	ChrgitmLv                    string                       `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
417
+	UserOrgId                    int64                        `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
418
+	ProjectId                    int64                        `gorm:"column:project_id" json:"project_id" form:"project_id"`
419
+	Type                         int64                        `gorm:"column:type" json:"type" form:"type"`
420
+	FulamtOwnpayAmt              float64                      `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
421
+	OverlmtAmt                   float64                      `gorm:"column:overlmt_amt" json:"overlmt_amt" form:"overlmt_amt"`
422
+	PreselfpayAmt                float64                      `gorm:"column:preselfpay_amt" json:"preselfpay_amt" form:"preselfpay_amt"`
423
+	PricUplmtAmt                 float64                      `gorm:"column:pric_uplmt_amt" json:"pric_uplmt_amt" form:"pric_uplmt_amt"`
424
+	HisChargePrescriptionProject HisChargePrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
425
+	HisChargeDoctorAdviceInfo    NewHisChargeDoctorAdviceInfo `gorm:"ForeignKey:AdviceId;AssociationForeignKey:ID" json:"advice"`
426
+}
427
+
428
+func (NewHisChargeOrderInfoTwo) TableName() string {
429
+	return "his_order_info"
430
+}
431
+
432
+type NewDrug struct {
433
+	ID           int64   `gorm:"column:id" json:"id" form:"id"`
434
+	DrugName     string  `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
435
+	MaxUnit      string  `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
436
+	MinNumber    int64   `gorm:"column:min_number" json:"min_number" form:"min_number"`
437
+	MinUnit      string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
438
+	Dose         string  `gorm:"column:dose" json:"dose" form:"dose"`
439
+	DoseUnit     string  `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
440
+	RetailPrice  float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
441
+	DrugDose     float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
442
+	DrugDoseUnit int64   `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
443
+}
444
+
445
+func (NewDrug) TableName() string {
446
+	return "xt_base_drug"
447
+}
448
+
449
+type NewHisChargeDoctorAdviceInfo struct {
450
+	ID                    int64   `gorm:"column:id" json:"id" form:"id"`
451
+	UserOrgId             int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
452
+	PatientId             int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
453
+	AdviceName            string  `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
454
+	PrescribingNumberUnit string  `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
455
+	Status                int64   `gorm:"column:status" json:"status" form:"status"`
456
+	DrugId                int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
457
+	Remark                string  `gorm:"column:remark" json:"remark" form:"remark"`
458
+	AdviceDate            int64   `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
459
+	Drug                  NewDrug `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" json:"drug"`
460
+	IsMedicine            int64   `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
461
+	ExecutionFrequencyId  int64   `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
462
+	IsSelfDrug            int64   `gorm:"column:is_self_drug" json:"is_self_drug" form:"is_self_drug"`
463
+}
464
+
465
+func (NewHisChargeDoctorAdviceInfo) TableName() string {
466
+	return "his_doctor_advice_info"
467
+}

+ 145 - 1
service/his_charge_service.go View File

@@ -6,7 +6,7 @@ import (
6 6
 	"time"
7 7
 )
8 8
 
9
-func GetAllPatientChargeDetails(org_id int64, start_time int64, end_time int64, keyword string, item_type int64) (patients []*models.ChargePatient, err error) {
9
+func GetAllPatientChargeDetails(org_id int64, start_time int64, end_time int64, keyword string, item_type int64) (patients []*models.NewChargePatient, err error) {
10 10
 	if len(keyword) == 0 {
11 11
 		switch item_type {
12 12
 		case 0:
@@ -152,6 +152,150 @@ func GetAllPatientChargeDetails(org_id int64, start_time int64, end_time int64,
152 152
 	return
153 153
 }
154 154
 
155
+func GetNewAllPatientDrugChargeDetails(org_id int64, start_time_str string, end_time_str string, start_time int64, end_time int64, keyword string, item_type int64) (patients []*models.NewChargeDetail, err error) {
156
+	if len(keyword) == 0 {
157
+		switch item_type {
158
+		case 0:
159
+			err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
160
+				Joins("JOIN his_order o ON oi.order_number = o.number   and o.setl_time BETWEEN  ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
161
+				Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
162
+				Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
163
+				Joins(" JOIN  xt_base_drug drug on  a.drug_id = drug.id").
164
+				Where("oi.advice_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ?  and oi.`upload_date` <= ?   and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
165
+			break
166
+		case 1:
167
+			err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
168
+				Joins("JOIN his_order o ON oi.order_number = o.number   and o.setl_time BETWEEN  ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
169
+				Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
170
+				Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
171
+				Joins(" JOIN  xt_base_drug drug on  a.drug_id = drug.id").
172
+				Where("oi.advice_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ?  and oi.`upload_date` <= ?   and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
173
+			break
174
+
175
+		}
176
+
177
+	} else {
178
+		keyword := "%" + keyword + "%"
179
+		switch item_type {
180
+		case 0:
181
+			err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
182
+				Joins("JOIN his_order o ON oi.order_number = o.number   and o.setl_time BETWEEN  ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
183
+				Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
184
+				Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
185
+				Joins(" JOIN  xt_base_drug drug on  a.drug_id = drug.id").
186
+				Where("oi.advice_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ?  and oi.`upload_date` <= ?   and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
187
+
188
+			break
189
+		case 1:
190
+			err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
191
+				Joins("JOIN his_order o ON oi.order_number = o.number   and o.setl_time BETWEEN  ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
192
+				Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
193
+				Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
194
+				Joins(" JOIN  xt_base_drug drug on  a.drug_id = drug.id").
195
+				Where("oi.advice_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ?  and oi.`upload_date` <= ?   and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
196
+
197
+			break
198
+
199
+		}
200
+
201
+	}
202
+
203
+	return
204
+}
205
+func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str string, end_time_str string, start_time int64, end_time int64, keyword string, item_type int64) (patients []*models.NewChargeDetail, err error) {
206
+	if len(keyword) == 0 {
207
+		switch item_type {
208
+		case 0:
209
+			err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
210
+				Joins("JOIN his_order o ON oi.order_number = o.number   and o.setl_time BETWEEN  ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
211
+				Joins(" JOIN his_prescription_project p ON oi.project_id = p.id ").
212
+				Joins(" join xt_his_project project on  p.project_id = project.id").
213
+				Joins(" join  xt_good_information good on  p.project_id = good.id").
214
+				Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
215
+				Where("oi.project_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ?  and oi.`upload_date` <= ?   and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
216
+
217
+			//err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1  AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
218
+			//	return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
219
+			//		Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
220
+			//			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").
221
+			//				Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
222
+			//					return db.Preload("Drug", "status = 1").Where("status = 1")
223
+			//				}).Preload("HisChargePrescriptionProject", func(db *gorm.DB) *gorm.DB {
224
+			//				return db.Select("id,project_id,user_org_id,status,patient_id,record_date,count,type").Preload("HisChargeProject", func(db *gorm.DB) *gorm.DB {
225
+			//					return db.Select("id,project_name,unit").Where("status = 1 ")
226
+			//				}).Preload("HisChargeGoodInfo", func(db *gorm.DB) *gorm.DB {
227
+			//					return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
228
+			//				}).Where("status = 1 ")
229
+			//			}).Where("status = 1")
230
+			//		}).Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
231
+			//}).Where("p.status = 1  AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
232
+
233
+			break
234
+		case 2:
235
+			err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
236
+				Joins("JOIN his_order o ON oi.order_number = o.number   and o.setl_time BETWEEN  ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
237
+				Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
238
+				Joins(" join xt_his_project project on  p.project_id = project.id").
239
+				Joins(" join  xt_good_information good on  p.project_id = good.id").
240
+				Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
241
+				Where("oi.project_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ?  and oi.`upload_date` <= ?   and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
242
+
243
+			break
244
+		case 3:
245
+			err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
246
+				Joins("JOIN his_order o ON oi.order_number = o.number   and o.setl_time BETWEEN  ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
247
+				Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 3").
248
+				Joins(" join xt_his_project project on  p.project_id = project.id").
249
+				Joins(" join  xt_good_information good on  p.project_id = good.id").
250
+				Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
251
+				Where("oi.project_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ?  and oi.`upload_date` <= ?   and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
252
+
253
+			break
254
+
255
+		}
256
+
257
+	} else {
258
+		keyword := "%" + keyword + "%"
259
+		switch item_type {
260
+		case 0:
261
+			err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
262
+				Joins("JOIN his_order o ON oi.order_number = o.number   and o.setl_time BETWEEN  ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
263
+				Joins(" JOIN his_prescription_project p ON oi.project_id = p.id ").
264
+				Joins(" join xt_his_project project on  p.project_id = project.id").
265
+				Joins(" join  xt_good_information good on  p.project_id = good.id").
266
+				Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
267
+				Where("oi.project_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ?  and oi.`upload_date` <= ?   and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
268
+
269
+			break
270
+
271
+		case 2:
272
+			err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
273
+				Joins("JOIN his_order o ON oi.order_number = o.number   and o.setl_time BETWEEN  ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
274
+				Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
275
+				Joins(" join xt_his_project project on  p.project_id = project.id").
276
+				Joins(" join  xt_good_information good on  p.project_id = good.id").
277
+				Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
278
+				Where("oi.project_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ?  and oi.`upload_date` <= ?   and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
279
+
280
+			break
281
+		case 3:
282
+			err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
283
+				Joins("JOIN his_order o ON oi.order_number = o.number   and o.setl_time BETWEEN  ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
284
+				Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 3").
285
+				Joins(" join xt_his_project project on  p.project_id = project.id").
286
+				Joins(" join  xt_good_information good on  p.project_id = good.id").
287
+				Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
288
+				Where("oi.project_id > 0 and oi.user_org_id = ? and oi.`upload_date` >= ?  and oi.`upload_date` <= ?   and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
289
+
290
+			break
291
+
292
+		}
293
+
294
+	}
295
+
296
+	return
297
+}
298
+
155 299
 func GetAllPatientChargeSettle(org_id int64, start_time int64, end_time int64, keyword string, item_type int64) (patients []*models.SettlePatient, err error) {
156 300
 	if len(keyword) == 0 {
157 301
 		switch item_type {

+ 18 - 0
service/schedule_service.go View File

@@ -1769,3 +1769,21 @@ func GetLastSchedule(patient_id int64, user_org_id int64) (models.XtSchedule, er
1769 1769
 	err := XTReadDB().Where("patient_id = ? and status =1 and user_org_id = ?", patient_id, user_org_id).Find(&schedule).Error
1770 1770
 	return schedule, err
1771 1771
 }
1772
+
1773
+func UpdateRepeatSchStatus(user_org_id int64, schedule_date int64) {
1774
+	var schedules []models.XtSchedule
1775
+	// Find duplicate records based on patient_id, schedule_date, and user_org_id
1776
+	XTReadDB().Where("user_org_id = ? AND schedule_date = ? AND status = ?", user_org_id, schedule_date, 1).
1777
+		Group("patient_id, schedule_date").
1778
+		Having("COUNT(*) > 1").
1779
+		Select("patient_id, schedule_date, MAX(id) as max_id").
1780
+		Find(&schedules)
1781
+
1782
+	for _, schedule := range schedules {
1783
+		// Update records with status = 0 where id is less than max_id
1784
+		XTReadDB().Model(&models.XtSchedule{}).
1785
+			Where("patient_id = ? AND schedule_date = ? AND id < ?", schedule.PatientId, schedule.ScheduleDate, schedule.MaxId).
1786
+			Update("status", 0)
1787
+	}
1788
+
1789
+}