index_evaluation_service.go 98KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989
  1. package statistics_service
  2. import (
  3. "XT_New/models"
  4. "XT_New/service"
  5. "fmt"
  6. "github.com/jinzhu/gorm"
  7. "math"
  8. "strconv"
  9. "strings"
  10. )
  11. func GetOrgFirstPatientInfo(user_org_id int64) (patient *models.Patients, err error) {
  12. db := service.XTReadDB()
  13. var tempPatient models.Patients
  14. findErr := db.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND lapseto = 1", user_org_id).Last(&tempPatient).Error
  15. if findErr == gorm.ErrRecordNotFound {
  16. return nil, nil
  17. }
  18. if findErr != nil {
  19. return nil, findErr
  20. }
  21. return &tempPatient, nil
  22. }
  23. type ProcessIndexDataStruct struct {
  24. Date string `json:"date"`
  25. Value float64 `json:"value"`
  26. }
  27. // 透析过程统计
  28. func GetDialysisProcessIndexChartData(user_org_id int64, patient_id int64, start_time int64, end_time int64, statistics_type int) (datas []*ProcessIndexDataStruct, err error) {
  29. db := service.XTReadDB()
  30. switch statistics_type {
  31. case 1:
  32. err = db.Raw("select from_unixtime(assessment_date,'%Y-%m-%d') as date, weight_before as value from xt_assessment_before_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND assessment_date <= ? AND assessment_date >= ? ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  33. break
  34. case 2:
  35. err = db.Raw("select from_unixtime(assessment_date,'%Y-%m-%d') as date, weight_after as value from xt_assessment_after_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND assessment_date <= ? AND assessment_date >= ? ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  36. break
  37. case 3:
  38. err = db.Raw("select from_unixtime(assessment_date,'%Y-%m-%d') as date, systolic_blood_pressure as value from xt_assessment_before_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND assessment_date <= ? AND assessment_date >= ? AND systolic_blood_pressure <> 0 ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  39. break
  40. case 4:
  41. err = db.Raw("select from_unixtime(assessment_date,'%Y-%m-%d') as date, diastolic_blood_pressure as value from xt_assessment_before_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND assessment_date <= ? AND assessment_date >= ? AND diastolic_blood_pressure <> 0", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  42. break
  43. case 5:
  44. err = db.Raw("select from_unixtime(assessment_date,'%Y-%m-%d') as date, pulse_frequency as value from xt_assessment_before_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND assessment_date <= ? AND assessment_date >= ? ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  45. break
  46. case 6:
  47. err = db.Raw("select from_unixtime(assessment_date,'%Y-%m-%d') as date, systolic_blood_pressure as value from xt_assessment_after_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND assessment_date <= ? AND assessment_date >= ? AND systolic_blood_pressure <> 0", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  48. break
  49. case 7:
  50. err = db.Raw("select from_unixtime(assessment_date,'%Y-%m-%d') as date, diastolic_blood_pressure as value from xt_assessment_after_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND assessment_date <= ? AND assessment_date >= ? AND diastolic_blood_pressure <> 0 ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  51. break
  52. case 8:
  53. err = db.Raw("select from_unixtime(assessment_date,'%Y-%m-%d') as date, pulse_frequency as value from xt_assessment_after_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND assessment_date <= ? AND assessment_date >= ? ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  54. break
  55. }
  56. if err != nil {
  57. return nil, err
  58. }
  59. return datas, nil
  60. }
  61. type otherItemAmount struct {
  62. Total int64 `json:"total"`
  63. Name string `json:"name"`
  64. Ratio string `json:"ratio"`
  65. }
  66. func GetDialysisProcessIndexOtherChartData(user_org_id int64, patient_id int64, start_time int64, end_time int64, statistics_type int) (item []*otherItemAmount, err error) {
  67. db := service.XTReadDB()
  68. var items []*otherItemAmount
  69. var tempErr error
  70. var total int64
  71. switch statistics_type {
  72. case 9:
  73. tempErr = db.Table("xt_dialysis_prescription as p").Where("p.user_org_id=? and p.status=1 and p.record_date >= ? and p.record_date <= ? AND p.patient_id = ? ", user_org_id, start_time, end_time, patient_id).
  74. Select("CASE WHEN p.mode_id = 1 THEN 'HD'" +
  75. " WHEN p.mode_id = 2 THEN 'HDF'" +
  76. " WHEN p.mode_id = 3 THEN 'HD+HP'" +
  77. " WHEN p.mode_id = 4 THEN 'HP'" +
  78. " WHEN p.mode_id = 5 THEN 'HF'" +
  79. " WHEN p.mode_id = 6 THEN 'SCUF'" +
  80. " WHEN p.mode_id = 7 THEN 'IUF'" +
  81. " WHEN p.mode_id = 8 THEN 'HFHD'" +
  82. " WHEN p.mode_id = 9 THEN 'HFHD+HP'" +
  83. " WHEN p.mode_id = 10 THEN 'PHF'" +
  84. " WHEN p.mode_id = 11 THEN 'HFR'" +
  85. " WHEN p.mode_id = 12 THEN 'HDF+HP'" +
  86. " WHEN p.mode_id = 13 THEN 'CRRT'" +
  87. " WHEN p.mode_id = 14 THEN '腹水回输'" +
  88. " WHEN p.mode_id = 19 THEN 'IUF+HD'" +
  89. " ELSE '未知' END AS name, COUNT(*) AS total",
  90. ).Group("p.mode_id").Scan(&items).Error
  91. break
  92. case 10:
  93. tempErr = db.Table("xt_dialysis_prescription as p").Where("p.user_org_id=? and p.status=1 and p.record_date >= ? and p.record_date <= ? AND p.patient_id = ? ", user_org_id, start_time, end_time, patient_id).
  94. Select("CASE WHEN p.anticoagulant = 1 THEN '无肝素'" +
  95. " WHEN p.anticoagulant = 2 THEN '普通肝素'" +
  96. " WHEN p.anticoagulant = 3 THEN '低分子肝素'" +
  97. " WHEN p.anticoagulant = 4 THEN '阿加曲班'" +
  98. " WHEN p.anticoagulant = 5 THEN '枸橼酸钠'" +
  99. " WHEN p.anticoagulant = 6 THEN '低分子肝素钙'" +
  100. " WHEN p.anticoagulant = 7 THEN '低分子肝素钠'" +
  101. " ELSE '未知' END AS name, COUNT(*) AS total",
  102. ).Group("p.anticoagulant").Scan(&items).Error
  103. break
  104. }
  105. db.Table("xt_dialysis_prescription as p").Where("p.user_org_id=? AND p.status = 1 AND p.patient_id = ? AND p.record_date >= ? and p.record_date <= ? ", user_org_id, patient_id, start_time, end_time).Count(&total)
  106. for _, item := range items {
  107. if math.IsNaN(float64(item.Total) / float64(total)) {
  108. item.Ratio = "0.0"
  109. } else {
  110. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(total))*100), 64)
  111. item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
  112. }
  113. }
  114. if tempErr != nil {
  115. return nil, err
  116. }
  117. return items, nil
  118. }
  119. type PatientDialysisRecord struct {
  120. models.VMSchedule
  121. DeviceNumber VMDeviceNumber `gorm:"foreignkey:ID;AssociationForeignKey:BedId;" json:"device_number"`
  122. DialysisPrescription VMDialysisPrescription `json:"prescription" gorm:"foreignkey:RecordDate;AssociationForeignKey:ScheduleDate;"`
  123. PredialysisEvaluation VMPredialysisEvaluation `json:"predialysis_evaluation" gorm:"foreignkey:AssessmentDate;AssociationForeignKey:ScheduleDate;"`
  124. AssessmentAfterDislysis models.AssessmentAfterDislysis `json:"assessment_after_dislysis" gorm:"foreignkey:AssessmentDate;AssociationForeignKey:ScheduleDate;"`
  125. Patient VMPatients `json:"patient" gorm:"foreignkey:ID;AssociationForeignKey:PatientID;"`
  126. }
  127. func GetDialysisProcessIndexTableData(orgID, patientID int64, page, limit, start, end int64) ([]*PatientDialysisRecord, int64, error) {
  128. offset := (page - 1) * limit
  129. var total int64
  130. var err error
  131. var orders []*PatientDialysisRecord
  132. readDb := service.XTReadDB()
  133. db := readDb.Table("xt_schedule as sch").
  134. Preload("DeviceNumber", "org_id=? and status=1", orgID).
  135. Preload("DialysisPrescription", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  136. Preload("PredialysisEvaluation", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  137. Preload("AssessmentAfterDislysis", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  138. Preload("Patient", "user_org_id=? and status=1", orgID).
  139. Where("sch.patient_id=? and sch.user_org_id=? and sch.status=1", patientID, orgID).Group("sch.schedule_date")
  140. if start != 0 {
  141. db = db.Where("sch.schedule_date>=?", start)
  142. }
  143. if end != 0 {
  144. db = db.Where("sch.schedule_date<=?", end)
  145. }
  146. err = db.Count(&total).Offset(offset).Limit(limit).Order("sch.schedule_date desc").Select("sch.patient_id,sch.schedule_date,sch.bed_id,sch.user_org_id").Find(&orders).Error
  147. return orders, total, err
  148. }
  149. func GetAnticoagulantData(user_org_id int64) (config []*models.Dataconfig, tempErr error) {
  150. var tempDataConfig []*models.Dataconfig
  151. var tempConfig models.Dataconfig
  152. db := service.XTReadDB()
  153. db.Model(&models.Dataconfig{}).Where("name = '抗凝剂' AND field_name = 'anticoagulant' AND parent_id = 0").First(&tempConfig)
  154. err := db.Model(&models.Dataconfig{}).Where("(org_id = 0 OR org_id = ?) AND parent_id = ?", user_org_id, tempConfig.ID).Find(&tempDataConfig).Error
  155. return tempDataConfig, err
  156. }
  157. //透析过程统计
  158. // 透析监测统计
  159. func GetDialysisWatchChartData(user_org_id int64, patient_id int64, start_time int64, end_time int64, statistics_type int) (datas []*ProcessIndexDataStruct, err error) {
  160. db := service.XTReadDB()
  161. switch statistics_type {
  162. case 1:
  163. if patient_id == 0 {
  164. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.systolic_blood_pressure as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? AND systolic_blood_pressure <> 0 Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
  165. } else {
  166. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.systolic_blood_pressure as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ? AND systolic_blood_pressure <> 0 Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  167. }
  168. break
  169. case 2:
  170. if patient_id == 0 {
  171. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.diastolic_blood_pressure as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? AND diastolic_blood_pressure <> 0 Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
  172. } else {
  173. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.diastolic_blood_pressure as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ? AND diastolic_blood_pressure <> 0 Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  174. }
  175. break
  176. case 3:
  177. if patient_id == 0 {
  178. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.pulse_frequency as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
  179. } else {
  180. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.pulse_frequency as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  181. }
  182. break
  183. case 4:
  184. if patient_id == 0 {
  185. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.breathing_rate as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
  186. } else {
  187. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.breathing_rate as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  188. }
  189. break
  190. case 5:
  191. if patient_id == 0 {
  192. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.temperature as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
  193. } else {
  194. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.temperature as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ?Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  195. }
  196. break
  197. case 6:
  198. if patient_id == 0 {
  199. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.blood_flow_volume as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
  200. } else {
  201. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.blood_flow_volume as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  202. }
  203. break
  204. case 7:
  205. if patient_id == 0 {
  206. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.venous_pressure as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
  207. } else {
  208. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.venous_pressure as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  209. }
  210. break
  211. case 8:
  212. if patient_id == 0 {
  213. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.arterial_pressure as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
  214. } else {
  215. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.arterial_pressure as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  216. }
  217. break
  218. case 9:
  219. if patient_id == 0 {
  220. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.transmembrane_pressure as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
  221. } else {
  222. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.transmembrane_pressure as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  223. }
  224. break
  225. case 10:
  226. if patient_id == 0 {
  227. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.dialysate_temperature as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
  228. } else {
  229. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.dialysate_temperature as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  230. }
  231. break
  232. case 11:
  233. if patient_id == 0 {
  234. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.ultrafiltration_rate as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
  235. } else {
  236. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.ultrafiltration_rate as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  237. }
  238. break
  239. case 12:
  240. if patient_id == 0 {
  241. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.ultrafiltration_volume as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
  242. } else {
  243. err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.ultrafiltration_volume as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  244. }
  245. break
  246. }
  247. if err != nil {
  248. return nil, err
  249. }
  250. return datas, nil
  251. }
  252. func GetDialysisWatchTableData(orgID, patientID int64, page, limit, start, end int64) ([]*VMMonitoringRecord, int64, error) {
  253. offset := (page - 1) * limit
  254. var total int64
  255. var err error
  256. var orders []*VMMonitoringRecord
  257. readDb := service.XTReadDB()
  258. db := readDb.Table("xt_monitoring_record as mo").
  259. Where(" mo.user_org_id=? and mo.status=1", orgID)
  260. if patientID != 0 {
  261. db = db.Where("mo.patient_id =?", patientID)
  262. }
  263. if start != 0 {
  264. db = db.Where("mo.operate_time>=?", start)
  265. }
  266. if end != 0 {
  267. db = db.Where("mo.operate_time<=?", end)
  268. }
  269. err = db.Count(&total).Offset(offset).Limit(limit).Order("mo.operate_time desc").Select("mo.patient_id,mo.operate_time,mo.systolic_blood_pressure, mo.diastolic_blood_pressure, mo.pulse_frequency,mo.breathing_rate,mo.temperature,mo.blood_flow_volume,mo.venous_pressure,mo.arterial_pressure,mo.transmembrane_pressure,mo.dialysate_temperature,mo.ultrafiltration_rate,mo.ultrafiltration_volume").Find(&orders).Error
  270. return orders, total, err
  271. }
  272. //透析监测统计
  273. // 透析体重统计
  274. func GetDialysisWeightChartData(user_org_id int64, start_time int64, end_time int64, statistics_type int) (item []*otherItemAmount, err error) {
  275. db := service.XTReadDB()
  276. var items []*otherItemAmount
  277. var tempErr error
  278. var Total int64
  279. switch statistics_type {
  280. case 1:
  281. 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)
  282. 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).
  283. Select("CASE WHEN dry_weight < 40 THEN '小于40kg'" +
  284. " WHEN dry_weight >= 40 AND dry_weight < 50 THEN '40~50kg'" +
  285. " WHEN dry_weight >= 50 AND dry_weight < 60 THEN '50~60kg'" +
  286. " WHEN dry_weight >= 60 AND dry_weight < 70 THEN '60~70kg'" +
  287. " WHEN dry_weight >= 70 THEN '大于70kg'" +
  288. " ELSE '未知' END AS name, COUNT(*) AS total",
  289. ).Group("name").Scan(&items).Error
  290. var isHasConditionOne bool = false
  291. var isHasConditionTwo bool = false
  292. var isHasConditionThree bool = false
  293. var isHasConditionFour bool = false
  294. var isHasConditionFive bool = false
  295. for _, item := range items {
  296. if item.Name == "小于40kg" {
  297. isHasConditionOne = true
  298. }
  299. if item.Name == "40~50kg" {
  300. isHasConditionTwo = true
  301. }
  302. if item.Name == "60~70kg" {
  303. isHasConditionThree = true
  304. }
  305. if item.Name == "大于70kg" {
  306. isHasConditionFour = true
  307. }
  308. if item.Name == "待定/卧床" {
  309. isHasConditionFive = true
  310. }
  311. }
  312. if !isHasConditionOne {
  313. newItem := &otherItemAmount{
  314. Total: 0,
  315. Name: "小于40kg",
  316. Ratio: "0",
  317. }
  318. items = append(items, newItem)
  319. }
  320. if !isHasConditionTwo {
  321. newItem := &otherItemAmount{
  322. Total: 0,
  323. Name: "40~50kg",
  324. Ratio: "0",
  325. }
  326. items = append(items, newItem)
  327. }
  328. if !isHasConditionThree {
  329. newItem := &otherItemAmount{
  330. Total: 0,
  331. Name: "60~70kg",
  332. Ratio: "0",
  333. }
  334. items = append(items, newItem)
  335. }
  336. if !isHasConditionFour {
  337. newItem := &otherItemAmount{
  338. Total: 0,
  339. Name: "大于70kg",
  340. Ratio: "0",
  341. }
  342. items = append(items, newItem)
  343. }
  344. if !isHasConditionFive {
  345. newItem := &otherItemAmount{
  346. Total: 0,
  347. Name: "未知",
  348. Ratio: "0",
  349. }
  350. items = append(items, newItem)
  351. }
  352. for _, item := range items {
  353. if math.IsNaN(float64(item.Total) / float64(Total)) {
  354. item.Ratio = "0.0"
  355. } else {
  356. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
  357. item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
  358. }
  359. }
  360. break
  361. case 2:
  362. 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)
  363. 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).
  364. Select("CASE WHEN weight_before < 40 THEN '小于40kg'" +
  365. " WHEN weight_before >= 40 AND weight_before < 50 THEN '40~50kg'" +
  366. " WHEN weight_before >= 50 AND weight_before < 60 THEN '50~60kg'" +
  367. " WHEN weight_before >= 60 AND weight_before < 70 THEN '60~70kg'" +
  368. " WHEN weight_before >= 70 THEN '大于70kg'" +
  369. " ELSE '未知' END AS name, COUNT(*) AS total",
  370. ).Group("name").Scan(&items).Error
  371. var isHasConditionOne bool = false
  372. var isHasConditionTwo bool = false
  373. var isHasConditionThree bool = false
  374. var isHasConditionFour bool = false
  375. var isHasConditionFive bool = false
  376. for _, item := range items {
  377. if item.Name == "小于40kg" {
  378. isHasConditionOne = true
  379. }
  380. if item.Name == "40~50kg" {
  381. isHasConditionTwo = true
  382. }
  383. if item.Name == "60~70kg" {
  384. isHasConditionThree = true
  385. }
  386. if item.Name == "大于70kg" {
  387. isHasConditionFour = true
  388. }
  389. if item.Name == "未知" {
  390. isHasConditionFive = true
  391. }
  392. }
  393. if !isHasConditionOne {
  394. newItem := &otherItemAmount{
  395. Total: 0,
  396. Name: "小于40kg",
  397. Ratio: "0",
  398. }
  399. items = append(items, newItem)
  400. }
  401. if !isHasConditionTwo {
  402. newItem := &otherItemAmount{
  403. Total: 0,
  404. Name: "40~50kg",
  405. Ratio: "0",
  406. }
  407. items = append(items, newItem)
  408. }
  409. if !isHasConditionThree {
  410. newItem := &otherItemAmount{
  411. Total: 0,
  412. Name: "60~70kg",
  413. Ratio: "0",
  414. }
  415. items = append(items, newItem)
  416. }
  417. if !isHasConditionFour {
  418. newItem := &otherItemAmount{
  419. Total: 0,
  420. Name: "大于70kg",
  421. Ratio: "0",
  422. }
  423. items = append(items, newItem)
  424. }
  425. if !isHasConditionFive {
  426. newItem := &otherItemAmount{
  427. Total: 0,
  428. Name: "未知",
  429. Ratio: "0",
  430. }
  431. items = append(items, newItem)
  432. }
  433. for _, item := range items {
  434. if math.IsNaN(float64(item.Total) / float64(Total)) {
  435. item.Ratio = "0.0"
  436. } else {
  437. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
  438. item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
  439. }
  440. }
  441. break
  442. case 3:
  443. //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)
  444. //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)
  445. var newTotal int64
  446. type weight struct {
  447. WeightAfter float64 `json:"weight_after"`
  448. WeightBefore float64 `json:"weight_before"`
  449. }
  450. var weights []*weight
  451. var weightAdd []float64
  452. 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)
  453. for index, _ := range weights {
  454. if index+1 < len(weights) {
  455. if weights[index+1].WeightAfter == 0 || weights[index].WeightBefore == 0 {
  456. continue
  457. }
  458. weightAdd = append(weightAdd, weights[index].WeightBefore-weights[index+1].WeightAfter)
  459. }
  460. }
  461. var total_one int64
  462. var total_two int64
  463. var total_three int64
  464. var total_four int64
  465. var total_five int64
  466. for _, item := range weightAdd {
  467. if item < 1 {
  468. total_one++
  469. }
  470. if item >= 1 && item < 2 {
  471. total_two++
  472. }
  473. if item >= 2 && item < 3 {
  474. total_three++
  475. }
  476. if item >= 3 && item <= 4 {
  477. total_four++
  478. }
  479. if item > 4 {
  480. total_five++
  481. }
  482. }
  483. newTotal = total_one + total_two + total_three + total_four + total_five
  484. newItem := &otherItemAmount{
  485. Total: total_one,
  486. Name: "小于1kg",
  487. Ratio: "0",
  488. }
  489. newItem1 := &otherItemAmount{
  490. Total: total_two,
  491. Name: "1-2kg",
  492. Ratio: "0",
  493. }
  494. newItem2 := &otherItemAmount{
  495. Total: total_three,
  496. Name: "2-3kg",
  497. Ratio: "0",
  498. }
  499. newItem3 := &otherItemAmount{
  500. Total: total_four,
  501. Name: "3-4kg",
  502. Ratio: "0",
  503. }
  504. newItem4 := &otherItemAmount{
  505. Total: total_five,
  506. Name: "大于4kg",
  507. Ratio: "0",
  508. }
  509. items = append(items, newItem)
  510. items = append(items, newItem1)
  511. items = append(items, newItem2)
  512. items = append(items, newItem3)
  513. items = append(items, newItem4)
  514. for _, item := range items {
  515. if math.IsNaN(float64(item.Total) / float64(newTotal)) {
  516. item.Ratio = "0.0"
  517. } else {
  518. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(newTotal))*100), 64)
  519. item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
  520. }
  521. }
  522. break
  523. case 4:
  524. db.Table("xt_assessment_after_dislysis ").Where("user_org_id=? and status=1 and created_time >= ? and created_time <= ?", user_org_id, start_time, end_time).Count(&Total)
  525. tempErr = db.Table("xt_assessment_after_dislysis").Where("user_org_id=? and status=1 and created_time >= ? and created_time <= ?", user_org_id, start_time, end_time).
  526. Select("CASE WHEN weight_after < 40 THEN '小于40kg'" +
  527. " WHEN weight_after >= 40 AND weight_after < 50 THEN '40~50kg'" +
  528. " WHEN weight_after >= 50 AND weight_after < 60 THEN '50~60kg'" +
  529. " WHEN weight_after >= 60 AND weight_after < 70 THEN '60~70kg'" +
  530. " WHEN weight_after >= 70 THEN '大于70kg'" +
  531. " ELSE '未知' END AS name, COUNT(*) AS total",
  532. ).Group("name").Scan(&items).Error
  533. var isHasConditionOne bool = false
  534. var isHasConditionTwo bool = false
  535. var isHasConditionThree bool = false
  536. var isHasConditionFour bool = false
  537. var isHasConditionFive bool = false
  538. for _, item := range items {
  539. if item.Name == "小于40kg" {
  540. isHasConditionOne = true
  541. }
  542. if item.Name == "40~50kg" {
  543. isHasConditionTwo = true
  544. }
  545. if item.Name == "60~70kg" {
  546. isHasConditionThree = true
  547. }
  548. if item.Name == "大于70kg" {
  549. isHasConditionFour = true
  550. }
  551. if item.Name == "未知" {
  552. isHasConditionFive = true
  553. }
  554. }
  555. if !isHasConditionOne {
  556. newItem := &otherItemAmount{
  557. Total: 0,
  558. Name: "小于40kg",
  559. Ratio: "0",
  560. }
  561. items = append(items, newItem)
  562. }
  563. if !isHasConditionTwo {
  564. newItem := &otherItemAmount{
  565. Total: 0,
  566. Name: "40~50kg",
  567. Ratio: "0",
  568. }
  569. items = append(items, newItem)
  570. }
  571. if !isHasConditionThree {
  572. newItem := &otherItemAmount{
  573. Total: 0,
  574. Name: "60~70kg",
  575. Ratio: "0",
  576. }
  577. items = append(items, newItem)
  578. }
  579. if !isHasConditionFour {
  580. newItem := &otherItemAmount{
  581. Total: 0,
  582. Name: "大于70kg",
  583. Ratio: "0",
  584. }
  585. items = append(items, newItem)
  586. }
  587. if !isHasConditionFive {
  588. newItem := &otherItemAmount{
  589. Total: 0,
  590. Name: "未知",
  591. Ratio: "0",
  592. }
  593. items = append(items, newItem)
  594. }
  595. for _, item := range items {
  596. if math.IsNaN(float64(item.Total) / float64(Total)) {
  597. item.Ratio = "0.0"
  598. } else {
  599. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
  600. item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
  601. }
  602. }
  603. break
  604. }
  605. if tempErr != nil {
  606. return nil, err
  607. }
  608. fmt.Println(items)
  609. return items, nil
  610. }
  611. func GetDialysisWeightTableData(orgID, patientID int64, page, limit, start, end int64) ([]*VMPredialysisEvaluation, int64, error) {
  612. offset := (page - 1) * limit
  613. var total int64
  614. var err error
  615. var orders []*VMPredialysisEvaluation
  616. readDb := service.XTReadDB()
  617. db := readDb.Table("xt_assessment_before_dislysis")
  618. db = db.Where(" user_org_id=? and status=1", orgID)
  619. if patientID > 0 {
  620. db = db.Where("patient_id=?", patientID)
  621. }
  622. if start != 0 {
  623. db = db.Where("assessment_date>=?", start)
  624. }
  625. if end != 0 {
  626. db = db.Where("assessment_date<=?", end)
  627. }
  628. db = db.Preload("VMAssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID).Preload("VMPatients", "status = 1 AND user_org_id = ?", orgID)
  629. err = db.Count(&total).Offset(offset).Limit(limit).Order("assessment_date desc").Select("dry_weight, weight_before, patient_id, assessment_date").Find(&orders).Error
  630. for _, item := range orders {
  631. after, _ := GetLastAfterWeight(orgID, item.AssessmentDate, item.PatientId)
  632. if after.ID > 0 {
  633. fmt.Println(after.WeightAfter)
  634. item.LastAfterWeight = after.WeightAfter
  635. }
  636. }
  637. return orders, total, err
  638. }
  639. type LastAfter struct {
  640. ID int64 `json:"id"`
  641. WeightAfter float64 `json:"weight_after"`
  642. }
  643. func GetLastAfterWeight(user_org_id int64, before_assessment_date int64, patient_id int64) (after LastAfter, err error) {
  644. readDb := service.XTReadDB()
  645. err = readDb.Raw("SELECT weight_after as weight_after,id as id from xt_assessment_after_dislysis WHERE (user_org_id = ? AND patient_id = ? AND assessment_date < ?) ORDER BY id desc,`xt_assessment_after_dislysis`.`id` ASC LIMIT 1 ", user_org_id, patient_id, before_assessment_date).Scan(&after).Error
  646. return
  647. }
  648. func GetPatientDialysisWeightChartData(user_org_id int64, patient_id int64, start_time int64, end_time int64, statistics_type int) (datas []*ProcessIndexDataStruct, err error) {
  649. db := service.XTReadDB()
  650. switch statistics_type {
  651. case 1:
  652. err = db.Raw("select from_unixtime(assessment_date, '%Y-%m-%d') as date, dry_weight as value from xt_assessment_before_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND created_time <= ? AND created_time >= ? ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  653. break
  654. case 2:
  655. err = db.Raw("select from_unixtime(assessment_date, '%Y-%m-%d') as date, weight_before as value from xt_assessment_before_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND created_time <= ? AND created_time >= ? ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  656. break
  657. case 3:
  658. type weight struct {
  659. WeightAfter float64 `json:"weight_after"`
  660. WeightBefore float64 `json:"weight_before"`
  661. Date string `json:"date"`
  662. }
  663. var weights []*weight
  664. db.Raw("Select xt_assessment_after_dislysis.weight_after as weight_after ,xt_assessment_before_dislysis.weight_before as weight_before,from_unixtime(xt_assessment_before_dislysis.assessment_date,'%Y-%m-%d') as date 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 <= ? AND xt_assessment_before_dislysis.patient_id = ? Order by date desc", user_org_id, start_time, end_time, patient_id).Scan(&weights)
  665. fmt.Println(len(weights))
  666. for index, _ := range weights {
  667. if index+1 < len(weights) {
  668. var weight_add ProcessIndexDataStruct
  669. fmt.Println(weights[index+1].WeightAfter)
  670. fmt.Println(weights[index].WeightBefore)
  671. if weights[index+1].WeightAfter == 0 || weights[index].WeightBefore == 0 {
  672. continue
  673. }
  674. add := weights[index].WeightBefore - weights[index+1].WeightAfter
  675. weight_add.Value = add
  676. weight_add.Date = weights[index].Date
  677. datas = append(datas, &weight_add)
  678. }
  679. }
  680. break
  681. case 4:
  682. err = db.Raw("select from_unixtime(assessment_date, '%Y-%m-%d') as date, weight_after as value from xt_assessment_after_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND created_time <= ? AND created_time >= ? ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  683. break
  684. }
  685. if err != nil {
  686. return nil, err
  687. }
  688. return datas, nil
  689. }
  690. //透析体重统计
  691. // 透析血压统计
  692. func GetBloodPressureChartData(user_org_id int64, start_time int64, end_time int64, statistics_type int, patient_id int64) (item []*otherItemAmount, err error) {
  693. db := service.XTReadDB()
  694. var items []*otherItemAmount
  695. var tempErr error
  696. var TotalOne int64
  697. var TotalTwo int64
  698. var Total int64
  699. switch statistics_type {
  700. case 1:
  701. type bp struct {
  702. SystolicBloodPressure float64 `json:"systolic_blood_pressure"`
  703. DiastolicBloodPressure float64 `json:"diastolic_blood_pressure"`
  704. }
  705. var bps []*bp
  706. if patient_id == 0 {
  707. db.Raw("SELECT systolic_blood_pressure,diastolic_blood_pressure FROM xt_assessment_before_dislysis Where user_org_id = ? AND created_time >= ? AND created_time <= ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 UNION ALL SELECT systolic_blood_pressure,diastolic_blood_pressure FROM xt_assessment_after_dislysis Where user_org_id = ? AND created_time >= ? AND created_time <= ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time, user_org_id, start_time, end_time).Scan(&bps)
  708. db.Raw("SELECT count(id) FROM xt_assessment_before_dislysis Where user_org_id = ? AND created_time >= ? AND created_time <= ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time).Count(&TotalOne)
  709. db.Raw("SELECT count(id) FROM xt_assessment_after_dislysis Where user_org_id = ? AND created_time >= ? AND created_time <= ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time).Count(&TotalTwo)
  710. Total = TotalOne + TotalTwo
  711. fmt.Println("----Total-----")
  712. fmt.Println(TotalOne)
  713. fmt.Println(TotalTwo)
  714. fmt.Println(Total)
  715. } else {
  716. db.Raw("SELECT systolic_blood_pressure,diastolic_blood_pressure FROM xt_assessment_before_dislysis Where user_org_id = ? AND created_time >= ? AND created_time <= ? AND patient_id = ? AND AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 UNION ALL SELECT systolic_blood_pressure,diastolic_blood_pressure FROM xt_assessment_after_dislysis Where user_org_id = ? AND created_time >= ? AND created_time <= ? AND patient_id = ? AND AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time, patient_id, user_org_id, start_time, end_time, patient_id).Scan(&bps)
  717. db.Raw("SELECT count(id) FROM xt_assessment_before_dislysis Where user_org_id = ? AND created_time >= ? AND created_time <= ? AND patient_id = ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time, patient_id).Count(&TotalOne)
  718. db.Raw("SELECT count(id) FROM xt_assessment_after_dislysis Where user_org_id = ? AND created_time >= ? AND created_time <= ? AND patient_id = ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time, patient_id).Count(&TotalTwo)
  719. Total = TotalOne + TotalTwo
  720. fmt.Println(TotalOne)
  721. fmt.Println(TotalTwo)
  722. fmt.Println(Total)
  723. }
  724. var total_one int64
  725. var total_two int64
  726. var total_three int64
  727. var total_four int64
  728. for _, item := range bps {
  729. if item.SystolicBloodPressure > 160 && item.DiastolicBloodPressure > 100 {
  730. total_one++
  731. } else if item.SystolicBloodPressure < 140 && item.DiastolicBloodPressure < 90 {
  732. total_two++
  733. } else if item.SystolicBloodPressure >= 140 && item.SystolicBloodPressure <= 160 && item.DiastolicBloodPressure >= 90 && item.DiastolicBloodPressure <= 100 {
  734. total_three++
  735. } else {
  736. total_four++
  737. }
  738. }
  739. newItem := &otherItemAmount{
  740. Total: total_one,
  741. Name: "大于160/100mmHg",
  742. Ratio: "0",
  743. }
  744. newItem1 := &otherItemAmount{
  745. Total: total_two,
  746. Name: "小于140/90mmHg",
  747. Ratio: "0",
  748. }
  749. newItem2 := &otherItemAmount{
  750. Total: total_three,
  751. Name: "140-160mmHg/90-100mmHg",
  752. Ratio: "0",
  753. }
  754. newItem3 := &otherItemAmount{
  755. Total: total_four,
  756. Name: "其他",
  757. Ratio: "0",
  758. }
  759. items = append(items, newItem)
  760. items = append(items, newItem1)
  761. items = append(items, newItem2)
  762. items = append(items, newItem3)
  763. for _, item := range items {
  764. if math.IsNaN(float64(item.Total) / float64(Total)) {
  765. item.Ratio = "0.0"
  766. } else {
  767. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
  768. item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
  769. }
  770. }
  771. break
  772. case 2:
  773. if patient_id == 0 {
  774. tempErr = db.Table("xt_assessment_before_dislysis ").Where("user_org_id=? and status=1 and created_time >= ? and created_time <= ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time).
  775. Select("CASE WHEN systolic_blood_pressure > 160 AND diastolic_blood_pressure > 100 THEN '大于160/100mmHg'" +
  776. " WHEN systolic_blood_pressure < 140 AND diastolic_blood_pressure < 90 THEN '小于140/90mmHg'" +
  777. " WHEN systolic_blood_pressure >= 140 AND systolic_blood_pressure <= 160 AND diastolic_blood_pressure >= 90 AND diastolic_blood_pressure <= 100 THEN '140-160mmHg/90-100mmHg'" +
  778. " ELSE '其他' END AS name, COUNT(*) AS total",
  779. ).Group("name").Scan(&items).Error
  780. db.Table("xt_assessment_before_dislysis ").Where("user_org_id=? AND status = 1 AND created_time >= ? AND created_time <= ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time).Count(&Total)
  781. } else {
  782. tempErr = db.Table("xt_assessment_before_dislysis ").Where("user_org_id=? and status=1 and created_time >= ? and created_time <= ? and patient_id = ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time, patient_id).
  783. Select("CASE WHEN systolic_blood_pressure > 160 AND diastolic_blood_pressure > 100 THEN '大于160/100mmHg'" +
  784. " WHEN systolic_blood_pressure < 140 AND diastolic_blood_pressure < 90 THEN '小于140/90mmHg'" +
  785. " WHEN systolic_blood_pressure >= 140 AND systolic_blood_pressure <= 160 AND diastolic_blood_pressure >= 90 AND diastolic_blood_pressure <= 100 THEN '140-160mmHg/90-100mmHg'" +
  786. " ELSE '其他' END AS name, COUNT(*) AS total",
  787. ).Group("name").Scan(&items).Error
  788. db.Table("xt_assessment_before_dislysis ").Where("user_org_id=? AND status = 1 AND created_time >= ? AND created_time <= ? AND patient_id = ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0", user_org_id, start_time, end_time, patient_id).Count(&Total)
  789. }
  790. var isHasConditionOne bool = false
  791. var isHasConditionTwo bool = false
  792. var isHasConditionThree bool = false
  793. var isHasConditionFour bool = false
  794. for _, item := range items {
  795. if item.Name == "大于160/100mmHg" {
  796. isHasConditionOne = true
  797. }
  798. if item.Name == "小于140/90mmHg" {
  799. isHasConditionTwo = true
  800. }
  801. if item.Name == "140-160mmHg/90-100mmHg" {
  802. isHasConditionThree = true
  803. }
  804. if item.Name == "其他" {
  805. isHasConditionFour = true
  806. }
  807. }
  808. if !isHasConditionOne {
  809. newItem := &otherItemAmount{
  810. Total: 0,
  811. Name: "大于160/100mmHg",
  812. Ratio: "0",
  813. }
  814. items = append(items, newItem)
  815. }
  816. if !isHasConditionTwo {
  817. newItem := &otherItemAmount{
  818. Total: 0,
  819. Name: "小于140/90mmHg",
  820. Ratio: "0",
  821. }
  822. items = append(items, newItem)
  823. }
  824. if !isHasConditionThree {
  825. newItem := &otherItemAmount{
  826. Total: 0,
  827. Name: "140-160mmHg/90-100mmHg",
  828. Ratio: "0",
  829. }
  830. items = append(items, newItem)
  831. }
  832. if !isHasConditionFour {
  833. newItem := &otherItemAmount{
  834. Total: 0,
  835. Name: "其他",
  836. Ratio: "0",
  837. }
  838. items = append(items, newItem)
  839. }
  840. for _, item := range items {
  841. if math.IsNaN(float64(item.Total) / float64(Total)) {
  842. item.Ratio = "0.0"
  843. } else {
  844. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
  845. item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
  846. }
  847. }
  848. break
  849. case 3:
  850. if patient_id == 0 {
  851. tempErr = db.Table("xt_assessment_after_dislysis ").Where("user_org_id=? and status=1 and created_time >= ? and created_time <= ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time).
  852. Select("CASE WHEN systolic_blood_pressure > 160 AND diastolic_blood_pressure > 100 THEN '大于160/100mmHg'" +
  853. " WHEN systolic_blood_pressure < 140 AND diastolic_blood_pressure < 90 THEN '小于140/90mmHg'" +
  854. " WHEN systolic_blood_pressure >= 140 AND systolic_blood_pressure <= 160 AND diastolic_blood_pressure >= 90 AND diastolic_blood_pressure <= 100 THEN '140-160mmHg/90-100mmHg'" +
  855. " ELSE '其他' END AS name, COUNT(*) AS total",
  856. ).Group("name").Scan(&items).Error
  857. db.Table("xt_assessment_after_dislysis").Where("user_org_id=? AND status = 1 AND created_time >= ? AND created_time <= ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time).Count(&Total)
  858. } else {
  859. tempErr = db.Table("xt_assessment_after_dislysis ").Where("user_org_id=? and status=1 and created_time >= ? and created_time <= ? and patient_id = ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0", user_org_id, start_time, end_time, patient_id).
  860. Select("CASE WHEN systolic_blood_pressure > 160 AND diastolic_blood_pressure > 100 THEN '大于160/100mmHg'" +
  861. " WHEN systolic_blood_pressure < 140 AND diastolic_blood_pressure < 90 THEN '小于140/90mmHg'" +
  862. " WHEN systolic_blood_pressure >= 140 AND systolic_blood_pressure <= 160 AND diastolic_blood_pressure >= 90 AND diastolic_blood_pressure <= 100 THEN '140-160mmHg/90-100mmHg'" +
  863. " ELSE '其他' END AS name, COUNT(*) AS total",
  864. ).Group("name").Scan(&items).Error
  865. db.Table("xt_assessment_after_dislysis ").Where("user_org_id=? AND status = 1 AND created_time >= ? AND created_time <= ? AND patient_id = ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time, patient_id).Count(&Total)
  866. }
  867. var isHasConditionOne bool = false
  868. var isHasConditionTwo bool = false
  869. var isHasConditionThree bool = false
  870. var isHasConditionFour bool = false
  871. for _, item := range items {
  872. if item.Name == "大于160/100mmHg" {
  873. isHasConditionOne = true
  874. }
  875. if item.Name == "小于140/90mmHg" {
  876. isHasConditionTwo = true
  877. }
  878. if item.Name == "140-160mmHg/90-100mmHg" {
  879. isHasConditionThree = true
  880. }
  881. if item.Name == "其他" {
  882. isHasConditionFour = true
  883. }
  884. }
  885. if !isHasConditionOne {
  886. newItem := &otherItemAmount{
  887. Total: 0,
  888. Name: "大于160/100mmHg",
  889. Ratio: "0",
  890. }
  891. items = append(items, newItem)
  892. }
  893. if !isHasConditionTwo {
  894. newItem := &otherItemAmount{
  895. Total: 0,
  896. Name: "小于140/90mmHg",
  897. Ratio: "0",
  898. }
  899. items = append(items, newItem)
  900. }
  901. if !isHasConditionThree {
  902. newItem := &otherItemAmount{
  903. Total: 0,
  904. Name: "140-160mmHg/90-100mmHg",
  905. Ratio: "0",
  906. }
  907. items = append(items, newItem)
  908. }
  909. if !isHasConditionFour {
  910. newItem := &otherItemAmount{
  911. Total: 0,
  912. Name: "其他",
  913. Ratio: "0",
  914. }
  915. items = append(items, newItem)
  916. }
  917. for _, item := range items {
  918. if math.IsNaN(float64(item.Total) / float64(Total)) {
  919. item.Ratio = "0.0"
  920. } else {
  921. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
  922. item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
  923. }
  924. }
  925. break
  926. }
  927. if tempErr != nil {
  928. return nil, err
  929. }
  930. return items, nil
  931. }
  932. func GetBloodPressureTableData(orgID, patientID int64, page, limit, start, end int64) ([]*VMSchedule, int64, error) {
  933. offset := (page - 1) * limit
  934. var total int64
  935. var err error
  936. var orders []*VMSchedule
  937. readDb := service.XTReadDB()
  938. db := readDb.Table("xt_schedule as sch")
  939. db = db.Where(" sch.user_org_id=? and sch.status=1", orgID)
  940. if patientID > 0 {
  941. db = db.Where("sch.patient_id=?", patientID)
  942. }
  943. if start != 0 {
  944. db = db.Where("sch.schedule_date>=?", start)
  945. }
  946. if end != 0 {
  947. db = db.Where("sch.schedule_date<=?", end)
  948. }
  949. db = db.Preload("VMPredialysisEvaluation", "status = 1 AND user_org_id = ?", orgID).
  950. Preload("VMAssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID).
  951. Preload("VMMinMonitoringRecord", func(db *gorm.DB) *gorm.DB {
  952. return db.Where("user_org_id = ? AND status = 1", orgID).Order("diastolic_blood_pressure ASC")
  953. }).
  954. Preload("VMMaxMonitoringRecord", func(db *gorm.DB) *gorm.DB {
  955. return db.Where("user_org_id = ? AND status = 1 ", orgID).Order("systolic_blood_pressure DESC")
  956. }).
  957. Preload("VMPatients", "status = 1 AND user_org_id = ?", orgID)
  958. err = db.Count(&total).Offset(offset).Limit(limit).Order("sch.schedule_date desc").Select(" sch.schedule_date,sch.patient_id,sch.user_org_id").Find(&orders).Error
  959. return orders, total, err
  960. }
  961. type BPDataStruct struct {
  962. Date string `json:"date"`
  963. SystolicBloodPressure float64 `json:"systolic_blood_pressure"`
  964. DiastolicBloodPressure float64 `json:"diastolic_blood_pressure"`
  965. }
  966. func GetPatientBloodPressureChartData(user_org_id int64, patient_id int64, start_time int64, end_time int64, statistics_type int) (datas []*BPDataStruct, err error) {
  967. db := service.XTReadDB()
  968. switch statistics_type {
  969. case 1:
  970. err = db.Raw("select from_unixtime(assessment_date, '%Y-%m-%d') as date, systolic_blood_pressure as systolic_blood_pressure, diastolic_blood_pressure as diastolic_blood_pressure from xt_assessment_before_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND created_time <= ? AND created_time >= ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  971. break
  972. case 2:
  973. err = db.Raw("select from_unixtime(assessment_date, '%Y-%m-%d') as date, systolic_blood_pressure as systolic_blood_pressure, diastolic_blood_pressure as diastolic_blood_pressure from xt_assessment_after_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND created_time <= ? AND created_time >= ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
  974. break
  975. }
  976. if err != nil {
  977. return nil, err
  978. }
  979. return datas, nil
  980. }
  981. //透析血压统计
  982. // 工作量统计
  983. func GetDoctorWorkloadChartData(user_org_id int64, start_time int64, end_time int64, statistics_type int, admin_user_id int64) (datas []*VMUserAdminRole, err error) {
  984. userDb := service.UserReadDB()
  985. db := service.XTReadDB()
  986. if admin_user_id == 0 {
  987. userDb.Raw("select admin_user_id, user_name,org_id from sgj_user_admin_role Where status = 1 AND org_id = ? AND user_type = 2 ", user_org_id).Scan(&datas)
  988. } else {
  989. userDb.Raw("select admin_user_id, user_name,org_id from sgj_user_admin_role Where status = 1 AND org_id = ? AND user_type = 2 AND admin_user_id = ?", user_org_id, admin_user_id).Scan(&datas)
  990. }
  991. var sys_datas VMUserAdminRole
  992. sys_datas.AdminUserId = 0
  993. sys_datas.PCount = 0
  994. sys_datas.UserName = "系统"
  995. datas = append(datas, &sys_datas)
  996. switch statistics_type {
  997. case 1:
  998. var Total int64
  999. db.Table("xt_dialysis_prescription as p").Joins("join xt_dialysis_order o On o.dialysis_date = p.record_date AND o.patient_id = p.patient_id AND o.status = 1").Where("p.user_org_id = ? AND p.status = 1 AND p.record_date >= ? AND p.record_date <= ? AND p.mode_id > 0 ", user_org_id, start_time, end_time).Count(&Total)
  1000. for _, item := range datas {
  1001. var total int64
  1002. db.Table("xt_dialysis_prescription as p").Joins("join xt_dialysis_order o On o.dialysis_date = p.record_date AND o.patient_id = p.patient_id AND o.status = 1").Where("p.user_org_id = ? AND p.status = 1 AND p.creater = ? AND p.record_date >= ? AND p.record_date <= ? AND p.mode_id > 0", user_org_id, item.AdminUserId, start_time, end_time).Count(&total)
  1003. item.PCount = total
  1004. if math.IsNaN(float64(item.PCount) / float64(Total)) {
  1005. item.PRatio = "0.0"
  1006. } else {
  1007. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.PCount)/float64(Total))*100), 64)
  1008. item.PRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1009. }
  1010. }
  1011. break
  1012. case 2:
  1013. var Total int64
  1014. db.Table("xt_patient_course_of_disease as course").Where("org_id = ? AND status = 1 AND record_time >= ? AND record_time <= ?", user_org_id, start_time, end_time).Count(&Total)
  1015. for _, item := range datas {
  1016. var total int64
  1017. db.Table("xt_patient_course_of_disease as course").Where("org_id = ? AND status = 1 AND recorder = ? AND record_time >= ? AND record_time <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&total)
  1018. item.CourseCount = total
  1019. if math.IsNaN(float64(item.CourseCount) / float64(Total)) {
  1020. item.CourseRatio = "0.0"
  1021. } else {
  1022. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.CourseCount)/float64(Total))*100), 64)
  1023. item.CourseRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1024. }
  1025. }
  1026. break
  1027. case 3:
  1028. var Total int64
  1029. db.Table("xt_patient_rescue_record as rescue").Where("org_id = ? AND status = 1 AND record_time >= ? AND record_time <= ?", user_org_id, start_time, end_time).Count(&Total)
  1030. for _, item := range datas {
  1031. var total int64
  1032. db.Table("xt_patient_rescue_record as rescue").Where("org_id = ? AND status = 1 AND recorder = ? AND record_time >= ? AND record_time <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&total)
  1033. item.RescueCount = total
  1034. if math.IsNaN(float64(item.RescueCount) / float64(Total)) {
  1035. item.RescueRatio = "0.0"
  1036. } else {
  1037. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.RescueCount)/float64(Total))*100), 64)
  1038. item.RescueRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1039. }
  1040. }
  1041. break
  1042. }
  1043. if err != nil {
  1044. return nil, err
  1045. }
  1046. fmt.Println(datas)
  1047. return datas, nil
  1048. }
  1049. func GetDoctorWorkloadTableData(user_org_id int64, start_time int64, end_time int64, admin_user_id int64) (datas []*VMUserAdminRole, err error) {
  1050. userDb := service.UserReadDB()
  1051. db := service.XTReadDB()
  1052. if admin_user_id == 0 {
  1053. userDb.Raw("select admin_user_id, user_name,org_id from sgj_user_admin_role Where org_id = ? AND user_type = 2 ", user_org_id).Scan(&datas)
  1054. } else {
  1055. userDb.Raw("select admin_user_id, user_name,org_id from sgj_user_admin_role Where org_id = ? AND user_type = 2 AND admin_user_id = ?", user_org_id, admin_user_id).Scan(&datas)
  1056. }
  1057. var sys_datas VMUserAdminRole
  1058. sys_datas.AdminUserId = 0
  1059. sys_datas.PCount = 0
  1060. sys_datas.UserName = "系统"
  1061. datas = append(datas, &sys_datas)
  1062. for _, item := range datas {
  1063. var Total int64
  1064. var TotalOne int64
  1065. var TotalTwo int64
  1066. db.Table("xt_dialysis_prescription as p").Joins("join xt_dialysis_order o On o.dialysis_date = p.record_date AND o.patient_id = p.patient_id AND o.user_org_id = ? AND o.status = 1", user_org_id).Where("p.user_org_id = ? AND p.status = 1 AND p.creater = ? AND p.record_date >= ? AND p.record_date <= ? AND p.mode_id > 0", user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
  1067. db.Table("xt_patient_course_of_disease as course").Where("org_id = ? AND status = 1 AND recorder = ? AND record_time >= ? AND record_time <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalOne)
  1068. db.Table("xt_patient_rescue_record as rescue").Where("org_id = ? AND status = 1 AND recorder = ? AND record_time >= ? AND record_time <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalTwo)
  1069. item.PCount = Total
  1070. item.CourseCount = TotalOne
  1071. item.RescueCount = TotalTwo
  1072. }
  1073. if err != nil {
  1074. return nil, err
  1075. }
  1076. return datas, nil
  1077. }
  1078. func GetNurseWorkloadChartData(user_org_id int64, start_time int64, end_time int64, statistics_type int, admin_user_id int64) (datas []*VMUserAdminRole, err error) {
  1079. userDb := service.UserReadDB()
  1080. db := service.XTReadDB()
  1081. if admin_user_id == 0 {
  1082. userDb.Raw("select admin_user_id, user_name,org_id from sgj_user_admin_role Where org_id = ? AND user_type = 3 ", user_org_id).Scan(&datas)
  1083. } else {
  1084. userDb.Raw("select admin_user_id, user_name,org_id from sgj_user_admin_role Where org_id = ? AND user_type = 3 AND admin_user_id = ?", user_org_id, admin_user_id).Scan(&datas)
  1085. }
  1086. var NewTotalOne int64
  1087. var NewTotalThree int64
  1088. var NewTotalFour int64
  1089. var NewTotalFive int64
  1090. var NewTotalSix int64
  1091. var NewTotalSeven int64
  1092. var NewTotalEight int64
  1093. var NewTotalNight int64
  1094. var NewTotalTen int64
  1095. db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ?", user_org_id, start_time, end_time).Count(&NewTotalOne)
  1096. db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ?", user_org_id, start_time, end_time).Count(&NewTotalFive)
  1097. db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ?", user_org_id, start_time, end_time).Count(&NewTotalSix)
  1098. db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ?", user_org_id, start_time, end_time).Count(&NewTotalSeven)
  1099. db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ?", user_org_id, start_time, end_time).Count(&NewTotalEight)
  1100. db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ?", user_org_id, start_time, end_time).Count(&NewTotalNight)
  1101. db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ?", user_org_id, start_time, end_time).Count(&NewTotalTen)
  1102. db.Table("xt_monitoring_record as monitor ").Joins("join xt_schedule sch On sch.schedule_date = monitor.monitoring_date AND sch.patient_id = monitor.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("monitor.user_org_id = ? AND monitor.status = 1 AND monitor.monitoring_date >= ? AND monitor.monitoring_date <= ?", user_org_id, start_time, end_time).Count(&NewTotalThree)
  1103. db.Table("xt_treatment_summary as summary").Joins("join xt_schedule sch On sch.schedule_date = summary.assessment_date AND sch.patient_id = summary.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("summary.user_org_id = ? AND summary.status = 1 AND summary.assessment_date >= ? AND summary.assessment_date <= ?", user_org_id, start_time, end_time).Count(&NewTotalFour)
  1104. switch statistics_type {
  1105. case 2:
  1106. for _, item := range datas {
  1107. var Total int64
  1108. db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.puncture_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&Total)
  1109. item.PunctureCount = Total
  1110. if math.IsNaN(float64(item.PunctureCount) / float64(NewTotalOne)) {
  1111. item.PunctureRatio = "0.0"
  1112. } else {
  1113. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.PunctureCount)/float64(NewTotalOne))*100), 64)
  1114. item.PunctureRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1115. }
  1116. }
  1117. break
  1118. case 1:
  1119. for _, item := range datas {
  1120. var Total int64
  1121. db.Table("xt_monitoring_record as monitor").Joins("join xt_schedule sch On sch.schedule_date = monitor.monitoring_date AND sch.patient_id = monitor.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("monitor.user_org_id = ? AND monitor.status = 1 AND monitor.monitoring_nurse = ? AND monitor.monitoring_date >= ? AND monitor.monitoring_date <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
  1122. item.CureCount = Total
  1123. if math.IsNaN(float64(item.CureCount) / float64(NewTotalThree)) {
  1124. item.CureRatio = "0.0"
  1125. } else {
  1126. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.CureCount)/float64(NewTotalThree))*100), 64)
  1127. item.CureRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1128. }
  1129. }
  1130. break
  1131. case 3:
  1132. for _, item := range datas {
  1133. var Total int64
  1134. db.Table("xt_treatment_summary as summary ").Joins("join xt_schedule sch On sch.schedule_date = summary.assessment_date AND sch.patient_id = summary.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("summary.user_org_id = ? AND summary.status = 1 AND summary.creater = ? AND summary.assessment_date >= ? AND summary.assessment_date <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
  1135. item.MissionCount = Total
  1136. if math.IsNaN(float64(item.MissionCount) / float64(NewTotalFour)) {
  1137. item.MissionRatio = "0.0"
  1138. } else {
  1139. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.MissionCount)/float64(NewTotalFour))*100), 64)
  1140. item.MissionRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1141. }
  1142. }
  1143. break
  1144. case 4:
  1145. for _, item := range datas {
  1146. var Total int64
  1147. db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.change_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&Total)
  1148. item.ChangeNuserCount = Total
  1149. if math.IsNaN(float64(item.ChangeNuserCount) / float64(NewTotalFive)) {
  1150. item.ChangeRatio = "0.0"
  1151. } else {
  1152. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.ChangeNuserCount)/float64(NewTotalFive))*100), 64)
  1153. item.ChangeRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1154. }
  1155. }
  1156. break
  1157. case 5:
  1158. for _, item := range datas {
  1159. var Total int64
  1160. db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.difficult_puncture_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&Total)
  1161. item.DiffiCultPuntureNuserCount = Total
  1162. if math.IsNaN(float64(item.DiffiCultPuntureNuserCount) / float64(NewTotalSix)) {
  1163. item.DiffiCultNuserRatio = "0.0"
  1164. } else {
  1165. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.DiffiCultPuntureNuserCount)/float64(NewTotalSix))*100), 64)
  1166. item.DiffiCultNuserRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1167. }
  1168. }
  1169. break
  1170. case 6:
  1171. for _, item := range datas {
  1172. var Total int64
  1173. db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.new_fistula_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&Total)
  1174. item.NewNuserCount = Total
  1175. if math.IsNaN(float64(item.NewNuserCount) / float64(NewTotalSeven)) {
  1176. item.NewNuserRatio = "0.0"
  1177. } else {
  1178. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.NewNuserCount)/float64(NewTotalSeven))*100), 64)
  1179. item.NewNuserRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1180. }
  1181. }
  1182. break
  1183. case 7:
  1184. for _, item := range datas {
  1185. var Total int64
  1186. db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.start_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&Total)
  1187. item.StartNuserCount = Total
  1188. if math.IsNaN(float64(item.StartNuserCount) / float64(NewTotalEight)) {
  1189. item.StartNuserRatio = "0.0"
  1190. } else {
  1191. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.StartNuserCount)/float64(NewTotalEight))*100), 64)
  1192. item.StartNuserRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1193. }
  1194. }
  1195. break
  1196. case 8:
  1197. for _, item := range datas {
  1198. var Total int64
  1199. db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.finish_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&Total)
  1200. item.FinshNurserCount = Total
  1201. if math.IsNaN(float64(item.FinshNurserCount) / float64(NewTotalNight)) {
  1202. item.FinshNurseRatio = "0.0"
  1203. } else {
  1204. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.FinshNurserCount)/float64(NewTotalNight))*100), 64)
  1205. item.FinshNurseRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1206. }
  1207. }
  1208. break
  1209. case 9:
  1210. for _, item := range datas {
  1211. var Total int64
  1212. db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.washpipe_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&Total)
  1213. item.WashpipeNurserCount = Total
  1214. if math.IsNaN(float64(item.WashpipeNurserCount) / float64(NewTotalTen)) {
  1215. item.WashpipeNurseRatio = "0.0"
  1216. } else {
  1217. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.WashpipeNurserCount)/float64(NewTotalTen))*100), 64)
  1218. item.WashpipeNurseRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1219. }
  1220. }
  1221. break
  1222. }
  1223. if err != nil {
  1224. return nil, err
  1225. }
  1226. return datas, nil
  1227. }
  1228. func GetNurseWorkloadTableData(user_org_id int64, start_time int64, end_time int64, admin_user_id int64, page int64, limit int64) (datas []*VMUserAdminRole, AdminTotal int64, err error) {
  1229. userDb := service.UserReadDB()
  1230. db := service.XTReadDB()
  1231. //var tempConfig models.Dataconfig
  1232. //offset := (page - 1) * limit
  1233. //db.Model(&models.Dataconfig{}).Where("name = '血管通路' AND module = 'hemodialysis' AND field_name = 'vascular_access_desc' AND parent_id = 0").First(&tempConfig)
  1234. if admin_user_id == 0 {
  1235. userDb.Raw("select admin_user_id, user_name,org_id from sgj_user_admin_role Where org_id = ? AND user_type = 3 ", user_org_id).Scan(&datas)
  1236. } else {
  1237. userDb.Raw("select admin_user_id, user_name,org_id from sgj_user_admin_role Where org_id = ? AND user_type = 3 AND admin_user_id = ?", user_org_id, admin_user_id).Scan(&datas)
  1238. }
  1239. for _, item := range datas {
  1240. var Total int64
  1241. var TotalTwo int64
  1242. var TotalThree int64
  1243. var TotalFour int64
  1244. var TotalFive int64
  1245. var TotalSix int64
  1246. var TotalSeven int64
  1247. var TotalEghit int64
  1248. var TotalNight int64
  1249. //db.Raw("select count(*) as total from (select d.patient_id as patient, d.id, d.`assessment_date` as date,config.name as name from xt_assessment_before_dislysis as d JOIN `xt_data_config` config on d.`blood_access_part_opera_id` = config.value AND config.org_id = ? AND config.parent_id = ? AND FIND_IN_SET('内瘘',config.name) > 0 Where d.user_org_id = ? AND d.assessment_date >=? AND d.assessment_date <= ? Group by d.id) b JOIN `xt_dialysis_order` on xt_dialysis_order.`dialysis_date` = b.date AND xt_dialysis_order.user_org_id = ? AND xt_dialysis_order.status = 1 AND xt_dialysis_order.start_nurse = ? AND xt_dialysis_order.dialysis_date >= ? AND xt_dialysis_order.dialysis_date <= ? ", user_org_id, tempConfig.ID, user_org_id, start_time, end_time, user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
  1250. //db.Raw("select count(*) as total_one from (select d.patient_id as patient, d.id, d.`assessment_date` as date,config.name as name from xt_assessment_before_dislysis as d JOIN `xt_data_config` config on d.`blood_access_part_opera_id` = config.value AND config.org_id = ? AND config.parent_id = ? AND FIND_IN_SET('导管',config.name) > 0 Where d.user_org_id = ? AND d.assessment_date >=? AND d.assessment_date <= ? Group by d.id) b JOIN `xt_dialysis_order` on xt_dialysis_order.`dialysis_date` = b.date AND xt_dialysis_order.user_org_id = ? AND xt_dialysis_order.status = 1 AND xt_dialysis_order.start_nurse = ? AND xt_dialysis_order.dialysis_date >= ? AND xt_dialysis_order.dialysis_date <= ? ", user_org_id, tempConfig.ID, user_org_id, start_time, end_time, user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalOne)
  1251. db.Table("xt_monitoring_record as monitor ").Joins("join xt_schedule sch On sch.schedule_date = monitor.monitoring_date AND sch.patient_id = monitor.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("monitor.user_org_id = ? AND monitor.status = 1 AND monitor.monitoring_nurse = ? AND monitor.monitoring_date >= ? AND monitor.monitoring_date <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalTwo)
  1252. db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.puncture_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&Total)
  1253. db.Table("xt_treatment_summary as summary").Joins("join xt_schedule sch On sch.schedule_date = summary.assessment_date AND sch.patient_id = summary.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("summary.user_org_id = ? AND summary.status = 1 AND summary.creater = ? AND summary.assessment_date >= ? AND summary.assessment_date <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalThree)
  1254. db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.change_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalFour)
  1255. db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.difficult_puncture_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalFive)
  1256. db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.new_fistula_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalSix)
  1257. db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.start_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalSeven)
  1258. db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.finish_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalEghit)
  1259. db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.washpipe_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalNight)
  1260. item.PunctureCount = Total
  1261. item.CureCount = TotalTwo
  1262. item.MissionCount = TotalThree
  1263. item.ChangeNuserCount = TotalFour
  1264. item.DiffiCultPuntureNuserCount = TotalFive
  1265. item.NewNuserCount = TotalSix
  1266. item.StartNuserCount = TotalSeven
  1267. item.FinshNurserCount = TotalEghit
  1268. item.WashpipeNurserCount = TotalNight
  1269. }
  1270. if err != nil {
  1271. return nil, AdminTotal, err
  1272. }
  1273. return datas, AdminTotal, nil
  1274. }
  1275. //func GetMobilNurseWorkloadTableData(user_org_id int64, start_time int64, end_time int64, admin_user_id int64, page int64, limit int64) (datas []*VMUserAdminRole, AdminTotal int64, err error) {
  1276. // userDb := service.UserReadDB()
  1277. // db := service.XTReadDB()
  1278. // //var tempConfig models.Dataconfig
  1279. // //offset := (page - 1) * limit
  1280. //
  1281. // //db.Model(&models.Dataconfig{}).Where("name = '血管通路' AND module = 'hemodialysis' AND field_name = 'vascular_access_desc' AND parent_id = 0").First(&tempConfig)
  1282. //
  1283. // if admin_user_id == 0 {
  1284. // userDb.Raw("select admin_user_id, user_name,org_id from sgj_user_admin_role Where org_id = ? AND user_type = 3 ", user_org_id).Scan(&datas)
  1285. // } else {
  1286. // userDb.Raw("select admin_user_id, user_name,org_id from sgj_user_admin_role Where org_id = ? AND user_type = 3 AND admin_user_id = ?", user_org_id, admin_user_id).Scan(&datas)
  1287. // }
  1288. //
  1289. // for _, item := range datas {
  1290. // var Total int64
  1291. // var TotalTwo int64
  1292. // var TotalThree int64
  1293. // var TotalFour int64
  1294. // var TotalFive int64
  1295. // var TotalSix int64
  1296. // var TotalSeven int64
  1297. // var TotalEghit int64
  1298. // var TotalNight int64
  1299. // //db.Raw("select count(*) as total from (select d.patient_id as patient, d.id, d.`assessment_date` as date,config.name as name from xt_assessment_before_dislysis as d JOIN `xt_data_config` config on d.`blood_access_part_opera_id` = config.value AND config.org_id = ? AND config.parent_id = ? AND FIND_IN_SET('内瘘',config.name) > 0 Where d.user_org_id = ? AND d.assessment_date >=? AND d.assessment_date <= ? Group by d.id) b JOIN `xt_dialysis_order` on xt_dialysis_order.`dialysis_date` = b.date AND xt_dialysis_order.user_org_id = ? AND xt_dialysis_order.status = 1 AND xt_dialysis_order.start_nurse = ? AND xt_dialysis_order.dialysis_date >= ? AND xt_dialysis_order.dialysis_date <= ? ", user_org_id, tempConfig.ID, user_org_id, start_time, end_time, user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
  1300. // //db.Raw("select count(*) as total_one from (select d.patient_id as patient, d.id, d.`assessment_date` as date,config.name as name from xt_assessment_before_dislysis as d JOIN `xt_data_config` config on d.`blood_access_part_opera_id` = config.value AND config.org_id = ? AND config.parent_id = ? AND FIND_IN_SET('导管',config.name) > 0 Where d.user_org_id = ? AND d.assessment_date >=? AND d.assessment_date <= ? Group by d.id) b JOIN `xt_dialysis_order` on xt_dialysis_order.`dialysis_date` = b.date AND xt_dialysis_order.user_org_id = ? AND xt_dialysis_order.status = 1 AND xt_dialysis_order.start_nurse = ? AND xt_dialysis_order.dialysis_date >= ? AND xt_dialysis_order.dialysis_date <= ? ", user_org_id, tempConfig.ID, user_org_id, start_time, end_time, user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalOne)
  1301. // db.Table("xt_monitoring_record as monitor ").Joins("join xt_schedule sch On sch.schedule_date = monitor.monitoring_date AND sch.patient_id = monitor.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("monitor.user_org_id = ? AND monitor.status = 1 AND monitor.monitoring_nurse = ? AND monitor.monitoring_date >= ? AND monitor.monitoring_date <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalTwo)
  1302. // db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.puncture_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&Total)
  1303. // db.Table("xt_treatment_summary as summary").Joins("join xt_schedule sch On sch.schedule_date = summary.assessment_date AND sch.patient_id = summary.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("summary.user_org_id = ? AND summary.status = 1 AND summary.creater = ? AND summary.assessment_date >= ? AND summary.assessment_date <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalThree)
  1304. //
  1305. // db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.change_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalFour)
  1306. // db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.difficult_puncture_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalFive)
  1307. // db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.new_fistula_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalSix)
  1308. // db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.start_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalSeven)
  1309. // db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.finish_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalEghit)
  1310. // db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.washpipe_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalNight)
  1311. //
  1312. // item.PunctureCount = Total
  1313. // item.CureCount = TotalTwo
  1314. // item.MissionCount = TotalThree
  1315. // item.ChangeNuserCount = TotalFour
  1316. // item.DiffiCultPuntureNuserCount = TotalFive
  1317. // item.NewNuserCount = TotalSix
  1318. // item.StartNuserCount = TotalSeven
  1319. // item.FinshNurserCount = TotalEghit
  1320. // item.WashpipeNurserCount = TotalNight
  1321. // }
  1322. //
  1323. // if err != nil {
  1324. // return nil, AdminTotal, err
  1325. // }
  1326. // return datas, AdminTotal, nil
  1327. //
  1328. //}
  1329. // 工作量统计
  1330. type AdminUser struct {
  1331. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1332. AdminUserId int64 `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
  1333. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  1334. UserName string `gorm:"column:user_name" json:"user_name" form:"user_name"`
  1335. UserType int64 `gorm:"column:user_type" json:"user_type" form:"user_type"`
  1336. }
  1337. func GetAllAdminUser(user_org_id int64) (datas []*AdminUser, err error) {
  1338. userDb := service.UserReadDB()
  1339. userDb.Raw("select id, admin_user_id, user_name,org_id, user_type from sgj_user_admin_role Where status = 1 AND org_id = ?", user_org_id).Scan(&datas)
  1340. return datas, nil
  1341. }
  1342. //func FindOrgInspectionCount(user_org_id int64) (count int64, err error) {
  1343. // db := service.XTReadDB()
  1344. // err = db.Model(&models.QualityControlStandard{}).Where("status = 1 AND org_id = ? ", user_org_id).Count(&count).Error
  1345. // return
  1346. //}
  1347. type InspectionReference struct {
  1348. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1349. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  1350. ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
  1351. Project string `gorm:"column:project" json:"project" form:"project"`
  1352. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1353. ItemName string `gorm:"column:item_name" json:"item_name" form:"item_name"`
  1354. RangeType int64 `gorm:"column:range_type" json:"range_type" form:"range_type"`
  1355. RangeMin string `gorm:"column:range_min" json:"range_min" form:"range_min"`
  1356. RangeMax string `gorm:"column:range_max" json:"range_max" form:"range_max"`
  1357. RangeValue string `gorm:"column:range_value" json:"range_value" form:"range_value"`
  1358. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1359. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1360. }
  1361. func FindOrgQualityControlStandardInspectionReference(user_org_id int64) (references []*InspectionReference, err error) {
  1362. db := service.XTReadDB()
  1363. err = db.Raw("SELECT reference.project_name AS project_name,qcs.inspection_major AS project_id, qcs.inspection_minor AS id,reference.item_name AS item_name,qcs.range_type AS range_type,reference.range_min AS range_min,reference.range_max AS range_max,reference.unit AS unit,qcs.range_value AS range_value FROM xt_quality_control_standard qcs LEFT JOIN xt_inspection_reference reference ON qcs.inspection_major = reference.project_id AND ( qcs.inspection_minor = reference.item_id AND reference.org_id = ?) OR (org_id = 0 AND qcs.inspection_minor = reference.id ) WHERE qcs.user_org_id = ? AND qcs.status = 1 AND reference.status = 1", user_org_id, user_org_id).Scan(&references).Error
  1364. return
  1365. }
  1366. func FindOrgInspectionReference(user_org_id int64, range_type int) (references []*models.InspectionReference, err error) {
  1367. db := service.XTReadDB()
  1368. if range_type == 1 {
  1369. err = db.Model(&models.InspectionReference{}).Where("status = 1 AND org_id = ? AND range_type = 1 AND (range_min REGEXP '[^0-9.]') = 0 AND (range_max REGEXP '[^0-9.]') = 0 ", user_org_id).Find(&references).Error
  1370. } else {
  1371. err = db.Model(&models.InspectionReference{}).Where("status = 1 AND org_id = ? AND range_type = 2", user_org_id).Find(&references).Error
  1372. }
  1373. return
  1374. }
  1375. func FindProcjectInspectionReference(user_org_id int64, project_id int64, item_id int64) (references models.InspectionReference, err error) {
  1376. db := service.XTReadDB()
  1377. err = db.Model(&models.InspectionReference{}).Where("status = 1 AND org_id = ? AND project_id = ? AND id = ?", user_org_id, project_id, item_id).First(&references).Error
  1378. return
  1379. }
  1380. func FindOrgInspectionReferenceRangeTypeValue(user_org_id int64, project_id int64, item_id int64) (inspection []*models.Inspection, err error) {
  1381. db := service.XTReadDB()
  1382. err = db.Model(&models.Inspection{}).Where("status = 1 AND org_id = ? AND project_id = ? AND item_id = ? ", user_org_id, project_id, item_id).Group("inspect_value").Find(&inspection).Error
  1383. return
  1384. }
  1385. func FindOrgConfigRangeTypeValue(user_org_id int64, project_id int64, item_id int64) (qcs models.InspectionReference, err error) {
  1386. db := service.XTReadDB()
  1387. err = db.Model(&models.InspectionReference{}).Where("status = 1 AND org_id = ? AND project_id = ? AND item_id = ?", user_org_id, project_id, item_id).First(&qcs).Error
  1388. return
  1389. }
  1390. func FindOrgConfigRangeTypeValueTwo(user_org_id int64, project_id int64, item_id int64) (qcs models.InspectionReference, err error) {
  1391. db := service.XTReadDB()
  1392. err = db.Model(&models.InspectionReference{}).Where("status = 1 AND org_id = ? AND project_id = ? AND id = ?", user_org_id, project_id, item_id).First(&qcs).Error
  1393. return
  1394. }
  1395. func GetInspectionChartData(user_org_id int64, start_time int64, end_time int64, project_id int64, item_id int64, range_type int, range_value string) (item []*otherItemAmount, err error) {
  1396. db := service.XTReadDB()
  1397. var items []*otherItemAmount
  1398. var tempErr error
  1399. var Total int64
  1400. selectContent := "CASE"
  1401. range_value_arr := strings.Split(range_value, ",")
  1402. db.Table("xt_inspection").Where("org_id=? and status=1 and inspect_date >= ? and inspect_date <= ? AND project_id = ? AND item_id = ? AND inspect_value <> '' ", user_org_id, start_time, end_time, project_id, item_id).Count(&Total)
  1403. if range_type == 1 {
  1404. tempErr = db.Table("xt_inspection").Where("org_id=? and status=1 and inspect_date >= ? and inspect_date <= ? AND project_id = ? AND item_id = ? AND inspect_value <> ''", user_org_id, start_time, end_time, project_id, item_id).
  1405. Select("CASE WHEN inspect_value < " + range_value_arr[0] + " THEN " + "'" + "小于" + range_value_arr[0] + "'" +
  1406. " WHEN inspect_value >= " + range_value_arr[0] + " AND inspect_value <= " + range_value_arr[1] + " THEN " + "'" + range_value_arr[0] + "~" + range_value_arr[1] + "'" +
  1407. " WHEN inspect_value > " + range_value_arr[1] + " THEN " + "'" + "大于" + range_value_arr[1] + "'" +
  1408. " ELSE '未知' END AS name, COUNT(*) AS total",
  1409. ).Group("name").Scan(&items).Error
  1410. var isHasConditionOne bool = false
  1411. var isHasConditionTwo bool = false
  1412. var isHasConditionThree bool = false
  1413. for _, item := range items {
  1414. if item.Name == "大于"+range_value_arr[1] {
  1415. isHasConditionOne = true
  1416. }
  1417. if item.Name == "小于"+range_value_arr[0] {
  1418. isHasConditionTwo = true
  1419. }
  1420. if item.Name == range_value_arr[0]+"~"+range_value_arr[1] {
  1421. isHasConditionThree = true
  1422. }
  1423. }
  1424. if !isHasConditionOne {
  1425. newItem := &otherItemAmount{
  1426. Total: 0,
  1427. Name: "大于" + range_value_arr[1],
  1428. Ratio: "0",
  1429. }
  1430. items = append(items, newItem)
  1431. }
  1432. if !isHasConditionTwo {
  1433. newItem := &otherItemAmount{
  1434. Total: 0,
  1435. Name: "小于" + range_value_arr[0],
  1436. Ratio: "0",
  1437. }
  1438. items = append(items, newItem)
  1439. }
  1440. if !isHasConditionThree {
  1441. newItem := &otherItemAmount{
  1442. Total: 0,
  1443. Name: range_value_arr[0] + "~" + range_value_arr[1],
  1444. Ratio: "0",
  1445. }
  1446. items = append(items, newItem)
  1447. }
  1448. for _, item := range items {
  1449. if math.IsNaN(float64(item.Total) / float64(Total)) {
  1450. item.Ratio = "0.0"
  1451. } else {
  1452. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
  1453. item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1454. }
  1455. }
  1456. return items, tempErr
  1457. } else {
  1458. for _, item := range range_value_arr {
  1459. //selectContent = selectContent + " WHEN inspect_value =" + item + " THEN " + "'" + item + "'"
  1460. selectContent = selectContent + " WHEN inspect_value =" + "'" + item + "'" + " THEN " + "'" + item + "'"
  1461. }
  1462. tempErr = db.Table("xt_inspection").Where("org_id=? and status=1 and inspect_date >= ? and inspect_date <= ? AND project_id = ? AND item_id = ? AND inspect_value <> '' ", user_org_id, start_time, end_time, project_id, item_id).
  1463. Select(selectContent +
  1464. " ELSE '未知' END AS name, COUNT(*) AS total",
  1465. ).Group("name").Scan(&items).Error
  1466. for _, item := range items {
  1467. if math.IsNaN(float64(item.Total) / float64(Total)) {
  1468. item.Ratio = "0.0"
  1469. } else {
  1470. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
  1471. item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1472. }
  1473. }
  1474. return items, tempErr
  1475. }
  1476. }
  1477. type Inspection struct {
  1478. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1479. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1480. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  1481. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1482. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1483. ItemName string `gorm:"column:item_name" json:"item_name" form:"item_name"`
  1484. ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
  1485. InspectType int64 `gorm:"column:inspect_type" json:"inspect_type" form:"inspect_type"`
  1486. InspectValue string `gorm:"column:inspect_value" json:"inspect_value" form:"inspect_value"`
  1487. InspectDate int64 `gorm:"column:inspect_date" json:"inspect_date" form:"inspect_date"`
  1488. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1489. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1490. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  1491. Patient models.Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patient"`
  1492. }
  1493. func (Inspection) TableName() string {
  1494. return "xt_inspection"
  1495. }
  1496. func GetInspectionChartTableData(user_org_id int64, start_time int64, end_time int64, project_id int64, item_id int64, patient_id int64, page, limit int64, range_type int, range_value string) (datas []*Inspection, total int64, err error) {
  1497. if range_type == 1 {
  1498. index := strings.Index(range_value, "小于")
  1499. indexTwo := strings.Index(range_value, "大于")
  1500. indexThree := strings.Index(range_value, "~")
  1501. if index != -1 {
  1502. value, _ := strconv.ParseFloat(strings.Replace(range_value, "小于", "", 1), 64)
  1503. db := service.XTReadDB()
  1504. offset := (page - 1) * limit
  1505. err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND inspect_date >= ? AND inspect_date <= ? AND project_id = ? AND item_id = ? AND status = 1 AND inspect_value < ?", user_org_id, start_time, end_time, project_id, item_id, value).Preload("Patient", func(db *gorm.DB) *gorm.DB {
  1506. return db.Where("status = 1 AND user_org_id = ?", user_org_id)
  1507. }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
  1508. return datas, total, err
  1509. } else if indexTwo != -1 {
  1510. value, _ := strconv.ParseFloat(strings.Replace(range_value, "大于", "", 1), 64)
  1511. db := service.XTReadDB()
  1512. offset := (page - 1) * limit
  1513. err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND inspect_date >= ? AND inspect_date <= ? AND project_id = ? AND item_id = ? AND status = 1 AND inspect_value > ?", user_org_id, start_time, end_time, project_id, item_id, value).Preload("Patient", func(db *gorm.DB) *gorm.DB {
  1514. return db.Where("status = 1 AND user_org_id = ?", user_org_id)
  1515. }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
  1516. return datas, total, err
  1517. } else if indexThree != -1 {
  1518. range_value_arr := strings.Split(range_value, "~")
  1519. fmt.Println(range_value_arr)
  1520. float1, err := strconv.ParseFloat(range_value_arr[0], 64)
  1521. float2, err := strconv.ParseFloat(range_value_arr[1], 64)
  1522. fmt.Println(err)
  1523. fmt.Println(float1)
  1524. fmt.Println(float2)
  1525. db := service.XTReadDB()
  1526. offset := (page - 1) * limit
  1527. err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND inspect_date >= ? AND inspect_date <= ? AND project_id = ? AND item_id = ? AND status = 1 AND inspect_value >= ? AND inspect_value <= ?", user_org_id, start_time, end_time, project_id, item_id, float1, float2).Preload("Patient", func(db *gorm.DB) *gorm.DB {
  1528. return db.Where("status = 1 AND user_org_id = ?", user_org_id)
  1529. }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
  1530. return datas, total, err
  1531. } else {
  1532. db := service.XTReadDB()
  1533. offset := (page - 1) * limit
  1534. err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND inspect_date >= ? AND inspect_date <= ? AND project_id = ? AND item_id = ? AND status = 1 ", user_org_id, start_time, end_time, project_id, item_id).Preload("Patient", func(db *gorm.DB) *gorm.DB {
  1535. return db.Where("status = 1 AND user_org_id = ?", user_org_id)
  1536. }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
  1537. return datas, total, err
  1538. }
  1539. } else {
  1540. if range_value == "全部" {
  1541. db := service.XTReadDB()
  1542. offset := (page - 1) * limit
  1543. err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND inspect_date >= ? AND inspect_date <= ? AND project_id = ? AND item_id = ? AND status = 1 ", user_org_id, start_time, end_time, project_id, item_id).Preload("Patient", func(db *gorm.DB) *gorm.DB {
  1544. return db.Where("status = 1 AND user_org_id = ?", user_org_id)
  1545. }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
  1546. return datas, total, err
  1547. } else {
  1548. db := service.XTReadDB()
  1549. offset := (page - 1) * limit
  1550. err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND inspect_date >= ? AND inspect_date <= ? AND project_id = ? AND item_id = ? AND status = 1 AND inspect_value = ?", user_org_id, start_time, end_time, project_id, item_id, range_value).Preload("Patient", func(db *gorm.DB) *gorm.DB {
  1551. return db.Where("status = 1 AND user_org_id = ?", user_org_id)
  1552. }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
  1553. return datas, total, err
  1554. }
  1555. }
  1556. }
  1557. type NewIndexDataStruct struct {
  1558. Date string `json:"date"`
  1559. Value string `json:"value"`
  1560. }
  1561. func GetPatientInspectionChartData(user_org_id int64, start_time int64, end_time int64, project_id int64, item_id int64, patient_id int64) (datas []*NewIndexDataStruct, err error) {
  1562. db := service.XTReadDB()
  1563. err = db.Raw("select from_unixtime(inspect_date, '%Y-%m-%d') as date, inspect_value as value from xt_inspection Where status = 1 AND org_id = ? AND patient_id = ? AND project_id = ? AND item_id = ? AND inspect_date <= ? AND inspect_date >= ? Order by inspect_date asc ", user_org_id, patient_id, project_id, item_id, end_time, start_time).Scan(&datas).Error
  1564. if err != nil {
  1565. return nil, err
  1566. }
  1567. return datas, nil
  1568. }
  1569. func GetPatientInspectionBarChartData(user_org_id int64, start_time int64, end_time int64, project_id int64, item_id int64, range_type int, range_value string, patient_id int64) (item []*otherItemAmount, err error) {
  1570. db := service.XTReadDB()
  1571. var items []*otherItemAmount
  1572. var tempErr error
  1573. selectContent := "CASE"
  1574. range_value_arr := strings.Split(range_value, ",")
  1575. var Total int64
  1576. db.Table("xt_inspection").Where("org_id=? and status=1 and inspect_date >= ? and inspect_date <= ? AND project_id = ? AND item_id = ? AND patient_id = ? AND inspect_value <> ''", user_org_id, start_time, end_time, project_id, item_id, patient_id).Count(&Total)
  1577. if range_type == 1 {
  1578. tempErr = db.Table("xt_inspection").Where("org_id=? and status=1 and inspect_date >= ? and inspect_date <= ? AND project_id = ? AND item_id = ? AND patient_id = ? AND inspect_value <> ''", user_org_id, start_time, end_time, project_id, item_id, patient_id).
  1579. Select("CASE WHEN inspect_value < " + range_value_arr[0] + " THEN " + "'" + "小于" + range_value_arr[0] + "'" +
  1580. " WHEN inspect_value >= " + range_value_arr[0] + " AND inspect_value <= " + range_value_arr[1] + " THEN " + "'" + range_value_arr[0] + "~" + range_value_arr[1] + "'" +
  1581. " WHEN inspect_value > " + range_value_arr[1] + " THEN " + "'" + "大于" + range_value_arr[1] + "'" +
  1582. " ELSE '未知' END AS name, COUNT(*) AS total",
  1583. ).Group("name").Scan(&items).Error
  1584. var isHasConditionOne bool = false
  1585. var isHasConditionTwo bool = false
  1586. var isHasConditionThree bool = false
  1587. for _, item := range items {
  1588. if item.Name == "大于"+range_value_arr[1] {
  1589. isHasConditionOne = true
  1590. }
  1591. if item.Name == "小于"+range_value_arr[0] {
  1592. isHasConditionTwo = true
  1593. }
  1594. if item.Name == range_value_arr[0]+"~"+range_value_arr[1] {
  1595. isHasConditionThree = true
  1596. }
  1597. }
  1598. if !isHasConditionOne {
  1599. newItem := &otherItemAmount{
  1600. Total: 0,
  1601. Name: "大于" + range_value_arr[1],
  1602. Ratio: "0",
  1603. }
  1604. items = append(items, newItem)
  1605. }
  1606. if !isHasConditionTwo {
  1607. newItem := &otherItemAmount{
  1608. Total: 0,
  1609. Name: "小于" + range_value_arr[0],
  1610. Ratio: "0",
  1611. }
  1612. items = append(items, newItem)
  1613. }
  1614. if !isHasConditionThree {
  1615. newItem := &otherItemAmount{
  1616. Total: 0,
  1617. Name: range_value_arr[0] + "~" + range_value_arr[1],
  1618. Ratio: "0",
  1619. }
  1620. items = append(items, newItem)
  1621. }
  1622. for _, item := range items {
  1623. if math.IsNaN(float64(item.Total) / float64(Total)) {
  1624. item.Ratio = "0.0"
  1625. } else {
  1626. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
  1627. item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1628. }
  1629. }
  1630. return items, tempErr
  1631. } else {
  1632. for _, item := range range_value_arr {
  1633. selectContent = selectContent + " WHEN inspect_value =" + "'" + item + "'" + " THEN " + "'" + item + "'"
  1634. }
  1635. tempErr = db.Table("xt_inspection").Where("org_id=? and status=1 and inspect_date >= ? and inspect_date <= ? AND patient_id = ? AND inspect_value <> '' AND project_id = ? AND item_id = ?", user_org_id, start_time, end_time, patient_id, project_id, item_id).
  1636. Select(selectContent +
  1637. " ELSE '未知' END AS name, COUNT(*) AS total",
  1638. ).Group("name").Scan(&items).Error
  1639. for _, item := range items {
  1640. if math.IsNaN(float64(item.Total) / float64(Total)) {
  1641. item.Ratio = "0.0"
  1642. } else {
  1643. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
  1644. item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1645. }
  1646. }
  1647. return items, tempErr
  1648. }
  1649. }
  1650. type VMPatient struct {
  1651. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1652. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1653. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  1654. Name string `gorm:"column:name" json:"name" form:"name"`
  1655. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  1656. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1657. }
  1658. func (VMPatient) TableName() string {
  1659. return "xt_patients"
  1660. }
  1661. func GetOrgPatients(user_org_id int64) (patient *[]VMPatient, err error) {
  1662. db := service.XTReadDB()
  1663. var tempPatient []VMPatient
  1664. findErr := db.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND lapseto = 1", user_org_id).Find(&tempPatient).Error
  1665. if findErr == gorm.ErrRecordNotFound {
  1666. return nil, nil
  1667. }
  1668. if findErr != nil {
  1669. return nil, findErr
  1670. }
  1671. return &tempPatient, nil
  1672. }
  1673. func FindOrgQualityControlStandardInspectionReferenceById(user_org_id int64, project_id int64, item_id int64) (references InspectionReference, err error) {
  1674. db := service.XTReadDB()
  1675. err = db.Raw("Select reference.project_name as project_name,qcs.inspection_major as project_id, qcs.inspection_minor as id,reference.item_name as item_name,qcs.range_type as range_type,reference.range_min as range_min, reference.range_max as range_max,reference.unit as unit,qcs.range_value as range_value from xt_quality_control_standard qcs Left JOIN xt_inspection_reference reference ON qcs.inspection_major = reference.project_id and qcs.inspection_minor = reference.id and (reference.org_id = ? OR org_id = 0) Where qcs.user_org_id = ? AND qcs.status = 1 AND qcs.inspection_major = ? AND qcs.inspection_minor = ?", user_org_id, user_org_id, project_id, item_id).Scan(&references).Error
  1676. return
  1677. }
  1678. func FindOrgInspectionCount(user_org_id int64) (count int64, err error) {
  1679. db := service.XTReadDB()
  1680. err = db.Model(&models.InspectionReference{}).Where("status = 1 AND org_id = ?", user_org_id).Count(&count).Error
  1681. return
  1682. }
  1683. func GetOrderDialysisCount(orgid int64, startime int64, endtime int64) (order []*models.BloodDialysisOrderOne, err error) {
  1684. db := service.XTReadDB()
  1685. table := db.Table("xt_schedule as s")
  1686. fmt.Println(table)
  1687. d := db.Table("xt_patients as p")
  1688. fmt.Println(d)
  1689. db = db.Table("xt_dialysis_order as o").Where("o.status = 1")
  1690. if orgid > 0 {
  1691. db = db.Where("o.user_org_id = ?", orgid)
  1692. }
  1693. if startime > 0 {
  1694. db = db.Where("o.dialysis_date>=?", startime)
  1695. }
  1696. if endtime > 0 {
  1697. db = db.Where("o.dialysis_date<=?", endtime)
  1698. }
  1699. err = db.Group("o.start_nurse,s.mode_id").Select("s.mode_id,s.patient_id,count(s.mode_id) as count,o.start_nurse").Joins("left join xt_schedule as s on s.patient_id = o.patient_id").Joins("left join xt_patients as p on p.id = o.patient_id ").Where("s.schedule_date = o.dialysis_date and s.status = 1 and o.user_org_id = ?", orgid).Scan(&order).Error
  1700. return order, err
  1701. }