Browse Source

医保对接

csx 2 years ago
parent
commit
51cd440955

+ 126 - 0
controllers/his_api_controller.go View File

@@ -5211,9 +5211,52 @@ func (c *HisApiController) GetUploadInfo() {
5211 5211
 			}
5212 5212
 		}
5213 5213
 		if err == nil {
5214
+			houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
5215
+			var goods []*models.DialysisBeforePrepareGoods
5216
+			var newGoods []*models.NewDialysisBeforePrepareGoods
5217
+			var infos []*models.HisDoctorAdviceInfo
5218
+
5219
+			for _, info := range prescriptions {
5220
+				if info.Type == 1 {
5221
+					infos = append(infos, info.HisDoctorAdviceInfo...)
5222
+				}
5223
+				if info.Type == 2 {
5224
+					for _, sumItem := range info.HisPrescriptionProject {
5225
+						if sumItem.Type == 3 {
5226
+							var good models.DialysisBeforePrepareGoods
5227
+							var newGood models.NewDialysisBeforePrepareGoods
5228
+							good.GoodId = sumItem.GoodInfo.ID
5229
+							good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
5230
+							count, _ := strconv.Atoi(sumItem.Count)
5231
+							good.Count = int64(count)
5232
+							good.StorehouseId = houseConfig.StorehouseOutInfo
5233
+							good.ProjectId = sumItem.ID
5234
+							goods = append(goods, &good)
5235
+
5236
+							newGood.GoodId = sumItem.GoodInfo.ID
5237
+							newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
5238
+							count2, _ := strconv.Atoi(sumItem.Count)
5239
+							newGood.Count = int64(count2)
5240
+							newGood.StorehouseId = houseConfig.StorehouseOutInfo
5241
+							newGood.ProjectId = sumItem.ID
5242
+							newGoods = append(newGoods, &newGood)
5243
+						}
5244
+
5245
+					}
5246
+
5247
+				}
5248
+			}
5249
+			for _, item := range infos {
5250
+				service.HisDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item)
5251
+				//service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
5252
+
5253
+			}
5254
+			service.ConsumablesDeliveryTotal(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, goods, newGoods, adminUser.AdminUser.Id)
5255
+
5214 5256
 			c.ServeSuccessJSON(map[string]interface{}{
5215 5257
 				"msg": "结算成功",
5216 5258
 			})
5259
+
5217 5260
 		}
5218 5261
 	} else {
5219 5262
 		if tempOrder.IsPre > 0 {
@@ -5241,6 +5284,48 @@ func (c *HisApiController) GetUploadInfo() {
5241 5284
 				return
5242 5285
 			}
5243 5286
 			if err == nil {
5287
+
5288
+				houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
5289
+				var goods []*models.DialysisBeforePrepareGoods
5290
+				var newGoods []*models.NewDialysisBeforePrepareGoods
5291
+				var infos []*models.HisDoctorAdviceInfo
5292
+
5293
+				for _, info := range prescriptions {
5294
+					if info.Type == 1 {
5295
+						infos = append(infos, info.HisDoctorAdviceInfo...)
5296
+					}
5297
+					if info.Type == 2 {
5298
+						for _, sumItem := range info.HisPrescriptionProject {
5299
+							if sumItem.Type == 3 {
5300
+								var good models.DialysisBeforePrepareGoods
5301
+								var newGood models.NewDialysisBeforePrepareGoods
5302
+								good.GoodId = sumItem.GoodInfo.ID
5303
+								good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
5304
+								count, _ := strconv.Atoi(sumItem.Count)
5305
+								good.Count = int64(count)
5306
+								good.StorehouseId = houseConfig.StorehouseOutInfo
5307
+								good.ProjectId = sumItem.ID
5308
+								goods = append(goods, &good)
5309
+
5310
+								newGood.GoodId = sumItem.GoodInfo.ID
5311
+								newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
5312
+								count2, _ := strconv.Atoi(sumItem.Count)
5313
+								newGood.Count = int64(count2)
5314
+								newGood.StorehouseId = houseConfig.StorehouseOutInfo
5315
+								newGood.ProjectId = sumItem.ID
5316
+								newGoods = append(newGoods, &newGood)
5317
+							}
5318
+
5319
+						}
5320
+
5321
+					}
5322
+				}
5323
+				for _, item := range infos {
5324
+					service.HisDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item)
5325
+
5326
+				}
5327
+				service.ConsumablesDeliveryTotal(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, goods, newGoods, adminUser.AdminUser.Id)
5328
+
5244 5329
 				c.ServeSuccessJSON(map[string]interface{}{
5245 5330
 					"msg": "结算成功",
5246 5331
 				})
@@ -5269,6 +5354,47 @@ func (c *HisApiController) Refund() {
5269 5354
 			return
5270 5355
 		}
5271 5356
 	}
5357
+
5358
+	if order.ID == 0 {
5359
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
5360
+		return
5361
+	}
5362
+	orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
5363
+	houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
5364
+	var goods []*models.DialysisBeforePrepareGoods
5365
+	var newGoods []*models.NewDialysisBeforePrepareGoods
5366
+	var infos []*models.HisDoctorAdviceInfo
5367
+
5368
+	for _, info := range orders {
5369
+		if info.AdviceId > 0 && info.ProjectId == 0 {
5370
+			infos = append(infos, &info.HisDoctorAdviceInfo)
5371
+		}
5372
+		if info.ProjectId > 0 && info.AdviceId == 0 {
5373
+			if info.HisPrescriptionProject.Type == 3 {
5374
+				var good models.DialysisBeforePrepareGoods
5375
+				var newGood models.NewDialysisBeforePrepareGoods
5376
+				good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
5377
+				good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
5378
+				count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
5379
+				good.Count = int64(count)
5380
+				good.StorehouseId = houseConfig.StorehouseOutInfo
5381
+				good.ProjectId = info.HisPrescriptionProject.ID
5382
+				goods = append(goods, &good)
5383
+
5384
+				newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
5385
+				newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
5386
+				count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
5387
+				newGood.Count = int64(count2)
5388
+				newGood.StorehouseId = houseConfig.StorehouseOutInfo
5389
+				newGood.ProjectId = info.HisPrescriptionProject.ID
5390
+				newGoods = append(newGoods, &newGood)
5391
+			}
5392
+		}
5393
+	}
5394
+	for _, item := range infos {
5395
+		service.DrugAutoAddCancelInfo(item, order.Creator)
5396
+	}
5397
+
5272 5398
 	c.ServeSuccessJSON(map[string]interface{}{
5273 5399
 		"msg": "退费成功",
5274 5400
 	})

+ 95 - 0
controllers/stock_in_api_controller.go View File

@@ -147,6 +147,101 @@ func StockManagerApiRegistRouters() {
147 147
 	beego.Router("/api/stock/checkstockwarehouseinfo", &StockManagerApiController{}, "Get:CheckStockWarehouseInfo")
148 148
 	beego.Router("/api/stock/checkreturnstockwarehouseinfo", &StockManagerApiController{}, "Get:CheckReturnStockWarehouseInfo")
149 149
 	beego.Router("/api/stock/getprintlist", &StockManagerApiController{}, "Get:GetPrintList")
150
+
151
+	//结算成功后调用操作库存相关接口
152
+	beego.Router("/api/settle/stock", &StockManagerApiController{}, "Get:HandleSettleStock")
153
+	beego.Router("/api/settle/cancelstock", &StockManagerApiController{}, "Get:HandleRefundStock")
154
+
155
+}
156
+func (c *StockManagerApiController) HandleRefundStock() {
157
+	order_id, _ := c.GetInt64("order_id", 0)
158
+	order, _ := service.GetHisOrderByIDThree(order_id)
159
+	if order.ID == 0 {
160
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
161
+		return
162
+	}
163
+	orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
164
+	houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
165
+	var goods []*models.DialysisBeforePrepareGoods
166
+	var newGoods []*models.NewDialysisBeforePrepareGoods
167
+	var infos []*models.HisDoctorAdviceInfo
168
+
169
+	for _, info := range orders {
170
+		if info.AdviceId > 0 && info.ProjectId == 0 {
171
+			infos = append(infos, &info.HisDoctorAdviceInfo)
172
+		}
173
+		if info.ProjectId > 0 && info.AdviceId == 0 {
174
+			if info.HisPrescriptionProject.Type == 3 {
175
+				var good models.DialysisBeforePrepareGoods
176
+				var newGood models.NewDialysisBeforePrepareGoods
177
+				good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
178
+				good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
179
+				count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
180
+				good.Count = int64(count)
181
+				good.StorehouseId = houseConfig.StorehouseOutInfo
182
+				good.ProjectId = info.HisPrescriptionProject.ID
183
+				goods = append(goods, &good)
184
+
185
+				newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
186
+				newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
187
+				count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
188
+				newGood.Count = int64(count2)
189
+				newGood.StorehouseId = houseConfig.StorehouseOutInfo
190
+				newGood.ProjectId = info.HisPrescriptionProject.ID
191
+				newGoods = append(newGoods, &newGood)
192
+			}
193
+		}
194
+	}
195
+	for _, item := range infos {
196
+		//service.HisDrugsDelivery(item.UserOrgId, order.Creator, item)
197
+		service.DrugAutoAddCancelInfo(item, order.Creator)
198
+
199
+	}
200
+
201
+}
202
+func (c *StockManagerApiController) HandleSettleStock() {
203
+	order_id, _ := c.GetInt64("order_id", 0)
204
+	order, _ := service.GetHisOrderByID(order_id)
205
+	if order.ID == 0 {
206
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
207
+		return
208
+	}
209
+	orders, _ := service.GetHisOrderDetailByNumberTwo(order.Number, order.UserOrgId)
210
+	houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
211
+	var goods []*models.DialysisBeforePrepareGoods
212
+	var newGoods []*models.NewDialysisBeforePrepareGoods
213
+	var infos []*models.HisDoctorAdviceInfo
214
+
215
+	for _, info := range orders {
216
+		if info.AdviceId > 0 && info.ProjectId == 0 {
217
+			infos = append(infos, &info.HisDoctorAdviceInfo)
218
+		}
219
+		if info.ProjectId > 0 && info.AdviceId == 0 {
220
+			if info.HisPrescriptionProject.Type == 3 {
221
+				var good models.DialysisBeforePrepareGoods
222
+				var newGood models.NewDialysisBeforePrepareGoods
223
+				good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
224
+				good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
225
+				count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
226
+				good.Count = int64(count)
227
+				good.StorehouseId = houseConfig.StorehouseOutInfo
228
+				good.ProjectId = info.HisPrescriptionProject.ID
229
+				goods = append(goods, &good)
230
+
231
+				newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
232
+				newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
233
+				count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
234
+				newGood.Count = int64(count2)
235
+				newGood.StorehouseId = houseConfig.StorehouseOutInfo
236
+				newGood.ProjectId = info.HisPrescriptionProject.ID
237
+				newGoods = append(newGoods, &newGood)
238
+			}
239
+		}
240
+	}
241
+	service.ConsumablesDeliveryTotal(order.UserOrgId, order.PatientId, order.SettleAccountsDate, goods, newGoods, order.Creator)
242
+	for _, item := range infos {
243
+		service.HisDrugsDelivery(item.UserOrgId, order.Creator, item)
244
+	}
150 245
 }
151 246
 
152 247
 func (c *StockManagerApiController) CreateWarehouse() {

+ 1 - 1
service/his_config_service.go View File

@@ -864,7 +864,7 @@ func GetDataConfig(orgid int64) (dataconfig []*models.DictDataconfig, err error)
864 864
 //翻译项目中的组
865 865
 func TranslateZu(sc, orgid int64, types string) (s string, err error) {
866 866
 	var dataconfig []*models.DictDataconfig
867
-	tmp := "select * from xt_drug_data_config where parent_id in (select id from xt_drug_data_config where name = \"" + types + "\" and parent_id = 0) and value = " + config.ToString(sc) + " and status = 1 and (org_id = " + config.ToString(orgid) + " or org_id = 0)"
867
+	tmp := "select * from xt_drug_data_config where parent_id in (select id from xt_d·rug_data_config where name = \"" + types + "\" and parent_id = 0) and value = " + config.ToString(sc) + " and status = 1 and (org_id = " + config.ToString(orgid) + " or org_id = 0)"
868 868
 
869 869
 	err = XTReadDB().Raw(tmp).Scan(&dataconfig).Error
870 870
 	if err != nil {

+ 5 - 0
service/his_hospital_service.go View File

@@ -560,3 +560,8 @@ func GetPsnByPatientId(patient_id int64) (psn models.HisPsn, err error) {
560 560
 	err = readDb.Model(&models.HisPsn{}).Where("patient_id = ?", patient_id).Last(&psn).Error
561 561
 	return
562 562
 }
563
+
564
+func GetHisPrescriptionProjectByIDTwo(id int64) (projects models.HisPrescriptionProject, err error) {
565
+	err = readDb.Model(&models.HisPrescriptionProject{}).Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("id = ? AND status = 1", id).First(&projects).Error
566
+	return
567
+}

+ 55 - 5
service/his_service.go View File

@@ -44,11 +44,13 @@ func (HisPatient) TableName() string {
44 44
 }
45 45
 
46 46
 type Schedule struct {
47
-	ID           int64 `gorm:"column:id" json:"id" form:"id"`
48
-	UserOrgId    int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
49
-	PatientId    int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
50
-	Status       int64 `gorm:"column:status" json:"status" form:"status"`
51
-	ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
47
+	ID                  int64  `gorm:"column:id" json:"id" form:"id"`
48
+	UserOrgId           int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
49
+	PatientId           int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
50
+	Status              int64  `gorm:"column:status" json:"status" form:"status"`
51
+	ScheduleDate        int64  `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
52
+	ModeId              int64  `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
53
+	DialysisMachineName string `gorm:"column:dialysis_machine_name" json:"dialysis_machine_name" form:"dialysis_machine_name"`
52 54
 }
53 55
 
54 56
 func (Schedule) TableName() string {
@@ -2532,3 +2534,51 @@ func UpDateOrderTwo(order *models.HisOrder) (err error) {
2532 2534
 	err = writeDb.Save(&order).Error
2533 2535
 	return
2534 2536
 }
2537
+
2538
+type HisOrderInfoTwo struct {
2539
+	ID                     int64                      `gorm:"column:id" json:"id" form:"id"`
2540
+	OrderNumber            string                     `gorm:"column:order_number" json:"order_number" form:"order_number"`
2541
+	UploadDate             int64                      `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
2542
+	AdviceId               int64                      `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
2543
+	DetItemFeeSumamt       float64                    `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
2544
+	Cnt                    float64                    `gorm:"column:cnt" json:"cnt" form:"cnt"`
2545
+	Pric                   float64                    `gorm:"column:pric" json:"pric" form:"pric"`
2546
+	PatientId              int64                      `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
2547
+	MedChrgitmType         string                     `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
2548
+	Status                 int64                      `gorm:"column:status" json:"status" form:"status"`
2549
+	FeedetlSn              string                     `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
2550
+	ChldMedcFlag           string                     `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
2551
+	ChrgitmLv              string                     `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
2552
+	UserOrgId              int64                      `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
2553
+	ProjectId              int64                      `gorm:"column:project_id" json:"project_id" form:"project_id"`
2554
+	ItemId                 int64                      `gorm:"column:item_id" json:"item_id" form:"item_id"`
2555
+	FulamtOwnpayAmt        float64                    `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
2556
+	HisPrescriptionProject HisPrescriptionProject     `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
2557
+	HisDoctorAdviceInfo    models.HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
2558
+}
2559
+
2560
+func (HisOrderInfoTwo) TableName() string {
2561
+	return "his_order_info"
2562
+}
2563
+func GetHisOrderDetailByNumberTwo(order_number string, org_id int64) (order []*HisOrderInfoTwo, err error) {
2564
+	err = readDb.Model(&HisOrderInfoTwo{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
2565
+		return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisProject", "status = 1 AND user_org_id = ?", org_id).Preload("VMGoodInfo", "status = 1 AND org_id = ?", org_id)
2566
+	}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
2567
+		return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
2568
+	}).Find(&order).Error
2569
+	return
2570
+}
2571
+
2572
+func GetHisOrderDetailByNumberThree(order_number string, org_id int64) (order []*HisOrderInfoTwo, err error) {
2573
+	err = readDb.Model(&HisOrderInfoTwo{}).Where("order_number = ?", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
2574
+		return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisProject", "status = 1 AND user_org_id = ?", org_id).Preload("VMGoodInfo", "status = 1 AND org_id = ?", org_id)
2575
+	}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
2576
+		return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
2577
+	}).Find(&order).Error
2578
+	return
2579
+}
2580
+
2581
+func GetHisOrderByIDThree(order_id int64) (order models.HisOrder, err error) {
2582
+	err = readDb.Model(&models.HisOrder{}).Where("id = ?", order_id).First(&order).Error
2583
+	return
2584
+}

+ 1 - 1
service/his_summary_service.go View File

@@ -9,7 +9,7 @@ import (
9 9
 func GetHisSummaryDetailList(keyword string, item_type int64, patient_id int64, org_id int64, start_time int64, end_time int64) (patients []*models.ChargePatient, err error) {
10 10
 
11 11
 	err = XTReadDB().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 and orders.patient_id = ?", start_time, end_time, org_id, patient_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
12
-		return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id,psn_cash_pay,acct_pay,fund_pay_sumamt,is_medicine_insurance,medfee_sumamt").
12
+		return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id,psn_cash_pay,acct_pay,fund_pay_sumamt,is_medicine_insurance,medfee_sumamt,maf_pay,hifes_pay").
13 13
 			Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
14 14
 				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").Where("status = 1").
15 15
 					Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {