|
@@ -633,114 +633,132 @@ func (c *HisApiController) CreateHisPrescription() {
|
633
|
633
|
|
634
|
634
|
patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
|
635
|
635
|
|
636
|
|
- //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
|
637
|
|
- //
|
638
|
|
- //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
|
639
|
|
- //
|
640
|
|
- //if drugStockConfig.IsOpen == 1 {
|
641
|
|
- // //校验库存总量
|
642
|
|
- // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
|
643
|
|
- // prescriptions, _ := dataBody["prescriptions"].([]interface{})
|
644
|
|
- // if len(prescriptions) > 0 {
|
645
|
|
- // for _, item := range prescriptions {
|
646
|
|
- // items := item.(map[string]interface{})
|
647
|
|
- // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
|
648
|
|
- // advices := items["advices"].([]interface{})
|
649
|
|
- // if len(advices) > 0 {
|
650
|
|
- // for _, advice := range advices {
|
651
|
|
- // var drug_id int64
|
652
|
|
- // var prescribing_number float64
|
653
|
|
- // var prescribingNumberUnit string
|
654
|
|
- //
|
655
|
|
- // if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
|
656
|
|
- // drug_id = int64(advice.(map[string]interface{})["id"].(float64))
|
657
|
|
- // }
|
658
|
|
- // if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
|
659
|
|
- // //prescribing_number = advice.(map[string]interface{})["prescribing_number"].(string)
|
660
|
|
- // prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
|
661
|
|
- // prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
|
662
|
|
- //
|
663
|
|
- // }
|
664
|
|
- //
|
665
|
|
- // if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
|
666
|
|
- // prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
|
667
|
|
- // }
|
668
|
|
- //
|
669
|
|
- // drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, drug_id)
|
670
|
|
- // if drug.ID == 0 {
|
671
|
|
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
672
|
|
- // return
|
673
|
|
- // }
|
674
|
|
- //
|
675
|
|
- // if prescribingNumberUnit == drug.MinUnit {
|
676
|
|
- // if prescribing_number > drug.Total {
|
677
|
|
- // c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
|
678
|
|
- // //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
|
679
|
|
- // return
|
680
|
|
- // }
|
681
|
|
- // } else {
|
682
|
|
- // if prescribingNumberUnit == drug.MaxUnit {
|
683
|
|
- // num := prescribing_number * float64(drug.MinNumber)
|
684
|
|
- // if num > drug.Total {
|
685
|
|
- // c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
|
686
|
|
- // //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
|
687
|
|
- // return
|
688
|
|
- // }
|
689
|
|
- // }
|
690
|
|
- // }
|
691
|
|
- // }
|
692
|
|
- // }
|
693
|
|
- // }
|
694
|
|
- // }
|
695
|
|
- // }
|
696
|
|
- // }
|
697
|
|
- //}
|
698
|
|
- //
|
699
|
|
- //if stockConfig.IsOpen == 1 {
|
700
|
|
- // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
|
701
|
|
- // prescriptions, _ := dataBody["prescriptions"].([]interface{})
|
702
|
|
- // if len(prescriptions) > 0 {
|
703
|
|
- // for _, item := range prescriptions {
|
704
|
|
- // items := item.(map[string]interface{})
|
705
|
|
- // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
|
706
|
|
- // projects := items["project"].([]interface{})
|
707
|
|
- // if len(projects) > 0 {
|
708
|
|
- // for _, project := range projects {
|
709
|
|
- // var project_id int64
|
710
|
|
- // var project_type int64
|
711
|
|
- // var totals float64
|
712
|
|
- // if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
|
713
|
|
- // project_id = int64(project.(map[string]interface{})["project_id"].(float64))
|
714
|
|
- // }
|
715
|
|
- // if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
|
716
|
|
- // project_type = int64(project.(map[string]interface{})["type"].(float64))
|
717
|
|
- // }
|
718
|
|
- // if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
|
719
|
|
- // total, _ := project.(map[string]interface{})["total"].(string)
|
720
|
|
- //
|
721
|
|
- // totals, _ = strconv.ParseFloat(total, 64)
|
722
|
|
- // }
|
723
|
|
- // if project_type == 3 {
|
724
|
|
- // good, _ := service.FindGoodInfoByIdTwo(project_id)
|
725
|
|
- // if good.ID == 0 {
|
726
|
|
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
727
|
|
- // return
|
728
|
|
- // }
|
729
|
|
- // if totals > good.Total {
|
730
|
|
- // c.ServeDynamicFailJsonSend(good.GoodName + "库存不足")
|
731
|
|
- // //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
|
732
|
|
- // return
|
733
|
|
- // }
|
734
|
|
- //
|
735
|
|
- // }
|
736
|
|
- //
|
737
|
|
- // }
|
738
|
|
- // }
|
739
|
|
- // }
|
740
|
|
- // }
|
741
|
|
- // }
|
742
|
|
- // }
|
743
|
|
- //}
|
|
636
|
+ _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
|
|
637
|
+
|
|
638
|
+ _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
|
|
639
|
+
|
|
640
|
+ if drugStockConfig.IsOpen == 1 {
|
|
641
|
+ //校验库存总量
|
|
642
|
+ if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
|
|
643
|
+ prescriptions, _ := dataBody["prescriptions"].([]interface{})
|
|
644
|
+ if len(prescriptions) > 0 {
|
|
645
|
+ for _, item := range prescriptions {
|
|
646
|
+ items := item.(map[string]interface{})
|
|
647
|
+ if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
|
|
648
|
+ advices := items["advices"].([]interface{})
|
|
649
|
+ if len(advices) > 0 {
|
|
650
|
+ for _, advice := range advices {
|
|
651
|
+ var drug_id int64
|
|
652
|
+ var prescribing_number float64
|
|
653
|
+ var prescribingNumberUnit string
|
|
654
|
+
|
|
655
|
+ if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
|
|
656
|
+ drug_id = int64(advice.(map[string]interface{})["id"].(float64))
|
|
657
|
+ }
|
|
658
|
+ if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
|
|
659
|
+ //prescribing_number = advice.(map[string]interface{})["prescribing_number"].(string)
|
|
660
|
+ prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
|
|
661
|
+ prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
|
|
662
|
+
|
|
663
|
+ }
|
|
664
|
+
|
|
665
|
+ if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
|
|
666
|
+ prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
|
|
667
|
+ }
|
|
668
|
+
|
|
669
|
+ drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, drug_id)
|
|
670
|
+ if drug.ID == 0 {
|
|
671
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
672
|
+ return
|
|
673
|
+ }
|
|
674
|
+
|
|
675
|
+ //查询药品的搜有库存
|
|
676
|
+ list, _ := service.GetDrugWarehouseInfoPrescription(drug_id, adminInfo.CurrentOrgId)
|
|
677
|
+ var total_count int64
|
|
678
|
+ for _, it := range list {
|
|
679
|
+ total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
|
|
680
|
+ }
|
|
681
|
+ totals := strconv.FormatInt(total_count, 10)
|
|
682
|
+ all_count, _ := strconv.ParseFloat(totals, 64)
|
|
683
|
+ fmt.Println("all_count2323323233232", all_count)
|
|
684
|
+ if prescribingNumberUnit == drug.MinUnit {
|
|
685
|
+ if prescribing_number > all_count {
|
|
686
|
+ c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
|
|
687
|
+ //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
|
|
688
|
+ return
|
|
689
|
+ }
|
|
690
|
+ } else {
|
|
691
|
+ if prescribingNumberUnit == drug.MaxUnit {
|
|
692
|
+ num := prescribing_number * float64(drug.MinNumber)
|
|
693
|
+ if num > all_count {
|
|
694
|
+ c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
|
|
695
|
+ //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
|
|
696
|
+ return
|
|
697
|
+ }
|
|
698
|
+ }
|
|
699
|
+ }
|
|
700
|
+
|
|
701
|
+ }
|
|
702
|
+ }
|
|
703
|
+ }
|
|
704
|
+ }
|
|
705
|
+ }
|
|
706
|
+ }
|
|
707
|
+ }
|
|
708
|
+
|
|
709
|
+ if stockConfig.IsOpen == 1 {
|
|
710
|
+ if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
|
|
711
|
+ prescriptions, _ := dataBody["prescriptions"].([]interface{})
|
|
712
|
+ if len(prescriptions) > 0 {
|
|
713
|
+ for _, item := range prescriptions {
|
|
714
|
+ items := item.(map[string]interface{})
|
|
715
|
+ if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
|
|
716
|
+ projects := items["project"].([]interface{})
|
|
717
|
+ if len(projects) > 0 {
|
|
718
|
+ for _, project := range projects {
|
|
719
|
+ var project_id int64
|
|
720
|
+ var project_type int64
|
|
721
|
+ var totals float64
|
|
722
|
+ if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
|
|
723
|
+ project_id = int64(project.(map[string]interface{})["project_id"].(float64))
|
|
724
|
+ }
|
|
725
|
+ if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
|
|
726
|
+ project_type = int64(project.(map[string]interface{})["type"].(float64))
|
|
727
|
+ }
|
|
728
|
+ if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
|
|
729
|
+ total, _ := project.(map[string]interface{})["total"].(string)
|
|
730
|
+
|
|
731
|
+ totals, _ = strconv.ParseFloat(total, 64)
|
|
732
|
+ }
|
|
733
|
+ if project_type == 3 {
|
|
734
|
+ good, _ := service.FindGoodInfoByIdTwo(project_id)
|
|
735
|
+ if good.ID == 0 {
|
|
736
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
737
|
+ return
|
|
738
|
+ }
|
|
739
|
+ //查询耗材库存
|
|
740
|
+ list, _ := service.GetGoodWarehouseInfo(project_id)
|
|
741
|
+ var stock_count int64
|
|
742
|
+ for _, it := range list {
|
|
743
|
+ stock_count += it.StockCount
|
|
744
|
+ }
|
|
745
|
+ stock_counts := strconv.FormatInt(stock_count, 10)
|
|
746
|
+ stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
|
|
747
|
+ if totals > stock_total_count {
|
|
748
|
+ c.ServeDynamicFailJsonSend(good.GoodName + "库存不足")
|
|
749
|
+
|
|
750
|
+ return
|
|
751
|
+ }
|
|
752
|
+
|
|
753
|
+ }
|
|
754
|
+
|
|
755
|
+ }
|
|
756
|
+ }
|
|
757
|
+ }
|
|
758
|
+ }
|
|
759
|
+ }
|
|
760
|
+ }
|
|
761
|
+ }
|
744
|
762
|
|
745
|
763
|
info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
|
746
|
764
|
var hpInfo models.HisPrescriptionInfo
|