Ver código fonte

医保对接

csx 3 anos atrás
pai
commit
75dc44d678

+ 379 - 296
controllers/his_api_controller.go Ver arquivo

@@ -435,147 +435,150 @@ func (c *HisApiController) GetHisPatientInfo() {
435 435
 		prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
436 436
 		last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
437 437
 	}
438
-
439 438
 	sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
440
-	if sch.ID > 0 {
441
-		var week string
442
-		t := time.Now()
443
-		switch t.Weekday().String() {
444
-		case "Monday":
445
-			week = "周一"
446
-			break
447
-		case "Tuesday":
448
-			week = "周二"
449
-
450
-			break
451
-		case "Wednesday":
452
-			week = "周三"
453
-
454
-			break
455
-		case "Thursday":
456
-			week = "周四"
457
-
458
-			break
459
-		case "Friday":
460
-			week = "周五"
461
-
462
-			break
463
-		case "Saturday":
464
-			week = "周六"
465
-
466
-			break
467
-		case "Sunday":
468
-			week = "周日"
469
-
470
-			break
471 439
 
472
-		}
440
+	if admin.CurrentOrgId != 10215 {
473 441
 
474
-		mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
475
-		temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
476
-
477
-		//根据推送频率组装新的数组
478
-		for _, item := range temp_sch_prescriptions {
479
-			var cus CustomTemplate
480
-			cus.ID = item.ID
481
-			cus.UserOrgId = item.UserOrgId
482
-			cus.PatientId = item.PatientId
483
-			cus.MedType = item.MedType
484
-			cus.RecordDate = item.RecordDate
485
-			cus.Type = item.Type
486
-			cus.PType = item.PType
487
-			for _, subItem := range item.HisPrescriptionAdviceTemplate {
488
-				if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
489
-					if subItem.FrequencyType == 1 { //每次必推
490
-						cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
491
-					}
442
+		if sch.ID > 0 {
443
+			var week string
444
+			t := time.Now()
445
+			switch t.Weekday().String() {
446
+			case "Monday":
447
+				week = "周一"
448
+				break
449
+			case "Tuesday":
450
+				week = "周二"
492 451
 
493
-					if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
494
-						cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
495
-					}
452
+				break
453
+			case "Wednesday":
454
+				week = "周三"
496 455
 
497
-					if subItem.FrequencyType == 2 { //按照天数频率
498
-						p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
499
-						now := p.Unix()
500
-						dayStr := strconv.FormatInt(subItem.DayCount, 10)
501
-						dayStr2 := "-" + dayStr
502
-						count, _ := strconv.ParseInt(dayStr2, 10, 64)
503
-						oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
504
-						advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
505
-						if len(advices) == 0 {
506
-							cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
507
-						}
508
-					}
509
-				}
510
-			}
456
+				break
457
+			case "Thursday":
458
+				week = "周四"
511 459
 
512
-			for _, subItem := range item.HisPrescriptionProjectTemplate {
460
+				break
461
+			case "Friday":
462
+				week = "周五"
463
+
464
+				break
465
+			case "Saturday":
466
+				week = "周六"
467
+
468
+				break
469
+			case "Sunday":
470
+				week = "周日"
471
+
472
+				break
473
+
474
+			}
513 475
 
514
-				if subItem.Type == 2 {
515
-					if subItem.XtHisProject.MedicalStatus != 1 {
516
-						if subItem.FrequencyType == 1 {
517
-							cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
476
+			mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
477
+			temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
478
+
479
+			//根据推送频率组装新的数组
480
+			for _, item := range temp_sch_prescriptions {
481
+				var cus CustomTemplate
482
+				cus.ID = item.ID
483
+				cus.UserOrgId = item.UserOrgId
484
+				cus.PatientId = item.PatientId
485
+				cus.MedType = item.MedType
486
+				cus.RecordDate = item.RecordDate
487
+				cus.Type = item.Type
488
+				cus.PType = item.PType
489
+				for _, subItem := range item.HisPrescriptionAdviceTemplate {
490
+					if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
491
+						if subItem.FrequencyType == 1 { //每次必推
492
+							cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
518 493
 						}
519 494
 
520
-						if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
521
-							cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
495
+						if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
496
+							cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
522 497
 						}
523 498
 
524
-						if subItem.FrequencyType == 2 {
499
+						if subItem.FrequencyType == 2 { //按照天数频率
525 500
 							p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
526 501
 							now := p.Unix()
527 502
 							dayStr := strconv.FormatInt(subItem.DayCount, 10)
528 503
 							dayStr2 := "-" + dayStr
529 504
 							count, _ := strconv.ParseInt(dayStr2, 10, 64)
530 505
 							oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
531
-							projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
532
-							if len(projects) == 0 {
533
-								cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
506
+							advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
507
+							if len(advices) == 0 {
508
+								cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
534 509
 							}
535 510
 						}
536
-
537 511
 					}
512
+				}
538 513
 
539
-				} else if subItem.Type == 3 {
540
-					if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
541
-						if subItem.FrequencyType == 1 {
542
-							cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
543
-						}
514
+				for _, subItem := range item.HisPrescriptionProjectTemplate {
515
+
516
+					if subItem.Type == 2 {
517
+						if subItem.XtHisProject.MedicalStatus != 1 {
518
+							if subItem.FrequencyType == 1 {
519
+								cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
520
+							}
521
+
522
+							if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
523
+								cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
524
+							}
525
+
526
+							if subItem.FrequencyType == 2 {
527
+								p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
528
+								now := p.Unix()
529
+								dayStr := strconv.FormatInt(subItem.DayCount, 10)
530
+								dayStr2 := "-" + dayStr
531
+								count, _ := strconv.ParseInt(dayStr2, 10, 64)
532
+								oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
533
+								projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
534
+								if len(projects) == 0 {
535
+									cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
536
+								}
537
+							}
544 538
 
545
-						if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
546
-							cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
547 539
 						}
548 540
 
549
-						if subItem.FrequencyType == 2 {
550
-							p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
551
-							now := p.Unix()
552
-							dayStr := strconv.FormatInt(subItem.DayCount, 10)
553
-							dayStr2 := "-" + dayStr
554
-							count, _ := strconv.ParseInt(dayStr2, 10, 64)
555
-							oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
556
-							projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
557
-							if len(projects) == 0 {
541
+					} else if subItem.Type == 3 {
542
+						if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
543
+							if subItem.FrequencyType == 1 {
558 544
 								cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
559 545
 							}
546
+
547
+							if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
548
+								cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
549
+							}
550
+
551
+							if subItem.FrequencyType == 2 {
552
+								p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
553
+								now := p.Unix()
554
+								dayStr := strconv.FormatInt(subItem.DayCount, 10)
555
+								dayStr2 := "-" + dayStr
556
+								count, _ := strconv.ParseInt(dayStr2, 10, 64)
557
+								oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
558
+								projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
559
+								if len(projects) == 0 {
560
+									cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
561
+								}
562
+							}
560 563
 						}
564
+
561 565
 					}
562 566
 
563 567
 				}
564 568
 
565
-			}
569
+				sch_prescriptions = append(sch_prescriptions, cus)
566 570
 
567
-			sch_prescriptions = append(sch_prescriptions, cus)
571
+			}
568 572
 
569
-		}
573
+			for _, item := range sch_prescriptions {
574
+				if len(item.HisPrescriptionProjectTemplate) == 0 {
575
+					item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
576
+				}
577
+				if len(item.HisPrescriptionAdviceTemplate) == 0 {
578
+					item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
579
+				}
570 580
 
571
-		for _, item := range sch_prescriptions {
572
-			if len(item.HisPrescriptionProjectTemplate) == 0 {
573
-				item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
574 581
 			}
575
-			if len(item.HisPrescriptionAdviceTemplate) == 0 {
576
-				item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
577
-			}
578
-
579 582
 		}
580 583
 	}
581 584
 
@@ -817,7 +820,6 @@ func (c *HisApiController) CreateHisPrescription() {
817 820
 			}
818 821
 		}
819 822
 	}
820
-
821 823
 	if stockConfig.IsOpen == 1 {
822 824
 		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
823 825
 			prescriptions, _ := dataBody["prescriptions"].([]interface{})
@@ -876,176 +878,173 @@ func (c *HisApiController) CreateHisPrescription() {
876 878
 		}
877 879
 	}
878 880
 
879
-	ch := make(chan struct{})
880
-	count := 2 // count 表示活动的协程个数
881
-
882
-	go func() {
883
-		if drugStockConfig.IsOpen == 1 {
884
-			//校验库存总量
885
-			if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
886
-				prescriptions, _ := dataBody["prescriptions"].([]interface{})
887
-				if len(prescriptions) > 0 {
888
-					for _, item := range prescriptions {
889
-						items := item.(map[string]interface{})
890
-						if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
891
-							advices := items["advices"].([]interface{})
892
-							if len(advices) > 0 {
893
-								for _, advice := range advices {
894
-									var drug_id int64
895
-									var prescribingNumberUnit string
896
-									var prescribingNumber string
897
-									var adviceId int64
898
-									if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
899
-										drug_id = int64(advice.(map[string]interface{})["id"].(float64))
900
-									}
901
-									if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
902
-
903
-										prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
904
-
905
-									}
906
-
907
-									if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
908
-										prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
909
-									}
910
-
911
-									if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
912
-										adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
913
-									}
914
-
915
-									drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
916
-									if drug.ID == 0 {
917
-										c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
918
-										return
919
-									}
920
-
921
-									//查询药品的所有库存
922
-									list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId)
923
-									var total_count int64
924
-									for _, it := range list {
925
-										total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
926
-									}
927
-
928
-									//查询该药品是否存在开药记录
929
-									advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
930
-									//修改处方
931
-									if advicelist.ID > 0 {
932
-										var device_number int64
933
-										if advicelist.PrescribingNumberUnit == drug.MaxUnit {
934
-											prescribingNumber := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
935
-											prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
936
-											device_number = prescribingNumberInt * drug.MinNumber
937
-										}
938
-										if advicelist.PrescribingNumberUnit == drug.MinUnit {
939
-											prescribingNumber := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
940
-											prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
941
-											device_number = prescribingNumberInt
942
-										}
943
-
944
-										var sum_count int64
945
-										//判断是否做过修改
946
-										if prescribingNumberUnit == drug.MaxUnit {
947
-
948
-											prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
949
-
950
-											sum_count = prescribingNumberInt * drug.MinNumber
951
-										}
952
-										if prescribingNumberUnit == drug.MinUnit {
953
-											prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
954
-											sum_count = prescribingNumberInt
955
-										}
956
-										fmt.Println("原先药品记录", device_number)
957
-										fmt.Println("现在出库数量", sum_count)
958
-										if device_number != sum_count {
959
-
960
-											// 查询该药品最后一次出库记录
961
-											druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime)
962
-											//回退库存
963
-											if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
964
-												service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, druginfo.Count)
965
-											}
966
-											if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
967
-												service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, druginfo.Count)
968
-											}
969
-
970
-											if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
971
-												service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, druginfo.Count)
972
-											}
973
-
974
-											//删除记录
975
-											service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
976
-										}
977
-									}
978
-								}
979
-							}
980
-						}
981
-					}
982
-				}
983
-			}
984
-		}
985
-		ch <- struct{}{}
986
-	}()
987
-
988
-	go func() {
989
-		if stockConfig.IsOpen == 1 {
990
-			if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
991
-				prescriptions, _ := dataBody["prescriptions"].([]interface{})
992
-				if len(prescriptions) > 0 {
993
-					for _, item := range prescriptions {
994
-						items := item.(map[string]interface{})
995
-						if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
996
-							projects := items["project"].([]interface{})
997
-							if len(projects) > 0 {
998
-								for _, project := range projects {
999
-									var project_id int64
1000
-									var project_type int64
1001
-									var parsetotal int64
1002
-									if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
1003
-										project_id = int64(project.(map[string]interface{})["project_id"].(float64))
1004
-									}
1005
-									if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
1006
-										project_type = int64(project.(map[string]interface{})["type"].(float64))
1007
-									}
1008
-									if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
1009
-										total, _ := project.(map[string]interface{})["total"].(string)
1010
-										parsetotal, _ = strconv.ParseInt(total, 10, 64)
1011
-									}
1012
-									if project_type == 3 {
1013
-										//查找该耗材的出库记录
1014
-										goodWarehouseInfo, _ := service.GetAutoRecordByGoodId(project_id, patient_id, recordDateTime)
1015
-										//查询该患者耗材的历史数据
1016
-										ordProject, _ := service.GetHisProjectPrescriptionByPatientId(patient_id, recordDateTime)
1017
-										if goodWarehouseInfo.ID > 0 {
1018
-											//数量发生改变
1019
-											if parsetotal != goodWarehouseInfo.Count || len(ordProject) != len(projects) {
1020
-												//查找今日该患者已经出库的所有耗材
1021
-												goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
1022
-												for _, item := range goodList {
1023
-													//回退库存
1024
-													service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
1025
-													//删除记录
1026
-													service.DeleteAutoWarehouse(item.PatientId, item.SysRecordTime)
1027
-												}
1028
-											}
1029
-										}
1030
-									}
1031
-								}
1032
-							}
1033
-						}
1034
-					}
1035
-				}
1036
-			}
1037
-		}
1038
-		ch <- struct{}{}
1039
-	}()
1040
-
1041
-	for range ch {
1042
-		// 每次从ch中接收数据,表明一个活动的协程结束
1043
-		count--
1044
-		// 当所有活动的协程都结束时,关闭管道
1045
-		if count == 0 {
1046
-			close(ch)
1047
-		}
1048
-	}
881
+	//ch := make(chan struct{})
882
+	//count := 2 // count 表示活动的协程个数
883
+	//go func() {
884
+	//	if drugStockConfig.IsOpen == 1 {
885
+	//		//校验库存总量
886
+	//		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
887
+	//			prescriptions, _ := dataBody["prescriptions"].([]interface{})
888
+	//			if len(prescriptions) > 0 {
889
+	//				for _, item := range prescriptions {
890
+	//					items := item.(map[string]interface{})
891
+	//					if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
892
+	//						advices := items["advices"].([]interface{})
893
+	//						if len(advices) > 0 {
894
+	//							for _, advice := range advices {
895
+	//								var drug_id int64
896
+	//								var prescribingNumberUnit string
897
+	//								var prescribingNumber string
898
+	//								var adviceId int64
899
+	//								if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
900
+	//									drug_id = int64(advice.(map[string]interface{})["id"].(float64))
901
+	//								}
902
+	//								if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
903
+	//
904
+	//									prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
905
+	//
906
+	//								}
907
+	//
908
+	//								if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
909
+	//									prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
910
+	//								}
911
+	//
912
+	//								if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
913
+	//									adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
914
+	//								}
915
+	//
916
+	//								drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
917
+	//								if drug.ID == 0 {
918
+	//									c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
919
+	//									return
920
+	//								}
921
+	//
922
+	//								//查询药品的所有库存
923
+	//								list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId)
924
+	//								var total_count int64
925
+	//								for _, it := range list {
926
+	//									total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
927
+	//								}
928
+	//
929
+	//								//查询该药品是否存在开药记录
930
+	//								advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
931
+	//								//修改处方
932
+	//								if advicelist.ID > 0 {
933
+	//									var device_number int64
934
+	//									if advicelist.PrescribingNumberUnit == drug.MaxUnit {
935
+	//										prescribingNumber := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
936
+	//										prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
937
+	//										device_number = prescribingNumberInt * drug.MinNumber
938
+	//									}
939
+	//									if advicelist.PrescribingNumberUnit == drug.MinUnit {
940
+	//										prescribingNumber := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
941
+	//										prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
942
+	//										device_number = prescribingNumberInt
943
+	//									}
944
+	//
945
+	//									var sum_count int64
946
+	//									//判断是否做过修改
947
+	//									if prescribingNumberUnit == drug.MaxUnit {
948
+	//
949
+	//										prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
950
+	//
951
+	//										sum_count = prescribingNumberInt * drug.MinNumber
952
+	//									}
953
+	//									if prescribingNumberUnit == drug.MinUnit {
954
+	//										prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
955
+	//										sum_count = prescribingNumberInt
956
+	//									}
957
+	//									fmt.Println("原先药品记录", device_number)
958
+	//									fmt.Println("现在出库数量", sum_count)
959
+	//									if device_number != sum_count {
960
+	//
961
+	//										// 查询该药品最后一次出库记录
962
+	//										druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime)
963
+	//										//回退库存
964
+	//										if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
965
+	//											service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, druginfo.Count)
966
+	//										}
967
+	//										if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
968
+	//											service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, druginfo.Count)
969
+	//										}
970
+	//
971
+	//										if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
972
+	//											service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, druginfo.Count)
973
+	//										}
974
+	//
975
+	//										//删除记录
976
+	//										service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
977
+	//									}
978
+	//								}
979
+	//							}
980
+	//						}
981
+	//					}
982
+	//				}
983
+	//			}
984
+	//		}
985
+	//	}
986
+	//	ch <- struct{}{}
987
+	//}()
988
+	//go func() {
989
+	//	if stockConfig.IsOpen == 1 {
990
+	//		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
991
+	//			prescriptions, _ := dataBody["prescriptions"].([]interface{})
992
+	//			if len(prescriptions) > 0 {
993
+	//				for _, item := range prescriptions {
994
+	//					items := item.(map[string]interface{})
995
+	//					if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
996
+	//						projects := items["project"].([]interface{})
997
+	//						if len(projects) > 0 {
998
+	//							for _, project := range projects {
999
+	//								var project_id int64
1000
+	//								var project_type int64
1001
+	//								var parsetotal int64
1002
+	//								if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
1003
+	//									project_id = int64(project.(map[string]interface{})["project_id"].(float64))
1004
+	//								}
1005
+	//								if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
1006
+	//									project_type = int64(project.(map[string]interface{})["type"].(float64))
1007
+	//								}
1008
+	//								if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
1009
+	//									total, _ := project.(map[string]interface{})["total"].(string)
1010
+	//									parsetotal, _ = strconv.ParseInt(total, 10, 64)
1011
+	//								}
1012
+	//								if project_type == 3 {
1013
+	//									//查找该耗材的出库记录
1014
+	//									goodWarehouseInfo, _ := service.GetAutoRecordByGoodId(project_id, patient_id, recordDateTime)
1015
+	//									//查询该患者耗材的历史数据
1016
+	//									ordProject, _ := service.GetHisProjectPrescriptionByPatientId(patient_id, recordDateTime)
1017
+	//									if goodWarehouseInfo.ID > 0 {
1018
+	//										//数量发生改变
1019
+	//										if parsetotal != goodWarehouseInfo.Count || len(ordProject) != len(projects) {
1020
+	//											//查找今日该患者已经出库的所有耗材
1021
+	//											goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
1022
+	//											for _, item := range goodList {
1023
+	//												//回退库存
1024
+	//												service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
1025
+	//												//删除记录
1026
+	//												service.DeleteAutoWarehouse(item.PatientId, item.SysRecordTime)
1027
+	//											}
1028
+	//										}
1029
+	//									}
1030
+	//								}
1031
+	//							}
1032
+	//						}
1033
+	//					}
1034
+	//				}
1035
+	//			}
1036
+	//		}
1037
+	//	}
1038
+	//	ch <- struct{}{}
1039
+	//}()
1040
+	//for range ch {
1041
+	//	// 每次从ch中接收数据,表明一个活动的协程结束
1042
+	//	count--
1043
+	//	// 当所有活动的协程都结束时,关闭管道
1044
+	//	if count == 0 {
1045
+	//		close(ch)
1046
+	//	}
1047
+	//}
1049 1048
 
1050 1049
 	info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
1051 1050
 	var hpInfo models.HisPrescriptionInfo
@@ -1258,7 +1257,7 @@ func (c *HisApiController) CreateHisPrescription() {
1258 1257
 							s.HisPatientId = his_patient_id
1259 1258
 							s.StartTime = pTime
1260 1259
 
1261
-							errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
1260
+							errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}), adminInfo.CurrentOrgId)
1262 1261
 							if errcode > 0 {
1263 1262
 								c.ServeFailJSONWithSGJErrorCode(errcode)
1264 1263
 								return
@@ -3024,7 +3023,7 @@ func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdd
3024 3023
 	return 0
3025 3024
 }
3026 3025
 
3027
-func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
3026
+func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}, org_id int64) int {
3028 3027
 
3029 3028
 	if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
3030 3029
 		utils.ErrorLog("drug_name")
@@ -3143,7 +3142,7 @@ func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo,
3143 3142
 					advice.StartTime = hisAdvice.StartTime
3144 3143
 					advice.HospApprFlag = hisAdvice.HospApprFlag
3145 3144
 
3146
-					if hisAdvice.SingleDose != advice.SingleDose || hisAdvice.DeliveryWay != advice.DeliveryWay || hisAdvice.ExecutionFrequency != advice.ExecutionFrequency || hisAdvice.Day != advice.Day || hisAdvice.PrescribingNumber != advice.PrescribingNumber || hisAdvice.Price != advice.Price || hisAdvice.Remark != advice.Remark {
3145
+					if hisAdvice.PrescribingNumberUnit != advice.PrescribingNumberUnit || hisAdvice.SingleDose != advice.SingleDose || hisAdvice.DeliveryWay != advice.DeliveryWay || hisAdvice.ExecutionFrequency != advice.ExecutionFrequency || hisAdvice.Day != advice.Day || hisAdvice.PrescribingNumber != advice.PrescribingNumber || hisAdvice.Price != advice.Price || hisAdvice.Remark != advice.Remark {
3147 3146
 						advice.ExecutionTime = 0
3148 3147
 						advice.ExecutionStaff = 0
3149 3148
 						advice.ExecutionState = 2
@@ -3155,6 +3154,62 @@ func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo,
3155 3154
 					//advice.Groupno = hisAdvice.Groupno
3156 3155
 
3157 3156
 				}
3157
+
3158
+				if hisAdvice.ID > 0 {
3159
+					drug, _ := service.FindBaseDrugLibRecordSeven(org_id, hisAdvice.DrugId)
3160
+					//查询药品的所有库存
3161
+					list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug.ID, org_id)
3162
+					var total_count int64
3163
+					for _, it := range list {
3164
+						total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
3165
+					}
3166
+
3167
+					var device_number int64
3168
+					if hisAdvice.PrescribingNumberUnit == drug.MaxUnit {
3169
+						prescribingNumber := strconv.FormatFloat(hisAdvice.PrescribingNumber, 'f', -1, 64)
3170
+						prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
3171
+						device_number = prescribingNumberInt * drug.MinNumber
3172
+					}
3173
+					if hisAdvice.PrescribingNumberUnit == drug.MinUnit {
3174
+						prescribingNumber := strconv.FormatFloat(hisAdvice.PrescribingNumber, 'f', -1, 64)
3175
+						prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
3176
+						device_number = prescribingNumberInt
3177
+					}
3178
+
3179
+					var sum_count int64
3180
+					//判断是否做过修改
3181
+					if advice.PrescribingNumberUnit == drug.MaxUnit {
3182
+
3183
+						prescribingNumberInt, _ := strconv.ParseInt(strconv.FormatFloat(advice.PrescribingNumber, 'f', 1, 32), 10, 64)
3184
+						sum_count = prescribingNumberInt * drug.MinNumber
3185
+					}
3186
+					if advice.PrescribingNumberUnit == drug.MinUnit {
3187
+						prescribingNumberInt, _ := strconv.ParseInt(strconv.FormatFloat(advice.PrescribingNumber, 'f', 1, 32), 10, 64)
3188
+						sum_count = prescribingNumberInt
3189
+					}
3190
+					fmt.Println("原先药品记录", device_number)
3191
+					fmt.Println("现在出库数量", sum_count)
3192
+					if device_number != sum_count {
3193
+
3194
+						// 查询该药品最后一次出库记录
3195
+						druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug.ID, advice.PatientId, advice.RecordDate)
3196
+						//回退库存
3197
+						if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
3198
+							service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, druginfo.Count)
3199
+						}
3200
+						if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
3201
+							service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, druginfo.Count)
3202
+						}
3203
+
3204
+						if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
3205
+							service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, druginfo.Count)
3206
+						}
3207
+
3208
+						//删除记录
3209
+						service.DeleteDrugAutoWarehouseSeven(drug.ID, advice.PatientId, advice.RecordDate, advice.ID)
3210
+					}
3211
+
3212
+				}
3158 3213
 			}
3159 3214
 		}
3160 3215
 	}
@@ -3283,6 +3338,24 @@ func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo,
3283 3338
 }
3284 3339
 
3285 3340
 func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
3341
+	if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
3342
+		project_id := int64(json["project_id"].(float64))
3343
+		project.ProjectId = project_id
3344
+		fmt.Println(project_id)
3345
+		fmt.Println(project.ProjectId)
3346
+	}
3347
+
3348
+	if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
3349
+		types := int64(json["type"].(float64))
3350
+		project.Type = types
3351
+	}
3352
+
3353
+	if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
3354
+		total, _ := json["total"].(string)
3355
+		//totals, _ := strconv.ParseInt(total, 10, 64)
3356
+		project.Count = total
3357
+	}
3358
+
3286 3359
 	project.ExecutionStaff = 0
3287 3360
 	project.ExecutionState = 2
3288 3361
 	project.ExecutionTime = 0
@@ -3300,16 +3373,32 @@ func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionPro
3300 3373
 		project.CheckState = temp_project.CheckState
3301 3374
 		project.CheckTime = temp_project.CheckTime
3302 3375
 		project.TeamId = temp_project.TeamId
3303
-	}
3304
-	if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
3305
-		types := int64(json["type"].(float64))
3306
-		project.Type = types
3307
-	}
3308
-	if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
3309
-		project_id := int64(json["project_id"].(float64))
3310
-		project.ProjectId = project_id
3311
-		fmt.Println(project_id)
3312
-		fmt.Println(project.ProjectId)
3376
+
3377
+		if id > 0 {
3378
+			if project.Type == 3 {
3379
+				//查找该耗材的出库记录
3380
+				goodWarehouseInfo, _ := service.GetAutoRecordByGoodId(project.ProjectId, temp_project.PatientId, temp_project.RecordDate)
3381
+				//查询该患者耗材的历史数据
3382
+				//ordProject, _ := service.GetHisProjectPrescriptionByPatientId(temp_project.PatientId, temp_project.RecordDate)
3383
+				if goodWarehouseInfo.ID > 0 {
3384
+					//数量发生改变
3385
+					parsetotal, _ := strconv.ParseInt(project.Count, 10, 64)
3386
+
3387
+					if parsetotal != goodWarehouseInfo.Count {
3388
+						//查找今日该患者已经出库的所有耗材
3389
+						goodList, _ := service.GetAllAutoRecordByPatient(temp_project.PatientId, temp_project.RecordDate)
3390
+						for _, item := range goodList {
3391
+							//回退库存
3392
+							service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
3393
+							//删除记录
3394
+							service.DeleteAutoWarehouse(item.PatientId, item.SysRecordTime)
3395
+						}
3396
+					}
3397
+				}
3398
+			}
3399
+
3400
+		}
3401
+
3313 3402
 	}
3314 3403
 
3315 3404
 	if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
@@ -3323,12 +3412,6 @@ func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionPro
3323 3412
 		project.Price = price
3324 3413
 	}
3325 3414
 
3326
-	if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
3327
-		total, _ := json["total"].(string)
3328
-		//totals, _ := strconv.ParseInt(total, 10, 64)
3329
-		project.Count = total
3330
-	}
3331
-
3332 3415
 	if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
3333 3416
 		medical_code, _ := json["medical_code"].(string)
3334 3417
 		project.MedListCodg = medical_code

+ 40 - 0
controllers/his_hospital_api_controller.go Ver arquivo

@@ -32,6 +32,8 @@ func HisHospitalManagerApiRegistRouters() {
32 32
 	beego.Router("/api/hospitaldetail/list", &HisHospitalApiController{}, "get:GetHisHospitalDetailPatientList")
33 33
 	beego.Router("/api/hospitaldetail/info", &HisHospitalApiController{}, "get:GetHisHospitalDetailInfo")
34 34
 
35
+	beego.Router("/api/monthhospitaldetail/get", &HisHospitalApiController{}, "get:GetHisHospitalMonthDetailInfo")
36
+
35 37
 }
36 38
 
37 39
 func (c *HisHospitalApiController) GetHisHospitalPatientList() {
@@ -752,3 +754,41 @@ func (c *HisHospitalApiController) GetHisHospitalDetailInfo() {
752 754
 		"his_info":            record,
753 755
 	})
754 756
 }
757
+func (c *HisHospitalApiController) GetHisHospitalMonthDetailInfo() {
758
+	id, _ := c.GetInt64("id")
759
+	is_upload, _ := c.GetInt64("is_upload")
760
+	patient_id, _ := c.GetInt64("patient_id")
761
+	start_time_str := c.GetString("start_time")
762
+	end_time_str := c.GetString("end_time")
763
+
764
+	record, _ := service.GetInHospitalRecord(id)
765
+	timeLayout := "2006-01-02"
766
+	loc, _ := time.LoadLocation("Local")
767
+	adminInfo := c.GetAdminUserInfo()
768
+	theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
769
+	if err != nil {
770
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
771
+		return
772
+	}
773
+	recordStartTime := theStartTime.Unix()
774
+	theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
775
+	if err != nil {
776
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
777
+		return
778
+	}
779
+	recordEndTime := theEndTime.Unix()
780
+	//var prescriptions []*models.HisPrescription
781
+
782
+	var monthPrescriptions []*models.HisPrescription
783
+	if is_upload == 1 {
784
+		monthPrescriptions, _ = service.GetMonthUnUploadHisHospitalPrescription(adminInfo.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
785
+	} else if is_upload == 2 {
786
+		monthPrescriptions, _ = service.GetMonthUploadHisHospitalPrescription(adminInfo.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
787
+	} else {
788
+		monthPrescriptions, _ = service.GetAllMonthHisHospitalPrescription(adminInfo.CurrentOrgId, patient_id, recordStartTime, recordEndTime)
789
+	}
790
+	c.ServeSuccessJSON(map[string]interface{}{
791
+		"month_prescriptions": monthPrescriptions,
792
+		"his_info":            record,
793
+	})
794
+}

+ 16 - 0
service/his_hospital_service.go Ver arquivo

@@ -397,3 +397,19 @@ func GetMonthUploadHisHospitalPrescription(org_id int64, patient_id int64, start
397 397
 		Find(&prescription).Error
398 398
 	return
399 399
 }
400
+
401
+func GetAllMonthHisHospitalPrescription(org_id int64, patient_id int64, start_time int64, end_time int64) (prescription []*models.HisPrescription, err error) {
402
+	err = readDb.Model(&models.HisPrescription{}).
403
+		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
404
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
405
+		}).
406
+		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
407
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
408
+		}).
409
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
410
+			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")
411
+		}).
412
+		Where("user_org_id = ? AND status = 1 AND patient_id = ? AND record_date <= ? AND  record_date >= ? AND p_type = 1", org_id, patient_id, end_time, start_time).
413
+		Find(&prescription).Error
414
+	return
415
+}