|
@@ -1299,3 +1299,247 @@ func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64,
|
1299
|
1299
|
err = db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule AS x ON x.patient_id = o.patient_id where o.status = 1 and o.dialysis_date>=? and o.dialysis_date<=? and o.user_org_id = ? and x.schedule_date = o.dialysis_date and x.status = 1 and o.patient_id = ?", startime, endtime, orgid, patientid).Scan(&order).Group("o.patient_id").Error
|
1300
|
1300
|
return order, err
|
1301
|
1301
|
}
|
|
1302
|
+
|
|
1303
|
+func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
|
|
1304
|
+ err = readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND count > 0", orgID, patient_id, recordDate).Find(&consumables).Error
|
|
1305
|
+ return
|
|
1306
|
+}
|
|
1307
|
+
|
|
1308
|
+//func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
|
|
1309
|
+// err = readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1", orgID, patient_id,recordDate).Find(&consumables).Error
|
|
1310
|
+// return
|
|
1311
|
+//}
|
|
1312
|
+//
|
|
1313
|
+
|
|
1314
|
+func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
|
|
1315
|
+ err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date < ?", patientID, orgID, maxDate).Order("record_date desc").Find(&prepare).Error
|
|
1316
|
+
|
|
1317
|
+ return
|
|
1318
|
+}
|
|
1319
|
+
|
|
1320
|
+type GoodsType struct {
|
|
1321
|
+ ID int64 `gorm:"column:id" json:"id"`
|
|
1322
|
+ TypeName string `gorm:"column:type_name" json:"type_name"`
|
|
1323
|
+ Remark string `gorm:"column:remark" json:"remark"`
|
|
1324
|
+ OrgId int64 `gorm:"column:org_id" json:"org_id"`
|
|
1325
|
+ Status int64 `gorm:"column:status" json:"status"`
|
|
1326
|
+ Type int64 `gorm:"column:type" json:"type"`
|
|
1327
|
+}
|
|
1328
|
+
|
|
1329
|
+func (GoodsType) TableName() string {
|
|
1330
|
+ return "xt_goods_type"
|
|
1331
|
+}
|
|
1332
|
+
|
|
1333
|
+type VMGoodInfo struct {
|
|
1334
|
+ ID int64 `gorm:"column:id" json:"id"`
|
|
1335
|
+ SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
|
|
1336
|
+ GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
|
|
1337
|
+ OrgId int64 `gorm:"column:org_id" json:"org_id"`
|
|
1338
|
+}
|
|
1339
|
+
|
|
1340
|
+func (VMGoodInfo) TableName() string {
|
|
1341
|
+ return "xt_good_information"
|
|
1342
|
+}
|
|
1343
|
+
|
|
1344
|
+type AutomaticReduceDetail struct {
|
|
1345
|
+ ID int64 `gorm:"column:id" json:"id"`
|
|
1346
|
+ PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
|
|
1347
|
+ Status int64 `gorm:"column:status" json:"status"`
|
|
1348
|
+ RecordTime int64 `gorm:"column:record_time" json:"record_time"`
|
|
1349
|
+ OrgId int64 `gorm:"column:org_id" json:"org_id"`
|
|
1350
|
+ GoodId int64 `gorm:"column:good_id" json:"good_id"`
|
|
1351
|
+ GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
|
|
1352
|
+ VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
|
|
1353
|
+ GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
|
|
1354
|
+ Count int64 `gorm:"column:count" json:"count"`
|
|
1355
|
+}
|
|
1356
|
+
|
|
1357
|
+func (AutomaticReduceDetail) TableName() string {
|
|
1358
|
+ return "xt_automatic_reduce_detail"
|
|
1359
|
+}
|
|
1360
|
+
|
|
1361
|
+type DialysisBeforePrepare struct {
|
|
1362
|
+ ID int64 `gorm:"column:id" json:"id" form:"id"`
|
|
1363
|
+ UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
|
|
1364
|
+ PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
|
|
1365
|
+ RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
|
|
1366
|
+ GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
|
|
1367
|
+ GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
|
|
1368
|
+ Count int64 `gorm:"column:count" json:"count" form:"count"`
|
|
1369
|
+ Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
|
|
1370
|
+ Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
|
|
1371
|
+ Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
|
|
1372
|
+ Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
|
|
1373
|
+ VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
|
|
1374
|
+ GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
|
|
1375
|
+}
|
|
1376
|
+
|
|
1377
|
+func (DialysisBeforePrepare) TableName() string {
|
|
1378
|
+ return "dialysis_before_prepare"
|
|
1379
|
+}
|
|
1380
|
+
|
|
1381
|
+type MDialysisGoodsVM struct {
|
|
1382
|
+ ID int64 `gorm:"column:id" json:"id"`
|
|
1383
|
+ UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
|
|
1384
|
+ PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
|
|
1385
|
+ BedId int64 `gorm:"column:bed_id" json:"bed_id"`
|
|
1386
|
+ PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
|
|
1387
|
+ ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
|
|
1388
|
+ ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
|
|
1389
|
+ ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
|
|
1390
|
+ ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
|
|
1391
|
+ Status int64 `gorm:"column:status" json:"status"`
|
|
1392
|
+
|
|
1393
|
+ DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
|
|
1394
|
+ SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
|
|
1395
|
+ AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordTime" json:"good_user"`
|
|
1396
|
+ LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
|
|
1397
|
+ DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
|
|
1398
|
+ LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
|
|
1399
|
+}
|
|
1400
|
+
|
|
1401
|
+func (MDialysisGoodsVM) TableName() string {
|
|
1402
|
+ return "xt_schedule"
|
|
1403
|
+}
|
|
1404
|
+
|
|
1405
|
+type VMWarehouseOutInfo struct {
|
|
1406
|
+ ID int64 `gorm:"column:id" json:"id"`
|
|
1407
|
+ WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
|
|
1408
|
+ GoodId int64 `gorm:"column:good_id" json:"good_id"`
|
|
1409
|
+ GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
|
|
1410
|
+ Count int64 `gorm:"column:count" json:"count"`
|
|
1411
|
+ Price float64 `gorm:"column:price" json:"price"`
|
|
1412
|
+ TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
|
|
1413
|
+ Status int64 `gorm:"column:status" json:"status"`
|
|
1414
|
+ OrgId int64 `gorm:"column:org_id" json:"org_id"`
|
|
1415
|
+ WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
|
|
1416
|
+ GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
|
|
1417
|
+ GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
|
|
1418
|
+ IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
|
|
1419
|
+ SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
|
|
1420
|
+ Mtime int64 `gorm:"column:mtime" json:"mtime"`
|
|
1421
|
+ Ctime int64 `gorm:"column:ctime" json:"ctime"`
|
|
1422
|
+}
|
|
1423
|
+
|
|
1424
|
+func (VMWarehouseOutInfo) TableName() string {
|
|
1425
|
+ return "xt_warehouse_out_info"
|
|
1426
|
+}
|
|
1427
|
+
|
|
1428
|
+type DialysisGoodsDate struct {
|
|
1429
|
+ RecordDate int64
|
|
1430
|
+}
|
|
1431
|
+
|
|
1432
|
+type DialysisGoodsDetailDate struct {
|
|
1433
|
+ RecordTime int64
|
|
1434
|
+}
|
|
1435
|
+
|
|
1436
|
+func MobileGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, partition_id int64, page int, limit int, patient_id int64, keywords string) ([]*MDialysisGoodsVM, error, int64) {
|
|
1437
|
+ var vms []*MDialysisGoodsVM
|
|
1438
|
+ var total int64
|
|
1439
|
+
|
|
1440
|
+ db := readDb.
|
|
1441
|
+ Table("xt_schedule as sch").
|
|
1442
|
+ Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
|
|
1443
|
+ Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
|
|
1444
|
+ Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
|
|
1445
|
+ Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
|
|
1446
|
+ return db.Preload("VMGoodInfo", "status = 1 AND org_id = ?", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND user_org_id = ? AND record_date = ? AND count > 0 ", orgID, scheduleDate)
|
|
1447
|
+ }).
|
|
1448
|
+ Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
|
|
1449
|
+ return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND org_id = ? AND record_time = ? AND count > 0 ", orgID, scheduleDate)
|
|
1450
|
+ }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
|
|
1451
|
+ if scheduleDate != 0 {
|
|
1452
|
+ db = db.Where("schedule_date = ?", scheduleDate)
|
|
1453
|
+ }
|
|
1454
|
+ if schedule_type != 0 {
|
|
1455
|
+ db = db.Where("schedule_type = ?", schedule_type)
|
|
1456
|
+ }
|
|
1457
|
+ if partition_id != 0 {
|
|
1458
|
+ db = db.Where("partition_id = ?", partition_id)
|
|
1459
|
+ }
|
|
1460
|
+ if patient_id != 0 {
|
|
1461
|
+ db = db.Where("patient_id = ?", patient_id)
|
|
1462
|
+ }
|
|
1463
|
+ //db = db.Count(&total)
|
|
1464
|
+ //offset := (page - 1) * limit
|
|
1465
|
+ //
|
|
1466
|
+ //db = db.Offset(offset).Limit(limit)
|
|
1467
|
+ err := db.Find(&vms).Error
|
|
1468
|
+
|
|
1469
|
+ return vms, err, total
|
|
1470
|
+}
|
|
1471
|
+
|
|
1472
|
+func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
|
|
1473
|
+ var Id []*DialysisGoodsDetailDate
|
|
1474
|
+ err = readDb.Model(&AutomaticReduceDetail{}).Where("patient_id = ? AND org_id = ? AND status=1 AND record_time < ? AND count > 0", patient_id, orgID, record_time).Select("record_time").Group("record_time").Order("record_time asc").Scan(&Id).Error
|
|
1475
|
+ if len(Id) > 0 {
|
|
1476
|
+ err = readDb.Model(&AutomaticReduceDetail{}).Where("patient_id = ? AND org_id = ? AND status=1 AND record_time = ? AND count > 0", patient_id, orgID, Id[len(Id)-1].RecordTime).Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Find(&goodUser).Error
|
|
1477
|
+ }
|
|
1478
|
+ return
|
|
1479
|
+}
|
|
1480
|
+
|
|
1481
|
+func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
|
|
1482
|
+ var Id []*DialysisGoodsDate
|
|
1483
|
+ err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date < ? AND count > 0", patient_id, orgID, record_time).Select("record_date").Group("record_date").Order("record_date asc").Scan(&Id).Error
|
|
1484
|
+ if len(Id) > 0 {
|
|
1485
|
+ err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? AND count > 0", patient_id, orgID, Id[len(Id)-1].RecordDate).Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Find(&goodUser).Error
|
|
1486
|
+ }
|
|
1487
|
+ return
|
|
1488
|
+}
|
|
1489
|
+
|
|
1490
|
+func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
|
|
1491
|
+ db := readDb.Model(&models.StockInfo{})
|
|
1492
|
+ db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
|
|
1493
|
+ db = db.Joins("JOIN xt_warehouse_out_info AS info ON info.good_id=xt_good_information.id AND info.status = 1 AND info.org_id = ?", orgID).Group("xt_good_information.id")
|
|
1494
|
+ db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
|
|
1495
|
+ return db.Where("xt_warehouse_out_info.org_id = ? AND xt_warehouse_out_info.status = 1", orgID).Joins("JOIN xt_warehouse_out ON xt_warehouse_out.id = xt_warehouse_out_info.warehouse_out_id AND xt_warehouse_out.status = 1 AND xt_warehouse_out.warehouse_out_time >=? AND xt_warehouse_out.warehouse_out_time<= ? AND xt_warehouse_out.org_id = ? ", start_time, end_time, orgID)
|
|
1496
|
+ })
|
|
1497
|
+ db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
|
|
1498
|
+ err = db.Order("ctime desc").Find(&list).Error
|
|
1499
|
+ return
|
|
1500
|
+}
|
|
1501
|
+
|
|
1502
|
+func PCGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, partition_id int64, page int, limit int, patient_id int64, keywords string) ([]*MDialysisGoodsVM, error, int64) {
|
|
1503
|
+ var vms []*MDialysisGoodsVM
|
|
1504
|
+ var total int64
|
|
1505
|
+
|
|
1506
|
+ db := readDb.
|
|
1507
|
+ Model(&models.Schedule{}).
|
|
1508
|
+ Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
|
|
1509
|
+ Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
|
|
1510
|
+ Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
|
|
1511
|
+ Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
|
|
1512
|
+ return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND user_org_id = ? AND record_date = ? AND count > 0 ", orgID, scheduleDate)
|
|
1513
|
+ }).
|
|
1514
|
+ Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
|
|
1515
|
+ return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND org_id = ? AND record_time = ? AND count > 0", orgID, scheduleDate)
|
|
1516
|
+ }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
|
|
1517
|
+
|
|
1518
|
+ if scheduleDate != 0 {
|
|
1519
|
+ db = db.Where("schedule_date = ?", scheduleDate)
|
|
1520
|
+ }
|
|
1521
|
+ if patient_id != 0 {
|
|
1522
|
+ db = db.Where("patient_id = ?", patient_id)
|
|
1523
|
+ }
|
|
1524
|
+ if len(keywords) != 0 {
|
|
1525
|
+ keywords = "%" + keywords + "%"
|
|
1526
|
+ db = db.Joins("JOIN xt_patients AS patient ON patient.id=xt_schedule.patient_id AND patient.status = 1 AND patient.user_org_id = ? AND patient.name Like ?", orgID, keywords)
|
|
1527
|
+ } else {
|
|
1528
|
+ if schedule_type != 0 {
|
|
1529
|
+ db = db.Where("schedule_type = ?", schedule_type)
|
|
1530
|
+ }
|
|
1531
|
+ if partition_id != 0 {
|
|
1532
|
+ db = db.Where("partition_id = ?", partition_id)
|
|
1533
|
+ }
|
|
1534
|
+
|
|
1535
|
+ db = db.Count(&total)
|
|
1536
|
+ offset := (page - 1) * limit
|
|
1537
|
+
|
|
1538
|
+ db = db.Offset(offset).Limit(limit)
|
|
1539
|
+
|
|
1540
|
+ }
|
|
1541
|
+
|
|
1542
|
+ err := db.Find(&vms).Error
|
|
1543
|
+
|
|
1544
|
+ return vms, err, total
|
|
1545
|
+}
|