|
@@ -520,7 +520,7 @@ func GetInspectionProjectCount(orgid int64, startime int64, endtime int64) (proj
|
520
|
520
|
db = db.Where("x.inspect_date <=?", endtime)
|
521
|
521
|
}
|
522
|
522
|
|
523
|
|
- err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Group("project_id,patient_id").Scan(&projectCounts).Error
|
|
523
|
+ err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,t.sort").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Group("project_id,patient_id").Scan(&projectCounts).Error
|
524
|
524
|
return
|
525
|
525
|
}
|
526
|
526
|
|
|
@@ -610,3 +610,473 @@ func GetPatientListData(orgid int64, startime int64, endtime int64, limit int64,
|
610
|
610
|
err = db.Group("x.patient_id").Select("x.id,x.patient_id,x.project_id,x.project_name,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Count(&total).Offset(offset).Limit(limit).Scan(&inspection).Error
|
611
|
611
|
return inspection, total, err
|
612
|
612
|
}
|
|
613
|
+
|
|
614
|
+func GetPatientListInfo(orgid int64, startime int64, endtime int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
|
|
615
|
+
|
|
616
|
+ db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
|
|
617
|
+ table := XTReadDB().Table("xt_inspection_reference as r")
|
|
618
|
+ fmt.Println(table)
|
|
619
|
+ d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
|
|
620
|
+ pa := XTReadDB().Table("xt_patients as s")
|
|
621
|
+ fmt.Println(pa)
|
|
622
|
+ fmt.Println(d)
|
|
623
|
+ if orgid > 0 {
|
|
624
|
+ db = db.Where("x.org_id = ?", orgid)
|
|
625
|
+ }
|
|
626
|
+ if startime > 0 {
|
|
627
|
+ db = db.Where("x.inspect_date >=?", startime)
|
|
628
|
+ }
|
|
629
|
+ if endtime > 0 {
|
|
630
|
+ db = db.Where("x.inspect_date <=?", endtime)
|
|
631
|
+ }
|
|
632
|
+
|
|
633
|
+ err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,s.name").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Joins("left join xt_patients as s on s.id = x.patient_id").Group("project_id,patient_id").Scan(&projectCounts).Error
|
|
634
|
+ return
|
|
635
|
+}
|
|
636
|
+
|
|
637
|
+func GetPatientDetailCheck(id int64, orgid int64, startime int64, endtime int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
|
|
638
|
+
|
|
639
|
+ db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
|
|
640
|
+ table := XTReadDB().Table("xt_inspection_reference as r")
|
|
641
|
+ fmt.Println(table)
|
|
642
|
+ d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
|
|
643
|
+ pa := XTReadDB().Table("xt_patients as s")
|
|
644
|
+ fmt.Println(pa)
|
|
645
|
+ fmt.Println(d)
|
|
646
|
+ if id > 0 {
|
|
647
|
+ db = db.Where("s.id = ?", id)
|
|
648
|
+ }
|
|
649
|
+ if orgid > 0 {
|
|
650
|
+ db = db.Where("x.org_id = ?", orgid)
|
|
651
|
+ }
|
|
652
|
+ if startime > 0 {
|
|
653
|
+ db = db.Where("x.inspect_date >=?", startime)
|
|
654
|
+ }
|
|
655
|
+ if endtime > 0 {
|
|
656
|
+ db = db.Where("x.inspect_date <=?", endtime)
|
|
657
|
+ }
|
|
658
|
+
|
|
659
|
+ err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,s.name").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Joins("left join xt_patients as s on s.id = x.patient_id").Group("project_id,patient_id").Scan(&projectCounts).Error
|
|
660
|
+ return
|
|
661
|
+}
|
|
662
|
+
|
|
663
|
+func GetSearchDetailCheck(orgid int64, keywords string, startime int64, endtime int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
|
|
664
|
+ db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
|
|
665
|
+ table := XTReadDB().Table("xt_inspection_reference as r")
|
|
666
|
+ fmt.Println(table)
|
|
667
|
+ d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
|
|
668
|
+ pa := XTReadDB().Table("xt_patients as s")
|
|
669
|
+ fmt.Println(pa)
|
|
670
|
+ fmt.Println(d)
|
|
671
|
+ if len(keywords) > 0 {
|
|
672
|
+ likeKey := "%" + keywords + "%"
|
|
673
|
+ db = db.Where("s.name LIKE ? OR s.dialysis_no LIKE ?", likeKey, likeKey)
|
|
674
|
+ }
|
|
675
|
+ if orgid > 0 {
|
|
676
|
+ db = db.Where("x.org_id = ?", orgid)
|
|
677
|
+ }
|
|
678
|
+ if startime > 0 {
|
|
679
|
+ db = db.Where("x.inspect_date >=?", startime)
|
|
680
|
+ }
|
|
681
|
+ if endtime > 0 {
|
|
682
|
+ db = db.Where("x.inspect_date <=?", endtime)
|
|
683
|
+ }
|
|
684
|
+
|
|
685
|
+ err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,s.name").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Joins("left join xt_patients as s on s.id = x.patient_id").Group("project_id,patient_id").Scan(&projectCounts).Error
|
|
686
|
+ return
|
|
687
|
+}
|
|
688
|
+
|
|
689
|
+func GetNormDataByOrgId(orgid int64) (standard []*models.QualityControlStandard, err error) {
|
|
690
|
+
|
|
691
|
+ db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
|
|
692
|
+ if orgid > 0 {
|
|
693
|
+ db = db.Where("x.user_org_id = ?", orgid)
|
|
694
|
+ }
|
|
695
|
+ table := XTReadDB().Table("xt_inspection_reference as s")
|
|
696
|
+ fmt.Println(table)
|
|
697
|
+
|
|
698
|
+ err = db.Order("x.sort asc,x.created_time desc").Group("x.id").Select("x.id,x.inspection_major,x.inspection_minor,x.min_range,x.large_range,x.sort,x.user_org_id,s.unit,s.project_name,s.item_name").
|
|
699
|
+ Joins("left join xt_inspection_reference as s on s.id = x.inspection_minor").Scan(&standard).Error
|
|
700
|
+ return standard, err
|
|
701
|
+}
|
|
702
|
+
|
|
703
|
+func GetNormData(orgid int64) (standard []*models.QualityControlStandard, err error) {
|
|
704
|
+
|
|
705
|
+ db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
|
|
706
|
+ if orgid > 0 {
|
|
707
|
+ db = db.Where("x.user_org_id = ?", orgid)
|
|
708
|
+ }
|
|
709
|
+ table := XTReadDB().Table("xt_inspection_reference as s")
|
|
710
|
+ fmt.Println(table)
|
|
711
|
+
|
|
712
|
+ err = db.Order("x.sort asc,x.created_time desc").Group("x.id").Select("x.id,x.inspection_major,x.inspection_minor,x.min_range,x.large_range,x.sort,x.user_org_id,s.unit,s.project_name,s.item_name").
|
|
713
|
+ Joins("left join xt_inspection_reference as s on s.id = x.inspection_minor").Scan(&standard).Error
|
|
714
|
+ return standard, err
|
|
715
|
+}
|
|
716
|
+
|
|
717
|
+func GetItemNameGroup(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientInspection, err error) {
|
|
718
|
+ db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
|
|
719
|
+ table := XTReadDB().Table("xt_inspection_reference as r")
|
|
720
|
+ fmt.Println(table)
|
|
721
|
+ if orgid > 0 {
|
|
722
|
+ db = db.Where("x.org_id = ?", orgid)
|
|
723
|
+ }
|
|
724
|
+ if startime > 0 {
|
|
725
|
+ db = db.Where("x.inspect_date >=?", startime)
|
|
726
|
+ }
|
|
727
|
+ if endtime > 0 {
|
|
728
|
+ db = db.Where("x.inspect_date <=?", endtime)
|
|
729
|
+ }
|
|
730
|
+ err = db.Group("x.item_id").Select(" count(x.item_id ) AS count,x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,r.range_min,r.range_max").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Scan(&inspection).Error
|
|
731
|
+ return inspection, err
|
|
732
|
+}
|
|
733
|
+
|
|
734
|
+func GetFirstQuarter(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientInspection, err error) {
|
|
735
|
+
|
|
736
|
+ db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
|
|
737
|
+ table := XTReadDB().Table("xt_inspection_reference as r")
|
|
738
|
+ fmt.Println(table)
|
|
739
|
+ if orgid > 0 {
|
|
740
|
+ db = db.Where("x.org_id = ?", orgid)
|
|
741
|
+ }
|
|
742
|
+ if startime > 0 {
|
|
743
|
+ db = db.Where("x.inspect_date >=?", startime)
|
|
744
|
+ }
|
|
745
|
+ if endtime > 0 {
|
|
746
|
+ db = db.Where("x.inspect_date <=?", endtime)
|
|
747
|
+ }
|
|
748
|
+ err = db.Group("x.item_id").Select("count(x.item_id) as count,x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,r.range_min,r.range_max").Where("x.inspect_value+0 >= r.range_min+0 and x.inspect_value+0 <= r.range_max+0").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Scan(&inspection).Error
|
|
749
|
+ return inspection, err
|
|
750
|
+}
|
|
751
|
+
|
|
752
|
+func GetQuarterTotalCount(orgid int64, startime int64, endtime int64, lapseto int64) (inspection []*models.VmPatientInspection, err error) {
|
|
753
|
+
|
|
754
|
+ db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
|
|
755
|
+ table := XTReadDB().Table("xt_inspection_reference as r")
|
|
756
|
+ fmt.Println(table)
|
|
757
|
+ d := XTReadDB().Table("xt_patients as s")
|
|
758
|
+ fmt.Println(d)
|
|
759
|
+ d2 := XTReadDB().Table("xt_quality_control_standard as p")
|
|
760
|
+ fmt.Println(d2)
|
|
761
|
+ if orgid > 0 {
|
|
762
|
+ db = db.Where("x.org_id = ?", orgid)
|
|
763
|
+ }
|
|
764
|
+ if startime > 0 {
|
|
765
|
+ db = db.Where("x.inspect_date >=?", startime)
|
|
766
|
+ }
|
|
767
|
+ if endtime > 0 {
|
|
768
|
+ db = db.Where("x.inspect_date <=?", endtime)
|
|
769
|
+ }
|
|
770
|
+ if lapseto > 0 {
|
|
771
|
+ d = d.Where("s.lapseto = ?", lapseto)
|
|
772
|
+ }
|
|
773
|
+ err = db.Group("x.item_id").Select("sum(case when x.inspect_date >=? and x.inspect_date<=? then 1 else 0 end) as total,sum(case when x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 and x.inspect_date >=? and x.inspect_date <=? then 1 else 0 end) as count,x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_value,x.inspect_date,r.range_min,r.range_max,p.sort", startime, endtime, startime, endtime).Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_quality_control_standard as p on p.inspection_minor = x.item_id").Order("p.sort asc").Scan(&inspection).Error
|
|
774
|
+ return inspection, err
|
|
775
|
+}
|
|
776
|
+
|
|
777
|
+func GetProjectList(orgid int64, lapseto int64, modetype int64, startime int64, endtime int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCountOne, err error) {
|
|
778
|
+
|
|
779
|
+ if lapseto == 0 {
|
|
780
|
+ d := XTReadDB().Table("xt_patients as s")
|
|
781
|
+ fmt.Println("d", d)
|
|
782
|
+ db := readDb.Table("xt_inspection as x ").Where("x.status=1")
|
|
783
|
+
|
|
784
|
+ countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
|
|
785
|
+ "SELECT " +
|
|
786
|
+ "CASE " +
|
|
787
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
|
|
788
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
|
|
789
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
|
|
790
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
|
|
791
|
+ " ELSE '其他'" +
|
|
792
|
+ "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2)"
|
|
793
|
+ countParams := make([]interface{}, 0)
|
|
794
|
+ countParams = append(countParams, firststart)
|
|
795
|
+ countParams = append(countParams, firstend)
|
|
796
|
+ countParams = append(countParams, sencondstart)
|
|
797
|
+ countParams = append(countParams, sencondend)
|
|
798
|
+ countParams = append(countParams, threestart)
|
|
799
|
+ countParams = append(countParams, threeend)
|
|
800
|
+ countParams = append(countParams, fourstart)
|
|
801
|
+ countParams = append(countParams, fourend)
|
|
802
|
+ if orgid > 0 {
|
|
803
|
+ db = db.Where("x.org_id=?", orgid)
|
|
804
|
+ countSQL += " AND x.org_id=?"
|
|
805
|
+ countParams = append(countParams, orgid)
|
|
806
|
+
|
|
807
|
+ }
|
|
808
|
+ if modetype > 0 {
|
|
809
|
+ db = db.Where("x.item_id = ?", modetype)
|
|
810
|
+ countSQL += " AND x.item_id=?"
|
|
811
|
+ countParams = append(countParams, modetype)
|
|
812
|
+ }
|
|
813
|
+ if startime > 0 {
|
|
814
|
+ db = db.Where("x.inspect_date >= ?", startime)
|
|
815
|
+ countSQL += " AND x.inspect_date >=?"
|
|
816
|
+ countParams = append(countParams, startime)
|
|
817
|
+ }
|
|
818
|
+ if endtime > 0 {
|
|
819
|
+ db = db.Where("x.inspect_date <= ?", endtime)
|
|
820
|
+ countSQL += " AND x.inspect_date <=?"
|
|
821
|
+ countParams = append(countParams, endtime)
|
|
822
|
+ }
|
|
823
|
+ countSQL += ")a GROUP BY nnd"
|
|
824
|
+ err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
|
|
825
|
+ }
|
|
826
|
+
|
|
827
|
+ if lapseto == 1 {
|
|
828
|
+ d := XTReadDB().Table("xt_patients as s")
|
|
829
|
+ fmt.Println("d", d)
|
|
830
|
+ db := readDb.Table("xt_inspection as x ").Where("x.status=1")
|
|
831
|
+
|
|
832
|
+ countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
|
|
833
|
+ "SELECT " +
|
|
834
|
+ "CASE " +
|
|
835
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
|
|
836
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
|
|
837
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
|
|
838
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
|
|
839
|
+ "ELSE '其他'" +
|
|
840
|
+ "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1)"
|
|
841
|
+ countParams := make([]interface{}, 0)
|
|
842
|
+ countParams = append(countParams, firststart)
|
|
843
|
+ countParams = append(countParams, firstend)
|
|
844
|
+ countParams = append(countParams, sencondstart)
|
|
845
|
+ countParams = append(countParams, sencondend)
|
|
846
|
+ countParams = append(countParams, threestart)
|
|
847
|
+ countParams = append(countParams, threeend)
|
|
848
|
+ countParams = append(countParams, fourstart)
|
|
849
|
+ countParams = append(countParams, fourend)
|
|
850
|
+ if orgid > 0 {
|
|
851
|
+ db = db.Where("x.org_id=?", orgid)
|
|
852
|
+ countSQL += " AND x.org_id=?"
|
|
853
|
+ countParams = append(countParams, orgid)
|
|
854
|
+
|
|
855
|
+ }
|
|
856
|
+ if modetype > 0 {
|
|
857
|
+ db = db.Where("x.item_id = ?", modetype)
|
|
858
|
+ countSQL += " AND x.item_id=?"
|
|
859
|
+ countParams = append(countParams, modetype)
|
|
860
|
+ }
|
|
861
|
+
|
|
862
|
+ if startime > 0 {
|
|
863
|
+ db = db.Where("x.inspect_date >= ?", startime)
|
|
864
|
+ countSQL += " AND x.inspect_date >=?"
|
|
865
|
+ countParams = append(countParams, startime)
|
|
866
|
+ }
|
|
867
|
+ if endtime > 0 {
|
|
868
|
+ db = db.Where("x.inspect_date <= ?", endtime)
|
|
869
|
+ countSQL += " AND x.inspect_date <=?"
|
|
870
|
+ countParams = append(countParams, endtime)
|
|
871
|
+ }
|
|
872
|
+
|
|
873
|
+ countSQL += ")a GROUP BY nnd"
|
|
874
|
+ err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
|
|
875
|
+ }
|
|
876
|
+
|
|
877
|
+ if lapseto == 2 {
|
|
878
|
+ d := XTReadDB().Table("xt_patients as s")
|
|
879
|
+ fmt.Println("d", d)
|
|
880
|
+ db := readDb.Table("xt_inspection as x ").Where("x.status=1")
|
|
881
|
+
|
|
882
|
+ countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
|
|
883
|
+ "SELECT " +
|
|
884
|
+ "CASE " +
|
|
885
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
|
|
886
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
|
|
887
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
|
|
888
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
|
|
889
|
+ " ELSE '其他'" +
|
|
890
|
+ "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2)"
|
|
891
|
+ countParams := make([]interface{}, 0)
|
|
892
|
+ countParams = append(countParams, firststart)
|
|
893
|
+ countParams = append(countParams, firstend)
|
|
894
|
+ countParams = append(countParams, sencondstart)
|
|
895
|
+ countParams = append(countParams, sencondend)
|
|
896
|
+ countParams = append(countParams, threestart)
|
|
897
|
+ countParams = append(countParams, threeend)
|
|
898
|
+ countParams = append(countParams, fourstart)
|
|
899
|
+ countParams = append(countParams, fourend)
|
|
900
|
+ if orgid > 0 {
|
|
901
|
+ db = db.Where("x.org_id=?", orgid)
|
|
902
|
+ countSQL += " AND x.org_id=?"
|
|
903
|
+ countParams = append(countParams, orgid)
|
|
904
|
+
|
|
905
|
+ }
|
|
906
|
+ if modetype > 0 {
|
|
907
|
+ db = db.Where("x.item_id = ?", modetype)
|
|
908
|
+ countSQL += " AND x.item_id=?"
|
|
909
|
+ countParams = append(countParams, modetype)
|
|
910
|
+ }
|
|
911
|
+
|
|
912
|
+ if startime > 0 {
|
|
913
|
+ db = db.Where("x.inspect_date >= ?", startime)
|
|
914
|
+ countSQL += " AND x.inspect_date >=?"
|
|
915
|
+ countParams = append(countParams, startime)
|
|
916
|
+ }
|
|
917
|
+ if endtime > 0 {
|
|
918
|
+ db = db.Where("x.inspect_date <= ?", endtime)
|
|
919
|
+ countSQL += " AND x.inspect_date <=?"
|
|
920
|
+ countParams = append(countParams, endtime)
|
|
921
|
+ }
|
|
922
|
+
|
|
923
|
+ countSQL += ")a GROUP BY nnd"
|
|
924
|
+ err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
|
|
925
|
+
|
|
926
|
+ }
|
|
927
|
+ return
|
|
928
|
+}
|
|
929
|
+
|
|
930
|
+func GetProjectStandList(orgid int64, lapseto int64, modetype int64, startime int64, endtime int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCount, err error) {
|
|
931
|
+
|
|
932
|
+ if lapseto == 0 {
|
|
933
|
+ d := XTReadDB().Table("xt_patients as s")
|
|
934
|
+ fmt.Println("d", d)
|
|
935
|
+ db := readDb.Table("xt_inspection as x ").Where("x.status=1")
|
|
936
|
+ table := XTReadDB().Table("xt_inspection_reference as r")
|
|
937
|
+ fmt.Println(table)
|
|
938
|
+ countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
|
|
939
|
+ "SELECT " +
|
|
940
|
+ "CASE " +
|
|
941
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第一季度'" +
|
|
942
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第二季度'" +
|
|
943
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第三季度'" +
|
|
944
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第四季度'" +
|
|
945
|
+ " ELSE '其他'" +
|
|
946
|
+ "END AS nnd FROM xt_inspection as x left join xt_inspection_reference as r on r.id = x.item_id left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2) and (x.inspect_value + 0 >= r.range_min + 0 AND x.inspect_value + 0 <= r.range_max + 0)"
|
|
947
|
+ countParams := make([]interface{}, 0)
|
|
948
|
+ countParams = append(countParams, firststart)
|
|
949
|
+ countParams = append(countParams, firstend)
|
|
950
|
+ countParams = append(countParams, sencondstart)
|
|
951
|
+ countParams = append(countParams, sencondend)
|
|
952
|
+ countParams = append(countParams, threestart)
|
|
953
|
+ countParams = append(countParams, threeend)
|
|
954
|
+ countParams = append(countParams, fourstart)
|
|
955
|
+ countParams = append(countParams, fourend)
|
|
956
|
+ if orgid > 0 {
|
|
957
|
+ db = db.Where("x.org_id=?", orgid)
|
|
958
|
+ countSQL += " AND x.org_id=?"
|
|
959
|
+ countParams = append(countParams, orgid)
|
|
960
|
+
|
|
961
|
+ }
|
|
962
|
+ if modetype > 0 {
|
|
963
|
+ db = db.Where("x.item_id = ?", modetype)
|
|
964
|
+ countSQL += " AND x.item_id=?"
|
|
965
|
+ countParams = append(countParams, modetype)
|
|
966
|
+ }
|
|
967
|
+ if startime > 0 {
|
|
968
|
+ db = db.Where("x.inspect_date >= ? ", startime)
|
|
969
|
+ countSQL += " AND x.inspect_date >=?"
|
|
970
|
+ countParams = append(countParams, startime)
|
|
971
|
+ }
|
|
972
|
+ if endtime > 0 {
|
|
973
|
+ db = db.Where("x.inspect_date <= ?", endtime)
|
|
974
|
+ countSQL += " AND x.inspect_date <=?"
|
|
975
|
+ countParams = append(countParams, endtime)
|
|
976
|
+ }
|
|
977
|
+
|
|
978
|
+ countSQL += ")a GROUP BY nnd"
|
|
979
|
+ err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
|
|
980
|
+ }
|
|
981
|
+
|
|
982
|
+ if lapseto == 1 {
|
|
983
|
+ d := XTReadDB().Table("xt_patients as s")
|
|
984
|
+ fmt.Println("d", d)
|
|
985
|
+ db := readDb.Table("xt_inspection as x ").Where("x.status=1")
|
|
986
|
+ table := XTReadDB().Table("xt_inspection_reference as r")
|
|
987
|
+ fmt.Println(table)
|
|
988
|
+ countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
|
|
989
|
+ "SELECT " +
|
|
990
|
+ "CASE " +
|
|
991
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第一季度'" +
|
|
992
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第二季度'" +
|
|
993
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第三季度'" +
|
|
994
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第四季度'" +
|
|
995
|
+ " ELSE '其他'" +
|
|
996
|
+ "END AS nnd FROM xt_inspection as x left join xt_inspection_reference as r on r.id = x.item_id left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1) and (x.inspect_value + 0 >= r.range_min + 0 AND x.inspect_value + 0 <= r.range_max + 0)"
|
|
997
|
+ countParams := make([]interface{}, 0)
|
|
998
|
+ countParams = append(countParams, firststart)
|
|
999
|
+ countParams = append(countParams, firstend)
|
|
1000
|
+ countParams = append(countParams, sencondstart)
|
|
1001
|
+ countParams = append(countParams, sencondend)
|
|
1002
|
+ countParams = append(countParams, threestart)
|
|
1003
|
+ countParams = append(countParams, threeend)
|
|
1004
|
+ countParams = append(countParams, fourstart)
|
|
1005
|
+ countParams = append(countParams, fourend)
|
|
1006
|
+ if orgid > 0 {
|
|
1007
|
+ db = db.Where("x.org_id=?", orgid)
|
|
1008
|
+ countSQL += " AND x.org_id=?"
|
|
1009
|
+ countParams = append(countParams, orgid)
|
|
1010
|
+
|
|
1011
|
+ }
|
|
1012
|
+ if modetype > 0 {
|
|
1013
|
+ db = db.Where("x.item_id = ?", modetype)
|
|
1014
|
+ countSQL += " AND x.item_id=?"
|
|
1015
|
+ countParams = append(countParams, modetype)
|
|
1016
|
+ }
|
|
1017
|
+ if startime > 0 {
|
|
1018
|
+ db = db.Where("x.inspect_date >= ? ", startime)
|
|
1019
|
+ countSQL += " AND x.inspect_date >=?"
|
|
1020
|
+ countParams = append(countParams, startime)
|
|
1021
|
+ }
|
|
1022
|
+ if endtime > 0 {
|
|
1023
|
+ db = db.Where("x.inspect_date <= ?", endtime)
|
|
1024
|
+ countSQL += " AND x.inspect_date <=?"
|
|
1025
|
+ countParams = append(countParams, endtime)
|
|
1026
|
+ }
|
|
1027
|
+
|
|
1028
|
+ countSQL += ")a GROUP BY nnd"
|
|
1029
|
+ err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
|
|
1030
|
+ }
|
|
1031
|
+
|
|
1032
|
+ if lapseto == 2 {
|
|
1033
|
+ d := XTReadDB().Table("xt_patients as s")
|
|
1034
|
+ fmt.Println("d", d)
|
|
1035
|
+ db := readDb.Table("xt_inspection as x ").Where("x.status=1")
|
|
1036
|
+ table := XTReadDB().Table("xt_inspection_reference as r")
|
|
1037
|
+ fmt.Println(table)
|
|
1038
|
+ countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
|
|
1039
|
+ "SELECT " +
|
|
1040
|
+ "CASE " +
|
|
1041
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第一季度'" +
|
|
1042
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第二季度'" +
|
|
1043
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第三季度'" +
|
|
1044
|
+ " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第四季度'" +
|
|
1045
|
+ " ELSE '其他'" +
|
|
1046
|
+ "END AS nnd FROM xt_inspection as x left join xt_inspection_reference as r on r.id = x.item_id left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2) and (x.inspect_value + 0 >= r.range_min + 0 AND x.inspect_value + 0 <= r.range_max + 0)"
|
|
1047
|
+ countParams := make([]interface{}, 0)
|
|
1048
|
+ countParams = append(countParams, firststart)
|
|
1049
|
+ countParams = append(countParams, firstend)
|
|
1050
|
+ countParams = append(countParams, sencondstart)
|
|
1051
|
+ countParams = append(countParams, sencondend)
|
|
1052
|
+ countParams = append(countParams, threestart)
|
|
1053
|
+ countParams = append(countParams, threeend)
|
|
1054
|
+ countParams = append(countParams, fourstart)
|
|
1055
|
+ countParams = append(countParams, fourend)
|
|
1056
|
+ if orgid > 0 {
|
|
1057
|
+ db = db.Where("x.org_id=?", orgid)
|
|
1058
|
+ countSQL += " AND x.org_id=?"
|
|
1059
|
+ countParams = append(countParams, orgid)
|
|
1060
|
+
|
|
1061
|
+ }
|
|
1062
|
+ if modetype > 0 {
|
|
1063
|
+ db = db.Where("x.item_id = ?", modetype)
|
|
1064
|
+ countSQL += " AND x.item_id=?"
|
|
1065
|
+ countParams = append(countParams, modetype)
|
|
1066
|
+ }
|
|
1067
|
+ if startime > 0 {
|
|
1068
|
+ db = db.Where("x.inspect_date >= ? ", startime)
|
|
1069
|
+ countSQL += " AND x.inspect_date >=?"
|
|
1070
|
+ countParams = append(countParams, startime)
|
|
1071
|
+ }
|
|
1072
|
+ if endtime > 0 {
|
|
1073
|
+ db = db.Where("x.inspect_date <= ?", endtime)
|
|
1074
|
+ countSQL += " AND x.inspect_date <=?"
|
|
1075
|
+ countParams = append(countParams, endtime)
|
|
1076
|
+ }
|
|
1077
|
+
|
|
1078
|
+ countSQL += ")a GROUP BY nnd"
|
|
1079
|
+ err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
|
|
1080
|
+ }
|
|
1081
|
+ return
|
|
1082
|
+}
|