Browse Source

合并代码

csx 4 years ago
parent
commit
40b8dc43e9

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

+ 0 - 1
controllers/new_mobile_api_controllers/dialysis_parameter_api_controller.go View File

@@ -32,7 +32,6 @@ func (this *DialysisParamerterApiController) GetMobileDialysisParameters() {
32 32
 	orgid := adminUserInfo.Org.Id
33 33
 	fmt.Println(orgid)
34 34
 	keywords := this.GetString("keyword")
35
-	fmt.Println("keyword099999999999---------------------------------", keywords)
36 35
 	start_time := this.GetString("start_time")
37 36
 	fmt.Println("start_time", start_time)
38 37
 	limit, _ := this.GetInt64("limit")

+ 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
+}

+ 54 - 5
controllers/patient_api_controller.go View File

@@ -6,6 +6,8 @@ import (
6 6
 	"XT_New/service"
7 7
 	"XT_New/utils"
8 8
 	"encoding/json"
9
+	"github.com/jinzhu/gorm"
10
+	"math"
9 11
 	"math/rand"
10 12
 	"reflect"
11 13
 	"regexp"
@@ -1510,11 +1512,13 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1510 1512
 	adminUserInfo := c.GetAdminUserInfo()
1511 1513
 
1512 1514
 	advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
1515
+
1513 1516
 	if advice.ID == 0 || advice.PatientId != patient {
1514 1517
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
1515 1518
 		return
1516 1519
 	}
1517 1520
 
1521
+	//医嘱已执行
1518 1522
 	if advice.ExecutionState == 1 {
1519 1523
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
1520 1524
 		return
@@ -1558,11 +1562,56 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1558 1562
 	advice.ExecutionTime = theTime.Unix()
1559 1563
 	// advice.Checker = checker
1560 1564
 
1561
-	c.ServeSuccessJSON(map[string]interface{}{
1562
-		"msg":    "ok",
1563
-		"advice": advice,
1564
-	})
1565
-	return
1565
+	adviceName, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
1566
+
1567
+	//如果医嘱已执行,生成自备药出库单
1568
+	if adviceName.ExecutionState == 1 {
1569
+		prescribingNumber := strconv.FormatFloat(math.Abs(adviceName.PrescribingNumber), 'f', 0, 64)
1570
+		outStoreNumber, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1571
+
1572
+		timeStr := time.Now().Format("2006-01-02")
1573
+		timeArr := strings.Split(timeStr, "-")
1574
+		total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
1575
+
1576
+		total = total + 1
1577
+		warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1578
+		number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1579
+		number = number + total
1580
+		warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
1581
+
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
+		}
1613
+	}
1614
+
1566 1615
 }
1567 1616
 
1568 1617
 func (c *PatientApiController) CheckGroupAdvice() {

+ 661 - 0
controllers/self_drug_api_congtroller.go View File

@@ -0,0 +1,661 @@
1
+package controllers
2
+
3
+import (
4
+	"XT_New/enums"
5
+	"XT_New/models"
6
+	"XT_New/service"
7
+	"encoding/json"
8
+	"fmt"
9
+	"github.com/astaxie/beego"
10
+	"github.com/jinzhu/gorm"
11
+	"strconv"
12
+	"strings"
13
+	"time"
14
+)
15
+
16
+type SelfDrugApiController struct {
17
+	BaseAuthAPIController
18
+}
19
+
20
+func SelfDrugRouters() {
21
+
22
+	beego.Router("/api/drug/getcurrentpatient", &SelfDrugApiController{}, "Get:GetCurrentPatient")
23
+	beego.Router("/api/drug/getalldrugname", &SelfDrugApiController{}, "Get:GetAllDrugName")
24
+	beego.Router("/api/drug/savedrugname", &SelfDrugApiController{}, "Get:SaveDrugName")
25
+	beego.Router("/api/drug/getdrugnamelist", &SelfDrugApiController{}, "Get:GetDrugNameList")
26
+	beego.Router("/api/drug/getrullename", &SelfDrugApiController{}, "Get:GetRulleName")
27
+	beego.Router("/api/drug/getunitbybaseid", &SelfDrugApiController{}, "Get:GetUnitByBaseId")
28
+	beego.Router("/api/drug/saverullename", &SelfDrugApiController{}, "Get:SaveRulleName")
29
+	beego.Router("/api/drug/editrullername", &SelfDrugApiController{}, "Get:EditRullerName")
30
+	beego.Router("/api/drug/updatedrullername", &SelfDrugApiController{}, "Get:UpdatedRullerName")
31
+	beego.Router("/api/drug/getalldrugnamelist", &SelfDrugApiController{}, "Get:GetAllDrugNameList")
32
+	beego.Router("/api/drug/getrulllistbydrugname", &SelfDrugApiController{}, "Get:GetRullerListByDrugName")
33
+	beego.Router("/api/drug/saveselfmedicines", &SelfDrugApiController{}, "Post:SaveSelfMedicines")
34
+	beego.Router("/api/drug/getcurrentorgallstaff", &SelfDrugApiController{}, "Get:GetCurrentOrgAllStaff")
35
+	beego.Router("/api/drug/savestock", &SelfDrugApiController{}, "Post:SaveStock")
36
+	beego.Router("/api/drug/saveoutstock", &SelfDrugApiController{}, "Post:SaveOutStock")
37
+	beego.Router("/api/drug/deletedrugbyid", &SelfDrugApiController{}, "Get:DeleteDrugById")
38
+	beego.Router("/api/drug/saveradio", &SelfDrugApiController{}, "Get:SaveRadio")
39
+	beego.Router("/api/drug/deletedrugstand", &SelfDrugApiController{}, "Get:DeleteDrugStand")
40
+	beego.Router("/api/drug/getstocklist", &SelfDrugApiController{}, "Get:GetStockList")
41
+	beego.Router("/api/drug/deletedrugname", &SelfDrugApiController{}, "Get:DeleteDrugName")
42
+	beego.Router("/api/drug/getdrugdetail", &SelfDrugApiController{}, "Get:GetDrugDetail")
43
+	beego.Router("/api/drug/getallpatientstocklist", &SelfDrugApiController{}, "Get:GetAllPatientStockList")
44
+	beego.Router("/api/drug/getdrugdatabypatientid", &SelfDrugApiController{}, "Get:GetDrugDataByPatientId")
45
+	beego.Router("/api/drug/getselfmedicallist", &SelfDrugApiController{}, "Get:GetSelfMedicalList")
46
+	beego.Router("/api/drug/getdrugdescbydrugname", &SelfDrugApiController{}, "Get:GetDrugDescByDrugName")
47
+}
48
+
49
+func (this *SelfDrugApiController) GetCurrentPatient() {
50
+
51
+	adminUserInfo := this.GetAdminUserInfo()
52
+	orgId := adminUserInfo.CurrentOrgId
53
+	patient, err := service.GetCurrentPatient(orgId)
54
+	if err != nil {
55
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
56
+		return
57
+	}
58
+	this.ServeSuccessJSON(map[string]interface{}{
59
+		"patient": patient,
60
+	})
61
+}
62
+
63
+func (this *SelfDrugApiController) GetAllDrugName() {
64
+
65
+	adminUserInfo := this.GetAdminUserInfo()
66
+	orgId := adminUserInfo.CurrentOrgId
67
+	drugName, err := service.GetAllDrugName(orgId)
68
+	if err != nil {
69
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
70
+		return
71
+	}
72
+	this.ServeSuccessJSON(map[string]interface{}{
73
+		"drugName": drugName,
74
+	})
75
+}
76
+
77
+func (this *SelfDrugApiController) SaveDrugName() {
78
+
79
+	adminUserInfo := this.GetAdminUserInfo()
80
+	orgId := adminUserInfo.CurrentOrgId
81
+	drug_name := this.GetString("drug_name")
82
+	fmt.Println("drug_name", drug_name)
83
+	drugName := models.XtDrugName{
84
+		UserOrgId:   orgId,
85
+		DrugName:    drug_name,
86
+		Status:      1,
87
+		CreatedTime: time.Now().Unix(),
88
+	}
89
+	_, errcode := service.GetDrugName(drug_name, orgId)
90
+	if errcode == gorm.ErrRecordNotFound {
91
+		err := service.SaveDrugName(&drugName)
92
+		if err != nil {
93
+			this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
94
+			return
95
+		}
96
+		this.ServeSuccessJSON(map[string]interface{}{
97
+			"drugName": drugName,
98
+		})
99
+	} else {
100
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
101
+		return
102
+	}
103
+}
104
+
105
+func (this *SelfDrugApiController) GetDrugNameList() {
106
+
107
+	adminUserInfo := this.GetAdminUserInfo()
108
+	orgId := adminUserInfo.CurrentOrgId
109
+	list, err := service.GetDrugNameList(orgId)
110
+	if err != nil {
111
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
112
+		return
113
+	}
114
+	this.ServeSuccessJSON(map[string]interface{}{
115
+		"list": list,
116
+	})
117
+}
118
+
119
+func (this *SelfDrugApiController) GetRulleName() {
120
+
121
+	adminUserInfo := this.GetAdminUserInfo()
122
+	orgId := adminUserInfo.CurrentOrgId
123
+	name := this.GetString("name")
124
+	rulleName, err := service.GetRulleName(orgId, name)
125
+	rullerList, err := service.GetRulleList(orgId, name)
126
+	if err != nil {
127
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
128
+		return
129
+	}
130
+	this.ServeSuccessJSON(map[string]interface{}{
131
+		"rulleName":  rulleName,
132
+		"rullerList": rullerList,
133
+	})
134
+}
135
+
136
+func (this *SelfDrugApiController) GetUnitByBaseId() {
137
+
138
+	id, _ := this.GetInt64("id")
139
+	baseList, err := service.GetUnitByBaseId(id)
140
+	if err != nil {
141
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
142
+		return
143
+	}
144
+	this.ServeSuccessJSON(map[string]interface{}{
145
+		"baseList": baseList,
146
+	})
147
+}
148
+
149
+func (this *SelfDrugApiController) SaveRulleName() {
150
+	drug_name := this.GetString("drug_name")
151
+	drug_spec := this.GetString("drug_spec")
152
+	drug_stock_limit := this.GetString("drug_stock_limit")
153
+	drug_name_id, _ := this.GetInt64("drug_name_id")
154
+	price, _ := this.GetInt64("price")
155
+	prices := strconv.FormatInt(price, 10)
156
+	durg_price, _ := strconv.ParseFloat(prices, 64)
157
+	unit := this.GetString("unit")
158
+	adminUserInfo := this.GetAdminUserInfo()
159
+	orgId := adminUserInfo.CurrentOrgId
160
+	fmt.Println(drug_name, drug_stock_limit, unit, price, drug_spec, orgId)
161
+	drugSpecName := models.XtStandName{
162
+		DrugName:       drug_name,
163
+		DrugSpec:       drug_spec,
164
+		DrugStockLimit: drug_stock_limit,
165
+		DrugNameId:     drug_name_id,
166
+		Price:          durg_price,
167
+		MinUnit:        unit,
168
+		UserOrgId:      orgId,
169
+		Status:         1,
170
+		CreatedTime:    time.Now().Unix(),
171
+	}
172
+
173
+	err := service.SaveRulleName(&drugSpecName)
174
+	if err != nil {
175
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
176
+		return
177
+	}
178
+	this.ServeSuccessJSON(map[string]interface{}{
179
+		"RullerName": drugSpecName,
180
+	})
181
+}
182
+
183
+func (this *SelfDrugApiController) EditRullerName() {
184
+
185
+	id, _ := this.GetInt64("id")
186
+	rullerDetail, err := service.GetRullerNameDetail(id)
187
+	if err != nil {
188
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
189
+		return
190
+	}
191
+	this.ServeSuccessJSON(map[string]interface{}{
192
+		"rullerDetail": rullerDetail,
193
+	})
194
+}
195
+
196
+func (this *SelfDrugApiController) UpdatedRullerName() {
197
+
198
+	id, _ := this.GetInt64("id")
199
+	drug_name := this.GetString("drug_name")
200
+	drug_stock_limit := this.GetString("drug_stock_limit")
201
+	price, _ := this.GetInt64("price")
202
+	prices := strconv.FormatInt(price, 10)
203
+	durg_price, _ := strconv.ParseFloat(prices, 64)
204
+
205
+	drug_spec := this.GetString("drug_spec")
206
+	unit := this.GetString("unit")
207
+	drug_name_id, _ := this.GetInt64("drug_name_id")
208
+	RullerName := models.XtStandName{
209
+		DrugName:       drug_name,
210
+		DrugStockLimit: drug_stock_limit,
211
+		Price:          durg_price,
212
+		DrugSpec:       drug_spec,
213
+		MinUnit:        unit,
214
+		DrugNameId:     drug_name_id,
215
+	}
216
+
217
+	err := service.UpdatedRullerName(id, &RullerName)
218
+	if err != nil {
219
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
220
+		return
221
+	}
222
+	this.ServeSuccessJSON(map[string]interface{}{
223
+		"RullerName": RullerName,
224
+	})
225
+}
226
+
227
+func (this *SelfDrugApiController) GetAllDrugNameList() {
228
+
229
+	adminUserInfo := this.GetAdminUserInfo()
230
+	orgId := adminUserInfo.CurrentOrgId
231
+	rullerName, err := service.GetAllDrugNameList(orgId)
232
+
233
+	if err != nil {
234
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
235
+		return
236
+	}
237
+	this.ServeSuccessJSON(map[string]interface{}{
238
+		"rullerName": rullerName,
239
+	})
240
+}
241
+
242
+func (this *SelfDrugApiController) GetRullerListByDrugName() {
243
+
244
+	drug_name := this.GetString("drug_name")
245
+	fmt.Println(drug_name)
246
+	adminUserInfo := this.GetAdminUserInfo()
247
+	orgId := adminUserInfo.CurrentOrgId
248
+	fmt.Println("orgid", orgId)
249
+	drugName, err := service.GetRullerListByDrugName(drug_name, orgId)
250
+	if err != nil {
251
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
252
+		return
253
+	}
254
+	this.ServeSuccessJSON(map[string]interface{}{
255
+		"drugName": drugName,
256
+	})
257
+}
258
+
259
+func (this *SelfDrugApiController) SaveSelfMedicines() {
260
+
261
+	dataBody := make(map[string]interface{}, 0)
262
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
263
+	fmt.Println(err)
264
+	patient_id := int64(dataBody["patient_id"].(float64))
265
+	medicineData, _ := dataBody["medicineData"].([]interface{})
266
+	adminUserInfo := this.GetAdminUserInfo()
267
+	orgId := adminUserInfo.CurrentOrgId
268
+	for _, item := range medicineData {
269
+		items := item.(map[string]interface{})
270
+		drug_name := items["drug_name"].(string)
271
+		id := int64(items["id"].(float64))
272
+		drug_spec := items["drug_spec"].(string)
273
+		min_unit := items["min_unit"].(string)
274
+		medical := models.XtSelfMedical{
275
+			DrugName:    drug_name,
276
+			DrugNameId:  id,
277
+			DrugSpec:    drug_spec,
278
+			CreatedTime: time.Now().Unix(),
279
+			Status:      1,
280
+			UserOrgId:   orgId,
281
+			PatientId:   patient_id,
282
+			MinUnit:     min_unit,
283
+		}
284
+		//查询同个病人同个药品同个规格是否已存在
285
+		_, errcode := service.GetSelfMedicalByDrugName(drug_name, drug_spec, patient_id)
286
+
287
+		if errcode == gorm.ErrRecordNotFound {
288
+			err := service.CreateSelfMedical(&medical)
289
+			fmt.Println(err)
290
+		} else if errcode == nil {
291
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
292
+			return
293
+		}
294
+
295
+	}
296
+	returnData := make(map[string]interface{}, 0)
297
+	returnData["msg"] = "ok"
298
+	this.ServeSuccessJSON(returnData)
299
+	return
300
+}
301
+
302
+func (this *SelfDrugApiController) GetCurrentOrgAllStaff() {
303
+
304
+	adminUserInfo := this.GetAdminUserInfo()
305
+	orgid := adminUserInfo.CurrentOrgId
306
+	//fmt.Println(orgid)
307
+	appId := adminUserInfo.CurrentAppId
308
+	staff, err := service.GetCurrentOrgAllStaff(orgid, appId)
309
+	if err != nil {
310
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
311
+		return
312
+	}
313
+	this.ServeSuccessJSON(map[string]interface{}{
314
+		"staff": staff,
315
+	})
316
+}
317
+
318
+func (this *SelfDrugApiController) SaveStock() {
319
+
320
+	timeLayout := "2006-01-02"
321
+	loc, _ := time.LoadLocation("Local")
322
+	start_time := this.GetString("start_time")
323
+	fmt.Println("start_time", start_time)
324
+	admin_user_id, _ := this.GetInt64("admin_user_id")
325
+	fmt.Println("admin_user_id", admin_user_id)
326
+	patient_id, _ := this.GetInt64("patient_id")
327
+	dataBody := make(map[string]interface{}, 0)
328
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
329
+	fmt.Println(err)
330
+	stocks, _ := dataBody["stocks"].([]interface{})
331
+	adminUserInfo := this.GetAdminUserInfo()
332
+	orgId := adminUserInfo.CurrentOrgId
333
+	for _, item := range stocks {
334
+		items := item.(map[string]interface{})
335
+		drug_name := items["drug_name"].(string)
336
+		fmt.Println("drug_name", drug_name)
337
+		drug_name_id := int64(items["drug_name_id"].(float64))
338
+		fmt.Println("parient_id", drug_name_id)
339
+		drug_spec := items["drug_spec"].(string)
340
+		store_number := items["store_number"].(string)
341
+		fmt.Println("store_number", store_number)
342
+		storeNumber, _ := strconv.ParseInt(store_number, 10, 64)
343
+		remarks := items["remarks"].(string)
344
+		min_unit := items["min_unit"].(string)
345
+		medic_id := int64(items["id"].(float64))
346
+		timeStr := time.Now().Format("2006-01-02")
347
+		timeArr := strings.Split(timeStr, "-")
348
+		total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
349
+
350
+		total = total + 1
351
+		warehousing_in_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
352
+		number, _ := strconv.ParseInt(warehousing_in_order, 10, 64)
353
+		number = number + total
354
+		warehousing_in_order = "RKD" + strconv.FormatInt(number, 10)
355
+
356
+		theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
357
+		stock := models.XtSelfStock{
358
+			DrugName:      drug_name,
359
+			DrugNameId:    drug_name_id,
360
+			DrugSpec:      drug_spec,
361
+			StoreNumber:   storeNumber,
362
+			Remarks:       remarks,
363
+			AdminUserId:   admin_user_id,
364
+			StorckTime:    theTime.Unix(),
365
+			CreatedTime:   time.Now().Unix(),
366
+			Status:        1,
367
+			UserOrgId:     orgId,
368
+			StockInNumber: warehousing_in_order,
369
+			PatientId:     patient_id,
370
+			MinUnit:       min_unit,
371
+			StorageMode:   1,
372
+			MedicId:       medic_id,
373
+		}
374
+		err := service.CreateStock(&stock)
375
+		fmt.Println("err", err)
376
+	}
377
+	returnData := make(map[string]interface{}, 0)
378
+	returnData["msg"] = "ok"
379
+	this.ServeSuccessJSON(returnData)
380
+	return
381
+}
382
+
383
+func (this *SelfDrugApiController) SaveOutStock() {
384
+
385
+	timeLayout := "2006-01-02"
386
+	loc, _ := time.LoadLocation("Local")
387
+	start_time := this.GetString("start_time")
388
+	admin_user_id, _ := this.GetInt64("admin_user_id")
389
+	patient_id, _ := this.GetInt64("patient_id")
390
+	dataBody := make(map[string]interface{}, 0)
391
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
392
+	fmt.Println(err)
393
+	outStocks, _ := dataBody["outStocks"].([]interface{})
394
+	adminUserInfo := this.GetAdminUserInfo()
395
+	orgId := adminUserInfo.CurrentOrgId
396
+
397
+	for _, item := range outStocks {
398
+		items := item.(map[string]interface{})
399
+		drug_name := items["drug_name"].(string)
400
+		drug_name_id := int64(items["drug_name_id"].(float64))
401
+		drug_spec := items["drug_spec"].(string)
402
+		outstore_number := items["outstore_number"].(string)
403
+		outStoreNumber, _ := strconv.ParseInt(outstore_number, 10, 64)
404
+		remarks := items["remarks"].(string)
405
+		medic_id := int64(items["id"].(float64))
406
+		timeStr := time.Now().Format("2006-01-02")
407
+		timeArr := strings.Split(timeStr, "-")
408
+		total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
409
+
410
+		total = total + 1
411
+		warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
412
+		number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
413
+		number = number + total
414
+		warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
415
+		fmt.Println(remarks)
416
+		fmt.Println(items)
417
+		theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
418
+		stock := models.XtSelfOutStock{
419
+			DrugName:       drug_name,
420
+			DrugNameId:     drug_name_id,
421
+			DrugSpec:       drug_spec,
422
+			OutstoreNumber: outStoreNumber,
423
+			Remarks:        remarks,
424
+			AdminUserId:    admin_user_id,
425
+			StorckTime:     theTime.Unix(),
426
+			CreatedTime:    time.Now().Unix(),
427
+			Status:         1,
428
+			UserOrgId:      orgId,
429
+			StockOutNumber: warehousing_out_order,
430
+			PatientId:      patient_id,
431
+			ExitMode:       1,
432
+			MedicId:        medic_id,
433
+		}
434
+		err := service.CreateOutStock(&stock)
435
+		fmt.Println("err", err)
436
+	}
437
+	returnData := make(map[string]interface{}, 0)
438
+	returnData["msg"] = "ok"
439
+	this.ServeSuccessJSON(returnData)
440
+	return
441
+}
442
+
443
+func (this *SelfDrugApiController) DeleteDrugById() {
444
+	id, _ := this.GetInt64("id")
445
+	drug_name := this.GetString("drug_name")
446
+	fmt.Println("drug_name", drug_name)
447
+	adminUserInfo := this.GetAdminUserInfo()
448
+	orgId := adminUserInfo.CurrentOrgId
449
+
450
+	_, errcode := service.GetStandDrugByDrugName(drug_name, orgId)
451
+	fmt.Println("errcode", errcode)
452
+	if errcode == gorm.ErrRecordNotFound {
453
+		service.DeleteDrugName(id)
454
+		returnData := make(map[string]interface{}, 0)
455
+		returnData["msg"] = "ok"
456
+		this.ServeSuccessJSON(returnData)
457
+	} else if errcode == nil {
458
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
459
+		return
460
+	}
461
+}
462
+
463
+func (this *SelfDrugApiController) SaveRadio() {
464
+
465
+	radio, _ := this.GetInt64("radio")
466
+	adminUserInfo := this.GetAdminUserInfo()
467
+	orgId := adminUserInfo.CurrentOrgId
468
+	drugSet := models.XtDrugSet{
469
+		DrugStart:   radio,
470
+		UserOrgId:   orgId,
471
+		Status:      1,
472
+		CreatedTime: time.Now().Unix(),
473
+	}
474
+	_, errcode := service.GetDrugSetByUserOrgId(orgId)
475
+	if errcode == gorm.ErrRecordNotFound {
476
+		err := service.SaveRadio(&drugSet)
477
+		if err != nil {
478
+			this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
479
+			return
480
+		}
481
+		this.ServeSuccessJSON(map[string]interface{}{
482
+			"drugSet": drugSet,
483
+		})
484
+	} else if errcode == nil {
485
+		err := service.UpdateDrugSet(&drugSet, orgId)
486
+		if err != nil {
487
+			this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
488
+			return
489
+		}
490
+		this.ServeSuccessJSON(map[string]interface{}{
491
+			"drugSet": drugSet,
492
+		})
493
+	}
494
+
495
+}
496
+
497
+func (this *SelfDrugApiController) DeleteDrugStand() {
498
+
499
+	id, _ := this.GetInt64("id")
500
+	err := service.DeleteDrugStand(id)
501
+	fmt.Println(err)
502
+	returnData := make(map[string]interface{}, 0)
503
+	returnData["msg"] = "ok"
504
+	this.ServeSuccessJSON(returnData)
505
+}
506
+
507
+func (this *SelfDrugApiController) GetStockList() {
508
+
509
+	patientid, _ := this.GetInt64("id")
510
+	start_time := this.GetString("start_time")
511
+	fmt.Println("开始时间", start_time)
512
+	timeLayout := "2006-01-02"
513
+	loc, _ := time.LoadLocation("Local")
514
+	theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
515
+	startimeUnix := theTime.Unix()
516
+	keyword := this.GetString("keyword")
517
+	fmt.Println("keyword", keyword)
518
+	//统计总数量
519
+	stocklist, err := service.GetStockList(patientid, startimeUnix, keyword)
520
+
521
+	//统计出库数量
522
+	outStocklist, err := service.GetOutStockList(patientid, startimeUnix, keyword)
523
+	if err != nil {
524
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
525
+		return
526
+	}
527
+	this.ServeSuccessJSON(map[string]interface{}{
528
+		"stocklist":    stocklist,
529
+		"outStocklist": outStocklist,
530
+	})
531
+}
532
+
533
+func (this *SelfDrugApiController) DeleteDrugName() {
534
+
535
+	drug_name := this.GetString("drugname")
536
+	patient_id, _ := this.GetInt64("patientid")
537
+
538
+	//查询该药品是否出库
539
+	stocklist, _ := service.GetStockOutDetail(drug_name, patient_id)
540
+	if len(stocklist) == 0 {
541
+		//删除该药品
542
+		service.DeleteDrugStockNumber(drug_name, patient_id)
543
+		returnData := make(map[string]interface{}, 0)
544
+		returnData["msg"] = "ok"
545
+		this.ServeSuccessJSON(returnData)
546
+	} else {
547
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
548
+		return
549
+	}
550
+}
551
+
552
+func (this *SelfDrugApiController) GetDrugDetail() {
553
+
554
+	timeLayout := "2006-01-02"
555
+	loc, _ := time.LoadLocation("Local")
556
+	drug_name := this.GetString("drug_name")
557
+	drug_spec := this.GetString("drug_spec")
558
+	start_time := this.GetString("start_time")
559
+	startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
560
+	end_time := this.GetString("end_time")
561
+	endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
562
+	patient_id, _ := this.GetInt64("patient_id")
563
+	adminUserInfo := this.GetAdminUserInfo()
564
+	orgId := adminUserInfo.CurrentOrgId
565
+	//查询入库明细
566
+	stockDetail, err := service.GetStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
567
+
568
+	//查询出库明细
569
+	outStockDetail, err := service.GetOutStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
570
+	if err != nil {
571
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
572
+		return
573
+	}
574
+	this.ServeSuccessJSON(map[string]interface{}{
575
+		"stockDetail":    stockDetail,
576
+		"outStockDetail": outStockDetail,
577
+	})
578
+}
579
+
580
+func (this *SelfDrugApiController) GetAllPatientStockList() {
581
+
582
+	timeLayout := "2006-01-02"
583
+	loc, _ := time.LoadLocation("Local")
584
+	drug_name := this.GetString("drug_name")
585
+	drug_spec := this.GetString("drug_spec")
586
+	start_time := this.GetString("start_time")
587
+	theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
588
+	startUnix := theTime.Unix()
589
+	end_time := this.GetString("end_time")
590
+	endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
591
+	endTimeUnix := endTimes.Unix()
592
+	keywords := this.GetString("search_input")
593
+	adminUserInfo := this.GetAdminUserInfo()
594
+	orgId := adminUserInfo.CurrentOrgId
595
+
596
+	//入库
597
+	stocklist, err := service.GetAllPatientStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
598
+
599
+	//出库
600
+	outStockList, err := service.GetAllPatientOutStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
601
+	if err != nil {
602
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
603
+		return
604
+	}
605
+	this.ServeSuccessJSON(map[string]interface{}{
606
+		"stocklist":    stocklist,
607
+		"outStockList": outStockList,
608
+	})
609
+}
610
+
611
+func (this *SelfDrugApiController) GetDrugDataByPatientId() {
612
+
613
+	patient_id, _ := this.GetInt64("patient_id")
614
+	fmt.Println("patient_id", patient_id)
615
+	medicalList, err := service.GetDrugDataByPatientId(patient_id)
616
+	if err != nil {
617
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
618
+		return
619
+	}
620
+	this.ServeSuccessJSON(map[string]interface{}{
621
+		"medicalList": medicalList,
622
+	})
623
+}
624
+
625
+func (this *SelfDrugApiController) GetSelfMedicalList() {
626
+
627
+	patient_id, _ := this.GetInt64("patient_id")
628
+	adminUserInfo := this.GetAdminUserInfo()
629
+	orgId := adminUserInfo.CurrentOrgId
630
+	//查询该机构是否开启自备药
631
+	medical, _ := service.GetSetSelfMedical(orgId)
632
+	//开启
633
+	if medical.DrugStart == 1 {
634
+		list, err := service.GetSelfMedicalList(patient_id)
635
+		if err != nil {
636
+			this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
637
+			return
638
+		}
639
+		this.ServeSuccessJSON(map[string]interface{}{
640
+			"medicalList": list,
641
+		})
642
+	}
643
+}
644
+
645
+func (this *SelfDrugApiController) GetDrugDescByDrugName() {
646
+
647
+	drug_name := this.GetString("drug_name")
648
+	fmt.Println("drug_name", drug_name)
649
+	patient_id, _ := this.GetInt64("patient_id")
650
+	fmt.Println("patient_id", patient_id)
651
+	adminUserInfo := this.GetAdminUserInfo()
652
+	orgId := adminUserInfo.CurrentOrgId
653
+	drugspec, err := service.GetDrugDescByDrugName(drug_name, patient_id, orgId)
654
+	if err != nil {
655
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
656
+		return
657
+	}
658
+	this.ServeSuccessJSON(map[string]interface{}{
659
+		"drugspec": drugspec,
660
+	})
661
+}

+ 6 - 13
controllers/sign_weigh_api_controller.go View File

@@ -403,7 +403,7 @@ func (c *SignWeighAPIController) EditData() {
403 403
 }
404 404
 
405 405
 func (c *SignWeighAPIController) Sighdata() {
406
-	fmt.Println("哈哈哈哈哈哈哈哈哈哈")
406
+
407 407
 	patientID, _ := c.GetInt64("patient_id", 0)
408 408
 	fmt.Println("patientID", patientID)
409 409
 	dateTime := c.GetString("date_time")
@@ -417,11 +417,9 @@ func (c *SignWeighAPIController) Sighdata() {
417 417
 		return
418 418
 	}
419 419
 	dateTimeStam := theTime.Unix()
420
-	fmt.Println("datatimestam是什么", dateTimeStam)
421 420
 	adminUserInfo := c.GetAdminUserInfo()
422
-	fmt.Println(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)
423 421
 	sign, errord := service.GetSign(adminUserInfo.CurrentOrgId, dateTimeStam, patientID)
424
-	fmt.Println("sigh是什么东西", sign)
422
+	fmt.Println("sign", sign)
425 423
 	fmt.Println(err)
426 424
 	weighbefore, _ := c.GetFloat("weight_before", 0)
427 425
 	dryweightbefore, _ := c.GetFloat("dry_weight", 0)
@@ -436,9 +434,6 @@ func (c *SignWeighAPIController) Sighdata() {
436 434
 	breathingrateafter, _ := c.GetFloat("breathing_rateafter", 0)
437 435
 	systolicbloodpressureafter, _ := c.GetFloat("systolic_blood_pressureafter", 0)
438 436
 	diastolicbloodpressureafter, _ := c.GetFloat("diastolic_blood_pressureafter", 0)
439
-	fmt.Println("请查看数据")
440
-	fmt.Println("透前称重:", weighbefore, "干体重:", dryweightbefore, "透前温度", temperaturebefore, "透前脉搏", pulsefrequencybefore, "透前呼吸", breathinratebefore, "透前舒张压", systolicbloodpressurebefore, "透前伸缩呀", diastorlicbloodpressurebefore)
441
-	fmt.Println("透后体重", weightafter, "透后温度", temperatureafter, "透后脉搏", pulsefrequencyafter, "透后呼吸", breathingrateafter, "透后舒张压", systolicbloodpressureafter, "透后圣索亚", diastolicbloodpressureafter)
442 437
 
443 438
 	var sighForm models.SignWeight
444 439
 
@@ -469,21 +464,19 @@ func (c *SignWeighAPIController) Sighdata() {
469 464
 	if sighForm.WeightAfter > 0 {
470 465
 		sighForm.WeighTime = time.Now().Unix()
471 466
 	}
472
-	fmt.Println("sightForm是什么", sighForm)
467
+
473 468
 	if errord == gorm.ErrRecordNotFound {
474
-		fmt.Println("aaaaaaaaaaaaaa")
469
+
475 470
 		savesignweigh := service.Savesignweigh(&sighForm)
476 471
 		fmt.Println("savesignweight", savesignweigh)
477 472
 		c.ServeSuccessJSON(map[string]interface{}{
478 473
 			"signs": sighForm,
479 474
 		})
480
-		//signweigh := service.GetSignweigh(adminUserInfo.CurrentOrgId, patientID)
481
-		//fmt.Println("signweigh是什么?",signweigh)
482
-		fmt.Println(sighForm)
475
+
483 476
 	} else if errord == nil {
484 477
 		service.Updatesignweigh(&sighForm, patientID, adminUserInfo.CurrentOrgId)
485 478
 	} else {
486
-		fmt.Println("ccccccccccccc")
479
+
487 480
 		service.Updatesignweigh(&sighForm, patientID, adminUserInfo.CurrentOrgId)
488 481
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
489 482
 	}

+ 27 - 0
models/dialysis.go View File

@@ -759,6 +759,33 @@ type XtDialysisOrder struct {
759 759
 	WashpipeNurse  int64  `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
760 760
 }
761 761
 
762
+type XtDialysisOrders struct {
763
+	ID             int64  `gorm:"column:id" json:"id" form:"id"`
764
+	DialysisDate   int64  `gorm:"column:dialysis_date" json:"dialysis_date" form:"dialysis_date"`
765
+	UserOrgId      int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
766
+	PatientId      int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
767
+	PrescriptionId int64  `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
768
+	Stage          int64  `gorm:"column:stage" json:"stage" form:"stage"`
769
+	Remark         string `gorm:"column:remark" json:"remark" form:"remark"`
770
+	BedId          int64  `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
771
+	StartNurse     int64  `gorm:"column:start_nurse" json:"start_nurse" form:"start_nurse"`
772
+	FinishNurse    int64  `gorm:"column:finish_nurse" json:"finish_nurse" form:"finish_nurse"`
773
+	Status         int64  `gorm:"column:status" json:"status" form:"status"`
774
+	CreatedTime    int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
775
+	UpdatedTime    int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
776
+	StartTime      int64  `gorm:"column:start_time" json:"start_time" form:"start_time"`
777
+	EndTime        int64  `gorm:"column:end_time" json:"end_time" form:"end_time"`
778
+	PunctureNurse  int64  `gorm:"column:puncture_nurse" json:"puncture_nurse" form:"puncture_nurse"`
779
+	Creator        int64  `gorm:"column:creator" json:"creator" form:"creator"`
780
+	Modifier       int64  `gorm:"column:modifier" json:"modifier" form:"modifier"`
781
+	FinishCreator  int64  `gorm:"column:finish_creator" json:"finish_creator" form:"finish_creator"`
782
+	FinishModifier int64  `gorm:"column:finish_modifier" json:"finish_modifier" form:"finish_modifier"`
783
+	SchedualType   int64  `gorm:"column:schedual_type" json:"schedual_type" form:"schedual_type"`
784
+	Number         int64  `gorm:"column:number" json:"number" form:"number"`
785
+	UserName       int64  `gorm:"column:user_name" json:"user_name" form:"user_name"`
786
+	WashpipeNurse  int64  `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
787
+}
788
+
762 789
 func (XtDialysisOrder) TableName() string {
763 790
 	return "xt_dialysis_order"
764 791
 }

+ 222 - 0
models/self_drug_models.go View File

@@ -0,0 +1,222 @@
1
+package models
2
+
3
+type DrugPatients struct {
4
+	ID          int64  `gorm:"column:id" json:"id" form:"id"`
5
+	UserOrgId   int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
6
+	Name        string `gorm:"column:name" json:"name" form:"name"`
7
+	DialysisNo  string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
8
+	Status      int64  `gorm:"column:status" json:"status" form:"status"`
9
+	CreatedTime int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
10
+}
11
+
12
+func (DrugPatients) TableName() string {
13
+	return "xt_patients"
14
+}
15
+
16
+type XtBaseDrug struct {
17
+	ID                     int64   `gorm:"column:id" json:"id" form:"id"`
18
+	DrugName               string  `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
19
+	Pinyin                 string  `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
20
+	Wubi                   string  `gorm:"column:wubi" json:"wubi" form:"wubi"`
21
+	DrugAlias              string  `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
22
+	DrugAliasPinyin        string  `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
23
+	DrugAliasWubi          string  `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
24
+	DrugCategory           int64   `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
25
+	DrugSpec               string  `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
26
+	DrugType               int64   `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
27
+	DrugStockLimit         string  `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
28
+	DrugOriginPlace        string  `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
29
+	DrugDosageForm         int64   `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
30
+	MedicalInsuranceLevel  int64   `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
31
+	MaxUnit                string  `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
32
+	MinUnit                string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
33
+	UnitMatrixing          string  `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
34
+	RetailPrice            float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
35
+	LastPrice              float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
36
+	DrugControl            int64   `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
37
+	Number                 string  `gorm:"column:number" json:"number" form:"number"`
38
+	DrugClassify           string  `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
39
+	DrugDose               float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
40
+	DrugDoseUnit           int64   `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
41
+	MedicalInsuranceNumber string  `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
42
+	Manufacturer           int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
43
+	PharmacologyCategory   int64   `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
44
+	StatisticsCategory     int64   `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
45
+	Code                   string  `gorm:"column:code" json:"code" form:"code"`
46
+	IsSpecialDiseases      int64   `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
47
+	IsRecord               int64   `gorm:"column:is_record" json:"is_record" form:"is_record"`
48
+	Agent                  int64   `gorm:"column:agent" json:"agent" form:"agent"`
49
+	DrugStatus             string  `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
50
+	LimitRemark            string  `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
51
+	DeliveryWay            string  `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
52
+	ExecutionFrequency     string  `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
53
+	SingleDose             float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
54
+	PrescribingNumber      float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
55
+	Label                  int64   `gorm:"column:label" json:"label" form:"label"`
56
+	Sort                   int64   `gorm:"column:sort" json:"sort" form:"sort"`
57
+	IsUseDoctorAdvice      int64   `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
58
+	IsDefault              int64   `gorm:"column:is_default" json:"is_default" form:"is_default"`
59
+	IsChargePredict        int64   `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
60
+	IsStatisticsWork       int64   `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
61
+	IsChargeUse            int64   `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
62
+	Status                 int64   `gorm:"column:status" json:"status" form:"status"`
63
+	Ctime                  int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
64
+	Mtime                  int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
65
+	OrgId                  int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
66
+}
67
+
68
+func (XtBaseDrug) TableName() string {
69
+	return "xt_base_drug"
70
+}
71
+
72
+type XtDrugName struct {
73
+	ID          int64  `gorm:"column:id" json:"id" form:"id"`
74
+	DrugName    string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
75
+	UserOrgId   int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
76
+	Status      int64  `gorm:"column:status" json:"status" form:"status"`
77
+	CreatedTime int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
78
+	UpdatedTime int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
79
+	ParentId    int64  `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
80
+}
81
+
82
+func (XtDrugName) TableName() string {
83
+	return "xt_drug_name"
84
+}
85
+
86
+type XtStandName struct {
87
+	ID             int64   `gorm:"column:id" json:"id" form:"id"`
88
+	DrugSpec       string  `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
89
+	MinUnit        string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
90
+	Price          float64 `gorm:"column:price" json:"price" form:"price"`
91
+	DrugStockLimit string  `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
92
+	DrugNameId     int64   `gorm:"column:drug_name_id" json:"drug_name_id" form:"drug_name_id"`
93
+	UserOrgId      int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
94
+	Status         int64   `gorm:"column:status" json:"status" form:"status"`
95
+	CreatedTime    int64   `gorm:"column:created_time" json:"created_time" form:"created_time"`
96
+	UpdatedTime    int64   `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
97
+	DrugName       string  `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
98
+}
99
+
100
+func (XtStandName) TableName() string {
101
+	return "xt_stand_name"
102
+}
103
+
104
+type XtSelfMedical struct {
105
+	DrugName    string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
106
+	ID          int64  `gorm:"column:id" json:"id" form:"id"`
107
+	DrugSpec    string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
108
+	PatientId   int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
109
+	DrugNameId  int64  `gorm:"column:drug_name_id" json:"drug_name_id" form:"drug_name_id"`
110
+	Status      int64  `gorm:"column:status" json:"status" form:"status"`
111
+	UserOrgId   int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
112
+	CreatedTime int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
113
+	UpdatedTime int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
114
+	MinUnit     string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
115
+}
116
+
117
+func (XtSelfMedical) TableName() string {
118
+	return "xt_self_medical"
119
+}
120
+
121
+type XtSelfStock struct {
122
+	ID            int64  `gorm:"column:id" json:"id" form:"id"`
123
+	DrugName      string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
124
+	DrugNameId    int64  `gorm:"column:drug_name_id" json:"drug_name_id" form:"drug_name_id"`
125
+	DrugSpec      string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
126
+	Remarks       string `gorm:"column:remarks" json:"remarks" form:"remarks"`
127
+	StoreNumber   int64  `gorm:"column:store_number" json:"store_number" form:"store_number"`
128
+	AdminUserId   int64  `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
129
+	StorckTime    int64  `gorm:"column:storck_time" json:"storck_time" form:"storck_time"`
130
+	UserOrgId     int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
131
+	CreatedTime   int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
132
+	UpdatedTime   int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
133
+	Status        int64  `gorm:"column:status" json:"status" form:"status"`
134
+	StockInNumber string `gorm:"column:stock_in_number" json:"stock_in_number" form:"stock_in_number"`
135
+	PatientId     int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
136
+	MinUnit       string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
137
+	StorageMode   int64  `gorm:"column:storage_mode" json:"storage_mode" form:"storage_mode"`
138
+	MedicId       int64  `gorm:"column:medic_id" json:"medic_id" form:"medic_id"`
139
+}
140
+
141
+func (XtSelfStock) TableName() string {
142
+	return "xt_self_stock"
143
+}
144
+
145
+type XtSelfOutStock struct {
146
+	ID             int64  `gorm:"column:id" json:"id" form:"id"`
147
+	DrugName       string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
148
+	DrugNameId     int64  `gorm:"column:drug_name_id" json:"drug_name_id" form:"drug_name_id"`
149
+	DrugSpec       string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
150
+	Remarks        string `gorm:"column:remarks" json:"remarks" form:"remarks"`
151
+	OutstoreNumber int64  `gorm:"column:outstore_number" json:"outstore_number" form:"outstore_number"`
152
+	AdminUserId    int64  `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
153
+	StorckTime     int64  `gorm:"column:storck_time" json:"storck_time" form:"storck_time"`
154
+	UserOrgId      int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
155
+	CreatedTime    int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
156
+	UpdatedTime    int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
157
+	Status         int64  `gorm:"column:status" json:"status" form:"status"`
158
+	PatientId      int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
159
+	StockOutNumber string `gorm:"column:stock_out_number" json:"stock_out_number" form:"stock_out_number"`
160
+	ExitMode       int64  `gorm:"column:exit_mode" json:"exit_mode" form:"exit_mode"`
161
+	MedicId        int64  `gorm:"column:medic_id" json:"medic_id" form:"medic_id"`
162
+}
163
+
164
+func (XtSelfOutStock) TableName() string {
165
+	return "xt_self_out_stock"
166
+}
167
+
168
+type XtDrugSet struct {
169
+	ID          int64 `gorm:"column:id" json:"id" form:"id"`
170
+	DrugStart   int64 `gorm:"column:drug_start" json:"drug_start" form:"drug_start"`
171
+	UserOrgId   int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
172
+	Status      int64 `gorm:"column:status" json:"status" form:"status"`
173
+	CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
174
+	UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
175
+}
176
+
177
+func (XtDrugSet) TableName() string {
178
+	return "xt_drug_set"
179
+}
180
+
181
+type SelfStocks struct {
182
+	ID            int64  `gorm:"column:id" json:"id" form:"id"`
183
+	DrugName      string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
184
+	DrugNameId    int64  `gorm:"column:drug_name_id" json:"drug_name_id" form:"drug_name_id"`
185
+	DrugSpec      string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
186
+	Remarks       string `gorm:"column:remarks" json:"remarks" form:"remarks"`
187
+	StoreNumber   int64  `gorm:"column:store_number" json:"store_number" form:"store_number"`
188
+	AdminUserId   int64  `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
189
+	StorckTime    int64  `gorm:"column:storck_time" json:"storck_time" form:"storck_time"`
190
+	UserOrgId     int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
191
+	CreatedTime   int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
192
+	UpdatedTime   int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
193
+	Status        int64  `gorm:"column:status" json:"status" form:"status"`
194
+	StockInNumber string `gorm:"column:stock_in_number" json:"stock_in_number" form:"stock_in_number"`
195
+	PatientId     int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
196
+	MinUnit       string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
197
+	MedicId       int64  `gorm:"column:medic_id" json:"medic_id" form:"medic_id"`
198
+	Name          string `gorm:"column:name" json:"name" form:"name"`
199
+	DialysisNO    string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
200
+	Total         int64
201
+}
202
+
203
+type XtSelfOutStocks struct {
204
+	ID             int64  `gorm:"column:id" json:"id" form:"id"`
205
+	DrugName       string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
206
+	DrugNameId     int64  `gorm:"column:drug_name_id" json:"drug_name_id" form:"drug_name_id"`
207
+	DrugSpec       string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
208
+	Remarks        string `gorm:"column:remarks" json:"remarks" form:"remarks"`
209
+	OutstoreNumber int64  `gorm:"column:outstore_number" json:"outstore_number" form:"outstore_number"`
210
+	AdminUserId    int64  `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
211
+	StorckTime     int64  `gorm:"column:storck_time" json:"storck_time" form:"storck_time"`
212
+	UserOrgId      int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
213
+	CreatedTime    int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
214
+	UpdatedTime    int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
215
+	Status         int64  `gorm:"column:status" json:"status" form:"status"`
216
+	PatientId      int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
217
+	StockOutNumber string `gorm:"column:stock_out_number" json:"stock_out_number" form:"stock_out_number"`
218
+	MedicId        int64  `gorm:"column:medic_id" json:"medic_id" form:"medic_id"`
219
+	Name           string `gorm:"column:name" json:"name" form:"name"`
220
+	DialysisNO     string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
221
+	Count          int64
222
+}

+ 2 - 1
routers/router.go View File

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

+ 2 - 2
service/dialysis_service.go View File

@@ -547,8 +547,8 @@ func FindDialysisMode(orgID int64, patientId int64, scheduleDate int64) (models.
547 547
 	return schedule, err
548 548
 }
549 549
 
550
-func FindDialysisMacher(orgid int64, patientid int64, dialysisDate int64) (models.XtDialysisOrder, error) {
551
-	orders := models.XtDialysisOrder{}
550
+func FindDialysisMacher(orgid int64, patientid int64, dialysisDate int64) (models.XtDialysisOrders, error) {
551
+	orders := models.XtDialysisOrders{}
552 552
 	db := readDb.Table("xt_dialysis_order as o").Where("o.status = 1")
553 553
 	table := readDb.Table("xt_device_number as n")
554 554
 	fmt.Print("table", table)

+ 309 - 0
service/self_drug_service.go View File

@@ -0,0 +1,309 @@
1
+package service
2
+
3
+import (
4
+	"XT_New/models"
5
+	"fmt"
6
+	"github.com/jinzhu/gorm"
7
+)
8
+
9
+func GetCurrentPatient(orgid int64) (patients []*models.DrugPatients, err error) {
10
+
11
+	err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&patients).Error
12
+	return patients, err
13
+}
14
+
15
+func GetAllDrugName(orgid int64) (baseDrug []*models.XtBaseDrug, err error) {
16
+
17
+	err = XTReadDB().Group("drug_name").Where("org_id = ? and status = 1", orgid).Find(&baseDrug).Error
18
+	return baseDrug, err
19
+
20
+}
21
+
22
+func GetDrugName(drugname string, orgid int64) (*models.XtDrugName, error) {
23
+
24
+	drugName := models.XtDrugName{}
25
+	err := XTReadDB().Model(&drugName).Where("drug_name = ? and user_org_id = ? and status  =1", drugname, orgid).Find(&drugName).Error
26
+	if err == gorm.ErrRecordNotFound {
27
+		return nil, err
28
+	}
29
+	if err != nil {
30
+		return nil, err
31
+	}
32
+	return &drugName, nil
33
+}
34
+
35
+func SaveDrugName(drugname *models.XtDrugName) error {
36
+
37
+	err := XTWriteDB().Create(&drugname).Error
38
+	return err
39
+}
40
+
41
+func GetDrugNameList(orgid int64) (druname []*models.XtDrugName, err error) {
42
+
43
+	err = XTReadDB().Model(&druname).Where("user_org_id = ? and status = 1", orgid).Find(&druname).Error
44
+	return druname, err
45
+}
46
+
47
+func GetRulleName(orgid int64, name string) (baseDrug []*models.XtBaseDrug, err error) {
48
+
49
+	err = XTReadDB().Model(&baseDrug).Where("org_id = ? and drug_name = ? and status = 1", orgid, name).Find(&baseDrug).Error
50
+	return baseDrug, err
51
+}
52
+
53
+func GetRulleList(orgid int64, name string) (rulleName []*models.XtStandName, err error) {
54
+
55
+	err = XTReadDB().Model(&rulleName).Where("user_org_id = ? and drug_name = ? and status = 1", orgid, name).Find(&rulleName).Error
56
+	return rulleName, err
57
+}
58
+
59
+func GetUnitByBaseId(id int64) (models.XtBaseDrug, error) {
60
+	drug := models.XtBaseDrug{}
61
+	err := XTReadDB().Model(&drug).Where("id = ? and status = 1", id).Find(&drug).Error
62
+	return drug, err
63
+}
64
+
65
+func SaveRulleName(rullName *models.XtStandName) error {
66
+
67
+	err := XTWriteDB().Model(&rullName).Create(&rullName).Error
68
+	return err
69
+}
70
+
71
+func GetRullerNameDetail(id int64) (models.XtStandName, error) {
72
+	rullerName := models.XtStandName{}
73
+	err := XTReadDB().Model(&rullerName).Where("id= ? and status = 1", id).Find(&rullerName).Error
74
+	return rullerName, err
75
+}
76
+
77
+func UpdatedRullerName(id int64, re *models.XtStandName) error {
78
+
79
+	err := XTWriteDB().Model(&re).Where("id=?", id).Update(map[string]interface{}{"drug_spec": re.DrugSpec, "min_unit": re.MinUnit, "price": re.Price, "drug_stock_limit": re.DrugStockLimit, "drug_name": re.DrugName, "drug_name_id": re.DrugNameId}).Error
80
+	return err
81
+}
82
+
83
+func GetAllDrugNameList(orgid int64) (rullername []*models.XtStandName, err error) {
84
+
85
+	err = XTReadDB().Group("drug_name").Model(&rullername).Where("user_org_id = ? and status = 1", orgid).Find(&rullername).Error
86
+	return rullername, err
87
+}
88
+
89
+func GetRullerListByDrugName(drugname string, orgid int64) (rullername []*models.XtStandName, err error) {
90
+
91
+	err = XTReadDB().Model(&rullername).Where("drug_name = ? and user_org_id = ? and status = 1", drugname, orgid).Find(&rullername).Error
92
+	return rullername, err
93
+}
94
+
95
+func GetSelfMedicalByDrugName(drugname string, drug_spec string, patientid int64) (*models.XtSelfMedical, error) {
96
+	medical := models.XtSelfMedical{}
97
+	err := XTReadDB().Model(&medical).Where("drug_name = ? and drug_spec = ? and patient_id = ? and status = 1", drugname, drug_spec, patientid).Find(&medical).Error
98
+	if err == gorm.ErrRecordNotFound {
99
+		return nil, err
100
+	}
101
+	if err != nil {
102
+		return nil, err
103
+	}
104
+	return &medical, err
105
+}
106
+
107
+func CreateSelfMedical(medical *models.XtSelfMedical) error {
108
+
109
+	err = XTWriteDB().Model(&medical).Create(&medical).Error
110
+	return err
111
+}
112
+
113
+func GetCurrentOrgAllStaff(orgid int64, app int64) (role []*models.SgjUserAdminRole, err error) {
114
+
115
+	err = UserReadDB().Model(&role).Where("org_id = ? and app_id = ? and status = 1", orgid, app).Find(&role).Error
116
+	return role, err
117
+}
118
+
119
+func CreateStock(stock *models.XtSelfStock) error {
120
+
121
+	err := XTWriteDB().Model(&stock).Create(&stock).Error
122
+	return err
123
+}
124
+
125
+func CreateOutStock(stock *models.XtSelfOutStock) error {
126
+
127
+	err := XTWriteDB().Model(&stock).Create(&stock).Error
128
+	return err
129
+}
130
+
131
+func GetStandDrugByDrugName(drugname string, orgid int64) (*models.XtStandName, error) {
132
+	standname := models.XtStandName{}
133
+	err := XTReadDB().Model(&standname).Where("drug_name = ? and user_org_id = ? and status = 1", drugname, orgid).Find(&standname).Error
134
+	if err == gorm.ErrRecordNotFound {
135
+		return nil, err
136
+	}
137
+	if err != nil {
138
+		return nil, err
139
+	}
140
+	return &standname, nil
141
+}
142
+
143
+func DeleteDrugName(id int64) (models.XtStandName, error) {
144
+	standName := models.XtStandName{}
145
+	err := XTWriteDB().Model(&standName).Where("id = ?", id).Update(map[string]interface{}{"status": 0}).Error
146
+	return standName, err
147
+}
148
+
149
+func GetDrugSetByUserOrgId(orgid int64) (*models.XtDrugSet, error) {
150
+	set := models.XtDrugSet{}
151
+	err := XTReadDB().Model(&set).Where("user_org_id = ? and status = 1", orgid).Find(&set).Error
152
+	if err == gorm.ErrRecordNotFound {
153
+		return nil, err
154
+	}
155
+	if err != nil {
156
+		return nil, err
157
+	}
158
+	return &set, nil
159
+}
160
+
161
+func SaveRadio(drugSet *models.XtDrugSet) error {
162
+
163
+	err := XTWriteDB().Model(&drugSet).Create(&drugSet).Error
164
+	return err
165
+}
166
+
167
+func UpdateDrugSet(set *models.XtDrugSet, orgid int64) error {
168
+
169
+	err := XTWriteDB().Model(&set).Where("user_org_id = ?", orgid).Update(map[string]interface{}{"drug_start": set.DrugStart}).Error
170
+	return err
171
+}
172
+
173
+func DeleteDrugStand(id int64) error {
174
+
175
+	standName := models.XtStandName{}
176
+	err := XTWriteDB().Model(&standName).Where("id =?", id).Update(map[string]interface{}{"status": 0}).Error
177
+	return err
178
+}
179
+
180
+func GetStockList(patientid int64, startime int64, keyword string) (stock []*models.SelfStocks, err error) {
181
+	db := XTReadDB().Table("xt_self_stock as x").Where("x.status = 1")
182
+	likeKey := "%" + keyword + "%"
183
+	table := XTReadDB().Table("xt_patients as s")
184
+	fmt.Println(table)
185
+	if patientid > 0 {
186
+		db = db.Where("x.patient_id = ?", patientid)
187
+	}
188
+	//if startime >0 {
189
+	//  db = db.Where("x.storck_time = ?", startime)
190
+	//}
191
+	err = db.Group("x.drug_name,x.drug_spec").Select("x.id,x.drug_name,x.drug_name_id,x.drug_spec,x.remarks,x.store_number,x.admin_user_id,x.storck_time,x.user_org_id,x.stock_in_number,x.patient_id,x.min_unit,sum(x.store_number) as total").Joins("left join xt_patients as  s on s.id = x.patient_id").Where("s.name like ? or s.dialysis_no like ?", likeKey, likeKey).Scan(&stock).Error
192
+	return stock, err
193
+}
194
+
195
+func GetOutStockList(patientid int64, startime int64, keyword string) (outStock []*models.XtSelfOutStocks, err error) {
196
+	db := XTReadDB().Table("xt_self_out_stock as x").Where("x.status = 1")
197
+	likeKey := "%" + keyword + "%"
198
+	table := XTReadDB().Table("xt_patients as s")
199
+	fmt.Println(table)
200
+	if patientid > 0 {
201
+		db = db.Where("x.patient_id = ?", patientid)
202
+	}
203
+	//if startime > 0 {
204
+	//  db = db.Where("x.storck_time = ?", startime)
205
+	//}
206
+	err = db.Group("x.drug_name,x.drug_spec").Select("x.drug_name,x.drug_spec,x.patient_id,x.stock_out_number,sum(x.outstore_number) as count").Joins("left join xt_patients as  s on s.id = x.patient_id").Where("s.name like ? or s.dialysis_no like ?", likeKey, likeKey).Scan(&outStock).Error
207
+	return outStock, err
208
+}
209
+
210
+func GetStockOutDetail(durgname string, patientid int64) (stock []*models.XtSelfOutStock, err error) {
211
+
212
+	err = XTReadDB().Model(&stock).Where("drug_name = ? and patient_id = ? and status = 1", durgname, patientid).Find(&stock).Error
213
+	return stock, err
214
+}
215
+
216
+func DeleteDrugStockNumber(drugname string, patientid int64) (models.XtSelfStock, error) {
217
+	stock := models.XtSelfStock{}
218
+	err := XTWriteDB().Model(&stock).Where("drug_name = ? and patient_id = ?", drugname, patientid).Update(map[string]interface{}{"status": 0}).Error
219
+	return stock, err
220
+}
221
+
222
+func GetStockDetail(drugname string, drugspec string, startime int64, endtime int64, patientid int64, orgid int64) (stock []*models.XtSelfStock, err error) {
223
+	fmt.Println("startime", startime)
224
+	fmt.Println("endtime", endtime)
225
+	err = XTReadDB().Model(&stock).Where("drug_name = ? and drug_spec = ? and patient_id =? and user_org_id = ? and status = 1", drugname, drugspec, patientid, orgid).Find(&stock).Error
226
+	return stock, err
227
+}
228
+
229
+func GetOutStockDetail(drugname string, drugspec string, startime int64, endtime int64, patientid int64, orgid int64) (outStock []*models.XtSelfOutStock, err error) {
230
+	fmt.Println(startime)
231
+	fmt.Println(endtime)
232
+	err = XTReadDB().Model(&outStock).Where("drug_name = ? and drug_spec=? and patient_id = ? and user_org_id = ? and status = 1", drugname, drugspec, patientid, orgid).Find(&outStock).Error
233
+	return outStock, err
234
+}
235
+
236
+func GetAllPatientStockList(drug_name string, drug_spec string, startime int64, endtime int64, keyword string, orgid int64) (stocks []*models.SelfStocks, err error) {
237
+
238
+	db := XTReadDB().Table("xt_self_stock as x").Where("x.status = 1")
239
+	likeKey := "%" + keyword + "%"
240
+	table := XTReadDB().Table("xt_patients as s")
241
+	fmt.Println(table)
242
+	if len(drug_name) > 0 {
243
+		db = db.Where("x.drug_name = ?", drug_name)
244
+	}
245
+	if len(drug_spec) > 0 {
246
+		db = db.Where("x.drug_spec = ?", drug_spec)
247
+	}
248
+	if startime > 0 {
249
+		db = db.Where("x.storck_time >= ?", startime)
250
+	}
251
+	if endtime > 0 {
252
+		db = db.Where("x.storck_time <= ?", endtime)
253
+	}
254
+	if orgid > 0 {
255
+		db = db.Where("x.user_org_id = ?", orgid)
256
+	}
257
+	err = db.Group("x.patient_id,x.drug_name,x.drug_spec").Select("x.drug_name,x.drug_spec,x.patient_id,x.store_number,sum(x.store_number) as total,s.name,s.dialysis_no,x.min_unit").Joins("left join xt_patients as  s on s.id = x.patient_id").Where("s.name like ? or s.dialysis_no like ?", likeKey, likeKey).Scan(&stocks).Error
258
+	return stocks, err
259
+}
260
+
261
+func GetAllPatientOutStockList(drug_name string, drug_spec string, startime int64, endtime int64, keyword string, orgid int64) (outStock []*models.XtSelfOutStocks, err error) {
262
+
263
+	db := XTReadDB().Table("xt_self_out_stock as x").Where("x.status = 1")
264
+	likeKey := "%" + keyword + "%"
265
+	table := XTReadDB().Table("xt_patients as s")
266
+	fmt.Println(table)
267
+	if len(drug_name) > 0 {
268
+		db = db.Where("x.drug_name = ?", drug_name)
269
+	}
270
+	if len(drug_spec) > 0 {
271
+		db = db.Where("x.drug_spec=?", drug_spec)
272
+	}
273
+
274
+	if startime > 0 {
275
+		db = db.Where("x.storck_time >= ?", startime)
276
+	}
277
+	if endtime > 0 {
278
+		db = db.Where("x.storck_time<=?", endtime)
279
+	}
280
+	if orgid > 0 {
281
+		db = db.Where("x.user_org_id = ?", orgid)
282
+	}
283
+	err = db.Group("x.patient_id,x.drug_name,x.drug_spec").Select("x.drug_name,x.drug_spec,x.patient_id,x.stock_out_number,sum(x.outstore_number) as count").Joins("left join xt_patients as  s on s.id = x.patient_id").Where("s.name like ? or s.dialysis_no like ?", likeKey, likeKey).Scan(&outStock).Error
284
+	return outStock, err
285
+}
286
+
287
+func GetDrugDataByPatientId(patientid int64) (selfMedical []*models.XtSelfMedical, err error) {
288
+
289
+	err = XTReadDB().Group("drug_name,drug_spec").Model(&selfMedical).Where("patient_id = ? and status = 1", patientid).Find(&selfMedical).Error
290
+	return selfMedical, err
291
+}
292
+
293
+func GetSetSelfMedical(orgid int64) (models.XtDrugSet, error) {
294
+	medical := models.XtDrugSet{}
295
+	err := XTReadDB().Model(&medical).Where("user_org_id = ? and status = 1", orgid).Find(&medical).Error
296
+	return medical, err
297
+}
298
+
299
+func GetSelfMedicalList(patientid int64) (selfmedical []*models.XtSelfMedical, err error) {
300
+
301
+	err = XTReadDB().Group("drug_name").Model(&selfmedical).Where("patient_id = ? and status = 1", patientid).Find(&selfmedical).Error
302
+	return selfmedical, err
303
+}
304
+
305
+func GetDrugDescByDrugName(drugname string, patient_id int64, orgid int64) (selfMedical []*models.XtSelfMedical, err error) {
306
+
307
+	err = XTReadDB().Model(&selfMedical).Where("drug_name = ? and patient_id = ? and user_org_id = ? and status = 1", drugname, patient_id, orgid).Find(&selfMedical).Error
308
+	return selfMedical, err
309
+}