|
@@ -1772,105 +1772,265 @@ type DialysisDataTwo struct {
|
1772
|
1772
|
WeightStatus string `json:"weight_status"`
|
1773
|
1773
|
}
|
1774
|
1774
|
|
1775
|
|
-func GetNewDialysisWeightDetailTableTen(user_org_id int64, start_time int64, end_time int64, addType, dryType, afterType, page, limit int64) ([]DialysisDataTwo, int64, error) {
|
|
1775
|
+//func GetNewDialysisWeightDetailTableTen(user_org_id int64, start_time int64, end_time int64, addType, dryType, afterType, page, limit int64) ([]DialysisDataTwo, int64, error) {
|
|
1776
|
+// offset := (page - 1) * limit
|
|
1777
|
+// var dialysisData []DialysisDataTwo
|
|
1778
|
+// var total int64
|
|
1779
|
+// // 构建基本查询
|
|
1780
|
+// query := readDb.Table("xt_assessment_before_dislysis b").
|
|
1781
|
+// Select(`
|
|
1782
|
+// p.dialysis_no AS dialysis_no,
|
|
1783
|
+// p.name AS patient_name,
|
|
1784
|
+// p.gender AS gender,
|
|
1785
|
+// FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) AS age,
|
|
1786
|
+// b.assessment_date AS assessment_date,
|
|
1787
|
+// b.dry_weight AS dry_weight,
|
|
1788
|
+// b.weight_before AS weight_before,
|
|
1789
|
+// a.weight_after AS weight_after,
|
|
1790
|
+// (
|
|
1791
|
+// SELECT a2.weight_after
|
|
1792
|
+// FROM xt_assessment_after_dislysis a2
|
|
1793
|
+// JOIN xt_assessment_before_dislysis b2
|
|
1794
|
+// ON a2.patient_id = b2.patient_id
|
|
1795
|
+// AND a2.assessment_date = b2.assessment_date
|
|
1796
|
+// WHERE b2.patient_id = b.patient_id
|
|
1797
|
+// AND b2.assessment_date < b.assessment_date
|
|
1798
|
+// ORDER BY b2.assessment_date DESC LIMIT 1
|
|
1799
|
+// ) AS last_weight_after,
|
|
1800
|
+// CASE
|
|
1801
|
+// WHEN (
|
|
1802
|
+// SELECT a2.weight_after
|
|
1803
|
+// FROM xt_assessment_after_dislysis a2
|
|
1804
|
+// JOIN xt_assessment_before_dislysis b2
|
|
1805
|
+// ON a2.patient_id = b2.patient_id
|
|
1806
|
+// AND a2.assessment_date = b2.assessment_date
|
|
1807
|
+// WHERE b2.patient_id = b.patient_id
|
|
1808
|
+// AND b2.assessment_date < b.assessment_date
|
|
1809
|
+// ORDER BY b2.assessment_date DESC LIMIT 1
|
|
1810
|
+// ) IS NOT NULL
|
|
1811
|
+// THEN (b.weight_before - (
|
|
1812
|
+// SELECT a2.weight_after
|
|
1813
|
+// FROM xt_assessment_after_dislysis a2
|
|
1814
|
+// JOIN xt_assessment_before_dislysis b2
|
|
1815
|
+// ON a2.patient_id = b2.patient_id
|
|
1816
|
+// AND a2.assessment_date = b2.assessment_date
|
|
1817
|
+// WHERE b2.patient_id = b.patient_id
|
|
1818
|
+// AND b2.assessment_date < b.assessment_date
|
|
1819
|
+// ORDER BY b2.assessment_date DESC LIMIT 1
|
|
1820
|
+// )) / (
|
|
1821
|
+// SELECT a2.weight_after
|
|
1822
|
+// FROM xt_assessment_after_dislysis a2
|
|
1823
|
+// JOIN xt_assessment_before_dislysis b2
|
|
1824
|
+// ON a2.patient_id = b2.patient_id
|
|
1825
|
+// AND a2.assessment_date = b2.assessment_date
|
|
1826
|
+// WHERE b2.patient_id = b.patient_id
|
|
1827
|
+// AND b2.assessment_date < b.assessment_date
|
|
1828
|
+// ORDER BY b2.assessment_date DESC LIMIT 1
|
|
1829
|
+// )
|
|
1830
|
+// ELSE NULL
|
|
1831
|
+// END AS weight_add,
|
|
1832
|
+// CASE
|
|
1833
|
+// WHEN b.dry_weight IS NOT NULL THEN
|
|
1834
|
+// CASE
|
|
1835
|
+// WHEN b.dry_weight < 40 THEN '小于40'
|
|
1836
|
+// WHEN b.dry_weight BETWEEN 40 AND 50 THEN '40~50'
|
|
1837
|
+// WHEN b.dry_weight BETWEEN 50 AND 60 THEN '50~60'
|
|
1838
|
+// WHEN b.dry_weight BETWEEN 60 AND 70 THEN '60~70'
|
|
1839
|
+// WHEN b.dry_weight > 70 THEN '大于70'
|
|
1840
|
+// END
|
|
1841
|
+// ELSE '其他'
|
|
1842
|
+// END AS dry_weight_category,
|
|
1843
|
+// CASE
|
|
1844
|
+// WHEN b.dry_weight IS NOT NULL THEN
|
|
1845
|
+// CASE
|
|
1846
|
+// WHEN ABS(a.weight_after - b.dry_weight) <= 0.3 THEN '达标'
|
|
1847
|
+// ELSE '不达标'
|
|
1848
|
+// END
|
|
1849
|
+// ELSE '其他'
|
|
1850
|
+// END AS weight_status
|
|
1851
|
+// `).
|
|
1852
|
+// Joins("JOIN xt_patients p ON p.id = b.patient_id").
|
|
1853
|
+// Joins("JOIN xt_assessment_after_dislysis a ON p.id = a.patient_id AND b.assessment_date = a.assessment_date AND a.status = 1").
|
|
1854
|
+// Where("b.user_org_id = ?", user_org_id).
|
|
1855
|
+// Where("b.assessment_date >= ?", start_time).
|
|
1856
|
+// Where("b.assessment_date <= ?", end_time).
|
|
1857
|
+// Where("b.status = ?", 1)
|
|
1858
|
+//
|
|
1859
|
+// fmt.Println("dry_type")
|
|
1860
|
+// fmt.Println(dryType)
|
|
1861
|
+// switch dryType {
|
|
1862
|
+// case 1:
|
|
1863
|
+// query.Where("dry_weight_category = '小于40'")
|
|
1864
|
+// case 2:
|
|
1865
|
+// query.Where("dry_weight_category = '40~50'")
|
|
1866
|
+// case 3:
|
|
1867
|
+// query.Where("dry_weight_category = '50~60'")
|
|
1868
|
+// case 4:
|
|
1869
|
+// query.Where("dry_weight_category = '60~70'")
|
|
1870
|
+// case 5:
|
|
1871
|
+// query.Where("dry_weight_category = '大于70'")
|
|
1872
|
+// }
|
|
1873
|
+//
|
|
1874
|
+// // 根据传入的 add_type 值动态构建条件
|
|
1875
|
+// addTypeCondition(query, addType)
|
|
1876
|
+// // 根据传入的 dry_type 值动态构建条件
|
|
1877
|
+// //fmt.Println("dry_type")
|
|
1878
|
+// //fmt.Println(dryType)
|
|
1879
|
+//
|
|
1880
|
+// //dryTypeCondition(query, dryType)
|
|
1881
|
+// // 根据传入的 after_type 值动态构建条件
|
|
1882
|
+// afterTypeCondition(query, afterType)
|
|
1883
|
+// // 获取总记录数
|
|
1884
|
+// if err := query.Count(&total).Error; err != nil {
|
|
1885
|
+// return nil, 0, fmt.Errorf("count query failed: %v", err)
|
|
1886
|
+// }
|
|
1887
|
+// // 获取分页数据
|
|
1888
|
+// rows, err := query.Order("p.id, b.assessment_date").Offset(int(offset)).Limit(int(limit)).Rows()
|
|
1889
|
+// if err != nil {
|
|
1890
|
+// return nil, 0, fmt.Errorf("pagination query failed: %v", err)
|
|
1891
|
+// }
|
|
1892
|
+// defer rows.Close()
|
|
1893
|
+// // 处理结果集
|
|
1894
|
+// for rows.Next() {
|
|
1895
|
+// var data DialysisDataTwo
|
|
1896
|
+// if err := rows.Scan(
|
|
1897
|
+// &data.DialysisNo,
|
|
1898
|
+// &data.PatientName,
|
|
1899
|
+// &data.Gender,
|
|
1900
|
+// &data.Age,
|
|
1901
|
+// &data.AssessmentDate,
|
|
1902
|
+// &data.DryWeight,
|
|
1903
|
+// &data.WeightBefore,
|
|
1904
|
+// &data.WeightAfter,
|
|
1905
|
+// &data.LastWeightAfter,
|
|
1906
|
+// &data.WeightAdd,
|
|
1907
|
+// &data.DryWeightCategory,
|
|
1908
|
+// &data.WeightStatus,
|
|
1909
|
+// ); err != nil {
|
|
1910
|
+// return nil, 0, fmt.Errorf("row scan failed: %v", err)
|
|
1911
|
+// }
|
|
1912
|
+// // 将每一行结果追加到切片中
|
|
1913
|
+// dialysisData = append(dialysisData, data)
|
|
1914
|
+// }
|
|
1915
|
+// return dialysisData, total, nil
|
|
1916
|
+//}
|
|
1917
|
+
|
|
1918
|
+func GetNewDialysisWeightDetailTableTen(
|
|
1919
|
+ user_org_id int64,
|
|
1920
|
+ start_time int64,
|
|
1921
|
+ end_time int64,
|
|
1922
|
+ addType, dryType, afterType, page, limit int64,
|
|
1923
|
+) ([]DialysisDataTwo, int64, error) {
|
1776
|
1924
|
offset := (page - 1) * limit
|
1777
|
1925
|
var dialysisData []DialysisDataTwo
|
1778
|
1926
|
var total int64
|
|
1927
|
+
|
1779
|
1928
|
// 构建基本查询
|
1780
|
1929
|
query := readDb.Table("xt_assessment_before_dislysis b").
|
1781
|
1930
|
Select(`
|
1782
|
|
- p.dialysis_no AS dialysis_no,
|
1783
|
|
- p.name AS patient_name,
|
1784
|
|
- p.gender AS gender,
|
1785
|
|
- FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) AS age,
|
1786
|
|
- b.assessment_date AS assessment_date,
|
1787
|
|
- b.dry_weight AS dry_weight,
|
1788
|
|
- b.weight_before AS weight_before,
|
1789
|
|
- a.weight_after AS weight_after,
|
1790
|
|
- (
|
1791
|
|
- SELECT a2.weight_after
|
1792
|
|
- FROM xt_assessment_after_dislysis a2
|
1793
|
|
- JOIN xt_assessment_before_dislysis b2
|
1794
|
|
- ON a2.patient_id = b2.patient_id
|
1795
|
|
- AND a2.assessment_date = b2.assessment_date
|
1796
|
|
- WHERE b2.patient_id = b.patient_id
|
1797
|
|
- AND b2.assessment_date < b.assessment_date
|
1798
|
|
- ORDER BY b2.assessment_date DESC LIMIT 1
|
1799
|
|
- ) AS last_weight_after,
|
1800
|
|
- CASE
|
1801
|
|
- WHEN (
|
1802
|
|
- SELECT a2.weight_after
|
1803
|
|
- FROM xt_assessment_after_dislysis a2
|
1804
|
|
- JOIN xt_assessment_before_dislysis b2
|
1805
|
|
- ON a2.patient_id = b2.patient_id
|
1806
|
|
- AND a2.assessment_date = b2.assessment_date
|
1807
|
|
- WHERE b2.patient_id = b.patient_id
|
1808
|
|
- AND b2.assessment_date < b.assessment_date
|
1809
|
|
- ORDER BY b2.assessment_date DESC LIMIT 1
|
1810
|
|
- ) IS NOT NULL
|
1811
|
|
- THEN (b.weight_before - (
|
1812
|
|
- SELECT a2.weight_after
|
1813
|
|
- FROM xt_assessment_after_dislysis a2
|
1814
|
|
- JOIN xt_assessment_before_dislysis b2
|
1815
|
|
- ON a2.patient_id = b2.patient_id
|
1816
|
|
- AND a2.assessment_date = b2.assessment_date
|
1817
|
|
- WHERE b2.patient_id = b.patient_id
|
1818
|
|
- AND b2.assessment_date < b.assessment_date
|
1819
|
|
- ORDER BY b2.assessment_date DESC LIMIT 1
|
1820
|
|
- )) / (
|
1821
|
|
- SELECT a2.weight_after
|
1822
|
|
- FROM xt_assessment_after_dislysis a2
|
1823
|
|
- JOIN xt_assessment_before_dislysis b2
|
1824
|
|
- ON a2.patient_id = b2.patient_id
|
1825
|
|
- AND a2.assessment_date = b2.assessment_date
|
1826
|
|
- WHERE b2.patient_id = b.patient_id
|
1827
|
|
- AND b2.assessment_date < b.assessment_date
|
1828
|
|
- ORDER BY b2.assessment_date DESC LIMIT 1
|
1829
|
|
- )
|
1830
|
|
- ELSE NULL
|
1831
|
|
- END AS weight_add,
|
1832
|
|
- CASE
|
1833
|
|
- WHEN b.dry_weight IS NOT NULL THEN
|
1834
|
|
- CASE
|
1835
|
|
- WHEN b.dry_weight < 40 THEN '小于40'
|
1836
|
|
- WHEN b.dry_weight BETWEEN 40 AND 50 THEN '40~50'
|
1837
|
|
- WHEN b.dry_weight BETWEEN 50 AND 60 THEN '50~60'
|
1838
|
|
- WHEN b.dry_weight BETWEEN 60 AND 70 THEN '60~70'
|
1839
|
|
- WHEN b.dry_weight > 70 THEN '大于70'
|
1840
|
|
- END
|
1841
|
|
- ELSE '其他'
|
1842
|
|
- END AS dry_weight_category,
|
1843
|
|
- CASE
|
1844
|
|
- WHEN b.dry_weight IS NOT NULL THEN
|
1845
|
|
- CASE
|
1846
|
|
- WHEN ABS(a.weight_after - b.dry_weight) <= 0.3 THEN '达标'
|
1847
|
|
- ELSE '不达标'
|
1848
|
|
- END
|
1849
|
|
- ELSE '其他'
|
1850
|
|
- END AS weight_status
|
1851
|
|
- `).
|
|
1931
|
+ p.dialysis_no AS dialysis_no,
|
|
1932
|
+ p.name AS patient_name,
|
|
1933
|
+ p.gender AS gender,
|
|
1934
|
+ FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) AS age,
|
|
1935
|
+ b.assessment_date AS assessment_date,
|
|
1936
|
+ b.dry_weight AS dry_weight,
|
|
1937
|
+ b.weight_before AS weight_before,
|
|
1938
|
+ a.weight_after AS weight_after,
|
|
1939
|
+ (
|
|
1940
|
+ SELECT a2.weight_after
|
|
1941
|
+ FROM xt_assessment_after_dislysis a2
|
|
1942
|
+ JOIN xt_assessment_before_dislysis b2
|
|
1943
|
+ ON a2.patient_id = b2.patient_id
|
|
1944
|
+ AND a2.assessment_date = b2.assessment_date
|
|
1945
|
+ WHERE b2.patient_id = b.patient_id
|
|
1946
|
+ AND b2.assessment_date < b.assessment_date
|
|
1947
|
+ ORDER BY b2.assessment_date DESC LIMIT 1
|
|
1948
|
+ ) AS last_weight_after,
|
|
1949
|
+ CASE
|
|
1950
|
+ WHEN (
|
|
1951
|
+ SELECT a2.weight_after
|
|
1952
|
+ FROM xt_assessment_after_dislysis a2
|
|
1953
|
+ JOIN xt_assessment_before_dislysis b2
|
|
1954
|
+ ON a2.patient_id = b2.patient_id
|
|
1955
|
+ AND a2.assessment_date = b2.assessment_date
|
|
1956
|
+ WHERE b2.patient_id = b.patient_id
|
|
1957
|
+ AND b2.assessment_date < b.assessment_date
|
|
1958
|
+ ORDER BY b2.assessment_date DESC LIMIT 1
|
|
1959
|
+ ) IS NOT NULL
|
|
1960
|
+ THEN (b.weight_before - (
|
|
1961
|
+ SELECT a2.weight_after
|
|
1962
|
+ FROM xt_assessment_after_dislysis a2
|
|
1963
|
+ JOIN xt_assessment_before_dislysis b2
|
|
1964
|
+ ON a2.patient_id = b2.patient_id
|
|
1965
|
+ AND a2.assessment_date = b2.assessment_date
|
|
1966
|
+ WHERE b2.patient_id = b.patient_id
|
|
1967
|
+ AND b2.assessment_date < b.assessment_date
|
|
1968
|
+ ORDER BY b2.assessment_date DESC LIMIT 1
|
|
1969
|
+ )) / (
|
|
1970
|
+ SELECT a2.weight_after
|
|
1971
|
+ FROM xt_assessment_after_dislysis a2
|
|
1972
|
+ JOIN xt_assessment_before_dislysis b2
|
|
1973
|
+ ON a2.patient_id = b2.patient_id
|
|
1974
|
+ AND a2.assessment_date = b2.assessment_date
|
|
1975
|
+ WHERE b2.patient_id = b.patient_id
|
|
1976
|
+ AND b2.assessment_date < b.assessment_date
|
|
1977
|
+ ORDER BY b2.assessment_date DESC LIMIT 1
|
|
1978
|
+ )
|
|
1979
|
+ ELSE NULL
|
|
1980
|
+ END AS weight_add,
|
|
1981
|
+ CASE
|
|
1982
|
+ WHEN b.dry_weight IS NOT NULL THEN
|
|
1983
|
+ CASE
|
|
1984
|
+ WHEN ABS(a.weight_after - b.dry_weight) <= 0.3 THEN '达标'
|
|
1985
|
+ ELSE '不达标'
|
|
1986
|
+ END
|
|
1987
|
+ ELSE '其他'
|
|
1988
|
+ END AS weight_status
|
|
1989
|
+ `).
|
1852
|
1990
|
Joins("JOIN xt_patients p ON p.id = b.patient_id").
|
1853
|
1991
|
Joins("JOIN xt_assessment_after_dislysis a ON p.id = a.patient_id AND b.assessment_date = a.assessment_date AND a.status = 1").
|
1854
|
1992
|
Where("b.user_org_id = ?", user_org_id).
|
1855
|
1993
|
Where("b.assessment_date >= ?", start_time).
|
1856
|
1994
|
Where("b.assessment_date <= ?", end_time).
|
1857
|
1995
|
Where("b.status = ?", 1)
|
1858
|
|
- // 根据传入的 add_type 值动态构建条件
|
1859
|
|
- addTypeCondition(query, addType)
|
|
1996
|
+
|
1860
|
1997
|
// 根据传入的 dry_type 值动态构建条件
|
1861
|
|
- dryTypeCondition(query, dryType)
|
1862
|
|
- // 根据传入的 after_type 值动态构建条件
|
|
1998
|
+ fmt.Println("00=-----11111")
|
|
1999
|
+ fmt.Println(dryType)
|
|
2000
|
+
|
|
2001
|
+ switch dryType {
|
|
2002
|
+ case 1:
|
|
2003
|
+ fmt.Println("00=-----11111")
|
|
2004
|
+ fmt.Println(dryType)
|
|
2005
|
+ query = query.Where("b.dry_weight < ?", 40)
|
|
2006
|
+ case 2:
|
|
2007
|
+ query = query.Where("b.dry_weight BETWEEN ? AND ?", 40, 50)
|
|
2008
|
+ case 3:
|
|
2009
|
+ query = query.Where("b.dry_weight BETWEEN ? AND ?", 50, 60)
|
|
2010
|
+ case 4:
|
|
2011
|
+ query = query.Where("b.dry_weight BETWEEN ? AND ?", 60, 70)
|
|
2012
|
+ case 5:
|
|
2013
|
+ query = query.Where("b.dry_weight > ?", 70)
|
|
2014
|
+ }
|
|
2015
|
+
|
|
2016
|
+ //// 根据传入的 add_type 值动态构建条件
|
|
2017
|
+ addTypeCondition(query, addType)
|
|
2018
|
+ //
|
|
2019
|
+ //// 根据传入的 after_type 值动态构建条件
|
1863
|
2020
|
afterTypeCondition(query, afterType)
|
|
2021
|
+
|
1864
|
2022
|
// 获取总记录数
|
1865
|
2023
|
if err := query.Count(&total).Error; err != nil {
|
1866
|
2024
|
return nil, 0, fmt.Errorf("count query failed: %v", err)
|
1867
|
2025
|
}
|
|
2026
|
+
|
1868
|
2027
|
// 获取分页数据
|
1869
|
2028
|
rows, err := query.Order("p.id, b.assessment_date").Offset(int(offset)).Limit(int(limit)).Rows()
|
1870
|
2029
|
if err != nil {
|
1871
|
2030
|
return nil, 0, fmt.Errorf("pagination query failed: %v", err)
|
1872
|
2031
|
}
|
1873
|
2032
|
defer rows.Close()
|
|
2033
|
+
|
1874
|
2034
|
// 处理结果集
|
1875
|
2035
|
for rows.Next() {
|
1876
|
2036
|
var data DialysisDataTwo
|
|
@@ -1885,7 +2045,6 @@ func GetNewDialysisWeightDetailTableTen(user_org_id int64, start_time int64, end
|
1885
|
2045
|
&data.WeightAfter,
|
1886
|
2046
|
&data.LastWeightAfter,
|
1887
|
2047
|
&data.WeightAdd,
|
1888
|
|
- &data.DryWeightCategory,
|
1889
|
2048
|
&data.WeightStatus,
|
1890
|
2049
|
); err != nil {
|
1891
|
2050
|
return nil, 0, fmt.Errorf("row scan failed: %v", err)
|
|
@@ -1900,41 +2059,30 @@ func GetNewDialysisWeightDetailTableTen(user_org_id int64, start_time int64, end
|
1900
|
2059
|
func addTypeCondition(query *gorm.DB, addType int64) {
|
1901
|
2060
|
switch addType {
|
1902
|
2061
|
case 1:
|
1903
|
|
- query.Where("weight_add <= 0.03")
|
|
2062
|
+ query = query.Where("weight_add <= 0.03")
|
1904
|
2063
|
case 2:
|
1905
|
|
- query.Where("weight_add > 0.03 AND weight_add < 0.05")
|
|
2064
|
+ query = query.Where("weight_add > 0.03 AND weight_add < 0.05")
|
1906
|
2065
|
case 3:
|
1907
|
|
- query.Where("weight_add >= 0.05")
|
|
2066
|
+ query = query.Where("weight_add >= 0.05")
|
1908
|
2067
|
case 4:
|
1909
|
|
- query.Where("weight_add IS NULL")
|
|
2068
|
+ query = query.Where("weight_add IS NULL")
|
1910
|
2069
|
}
|
1911
|
2070
|
}
|
1912
|
2071
|
|
1913
|
2072
|
// dryType 条件处理
|
1914
|
2073
|
func dryTypeCondition(query *gorm.DB, dryType int64) {
|
1915
|
|
- switch dryType {
|
1916
|
|
- case 1:
|
1917
|
|
- query.Where("dry_weight_category = '小于40'")
|
1918
|
|
- case 2:
|
1919
|
|
- query.Where("dry_weight_category = '40~50'")
|
1920
|
|
- case 3:
|
1921
|
|
- query.Where("dry_weight_category = '50~60'")
|
1922
|
|
- case 4:
|
1923
|
|
- query.Where("dry_weight_category = '60~70'")
|
1924
|
|
- case 5:
|
1925
|
|
- query.Where("dry_weight_category = '大于70'")
|
1926
|
|
- }
|
|
2074
|
+
|
1927
|
2075
|
}
|
1928
|
2076
|
|
1929
|
2077
|
// afterType 条件处理
|
1930
|
2078
|
func afterTypeCondition(query *gorm.DB, afterType int64) {
|
1931
|
2079
|
switch afterType {
|
1932
|
2080
|
case 1:
|
1933
|
|
- query.Where("weight_status = '达标'")
|
|
2081
|
+ query = query.Where("weight_status = '达标'")
|
1934
|
2082
|
case 2:
|
1935
|
|
- query.Where("weight_status = '不达标'")
|
|
2083
|
+ query = query.Where("weight_status = '不达标'")
|
1936
|
2084
|
case 3:
|
1937
|
|
- query.Where("weight_status = '其他'")
|
|
2085
|
+ query = query.Where("weight_status = '其他'")
|
1938
|
2086
|
}
|
1939
|
2087
|
}
|
1940
|
2088
|
|
|
@@ -1953,102 +2101,217 @@ type DialysisDataThree struct {
|
1953
|
2101
|
BPStatus string `json:"血压达标状态"`
|
1954
|
2102
|
}
|
1955
|
2103
|
|
1956
|
|
-func GetNewDialysisBPDetailTableTen(user_org_id int64, start_time int64, end_time int64, addType, page, limit int64) ([]DialysisDataThree, int64, error) {
|
|
2104
|
+// func GetNewDialysisBPDetailTableTen(user_org_id int64, start_time int64, end_time int64, addType, page, limit int64) ([]DialysisDataThree, int64, error) {
|
|
2105
|
+// offset := (page - 1) * limit
|
|
2106
|
+// var total int64
|
|
2107
|
+// var results []DialysisDataThree
|
|
2108
|
+// // SQL 查询
|
|
2109
|
+// query := `
|
|
2110
|
+// SELECT
|
|
2111
|
+// p.dialysis_no AS 透析号,
|
|
2112
|
+// p.name AS 患者姓名,
|
|
2113
|
+// p.gender AS 性别,
|
|
2114
|
+// FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) AS 年龄,
|
|
2115
|
+// b.assessment_date AS 透析日期,
|
|
2116
|
+// b.dry_weight AS 干体重,
|
|
2117
|
+// CONCAT(b.systolic_blood_pressure, '/', b.diastolic_blood_pressure) AS 透前血压,
|
|
2118
|
+// CONCAT(a.systolic_blood_pressure, '/', a.diastolic_blood_pressure) AS 透后血压,
|
|
2119
|
+// GROUP_CONCAT(CONCAT(m.systolic_blood_pressure, '/', m.diastolic_blood_pressure) ORDER BY m.monitoring_date ASC SEPARATOR ',') AS 监测记录血压,
|
|
2120
|
+// (SELECT mr.ultrafiltration_rate
|
|
2121
|
+// FROM xt_monitoring_record mr
|
|
2122
|
+// WHERE mr.patient_id = p.id AND mr.monitoring_date = b.assessment_date
|
|
2123
|
+// ORDER BY mr.operate_time DESC
|
|
2124
|
+// LIMIT 1) AS 超滤率,
|
|
2125
|
+// (SELECT mr.ultrafiltration_volume
|
|
2126
|
+// FROM xt_monitoring_record mr
|
|
2127
|
+// WHERE mr.patient_id = p.id AND mr.monitoring_date = b.assessment_date
|
|
2128
|
+// ORDER BY mr.operate_time DESC
|
|
2129
|
+// LIMIT 1) AS 超滤总量,
|
|
2130
|
+// CASE
|
|
2131
|
+// WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) < 60 THEN
|
|
2132
|
+// CASE
|
|
2133
|
+// WHEN b.systolic_blood_pressure < 140 OR b.diastolic_blood_pressure < 90 THEN '达标'
|
|
2134
|
+// ELSE '不达标'
|
|
2135
|
+// END
|
|
2136
|
+// WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) >= 60 THEN
|
|
2137
|
+// CASE
|
|
2138
|
+// WHEN b.systolic_blood_pressure < 160 OR b.diastolic_blood_pressure < 90 THEN '达标'
|
|
2139
|
+// ELSE '不达标'
|
|
2140
|
+// END
|
|
2141
|
+// END AS 血压达标状态
|
|
2142
|
+// FROM
|
|
2143
|
+// xt_patients p
|
|
2144
|
+// JOIN
|
|
2145
|
+// xt_assessment_before_dislysis b ON p.id = b.patient_id
|
|
2146
|
+// JOIN
|
|
2147
|
+// xt_assessment_after_dislysis a ON p.id = a.patient_id AND b.assessment_date = a.assessment_date
|
|
2148
|
+// JOIN
|
|
2149
|
+// xt_monitoring_record m ON p.id = m.patient_id AND m.monitoring_date = b.assessment_date
|
|
2150
|
+// WHERE
|
|
2151
|
+// b.user_org_id = ?
|
|
2152
|
+// AND b.assessment_date >= ?
|
|
2153
|
+// AND b.assessment_date <= ?
|
|
2154
|
+// AND (
|
|
2155
|
+// (? = 1 AND CASE
|
|
2156
|
+// WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) < 60 THEN
|
|
2157
|
+// CASE
|
|
2158
|
+// WHEN b.systolic_blood_pressure < 140 OR b.diastolic_blood_pressure < 90 THEN 1
|
|
2159
|
+// ELSE 0
|
|
2160
|
+// END
|
|
2161
|
+// WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) >= 60 THEN
|
|
2162
|
+// CASE
|
|
2163
|
+// WHEN b.systolic_blood_pressure < 160 OR b.diastolic_blood_pressure < 90 THEN 1
|
|
2164
|
+// ELSE 0
|
|
2165
|
+// END
|
|
2166
|
+// END = 1)
|
|
2167
|
+// OR
|
|
2168
|
+// (? = 2 AND CASE
|
|
2169
|
+// WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) < 60 THEN
|
|
2170
|
+// CASE
|
|
2171
|
+// WHEN b.systolic_blood_pressure >= 140 AND b.diastolic_blood_pressure >= 90 THEN 1
|
|
2172
|
+// ELSE 0
|
|
2173
|
+// END
|
|
2174
|
+// WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) >= 60 THEN
|
|
2175
|
+// CASE
|
|
2176
|
+// WHEN b.systolic_blood_pressure >= 160 AND b.diastolic_blood_pressure >= 90 THEN 1
|
|
2177
|
+// ELSE 0
|
|
2178
|
+// END
|
|
2179
|
+// END = 1)
|
|
2180
|
+// )
|
|
2181
|
+// GROUP BY
|
|
2182
|
+// p.id, b.assessment_date
|
|
2183
|
+// ORDER BY
|
|
2184
|
+// p.id, b.assessment_date
|
|
2185
|
+// LIMIT ? OFFSET ?;
|
|
2186
|
+// `
|
|
2187
|
+//
|
|
2188
|
+// // 计算总数
|
|
2189
|
+// countQuery := `
|
|
2190
|
+// SELECT COUNT(*)
|
|
2191
|
+// FROM
|
|
2192
|
+// xt_patients p
|
|
2193
|
+// JOIN
|
|
2194
|
+// xt_assessment_before_dislysis b ON p.id = b.patient_id
|
|
2195
|
+// WHERE
|
|
2196
|
+// b.user_org_id = ?
|
|
2197
|
+// AND b.assessment_date >= ?
|
|
2198
|
+// AND b.assessment_date <= ?
|
|
2199
|
+// `
|
|
2200
|
+//
|
|
2201
|
+// // 执行统计查询
|
|
2202
|
+// if err := readDb.Raw(countQuery, user_org_id, start_time, end_time).Scan(&total).Error; err != nil {
|
|
2203
|
+// return nil, 0, fmt.Errorf("error calculating total count: %v", err)
|
|
2204
|
+// }
|
|
2205
|
+//
|
|
2206
|
+// // 执行数据查询
|
|
2207
|
+// if err := readDb.Raw(query, user_org_id, start_time, end_time, addType, addType, limit, offset).Scan(&results).Error; err != nil {
|
|
2208
|
+// return nil, 0, fmt.Errorf("error executing query: %v", err)
|
|
2209
|
+// }
|
|
2210
|
+//
|
|
2211
|
+// return results, total, nil
|
|
2212
|
+// }
|
|
2213
|
+func GetNewDialysisBPDetailTableTen(
|
|
2214
|
+ user_org_id int64,
|
|
2215
|
+ start_time int64,
|
|
2216
|
+ end_time int64,
|
|
2217
|
+ addType, page, limit int64,
|
|
2218
|
+) ([]DialysisDataThree, int64, error) {
|
1957
|
2219
|
offset := (page - 1) * limit
|
1958
|
2220
|
var total int64
|
1959
|
2221
|
var results []DialysisDataThree
|
|
2222
|
+
|
1960
|
2223
|
// SQL 查询
|
1961
|
2224
|
query := `
|
1962
|
|
- SELECT
|
1963
|
|
- p.dialysis_no AS 透析号,
|
1964
|
|
- p.name AS 患者姓名,
|
1965
|
|
- p.gender AS 性别,
|
1966
|
|
- FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) AS 年龄,
|
1967
|
|
- b.assessment_date AS 透析日期,
|
1968
|
|
- b.dry_weight AS 干体重,
|
1969
|
|
- CONCAT(b.systolic_blood_pressure, '/', b.diastolic_blood_pressure) AS 透前血压,
|
1970
|
|
- CONCAT(a.systolic_blood_pressure, '/', a.diastolic_blood_pressure) AS 透后血压,
|
1971
|
|
- GROUP_CONCAT(CONCAT(m.systolic_blood_pressure, '/', m.diastolic_blood_pressure) ORDER BY m.monitoring_date ASC SEPARATOR ',') AS 监测记录血压,
|
1972
|
|
- (SELECT mr.ultrafiltration_rate
|
1973
|
|
- FROM xt_monitoring_record mr
|
1974
|
|
- WHERE mr.patient_id = p.id AND mr.monitoring_date = b.assessment_date
|
1975
|
|
- ORDER BY mr.operate_time DESC
|
1976
|
|
- LIMIT 1) AS 超滤率,
|
1977
|
|
- (SELECT mr.ultrafiltration_volume
|
1978
|
|
- FROM xt_monitoring_record mr
|
1979
|
|
- WHERE mr.patient_id = p.id AND mr.monitoring_date = b.assessment_date
|
1980
|
|
- ORDER BY mr.operate_time DESC
|
1981
|
|
- LIMIT 1) AS 超滤总量,
|
1982
|
|
- CASE
|
1983
|
|
- WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) < 60 THEN
|
1984
|
|
- CASE
|
1985
|
|
- WHEN b.systolic_blood_pressure < 140 OR b.diastolic_blood_pressure < 90 THEN '达标'
|
1986
|
|
- ELSE '不达标'
|
1987
|
|
- END
|
1988
|
|
- WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) >= 60 THEN
|
1989
|
|
- CASE
|
1990
|
|
- WHEN b.systolic_blood_pressure < 160 OR b.diastolic_blood_pressure < 90 THEN '达标'
|
1991
|
|
- ELSE '不达标'
|
1992
|
|
- END
|
1993
|
|
- END AS 血压达标状态
|
1994
|
|
- FROM
|
1995
|
|
- xt_patients p
|
1996
|
|
- JOIN
|
1997
|
|
- xt_assessment_before_dislysis b ON p.id = b.patient_id
|
1998
|
|
- JOIN
|
1999
|
|
- xt_assessment_after_dislysis a ON p.id = a.patient_id AND b.assessment_date = a.assessment_date
|
2000
|
|
- JOIN
|
2001
|
|
- xt_monitoring_record m ON p.id = m.patient_id AND m.monitoring_date = b.assessment_date
|
2002
|
|
- WHERE
|
2003
|
|
- b.user_org_id = ?
|
2004
|
|
- AND b.assessment_date >= ?
|
2005
|
|
- AND b.assessment_date <= ?
|
2006
|
|
- AND (
|
2007
|
|
- (? = 1 AND CASE
|
2008
|
|
- WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) < 60 THEN
|
2009
|
|
- CASE
|
2010
|
|
- WHEN b.systolic_blood_pressure < 140 OR b.diastolic_blood_pressure < 90 THEN 1
|
2011
|
|
- ELSE 0
|
2012
|
|
- END
|
2013
|
|
- WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) >= 60 THEN
|
2014
|
|
- CASE
|
2015
|
|
- WHEN b.systolic_blood_pressure < 160 OR b.diastolic_blood_pressure < 90 THEN 1
|
2016
|
|
- ELSE 0
|
2017
|
|
- END
|
2018
|
|
- END = 1)
|
2019
|
|
- OR
|
2020
|
|
- (? = 2 AND CASE
|
2021
|
|
- WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) < 60 THEN
|
2022
|
|
- CASE
|
2023
|
|
- WHEN b.systolic_blood_pressure >= 140 AND b.diastolic_blood_pressure >= 90 THEN 1
|
2024
|
|
- ELSE 0
|
2025
|
|
- END
|
2026
|
|
- WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) >= 60 THEN
|
2027
|
|
- CASE
|
2028
|
|
- WHEN b.systolic_blood_pressure >= 160 AND b.diastolic_blood_pressure >= 90 THEN 1
|
2029
|
|
- ELSE 0
|
2030
|
|
- END
|
2031
|
|
- END = 1)
|
2032
|
|
- )
|
2033
|
|
- GROUP BY
|
2034
|
|
- p.id, b.assessment_date
|
2035
|
|
- ORDER BY
|
2036
|
|
- p.id, b.assessment_date
|
2037
|
|
- LIMIT ? OFFSET ?;
|
2038
|
|
- `
|
|
2225
|
+ SELECT
|
|
2226
|
+ p.dialysis_no AS DialysisNo,
|
|
2227
|
+ p.name AS PatientName,
|
|
2228
|
+ p.gender AS Gender,
|
|
2229
|
+ FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) AS Age,
|
|
2230
|
+ b.assessment_date AS AssessmentDate,
|
|
2231
|
+ b.dry_weight AS DryWeight,
|
|
2232
|
+ CONCAT(b.systolic_blood_pressure, '/', b.diastolic_blood_pressure) AS PreDialysisBP,
|
|
2233
|
+ CONCAT(a.systolic_blood_pressure, '/', a.diastolic_blood_pressure) AS PostDialysisBP,
|
|
2234
|
+ GROUP_CONCAT(CONCAT(m.systolic_blood_pressure, '/', m.diastolic_blood_pressure) ORDER BY m.monitoring_date ASC SEPARATOR ',') AS MonitoringBP,
|
|
2235
|
+ (SELECT mr.ultrafiltration_rate
|
|
2236
|
+ FROM xt_monitoring_record mr
|
|
2237
|
+ WHERE mr.patient_id = p.id AND mr.monitoring_date = b.assessment_date
|
|
2238
|
+ ORDER BY mr.operate_time DESC
|
|
2239
|
+ LIMIT 1) AS UltrafiltrationRate,
|
|
2240
|
+ (SELECT mr.ultrafiltration_volume
|
|
2241
|
+ FROM xt_monitoring_record mr
|
|
2242
|
+ WHERE mr.patient_id = p.id AND mr.monitoring_date = b.assessment_date
|
|
2243
|
+ ORDER BY mr.operate_time DESC
|
|
2244
|
+ LIMIT 1) AS UltrafiltrationVol,
|
|
2245
|
+ CASE
|
|
2246
|
+ WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) < 60 THEN
|
|
2247
|
+ CASE
|
|
2248
|
+ WHEN b.systolic_blood_pressure < 140 OR b.diastolic_blood_pressure < 90 THEN '达标'
|
|
2249
|
+ ELSE '不达标'
|
|
2250
|
+ END
|
|
2251
|
+ WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) >= 60 THEN
|
|
2252
|
+ CASE
|
|
2253
|
+ WHEN b.systolic_blood_pressure < 160 OR b.diastolic_blood_pressure < 90 THEN '达标'
|
|
2254
|
+ ELSE '不达标'
|
|
2255
|
+ END
|
|
2256
|
+ END AS BPStatus
|
|
2257
|
+ FROM
|
|
2258
|
+ xt_patients p
|
|
2259
|
+ JOIN
|
|
2260
|
+ xt_assessment_before_dislysis b ON p.id = b.patient_id
|
|
2261
|
+ JOIN
|
|
2262
|
+ xt_assessment_after_dislysis a ON p.id = a.patient_id AND b.assessment_date = a.assessment_date
|
|
2263
|
+ JOIN
|
|
2264
|
+ xt_monitoring_record m ON p.id = m.patient_id AND m.monitoring_date = b.assessment_date
|
|
2265
|
+ WHERE
|
|
2266
|
+ b.user_org_id = ?
|
|
2267
|
+ AND b.assessment_date >= ?
|
|
2268
|
+ AND b.assessment_date <= ?
|
|
2269
|
+ AND (
|
|
2270
|
+ (? = 1 AND CASE
|
|
2271
|
+ WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) < 60 THEN
|
|
2272
|
+ CASE
|
|
2273
|
+ WHEN b.systolic_blood_pressure < 140 OR b.diastolic_blood_pressure < 90 THEN 1
|
|
2274
|
+ ELSE 0
|
|
2275
|
+ END
|
|
2276
|
+ WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) >= 60 THEN
|
|
2277
|
+ CASE
|
|
2278
|
+ WHEN b.systolic_blood_pressure < 160 OR b.diastolic_blood_pressure < 90 THEN 1
|
|
2279
|
+ ELSE 0
|
|
2280
|
+ END
|
|
2281
|
+ END = 1)
|
|
2282
|
+ OR
|
|
2283
|
+ (? = 2 AND CASE
|
|
2284
|
+ WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) < 60 THEN
|
|
2285
|
+ CASE
|
|
2286
|
+ WHEN b.systolic_blood_pressure >= 140 AND b.diastolic_blood_pressure >= 90 THEN 1
|
|
2287
|
+ ELSE 0
|
|
2288
|
+ END
|
|
2289
|
+ WHEN FLOOR((YEAR(CURDATE()) - SUBSTRING(p.id_card_no, 7, 4))) >= 60 THEN
|
|
2290
|
+ CASE
|
|
2291
|
+ WHEN b.systolic_blood_pressure >= 160 AND b.diastolic_blood_pressure >= 90 THEN 1
|
|
2292
|
+ ELSE 0
|
|
2293
|
+ END
|
|
2294
|
+ END = 1)
|
|
2295
|
+ )
|
|
2296
|
+ GROUP BY
|
|
2297
|
+ p.id, b.assessment_date
|
|
2298
|
+ ORDER BY
|
|
2299
|
+ p.id, b.assessment_date
|
|
2300
|
+ LIMIT ? OFFSET ?;
|
|
2301
|
+ `
|
2039
|
2302
|
|
2040
|
2303
|
// 计算总数
|
2041
|
2304
|
countQuery := `
|
2042
|
|
- SELECT COUNT(*)
|
2043
|
|
- FROM
|
2044
|
|
- xt_patients p
|
2045
|
|
- JOIN
|
2046
|
|
- xt_assessment_before_dislysis b ON p.id = b.patient_id
|
2047
|
|
- WHERE
|
2048
|
|
- b.user_org_id = ?
|
2049
|
|
- AND b.assessment_date >= ?
|
2050
|
|
- AND b.assessment_date <= ?
|
2051
|
|
- `
|
|
2305
|
+ SELECT COUNT(*)
|
|
2306
|
+ FROM
|
|
2307
|
+ xt_patients p
|
|
2308
|
+ JOIN
|
|
2309
|
+ xt_assessment_before_dislysis b ON p.id = b.patient_id
|
|
2310
|
+ WHERE
|
|
2311
|
+ b.user_org_id = ?
|
|
2312
|
+ AND b.assessment_date >= ?
|
|
2313
|
+ AND b.assessment_date <= ?
|
|
2314
|
+ `
|
2052
|
2315
|
|
2053
|
2316
|
// 执行统计查询
|
2054
|
2317
|
if err := readDb.Raw(countQuery, user_org_id, start_time, end_time).Scan(&total).Error; err != nil {
|