浏览代码

医保对接

csx 3 年前
父节点
当前提交
45615cdc7c
共有 1 个文件被更改,包括 228 次插入0 次删除
  1. 228 0
      controllers/his_api_controller.go

+ 228 - 0
controllers/his_api_controller.go 查看文件

@@ -710,6 +710,234 @@ func (c *HisApiController) CreateHisPrescription() {
710 710
 
711 711
 	_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
712 712
 
713
+	if drugStockConfig.IsOpen == 1 {
714
+		//校验库存总量
715
+		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
716
+			prescriptions, _ := dataBody["prescriptions"].([]interface{})
717
+			if len(prescriptions) > 0 {
718
+				for _, item := range prescriptions {
719
+					items := item.(map[string]interface{})
720
+					if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
721
+						advices := items["advices"].([]interface{})
722
+						if len(advices) > 0 {
723
+							for _, advice := range advices {
724
+								var drug_id int64
725
+								var prescribing_number float64
726
+								var prescribingNumberUnit string
727
+								var prescribingNumber string
728
+								var adviceId int64
729
+								if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
730
+									drug_id = int64(advice.(map[string]interface{})["id"].(float64))
731
+								}
732
+								if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
733
+									//prescribing_number = advice.(map[string]interface{})["prescribing_number"].(string)
734
+									prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
735
+									prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
736
+									prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
737
+
738
+								}
739
+
740
+								if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
741
+									prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
742
+								}
743
+
744
+								if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
745
+									adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
746
+								}
747
+
748
+								drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, drug_id)
749
+								if drug.ID == 0 {
750
+									c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
751
+									return
752
+								}
753
+
754
+								//查询药品的所有库存
755
+								list, _ := service.GetDrugWarehouseInfoPrescription(drug_id, adminInfo.CurrentOrgId)
756
+								var total_count int64
757
+								for _, it := range list {
758
+									total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
759
+								}
760
+								totals := strconv.FormatInt(total_count, 10)
761
+								//查询该药品是否存在开药记录
762
+								advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
763
+								//修改处方
764
+								if advicelist.ID > 0 {
765
+									var device_number int64
766
+									if advicelist.PrescribingNumberUnit == drug.MaxUnit {
767
+										prescribingNumber := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
768
+										prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
769
+										device_number = prescribingNumberInt * drug.MinNumber
770
+									}
771
+									if advicelist.PrescribingNumberUnit == drug.MinUnit {
772
+										prescribingNumber := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
773
+										prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
774
+										device_number = prescribingNumberInt
775
+									}
776
+
777
+									var number_count int64
778
+									if prescribingNumberUnit == drug.MaxUnit {
779
+										prescribingNumber := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
780
+										prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
781
+										number_count = prescribingNumberInt * drug.MinNumber
782
+									}
783
+									if prescribingNumberUnit == drug.MinUnit {
784
+										prescribingNumber := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
785
+										prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
786
+										number_count = prescribingNumberInt
787
+									}
788
+									//如果修改的数量大于之前修改的数量
789
+									if (number_count - device_number) > 0 {
790
+										//如果修改的差数量 大于库存数量
791
+										if (number_count - device_number) > total_count {
792
+											c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
793
+											return
794
+										}
795
+									}
796
+
797
+									var sum_count int64
798
+									//判断是否做过修改
799
+									if prescribingNumberUnit == drug.MaxUnit {
800
+
801
+										prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
802
+
803
+										sum_count = prescribingNumberInt * drug.MinNumber
804
+									}
805
+									if prescribingNumberUnit == drug.MinUnit {
806
+										prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
807
+										sum_count = prescribingNumberInt
808
+									}
809
+									fmt.Println("原先药品记录", device_number)
810
+									fmt.Println("现在出库数量", sum_count)
811
+									if device_number != sum_count {
812
+
813
+										// 查询该药品最后一次出库记录
814
+										druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime)
815
+										//回退库存
816
+										if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
817
+											service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, druginfo.Count)
818
+										}
819
+										if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
820
+											service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, druginfo.Count)
821
+										}
822
+
823
+										if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
824
+											service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, druginfo.Count)
825
+										}
826
+
827
+										//删除记录
828
+										service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
829
+									}
830
+
831
+								}
832
+
833
+								//新增处方
834
+								if advicelist.ID == 0 {
835
+									all_count, _ := strconv.ParseFloat(totals, 64)
836
+									if prescribingNumberUnit == drug.MinUnit {
837
+										if prescribing_number > all_count {
838
+											c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
839
+											return
840
+										}
841
+									} else {
842
+										if prescribingNumberUnit == drug.MaxUnit {
843
+											num := prescribing_number * float64(drug.MinNumber)
844
+											if num > all_count {
845
+												c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
846
+												return
847
+											}
848
+										}
849
+									}
850
+								}
851
+							}
852
+
853
+						}
854
+					}
855
+				}
856
+			}
857
+		}
858
+	}
859
+	if stockConfig.IsOpen == 1 {
860
+		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
861
+			prescriptions, _ := dataBody["prescriptions"].([]interface{})
862
+			if len(prescriptions) > 0 {
863
+				for _, item := range prescriptions {
864
+					items := item.(map[string]interface{})
865
+					if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
866
+						projects := items["project"].([]interface{})
867
+						if len(projects) > 0 {
868
+							for _, project := range projects {
869
+								var project_id int64
870
+								var project_type int64
871
+								var totals float64
872
+								var parsetotal int64
873
+								if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
874
+									project_id = int64(project.(map[string]interface{})["project_id"].(float64))
875
+								}
876
+								if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
877
+									project_type = int64(project.(map[string]interface{})["type"].(float64))
878
+								}
879
+								if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
880
+									total, _ := project.(map[string]interface{})["total"].(string)
881
+
882
+									totals, _ = strconv.ParseFloat(total, 64)
883
+									parsetotal, _ = strconv.ParseInt(total, 10, 64)
884
+								}
885
+								if project_type == 3 {
886
+
887
+									//查找该耗材的出库记录
888
+									goodWarehouseInfo, _ := service.GetAutoRecordByGoodId(project_id, patient_id, recordDateTime)
889
+									fmt.Println("出库数量00000000000000000000000", parsetotal)
890
+									fmt.Println("已经出库数量0000000000000000000", goodWarehouseInfo.Count)
891
+
892
+									//查询该患者耗材的历史数据
893
+									ordProject, _ := service.GetHisProjectPrescriptionByPatientId(patient_id, recordDateTime)
894
+									fmt.Println("长度1", len(ordProject))
895
+									fmt.Println("新长度", len(projects))
896
+									if goodWarehouseInfo.ID > 0 {
897
+										//数量发生改变
898
+										if parsetotal != goodWarehouseInfo.Count || len(ordProject) != len(projects) {
899
+											//查找今日该患者已经出库的所有耗材
900
+											goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
901
+											for _, item := range goodList {
902
+												//回退库存
903
+												service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
904
+												//删除记录
905
+												service.DeleteAutoWarehouse(item.PatientId, item.SysRecordTime)
906
+											}
907
+
908
+										}
909
+
910
+									}
911
+									if goodWarehouseInfo.ID == 0 {
912
+										good, _ := service.FindGoodInfoByIdTwo(project_id)
913
+										if good.ID == 0 {
914
+											c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
915
+											return
916
+										}
917
+										//查询耗材库存
918
+										list, _ := service.GetGoodWarehouseInfo(project_id)
919
+										var stock_count int64
920
+										for _, it := range list {
921
+											stock_count += it.StockCount
922
+										}
923
+										stock_counts := strconv.FormatInt(stock_count, 10)
924
+										stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
925
+										if totals > stock_total_count {
926
+											fmt.Println("hh23323233233332323332323323322323")
927
+											c.ServeDynamicFailJsonSend(good.GoodName + "库存不足")
928
+											return
929
+										}
930
+									}
931
+								}
932
+
933
+							}
934
+						}
935
+					}
936
+				}
937
+			}
938
+		}
939
+	}
940
+
713 941
 	ch := make(chan struct{})
714 942
 	count := 3 // count 表示活动的协程个数
715 943