|
@@ -3,7 +3,10 @@ package service
|
3
|
3
|
import (
|
4
|
4
|
"database/sql"
|
5
|
5
|
"fmt"
|
|
6
|
+ "log"
|
|
7
|
+ "math"
|
6
|
8
|
"reflect"
|
|
9
|
+ "strconv"
|
7
|
10
|
"strings"
|
8
|
11
|
"time"
|
9
|
12
|
|
|
@@ -1232,3 +1235,826 @@ func GetScheduleInfo(start_date string, end_date string, mode int64, org_id int6
|
1232
|
1235
|
}).Where("FROM_UNIXTIME(schedule_date, '%Y-%m-%d') >= ? and FROM_UNIXTIME(schedule_date, '%Y-%m-%d') <= ? and user_org_id = ? and mode_id = ? and status = 1", start_date, end_date, org_id, mode).Count(&total).Offset(offset).Limit(limit).Find(&qcp).Error
|
1233
|
1236
|
return
|
1234
|
1237
|
}
|
|
1238
|
+
|
|
1239
|
+type otherItemAmount struct {
|
|
1240
|
+ Total int64 `json:"total"`
|
|
1241
|
+ Name string `json:"name"`
|
|
1242
|
+ Ratio string `json:"ratio"`
|
|
1243
|
+}
|
|
1244
|
+
|
|
1245
|
+// xt_patients model
|
|
1246
|
+type Patient struct {
|
|
1247
|
+ ID uint `gorm:"primaryKey"`
|
|
1248
|
+ IDCardNo string `gorm:"column:id_card_no"`
|
|
1249
|
+}
|
|
1250
|
+
|
|
1251
|
+// xt_assessment_before_dislysis model
|
|
1252
|
+type Assessment struct {
|
|
1253
|
+ ID uint `gorm:"id"`
|
|
1254
|
+ PatientID uint `gorm:"column:patient_id"`
|
|
1255
|
+ SystolicBP int `gorm:"column:systolic_blood_pressure"`
|
|
1256
|
+ DiastolicBP int `gorm:"column:diastolic_blood_pressure"`
|
|
1257
|
+ AssessmentDate time.Time `gorm:"column:assessment_date"`
|
|
1258
|
+ UserOrgID int `gorm:"column:user_org_id"`
|
|
1259
|
+}
|
|
1260
|
+
|
|
1261
|
+func (Assessment) TableName() string {
|
|
1262
|
+ return "xt_assessment_before_dislysis"
|
|
1263
|
+}
|
|
1264
|
+
|
|
1265
|
+// xt_assessment_before_dislysis model
|
|
1266
|
+type AssessmentAfter struct {
|
|
1267
|
+ ID uint `gorm:"id"`
|
|
1268
|
+ PatientID uint `gorm:"column:patient_id"`
|
|
1269
|
+ SystolicBP int `gorm:"column:systolic_blood_pressure"`
|
|
1270
|
+ DiastolicBP int `gorm:"column:diastolic_blood_pressure"`
|
|
1271
|
+ AssessmentDate time.Time `gorm:"column:assessment_date"`
|
|
1272
|
+ UserOrgID int `gorm:"column:user_org_id"`
|
|
1273
|
+}
|
|
1274
|
+
|
|
1275
|
+func (AssessmentAfter) TableName() string {
|
|
1276
|
+ return "xt_assessment_before_dislysis"
|
|
1277
|
+}
|
|
1278
|
+
|
|
1279
|
+type WeightDetail struct {
|
|
1280
|
+ DialysisNo string
|
|
1281
|
+ PatientName string
|
|
1282
|
+ Gender int64
|
|
1283
|
+ IDCardNo string
|
|
1284
|
+ DialysisDate string
|
|
1285
|
+ DryWeight float64
|
|
1286
|
+ LastWeightAfter float64
|
|
1287
|
+ WeightBefore float64
|
|
1288
|
+}
|
|
1289
|
+
|
|
1290
|
+func GetNewDialysisWeightChartData(user_org_id int64, start_time int64, end_time int64, statistics_type int) (item []*otherItemAmount, err error) {
|
|
1291
|
+ db := XTReadDB()
|
|
1292
|
+ var items []*otherItemAmount
|
|
1293
|
+ var tempErr error
|
|
1294
|
+ var Total int64
|
|
1295
|
+ switch statistics_type {
|
|
1296
|
+ case 1:
|
|
1297
|
+ db.Table("xt_assessment_before_dislysis ").Where("user_org_id=? and status=1 and created_time >= ? and created_time <= ?", user_org_id, start_time, end_time).Count(&Total)
|
|
1298
|
+ tempErr = db.Table("xt_assessment_before_dislysis ").Where("user_org_id=? and status=1 and created_time >= ? and created_time <= ?", user_org_id, start_time, end_time).
|
|
1299
|
+ Select("CASE WHEN dry_weight < 40 THEN '小于40kg'" +
|
|
1300
|
+ " WHEN dry_weight >= 40 AND dry_weight < 50 THEN '40~50kg'" +
|
|
1301
|
+ " WHEN dry_weight >= 50 AND dry_weight < 60 THEN '50~60kg'" +
|
|
1302
|
+ " WHEN dry_weight >= 60 AND dry_weight < 70 THEN '60~70kg'" +
|
|
1303
|
+ " WHEN dry_weight >= 70 THEN '大于70kg'" +
|
|
1304
|
+ " ELSE '未知' END AS name, COUNT(*) AS total",
|
|
1305
|
+ ).Group("name").Scan(&items).Error
|
|
1306
|
+
|
|
1307
|
+ var isHasConditionOne bool = false
|
|
1308
|
+ var isHasConditionTwo bool = false
|
|
1309
|
+ var isHasConditionThree bool = false
|
|
1310
|
+ var isHasConditionFour bool = false
|
|
1311
|
+ var isHasConditionFive bool = false
|
|
1312
|
+
|
|
1313
|
+ for _, item := range items {
|
|
1314
|
+ if item.Name == "小于40kg" {
|
|
1315
|
+ isHasConditionOne = true
|
|
1316
|
+ }
|
|
1317
|
+ if item.Name == "40~50kg" {
|
|
1318
|
+ isHasConditionTwo = true
|
|
1319
|
+ }
|
|
1320
|
+ if item.Name == "60~70kg" {
|
|
1321
|
+ isHasConditionThree = true
|
|
1322
|
+ }
|
|
1323
|
+ if item.Name == "大于70kg" {
|
|
1324
|
+ isHasConditionFour = true
|
|
1325
|
+ }
|
|
1326
|
+ if item.Name == "待定/卧床" {
|
|
1327
|
+ isHasConditionFive = true
|
|
1328
|
+ }
|
|
1329
|
+ }
|
|
1330
|
+ if !isHasConditionOne {
|
|
1331
|
+ newItem := &otherItemAmount{
|
|
1332
|
+ Total: 0,
|
|
1333
|
+ Name: "小于40kg",
|
|
1334
|
+ Ratio: "0",
|
|
1335
|
+ }
|
|
1336
|
+ items = append(items, newItem)
|
|
1337
|
+ }
|
|
1338
|
+
|
|
1339
|
+ if !isHasConditionTwo {
|
|
1340
|
+ newItem := &otherItemAmount{
|
|
1341
|
+ Total: 0,
|
|
1342
|
+ Name: "40~50kg",
|
|
1343
|
+ Ratio: "0",
|
|
1344
|
+ }
|
|
1345
|
+ items = append(items, newItem)
|
|
1346
|
+ }
|
|
1347
|
+ if !isHasConditionThree {
|
|
1348
|
+ newItem := &otherItemAmount{
|
|
1349
|
+ Total: 0,
|
|
1350
|
+ Name: "60~70kg",
|
|
1351
|
+ Ratio: "0",
|
|
1352
|
+ }
|
|
1353
|
+ items = append(items, newItem)
|
|
1354
|
+
|
|
1355
|
+ }
|
|
1356
|
+
|
|
1357
|
+ if !isHasConditionFour {
|
|
1358
|
+ newItem := &otherItemAmount{
|
|
1359
|
+ Total: 0,
|
|
1360
|
+ Name: "大于70kg",
|
|
1361
|
+ Ratio: "0",
|
|
1362
|
+ }
|
|
1363
|
+ items = append(items, newItem)
|
|
1364
|
+
|
|
1365
|
+ }
|
|
1366
|
+
|
|
1367
|
+ if !isHasConditionFive {
|
|
1368
|
+ newItem := &otherItemAmount{
|
|
1369
|
+ Total: 0,
|
|
1370
|
+ Name: "未知",
|
|
1371
|
+ Ratio: "0",
|
|
1372
|
+ }
|
|
1373
|
+ items = append(items, newItem)
|
|
1374
|
+ }
|
|
1375
|
+
|
|
1376
|
+ for _, item := range items {
|
|
1377
|
+ if math.IsNaN(float64(item.Total) / float64(Total)) {
|
|
1378
|
+ item.Ratio = "0.0"
|
|
1379
|
+ } else {
|
|
1380
|
+ float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
|
|
1381
|
+ item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
|
|
1382
|
+ }
|
|
1383
|
+ }
|
|
1384
|
+
|
|
1385
|
+ break
|
|
1386
|
+ case 2:
|
|
1387
|
+
|
|
1388
|
+ //db.Table("xt_assessment_before_dislysis ").Where("user_org_id=? and status=1 and created_time >= ? and created_time <= ?", user_org_id, start_time, end_time).Count(&Total)
|
|
1389
|
+
|
|
1390
|
+ //db.Raw("Select count(*) from `xt_assessment_before_dislysis` LEFT JOIN `xt_assessment_after_dislysis` On xt_assessment_before_dislysis.`patient_id` = xt_assessment_after_dislysis.`patient_id` AND xt_assessment_before_dislysis.assessment_date = xt_assessment_after_dislysis.assessment_date AND xt_assessment_after_dislysis.weight_after != 0 Where xt_assessment_before_dislysis.user_org_id = ? AND xt_assessment_before_dislysis.created_time >= ? AND xt_assessment_before_dislysis.created_time <= ? Order by xt_assessment_before_dislysis.assessment_date desc", user_org_id, start_time, end_time).Count(&Total)
|
|
1391
|
+
|
|
1392
|
+ var newTotal int64
|
|
1393
|
+ type weight struct {
|
|
1394
|
+ WeightAfter float64 `json:"weight_after"`
|
|
1395
|
+ WeightBefore float64 `json:"weight_before"`
|
|
1396
|
+ }
|
|
1397
|
+ var weights []*weight
|
|
1398
|
+ var weightAdd []float64
|
|
1399
|
+ db.Raw("Select xt_assessment_after_dislysis.weight_after as weight_after ,xt_assessment_before_dislysis.weight_before as weight_before from `xt_assessment_before_dislysis` LEFT JOIN `xt_assessment_after_dislysis` On xt_assessment_before_dislysis.`patient_id` = xt_assessment_after_dislysis.`patient_id` AND xt_assessment_before_dislysis.assessment_date = xt_assessment_after_dislysis.assessment_date AND xt_assessment_after_dislysis.weight_after <> 0 AND xt_assessment_after_dislysis.user_org_id = ? Where xt_assessment_before_dislysis.user_org_id = ? AND xt_assessment_before_dislysis.created_time >= ? AND xt_assessment_before_dislysis.created_time <= ? Order by xt_assessment_before_dislysis.assessment_date desc", user_org_id, user_org_id, start_time, end_time).Scan(&weights)
|
|
1400
|
+ for index, _ := range weights {
|
|
1401
|
+ if index+1 < len(weights) {
|
|
1402
|
+ if weights[index+1].WeightAfter == 0 || weights[index].WeightBefore == 0 {
|
|
1403
|
+ continue
|
|
1404
|
+ }
|
|
1405
|
+ weightAdd = append(weightAdd, ((weights[index].WeightBefore - weights[index+1].WeightAfter) / weights[index+1].WeightAfter))
|
|
1406
|
+ }
|
|
1407
|
+ }
|
|
1408
|
+
|
|
1409
|
+ var total_one int64
|
|
1410
|
+ var total_two int64
|
|
1411
|
+ var total_three int64
|
|
1412
|
+ for _, item := range weightAdd {
|
|
1413
|
+ if item <= 0.03 {
|
|
1414
|
+ total_one++
|
|
1415
|
+
|
|
1416
|
+ }
|
|
1417
|
+
|
|
1418
|
+ if item > 0.03 && item < 0.05 {
|
|
1419
|
+ total_two++
|
|
1420
|
+
|
|
1421
|
+ }
|
|
1422
|
+
|
|
1423
|
+ if item >= 0.05 {
|
|
1424
|
+ total_three++
|
|
1425
|
+
|
|
1426
|
+ }
|
|
1427
|
+
|
|
1428
|
+ }
|
|
1429
|
+
|
|
1430
|
+ newTotal = total_one + total_two + total_three
|
|
1431
|
+
|
|
1432
|
+ newItem := &otherItemAmount{
|
|
1433
|
+ Total: total_one,
|
|
1434
|
+ Name: "体重增长<=3%",
|
|
1435
|
+ Ratio: "0",
|
|
1436
|
+ }
|
|
1437
|
+ newItem1 := &otherItemAmount{
|
|
1438
|
+ Total: total_two,
|
|
1439
|
+ Name: "3%<体重增长<5%",
|
|
1440
|
+ Ratio: "0",
|
|
1441
|
+ }
|
|
1442
|
+ newItem2 := &otherItemAmount{
|
|
1443
|
+ Total: total_three,
|
|
1444
|
+ Name: "体重增长>=5%",
|
|
1445
|
+ Ratio: "0",
|
|
1446
|
+ }
|
|
1447
|
+
|
|
1448
|
+ items = append(items, newItem)
|
|
1449
|
+ items = append(items, newItem1)
|
|
1450
|
+ items = append(items, newItem2)
|
|
1451
|
+ for _, item := range items {
|
|
1452
|
+ if math.IsNaN(float64(item.Total) / float64(newTotal)) {
|
|
1453
|
+ item.Ratio = "0.0"
|
|
1454
|
+ } else {
|
|
1455
|
+ float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(newTotal))*100), 64)
|
|
1456
|
+ item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
|
|
1457
|
+ }
|
|
1458
|
+ }
|
|
1459
|
+
|
|
1460
|
+ break
|
|
1461
|
+ case 3:
|
|
1462
|
+
|
|
1463
|
+ //db.Table("xt_assessment_before_dislysis ").Where("user_org_id=? and status=1 and created_time >= ? and created_time <= ?", user_org_id, start_time, end_time).Count(&Total)
|
|
1464
|
+
|
|
1465
|
+ //db.Raw("Select count(*) from `xt_assessment_before_dislysis` LEFT JOIN `xt_assessment_after_dislysis` On xt_assessment_before_dislysis.`patient_id` = xt_assessment_after_dislysis.`patient_id` AND xt_assessment_before_dislysis.assessment_date = xt_assessment_after_dislysis.assessment_date AND xt_assessment_after_dislysis.weight_after != 0 Where xt_assessment_before_dislysis.user_org_id = ? AND xt_assessment_before_dislysis.created_time >= ? AND xt_assessment_before_dislysis.created_time <= ? Order by xt_assessment_before_dislysis.assessment_date desc", user_org_id, start_time, end_time).Count(&Total)
|
|
1466
|
+
|
|
1467
|
+ var newTotal int64
|
|
1468
|
+ type weight struct {
|
|
1469
|
+ DryWeight float64 `json:"dry_weight"`
|
|
1470
|
+ WeightBefore float64 `json:"weight_before"`
|
|
1471
|
+ }
|
|
1472
|
+ var weights []*weight
|
|
1473
|
+ var weightAdd []float64
|
|
1474
|
+ db.Raw("Select xt_assessment_before_dislysis.dry_weight as dry_weight ,xt_assessment_before_dislysis.weight_before as weight_before from `xt_assessment_before_dislysis` Where xt_assessment_before_dislysis.user_org_id = ? AND xt_assessment_before_dislysis.created_time >= ? AND xt_assessment_before_dislysis.created_time <= ? Order by xt_assessment_before_dislysis.assessment_date desc", user_org_id, user_org_id, start_time, end_time).Scan(&weights)
|
|
1475
|
+ for index, _ := range weights {
|
|
1476
|
+ weightAdd = append(weightAdd, ((weights[index].WeightBefore - weights[index].DryWeight) / weights[index].DryWeight))
|
|
1477
|
+ }
|
|
1478
|
+
|
|
1479
|
+ var total_one int64
|
|
1480
|
+ var total_two int64
|
|
1481
|
+ var total_three int64
|
|
1482
|
+ for _, item := range weightAdd {
|
|
1483
|
+ if item <= 0.03 {
|
|
1484
|
+ total_one++
|
|
1485
|
+
|
|
1486
|
+ }
|
|
1487
|
+
|
|
1488
|
+ if item > 0.03 && item < 0.05 {
|
|
1489
|
+ total_two++
|
|
1490
|
+
|
|
1491
|
+ }
|
|
1492
|
+
|
|
1493
|
+ if item >= 0.05 {
|
|
1494
|
+ total_three++
|
|
1495
|
+
|
|
1496
|
+ }
|
|
1497
|
+
|
|
1498
|
+ }
|
|
1499
|
+
|
|
1500
|
+ newTotal = total_one + total_two + total_three
|
|
1501
|
+
|
|
1502
|
+ newItem := &otherItemAmount{
|
|
1503
|
+ Total: total_one,
|
|
1504
|
+ Name: "体重增长<=3%",
|
|
1505
|
+ Ratio: "0",
|
|
1506
|
+ }
|
|
1507
|
+ newItem1 := &otherItemAmount{
|
|
1508
|
+ Total: total_two,
|
|
1509
|
+ Name: "3%<体重增长<5%",
|
|
1510
|
+ Ratio: "0",
|
|
1511
|
+ }
|
|
1512
|
+ newItem2 := &otherItemAmount{
|
|
1513
|
+ Total: total_three,
|
|
1514
|
+ Name: "体重增长>=5%",
|
|
1515
|
+ Ratio: "0",
|
|
1516
|
+ }
|
|
1517
|
+
|
|
1518
|
+ items = append(items, newItem)
|
|
1519
|
+ items = append(items, newItem1)
|
|
1520
|
+ items = append(items, newItem2)
|
|
1521
|
+ for _, item := range items {
|
|
1522
|
+ if math.IsNaN(float64(item.Total) / float64(newTotal)) {
|
|
1523
|
+ item.Ratio = "0.0"
|
|
1524
|
+ } else {
|
|
1525
|
+ float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(newTotal))*100), 64)
|
|
1526
|
+ item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
|
|
1527
|
+ }
|
|
1528
|
+ }
|
|
1529
|
+
|
|
1530
|
+ break
|
|
1531
|
+ case 4:
|
|
1532
|
+ var newTotal int64
|
|
1533
|
+ type weight struct {
|
|
1534
|
+ WeightAfter float64 `json:"weight_after"`
|
|
1535
|
+ DryWeight float64 `json:"dry_weight"`
|
|
1536
|
+ }
|
|
1537
|
+ var weights []*weight
|
|
1538
|
+ //var weightAdd []float64
|
|
1539
|
+ db.Raw("Select xt_assessment_after_dislysis.weight_after as weight_after ,xt_assessment_before_dislysis.dry_weight as dry_weight from `xt_assessment_before_dislysis` LEFT JOIN `xt_assessment_after_dislysis` On xt_assessment_before_dislysis.`patient_id` = xt_assessment_after_dislysis.`patient_id` AND xt_assessment_before_dislysis.assessment_date = xt_assessment_after_dislysis.assessment_date AND xt_assessment_after_dislysis.weight_after <> 0 AND xt_assessment_after_dislysis.user_org_id = ? Where xt_assessment_before_dislysis.user_org_id = ? AND xt_assessment_before_dislysis.created_time >= ? AND xt_assessment_before_dislysis.created_time <= ? Order by xt_assessment_before_dislysis.assessment_date desc", user_org_id, user_org_id, start_time, end_time).Scan(&weights)
|
|
1540
|
+
|
|
1541
|
+ var total_one int64
|
|
1542
|
+ var total_two int64
|
|
1543
|
+ var total_three int64
|
|
1544
|
+ for _, item := range weights {
|
|
1545
|
+ if item.WeightAfter != 0 && item.DryWeight != 0 {
|
|
1546
|
+ if item.WeightAfter-item.DryWeight == 0.3 || item.WeightAfter-item.DryWeight == -0.3 {
|
|
1547
|
+ total_one++
|
|
1548
|
+
|
|
1549
|
+ }
|
|
1550
|
+
|
|
1551
|
+ if item.WeightAfter-item.DryWeight > 0.3 && item.WeightAfter-item.DryWeight < -0.3 {
|
|
1552
|
+ total_two++
|
|
1553
|
+
|
|
1554
|
+ }
|
|
1555
|
+ }
|
|
1556
|
+
|
|
1557
|
+ if item.WeightAfter == 0 {
|
|
1558
|
+ total_three++
|
|
1559
|
+ }
|
|
1560
|
+
|
|
1561
|
+ }
|
|
1562
|
+
|
|
1563
|
+ newTotal = total_one + total_two + total_three
|
|
1564
|
+
|
|
1565
|
+ newItem := &otherItemAmount{
|
|
1566
|
+ Total: total_one,
|
|
1567
|
+ Name: "达到干体重",
|
|
1568
|
+ Ratio: "0",
|
|
1569
|
+ }
|
|
1570
|
+ newItem1 := &otherItemAmount{
|
|
1571
|
+ Total: total_two,
|
|
1572
|
+ Name: "未达到干体重",
|
|
1573
|
+ Ratio: "0",
|
|
1574
|
+ }
|
|
1575
|
+ newItem2 := &otherItemAmount{
|
|
1576
|
+ Total: total_three,
|
|
1577
|
+ Name: "其他或卧床",
|
|
1578
|
+ Ratio: "0",
|
|
1579
|
+ }
|
|
1580
|
+
|
|
1581
|
+ items = append(items, newItem)
|
|
1582
|
+ items = append(items, newItem1)
|
|
1583
|
+ items = append(items, newItem2)
|
|
1584
|
+ for _, item := range items {
|
|
1585
|
+ if math.IsNaN(float64(item.Total) / float64(newTotal)) {
|
|
1586
|
+ item.Ratio = "0.0"
|
|
1587
|
+ } else {
|
|
1588
|
+ float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(newTotal))*100), 64)
|
|
1589
|
+ item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
|
|
1590
|
+ }
|
|
1591
|
+ }
|
|
1592
|
+
|
|
1593
|
+ break
|
|
1594
|
+ }
|
|
1595
|
+ if tempErr != nil {
|
|
1596
|
+ return nil, err
|
|
1597
|
+ }
|
|
1598
|
+
|
|
1599
|
+ fmt.Println(items)
|
|
1600
|
+ return items, nil
|
|
1601
|
+}
|
|
1602
|
+func GetNewDialysisBloodChartData(user_org_id int64, start_time int64, end_time int64, statistics_type int) (item []otherItemAmount, err error) {
|
|
1603
|
+ db := XTReadDB()
|
|
1604
|
+ switch statistics_type {
|
|
1605
|
+ case 1:
|
|
1606
|
+ var assessments []Assessment
|
|
1607
|
+ err = db.Joins("JOIN xt_patients ON xt_patients.id = xt_assessment_before_dislysis.patient_id").
|
|
1608
|
+ Where("xt_assessment_before_dislysis.assessment_date >= ? AND xt_assessment_before_dislysis.assessment_date <= ? AND xt_assessment_before_dislysis.user_org_id = ?", start_time, end_time, user_org_id).
|
|
1609
|
+ Find(&assessments).Error
|
|
1610
|
+ if err != nil {
|
|
1611
|
+ log.Fatal("Query execution error:", err)
|
|
1612
|
+ }
|
|
1613
|
+
|
|
1614
|
+ var total, metStandard, unmetStandard int
|
|
1615
|
+
|
|
1616
|
+ // Iterate through the result set
|
|
1617
|
+ for _, assessment := range assessments {
|
|
1618
|
+ // Fetch patient information
|
|
1619
|
+ var patient Patient
|
|
1620
|
+ err = db.First(&patient, assessment.PatientID).Error
|
|
1621
|
+ if err != nil {
|
|
1622
|
+ log.Printf("Skipping record due to missing patient data for ID: %v", assessment.PatientID)
|
|
1623
|
+ continue
|
|
1624
|
+ }
|
|
1625
|
+
|
|
1626
|
+ // Calculate the patient's age
|
|
1627
|
+ age, err := calculateAge(patient.IDCardNo)
|
|
1628
|
+ if err != nil {
|
|
1629
|
+ log.Printf("Skipping record due to invalid ID card number: %v", patient.IDCardNo)
|
|
1630
|
+ continue
|
|
1631
|
+ }
|
|
1632
|
+
|
|
1633
|
+ // Update the total count of patients
|
|
1634
|
+ total++
|
|
1635
|
+
|
|
1636
|
+ // Determine if the patient meets the standard based on their age and blood pressure
|
|
1637
|
+ if (age < 60 && assessment.SystolicBP < 140 && assessment.DiastolicBP < 90) || (age >= 60 && assessment.SystolicBP < 160 && assessment.DiastolicBP < 90) {
|
|
1638
|
+ metStandard++
|
|
1639
|
+ } else {
|
|
1640
|
+ unmetStandard++
|
|
1641
|
+ }
|
|
1642
|
+ }
|
|
1643
|
+
|
|
1644
|
+ // Calculate and print the results
|
|
1645
|
+ if total > 0 {
|
|
1646
|
+ metPercentage := float64(metStandard) / float64(total) * 100
|
|
1647
|
+ unmetPercentage := float64(unmetStandard) / float64(total) * 100
|
|
1648
|
+ fmt.Printf("Total patients: %d\n", total)
|
|
1649
|
+ fmt.Printf("Met standard: %d (%.2f%%)\n", metStandard, metPercentage)
|
|
1650
|
+ fmt.Printf("Unmet standard: %d (%.2f%%)\n", unmetStandard, unmetPercentage)
|
|
1651
|
+
|
|
1652
|
+ var items otherItemAmount
|
|
1653
|
+ items.Name = "达标患者"
|
|
1654
|
+ items.Ratio = strconv.FormatFloat(metPercentage, 'f', 1, 32)
|
|
1655
|
+ items.Total = int64(metStandard)
|
|
1656
|
+ item = append(item, items)
|
|
1657
|
+
|
|
1658
|
+ var items2 otherItemAmount
|
|
1659
|
+ items2.Name = "未达标患者"
|
|
1660
|
+ items2.Ratio = strconv.FormatFloat(unmetPercentage, 'f', 1, 32)
|
|
1661
|
+ items2.Total = int64(unmetStandard)
|
|
1662
|
+ item = append(item, items2)
|
|
1663
|
+
|
|
1664
|
+ }
|
|
1665
|
+ case 2:
|
|
1666
|
+ var assessments []AssessmentAfter
|
|
1667
|
+ err = db.Joins("JOIN xt_patients ON xt_patients.id = xt_assessment_after_dislysis.patient_id").
|
|
1668
|
+ Where("xt_assessment_after_dislysis.assessment_date >= ? AND xt_assessment_after_dislysis.assessment_date <= ? AND xt_assessment_before_dislysis.user_org_id = ?", start_time, end_time, user_org_id).
|
|
1669
|
+ Find(&assessments).Error
|
|
1670
|
+ if err != nil {
|
|
1671
|
+ log.Fatal("Query execution error:", err)
|
|
1672
|
+ }
|
|
1673
|
+
|
|
1674
|
+ var total, metStandard, unmetStandard int
|
|
1675
|
+
|
|
1676
|
+ // Iterate through the result set
|
|
1677
|
+ for _, assessment := range assessments {
|
|
1678
|
+ // Fetch patient information
|
|
1679
|
+ var patient Patient
|
|
1680
|
+ err = db.First(&patient, assessment.PatientID).Error
|
|
1681
|
+ if err != nil {
|
|
1682
|
+ log.Printf("Skipping record due to missing patient data for ID: %v", assessment.PatientID)
|
|
1683
|
+ continue
|
|
1684
|
+ }
|
|
1685
|
+
|
|
1686
|
+ // Calculate the patient's age
|
|
1687
|
+ age, err := calculateAge(patient.IDCardNo)
|
|
1688
|
+ if err != nil {
|
|
1689
|
+ log.Printf("Skipping record due to invalid ID card number: %v", patient.IDCardNo)
|
|
1690
|
+ continue
|
|
1691
|
+ }
|
|
1692
|
+
|
|
1693
|
+ // Update the total count of patients
|
|
1694
|
+ total++
|
|
1695
|
+
|
|
1696
|
+ // Determine if the patient meets the standard based on their age and blood pressure
|
|
1697
|
+ if (age < 60 && assessment.SystolicBP < 140 && assessment.DiastolicBP < 90) || (age >= 60 && assessment.SystolicBP < 160 && assessment.DiastolicBP < 90) {
|
|
1698
|
+ metStandard++
|
|
1699
|
+ } else {
|
|
1700
|
+ unmetStandard++
|
|
1701
|
+ }
|
|
1702
|
+ }
|
|
1703
|
+
|
|
1704
|
+ // Calculate and print the results
|
|
1705
|
+ if total > 0 {
|
|
1706
|
+ metPercentage := float64(metStandard) / float64(total) * 100
|
|
1707
|
+ unmetPercentage := float64(unmetStandard) / float64(total) * 100
|
|
1708
|
+ fmt.Printf("Total patients: %d\n", total)
|
|
1709
|
+ fmt.Printf("Met standard: %d (%.2f%%)\n", metStandard, metPercentage)
|
|
1710
|
+ fmt.Printf("Unmet standard: %d (%.2f%%)\n", unmetStandard, unmetPercentage)
|
|
1711
|
+
|
|
1712
|
+ var items otherItemAmount
|
|
1713
|
+ items.Name = "达标患者"
|
|
1714
|
+ items.Ratio = strconv.FormatFloat(metPercentage, 'f', 1, 32)
|
|
1715
|
+ items.Total = int64(metStandard)
|
|
1716
|
+ item = append(item, items)
|
|
1717
|
+
|
|
1718
|
+ var items2 otherItemAmount
|
|
1719
|
+ items2.Name = "未达标患者"
|
|
1720
|
+ items2.Ratio = strconv.FormatFloat(unmetPercentage, 'f', 1, 32)
|
|
1721
|
+ items2.Total = int64(unmetStandard)
|
|
1722
|
+ item = append(item, items2)
|
|
1723
|
+ }
|
|
1724
|
+
|
|
1725
|
+ break
|
|
1726
|
+ }
|
|
1727
|
+ return
|
|
1728
|
+}
|
|
1729
|
+func calculateAge(idCardNo string) (int, error) {
|
|
1730
|
+ if len(idCardNo) < 14 {
|
|
1731
|
+ return 0, fmt.Errorf("invalid ID card number")
|
|
1732
|
+ }
|
|
1733
|
+
|
|
1734
|
+ // Extract birth year, month, and day from ID card number
|
|
1735
|
+ year := idCardNo[6:10]
|
|
1736
|
+ month := idCardNo[10:12]
|
|
1737
|
+ day := idCardNo[12:14]
|
|
1738
|
+
|
|
1739
|
+ // Parse the birth date
|
|
1740
|
+ birthDate, err := time.Parse("20060102", year+month+day)
|
|
1741
|
+ if err != nil {
|
|
1742
|
+ return 0, err
|
|
1743
|
+ }
|
|
1744
|
+
|
|
1745
|
+ // Calculate age
|
|
1746
|
+ now := time.Now()
|
|
1747
|
+ age := now.Year() - birthDate.Year()
|
|
1748
|
+ if now.YearDay() < birthDate.YearDay() {
|
|
1749
|
+ age--
|
|
1750
|
+ }
|
|
1751
|
+
|
|
1752
|
+ return age, nil
|
|
1753
|
+}
|
|
1754
|
+
|
|
1755
|
+// 定义结果结构体
|
|
1756
|
+type DialysisDataTwo struct {
|
|
1757
|
+ DialysisNo string `json:"dialysis_no"`
|
|
1758
|
+ PatientName string `json:"patient_name"`
|
|
1759
|
+ Gender string `json:"gender"`
|
|
1760
|
+ Age int `json:"age"`
|
|
1761
|
+ AssessmentDate string `json:"assessment_date"` // 使用 string 存储日期,或使用 time.Time
|
|
1762
|
+ DryWeight float64 `json:"dry_weight"`
|
|
1763
|
+ WeightBefore float64 `json:"weight_before"`
|
|
1764
|
+ WeightAfter float64 `json:"weight_after"`
|
|
1765
|
+ LastWeightAfter *float64 `json:"last_weight_after"` // 使用指针处理可能为空的值
|
|
1766
|
+ WeightAdd *float64 `json:"weight_add"` // 使用指针处理可能为空的值
|
|
1767
|
+ DryWeightCategory string `json:"dry_weight_category"`
|
|
1768
|
+ WeightStatus string `json:"weight_status"`
|
|
1769
|
+}
|
|
1770
|
+
|
|
1771
|
+func GetNewDialysisWeightDetailTableTen(user_org_id int64, start_time int64, end_time int64, addType, dryType, afterType, page, limit int64) ([]DialysisDataTwo, int64, error) {
|
|
1772
|
+ offset := (page - 1) * limit
|
|
1773
|
+ var dialysisData []DialysisDataTwo
|
|
1774
|
+ var total int64
|
|
1775
|
+ // 构建基本查询
|
|
1776
|
+ query := readDb.Table("xt_assessment_before_dislysis b").
|
|
1777
|
+ Select(`
|
|
1778
|
+ p.dialysis_no AS dialysis_no,
|
|
1779
|
+ p.name AS patient_name,
|
|
1780
|
+ p.gender AS gender,
|
|
1781
|
+ FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) AS age,
|
|
1782
|
+ b.assessment_date AS assessment_date,
|
|
1783
|
+ b.dry_weight AS dry_weight,
|
|
1784
|
+ b.weight_before AS weight_before,
|
|
1785
|
+ a.weight_after AS weight_after,
|
|
1786
|
+ (
|
|
1787
|
+ SELECT a2.weight_after
|
|
1788
|
+ FROM xt_assessment_after_dislysis a2
|
|
1789
|
+ JOIN xt_assessment_before_dislysis b2
|
|
1790
|
+ ON a2.patient_id = b2.patient_id
|
|
1791
|
+ AND a2.assessment_date = b2.assessment_date
|
|
1792
|
+ WHERE b2.patient_id = b.patient_id
|
|
1793
|
+ AND b2.assessment_date < b.assessment_date
|
|
1794
|
+ ORDER BY b2.assessment_date DESC LIMIT 1
|
|
1795
|
+ ) AS last_weight_after,
|
|
1796
|
+ CASE
|
|
1797
|
+ WHEN (
|
|
1798
|
+ SELECT a2.weight_after
|
|
1799
|
+ FROM xt_assessment_after_dislysis a2
|
|
1800
|
+ JOIN xt_assessment_before_dislysis b2
|
|
1801
|
+ ON a2.patient_id = b2.patient_id
|
|
1802
|
+ AND a2.assessment_date = b2.assessment_date
|
|
1803
|
+ WHERE b2.patient_id = b.patient_id
|
|
1804
|
+ AND b2.assessment_date < b.assessment_date
|
|
1805
|
+ ORDER BY b2.assessment_date DESC LIMIT 1
|
|
1806
|
+ ) IS NOT NULL
|
|
1807
|
+ THEN (b.weight_before - (
|
|
1808
|
+ SELECT a2.weight_after
|
|
1809
|
+ FROM xt_assessment_after_dislysis a2
|
|
1810
|
+ JOIN xt_assessment_before_dislysis b2
|
|
1811
|
+ ON a2.patient_id = b2.patient_id
|
|
1812
|
+ AND a2.assessment_date = b2.assessment_date
|
|
1813
|
+ WHERE b2.patient_id = b.patient_id
|
|
1814
|
+ AND b2.assessment_date < b.assessment_date
|
|
1815
|
+ ORDER BY b2.assessment_date DESC LIMIT 1
|
|
1816
|
+ )) / (
|
|
1817
|
+ SELECT a2.weight_after
|
|
1818
|
+ FROM xt_assessment_after_dislysis a2
|
|
1819
|
+ JOIN xt_assessment_before_dislysis b2
|
|
1820
|
+ ON a2.patient_id = b2.patient_id
|
|
1821
|
+ AND a2.assessment_date = b2.assessment_date
|
|
1822
|
+ WHERE b2.patient_id = b.patient_id
|
|
1823
|
+ AND b2.assessment_date < b.assessment_date
|
|
1824
|
+ ORDER BY b2.assessment_date DESC LIMIT 1
|
|
1825
|
+ )
|
|
1826
|
+ ELSE NULL
|
|
1827
|
+ END AS weight_add,
|
|
1828
|
+ CASE
|
|
1829
|
+ WHEN b.dry_weight IS NOT NULL THEN
|
|
1830
|
+ CASE
|
|
1831
|
+ WHEN b.dry_weight < 40 THEN '小于40'
|
|
1832
|
+ WHEN b.dry_weight BETWEEN 40 AND 50 THEN '40~50'
|
|
1833
|
+ WHEN b.dry_weight BETWEEN 50 AND 60 THEN '50~60'
|
|
1834
|
+ WHEN b.dry_weight BETWEEN 60 AND 70 THEN '60~70'
|
|
1835
|
+ WHEN b.dry_weight > 70 THEN '大于70'
|
|
1836
|
+ END
|
|
1837
|
+ ELSE '其他'
|
|
1838
|
+ END AS dry_weight_category,
|
|
1839
|
+ CASE
|
|
1840
|
+ WHEN b.dry_weight IS NOT NULL THEN
|
|
1841
|
+ CASE
|
|
1842
|
+ WHEN ABS(a.weight_after - b.dry_weight) <= 0.3 THEN '达标'
|
|
1843
|
+ ELSE '不达标'
|
|
1844
|
+ END
|
|
1845
|
+ ELSE '其他'
|
|
1846
|
+ END AS weight_status
|
|
1847
|
+ `).
|
|
1848
|
+ Joins("JOIN xt_patients p ON p.id = b.patient_id").
|
|
1849
|
+ Joins("JOIN xt_assessment_after_dislysis a ON p.id = a.patient_id AND b.assessment_date = a.assessment_date AND a.status = 1").
|
|
1850
|
+ Where("b.user_org_id = ?", user_org_id).
|
|
1851
|
+ Where("b.assessment_date >= ?", start_time).
|
|
1852
|
+ Where("b.assessment_date <= ?", end_time).
|
|
1853
|
+ Where("b.status = ?", 1)
|
|
1854
|
+ // 根据传入的 add_type 值动态构建条件
|
|
1855
|
+ addTypeCondition(query, addType)
|
|
1856
|
+ // 根据传入的 dry_type 值动态构建条件
|
|
1857
|
+ dryTypeCondition(query, dryType)
|
|
1858
|
+ // 根据传入的 after_type 值动态构建条件
|
|
1859
|
+ afterTypeCondition(query, afterType)
|
|
1860
|
+ // 获取总记录数
|
|
1861
|
+ if err := query.Count(&total).Error; err != nil {
|
|
1862
|
+ return nil, 0, fmt.Errorf("count query failed: %v", err)
|
|
1863
|
+ }
|
|
1864
|
+ // 获取分页数据
|
|
1865
|
+ rows, err := query.Order("p.id, b.assessment_date").Offset(int(offset)).Limit(int(limit)).Rows()
|
|
1866
|
+ if err != nil {
|
|
1867
|
+ return nil, 0, fmt.Errorf("pagination query failed: %v", err)
|
|
1868
|
+ }
|
|
1869
|
+ defer rows.Close()
|
|
1870
|
+ // 处理结果集
|
|
1871
|
+ for rows.Next() {
|
|
1872
|
+ var data DialysisDataTwo
|
|
1873
|
+ if err := rows.Scan(
|
|
1874
|
+ &data.DialysisNo,
|
|
1875
|
+ &data.PatientName,
|
|
1876
|
+ &data.Gender,
|
|
1877
|
+ &data.Age,
|
|
1878
|
+ &data.AssessmentDate,
|
|
1879
|
+ &data.DryWeight,
|
|
1880
|
+ &data.WeightBefore,
|
|
1881
|
+ &data.WeightAfter,
|
|
1882
|
+ &data.LastWeightAfter,
|
|
1883
|
+ &data.WeightAdd,
|
|
1884
|
+ &data.DryWeightCategory,
|
|
1885
|
+ &data.WeightStatus,
|
|
1886
|
+ ); err != nil {
|
|
1887
|
+ return nil, 0, fmt.Errorf("row scan failed: %v", err)
|
|
1888
|
+ }
|
|
1889
|
+ // 将每一行结果追加到切片中
|
|
1890
|
+ dialysisData = append(dialysisData, data)
|
|
1891
|
+ }
|
|
1892
|
+ return dialysisData, total, nil
|
|
1893
|
+}
|
|
1894
|
+
|
|
1895
|
+// addType 条件处理
|
|
1896
|
+func addTypeCondition(query *gorm.DB, addType int64) {
|
|
1897
|
+ switch addType {
|
|
1898
|
+ case 1:
|
|
1899
|
+ query.Where("weight_add <= 0.03")
|
|
1900
|
+ case 2:
|
|
1901
|
+ query.Where("weight_add > 0.03 AND weight_add < 0.05")
|
|
1902
|
+ case 3:
|
|
1903
|
+ query.Where("weight_add >= 0.05")
|
|
1904
|
+ case 4:
|
|
1905
|
+ query.Where("weight_add IS NULL")
|
|
1906
|
+ }
|
|
1907
|
+}
|
|
1908
|
+
|
|
1909
|
+// dryType 条件处理
|
|
1910
|
+func dryTypeCondition(query *gorm.DB, dryType int64) {
|
|
1911
|
+ switch dryType {
|
|
1912
|
+ case 1:
|
|
1913
|
+ query.Where("dry_weight_category = '小于40'")
|
|
1914
|
+ case 2:
|
|
1915
|
+ query.Where("dry_weight_category = '40~50'")
|
|
1916
|
+ case 3:
|
|
1917
|
+ query.Where("dry_weight_category = '50~60'")
|
|
1918
|
+ case 4:
|
|
1919
|
+ query.Where("dry_weight_category = '60~70'")
|
|
1920
|
+ case 5:
|
|
1921
|
+ query.Where("dry_weight_category = '大于70'")
|
|
1922
|
+ }
|
|
1923
|
+}
|
|
1924
|
+
|
|
1925
|
+// afterType 条件处理
|
|
1926
|
+func afterTypeCondition(query *gorm.DB, afterType int64) {
|
|
1927
|
+ switch afterType {
|
|
1928
|
+ case 1:
|
|
1929
|
+ query.Where("weight_status = '达标'")
|
|
1930
|
+ case 2:
|
|
1931
|
+ query.Where("weight_status = '不达标'")
|
|
1932
|
+ case 3:
|
|
1933
|
+ query.Where("weight_status = '其他'")
|
|
1934
|
+ }
|
|
1935
|
+}
|
|
1936
|
+
|
|
1937
|
+type DialysisDataThree struct {
|
|
1938
|
+ DialysisNo string `json:"透析号"`
|
|
1939
|
+ PatientName string `json:"患者姓名"`
|
|
1940
|
+ Gender string `json:"性别"`
|
|
1941
|
+ Age int `json:"年龄"`
|
|
1942
|
+ AssessmentDate string `json:"透析日期"`
|
|
1943
|
+ DryWeight float64 `json:"干体重"`
|
|
1944
|
+ PreDialysisBP string `json:"透前血压"`
|
|
1945
|
+ PostDialysisBP string `json:"透后血压"`
|
|
1946
|
+ MonitoringBP string `json:"监测记录血压"`
|
|
1947
|
+ UltrafiltrationRate float64 `json:"超滤率"`
|
|
1948
|
+ UltrafiltrationVol float64 `json:"超滤总量"`
|
|
1949
|
+ BPStatus string `json:"血压达标状态"`
|
|
1950
|
+}
|
|
1951
|
+
|
|
1952
|
+func GetNewDialysisBPDetailTableTen(user_org_id int64, start_time int64, end_time int64, addType, page, limit int64) ([]DialysisDataThree, int64, error) {
|
|
1953
|
+ offset := (page - 1) * limit
|
|
1954
|
+ var total int64
|
|
1955
|
+ var results []DialysisDataThree
|
|
1956
|
+ // SQL 查询
|
|
1957
|
+ query := `
|
|
1958
|
+ SELECT
|
|
1959
|
+ p.dialysis_no AS 透析号,
|
|
1960
|
+ p.name AS 患者姓名,
|
|
1961
|
+ p.gender AS 性别,
|
|
1962
|
+ FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) AS 年龄,
|
|
1963
|
+ b.assessment_date AS 透析日期,
|
|
1964
|
+ b.dry_weight AS 干体重,
|
|
1965
|
+ CONCAT(b.systolic_blood_pressure, '/', b.diastolic_blood_pressure) AS 透前血压,
|
|
1966
|
+ CONCAT(a.systolic_blood_pressure, '/', a.diastolic_blood_pressure) AS 透后血压,
|
|
1967
|
+ GROUP_CONCAT(CONCAT(m.systolic_blood_pressure, '/', m.diastolic_blood_pressure) ORDER BY m.monitoring_date ASC SEPARATOR ',') AS 监测记录血压,
|
|
1968
|
+ (SELECT mr.ultrafiltration_rate
|
|
1969
|
+ FROM xt_monitoring_record mr
|
|
1970
|
+ WHERE mr.patient_id = p.id AND mr.monitoring_date = b.assessment_date
|
|
1971
|
+ ORDER BY mr.operate_time DESC
|
|
1972
|
+ LIMIT 1) AS 超滤率,
|
|
1973
|
+ (SELECT mr.ultrafiltration_volume
|
|
1974
|
+ FROM xt_monitoring_record mr
|
|
1975
|
+ WHERE mr.patient_id = p.id AND mr.monitoring_date = b.assessment_date
|
|
1976
|
+ ORDER BY mr.operate_time DESC
|
|
1977
|
+ LIMIT 1) AS 超滤总量,
|
|
1978
|
+ CASE
|
|
1979
|
+ WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) < 60 THEN
|
|
1980
|
+ CASE
|
|
1981
|
+ WHEN b.systolic_blood_pressure < 140 OR b.diastolic_blood_pressure < 90 THEN '达标'
|
|
1982
|
+ ELSE '不达标'
|
|
1983
|
+ END
|
|
1984
|
+ WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) >= 60 THEN
|
|
1985
|
+ CASE
|
|
1986
|
+ WHEN b.systolic_blood_pressure < 160 OR b.diastolic_blood_pressure < 90 THEN '达标'
|
|
1987
|
+ ELSE '不达标'
|
|
1988
|
+ END
|
|
1989
|
+ END AS 血压达标状态
|
|
1990
|
+ FROM
|
|
1991
|
+ xt_patients p
|
|
1992
|
+ JOIN
|
|
1993
|
+ xt_assessment_before_dislysis b ON p.id = b.patient_id
|
|
1994
|
+ JOIN
|
|
1995
|
+ xt_assessment_after_dislysis a ON p.id = a.patient_id AND b.assessment_date = a.assessment_date
|
|
1996
|
+ JOIN
|
|
1997
|
+ xt_monitoring_record m ON p.id = m.patient_id AND m.monitoring_date = b.assessment_date
|
|
1998
|
+ WHERE
|
|
1999
|
+ b.user_org_id = ?
|
|
2000
|
+ AND b.assessment_date >= ?
|
|
2001
|
+ AND b.assessment_date <= ?
|
|
2002
|
+ AND (
|
|
2003
|
+ (? = 1 AND CASE
|
|
2004
|
+ WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) < 60 THEN
|
|
2005
|
+ CASE
|
|
2006
|
+ WHEN b.systolic_blood_pressure < 140 OR b.diastolic_blood_pressure < 90 THEN 1
|
|
2007
|
+ ELSE 0
|
|
2008
|
+ END
|
|
2009
|
+ WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) >= 60 THEN
|
|
2010
|
+ CASE
|
|
2011
|
+ WHEN b.systolic_blood_pressure < 160 OR b.diastolic_blood_pressure < 90 THEN 1
|
|
2012
|
+ ELSE 0
|
|
2013
|
+ END
|
|
2014
|
+ END = 1)
|
|
2015
|
+ OR
|
|
2016
|
+ (? = 2 AND CASE
|
|
2017
|
+ WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) < 60 THEN
|
|
2018
|
+ CASE
|
|
2019
|
+ WHEN b.systolic_blood_pressure >= 140 AND b.diastolic_blood_pressure >= 90 THEN 1
|
|
2020
|
+ ELSE 0
|
|
2021
|
+ END
|
|
2022
|
+ WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) >= 60 THEN
|
|
2023
|
+ CASE
|
|
2024
|
+ WHEN b.systolic_blood_pressure >= 160 AND b.diastolic_blood_pressure >= 90 THEN 1
|
|
2025
|
+ ELSE 0
|
|
2026
|
+ END
|
|
2027
|
+ END = 1)
|
|
2028
|
+ )
|
|
2029
|
+ GROUP BY
|
|
2030
|
+ p.id, b.assessment_date
|
|
2031
|
+ ORDER BY
|
|
2032
|
+ p.id, b.assessment_date
|
|
2033
|
+ LIMIT ? OFFSET ?;
|
|
2034
|
+ `
|
|
2035
|
+
|
|
2036
|
+ // 计算总数
|
|
2037
|
+ countQuery := `
|
|
2038
|
+ SELECT COUNT(*)
|
|
2039
|
+ FROM
|
|
2040
|
+ xt_patients p
|
|
2041
|
+ JOIN
|
|
2042
|
+ xt_assessment_before_dislysis b ON p.id = b.patient_id
|
|
2043
|
+ WHERE
|
|
2044
|
+ b.user_org_id = ?
|
|
2045
|
+ AND b.assessment_date >= ?
|
|
2046
|
+ AND b.assessment_date <= ?
|
|
2047
|
+ `
|
|
2048
|
+
|
|
2049
|
+ // 执行统计查询
|
|
2050
|
+ if err := readDb.Raw(countQuery, user_org_id, start_time, end_time).Scan(&total).Error; err != nil {
|
|
2051
|
+ return nil, 0, fmt.Errorf("error calculating total count: %v", err)
|
|
2052
|
+ }
|
|
2053
|
+
|
|
2054
|
+ // 执行数据查询
|
|
2055
|
+ if err := readDb.Raw(query, user_org_id, start_time, end_time, addType, addType, limit, offset).Scan(&results).Error; err != nil {
|
|
2056
|
+ return nil, 0, fmt.Errorf("error executing query: %v", err)
|
|
2057
|
+ }
|
|
2058
|
+
|
|
2059
|
+ return results, total, nil
|
|
2060
|
+}
|