|
@@ -7,6 +7,8 @@ import (
|
7
|
7
|
"XT_New/utils"
|
8
|
8
|
"encoding/json"
|
9
|
9
|
"fmt"
|
|
10
|
+ "github.com/jinzhu/gorm"
|
|
11
|
+ "math"
|
10
|
12
|
"strings"
|
11
|
13
|
|
12
|
14
|
// "fmt"
|
|
@@ -607,12 +609,117 @@ func (c *PatientApiController) ExecDoctorAdvice() {
|
607
|
609
|
advice.ExecutionState = 1
|
608
|
610
|
advice.Modifier = adminUserInfo.AdminUser.Id
|
609
|
611
|
|
610
|
|
- c.ServeSuccessJSON(map[string]interface{}{
|
611
|
|
- "msg": "ok",
|
612
|
|
- "advice": advice,
|
613
|
|
- "ids": ids,
|
614
|
|
- })
|
615
|
|
- return
|
|
612
|
+ //查询医嘱是否已经实行
|
|
613
|
+ if groupno > 0 {
|
|
614
|
+ advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
|
|
615
|
+ for _, item := range advices {
|
|
616
|
+ //如果医嘱已经执行生成自备药出库单
|
|
617
|
+ if item.ExecutionState == 1 {
|
|
618
|
+
|
|
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,
|
|
653
|
+ }
|
|
654
|
+
|
|
655
|
+ //创建出库单
|
|
656
|
+ service.CreateOutStock(&stock)
|
|
657
|
+
|
|
658
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
659
|
+ "msg": "ok",
|
|
660
|
+ "advice": advice,
|
|
661
|
+ "ids": ids,
|
|
662
|
+ })
|
|
663
|
+ return
|
|
664
|
+ }
|
|
665
|
+
|
|
666
|
+ }
|
|
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,
|
|
707
|
+ }
|
|
708
|
+
|
|
709
|
+ //创建出库单
|
|
710
|
+ service.CreateOutStock(&stock)
|
|
711
|
+
|
|
712
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
713
|
+ "msg": "ok",
|
|
714
|
+ "advice": advice,
|
|
715
|
+ "ids": ids,
|
|
716
|
+ })
|
|
717
|
+ return
|
|
718
|
+ }
|
|
719
|
+
|
|
720
|
+ }
|
|
721
|
+ }
|
|
722
|
+ }
|
616
|
723
|
|
617
|
724
|
}
|
618
|
725
|
func (c *PatientApiController) ModifyExecDoctorAdvice() {
|