Browse Source

自备药开发

XMLWAN 4 years ago
parent
commit
9a078bcc2e

+ 113 - 6
controllers/mobile_api_controllers/patient_api_controller.go View File

@@ -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() {

+ 50 - 0
controllers/new_mobile_api_controllers/new_self_drug_api_controller.go View File

@@ -0,0 +1,50 @@
1
+package new_mobile_api_controllers
2
+
3
+import (
4
+	"XT_New/controllers/mobile_api_controllers"
5
+	"XT_New/enums"
6
+	"XT_New/service"
7
+	"fmt"
8
+)
9
+
10
+type NewDrugApiController struct {
11
+	mobile_api_controllers.MobileBaseAPIAuthController
12
+}
13
+
14
+func (this *NewDrugApiController) GetSelfMedicalList() {
15
+
16
+	patient_id, _ := this.GetInt64("patient_id")
17
+	fmt.Println("222222222", patient_id)
18
+	adminUserInfo := this.GetMobileAdminUserInfo()
19
+	orgId := adminUserInfo.Org.Id
20
+	medical, _ := service.GetSetSelfMedical(orgId)
21
+	//开启
22
+	if medical.DrugStart == 1 {
23
+		list, err := service.GetSelfMedicalList(patient_id)
24
+		if err != nil {
25
+			this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取自备药失败")
26
+			return
27
+		}
28
+		this.ServeSuccessJSON(map[string]interface{}{
29
+			"medicalList": list,
30
+		})
31
+	}
32
+}
33
+
34
+func (this *NewDrugApiController) GetDrugDescByDrugName() {
35
+
36
+	drug_name := this.GetString("drug_name")
37
+	fmt.Println("drug_name", drug_name)
38
+	patient_id, _ := this.GetInt64("patient_id")
39
+	fmt.Println("patient_id", patient_id)
40
+	adminUserInfo := this.GetMobileAdminUserInfo()
41
+	orgId := adminUserInfo.Org.Id
42
+	drugspec, err := service.GetDrugDescByDrugName(drug_name, patient_id, orgId)
43
+	if err != nil {
44
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
45
+		return
46
+	}
47
+	this.ServeSuccessJSON(map[string]interface{}{
48
+		"drugspec": drugspec,
49
+	})
50
+}

+ 9 - 0
controllers/new_mobile_api_controllers/new_self_drug_api_router.go View File

@@ -0,0 +1,9 @@
1
+package new_mobile_api_controllers
2
+
3
+import "github.com/astaxie/beego"
4
+
5
+func NewDrugApiControllersRegisterRouters() {
6
+
7
+	beego.Router("/m/api/drug/getselfmedicallist", &NewDrugApiController{}, "Get:GetSelfMedicalList")
8
+	beego.Router("/m/api/getdrugdescbydrugname", &NewDrugApiController{}, "Get:GetDrugDescByDrugName")
9
+}

+ 33 - 24
controllers/patient_api_controller.go View File

@@ -6,6 +6,7 @@ import (
6 6
 	"XT_New/service"
7 7
 	"XT_New/utils"
8 8
 	"encoding/json"
9
+	"github.com/jinzhu/gorm"
9 10
 	"math"
10 11
 	"math/rand"
11 12
 	"reflect"
@@ -1578,31 +1579,39 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1578 1579
 		number = number + total
1579 1580
 		warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
1580 1581
 
1581
-		medicalName, _ := service.GetSelfMedicalByDrugName(adviceName.AdviceName, adviceName.AdviceDesc, adviceName.PatientId)
1582
-
1583
-		outStock := models.XtSelfOutStock{
1584
-			DrugName:       adviceName.AdviceName,
1585
-			DrugSpec:       adviceName.AdviceDesc,
1586
-			OutstoreNumber: outStoreNumber,
1587
-			AdminUserId:    adminUserInfo.AdminUser.Id,
1588
-			CreatedTime:    time.Now().Unix(),
1589
-			Status:         1,
1590
-			PatientId:      adviceName.PatientId,
1591
-			StockOutNumber: warehousing_out_order,
1592
-			ExitMode:       2,
1593
-			StorckTime:     adviceName.AdviceDate,
1594
-			MedicId:        medicalName.ID,
1595
-			DrugNameId:     medicalName.DrugNameId,
1596
-			UserOrgId:      adminUserInfo.CurrentOrgId,
1597
-		}
1598
-		//创建出库单,自动出库
1599
-		service.CreateOutStock(&outStock)
1582
+		medicalName, errcode := service.GetSelfMedicalByDrugName(adviceName.AdviceName, adviceName.AdviceDesc, adviceName.PatientId)
1583
+		if errcode == gorm.ErrRecordNotFound {
1584
+			c.ServeSuccessJSON(map[string]interface{}{
1585
+				"msg":    "ok",
1586
+				"advice": advice,
1587
+			})
1588
+			return
1589
+		} else if errcode == nil {
1590
+			outStock := models.XtSelfOutStock{
1591
+				DrugName:       adviceName.AdviceName,
1592
+				DrugSpec:       adviceName.AdviceDesc,
1593
+				OutstoreNumber: outStoreNumber,
1594
+				AdminUserId:    adminUserInfo.AdminUser.Id,
1595
+				CreatedTime:    time.Now().Unix(),
1596
+				Status:         1,
1597
+				PatientId:      adviceName.PatientId,
1598
+				StockOutNumber: warehousing_out_order,
1599
+				ExitMode:       2,
1600
+				StorckTime:     adviceName.AdviceDate,
1601
+				MedicId:        medicalName.ID,
1602
+				DrugNameId:     medicalName.DrugNameId,
1603
+				UserOrgId:      adminUserInfo.CurrentOrgId,
1604
+			}
1605
+			//创建出库单,自动出库
1606
+			service.CreateOutStock(&outStock)
1607
+			c.ServeSuccessJSON(map[string]interface{}{
1608
+				"msg":    "ok",
1609
+				"advice": advice,
1610
+			})
1611
+			return
1612
+		}
1600 1613
 	}
1601
-	c.ServeSuccessJSON(map[string]interface{}{
1602
-		"msg":    "ok",
1603
-		"advice": advice,
1604
-	})
1605
-	return
1614
+
1606 1615
 }
1607 1616
 
1608 1617
 func (c *PatientApiController) CheckGroupAdvice() {

+ 1 - 1
routers/router.go View File

@@ -66,6 +66,6 @@ func init() {
66 66
 	new_m_api.StaffScheduleApiControllersRegisterRouters()
67 67
 	controllers.DialysisPrameteRoutes()
68 68
 	new_m_api.DialysisParameterApiControllersRegisterRouters()
69
-
70 69
 	controllers.SelfDrugRouters()
70
+	new_m_api.NewDrugApiControllersRegisterRouters()
71 71
 }