Browse Source

耗材参数

XMLWAN 3 years ago
parent
commit
0f9d52d789

+ 12 - 1
controllers/dialysis_api_controller.go View File

@@ -256,7 +256,9 @@ func (c *DialysisApiController) PostPrescription() {
256 256
 	replacement_flow := c.GetString("replacement_flow")
257 257
 	plasma_separator := c.GetString("plasma_separator")
258 258
 	bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
259
-
259
+	oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
260
+	oxygen_flow := c.GetString("oxygen_flow")
261
+	oxygen_time := c.GetString("oxygen_time")
260 262
 	appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
261 263
 	//template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
262 264
 
@@ -347,6 +349,9 @@ func (c *DialysisApiController) PostPrescription() {
347 349
 		ReplacementFlow:            replacement_flow,
348 350
 		PlasmaSeparator:            plasma_separator,
349 351
 		BilirubinAdsorptionColumn:  bilirubin_adsorption_column,
352
+		OxygenFlow:                 oxygen_flow,
353
+		OxygenUptake:               oxygen_uptake,
354
+		OxygenTime:                 oxygen_time,
350 355
 	}
351 356
 
352 357
 	//查询最近透析准备表里是否存在 透析器 灌流器
@@ -589,6 +594,9 @@ func (c *DialysisApiController) PostSoulution() {
589 594
 	replacement_flow := c.GetString("replacement_flow")
590 595
 	plasma_separator := c.GetString("plasma_separator")
591 596
 	bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
597
+	oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
598
+	oxygen_flow := c.GetString("oxygen_flow")
599
+	oxygen_time := c.GetString("oxygen_time")
592 600
 	var prescription_doctor int64
593 601
 	appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
594 602
 
@@ -690,6 +698,9 @@ func (c *DialysisApiController) PostSoulution() {
690 698
 		ReplacementFlow:           replacement_flow,
691 699
 		PlasmaSeparator:           plasma_separator,
692 700
 		BilirubinAdsorptionColumn: bilirubin_adsorption_column,
701
+		OxygenTime:                oxygen_time,
702
+		OxygenUptake:              oxygen_uptake,
703
+		OxygenFlow:                oxygen_flow,
693 704
 	}
694 705
 
695 706
 	//查询最近透析准备表里是否存在 透析器 灌流器

+ 38 - 16
controllers/drug_stock_api_contorller.go View File

@@ -446,7 +446,7 @@ func (c *StockDrugApiController) GetDrugWarehouseInfoList() {
446 446
 
447 447
 	warehousing, err := service.FindDrugWarehousingById(id, admin.CurrentOrgId)
448 448
 
449
-	manufacturerList, _ := service.GetAllDrugLibList(admin.CurrentOrgId)
449
+	manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
450 450
 	if err != nil {
451 451
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
452 452
 		return
@@ -597,12 +597,12 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
597 597
 
598 598
 				}
599 599
 
600
-				if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
601
-					utils.ErrorLog("number")
600
+				if items["lot_number"] == nil || reflect.TypeOf(items["lot_number"]).String() != "string" {
601
+					utils.ErrorLog("lot_number")
602 602
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
603 603
 					return
604 604
 				}
605
-				number, _ := items["number"].(string)
605
+				number, _ := items["lot_number"].(string)
606 606
 
607 607
 				if items["batch_number"] == nil || reflect.TypeOf(items["batch_number"]).String() != "string" {
608 608
 					utils.ErrorLog("batch_number")
@@ -683,6 +683,7 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
683 683
 						//Dealer:           dealer,
684 684
 						RetailPrice:      last_price,
685 685
 						RetailTotalPrice: retail_price_total,
686
+						StockMaxNumber:   warehousing_count,
686 687
 					}
687 688
 					upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
688 689
 				}
@@ -1170,8 +1171,10 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1170 1171
 
1171 1172
 	if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
1172 1173
 		thisStockIn, _ := dataBody["stockOut"].([]interface{})
1174
+
1173 1175
 		if len(thisStockIn) > 0 {
1174 1176
 			for _, item := range thisStockIn {
1177
+
1175 1178
 				items := item.(map[string]interface{})
1176 1179
 
1177 1180
 				if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
@@ -1194,18 +1197,21 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1194 1197
 				}
1195 1198
 				price, _ := strconv.ParseFloat(items["price"].(string), 64)
1196 1199
 
1197
-				if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
1198
-					utils.ErrorLog("retail_price")
1200
+				if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
1201
+					utils.ErrorLog("last_price")
1199 1202
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1200 1203
 					return
1201 1204
 				}
1202
-				retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
1205
+				last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
1203 1206
 
1204 1207
 				count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
1205 1208
 
1206 1209
 				total := float64(count) * price
1207
-				retail_price_total := float64(count) * retail_price
1210
+				retail_price_total := float64(count) * last_price
1208 1211
 				remark := items["remark"].(string)
1212
+				packing_unit := items["packing_unit"].(string)
1213
+
1214
+				fmt.Println("包装单位999999999999", packing_unit)
1209 1215
 
1210 1216
 				warehouseOutInfo := &models.DrugWarehouseOutInfo{
1211 1217
 					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -1221,25 +1227,41 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1221 1227
 					Type:                    types,
1222 1228
 					Manufacturer:            manufacturer_id,
1223 1229
 					Dealer:                  dealer_id,
1224
-					RetailPrice:             retail_price,
1230
+					RetailPrice:             last_price,
1225 1231
 					RetailTotalPrice:        retail_price_total,
1232
+					CountUnit:               packing_unit,
1226 1233
 				}
1227 1234
 				warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1228 1235
 
1229 1236
 			}
1230 1237
 		}
1231 1238
 	}
1232
-	errs := service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
1233
-	info, _ := service.FindLastDrugWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
1234
-	if errs != nil {
1235
-		utils.ErrorLog(errs.Error())
1236
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
1237
-		return
1239
+
1240
+	//调用出库逻辑
1241
+	for _, item := range warehousingOutInfo {
1242
+
1243
+		// 出库流程
1244
+		// 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
1245
+		drup, _ := service.FindBaseDrugLibRecord(item.OrgId, item.DrugId)
1246
+		if drup.ID > 0 {
1247
+			prescribingNumber := item.Count
1248
+
1249
+			service.AutoDrugDeliverInfo(item.OrgId, prescribingNumber, &warehouseOut, &drup, item)
1250
+
1251
+		}
1252
+
1238 1253
 	}
1239 1254
 
1255
+	//errs := service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
1256
+	//info, _ := service.FindLastDrugWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
1257
+	//if errs != nil {
1258
+	//	utils.ErrorLog(errs.Error())
1259
+	//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
1260
+	//	return
1261
+	//}
1262
+
1240 1263
 	c.ServeSuccessJSON(map[string]interface{}{
1241 1264
 		"msg":                   "出库成功",
1242
-		"info":                  info,
1243 1265
 		"warehousing_out_order": warehousing_out_order,
1244 1266
 	})
1245 1267
 

+ 112 - 0
controllers/gobal_config_api_controller.go View File

@@ -86,6 +86,10 @@ func GobalConfigRegistRouters() {
86 86
 	beego.Router("/api/order/getorderconfig", &GobalConfigApiController{}, "Get:GetOrderConfig")
87 87
 	beego.Router("/api/drugstock/getdrugautomaticlist", &GobalConfigApiController{}, "Get:GetDrugAutoMaticList")
88 88
 	beego.Router("/api/drugstock/getdrugwarehouseorderinfo", &GobalConfigApiController{}, "Get:GetDrugWarehuseOrderInfo")
89
+
90
+	//新接口
91
+	beego.Router("/api/drugstock/drugstocklist", &GobalConfigApiController{}, "Get:GetDrugStockList")
92
+	beego.Router("/api/drugstock/getdrugstockflow", &GobalConfigApiController{}, "Get:GetDrugStockFllow")
89 93
 }
90 94
 
91 95
 //provinces, _ := service.GetDistrictsByUpid(0)21
@@ -1732,3 +1736,111 @@ func (c *GobalConfigApiController) GetDrugWarehuseOrderInfo() {
1732 1736
 		"list": list,
1733 1737
 	})
1734 1738
 }
1739
+
1740
+func (c *GobalConfigApiController) GetDrugStockList() {
1741
+
1742
+	page, _ := c.GetInt64("page", -1)
1743
+	limit, _ := c.GetInt64("limit", -1)
1744
+	keyword := c.GetString("keyword")
1745
+	drug_category, _ := c.GetInt64("drug_category")
1746
+	start_time := c.GetString("start_time")
1747
+	end_time := c.GetString("end_time")
1748
+	timeLayout := "2006-01-02"
1749
+	loc, _ := time.LoadLocation("Local")
1750
+
1751
+	var startTime int64
1752
+	if len(start_time) > 0 {
1753
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
1754
+		if err != nil {
1755
+			fmt.Println(err)
1756
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1757
+			return
1758
+		}
1759
+		startTime = theTime.Unix()
1760
+	}
1761
+	var endTime int64
1762
+	if len(end_time) > 0 {
1763
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
1764
+		if err != nil {
1765
+			utils.ErrorLog(err.Error())
1766
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1767
+			return
1768
+		}
1769
+		endTime = theTime.Unix()
1770
+	}
1771
+	adminUserInfo := c.GetAdminUserInfo()
1772
+
1773
+	//查询入库数量
1774
+	list, total, err := service.GetDrugStockList(page, limit, keyword, drug_category, startTime, endTime, adminUserInfo.CurrentOrgId)
1775
+	manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
1776
+	if err != nil {
1777
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
1778
+		return
1779
+	}
1780
+	c.ServeSuccessJSON(map[string]interface{}{
1781
+		"list":             list,
1782
+		"total":            total,
1783
+		"manufacturerList": manufacturerList,
1784
+	})
1785
+}
1786
+
1787
+func (c *GobalConfigApiController) GetDrugStockFllow() {
1788
+
1789
+	drug_id, _ := c.GetInt64("drug_id")
1790
+	start_time := c.GetString("start_time")
1791
+	end_time := c.GetString("end_time")
1792
+	stock_type, _ := c.GetInt64("stock_type")
1793
+	page, _ := c.GetInt64("page")
1794
+	limit, _ := c.GetInt64("limit")
1795
+
1796
+	timeLayout := "2006-01-02"
1797
+	loc, _ := time.LoadLocation("Local")
1798
+	var startTime int64
1799
+	if len(start_time) > 0 {
1800
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
1801
+		if err != nil {
1802
+			fmt.Println(err)
1803
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1804
+			return
1805
+		}
1806
+		startTime = theTime.Unix()
1807
+	}
1808
+	var endTime int64
1809
+	if len(end_time) > 0 {
1810
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
1811
+		if err != nil {
1812
+			utils.ErrorLog(err.Error())
1813
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1814
+			return
1815
+		}
1816
+		endTime = theTime.Unix()
1817
+	}
1818
+	orgId := c.GetAdminUserInfo().CurrentOrgId
1819
+	manufacturerList, _ := service.GetAllManufacturerList(orgId)
1820
+	//查询入库数据
1821
+	if stock_type == 3 || stock_type == 0 {
1822
+		list, total, err := service.GetDrugStockFlow(drug_id, startTime, endTime, page, limit, orgId)
1823
+		if err != nil {
1824
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
1825
+			return
1826
+		}
1827
+		c.ServeSuccessJSON(map[string]interface{}{
1828
+			"list":             list,
1829
+			"total":            total,
1830
+			"manufacturerList": manufacturerList,
1831
+		})
1832
+	}
1833
+
1834
+	if stock_type >= 0 && stock_type != 3 {
1835
+		outList, total, err := service.GetDrugStockOutFlow(drug_id, startTime, endTime, page, limit, orgId, stock_type)
1836
+		if err != nil {
1837
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
1838
+			return
1839
+		}
1840
+		c.ServeSuccessJSON(map[string]interface{}{
1841
+			"outList": outList,
1842
+			"total":   total,
1843
+		})
1844
+	}
1845
+
1846
+}

+ 38 - 16
controllers/manager_center_api_controller.go View File

@@ -136,10 +136,10 @@ func (c *ManagerCenterApiController) CreateBaseDrugLib() {
136 136
 	loc, _ := time.LoadLocation("Local")
137 137
 	theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
138 138
 	drug_remark := c.GetString("drug_remark")
139
-	dosage := c.GetString("dosage")
140
-	unval := c.GetString("unval")
141
-	packing_unit := c.GetString("packing_unit")
142
-	packing_price, _ := c.GetFloat("packing_price")
139
+	dose, _ := c.GetFloat("dose")
140
+	dose_unit := c.GetString("dose_unit")
141
+	min_price, _ := c.GetFloat("min_price")
142
+	min_number, _ := c.GetInt64("min_number")
143 143
 	drug_day := c.GetString("drug_day")
144 144
 	adminInfo := c.GetAdminUserInfo()
145 145
 
@@ -197,11 +197,11 @@ func (c *ManagerCenterApiController) CreateBaseDrugLib() {
197 197
 		SocialSecurityDirectoryCode: social_security_directory_code,
198 198
 		RecordDate:                  theTime.Unix(),
199 199
 		DrugRemark:                  drug_remark,
200
-		Dosage:                      dosage,
201
-		Unval:                       unval,
202
-		PackingUnit:                 packing_unit,
203
-		PackingPrice:                packing_price,
204 200
 		DrugDay:                     drug_day,
201
+		MinNumber:                   min_number,
202
+		Dose:                        dose,
203
+		MinPrice:                    min_price,
204
+		DoseUnit:                    dose_unit,
205 205
 	}
206 206
 
207 207
 	total := service.FindAllDrugLibRecordTotal(adminInfo.CurrentOrgId)
@@ -286,11 +286,12 @@ func (c *ManagerCenterApiController) EditBaseDrugLib() {
286 286
 	loc, _ := time.LoadLocation("Local")
287 287
 	theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
288 288
 	drug_remark := c.GetString("drug_remark")
289
-	dosage := c.GetString("dosage")
290
-	unval := c.GetString("unval")
291
-	packing_unit := c.GetString("packing_unit")
292
-	packing_price, _ := c.GetFloat("packing_price")
289
+	min_number, _ := c.GetInt64("min_number")
293 290
 	drug_day := c.GetString("drug_day")
291
+	dose, _ := c.GetFloat("dose")
292
+	dose_unit := c.GetString("dose_unit")
293
+	fmt.Println("单位999999999999999999999999999999", dose_unit)
294
+	min_price, _ := c.GetFloat("min_price")
294 295
 	adminInfo := c.GetAdminUserInfo()
295 296
 	drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, id)
296 297
 
@@ -350,11 +351,11 @@ func (c *ManagerCenterApiController) EditBaseDrugLib() {
350 351
 		SocialSecurityDirectoryCode: social_security_directory_code,
351 352
 		RecordDate:                  theTime.Unix(),
352 353
 		DrugRemark:                  drug_remark,
353
-		Dosage:                      dosage,
354
-		Unval:                       unval,
355
-		PackingPrice:                packing_price,
356
-		PackingUnit:                 packing_unit,
357 354
 		DrugDay:                     drug_day,
355
+		MinNumber:                   min_number,
356
+		Dose:                        dose,
357
+		MinPrice:                    min_price,
358
+		DoseUnit:                    dose_unit,
358 359
 	}
359 360
 
360 361
 	err := service.UpdateBaseDrugLib(drugLib)
@@ -1460,6 +1461,11 @@ func (c *ManagerCenterApiController) CreateGoodInfo() {
1460 1461
 	social_security_directory_code := c.GetString("social_security_directory_code")
1461 1462
 	production_type := c.GetString("production_type")
1462 1463
 	special_medical := c.GetString("special_medical")
1464
+	min_number, _ := c.GetInt64("min_number")
1465
+	packing_unit := c.GetString("packing_unit")
1466
+	packing_price, _ := c.GetFloat("packing_price")
1467
+	min_unit := c.GetString("min_unit")
1468
+	default_count_unit := c.GetString("default_count_unit")
1463 1469
 	adminUserInfo := c.GetAdminUserInfo()
1464 1470
 
1465 1471
 	totals := service.FindGoodInfoByNameTwo(specification_name, adminUserInfo.CurrentOrgId, good_id, good_name)
@@ -1513,6 +1519,11 @@ func (c *ManagerCenterApiController) CreateGoodInfo() {
1513 1519
 		SocialSecurityDirectoryCode: social_security_directory_code,
1514 1520
 		ProductionType:              production_type,
1515 1521
 		SpecialMedical:              special_medical,
1522
+		MinNumber:                   min_number,
1523
+		PackingUnit:                 packing_unit,
1524
+		PackingPrice:                packing_price,
1525
+		DefaultCountUnit:            default_count_unit,
1526
+		MinUnit:                     min_unit,
1516 1527
 	}
1517 1528
 	err, goodInfos := service.AddSigleGoodInfo(&goodInfo)
1518 1529
 	if err == nil {
@@ -1566,6 +1577,12 @@ func (c *ManagerCenterApiController) ModifyGoodInfo() {
1566 1577
 	social_security_directory_code := c.GetString("social_security_directory_code")
1567 1578
 	production_type := c.GetString("production_type")
1568 1579
 	special_medical := c.GetString("special_medical")
1580
+
1581
+	min_number, _ := c.GetInt64("min_number")
1582
+	packing_unit := c.GetString("packing_unit")
1583
+	packing_price, _ := c.GetFloat("packing_price")
1584
+	default_count_unit := c.GetString("default_count_unit")
1585
+	min_unit := c.GetString("min_unit")
1569 1586
 	adminUserInfo := c.GetAdminUserInfo()
1570 1587
 
1571 1588
 	goodInfo := models.GoodInfo{
@@ -1610,6 +1627,11 @@ func (c *ManagerCenterApiController) ModifyGoodInfo() {
1610 1627
 		SpecialMedical:              special_medical,
1611 1628
 		SocialSecurityDirectoryCode: social_security_directory_code,
1612 1629
 		ProductionType:              production_type,
1630
+		MinNumber:                   min_number,
1631
+		PackingUnit:                 packing_unit,
1632
+		PackingPrice:                packing_price,
1633
+		DefaultCountUnit:            default_count_unit,
1634
+		MinUnit:                     min_unit,
1613 1635
 	}
1614 1636
 
1615 1637
 	totals := service.FindGoodInfoByNameOne(specification_name, adminUserInfo.CurrentOrgId, good_id, id, good_name)

File diff suppressed because it is too large
+ 843 - 806
controllers/mobile_api_controllers/dialysis_api_controller.go


+ 266 - 261
controllers/mobile_api_controllers/patient_api_controller.go View File

@@ -637,7 +637,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
637 637
 				}
638 638
 
639 639
 				if isHasWay {
640
-					out, err := service.FindDrugStockOutByIsSys(adminUserInfo.Org.Id, 1, record_time)
640
+					_, err := service.FindDrugStockOutByIsSys(adminUserInfo.Org.Id, 1, record_time)
641 641
 					if err == gorm.ErrRecordNotFound {
642 642
 						//没有记录,则创建出库单
643 643
 						timeStr := time.Now().Format("2006-01-02")
@@ -668,43 +668,46 @@ func (c *PatientApiController) ExecDoctorAdvice() {
668 668
 						} else {
669 669
 							for _, item := range advices {
670 670
 								if item.Way == 1 {
671
-									if item.PrescribingNumber > 0 {
672
-										warehouseOutInfo := &models.DrugWarehouseOutInfo{
673
-											WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
674
-											WarehouseOutId:          warehouseOut.ID,
675
-											Status:                  1,
676
-											Ctime:                   time.Now().Unix(),
677
-											Remark:                  "",
678
-											OrgId:                   adminUserInfo.Org.Id,
679
-											Type:                    1,
680
-											Manufacturer:            0,
681
-											Dealer:                  0,
682
-											IsSys:                   1,
683
-											SysRecordTime:           record_time,
684
-											DrugId:                  item.DrugId,
685
-										}
686
-										prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
687
-										count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
688
-										warehouseOutInfo.Count = count
689
-										stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
690
-										warehouseOutInfo.Price = stockInInfo.Price
691
-										err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
692
-										if err == nil {
693
-											details := &models.DrugAutomaticReduceDetail{
694
-												WarehouseOutId:          warehouseOutInfo.ID,
695
-												WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
696
-												PatientId:               item.PatientId,
697
-												Ctime:                   time.Now().Unix(),
698
-												Mtime:                   time.Now().Unix(),
699
-												Status:                  1,
700
-												RecordTime:              record_time,
701
-												OrgId:                   adminUserInfo.Org.Id,
702
-												DrugId:                  item.DrugId,
703
-												Count:                   count,
704
-											}
705
-											service.AddSigleDrugAutoReduceRecordInfo(details)
706
-										}
707
-									}
671
+
672
+									service.DrugsDelivery(item.UserOrgId, &item)
673
+
674
+									//if item.PrescribingNumber > 0 {
675
+									//	warehouseOutInfo := &models.DrugWarehouseOutInfo{
676
+									//		WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
677
+									//		WarehouseOutId:          warehouseOut.ID,
678
+									//		Status:                  1,
679
+									//		Ctime:                   time.Now().Unix(),
680
+									//		Remark:                  "",
681
+									//		OrgId:                   adminUserInfo.Org.Id,
682
+									//		Type:                    1,
683
+									//		Manufacturer:            0,
684
+									//		Dealer:                  0,
685
+									//		IsSys:                   1,
686
+									//		SysRecordTime:           record_time,
687
+									//		DrugId:                  item.DrugId,
688
+									//	}
689
+									//	prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
690
+									//	count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
691
+									//	warehouseOutInfo.Count = count
692
+									//	stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
693
+									//	warehouseOutInfo.Price = stockInInfo.Price
694
+									//	err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
695
+									//	if err == nil {
696
+									//		details := &models.DrugAutomaticReduceDetail{
697
+									//			WarehouseOutId:          warehouseOutInfo.ID,
698
+									//			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
699
+									//			PatientId:               item.PatientId,
700
+									//			Ctime:                   time.Now().Unix(),
701
+									//			Mtime:                   time.Now().Unix(),
702
+									//			Status:                  1,
703
+									//			RecordTime:              record_time,
704
+									//			OrgId:                   adminUserInfo.Org.Id,
705
+									//			DrugId:                  item.DrugId,
706
+									//			Count:                   count,
707
+									//		}
708
+									//		service.AddSigleDrugAutoReduceRecordInfo(details)
709
+									//	}
710
+									//}
708 711
 								}
709 712
 
710 713
 							}
@@ -713,71 +716,72 @@ func (c *PatientApiController) ExecDoctorAdvice() {
713 716
 					} else if err == nil {
714 717
 						for _, item := range advices {
715 718
 							if item.Way == 1 {
716
-								outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.Org.Id, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
717
-								if err == gorm.ErrRecordNotFound {
718
-									warehouseOutInfo := &models.DrugWarehouseOutInfo{
719
-										WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
720
-										WarehouseOutId:          out.ID,
721
-										Status:                  1,
722
-										Ctime:                   time.Now().Unix(),
723
-										Remark:                  "",
724
-										OrgId:                   adminUserInfo.Org.Id,
725
-										Type:                    1,
726
-										Manufacturer:            0,
727
-										Dealer:                  0,
728
-										IsSys:                   1,
729
-										SysRecordTime:           record_time,
730
-									}
731
-
732
-									stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
733
-									warehouseOutInfo.Price = stockInInfo.Price
734
-									warehouseOutInfo.DrugId = item.DrugId
735
-									prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
736
-									count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
737
-									warehouseOutInfo.Count = count
738
-									err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
739
-									if err == nil {
740
-										details := &models.DrugAutomaticReduceDetail{
741
-											WarehouseOutId:          warehouseOutInfo.ID,
742
-											WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
743
-											PatientId:               item.PatientId,
744
-											Ctime:                   time.Now().Unix(),
745
-											Mtime:                   time.Now().Unix(),
746
-											Status:                  1,
747
-											RecordTime:              record_time,
748
-											OrgId:                   adminUserInfo.Org.Id,
749
-											DrugId:                  item.DrugId,
750
-											Count:                   count,
751
-										}
752
-										service.AddSigleDrugAutoReduceRecordInfo(details)
753
-									}
754
-
755
-								} else if err == nil { //记录存在,则将增加数量
756
-									if outInfo.ID > 0 {
757
-										prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
758
-										count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
759
-										service.UpdateDrugStockOutInfoCount2(adminUserInfo.Org.Id, outInfo.ID, count)
760
-									}
761
-
762
-									//count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.Org.Id, record_time, item.DrugId, item.PatientId)
763
-									//if count == 0 {
764
-									prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
765
-									count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
766
-									details := &models.DrugAutomaticReduceDetail{
767
-										WarehouseOutId:          outInfo.ID,
768
-										WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
769
-										PatientId:               item.PatientId,
770
-										Ctime:                   time.Now().Unix(),
771
-										Mtime:                   time.Now().Unix(),
772
-										Status:                  1,
773
-										RecordTime:              record_time,
774
-										OrgId:                   adminUserInfo.Org.Id,
775
-										DrugId:                  item.DrugId,
776
-										Count:                   count,
777
-									}
778
-									service.AddSigleDrugAutoReduceRecordInfo(details)
779
-
780
-								}
719
+								service.DrugsDelivery(item.UserOrgId, &item)
720
+								//outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.Org.Id, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
721
+								//if err == gorm.ErrRecordNotFound {
722
+								//	warehouseOutInfo := &models.DrugWarehouseOutInfo{
723
+								//		WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
724
+								//		WarehouseOutId:          out.ID,
725
+								//		Status:                  1,
726
+								//		Ctime:                   time.Now().Unix(),
727
+								//		Remark:                  "",
728
+								//		OrgId:                   adminUserInfo.Org.Id,
729
+								//		Type:                    1,
730
+								//		Manufacturer:            0,
731
+								//		Dealer:                  0,
732
+								//		IsSys:                   1,
733
+								//		SysRecordTime:           record_time,
734
+								//	}
735
+								//
736
+								//	stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
737
+								//	warehouseOutInfo.Price = stockInInfo.Price
738
+								//	warehouseOutInfo.DrugId = item.DrugId
739
+								//	prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
740
+								//	count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
741
+								//	warehouseOutInfo.Count = count
742
+								//	err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
743
+								//	if err == nil {
744
+								//		details := &models.DrugAutomaticReduceDetail{
745
+								//			WarehouseOutId:          warehouseOutInfo.ID,
746
+								//			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
747
+								//			PatientId:               item.PatientId,
748
+								//			Ctime:                   time.Now().Unix(),
749
+								//			Mtime:                   time.Now().Unix(),
750
+								//			Status:                  1,
751
+								//			RecordTime:              record_time,
752
+								//			OrgId:                   adminUserInfo.Org.Id,
753
+								//			DrugId:                  item.DrugId,
754
+								//			Count:                   count,
755
+								//		}
756
+								//		service.AddSigleDrugAutoReduceRecordInfo(details)
757
+								//	}
758
+								//
759
+								//} else if err == nil { //记录存在,则将增加数量
760
+								//	if outInfo.ID > 0 {
761
+								//		prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
762
+								//		count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
763
+								//		service.UpdateDrugStockOutInfoCount2(adminUserInfo.Org.Id, outInfo.ID, count)
764
+								//	}
765
+								//
766
+								//	//count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.Org.Id, record_time, item.DrugId, item.PatientId)
767
+								//	//if count == 0 {
768
+								//	prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
769
+								//	count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
770
+								//	details := &models.DrugAutomaticReduceDetail{
771
+								//		WarehouseOutId:          outInfo.ID,
772
+								//		WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
773
+								//		PatientId:               item.PatientId,
774
+								//		Ctime:                   time.Now().Unix(),
775
+								//		Mtime:                   time.Now().Unix(),
776
+								//		Status:                  1,
777
+								//		RecordTime:              record_time,
778
+								//		OrgId:                   adminUserInfo.Org.Id,
779
+								//		DrugId:                  item.DrugId,
780
+								//		Count:                   count,
781
+								//	}
782
+								//	service.AddSigleDrugAutoReduceRecordInfo(details)
783
+								//
784
+								//}
781 785
 							}
782 786
 						}
783 787
 
@@ -796,7 +800,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
796 800
 				}
797 801
 
798 802
 				if isHasWay {
799
-					out, err := service.FindDrugStockOutByIsSys(adminUserInfo.Org.Id, 1, record_time)
803
+					_, err := service.FindDrugStockOutByIsSys(adminUserInfo.Org.Id, 1, record_time)
800 804
 					if err == gorm.ErrRecordNotFound {
801 805
 						//没有记录,则创建出库单
802 806
 						timeStr := time.Now().Format("2006-01-02")
@@ -827,43 +831,44 @@ func (c *PatientApiController) ExecDoctorAdvice() {
827 831
 						} else {
828 832
 							for _, item := range advices {
829 833
 								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
-									}
834
+									service.DrugsDelivery(item.UserOrgId, &item)
835
+									//if item.PrescribingNumber > 0 {
836
+									//	warehouseOutInfo := &models.DrugWarehouseOutInfo{
837
+									//		WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
838
+									//		WarehouseOutId:          warehouseOut.ID,
839
+									//		Status:                  1,
840
+									//		Ctime:                   time.Now().Unix(),
841
+									//		Remark:                  "",
842
+									//		OrgId:                   adminUserInfo.Org.Id,
843
+									//		Type:                    1,
844
+									//		Manufacturer:            0,
845
+									//		Dealer:                  0,
846
+									//		IsSys:                   1,
847
+									//		SysRecordTime:           record_time,
848
+									//		DrugId:                  item.DrugId,
849
+									//	}
850
+									//	prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
851
+									//	count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
852
+									//	warehouseOutInfo.Count = count
853
+									//	stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
854
+									//	warehouseOutInfo.Price = stockInInfo.Price
855
+									//	err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
856
+									//	if err == nil {
857
+									//		details := &models.DrugAutomaticReduceDetail{
858
+									//			WarehouseOutId:          warehouseOutInfo.ID,
859
+									//			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
860
+									//			PatientId:               item.PatientId,
861
+									//			Ctime:                   time.Now().Unix(),
862
+									//			Mtime:                   time.Now().Unix(),
863
+									//			Status:                  1,
864
+									//			RecordTime:              record_time,
865
+									//			OrgId:                   adminUserInfo.Org.Id,
866
+									//			DrugId:                  item.DrugId,
867
+									//			Count:                   count,
868
+									//		}
869
+									//		service.AddSigleDrugAutoReduceRecordInfo(details)
870
+									//	}
871
+									//}
867 872
 								}
868 873
 
869 874
 							}
@@ -872,77 +877,73 @@ func (c *PatientApiController) ExecDoctorAdvice() {
872 877
 					} else if err == nil {
873 878
 						for _, item := range advices {
874 879
 							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
-									//}
939
-									//else if count == 1 {
940
-									//	prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
941
-									//	count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
942
-									//	service.UpdateDrugUserInfoDetails(item.DrugId, record_time, adminUserInfo.Org.Id, item.PatientId, count, &outInfo)
943
-									//}
944
-
945
-								}
880
+								service.DrugsDelivery(item.UserOrgId, &item)
881
+								//outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.Org.Id, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
882
+								//if err == gorm.ErrRecordNotFound {
883
+								//	warehouseOutInfo := &models.DrugWarehouseOutInfo{
884
+								//		WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
885
+								//		WarehouseOutId:          out.ID,
886
+								//		Status:                  1,
887
+								//		Ctime:                   time.Now().Unix(),
888
+								//		Remark:                  "",
889
+								//		OrgId:                   adminUserInfo.Org.Id,
890
+								//		Type:                    1,
891
+								//		Manufacturer:            0,
892
+								//		Dealer:                  0,
893
+								//		IsSys:                   1,
894
+								//		SysRecordTime:           record_time,
895
+								//	}
896
+								//
897
+								//	stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
898
+								//	warehouseOutInfo.Price = stockInInfo.Price
899
+								//	warehouseOutInfo.DrugId = item.DrugId
900
+								//	//warehouseOutInfo.Count = item.
901
+								//	prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
902
+								//	count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
903
+								//	err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
904
+								//	if err == nil {
905
+								//		details := &models.DrugAutomaticReduceDetail{
906
+								//			WarehouseOutId:          warehouseOutInfo.ID,
907
+								//			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
908
+								//			PatientId:               item.PatientId,
909
+								//			Ctime:                   time.Now().Unix(),
910
+								//			Mtime:                   time.Now().Unix(),
911
+								//			Status:                  1,
912
+								//			RecordTime:              record_time,
913
+								//			OrgId:                   adminUserInfo.Org.Id,
914
+								//			DrugId:                  item.DrugId,
915
+								//			Count:                   count,
916
+								//		}
917
+								//		service.AddSigleDrugAutoReduceRecordInfo(details)
918
+								//	}
919
+								//
920
+								//} else if err == nil { //记录存在,则将增加数量
921
+								//	if outInfo.ID > 0 {
922
+								//		prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
923
+								//		count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
924
+								//		service.UpdateDrugStockOutInfoCount2(adminUserInfo.Org.Id, outInfo.ID, count)
925
+								//	}
926
+								//
927
+								//	//count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.Org.Id, record_time, item.DrugId, item.PatientId)
928
+								//	//if count == 0 {
929
+								//	prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
930
+								//	count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
931
+								//	details := &models.DrugAutomaticReduceDetail{
932
+								//		WarehouseOutId:          outInfo.ID,
933
+								//		WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
934
+								//		PatientId:               item.PatientId,
935
+								//		Ctime:                   time.Now().Unix(),
936
+								//		Mtime:                   time.Now().Unix(),
937
+								//		Status:                  1,
938
+								//		RecordTime:              record_time,
939
+								//		OrgId:                   adminUserInfo.Org.Id,
940
+								//		DrugId:                  item.DrugId,
941
+								//		Count:                   count,
942
+								//	}
943
+								//	service.AddSigleDrugAutoReduceRecordInfo(details)
944
+								//
945
+								//
946
+								//}
946 947
 							}
947 948
 						}
948 949
 
@@ -1001,7 +1002,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1001 1002
 
1002 1003
 				advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
1003 1004
 				for _, item := range advices {
1004
-					fmt.Println("item222222222222", item.ExecutionState)
1005
+
1005 1006
 					if item.ExecutionState == 1 && item.Way == 2 {
1006 1007
 
1007 1008
 						prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
@@ -1036,7 +1037,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1036 1037
 
1037 1038
 						//查询 该患者是否已出库
1038 1039
 						out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
1039
-						fmt.Println("errcode ------------------", errcode)
1040
+
1040 1041
 						if errcode == gorm.ErrRecordNotFound {
1041 1042
 							service.CreateOutStock(&outStock)
1042 1043
 						} else if errcode == nil {
@@ -1146,26 +1147,28 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1146 1147
 							stockInInfo, _ := service.FindLastDrugStockInInfoRecord(advice.DrugId, adminInfo.Org.Id)
1147 1148
 							warehouseOutInfo.Price = stockInInfo.Price
1148 1149
 							err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1150
+
1149 1151
 							if err == nil {
1150
-								details := &models.DrugAutomaticReduceDetail{
1151
-									WarehouseOutId:          warehouseOutInfo.ID,
1152
-									WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1153
-									PatientId:               advice.PatientId,
1154
-									Ctime:                   time.Now().Unix(),
1155
-									Mtime:                   time.Now().Unix(),
1156
-									Status:                  1,
1157
-									RecordTime:              record_time,
1158
-									OrgId:                   adminInfo.Org.Id,
1159
-									DrugId:                  advice.DrugId,
1160
-									Count:                   count,
1161
-								}
1162
-								service.AddSigleDrugAutoReduceRecordInfo(details)
1152
+								service.HisDrugsDelivery(adminInfo.Org.Id, &advice)
1153
+								//details := &models.DrugAutomaticReduceDetail{
1154
+								//	WarehouseOutId:          warehouseOutInfo.ID,
1155
+								//	WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1156
+								//	PatientId:               advice.PatientId,
1157
+								//	Ctime:                   time.Now().Unix(),
1158
+								//	Mtime:                   time.Now().Unix(),
1159
+								//	Status:                  1,
1160
+								//	RecordTime:              record_time,
1161
+								//	OrgId:                   adminInfo.Org.Id,
1162
+								//	DrugId:                  advice.DrugId,
1163
+								//	Count:                   count,
1164
+								//}
1165
+								//service.AddSigleDrugAutoReduceRecordInfo(details)
1163 1166
 							}
1164 1167
 						}
1165 1168
 					}
1166 1169
 
1167 1170
 				} else if err == nil {
1168
-					outInfo, err := service.FindDrugStockOutInfoByTypeId(adminInfo.Org.Id, advice.DrugId, out.ID, out.WarehouseOutOrderNumber)
1171
+					_, err := service.FindDrugStockOutInfoByTypeId(adminInfo.Org.Id, advice.DrugId, out.ID, out.WarehouseOutOrderNumber)
1169 1172
 					if err == gorm.ErrRecordNotFound {
1170 1173
 						warehouseOutInfo := &models.DrugWarehouseOutInfo{
1171 1174
 							WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
@@ -1189,42 +1192,44 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1189 1192
 						warehouseOutInfo.Count = count
1190 1193
 						err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1191 1194
 						if err == nil {
1192
-							details := &models.DrugAutomaticReduceDetail{
1193
-								WarehouseOutId:          warehouseOutInfo.ID,
1194
-								WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1195
-								PatientId:               advice.PatientId,
1196
-								Ctime:                   time.Now().Unix(),
1197
-								Mtime:                   time.Now().Unix(),
1198
-								Status:                  1,
1199
-								RecordTime:              record_time,
1200
-								OrgId:                   adminInfo.Org.Id,
1201
-								DrugId:                  advice.DrugId,
1202
-								Count:                   count,
1203
-							}
1204
-							service.AddSigleDrugAutoReduceRecordInfo(details)
1195
+							service.HisDrugsDelivery(adminInfo.Org.Id, &advice)
1196
+							//details := &models.DrugAutomaticReduceDetail{
1197
+							//	WarehouseOutId:          warehouseOutInfo.ID,
1198
+							//	WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1199
+							//	PatientId:               advice.PatientId,
1200
+							//	Ctime:                   time.Now().Unix(),
1201
+							//	Mtime:                   time.Now().Unix(),
1202
+							//	Status:                  1,
1203
+							//	RecordTime:              record_time,
1204
+							//	OrgId:                   adminInfo.Org.Id,
1205
+							//	DrugId:                  advice.DrugId,
1206
+							//	Count:                   count,
1207
+							//}
1208
+							//service.AddSigleDrugAutoReduceRecordInfo(details)
1205 1209
 						}
1206 1210
 
1207 1211
 					} else if err == nil { //记录存在,则将增加数量
1208
-						if outInfo.ID > 0 {
1209
-							prescribingNumber := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1210
-							count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1211
-							service.UpdateDrugStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, count)
1212
-						}
1213
-						prescribingNumber := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1214
-						count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1215
-						details := &models.DrugAutomaticReduceDetail{
1216
-							WarehouseOutId:          outInfo.ID,
1217
-							WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
1218
-							PatientId:               advice.PatientId,
1219
-							Ctime:                   time.Now().Unix(),
1220
-							Mtime:                   time.Now().Unix(),
1221
-							Status:                  1,
1222
-							RecordTime:              record_time,
1223
-							OrgId:                   adminInfo.Org.Id,
1224
-							DrugId:                  advice.DrugId,
1225
-							Count:                   count,
1226
-						}
1227
-						service.AddSigleDrugAutoReduceRecordInfo(details)
1212
+						service.HisDrugsDelivery(adminInfo.Org.Id, &advice)
1213
+						//if outInfo.ID > 0 {
1214
+						//	prescribingNumber := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1215
+						//	count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1216
+						//	service.UpdateDrugStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, count)
1217
+						//}
1218
+						//prescribingNumber := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1219
+						//count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1220
+						//details := &models.DrugAutomaticReduceDetail{
1221
+						//	WarehouseOutId:          outInfo.ID,
1222
+						//	WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
1223
+						//	PatientId:               advice.PatientId,
1224
+						//	Ctime:                   time.Now().Unix(),
1225
+						//	Mtime:                   time.Now().Unix(),
1226
+						//	Status:                  1,
1227
+						//	RecordTime:              record_time,
1228
+						//	OrgId:                   adminInfo.Org.Id,
1229
+						//	DrugId:                  advice.DrugId,
1230
+						//	Count:                   count,
1231
+						//}
1232
+						//service.AddSigleDrugAutoReduceRecordInfo(details)
1228 1233
 					}
1229 1234
 				}
1230 1235
 			}

+ 204 - 184
controllers/patient_api_controller.go View File

@@ -6,7 +6,7 @@ import (
6 6
 	"XT_New/service"
7 7
 	"XT_New/utils"
8 8
 	"encoding/json"
9
-	"github.com/jinzhu/gorm"
9
+	//"github.com/jinzhu/gorm"
10 10
 	"math"
11 11
 	"math/rand"
12 12
 	"reflect"
@@ -858,6 +858,9 @@ func (c *PatientApiController) UpdateDialysisSolution() {
858 858
 		DialysisDialyszers:         solution.DialysisDialyszers,
859 859
 		PlasmaSeparator:            solution.PlasmaSeparator,
860 860
 		BilirubinAdsorptionColumn:  solution.BilirubinAdsorptionColumn,
861
+		OxygenUptake:               solution.OxygenUptake,
862
+		OxygenFlow:                 solution.OxygenFlow,
863
+		OxygenTime:                 solution.OxygenTime,
861 864
 	}
862 865
 	service.UpdatePatientDialysisSolutionOne(solution.PatientId, adminUserInfo.CurrentOrgId, &prescription, todayTime.Unix())
863 866
 	if err != nil {
@@ -1648,12 +1651,12 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1648 1651
 
1649 1652
 		//自备药信息
1650 1653
 		privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.CurrentOrgId)
1651
-		fmt.Println("", drugStockConfig.IsOpen)
1654
+		fmt.Println("9999999999999999999999999", drugStockConfig.IsOpen)
1652 1655
 		if drugStockConfig.IsOpen == 1 {
1653 1656
 			//查询已经执行的医嘱
1654 1657
 			advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
1655 1658
 			for _, item := range advices {
1656
-
1659
+				fmt.Println("imte00000000000000", item.PrescribingNumber)
1657 1660
 				//调用药品出库接口
1658 1661
 				service.DrugsDelivery(item.UserOrgId, item)
1659 1662
 
@@ -1978,188 +1981,191 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1978 1981
 			//查询已经执行的医嘱
1979 1982
 			advices, _ := service.GetHisExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
1980 1983
 			for _, item := range advices {
1981
-				out, err := service.FindDrugStockOutByIsSys(adminUserInfo.CurrentOrgId, 1, item.RecordDate)
1982
-				if err == gorm.ErrRecordNotFound {
1983
-					//没有记录,则创建出库单
1984
-					timeStr := time.Now().Format("2006-01-02")
1985
-					timeArr := strings.Split(timeStr, "-")
1986
-					total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
1987
-					total = total + 1
1988
-					warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1989
-					number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1990
-					number = number + total
1991
-					warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
1992
-					creater := adminUserInfo.AdminUser.Id
1993
-					warehouseOut := models.DrugWarehouseOut{
1994
-						WarehouseOutOrderNumber: warehousing_out_order,
1995
-						OperationTime:           time.Now().Unix(),
1996
-						OrgId:                   adminUserInfo.CurrentOrgId,
1997
-						Creater:                 creater,
1998
-						Ctime:                   time.Now().Unix(),
1999
-						Status:                  1,
2000
-						WarehouseOutTime:        item.RecordDate,
2001
-						Dealer:                  0,
2002
-						Manufacturer:            0,
2003
-						Type:                    1,
2004
-						IsSys:                   1,
2005
-					}
2006
-
2007
-					err := service.AddSigleDrugWarehouseOut(&warehouseOut)
2008
-					if err != nil {
2009
-						utils.TraceLog("创建出库单失败 err = %v", err)
2010
-					} else {
2011
-						if item.PrescribingNumber > 0 {
2012
-							warehouseOutInfo := &models.DrugWarehouseOutInfo{
2013
-								WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
2014
-								WarehouseOutId:          warehouseOut.ID,
2015
-								Status:                  1,
2016
-								Ctime:                   time.Now().Unix(),
2017
-								Remark:                  "",
2018
-								OrgId:                   adminUserInfo.CurrentOrgId,
2019
-								Type:                    1,
2020
-								Manufacturer:            0,
2021
-								Dealer:                  0,
2022
-								IsSys:                   1,
2023
-								SysRecordTime:           item.RecordDate,
2024
-								DrugId:                  item.DrugId,
2025
-							}
2026
-							prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
2027
-							count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2028
-							warehouseOutInfo.Count = count
2029
-							stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
2030
-							warehouseOutInfo.Price = stockInInfo.Price
2031
-							err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
2032
-							if err == nil {
2033
-								details := &models.DrugAutomaticReduceDetail{
2034
-									WarehouseOutId:          warehouseOutInfo.ID,
2035
-									WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
2036
-									PatientId:               item.PatientId,
2037
-									Ctime:                   time.Now().Unix(),
2038
-									Mtime:                   time.Now().Unix(),
2039
-									Status:                  1,
2040
-									RecordTime:              item.RecordDate,
2041
-									OrgId:                   adminUserInfo.CurrentOrgId,
2042
-									DrugId:                  item.DrugId,
2043
-									Count:                   count,
2044
-								}
2045
-								service.AddSigleDrugAutoReduceRecordInfo(details)
2046
-								if err != nil {
2047
-									utils.TraceLog("创建出库单失败 err = %v", err)
2048
-								} else {
2049
-									if item.PrescribingNumber > 0 {
2050
-										warehouseOutInfo := &models.DrugWarehouseOutInfo{
2051
-											WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
2052
-											WarehouseOutId:          warehouseOut.ID,
2053
-											Status:                  1,
2054
-											Ctime:                   time.Now().Unix(),
2055
-											Remark:                  "",
2056
-											OrgId:                   adminUserInfo.CurrentOrgId,
2057
-											Type:                    1,
2058
-											Manufacturer:            0,
2059
-											Dealer:                  0,
2060
-											IsSys:                   1,
2061
-											SysRecordTime:           item.RecordDate,
2062
-											DrugId:                  item.DrugId,
2063
-										}
2064
-										prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
2065
-										count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2066
-										warehouseOutInfo.Count = count
2067
-										stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
2068
-										warehouseOutInfo.Price = stockInInfo.Price
2069
-										err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
2070
-										if err == nil {
2071
-											details := &models.DrugAutomaticReduceDetail{
2072
-												WarehouseOutId:          warehouseOutInfo.ID,
2073
-												WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
2074
-												PatientId:               item.PatientId,
2075
-												Ctime:                   time.Now().Unix(),
2076
-												Mtime:                   time.Now().Unix(),
2077
-												Status:                  1,
2078
-												RecordTime:              item.RecordDate,
2079
-												OrgId:                   adminUserInfo.CurrentOrgId,
2080
-												DrugId:                  item.DrugId,
2081
-												Count:                   count,
2082
-											}
2083
-											service.AddSigleDrugAutoReduceRecordInfo(details)
2084
-										}
2085
-									}
2086
-								}
2087
-
2088
-							}
2089
-						}
2090
-					}
2091
-				} else if err == nil {
2092
-					outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
2093
-					if err == gorm.ErrRecordNotFound {
2094
-						warehouseOutInfo := &models.DrugWarehouseOutInfo{
2095
-							WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
2096
-							WarehouseOutId:          out.ID,
2097
-							Status:                  1,
2098
-							Ctime:                   time.Now().Unix(),
2099
-							Remark:                  "",
2100
-							OrgId:                   adminUserInfo.CurrentOrgId,
2101
-							Type:                    1,
2102
-							Manufacturer:            0,
2103
-							Dealer:                  0,
2104
-							IsSys:                   1,
2105
-							SysRecordTime:           item.RecordDate,
2106
-						}
2107
-
2108
-						stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
2109
-						warehouseOutInfo.Price = stockInInfo.Price
2110
-						warehouseOutInfo.DrugId = item.DrugId
2111
-						prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
2112
-						count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2113
-						warehouseOutInfo.Count = count
2114
-						err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
2115
-						if err == nil {
2116
-							details := &models.DrugAutomaticReduceDetail{
2117
-								WarehouseOutId:          warehouseOutInfo.ID,
2118
-								WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
2119
-								PatientId:               item.PatientId,
2120
-								Ctime:                   time.Now().Unix(),
2121
-								Mtime:                   time.Now().Unix(),
2122
-								Status:                  1,
2123
-								RecordTime:              item.RecordDate,
2124
-								OrgId:                   adminUserInfo.CurrentOrgId,
2125
-								DrugId:                  item.DrugId,
2126
-								Count:                   count,
2127
-							}
2128
-							service.AddSigleDrugAutoReduceRecordInfo(details)
2129
-						}
2130
-
2131
-					} else if err == nil { //记录存在,则将增加数量
2132
-						if outInfo.ID > 0 {
2133
-							prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
2134
-							count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2135
-							service.UpdateDrugStockOutInfoCount2(adminUserInfo.CurrentOrgId, outInfo.ID, count)
2136
-						}
2137 1984
 
2138
-						count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.CurrentOrgId, item.RecordDate, item.DrugId, item.PatientId)
2139
-						if count == 0 {
2140
-							prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
2141
-							count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2142
-							details := &models.DrugAutomaticReduceDetail{
2143
-								WarehouseOutId:          outInfo.ID,
2144
-								WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
2145
-								PatientId:               item.PatientId,
2146
-								Ctime:                   time.Now().Unix(),
2147
-								Mtime:                   time.Now().Unix(),
2148
-								Status:                  1,
2149
-								RecordTime:              item.RecordDate,
2150
-								OrgId:                   adminUserInfo.CurrentOrgId,
2151
-								DrugId:                  item.DrugId,
2152
-								Count:                   count,
2153
-							}
2154
-							service.AddSigleDrugAutoReduceRecordInfo(details)
2155
-						} else if count == 1 {
2156
-							prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
2157
-							count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2158
-							service.UpdateDrugUserInfoDetails(item.DrugId, item.RecordDate, adminUserInfo.CurrentOrgId, item.PatientId, count, &outInfo)
2159
-						}
2160
-
2161
-					}
2162
-				}
1985
+				service.HisDrugsDelivery(item.UserOrgId, item)
1986
+
1987
+				//out, err := service.FindDrugStockOutByIsSys(adminUserInfo.CurrentOrgId, 1, item.RecordDate)
1988
+				//if err == gorm.ErrRecordNotFound {
1989
+				//	//没有记录,则创建出库单
1990
+				//	timeStr := time.Now().Format("2006-01-02")
1991
+				//	timeArr := strings.Split(timeStr, "-")
1992
+				//	total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
1993
+				//	total = total + 1
1994
+				//	warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1995
+				//	number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1996
+				//	number = number + total
1997
+				//	warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
1998
+				//	creater := adminUserInfo.AdminUser.Id
1999
+				//	warehouseOut := models.DrugWarehouseOut{
2000
+				//		WarehouseOutOrderNumber: warehousing_out_order,
2001
+				//		OperationTime:           time.Now().Unix(),
2002
+				//		OrgId:                   adminUserInfo.CurrentOrgId,
2003
+				//		Creater:                 creater,
2004
+				//		Ctime:                   time.Now().Unix(),
2005
+				//		Status:                  1,
2006
+				//		WarehouseOutTime:        item.RecordDate,
2007
+				//		Dealer:                  0,
2008
+				//		Manufacturer:            0,
2009
+				//		Type:                    1,
2010
+				//		IsSys:                   1,
2011
+				//	}
2012
+				//
2013
+				//	err := service.AddSigleDrugWarehouseOut(&warehouseOut)
2014
+				//	if err != nil {
2015
+				//		utils.TraceLog("创建出库单失败 err = %v", err)
2016
+				//	} else {
2017
+				//		if item.PrescribingNumber > 0 {
2018
+				//			warehouseOutInfo := &models.DrugWarehouseOutInfo{
2019
+				//				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
2020
+				//				WarehouseOutId:          warehouseOut.ID,
2021
+				//				Status:                  1,
2022
+				//				Ctime:                   time.Now().Unix(),
2023
+				//				Remark:                  "",
2024
+				//				OrgId:                   adminUserInfo.CurrentOrgId,
2025
+				//				Type:                    1,
2026
+				//				Manufacturer:            0,
2027
+				//				Dealer:                  0,
2028
+				//				IsSys:                   1,
2029
+				//				SysRecordTime:           item.RecordDate,
2030
+				//				DrugId:                  item.DrugId,
2031
+				//			}
2032
+				//			prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
2033
+				//			count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2034
+				//			warehouseOutInfo.Count = count
2035
+				//			stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
2036
+				//			warehouseOutInfo.Price = stockInInfo.Price
2037
+				//			err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
2038
+				//			if err == nil {
2039
+				//				details := &models.DrugAutomaticReduceDetail{
2040
+				//					WarehouseOutId:          warehouseOutInfo.ID,
2041
+				//					WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
2042
+				//					PatientId:               item.PatientId,
2043
+				//					Ctime:                   time.Now().Unix(),
2044
+				//					Mtime:                   time.Now().Unix(),
2045
+				//					Status:                  1,
2046
+				//					RecordTime:              item.RecordDate,
2047
+				//					OrgId:                   adminUserInfo.CurrentOrgId,
2048
+				//					DrugId:                  item.DrugId,
2049
+				//					Count:                   count,
2050
+				//				}
2051
+				//				service.AddSigleDrugAutoReduceRecordInfo(details)
2052
+				//				if err != nil {
2053
+				//					utils.TraceLog("创建出库单失败 err = %v", err)
2054
+				//				} else {
2055
+				//					if item.PrescribingNumber > 0 {
2056
+				//						warehouseOutInfo := &models.DrugWarehouseOutInfo{
2057
+				//							WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
2058
+				//							WarehouseOutId:          warehouseOut.ID,
2059
+				//							Status:                  1,
2060
+				//							Ctime:                   time.Now().Unix(),
2061
+				//							Remark:                  "",
2062
+				//							OrgId:                   adminUserInfo.CurrentOrgId,
2063
+				//							Type:                    1,
2064
+				//							Manufacturer:            0,
2065
+				//							Dealer:                  0,
2066
+				//							IsSys:                   1,
2067
+				//							SysRecordTime:           item.RecordDate,
2068
+				//							DrugId:                  item.DrugId,
2069
+				//						}
2070
+				//						prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
2071
+				//						count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2072
+				//						warehouseOutInfo.Count = count
2073
+				//						stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
2074
+				//						warehouseOutInfo.Price = stockInInfo.Price
2075
+				//						err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
2076
+				//						if err == nil {
2077
+				//							details := &models.DrugAutomaticReduceDetail{
2078
+				//								WarehouseOutId:          warehouseOutInfo.ID,
2079
+				//								WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
2080
+				//								PatientId:               item.PatientId,
2081
+				//								Ctime:                   time.Now().Unix(),
2082
+				//								Mtime:                   time.Now().Unix(),
2083
+				//								Status:                  1,
2084
+				//								RecordTime:              item.RecordDate,
2085
+				//								OrgId:                   adminUserInfo.CurrentOrgId,
2086
+				//								DrugId:                  item.DrugId,
2087
+				//								Count:                   count,
2088
+				//							}
2089
+				//							service.AddSigleDrugAutoReduceRecordInfo(details)
2090
+				//						}
2091
+				//					}
2092
+				//				}
2093
+				//
2094
+				//			}
2095
+				//		}
2096
+				//	}
2097
+				//} else if err == nil {
2098
+				//	outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
2099
+				//	if err == gorm.ErrRecordNotFound {
2100
+				//		warehouseOutInfo := &models.DrugWarehouseOutInfo{
2101
+				//			WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
2102
+				//			WarehouseOutId:          out.ID,
2103
+				//			Status:                  1,
2104
+				//			Ctime:                   time.Now().Unix(),
2105
+				//			Remark:                  "",
2106
+				//			OrgId:                   adminUserInfo.CurrentOrgId,
2107
+				//			Type:                    1,
2108
+				//			Manufacturer:            0,
2109
+				//			Dealer:                  0,
2110
+				//			IsSys:                   1,
2111
+				//			SysRecordTime:           item.RecordDate,
2112
+				//		}
2113
+				//
2114
+				//		stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
2115
+				//		warehouseOutInfo.Price = stockInInfo.Price
2116
+				//		warehouseOutInfo.DrugId = item.DrugId
2117
+				//		prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
2118
+				//		count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2119
+				//		warehouseOutInfo.Count = count
2120
+				//		err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
2121
+				//		if err == nil {
2122
+				//			details := &models.DrugAutomaticReduceDetail{
2123
+				//				WarehouseOutId:          warehouseOutInfo.ID,
2124
+				//				WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
2125
+				//				PatientId:               item.PatientId,
2126
+				//				Ctime:                   time.Now().Unix(),
2127
+				//				Mtime:                   time.Now().Unix(),
2128
+				//				Status:                  1,
2129
+				//				RecordTime:              item.RecordDate,
2130
+				//				OrgId:                   adminUserInfo.CurrentOrgId,
2131
+				//				DrugId:                  item.DrugId,
2132
+				//				Count:                   count,
2133
+				//			}
2134
+				//			service.AddSigleDrugAutoReduceRecordInfo(details)
2135
+				//		}
2136
+				//
2137
+				//	} else if err == nil { //记录存在,则将增加数量
2138
+				//		if outInfo.ID > 0 {
2139
+				//			prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
2140
+				//			count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2141
+				//			service.UpdateDrugStockOutInfoCount2(adminUserInfo.CurrentOrgId, outInfo.ID, count)
2142
+				//		}
2143
+				//
2144
+				//		count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.CurrentOrgId, item.RecordDate, item.DrugId, item.PatientId)
2145
+				//		if count == 0 {
2146
+				//			prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
2147
+				//			count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2148
+				//			details := &models.DrugAutomaticReduceDetail{
2149
+				//				WarehouseOutId:          outInfo.ID,
2150
+				//				WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
2151
+				//				PatientId:               item.PatientId,
2152
+				//				Ctime:                   time.Now().Unix(),
2153
+				//				Mtime:                   time.Now().Unix(),
2154
+				//				Status:                  1,
2155
+				//				RecordTime:              item.RecordDate,
2156
+				//				OrgId:                   adminUserInfo.CurrentOrgId,
2157
+				//				DrugId:                  item.DrugId,
2158
+				//				Count:                   count,
2159
+				//			}
2160
+				//			service.AddSigleDrugAutoReduceRecordInfo(details)
2161
+				//		} else if count == 1 {
2162
+				//			prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
2163
+				//			count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2164
+				//			service.UpdateDrugUserInfoDetails(item.DrugId, item.RecordDate, adminUserInfo.CurrentOrgId, item.PatientId, count, &outInfo)
2165
+				//		}
2166
+				//
2167
+				//	}
2168
+				//}
2163 2169
 			}
2164 2170
 		}
2165 2171
 		c.ServeSuccessJSON(map[string]interface{}{
@@ -3423,6 +3429,20 @@ func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, met
3423 3429
 		solution.BilirubinAdsorptionColumn = bilirubinAdsorptionColumn
3424 3430
 	}
3425 3431
 
3432
+	if dataBody["oxygen_uptake"] != nil && reflect.TypeOf(dataBody["oxygen_uptake"]).String() == "float64" {
3433
+		oxygen_uptake := int64(dataBody["oxygen_uptake"].(float64))
3434
+		solution.OxygenUptake = oxygen_uptake
3435
+	}
3436
+
3437
+	if dataBody["oxygen_flow"] != nil && reflect.TypeOf(dataBody["oxygen_flow"]).String() == "string" {
3438
+		oxygen_flow := dataBody["oxygen_flow"].(string)
3439
+		solution.OxygenFlow = oxygen_flow
3440
+	}
3441
+
3442
+	if dataBody["oxygen_time"] != nil && reflect.TypeOf(dataBody["oxygen_time"]).String() == "string" {
3443
+		oxygen_time := dataBody["oxygen_time"].(string)
3444
+		solution.OxygenTime = oxygen_time
3445
+	}
3426 3446
 	return
3427 3447
 }
3428 3448
 

+ 28 - 15
controllers/stock_in_api_controller.go View File

@@ -76,6 +76,8 @@ func StockManagerApiRegistRouters() {
76 76
 	beego.Router("/api/good/initializtion", &StockManagerApiController{}, "Get:GetInitializtion")
77 77
 
78 78
 	beego.Router("/api/good/getwarehouseorderinfolist", &StockManagerApiController{}, "Get:GetWarehouseOrderInfolist")
79
+
80
+	beego.Router("/api/good/postsearchgoodlist", &StockManagerApiController{}, "Get:PostSearchGoodList")
79 81
 }
80 82
 
81 83
 func (c *StockManagerApiController) CreateWarehouse() {
@@ -2607,12 +2609,13 @@ func (this *StockManagerApiController) AddDrugInformation() {
2607 2609
 
2608 2610
 		drug.DrugName = drug_name
2609 2611
 
2610
-		if goodNameM["unval"] == nil || reflect.TypeOf(goodNameM["unval"]).String() != "string" {
2611
-			utils.ErrorLog("unval")
2612
+		if goodNameM["min_number"] == nil || reflect.TypeOf(goodNameM["min_number"]).String() != "string" {
2613
+			utils.ErrorLog("min_number")
2612 2614
 			return
2613 2615
 		}
2614 2616
 
2615
-		unval, _ := goodNameM["unval"].(string)
2617
+		min_number, _ := goodNameM["min_number"].(string)
2618
+		minNumber, _ := strconv.ParseInt(min_number, 10, 64)
2616 2619
 		if len(drug_name) == 0 { //名字为空则生成一条导入错误日志
2617 2620
 			err_log := models.ExportErrLog{
2618 2621
 				LogType:    4,
@@ -2627,7 +2630,7 @@ func (this *StockManagerApiController) AddDrugInformation() {
2627 2630
 			continue
2628 2631
 		}
2629 2632
 
2630
-		drug.Unval = unval
2633
+		drug.MinNumber = minNumber
2631 2634
 
2632 2635
 		min_unit := goodNameM["min_unit"].(string)
2633 2636
 		if len(min_unit) == 0 { //名字为空则生成一条导入错误日志
@@ -2646,8 +2649,8 @@ func (this *StockManagerApiController) AddDrugInformation() {
2646 2649
 
2647 2650
 		drug.MinUnit = min_unit
2648 2651
 
2649
-		dosage, _ := goodNameM["dosage"].(string)
2650
-		if len(dosage) == 0 { //名字为空则生成一条导入错误日志
2652
+		dose := goodNameM["dose"].(float64)
2653
+		if dose < 0 { //名字为空则生成一条导入错误日志
2651 2654
 			err_log := models.ExportErrLog{
2652 2655
 				LogType:    4,
2653 2656
 				UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
@@ -2661,7 +2664,7 @@ func (this *StockManagerApiController) AddDrugInformation() {
2661 2664
 			continue
2662 2665
 		}
2663 2666
 
2664
-		drug.Dosage = dosage
2667
+		drug.Dose = dose
2665 2668
 
2666 2669
 		max_unit_id := goodNameM["max_unit"].(string)
2667 2670
 		if len(max_unit_id) == 0 { //名字为空则生成一条导入错误日志
@@ -2680,8 +2683,8 @@ func (this *StockManagerApiController) AddDrugInformation() {
2680 2683
 
2681 2684
 		drug.MaxUnit = max_unit_id
2682 2685
 
2683
-		packing_unit := goodNameM["packing_unit"].(string)
2684
-		if len(packing_unit) == 0 { //名字为空则生成一条导入错误日志
2686
+		max_unit := goodNameM["max_unit"].(string)
2687
+		if len(max_unit) == 0 { //名字为空则生成一条导入错误日志
2685 2688
 			err_log := models.ExportErrLog{
2686 2689
 				LogType:    4,
2687 2690
 				UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
@@ -2695,7 +2698,7 @@ func (this *StockManagerApiController) AddDrugInformation() {
2695 2698
 			continue
2696 2699
 		}
2697 2700
 
2698
-		drug.PackingUnit = packing_unit
2701
+		drug.MaxUnit = max_unit
2699 2702
 
2700 2703
 		delivery_way := goodNameM["delivery_way"].(string)
2701 2704
 		if len(delivery_way) == 0 { //名字为空则生成一条导入错误日志
@@ -3463,17 +3466,14 @@ func (this *StockManagerApiController) AddDrugInformation() {
3463 3466
 				DrugDose:                    item.DrugDose,
3464 3467
 				DrugDoseUnit:                item.DrugDoseUnit,
3465 3468
 				LmtUsedFlag:                 item.LmtUsedFlag,
3466
-				Dosage:                      item.Dosage,
3467
-				Unval:                       item.Unval,
3468
-				PackingUnit:                 item.PackingUnit,
3469
-				PackingPrice:                item.PackingPrice,
3470 3469
 				DrugDay:                     item.DrugDay,
3471 3470
 				DeliveryWay:                 item.DeliveryWay,
3472 3471
 				ExecutionFrequency:          item.ExecutionFrequency,
3472
+				DoseUnit:                    item.DoseUnit,
3473 3473
 			}
3474 3474
 
3475 3475
 			//查询同种药品同种规格是否存在
3476
-			_, drugerror := service.IsExistDrugByNameOne(item.DrugName, item.Dosage, item.MaxUnit, item.Unval, item.MinUnit, item.PackingUnit, orgId)
3476
+			_, drugerror := service.IsExistDrugByNameOne(item.DrugName, item.Dose, item.MaxUnit, item.MinNumber, item.MinUnit, item.MaxUnit, orgId)
3477 3477
 
3478 3478
 			if drugerror == gorm.ErrRecordNotFound {
3479 3479
 				service.CreateDrugsInfomation(&goodInfo)
@@ -3593,3 +3593,16 @@ func (this *StockManagerApiController) GetWarehouseOrderInfolist() {
3593 3593
 		"list": list,
3594 3594
 	})
3595 3595
 }
3596
+
3597
+func (this *StockManagerApiController) PostSearchGoodList() {
3598
+
3599
+	keyword := this.GetString("keyword")
3600
+	adminUserInfo := this.GetAdminUserInfo()
3601
+	orgId := adminUserInfo.CurrentOrgId
3602
+	list, _ := service.GetSearchGoodList(keyword, orgId)
3603
+	manufacturerList, _ := service.GetAllManufacturerList(orgId)
3604
+	this.ServeSuccessJSON(map[string]interface{}{
3605
+		"list":             list,
3606
+		"manufacturerList": manufacturerList,
3607
+	})
3608
+}

+ 47 - 5
models/dialysis.go View File

@@ -198,6 +198,38 @@ type DialysisSchedule struct {
198 198
 	//TreatmentMode   TreatmentMode   `gorm:"ForeignKey:ModeId"`
199 199
 }
200 200
 
201
+type DialysisScheduleOne struct {
202
+	ID           int64 `gorm:"column:id" json:"id" form:"id"`
203
+	UserOrgId    int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
204
+	PartitionId  int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
205
+	BedId        int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
206
+	PatientId    int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
207
+	ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
208
+	ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
209
+	ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
210
+	ModeId       int64 `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
211
+	Status       int64 `gorm:"column:status" json:"status" form:"status"`
212
+	CreatedTime  int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
213
+	UpdatedTime  int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
214
+
215
+	MonitorPatients MonitorPatients `gorm:"ForeignKey:PatientId" json:"patient"`
216
+	DeviceNumber    DeviceNumber    `gorm:"ForeignKey:BedId" json:"device_number"`
217
+	DeviceZone      DeviceZone      `gorm:"ForeignKey:PartitionId" json:"device_zone"`
218
+	TreatmentMode   TreatmentMode   `gorm:"ForeignKey:ModeId" json:"treatment_mode"`
219
+
220
+	DialysisOrder            MonitorDialysisOrder    `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
221
+	Prescription             DialysisPrescription    `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
222
+	AssessmentBeforeDislysis PredialysisEvaluation   `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
223
+	AssessmentAfterDislysis  AssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
224
+	MonitoringRecord         []MonitoringRecord      `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
225
+
226
+	//Patient         string          `gorm:"-" json:"patient" form:"patient"`
227
+	//SchedualPatient SchedualPatient `gorm:"ForeignKey:PatientId"`
228
+	//DeviceNumber    DeviceNumber    `gorm:"ForeignKey:BedId"`
229
+	//DeviceZone      DeviceZone      `gorm:"ForeignKey:PartitionId"`
230
+	//TreatmentMode   TreatmentMode   `gorm:"ForeignKey:ModeId"`
231
+}
232
+
201 233
 func (DialysisSchedule) TableName() string {
202 234
 	return "xt_schedule"
203 235
 }
@@ -987,6 +1019,7 @@ type DialysisBeforePrepare struct {
987 1019
 	Modifier     int64  `gorm:"column:modifier" json:"modifier" form:"modifier"`
988 1020
 	Status       int64  `gorm:"column:status" json:"status" form:"status"`
989 1021
 	CommdityCode string `gorm:"column:commdity_code" json:"commdity_code" form:"commdity_code"`
1022
+	NewCount     int64  `gorm:"column:new_count" json:"new_count" form:"new_count"`
990 1023
 }
991 1024
 
992 1025
 func (DialysisBeforePrepare) TableName() string {
@@ -994,11 +1027,20 @@ func (DialysisBeforePrepare) TableName() string {
994 1027
 }
995 1028
 
996 1029
 type DialysisBeforePrepareGoods struct {
997
-	GoodId       int64  `gorm:"column:good_id" json:"good_id" form:"good_id"`
998
-	Count       int64  `gorm:"column:count" json:"count" form:"count"`
999
-	GoodTypeId   int64  `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
1000
-	TypeName   	 string  `gorm:"column:type_name" json:"type_name" form:"type_name"`
1001
-	SpecificationName   string  `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
1030
+	GoodId            int64  `gorm:"column:good_id" json:"good_id" form:"good_id"`
1031
+	Count             int64  `gorm:"column:count" json:"count" form:"count"`
1032
+	GoodTypeId        int64  `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
1033
+	TypeName          string `gorm:"column:type_name" json:"type_name" form:"type_name"`
1034
+	SpecificationName string `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
1035
+}
1036
+
1037
+type NewDialysisBeforePrepareGoods struct {
1038
+	GoodId            int64  `gorm:"column:good_id" json:"good_id" form:"good_id"`
1039
+	Count             int64  `gorm:"column:count" json:"count" form:"count"`
1040
+	GoodTypeId        int64  `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
1041
+	TypeName          string `gorm:"column:type_name" json:"type_name" form:"type_name"`
1042
+	SpecificationName string `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
1043
+	NewCount          int64  `gorm:"column:new_count" json:"new_count" form:"new_count"`
1002 1044
 }
1003 1045
 
1004 1046
 type QueueCallConfig struct {

+ 6 - 10
models/drug.go View File

@@ -16,12 +16,11 @@ type BaseDrugLib struct {
16 16
 	DrugDosageForm              int64   `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
17 17
 	MedicalInsuranceLevel       int64   `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
18 18
 	MaxUnit                     string  `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
19
-	MinNumber					int64 	`gorm:"column:min_number" json:"min_number" form:"min_number"`
19
+	MinNumber                   int64   `gorm:"column:min_number" json:"min_number" form:"min_number"`
20 20
 	MinUnit                     string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
21
-	Dose                     	float64  `gorm:"column:dose" json:"dose" form:"dose"`
22
-	DoseUnit                    string  `gorm:"column:Dose_unit" json:"Dose_unit" form:"Dose_unit"`
23
-	MinPrice                    string  `gorm:"column:min_price" json:"min_price" form:"min_price"`
24
-
21
+	Dose                        float64 `gorm:"column:dose" json:"dose" form:"dose"`
22
+	DoseUnit                    string  `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
23
+	MinPrice                    float64 `gorm:"column:min_price" json:"min_price" form:"min_price"`
25 24
 	UnitMatrixing               string  `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
26 25
 	RetailPrice                 float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
27 26
 	LastPrice                   float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
@@ -65,11 +64,8 @@ type BaseDrugLib struct {
65 64
 	HospApprFlag                int64   `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
66 65
 	LmtUsedFlag                 int64   `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
67 66
 	//MedicineInsurancePercentage []*MedicineInsurancePercentage `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
68
-	Dosage       string  `gorm:"column:dosage" json:"dosage" form:"dosage"`
69
-	Unval        string  `gorm:"column:unval" json:"unval" form:"unval"`
70
-	PackingUnit  string  `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
71
-	PackingPrice float64 `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
72
-	DrugDay      string  `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
67
+	DrugDay string  `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
68
+	Total   float64 `gorm:"column:total" json:"total" form:"total"`
73 69
 }
74 70
 
75 71
 func (BaseDrugLib) TableName() string {

+ 5 - 0
models/good_models.go View File

@@ -71,6 +71,11 @@ type GoodInfo struct {
71 71
 	ProductionType              string    `gorm:"column:production_type" json:"production_type" form:"production_type"`
72 72
 	SpecialMedical              string    `gorm:"column:special_medical" json:"special_medical" form:"special_medical"`
73 73
 	IsMark                      int64     `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
74
+	MinNumber                   int64     `gorm:"column:min_number" json:"min_number" form:"min_number"`
75
+	PackingUnit                 string    `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
76
+	PackingPrice                float64   `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
77
+	DefaultCountUnit            string    `gorm:"column:default_count_unit" json:"default_count_unit" form:"default_count_unit"`
78
+	MinUnit                     string    `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
74 79
 }
75 80
 
76 81
 func (GoodInfo) TableName() string {

+ 1 - 1
models/new_monitor.go View File

@@ -20,7 +20,7 @@ type NewVMMonitorDialysisSchedule struct {
20 20
 	Prescription             VMDialysisPrescription    `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
21 21
 	AssessmentBeforeDislysis VMPredialysisEvaluation   `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
22 22
 	AssessmentAfterDislysis  VMAssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
23
-	MonitoringRecord         []VMMonitoringRecord      `gorm:"ForeignKey:PatientId,MonitoringDate;AssociationForeignKey:PatientId,ScheduleDate" json:"monitoring_record"`
23
+	MonitoringRecord         []VMMonitoringRecord      `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
24 24
 }
25 25
 
26 26
 func (NewVMMonitorDialysisSchedule) TableName() string {

+ 6 - 0
models/patient_models.go View File

@@ -237,6 +237,9 @@ type DialysisPrescription struct {
237 237
 	ReplacementFlow            string        `gorm:"column:replacement_flow" json:"replacement_flow" form:"replacement_flow"`
238 238
 	PlasmaSeparator            string        `gorm:"column:plasma_separator" json:"plasma_separator" form:"plasma_separator"`
239 239
 	BilirubinAdsorptionColumn  string        `gorm:"column:bilirubin_adsorption_column" json:"bilirubin_adsorption_column" form:"bilirubin_adsorption_column"`
240
+	OxygenUptake               int64         `gorm:"column:oxygen_uptake" json:"oxygen_uptake" form:"oxygen_uptake"`
241
+	OxygenFlow                 string        `gorm:"column:oxygen_flow" json:"oxygen_flow" form:"oxygen_flow"`
242
+	OxygenTime                 string        `gorm:"column:oxygen_time" json:"oxygen_time" form:"oxygen_time"`
240 243
 }
241 244
 
242 245
 func (DialysisPrescription) TableName() string {
@@ -342,6 +345,9 @@ type DialysisSolution struct {
342 345
 	Amylaceum                  string  `gorm:"column:amylaceum" json:"amylaceum" form:"amylaceum"`
343 346
 	PlasmaSeparator            string  `gorm:"column:plasma_separator" json:"plasma_separator" form:"plasma_separator"`
344 347
 	BilirubinAdsorptionColumn  string  `gorm:"column:bilirubin_adsorption_column" json:"bilirubin_adsorption_column" form:"bilirubin_adsorption_column"`
348
+	OxygenUptake               int64   `gorm:"column:oxygen_uptake" json:"oxygen_uptake" form:"oxygen_uptake"`
349
+	OxygenFlow                 string  `gorm:"column:oxygen_flow" json:"oxygen_flow" form:"oxygen_flow"`
350
+	OxygenTime                 string  `gorm:"column:oxygen_time" json:"oxygen_time" form:"oxygen_time"`
345 351
 }
346 352
 
347 353
 func (DialysisSolution) TableName() string {

+ 36 - 0
models/self_drug_models.go View File

@@ -560,3 +560,39 @@ type XtOrderConfig struct {
560 560
 func (XtOrderConfig) TableName() string {
561 561
 	return "xt_order_config"
562 562
 }
563
+
564
+type StDrugWarehouseInfo struct {
565
+	ID               int64   `gorm:"column:id" json:"id" form:"id"`
566
+	WarehousingId    int64   `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
567
+	DrugId           int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
568
+	Number           string  `gorm:"column:number" json:"number" form:"number"`
569
+	ProductDate      int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
570
+	ExpiryDate       int64   `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
571
+	WarehousingCount int64   `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
572
+	Price            float64 `gorm:"column:price" json:"price" form:"price"`
573
+	TotalPrice       float64 `gorm:"column:total_price" json:"total_price" form:"total_price"`
574
+	Dealer           int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
575
+	Manufacturer     int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
576
+	Remark           string  `gorm:"column:remark" json:"remark" form:"remark"`
577
+	Ctime            int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
578
+	Mtime            int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
579
+	Status           int64   `gorm:"column:status" json:"status" form:"status"`
580
+	OrgId            int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
581
+	IsReturn         int64   `gorm:"column:is_return" json:"is_return" form:"is_return"`
582
+	WarehousingOrder string  `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
583
+	Type             int64   `gorm:"column:type" json:"type" form:"type"`
584
+	RetailPrice      float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
585
+	RetailTotalPrice float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
586
+	StockMaxNumber   int64   `gorm:"column:stock_max_number" json:"stock_max_number"`
587
+	StockMinNumber   int64   `gorm:"column:stock_min_number" json:"stock_min_number"`
588
+	DrugName         string  `json:"drug_name"`
589
+	DrugType         int64   `json:"drug_type"`
590
+	MaxUnit          string  `json:"max_unit"`
591
+	MinUnit          string  `json:"min_unit"`
592
+	MinNumber        int64   `json:"min_number"`
593
+	Dose             float64 `json:"dose"`
594
+	DoseUnit         string  `json:"dose_unit"`
595
+	LastPrice        string  `json:"last_price"`
596
+	PackingUnit      string  `json:"packing_unit"`
597
+	Dosage           int64   `json:"dosage"`
598
+}

+ 7 - 7
models/service/dialysis_service.go View File

@@ -629,19 +629,19 @@ func GetLastAcceptsAssessment(patient int64, orgId int64) (error, models.Receive
629 629
 	return err, receiveTreatmentAsses
630 630
 }
631 631
 
632
-func GetDialysisWatch(orgID int64, schedulDate int64, schedulType int64, partitionType int64, page int64, limit int64) (schedule []*models.DialysisSchedule, err error, total int64) {
632
+func GetDialysisWatch(orgID int64, schedulDate int64, schedulType int64, partitionType int64, page int64, limit int64) (schedule []*models.DialysisScheduleOne, err error, total int64) {
633 633
 	db := readDb.
634 634
 		Model(&models.MonitorDialysisSchedule{}).
635 635
 		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
636 636
 		// Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
637
-		Preload("TreatmentMode", "status = 1").
638
-		Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
639
-		Preload("AssessmentBeforeDislysis", "status = 1 AND  user_org_id = ?", orgID).
640
-		Preload("AssessmentAfterDislysis", "status = 1 AND  user_org_id = ?", orgID).
637
+		Preload("TreatmentMode", "status = 1 ").
638
+		Preload("Prescription", "status = 1 AND user_org_id = ? and  record_date = ?", orgID, schedulDate).
639
+		Preload("AssessmentBeforeDislysis", "status = 1 AND  user_org_id = ? and assessment_date = ?", orgID, schedulDate).
640
+		Preload("AssessmentAfterDislysis", "status = 1 AND  user_org_id = ? and assessment_date = ?", orgID).
641 641
 		Preload("MonitoringRecord", func(db *gorm.DB) *gorm.DB {
642
-			return db.Where("status = 1 AND user_org_id = ?", orgID).Order("operate_time asc")
642
+			return db.Where("status = 1 AND user_org_id = ? and monitoring_date = ?", orgID, schedulDate).Order("operate_time asc")
643 643
 		}).
644
-		Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
644
+		Preload("DialysisOrder", "status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, schedulDate).
645 645
 		Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
646 646
 	db = db.Where("xt_schedule.status = 1 AND user_org_id = ?", orgID)
647 647
 	if schedulDate > 0 {

+ 7 - 1
models/service/stock_service.go View File

@@ -1260,6 +1260,11 @@ func UpDateWarehouseInfoByStock(warehouseInfo *models.WarehousingInfo) (err erro
1260 1260
 	return
1261 1261
 }
1262 1262
 
1263
+//func UpDateWarehouseInfoByStockDelete(id int64,count int64) (err error) {
1264
+//  err = writeDb.Model(&models.WarehousingInfo{}).Where("id = ?",id).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
1265
+//  return err
1266
+//}
1267
+
1263 1268
 func UpDateWarehouseStatus(id int64) (err error) {
1264 1269
 	err = readDb.Model(&models.WarehousingInfo{}).Where("id = ? AND status = 1", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
1265 1270
 	return
@@ -1983,7 +1988,8 @@ func AddSigleDrugWarehouseOutInfo(info *models.DrugWarehouseOutInfo) error {
1983 1988
 }
1984 1989
 
1985 1990
 func AddSigleAutoReduceRecordInfo(detail *models.AutomaticReduceDetail) error {
1986
-	err := writeDb.Create(&detail).Error
1991
+
1992
+	err := XTWriteDB().Create(&detail).Error
1987 1993
 	return err
1988 1994
 
1989 1995
 }

+ 2 - 2
models/stock_models.go View File

@@ -80,7 +80,6 @@ type WarehousingInfo struct {
80 80
 	ExpiryDate       int64       `gorm:"column:expiry_date" json:"expiry_date"`
81 81
 	WarehousingCount int64       `gorm:"column:warehousing_count" json:"warehousing_count"`
82 82
 	WarehousingUnit  string      `gorm:"column:warehousing_unit" json:"warehousing_unit"`
83
-	StockNumber   	 int64       `gorm:"column:stock_number" json:"stock_number"`
84 83
 	Price            float64     `gorm:"column:price" json:"price"`
85 84
 	TotalPrice       float64     `gorm:"column:total_price" json:"total_price"`
86 85
 	Dealer           int64       `gorm:"column:dealer" json:"dealer"`
@@ -91,6 +90,7 @@ type WarehousingInfo struct {
91 90
 	Status           int64       `gorm:"column:status" json:"status"`
92 91
 	OrgId            int64       `gorm:"column:org_id" json:"org_id"`
93 92
 	IsReturn         int64       `gorm:"column:is_return" json:"is_return"`
93
+	StockCount       int64       `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
94 94
 	Warehousing      Warehousing `ForeignKey:WarehousingId json:"warehouse"`
95 95
 	WarehousingOrder string      `gorm:"column:warehousing_order" json:"warehousing_order"`
96 96
 	GoodInfo         GoodInfo    `gorm:"ForeignKey:ID;AssociationForeignKey:GoodId" `
@@ -151,7 +151,7 @@ type WarehouseOutInfo struct {
151 151
 	Manufacturer            int64        `gorm:"column:manufacturer" json:"manufacturer"`
152 152
 	IsSys                   int64        `gorm:"column:is_sys" json:"is_sys"`
153 153
 	SysRecordTime           int64        `gorm:"column:sys_record_time" json:"sys_record_time"`
154
-	PatientId				int64 		 `gorm:"column:patient_id" json:"patient_id"`
154
+	PatientId               int64        `gorm:"column:patient_id" json:"patient_id"`
155 155
 }
156 156
 
157 157
 func (WarehouseOutInfo) TableName() string {

+ 83 - 0
service/gobal_config_service.go View File

@@ -479,3 +479,86 @@ func GetDrugWarehuseOrderInfo(orgid int64) (drug []*models.DrugWarehouseInfo, er
479 479
 	err = XTReadDB().Where("org_id = ? and status = 1", orgid).Group("drug_id").Find(&drug).Error
480 480
 	return drug, err
481 481
 }
482
+
483
+func GetDrugStockList(page int64, limit int64, keyword string, drugcategory int64, startime int64, endtime int64, orgid int64) (list []*models.StDrugWarehouseInfo, total int64, err error) {
484
+
485
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
486
+
487
+	likeKey := "%" + keyword + "%"
488
+	offset := (page - 1) * limit
489
+	if len(keyword) > 0 {
490
+		db = db.Joins("left join xt_base_drug as t on t.id = x.drug_id and t.status= 1 and t.org_id = ? and  t.drug_name like ?", orgid, likeKey)
491
+	} else {
492
+		db.Joins("left join xt_base_drug as t on t.id = x.drug_id and t.status= 1 and t.org_id = ?", orgid)
493
+	}
494
+	if drugcategory > 0 {
495
+		db = db.Joins("left join xt_base_drug as t on t.id = x.drug_id and t.status= 1 and t.org_id = ? and  t.drug_category = ?", orgid, drugcategory)
496
+	} else {
497
+		db = db.Joins("left join xt_base_drug as t on t.id = x.drug_id and t.status= 1 and t.org_id = ? and  t.drug_category = ?", orgid, drugcategory)
498
+	}
499
+
500
+	if startime > 0 {
501
+		db = db.Where("x.ctime >=?", startime)
502
+	}
503
+	if endtime > 0 {
504
+		db = db.Where("x.ctime<=?", endtime)
505
+	}
506
+
507
+	if orgid > 0 {
508
+		db = db.Where("x.org_id = ?", orgid)
509
+	}
510
+
511
+	err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.max_unit,x.min_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.packing_unit,t.dosage,t.manufacturer").Offset(offset).Count(&total).Group("x.drug_id").Order("x.ctime desc").Scan(&list).Error
512
+	return list, total, err
513
+}
514
+
515
+func GetDrugStockFlow(drugid int64, startime int64, endtime int64, page int64, limit int64, orgid int64) (list []*models.StDrugWarehouseInfo, total int64, err error) {
516
+
517
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
518
+	offset := (page - 1) * limit
519
+	if startime > 0 {
520
+		db = db.Where("x.ctime >=?", startime)
521
+	}
522
+	if endtime > 0 {
523
+		db = db.Where("x.ctime<=?", endtime)
524
+	}
525
+
526
+	if orgid > 0 {
527
+		db = db.Where("x.org_id = ?", orgid)
528
+	}
529
+
530
+	if drugid > 0 {
531
+		db = db.Where("x.drug_id = ?", drugid)
532
+	}
533
+
534
+	err = db.Joins("left join xt_base_drug as t on t.id = x.drug_id and t.status = 1 and t.org_id = ?", orgid).Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.max_unit,x.min_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.packing_unit,t.dosage,t.manufacturer").Offset(offset).Count(&total).Order("x.ctime desc").Scan(&list).Error
535
+	return list, total, err
536
+}
537
+
538
+func GetDrugStockOutFlow(drugid int64, startime int64, endtime int64, page int64, limit int64, orgid int64, stocktype int64) (list []*models.XtDrugWarehouseOutInfo, total int64, err error) {
539
+
540
+	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
541
+	offset := (page - 1) * limit
542
+	if startime > 0 {
543
+		db = db.Where("x.ctime >=?", startime)
544
+	}
545
+	if endtime > 0 {
546
+		db = db.Where("x.ctime<=?", endtime)
547
+	}
548
+
549
+	if orgid > 0 {
550
+		db = db.Where("x.org_id = ?", orgid)
551
+	}
552
+
553
+	if drugid > 0 {
554
+		db = db.Where("x.drug_id = ?", drugid)
555
+	}
556
+	if stocktype == 1 {
557
+		db = db.Where("x.is_sys = 0")
558
+	}
559
+	if stocktype == 2 {
560
+		db = db.Where("x,is_sys = 1")
561
+	}
562
+	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.warehousing_out_target,x.count,x.count_unit,x.price,x.total_price,x.product_date,x.expiry_date,x.org_id,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,x.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,x.warehouse_info_id").Offset(offset).Count(&total).Order("x.ctime desc").Scan(&list).Error
563
+	return list, total, err
564
+}

+ 1 - 1
service/manage_center_service.go View File

@@ -159,7 +159,7 @@ func FindBaseDrugLibRecordCount(lib *models.BaseDrugLib) (count int64) {
159 159
 }
160 160
 
161 161
 func FindBaseDrugLibRecordCountOne(lib *models.BaseDrugLib) (count int64) {
162
-	readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? and drug_name = ? and dosage = ? and max_unit = ? and unval = ? and min_unit = ? and packing_unit = ? and manufacturer = ? and status = 1", lib.OrgId, lib.DrugName, lib.Dosage, lib.MaxUnit, lib.Unval, lib.MinUnit, lib.PackingUnit, lib.Manufacturer).Count(&count)
162
+	readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? and drug_name = ? and dose = ? and dose_unit = ? and min_number = ? and min_unit = ? and max_unit = ? and manufacturer = ? and status = 1", lib.OrgId, lib.DrugName, lib.Dose, lib.DoseUnit, lib.MinNumber, lib.MinUnit, lib.MaxUnit, lib.Manufacturer).Count(&count)
163 163
 	return
164 164
 }
165 165
 

+ 1 - 1
service/patient_service.go View File

@@ -1491,7 +1491,7 @@ func GetDialysisCount(orgid int64, partitionid int64) (order []*models.BloodDial
1491 1491
 
1492 1492
 func UpdatePatientDialysisSolutionOne(patientid int64, orgid int64, prescription *models.DialysisPrescription, timenow int64) error {
1493 1493
 
1494
-	err = XTWriteDB().Model(&prescription).Where("patient_id = ? and user_org_id = ? and record_date = ? ", patientid, orgid, timenow).Updates(map[string]interface{}{"dialyzer": prescription.Dialyzer, "anticoagulant": prescription.Anticoagulant, "mode_id": prescription.ModeId, "dialysis_duration_hour": prescription.DialysisDurationHour, "anticoagulant_shouji": prescription.AnticoagulantShouji, "anticoagulant_weichi": prescription.AnticoagulantWeichi, "anticoagulant_zongliang": prescription.AnticoagulantZongliang, "kalium": prescription.Kalium, "sodium": prescription.Sodium, "calcium": prescription.Calcium, "dialyzer_perfusion_apparatus": prescription.DialyzerPerfusionApparatus, "blood_access": prescription.BloodAccess, "dialysate_flow": prescription.DialysateFlow, "dialysate_temperature": prescription.DialysateTemperature, "dialysis_dialyszers": prescription.DialysisDialyszers, "dialysis_irrigation": prescription.DialysisIrrigation, "plasma_separator": prescription.PlasmaSeparator, "bilirubin_adsorption_column": prescription.BilirubinAdsorptionColumn}).Error
1494
+	err = XTWriteDB().Model(&prescription).Where("patient_id = ? and user_org_id = ? and record_date = ? ", patientid, orgid, timenow).Updates(map[string]interface{}{"dialyzer": prescription.Dialyzer, "anticoagulant": prescription.Anticoagulant, "mode_id": prescription.ModeId, "dialysis_duration_hour": prescription.DialysisDurationHour, "anticoagulant_shouji": prescription.AnticoagulantShouji, "anticoagulant_weichi": prescription.AnticoagulantWeichi, "anticoagulant_zongliang": prescription.AnticoagulantZongliang, "kalium": prescription.Kalium, "sodium": prescription.Sodium, "calcium": prescription.Calcium, "dialyzer_perfusion_apparatus": prescription.DialyzerPerfusionApparatus, "blood_access": prescription.BloodAccess, "dialysate_flow": prescription.DialysateFlow, "dialysate_temperature": prescription.DialysateTemperature, "dialysis_dialyszers": prescription.DialysisDialyszers, "dialysis_irrigation": prescription.DialysisIrrigation, "plasma_separator": prescription.PlasmaSeparator, "bilirubin_adsorption_column": prescription.BilirubinAdsorptionColumn, "oxygen_uptake": prescription.OxygenUptake, "oxygen_flow": prescription.OxygenFlow, "oxygen_time": prescription.OxygenTime}).Error
1495 1495
 	return err
1496 1496
 }
1497 1497
 

+ 115 - 21
service/stock_service.go View File

@@ -241,6 +241,11 @@ func ModifyGoodInfo(goodInfo *models.GoodInfo) (error, *models.GoodInfo) {
241 241
 		"social_security_directory_code": goodInfo.SocialSecurityDirectoryCode,
242 242
 		"special_medical":                goodInfo.SpecialMedical,
243 243
 		"production_type":                goodInfo.ProductionType,
244
+		"min_number":                     goodInfo.MinNumber,
245
+		"packing_unit":                   goodInfo.PackingUnit,
246
+		"packing_price":                  goodInfo.PackingPrice,
247
+		"default_count_unit":             goodInfo.DefaultCountUnit,
248
+		"min_unit":                       goodInfo.MinUnit,
244 249
 	}).Error
245 250
 
246 251
 	writeDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND org_id = ?", goodInfo.ID, goodInfo.OrgId).Updates(map[string]interface{}{"good_type_id": goodInfo.GoodTypeId})
@@ -412,11 +417,11 @@ func CreateDrugWarehousingInfo(warehousingInfo []*models.DrugWarehouseInfo) (err
412 417
 	if len(warehousingInfo) > 0 {
413 418
 		utx := writeDb.Begin()
414 419
 		if len(warehousingInfo) > 0 {
415
-			thisSQL := "INSERT INTO xt_drug_warehouse_info (warehousing_id, drug_id, number, product_date,expiry_date,warehousing_count,price,total_price,dealer,manufacturer,remark,ctime,mtime,status,org_id,warehousing_order,type,retail_price,retail_total_price) VALUES "
420
+			thisSQL := "INSERT INTO xt_drug_warehouse_info (warehousing_id, drug_id, number, product_date,expiry_date,warehousing_count,price,total_price,dealer,manufacturer,remark,ctime,mtime,status,org_id,warehousing_order,type,retail_price,retail_total_price,stock_max_number) VALUES "
416 421
 			insertParams := make([]string, 0)
417 422
 			insertData := make([]interface{}, 0)
418 423
 			for _, info := range warehousingInfo {
419
-				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
424
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
420 425
 				insertData = append(insertData, info.WarehousingId)
421 426
 				insertData = append(insertData, info.DrugId)
422 427
 				insertData = append(insertData, info.Number)
@@ -436,7 +441,7 @@ func CreateDrugWarehousingInfo(warehousingInfo []*models.DrugWarehouseInfo) (err
436 441
 				insertData = append(insertData, info.Type)
437 442
 				insertData = append(insertData, info.RetailPrice)
438 443
 				insertData = append(insertData, info.RetailTotalPrice)
439
-
444
+				insertData = append(insertData, info.StockMaxNumber)
440 445
 			}
441 446
 			thisSQL += strings.Join(insertParams, ", ")
442 447
 			err = utx.Exec(thisSQL, insertData...).Error
@@ -453,11 +458,13 @@ func CreateDrugWarehousingInfo(warehousingInfo []*models.DrugWarehouseInfo) (err
453 458
 
454 459
 func FindLastWarehousingInfo(order string) (info models.WarehousingInfo, err error) {
455 460
 	err = readDb.Model(&models.WarehousingInfo{}).Where("warehousing_order = ? AND status = 1", order).Last(&info).Error
461
+
456 462
 	return info, err
463
+
457 464
 }
458 465
 
459
-func FindFirstWarehousingInfoByStock(good_id int64,good_type_id int64) (info models.WarehousingInfo, err error) {
460
-	err = readDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND good_type_id = ? AND status = 1 and stock_count > 0", order).Order("ctime").First(&info).Error
466
+func FindFirstWarehousingInfoByStock(good_id int64, good_type_id int64) (info models.WarehousingInfo, err error) {
467
+	err = readDb.Model(&models.WarehousingInfo{}).Where("good_id = ? AND good_type_id = ? AND status = 1 and stock_count > 0", good_id, good_type_id).Order("ctime").First(&info).Error
461 468
 	return info, err
462 469
 }
463 470
 
@@ -469,7 +476,7 @@ func FindLastDrugWarehousingInfoByID(drug_id int64) (info models.XtDrugWarehouse
469 476
 }
470 477
 
471 478
 // 出库时先进先出,找出最先入库的批次
472
-func  (drug_id int64) (info models.WarehousingInfo, err error) {
479
+func FindLastWarehousingInfoByID(drug_id int64) (info models.WarehousingInfo, err error) {
473 480
 	err = readDb.Model(&models.WarehousingInfo{}).Where("drup_id = ? AND status = 1 AND (stock_max_number > 0 or stock_min_number > 0) ", drug_id).Order("ctime").First(&info).Error
474 481
 	return info, err
475 482
 }
@@ -570,10 +577,9 @@ type Drug struct {
570 577
 	Mtime           int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
571 578
 	OrgId           int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
572 579
 	DrugCode        string  `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
573
-	Dosage          string  `gorm:"column:dosage" json:"dosage" form:"dosage"`
574
-	Unval           string  `gorm:"column:unval" json:"unval" form:"unval"`
575
-	PackingUnit     string  `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
576
-	PackingPrice    float64 `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
580
+	Dose            float64 `gorm:"column:dose" json:"dose" form:"dose"`
581
+	MinNumber       int64   `gorm:"column:min_number" json:"min_number" form:"min_number"`
582
+	DoseUnit        string  `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
577 583
 	DrugDay         string  `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
578 584
 	MaxUnit         string  `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
579 585
 	MinUnit         string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
@@ -1613,7 +1619,13 @@ func UpDateWarehouseOutStatus(id int64) (err error) {
1613 1619
 }
1614 1620
 
1615 1621
 func UpDateDrugWarehouseInfoByStock(info *models.XtDrugWarehouseInfo) (err error) {
1616
-	err = writeDb.Save(&info).Error
1622
+	ut := writeDb.Begin()
1623
+	err = ut.Save(&info).Error
1624
+	if err != nil {
1625
+		ut.Rollback()
1626
+		return err
1627
+	}
1628
+	ut.Commit()
1617 1629
 	return err
1618 1630
 }
1619 1631
 
@@ -1622,11 +1634,6 @@ func UpDateWarehouseInfoByStock(info *models.WarehousingInfo) (err error) {
1622 1634
 	return err
1623 1635
 }
1624 1636
 
1625
-func UpDateWarehouseInfoByStockDelete(id int64,count int64) (err error) {
1626
-	err = DB.Model(&models.WarehousingInfo{}).Where("id = ?",info.ID).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
1627
-	return err
1628
-}
1629
-
1630 1637
 func UpDateDrugWarehouseOutStatus(id int64) (err error) {
1631 1638
 	err = readDb.Model(&models.DrugWarehouseOutInfo{}).Where("id = ? AND status = 1", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
1632 1639
 	return
@@ -2059,16 +2066,45 @@ func FindLastDrugStockInInfoRecord(drug_id int64, org_id int64) (in models.DrugW
2059 2066
 
2060 2067
 }
2061 2068
 
2069
+func GetStockInRecoredByGoodId(goodid int64, goodtypeid int64, recordtime int64, patientid int64, orgid int64) (*models.WarehouseOutInfo, error) {
2070
+
2071
+	info := models.WarehouseOutInfo{}
2072
+
2073
+	err := XTReadDB().Model(&info).Where("good_id = ? and good_type_id = ? and sys_record_time = ? and patient_id = ? and org_id = ? and status = 1", goodid, goodtypeid, recordtime, patientid, orgid).Find(&info).Error
2074
+
2075
+	if err == gorm.ErrRecordNotFound {
2076
+		return nil, err
2077
+	}
2078
+
2079
+	if err != nil {
2080
+		return nil, err
2081
+	}
2082
+
2083
+	return &info, nil
2084
+}
2085
+
2086
+func UpdateAutoMaticReduceDetail(goodid int64, goodtypeid int64, recordtime int64, patientid int64, orgid int64, prepare *models.WarehouseOutInfo) error {
2087
+
2088
+	err := XTWriteDB().Model(&prepare).Where("good_id = ? and good_type_id = ? and sys_record_time = ? and patient_id = ? and org_id = ? and status =1", goodid, goodtypeid, recordtime, patientid, orgid).Updates(map[string]interface{}{"count": prepare.Count}).Error
2089
+	return err
2090
+}
2091
+
2062 2092
 func AddSigleWarehouseOutInfo(info *models.WarehouseOutInfo) error {
2093
+
2063 2094
 	err := writeDb.Create(&info).Error
2064 2095
 	return err
2065 2096
 
2066 2097
 }
2067 2098
 
2068 2099
 func AddSigleDrugWarehouseOutInfo(info *models.DrugWarehouseOutInfo) error {
2069
-	err := writeDb.Create(&info).Error
2100
+	ut := writeDb.Begin()
2101
+	err := ut.Create(&info).Error
2102
+	if err != nil {
2103
+		ut.Rollback()
2104
+		return err
2105
+	}
2106
+	ut.Commit()
2070 2107
 	return err
2071
-
2072 2108
 }
2073 2109
 
2074 2110
 func AddSigleAutoReduceRecordInfo(detail *models.AutomaticReduceDetail) error {
@@ -2088,7 +2124,7 @@ func FindStockOutInfoByTypeId(org_id int64, good_type_id int64, good_id int64, o
2088 2124
 	return
2089 2125
 }
2090 2126
 
2091
-func FindStockOutInfoByStock(org_id int64, good_type_id int64, good_id int64, record_date int64,patient_id int64) (out []*models.WarehouseOutInfo, err error) {
2127
+func FindStockOutInfoByStock(org_id int64, good_type_id int64, good_id int64, record_date int64, patient_id int64) (out []*models.WarehouseOutInfo, err error) {
2092 2128
 	err = readDb.Model(&models.WarehouseOutInfo{}).Where("status = 1 AND org_id = ? AND good_type_id = ? AND good_id = ? AND is_sys = 1 AND sys_record_time = ? AND patient_id = ?", org_id, good_type_id, good_id, record_date, patient_id).Order("ctime desc").Find(&out).Error
2093 2129
 	return
2094 2130
 }
@@ -2345,7 +2381,7 @@ func IsExistDrugByName(drugname string, drugdesc string, orgid int64) (*models.B
2345 2381
 	return &drug, nil
2346 2382
 }
2347 2383
 
2348
-func IsExistDrugByNameOne(drugname string, dosage string, maxunit string, unival string, minunit string, packtunit string, orgid int64) (*models.BaseDrugLib, error) {
2384
+func IsExistDrugByNameOne(drugname string, dosage float64, maxunit string, unival int64, minunit string, packtunit string, orgid int64) (*models.BaseDrugLib, error) {
2349 2385
 	var drug models.BaseDrugLib
2350 2386
 	var err error
2351 2387
 	err = XTReadDB().Model(&drug).Where("drug_name = ? and dosage = ?  and max_unit = ? and unval = ? and min_unit=? and packing_unit = ? and status =1 and org_id = ?", drugname, dosage, maxunit, unival, minunit, packtunit, orgid).Find(&drug).Error
@@ -2365,7 +2401,7 @@ func CreateDrugsInfomation(info *models.BaseDrugLib) error {
2365 2401
 
2366 2402
 func UpdateDrugsInformation(drug *models.BaseDrugLib, drugName string, drugSpec string, orgid int64) error {
2367 2403
 
2368
-	err := XTWriteDB().Model(&drug).Where("drug_name = ? and drug_spec = ? and org_id = ? and status = 1", drugName, drugSpec, orgid).Updates(map[string]interface{}{"drug_name": drug.DrugName, "drug_alias": drug.DrugAlias, "drug_spec": drug.DrugSpec, "drug_type": drug.DrugType, "drug_stock_limit": drug.DrugStockLimit, "drug_origin_place": drug.DrugOriginPlace, "drug_dosage_form": drug.DrugDosageForm, "medical_insurance_level": drug.MedicalInsuranceLevel, "max_unit": drug.MaxUnit, "min_unit": drug.MinUnit, "unit_matrixing": drug.UnitMatrixing, "retail_price": drug.RetailPrice, "last_price": drug.LastPrice, "drug_classify": drug.DrugClassify, "manufacturer": drug.Manufacturer, "dealer": drug.Dealer, "pinyin": drug.Pinyin, "wubi": drug.Wubi, "drug_alias_pinyin": drug.DrugAliasPinyin, "drug_alias_wubi": drug.DrugAliasWubi, "drug_category": drug.DrugCategory, "drug_control": drug.DrugControl, "number": drug.Number, "hosp_appr_flag": drug.HospApprFlag, "medical_insurance_number": drug.MedicalInsuranceNumber, "pharmacology_category": drug.PharmacologyCategory, "statistics_category": drug.StatisticsCategory, "code": drug.Code, "is_special_diseases": drug.IsSpecialDiseases, "is_record": drug.IsRecord, "prescription_mark": drug.PrescriptionMark, "social_security_directory_code": drug.SocialSecurityDirectoryCode, "record_date": drug.RecordDate, "drug_remark": drug.DrugRemark, "drug_status": drug.DrugStatus, "limit_remark": drug.LimitRemark, "drug_dose": drug.DrugDose, "drug_dose_unit": drug.DrugDoseUnit, "lmt_used_flag": drug.LmtUsedFlag, "delivery_way": drug.DeliveryWay, "execution_frequency": drug.ExecutionFrequency, "dosage": drug.Dosage, "unval": drug.Unval, "packing_unit": drug.PackingUnit, "packing_price": drug.PackingPrice, "drug_day": drug.DrugDay}).Error
2404
+	err := XTWriteDB().Model(&drug).Where("drug_name = ? and drug_spec = ? and org_id = ? and status = 1", drugName, drugSpec, orgid).Updates(map[string]interface{}{"drug_name": drug.DrugName, "drug_alias": drug.DrugAlias, "drug_spec": drug.DrugSpec, "drug_type": drug.DrugType, "drug_stock_limit": drug.DrugStockLimit, "drug_origin_place": drug.DrugOriginPlace, "drug_dosage_form": drug.DrugDosageForm, "medical_insurance_level": drug.MedicalInsuranceLevel, "max_unit": drug.MaxUnit, "min_unit": drug.MinUnit, "unit_matrixing": drug.UnitMatrixing, "retail_price": drug.RetailPrice, "last_price": drug.LastPrice, "drug_classify": drug.DrugClassify, "manufacturer": drug.Manufacturer, "dealer": drug.Dealer, "pinyin": drug.Pinyin, "wubi": drug.Wubi, "drug_alias_pinyin": drug.DrugAliasPinyin, "drug_alias_wubi": drug.DrugAliasWubi, "drug_category": drug.DrugCategory, "drug_control": drug.DrugControl, "number": drug.Number, "hosp_appr_flag": drug.HospApprFlag, "medical_insurance_number": drug.MedicalInsuranceNumber, "pharmacology_category": drug.PharmacologyCategory, "statistics_category": drug.StatisticsCategory, "code": drug.Code, "is_special_diseases": drug.IsSpecialDiseases, "is_record": drug.IsRecord, "prescription_mark": drug.PrescriptionMark, "social_security_directory_code": drug.SocialSecurityDirectoryCode, "record_date": drug.RecordDate, "drug_remark": drug.DrugRemark, "drug_status": drug.DrugStatus, "limit_remark": drug.LimitRemark, "drug_dose": drug.DrugDose, "drug_dose_unit": drug.DrugDoseUnit, "lmt_used_flag": drug.LmtUsedFlag, "delivery_way": drug.DeliveryWay, "execution_frequency": drug.ExecutionFrequency, "drug_day": drug.DrugDay}).Error
2369 2405
 	return err
2370 2406
 }
2371 2407
 
@@ -2582,3 +2618,61 @@ func GetSearchDrugList(keywords string, orgid int64) (drug []*models.BaseDrugLib
2582 2618
 	}
2583 2619
 	return
2584 2620
 }
2621
+
2622
+func GetSearchGoodList(keywords string, orgid int64) (good []*models.GoodInfo, err error) {
2623
+
2624
+	db := XTReadDB().Model(&good).Where("org_id =? and status = 1", orgid)
2625
+	if len(keywords) > 0 {
2626
+		likekey := "%" + keywords + "%"
2627
+		err = db.Where("(good_name Like ?)", likekey).Find(&good).Error
2628
+	} else {
2629
+		err = db.Find(&good).Error
2630
+	}
2631
+	return
2632
+}
2633
+
2634
+func CreateAutoReduceRecord(detail *models.BloodAutomaticReduceDetail) error {
2635
+
2636
+	err := writeDb.Create(&detail).Error
2637
+	return err
2638
+}
2639
+
2640
+func GetAutoMaticReduceDetail(orgid int64, patient_id int64, recordtime int64) (*models.BloodAutomaticReduceDetail, error) {
2641
+
2642
+	var autoreduece models.BloodAutomaticReduceDetail
2643
+	var err error
2644
+	err = XTReadDB().Model(&autoreduece).Where("org_id = ? and patient_id = ?  and status = 1 and record_time = ?", orgid, patient_id, recordtime).Find(&autoreduece).Error
2645
+	if err == gorm.ErrRecordNotFound {
2646
+		return nil, err
2647
+	}
2648
+	if err != nil {
2649
+		return nil, err
2650
+	}
2651
+	return &autoreduece, nil
2652
+}
2653
+
2654
+func DeleteAutoRedeceDetailTwo(orgid int64, patient_id int64, recordtime int64) error {
2655
+
2656
+	detail := models.BloodAutomaticReduceDetail{}
2657
+	err := XTWriteDB().Model(&detail).Where("org_id = ? and patient_id = ? and record_time = ? and status =1", orgid, patient_id, recordtime).Updates(map[string]interface{}{"status": 0}).Error
2658
+	return err
2659
+}
2660
+
2661
+func UpDateWarehouseInfoByStockDelete(id int64, count int64) (err error) {
2662
+	err = writeDb.Model(&models.WarehousingInfo{}).Where("id = ?", id).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
2663
+	return err
2664
+}
2665
+
2666
+func GetAutoDialysisBefor(goodid int64, goodtypeid int64, patientid int64, orgid int64, recorddate int64) (*models.BloodAutomaticReduceDetail, error) {
2667
+
2668
+	var autoreduece models.BloodAutomaticReduceDetail
2669
+	var err error
2670
+	err = XTReadDB().Model(&autoreduece).Where("good_id = ? and good_type_id = ? and patient_id = ? and org_id = ?  and status = 1 and record_time = ?", goodid, goodtypeid, patientid, orgid, recorddate).Find(&autoreduece).Error
2671
+	if err == gorm.ErrRecordNotFound {
2672
+		return nil, err
2673
+	}
2674
+	if err != nil {
2675
+		return nil, err
2676
+	}
2677
+	return &autoreduece, nil
2678
+}

File diff suppressed because it is too large
+ 1070 - 163
service/warhouse_service.go