|
@@ -609,118 +609,483 @@ func (c *PatientApiController) ExecDoctorAdvice() {
|
609
|
609
|
advice.ExecutionState = 1
|
610
|
610
|
advice.Modifier = adminUserInfo.AdminUser.Id
|
611
|
611
|
|
612
|
|
- //查询医嘱是否已经实行
|
613
|
|
- if groupno > 0 {
|
614
|
|
- advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
|
615
|
|
- for _, item := range advices {
|
616
|
|
- //如果医嘱已经执行生成自备药出库单
|
617
|
|
- if item.ExecutionState == 1 {
|
|
612
|
+ //处理出库相关逻辑
|
618
|
613
|
|
619
|
|
- prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
|
620
|
|
- outStoreNumber, _ := strconv.ParseInt(prescribingNumber, 10, 64)
|
621
|
|
- timeStr := time.Now().Format("2006-01-02")
|
622
|
|
- timeArr := strings.Split(timeStr, "-")
|
623
|
|
- total, _ := service.FindAllWarehouseOut(adminUserInfo.Org.Id)
|
624
|
|
- total = total + 1
|
625
|
|
- warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
|
626
|
|
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
|
627
|
|
- number = number + total
|
628
|
|
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
|
629
|
|
-
|
630
|
|
- medicalName, errcode := service.GetSelfMedicalByDrugName(item.AdviceName, item.AdviceDesc, item.PatientId)
|
631
|
|
- if errcode == gorm.ErrRecordNotFound {
|
632
|
|
- c.ServeSuccessJSON(map[string]interface{}{
|
633
|
|
- "msg": "ok",
|
634
|
|
- "advice": advice,
|
635
|
|
- "ids": ids,
|
636
|
|
- })
|
637
|
|
- return
|
638
|
|
- } else if errcode == nil {
|
639
|
|
- stock := models.XtSelfOutStock{
|
640
|
|
- DrugName: item.AdviceName,
|
641
|
|
- DrugNameId: medicalName.DrugNameId,
|
642
|
|
- DrugSpec: item.AdviceDesc,
|
643
|
|
- OutstoreNumber: outStoreNumber,
|
644
|
|
- AdminUserId: adminUserInfo.AdminUser.Id,
|
645
|
|
- StorckTime: item.AdviceDate,
|
646
|
|
- UserOrgId: adminUserInfo.Org.Id,
|
647
|
|
- CreatedTime: time.Now().Unix(),
|
648
|
|
- Status: 1,
|
649
|
|
- PatientId: item.PatientId,
|
650
|
|
- StockOutNumber: warehousing_out_order,
|
651
|
|
- ExitMode: 2,
|
652
|
|
- MedicId: medicalName.ID,
|
|
614
|
+ //1.判断是否启用药品管理和自备药出库功能
|
|
615
|
+
|
|
616
|
+ //药品管理信息
|
|
617
|
+ _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
|
|
618
|
+
|
|
619
|
+ //自备药信息
|
|
620
|
+ privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
|
|
621
|
+
|
|
622
|
+ if drugStockConfig.IsOpen == 1 {
|
|
623
|
+ if groupno > 0 {
|
|
624
|
+ advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
|
|
625
|
+ isHasWay := false //用来判断是否包含来自药品库的医嘱
|
|
626
|
+ record_time := int64(0)
|
|
627
|
+ for _, item := range advices {
|
|
628
|
+ if item.Way == 1 {
|
|
629
|
+ isHasWay = true
|
|
630
|
+ record_time = item.RecordDate
|
|
631
|
+ }
|
|
632
|
+ }
|
|
633
|
+
|
|
634
|
+ if isHasWay {
|
|
635
|
+ out, err := service.FindDrugStockOutByIsSys(adminUserInfo.Org.Id, 1, record_time)
|
|
636
|
+ if err == gorm.ErrRecordNotFound {
|
|
637
|
+ //没有记录,则创建出库单
|
|
638
|
+ timeStr := time.Now().Format("2006-01-02")
|
|
639
|
+ timeArr := strings.Split(timeStr, "-")
|
|
640
|
+ total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
|
|
641
|
+ total = total + 1
|
|
642
|
+ warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
|
|
643
|
+ number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
|
|
644
|
+ number = number + total
|
|
645
|
+ warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
|
|
646
|
+ creater := adminUserInfo.AdminUser.Id
|
|
647
|
+ warehouseOut := models.DrugWarehouseOut{
|
|
648
|
+ WarehouseOutOrderNumber: warehousing_out_order,
|
|
649
|
+ OperationTime: time.Now().Unix(),
|
|
650
|
+ OrgId: adminUserInfo.Org.Id,
|
|
651
|
+ Creater: creater,
|
|
652
|
+ Ctime: time.Now().Unix(),
|
|
653
|
+ Status: 1,
|
|
654
|
+ WarehouseOutTime: record_time,
|
|
655
|
+ Dealer: 0,
|
|
656
|
+ Manufacturer: 0,
|
|
657
|
+ Type: 1,
|
|
658
|
+ IsSys: 1,
|
653
|
659
|
}
|
|
660
|
+ err := service.AddSigleDrugWarehouseOut(&warehouseOut)
|
|
661
|
+ if err != nil {
|
|
662
|
+ utils.TraceLog("创建出库单失败 err = %v", err)
|
|
663
|
+ } else {
|
|
664
|
+ for _, item := range advices {
|
|
665
|
+ if item.Way == 1 {
|
|
666
|
+ if item.PrescribingNumber > 0 {
|
|
667
|
+ warehouseOutInfo := &models.DrugWarehouseOutInfo{
|
|
668
|
+ WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
|
|
669
|
+ WarehouseOutId: warehouseOut.ID,
|
|
670
|
+ Status: 1,
|
|
671
|
+ Ctime: time.Now().Unix(),
|
|
672
|
+ Remark: "",
|
|
673
|
+ OrgId: adminUserInfo.Org.Id,
|
|
674
|
+ Type: 1,
|
|
675
|
+ Manufacturer: 0,
|
|
676
|
+ Dealer: 0,
|
|
677
|
+ IsSys: 1,
|
|
678
|
+ SysRecordTime: record_time,
|
|
679
|
+ DrugId: item.DrugId,
|
|
680
|
+ }
|
|
681
|
+ prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
|
|
682
|
+ count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
|
|
683
|
+ warehouseOutInfo.Count = count
|
|
684
|
+ stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
|
|
685
|
+ warehouseOutInfo.Price = stockInInfo.Price
|
|
686
|
+ err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
|
|
687
|
+ if err == nil {
|
|
688
|
+ details := &models.DrugAutomaticReduceDetail{
|
|
689
|
+ WarehouseOutId: warehouseOutInfo.ID,
|
|
690
|
+ WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
|
|
691
|
+ PatientId: item.PatientId,
|
|
692
|
+ Ctime: time.Now().Unix(),
|
|
693
|
+ Mtime: time.Now().Unix(),
|
|
694
|
+ Status: 1,
|
|
695
|
+ RecordTime: record_time,
|
|
696
|
+ OrgId: adminUserInfo.Org.Id,
|
|
697
|
+ DrugId: item.DrugId,
|
|
698
|
+ Count: count,
|
|
699
|
+ }
|
|
700
|
+ service.AddSigleDrugAutoReduceRecordInfo(details)
|
|
701
|
+ }
|
|
702
|
+ }
|
|
703
|
+ }
|
654
|
704
|
|
655
|
|
- //创建出库单
|
656
|
|
- service.CreateOutStock(&stock)
|
|
705
|
+ }
|
|
706
|
+ }
|
|
707
|
+
|
|
708
|
+ } else if err == nil {
|
|
709
|
+ for _, item := range advices {
|
|
710
|
+ if item.Way == 1 {
|
|
711
|
+ outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.Org.Id, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
|
|
712
|
+ if err == gorm.ErrRecordNotFound {
|
|
713
|
+ warehouseOutInfo := &models.DrugWarehouseOutInfo{
|
|
714
|
+ WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
|
|
715
|
+ WarehouseOutId: out.ID,
|
|
716
|
+ Status: 1,
|
|
717
|
+ Ctime: time.Now().Unix(),
|
|
718
|
+ Remark: "",
|
|
719
|
+ OrgId: adminUserInfo.Org.Id,
|
|
720
|
+ Type: 1,
|
|
721
|
+ Manufacturer: 0,
|
|
722
|
+ Dealer: 0,
|
|
723
|
+ IsSys: 1,
|
|
724
|
+ SysRecordTime: record_time,
|
|
725
|
+ }
|
|
726
|
+
|
|
727
|
+ stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
|
|
728
|
+ warehouseOutInfo.Price = stockInInfo.Price
|
|
729
|
+ warehouseOutInfo.DrugId = item.DrugId
|
|
730
|
+ prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
|
|
731
|
+ count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
|
|
732
|
+ warehouseOutInfo.Count = count
|
|
733
|
+ err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
|
|
734
|
+ if err == nil {
|
|
735
|
+ details := &models.DrugAutomaticReduceDetail{
|
|
736
|
+ WarehouseOutId: warehouseOutInfo.ID,
|
|
737
|
+ WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
|
|
738
|
+ PatientId: item.PatientId,
|
|
739
|
+ Ctime: time.Now().Unix(),
|
|
740
|
+ Mtime: time.Now().Unix(),
|
|
741
|
+ Status: 1,
|
|
742
|
+ RecordTime: record_time,
|
|
743
|
+ OrgId: adminUserInfo.Org.Id,
|
|
744
|
+ DrugId: item.DrugId,
|
|
745
|
+ Count: count,
|
|
746
|
+ }
|
|
747
|
+ service.AddSigleDrugAutoReduceRecordInfo(details)
|
|
748
|
+ }
|
|
749
|
+
|
|
750
|
+ } else if err == nil { //记录存在,则将增加数量
|
|
751
|
+ if outInfo.ID > 0 {
|
|
752
|
+ prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
|
|
753
|
+ count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
|
|
754
|
+ service.UpdateDrugStockOutInfoCount2(adminUserInfo.Org.Id, outInfo.ID, count)
|
|
755
|
+ }
|
|
756
|
+
|
|
757
|
+ count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.Org.Id, record_time, item.DrugId, item.PatientId)
|
|
758
|
+ if count == 0 {
|
|
759
|
+ prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
|
|
760
|
+ count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
|
|
761
|
+ details := &models.DrugAutomaticReduceDetail{
|
|
762
|
+ WarehouseOutId: outInfo.ID,
|
|
763
|
+ WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
|
|
764
|
+ PatientId: item.PatientId,
|
|
765
|
+ Ctime: time.Now().Unix(),
|
|
766
|
+ Mtime: time.Now().Unix(),
|
|
767
|
+ Status: 1,
|
|
768
|
+ RecordTime: record_time,
|
|
769
|
+ OrgId: adminUserInfo.Org.Id,
|
|
770
|
+ DrugId: item.DrugId,
|
|
771
|
+ Count: count,
|
|
772
|
+ }
|
|
773
|
+ service.AddSigleDrugAutoReduceRecordInfo(details)
|
|
774
|
+ } else if count == 1 {
|
|
775
|
+ prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
|
|
776
|
+ count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
|
|
777
|
+ service.UpdateDrugUserInfoDetails(item.DrugId, record_time, adminUserInfo.Org.Id, item.PatientId, count, &outInfo)
|
|
778
|
+ }
|
|
779
|
+
|
|
780
|
+ }
|
|
781
|
+ }
|
|
782
|
+ }
|
657
|
783
|
|
658
|
|
- c.ServeSuccessJSON(map[string]interface{}{
|
659
|
|
- "msg": "ok",
|
660
|
|
- "advice": advice,
|
661
|
|
- "ids": ids,
|
662
|
|
- })
|
663
|
|
- return
|
664
|
784
|
}
|
665
|
785
|
|
666
|
786
|
}
|
667
|
|
- }
|
668
|
|
- } else {
|
669
|
|
- advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
|
670
|
|
- for _, item := range advices {
|
671
|
|
- if item.ExecutionState == 1 {
|
672
|
|
- prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
|
673
|
|
- outStoreNumber, _ := strconv.ParseInt(prescribingNumber, 10, 64)
|
674
|
|
- timeStr := time.Now().Format("2006-01-02")
|
675
|
|
- timeArr := strings.Split(timeStr, "-")
|
676
|
|
- total, _ := service.FindAllWarehouseOut(adminUserInfo.Org.Id)
|
677
|
|
- total = total + 1
|
678
|
|
- warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
|
679
|
|
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
|
680
|
|
- number = number + total
|
681
|
|
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
|
682
|
|
-
|
683
|
|
- medicalName, errc := service.GetSelfMedicalByDrugName(item.AdviceName, item.AdviceDesc, item.PatientId)
|
684
|
|
- if errc == gorm.ErrRecordNotFound {
|
685
|
|
- c.ServeSuccessJSON(map[string]interface{}{
|
686
|
|
- "msg": "ok",
|
687
|
|
- "advice": advice,
|
688
|
|
- "ids": ids,
|
689
|
|
- })
|
690
|
|
- return
|
691
|
|
- } else if errc == nil {
|
692
|
|
-
|
693
|
|
- stock := models.XtSelfOutStock{
|
694
|
|
- DrugName: item.AdviceName,
|
695
|
|
- DrugNameId: medicalName.DrugNameId,
|
696
|
|
- DrugSpec: item.AdviceDesc,
|
697
|
|
- OutstoreNumber: outStoreNumber,
|
698
|
|
- AdminUserId: adminUserInfo.AdminUser.Id,
|
699
|
|
- StorckTime: item.AdviceDate,
|
700
|
|
- UserOrgId: adminUserInfo.Org.Id,
|
701
|
|
- CreatedTime: time.Now().Unix(),
|
702
|
|
- Status: 1,
|
703
|
|
- PatientId: item.PatientId,
|
704
|
|
- StockOutNumber: warehousing_out_order,
|
705
|
|
- ExitMode: 2,
|
706
|
|
- MedicId: medicalName.ID,
|
|
787
|
+ } else {
|
|
788
|
+ advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
|
|
789
|
+ isHasWay := false //用来判断是否包含来自药品库的医嘱
|
|
790
|
+ record_time := int64(0)
|
|
791
|
+ for _, item := range advices {
|
|
792
|
+ if item.Way == 1 {
|
|
793
|
+ isHasWay = true
|
|
794
|
+ record_time = item.RecordDate
|
|
795
|
+ }
|
|
796
|
+ }
|
|
797
|
+
|
|
798
|
+ if isHasWay {
|
|
799
|
+ out, err := service.FindDrugStockOutByIsSys(adminUserInfo.Org.Id, 1, record_time)
|
|
800
|
+ if err == gorm.ErrRecordNotFound {
|
|
801
|
+ //没有记录,则创建出库单
|
|
802
|
+ timeStr := time.Now().Format("2006-01-02")
|
|
803
|
+ timeArr := strings.Split(timeStr, "-")
|
|
804
|
+ total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
|
|
805
|
+ total = total + 1
|
|
806
|
+ warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
|
|
807
|
+ number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
|
|
808
|
+ number = number + total
|
|
809
|
+ warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
|
|
810
|
+ creater := adminUserInfo.AdminUser.Id
|
|
811
|
+ warehouseOut := models.DrugWarehouseOut{
|
|
812
|
+ WarehouseOutOrderNumber: warehousing_out_order,
|
|
813
|
+ OperationTime: time.Now().Unix(),
|
|
814
|
+ OrgId: adminUserInfo.Org.Id,
|
|
815
|
+ Creater: creater,
|
|
816
|
+ Ctime: time.Now().Unix(),
|
|
817
|
+ Status: 1,
|
|
818
|
+ WarehouseOutTime: record_time,
|
|
819
|
+ Dealer: 0,
|
|
820
|
+ Manufacturer: 0,
|
|
821
|
+ Type: 1,
|
|
822
|
+ IsSys: 1,
|
707
|
823
|
}
|
|
824
|
+ err := service.AddSigleDrugWarehouseOut(&warehouseOut)
|
|
825
|
+ if err != nil {
|
|
826
|
+ utils.TraceLog("创建出库单失败 err = %v", err)
|
|
827
|
+ } else {
|
|
828
|
+ for _, item := range advices {
|
|
829
|
+ if item.Way == 1 {
|
|
830
|
+ if item.PrescribingNumber > 0 {
|
|
831
|
+ warehouseOutInfo := &models.DrugWarehouseOutInfo{
|
|
832
|
+ WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
|
|
833
|
+ WarehouseOutId: warehouseOut.ID,
|
|
834
|
+ Status: 1,
|
|
835
|
+ Ctime: time.Now().Unix(),
|
|
836
|
+ Remark: "",
|
|
837
|
+ OrgId: adminUserInfo.Org.Id,
|
|
838
|
+ Type: 1,
|
|
839
|
+ Manufacturer: 0,
|
|
840
|
+ Dealer: 0,
|
|
841
|
+ IsSys: 1,
|
|
842
|
+ SysRecordTime: record_time,
|
|
843
|
+ DrugId: item.DrugId,
|
|
844
|
+ }
|
|
845
|
+ prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
|
|
846
|
+ count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
|
|
847
|
+ warehouseOutInfo.Count = count
|
|
848
|
+ stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
|
|
849
|
+ warehouseOutInfo.Price = stockInInfo.Price
|
|
850
|
+ err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
|
|
851
|
+ if err == nil {
|
|
852
|
+ details := &models.DrugAutomaticReduceDetail{
|
|
853
|
+ WarehouseOutId: warehouseOutInfo.ID,
|
|
854
|
+ WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
|
|
855
|
+ PatientId: item.PatientId,
|
|
856
|
+ Ctime: time.Now().Unix(),
|
|
857
|
+ Mtime: time.Now().Unix(),
|
|
858
|
+ Status: 1,
|
|
859
|
+ RecordTime: record_time,
|
|
860
|
+ OrgId: adminUserInfo.Org.Id,
|
|
861
|
+ DrugId: item.DrugId,
|
|
862
|
+ Count: count,
|
|
863
|
+ }
|
|
864
|
+ service.AddSigleDrugAutoReduceRecordInfo(details)
|
|
865
|
+ }
|
|
866
|
+ }
|
|
867
|
+ }
|
708
|
868
|
|
709
|
|
- //创建出库单
|
710
|
|
- service.CreateOutStock(&stock)
|
|
869
|
+ }
|
|
870
|
+ }
|
|
871
|
+
|
|
872
|
+ } else if err == nil {
|
|
873
|
+ for _, item := range advices {
|
|
874
|
+ if item.Way == 1 {
|
|
875
|
+ outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.Org.Id, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
|
|
876
|
+ if err == gorm.ErrRecordNotFound {
|
|
877
|
+ warehouseOutInfo := &models.DrugWarehouseOutInfo{
|
|
878
|
+ WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
|
|
879
|
+ WarehouseOutId: out.ID,
|
|
880
|
+ Status: 1,
|
|
881
|
+ Ctime: time.Now().Unix(),
|
|
882
|
+ Remark: "",
|
|
883
|
+ OrgId: adminUserInfo.Org.Id,
|
|
884
|
+ Type: 1,
|
|
885
|
+ Manufacturer: 0,
|
|
886
|
+ Dealer: 0,
|
|
887
|
+ IsSys: 1,
|
|
888
|
+ SysRecordTime: record_time,
|
|
889
|
+ }
|
|
890
|
+
|
|
891
|
+ stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
|
|
892
|
+ warehouseOutInfo.Price = stockInInfo.Price
|
|
893
|
+ warehouseOutInfo.DrugId = item.DrugId
|
|
894
|
+ //warehouseOutInfo.Count = item.
|
|
895
|
+ prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
|
|
896
|
+ count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
|
|
897
|
+ err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
|
|
898
|
+ if err == nil {
|
|
899
|
+ details := &models.DrugAutomaticReduceDetail{
|
|
900
|
+ WarehouseOutId: warehouseOutInfo.ID,
|
|
901
|
+ WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
|
|
902
|
+ PatientId: item.PatientId,
|
|
903
|
+ Ctime: time.Now().Unix(),
|
|
904
|
+ Mtime: time.Now().Unix(),
|
|
905
|
+ Status: 1,
|
|
906
|
+ RecordTime: record_time,
|
|
907
|
+ OrgId: adminUserInfo.Org.Id,
|
|
908
|
+ DrugId: item.DrugId,
|
|
909
|
+ Count: count,
|
|
910
|
+ }
|
|
911
|
+ service.AddSigleDrugAutoReduceRecordInfo(details)
|
|
912
|
+ }
|
|
913
|
+
|
|
914
|
+ } else if err == nil { //记录存在,则将增加数量
|
|
915
|
+ if outInfo.ID > 0 {
|
|
916
|
+ prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
|
|
917
|
+ count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
|
|
918
|
+ service.UpdateDrugStockOutInfoCount2(adminUserInfo.Org.Id, outInfo.ID, count)
|
|
919
|
+ }
|
|
920
|
+
|
|
921
|
+ count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.Org.Id, record_time, item.DrugId, item.PatientId)
|
|
922
|
+ if count == 0 {
|
|
923
|
+ prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
|
|
924
|
+ count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
|
|
925
|
+ details := &models.DrugAutomaticReduceDetail{
|
|
926
|
+ WarehouseOutId: outInfo.ID,
|
|
927
|
+ WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
|
|
928
|
+ PatientId: item.PatientId,
|
|
929
|
+ Ctime: time.Now().Unix(),
|
|
930
|
+ Mtime: time.Now().Unix(),
|
|
931
|
+ Status: 1,
|
|
932
|
+ RecordTime: record_time,
|
|
933
|
+ OrgId: adminUserInfo.Org.Id,
|
|
934
|
+ DrugId: item.DrugId,
|
|
935
|
+ Count: count,
|
|
936
|
+ }
|
|
937
|
+ service.AddSigleDrugAutoReduceRecordInfo(details)
|
|
938
|
+ } else if count == 1 {
|
|
939
|
+ prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
|
|
940
|
+ count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
|
|
941
|
+ service.UpdateDrugUserInfoDetails(item.DrugId, record_time, adminUserInfo.Org.Id, item.PatientId, count, &outInfo)
|
|
942
|
+ }
|
|
943
|
+
|
|
944
|
+ }
|
|
945
|
+ }
|
|
946
|
+ }
|
711
|
947
|
|
712
|
|
- c.ServeSuccessJSON(map[string]interface{}{
|
713
|
|
- "msg": "ok",
|
714
|
|
- "advice": advice,
|
715
|
|
- "ids": ids,
|
716
|
|
- })
|
717
|
|
- return
|
718
|
948
|
}
|
719
|
949
|
|
720
|
950
|
}
|
721
|
951
|
}
|
722
|
952
|
}
|
723
|
953
|
|
|
954
|
+ if privateDrugConfig.DrugStart == 1 {
|
|
955
|
+ if groupno > 0 {
|
|
956
|
+ advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
|
|
957
|
+ for _, item := range advices {
|
|
958
|
+ if item.ExecutionState == 2 {
|
|
959
|
+ advice = item
|
|
960
|
+
|
|
961
|
+ }
|
|
962
|
+ }
|
|
963
|
+ } else {
|
|
964
|
+ advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
|
|
965
|
+ for _, item := range advices {
|
|
966
|
+ if item.ExecutionState == 2 {
|
|
967
|
+ advice = item
|
|
968
|
+
|
|
969
|
+ }
|
|
970
|
+ }
|
|
971
|
+ }
|
|
972
|
+ }
|
|
973
|
+
|
|
974
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
975
|
+ "msg": "ok",
|
|
976
|
+ "advice": advice,
|
|
977
|
+ "ids": ids,
|
|
978
|
+ })
|
|
979
|
+ return
|
|
980
|
+
|
|
981
|
+ //查询医嘱是否已经实行
|
|
982
|
+ //if groupno > 0 {
|
|
983
|
+ // advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
|
|
984
|
+ // for _, item := range advices {
|
|
985
|
+ // //如果医嘱已经执行生成自备药出库单
|
|
986
|
+ // if item.ExecutionState == 1 {
|
|
987
|
+ //
|
|
988
|
+ // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
|
|
989
|
+ // outStoreNumber, _ := strconv.ParseInt(prescribingNumber, 10, 64)
|
|
990
|
+ //
|
|
991
|
+ // timeStr := time.Now().Format("2006-01-02")
|
|
992
|
+ // timeArr := strings.Split(timeStr, "-")
|
|
993
|
+ // total, _ := service.FindAllWarehouseOut(adminUserInfo.Org.Id)
|
|
994
|
+ // total = total + 1
|
|
995
|
+ // warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
|
|
996
|
+ // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
|
|
997
|
+ // number = number + total
|
|
998
|
+ // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
|
|
999
|
+ //
|
|
1000
|
+ // medicalName, errcode := service.GetSelfMedicalByDrugName(item.AdviceName, item.AdviceDesc, item.PatientId)
|
|
1001
|
+ // if errcode == gorm.ErrRecordNotFound {
|
|
1002
|
+ // c.ServeSuccessJSON(map[string]interface{}{
|
|
1003
|
+ // "msg": "ok",
|
|
1004
|
+ // "advice": advice,
|
|
1005
|
+ // "ids": ids,
|
|
1006
|
+ // })
|
|
1007
|
+ // return
|
|
1008
|
+ // } else if errcode == nil {
|
|
1009
|
+ // stock := models.XtSelfOutStock{
|
|
1010
|
+ // DrugName: item.AdviceName,
|
|
1011
|
+ // DrugNameId: medicalName.DrugNameId,
|
|
1012
|
+ // DrugSpec: item.AdviceDesc,
|
|
1013
|
+ // OutstoreNumber: outStoreNumber,
|
|
1014
|
+ // AdminUserId: adminUserInfo.AdminUser.Id,
|
|
1015
|
+ // StorckTime: item.AdviceDate,
|
|
1016
|
+ // UserOrgId: adminUserInfo.Org.Id,
|
|
1017
|
+ // CreatedTime: time.Now().Unix(),
|
|
1018
|
+ // Status: 1,
|
|
1019
|
+ // PatientId: item.PatientId,
|
|
1020
|
+ // StockOutNumber: warehousing_out_order,
|
|
1021
|
+ // ExitMode: 2,
|
|
1022
|
+ // MedicId: medicalName.ID,
|
|
1023
|
+ // }
|
|
1024
|
+ //
|
|
1025
|
+ // //创建出库单
|
|
1026
|
+ // service.CreateOutStock(&stock)
|
|
1027
|
+ //
|
|
1028
|
+ // c.ServeSuccessJSON(map[string]interface{}{
|
|
1029
|
+ // "msg": "ok",
|
|
1030
|
+ // "advice": advice,
|
|
1031
|
+ // "ids": ids,
|
|
1032
|
+ // })
|
|
1033
|
+ // return
|
|
1034
|
+ // }
|
|
1035
|
+ //
|
|
1036
|
+ // }
|
|
1037
|
+ // }
|
|
1038
|
+ //} else {
|
|
1039
|
+ // advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
|
|
1040
|
+ // for _, item := range advices {
|
|
1041
|
+ // if item.ExecutionState == 1 {
|
|
1042
|
+ // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
|
|
1043
|
+ // outStoreNumber, _ := strconv.ParseInt(prescribingNumber, 10, 64)
|
|
1044
|
+ // timeStr := time.Now().Format("2006-01-02")
|
|
1045
|
+ // timeArr := strings.Split(timeStr, "-")
|
|
1046
|
+ // total, _ := service.FindAllWarehouseOut(adminUserInfo.Org.Id)
|
|
1047
|
+ // total = total + 1
|
|
1048
|
+ // warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
|
|
1049
|
+ // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
|
|
1050
|
+ // number = number + total
|
|
1051
|
+ // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
|
|
1052
|
+ //
|
|
1053
|
+ // medicalName, errc := service.GetSelfMedicalByDrugName(item.AdviceName, item.AdviceDesc, item.PatientId)
|
|
1054
|
+ // if errc == gorm.ErrRecordNotFound {
|
|
1055
|
+ //
|
|
1056
|
+ // } else if errc == nil {
|
|
1057
|
+ //
|
|
1058
|
+ // stock := models.XtSelfOutStock{
|
|
1059
|
+ // DrugName: item.AdviceName,
|
|
1060
|
+ // DrugNameId: medicalName.DrugNameId,
|
|
1061
|
+ // DrugSpec: item.AdviceDesc,
|
|
1062
|
+ // OutstoreNumber: outStoreNumber,
|
|
1063
|
+ // AdminUserId: adminUserInfo.AdminUser.Id,
|
|
1064
|
+ // StorckTime: item.AdviceDate,
|
|
1065
|
+ // UserOrgId: adminUserInfo.Org.Id,
|
|
1066
|
+ // CreatedTime: time.Now().Unix(),
|
|
1067
|
+ // Status: 1,
|
|
1068
|
+ // PatientId: item.PatientId,
|
|
1069
|
+ // StockOutNumber: warehousing_out_order,
|
|
1070
|
+ // ExitMode: 2,
|
|
1071
|
+ // MedicId: medicalName.ID,
|
|
1072
|
+ // }
|
|
1073
|
+ //
|
|
1074
|
+ // //创建出库单
|
|
1075
|
+ // service.CreateOutStock(&stock)
|
|
1076
|
+ //
|
|
1077
|
+ // c.ServeSuccessJSON(map[string]interface{}{
|
|
1078
|
+ // "msg": "ok",
|
|
1079
|
+ // "advice": advice,
|
|
1080
|
+ // "ids": ids,
|
|
1081
|
+ // })
|
|
1082
|
+ // return
|
|
1083
|
+ // }
|
|
1084
|
+ //
|
|
1085
|
+ // }
|
|
1086
|
+ // }
|
|
1087
|
+ //}
|
|
1088
|
+
|
724
|
1089
|
}
|
725
|
1090
|
func (c *PatientApiController) ModifyExecDoctorAdvice() {
|
726
|
1091
|
execution_time := c.GetString("execution_time")
|
|
@@ -1918,6 +2283,26 @@ func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (co
|
1918
|
2283
|
advice.AdviceDesc = adviceDsc
|
1919
|
2284
|
}
|
1920
|
2285
|
|
|
2286
|
+ if dataBody["src_type"] == nil {
|
|
2287
|
+ advice.Way = 0
|
|
2288
|
+
|
|
2289
|
+ } else {
|
|
2290
|
+ if dataBody["src_type"] != nil || reflect.TypeOf(dataBody["src_type"]).String() == "float64" {
|
|
2291
|
+ src_type := int64(dataBody["src_type"].(float64))
|
|
2292
|
+ advice.Way = src_type
|
|
2293
|
+ }
|
|
2294
|
+
|
|
2295
|
+ }
|
|
2296
|
+
|
|
2297
|
+ if dataBody["drug_id"] == nil {
|
|
2298
|
+ advice.DrugId = 0
|
|
2299
|
+ } else {
|
|
2300
|
+ if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
|
|
2301
|
+ drug_id := int64(dataBody["drug_id"].(float64))
|
|
2302
|
+ advice.DrugId = drug_id
|
|
2303
|
+ }
|
|
2304
|
+ }
|
|
2305
|
+
|
1921
|
2306
|
if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
|
1922
|
2307
|
singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
|
1923
|
2308
|
advice.SingleDose = singleDose
|
|
@@ -2619,6 +3004,30 @@ func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, jso
|
2619
|
3004
|
advice.Remark = remark
|
2620
|
3005
|
}
|
2621
|
3006
|
|
|
3007
|
+ //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
|
|
3008
|
+ // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
|
|
3009
|
+ // advice.Way = src_type
|
|
3010
|
+ //}
|
|
3011
|
+ if json["src_type"] == nil {
|
|
3012
|
+ advice.Way = 0
|
|
3013
|
+
|
|
3014
|
+ } else {
|
|
3015
|
+ if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
|
|
3016
|
+ src_type := int64(json["src_type"].(float64))
|
|
3017
|
+ advice.Way = src_type
|
|
3018
|
+ }
|
|
3019
|
+
|
|
3020
|
+ }
|
|
3021
|
+
|
|
3022
|
+ if json["drug_id"] == nil {
|
|
3023
|
+ advice.DrugId = 0
|
|
3024
|
+ } else {
|
|
3025
|
+ if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
|
|
3026
|
+ drug_id := int64(json["drug_id"].(float64))
|
|
3027
|
+ advice.DrugId = drug_id
|
|
3028
|
+ }
|
|
3029
|
+ }
|
|
3030
|
+
|
2622
|
3031
|
if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
|
2623
|
3032
|
drugSpecUnit, _ := json["drug_spec_unit"].(string)
|
2624
|
3033
|
advice.DrugSpecUnit = drugSpecUnit
|