index_evaluation_service.go 91KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931
  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 status = 1 AND 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 status = 1 AND 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 status = 1 AND 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 status = 1 AND 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 status = 1 AND org_id = ? AND user_type = 3 ", user_org_id).Offset(offset).Limit(limit).Scan(&datas)
  1236. } else {
  1237. userDb.Raw("select admin_user_id, user_name,org_id from sgj_user_admin_role Where status = 1 AND 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. //工作量统计
  1276. type AdminUser struct {
  1277. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1278. AdminUserId int64 `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
  1279. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  1280. UserName string `gorm:"column:user_name" json:"user_name" form:"user_name"`
  1281. UserType int64 `gorm:"column:user_type" json:"user_type" form:"user_type"`
  1282. }
  1283. func GetAllAdminUser(user_org_id int64) (datas []*AdminUser, err error) {
  1284. userDb := service.UserReadDB()
  1285. 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)
  1286. return datas, nil
  1287. }
  1288. //func FindOrgInspectionCount(user_org_id int64) (count int64, err error) {
  1289. // db := service.XTReadDB()
  1290. // err = db.Model(&models.QualityControlStandard{}).Where("status = 1 AND org_id = ? ", user_org_id).Count(&count).Error
  1291. // return
  1292. //}
  1293. type InspectionReference struct {
  1294. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1295. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  1296. ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
  1297. Project string `gorm:"column:project" json:"project" form:"project"`
  1298. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1299. ItemName string `gorm:"column:item_name" json:"item_name" form:"item_name"`
  1300. RangeType int64 `gorm:"column:range_type" json:"range_type" form:"range_type"`
  1301. RangeMin string `gorm:"column:range_min" json:"range_min" form:"range_min"`
  1302. RangeMax string `gorm:"column:range_max" json:"range_max" form:"range_max"`
  1303. RangeValue string `gorm:"column:range_value" json:"range_value" form:"range_value"`
  1304. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1305. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1306. }
  1307. func FindOrgQualityControlStandardInspectionReference(user_org_id int64) (references []*InspectionReference, err error) {
  1308. db := service.XTReadDB()
  1309. 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
  1310. return
  1311. }
  1312. func FindOrgInspectionReference(user_org_id int64, range_type int) (references []*models.InspectionReference, err error) {
  1313. db := service.XTReadDB()
  1314. if range_type == 1 {
  1315. 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
  1316. } else {
  1317. err = db.Model(&models.InspectionReference{}).Where("status = 1 AND org_id = ? AND range_type = 2", user_org_id).Find(&references).Error
  1318. }
  1319. return
  1320. }
  1321. func FindProcjectInspectionReference(user_org_id int64, project_id int64, item_id int64) (references models.InspectionReference, err error) {
  1322. db := service.XTReadDB()
  1323. 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
  1324. return
  1325. }
  1326. func FindOrgInspectionReferenceRangeTypeValue(user_org_id int64, project_id int64, item_id int64) (inspection []*models.Inspection, err error) {
  1327. db := service.XTReadDB()
  1328. 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
  1329. return
  1330. }
  1331. func FindOrgConfigRangeTypeValue(user_org_id int64, project_id int64, item_id int64) (qcs models.InspectionReference, err error) {
  1332. db := service.XTReadDB()
  1333. 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
  1334. return
  1335. }
  1336. 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) {
  1337. db := service.XTReadDB()
  1338. var items []*otherItemAmount
  1339. var tempErr error
  1340. var Total int64
  1341. selectContent := "CASE"
  1342. range_value_arr := strings.Split(range_value, ",")
  1343. 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)
  1344. if range_type == 1 {
  1345. 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).
  1346. Select("CASE WHEN inspect_value < " + range_value_arr[0] + " THEN " + "'" + "小于" + range_value_arr[0] + "'" +
  1347. " WHEN inspect_value >= " + range_value_arr[0] + " AND inspect_value <= " + range_value_arr[1] + " THEN " + "'" + range_value_arr[0] + "~" + range_value_arr[1] + "'" +
  1348. " WHEN inspect_value > " + range_value_arr[1] + " THEN " + "'" + "大于" + range_value_arr[1] + "'" +
  1349. " ELSE '未知' END AS name, COUNT(*) AS total",
  1350. ).Group("name").Scan(&items).Error
  1351. var isHasConditionOne bool = false
  1352. var isHasConditionTwo bool = false
  1353. var isHasConditionThree bool = false
  1354. for _, item := range items {
  1355. if item.Name == "大于"+range_value_arr[1] {
  1356. isHasConditionOne = true
  1357. }
  1358. if item.Name == "小于"+range_value_arr[0] {
  1359. isHasConditionTwo = true
  1360. }
  1361. if item.Name == range_value_arr[0]+"~"+range_value_arr[1] {
  1362. isHasConditionThree = true
  1363. }
  1364. }
  1365. if !isHasConditionOne {
  1366. newItem := &otherItemAmount{
  1367. Total: 0,
  1368. Name: "大于" + range_value_arr[1],
  1369. Ratio: "0",
  1370. }
  1371. items = append(items, newItem)
  1372. }
  1373. if !isHasConditionTwo {
  1374. newItem := &otherItemAmount{
  1375. Total: 0,
  1376. Name: "小于" + range_value_arr[0],
  1377. Ratio: "0",
  1378. }
  1379. items = append(items, newItem)
  1380. }
  1381. if !isHasConditionThree {
  1382. newItem := &otherItemAmount{
  1383. Total: 0,
  1384. Name: range_value_arr[0] + "~" + range_value_arr[1],
  1385. Ratio: "0",
  1386. }
  1387. items = append(items, newItem)
  1388. }
  1389. for _, item := range items {
  1390. if math.IsNaN(float64(item.Total) / float64(Total)) {
  1391. item.Ratio = "0.0"
  1392. } else {
  1393. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
  1394. item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1395. }
  1396. }
  1397. return items, tempErr
  1398. } else {
  1399. for _, item := range range_value_arr {
  1400. //selectContent = selectContent + " WHEN inspect_value =" + item + " THEN " + "'" + item + "'"
  1401. selectContent = selectContent + " WHEN inspect_value =" + "'" + item + "'" + " THEN " + "'" + item + "'"
  1402. }
  1403. 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).
  1404. Select(selectContent +
  1405. " ELSE '未知' END AS name, COUNT(*) AS total",
  1406. ).Group("name").Scan(&items).Error
  1407. for _, item := range items {
  1408. if math.IsNaN(float64(item.Total) / float64(Total)) {
  1409. item.Ratio = "0.0"
  1410. } else {
  1411. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
  1412. item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1413. }
  1414. }
  1415. return items, tempErr
  1416. }
  1417. }
  1418. type Inspection struct {
  1419. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1420. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1421. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  1422. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1423. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1424. ItemName string `gorm:"column:item_name" json:"item_name" form:"item_name"`
  1425. ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
  1426. InspectType int64 `gorm:"column:inspect_type" json:"inspect_type" form:"inspect_type"`
  1427. InspectValue string `gorm:"column:inspect_value" json:"inspect_value" form:"inspect_value"`
  1428. InspectDate int64 `gorm:"column:inspect_date" json:"inspect_date" form:"inspect_date"`
  1429. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1430. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1431. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  1432. Patient models.Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patient"`
  1433. }
  1434. func (Inspection) TableName() string {
  1435. return "xt_inspection"
  1436. }
  1437. 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) {
  1438. if range_type == 1 {
  1439. index := strings.Index(range_value, "小于")
  1440. indexTwo := strings.Index(range_value, "大于")
  1441. indexThree := strings.Index(range_value, "~")
  1442. if index != -1 {
  1443. value, _ := strconv.ParseFloat(strings.Replace(range_value, "小于", "", 1), 64)
  1444. db := service.XTReadDB()
  1445. offset := (page - 1) * limit
  1446. 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 {
  1447. return db.Where("status = 1 AND user_org_id = ?", user_org_id)
  1448. }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
  1449. return datas, total, err
  1450. } else if indexTwo != -1 {
  1451. value, _ := strconv.ParseFloat(strings.Replace(range_value, "大于", "", 1), 64)
  1452. db := service.XTReadDB()
  1453. offset := (page - 1) * limit
  1454. 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 {
  1455. return db.Where("status = 1 AND user_org_id = ?", user_org_id)
  1456. }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
  1457. return datas, total, err
  1458. } else if indexThree != -1 {
  1459. range_value_arr := strings.Split(range_value, "~")
  1460. fmt.Println(range_value_arr)
  1461. float1, err := strconv.ParseFloat(range_value_arr[0], 64)
  1462. float2, err := strconv.ParseFloat(range_value_arr[1], 64)
  1463. fmt.Println(err)
  1464. fmt.Println(float1)
  1465. fmt.Println(float2)
  1466. db := service.XTReadDB()
  1467. offset := (page - 1) * limit
  1468. 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 {
  1469. return db.Where("status = 1 AND user_org_id = ?", user_org_id)
  1470. }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
  1471. return datas, total, err
  1472. } else {
  1473. db := service.XTReadDB()
  1474. offset := (page - 1) * limit
  1475. 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 {
  1476. return db.Where("status = 1 AND user_org_id = ?", user_org_id)
  1477. }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
  1478. return datas, total, err
  1479. }
  1480. } else {
  1481. if range_value == "全部" {
  1482. db := service.XTReadDB()
  1483. offset := (page - 1) * limit
  1484. 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 {
  1485. return db.Where("status = 1 AND user_org_id = ?", user_org_id)
  1486. }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
  1487. return datas, total, err
  1488. } else {
  1489. db := service.XTReadDB()
  1490. offset := (page - 1) * limit
  1491. 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 {
  1492. return db.Where("status = 1 AND user_org_id = ?", user_org_id)
  1493. }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
  1494. return datas, total, err
  1495. }
  1496. }
  1497. }
  1498. type NewIndexDataStruct struct {
  1499. Date string `json:"date"`
  1500. Value string `json:"value"`
  1501. }
  1502. 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) {
  1503. db := service.XTReadDB()
  1504. 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
  1505. if err != nil {
  1506. return nil, err
  1507. }
  1508. return datas, nil
  1509. }
  1510. 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) {
  1511. db := service.XTReadDB()
  1512. var items []*otherItemAmount
  1513. var tempErr error
  1514. selectContent := "CASE"
  1515. range_value_arr := strings.Split(range_value, ",")
  1516. var Total int64
  1517. 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)
  1518. if range_type == 1 {
  1519. 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).
  1520. Select("CASE WHEN inspect_value < " + range_value_arr[0] + " THEN " + "'" + "小于" + range_value_arr[0] + "'" +
  1521. " WHEN inspect_value >= " + range_value_arr[0] + " AND inspect_value <= " + range_value_arr[1] + " THEN " + "'" + range_value_arr[0] + "~" + range_value_arr[1] + "'" +
  1522. " WHEN inspect_value > " + range_value_arr[1] + " THEN " + "'" + "大于" + range_value_arr[1] + "'" +
  1523. " ELSE '未知' END AS name, COUNT(*) AS total",
  1524. ).Group("name").Scan(&items).Error
  1525. var isHasConditionOne bool = false
  1526. var isHasConditionTwo bool = false
  1527. var isHasConditionThree bool = false
  1528. for _, item := range items {
  1529. if item.Name == "大于"+range_value_arr[1] {
  1530. isHasConditionOne = true
  1531. }
  1532. if item.Name == "小于"+range_value_arr[0] {
  1533. isHasConditionTwo = true
  1534. }
  1535. if item.Name == range_value_arr[0]+"~"+range_value_arr[1] {
  1536. isHasConditionThree = true
  1537. }
  1538. }
  1539. if !isHasConditionOne {
  1540. newItem := &otherItemAmount{
  1541. Total: 0,
  1542. Name: "大于" + range_value_arr[1],
  1543. Ratio: "0",
  1544. }
  1545. items = append(items, newItem)
  1546. }
  1547. if !isHasConditionTwo {
  1548. newItem := &otherItemAmount{
  1549. Total: 0,
  1550. Name: "小于" + range_value_arr[0],
  1551. Ratio: "0",
  1552. }
  1553. items = append(items, newItem)
  1554. }
  1555. if !isHasConditionThree {
  1556. newItem := &otherItemAmount{
  1557. Total: 0,
  1558. Name: range_value_arr[0] + "~" + range_value_arr[1],
  1559. Ratio: "0",
  1560. }
  1561. items = append(items, newItem)
  1562. }
  1563. for _, item := range items {
  1564. if math.IsNaN(float64(item.Total) / float64(Total)) {
  1565. item.Ratio = "0.0"
  1566. } else {
  1567. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
  1568. item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1569. }
  1570. }
  1571. return items, tempErr
  1572. } else {
  1573. for _, item := range range_value_arr {
  1574. selectContent = selectContent + " WHEN inspect_value =" + "'" + item + "'" + " THEN " + "'" + item + "'"
  1575. }
  1576. 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).
  1577. Select(selectContent +
  1578. " ELSE '未知' END AS name, COUNT(*) AS total",
  1579. ).Group("name").Scan(&items).Error
  1580. for _, item := range items {
  1581. if math.IsNaN(float64(item.Total) / float64(Total)) {
  1582. item.Ratio = "0.0"
  1583. } else {
  1584. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
  1585. item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1586. }
  1587. }
  1588. return items, tempErr
  1589. }
  1590. }
  1591. type VMPatient struct {
  1592. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1593. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1594. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  1595. Name string `gorm:"column:name" json:"name" form:"name"`
  1596. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  1597. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1598. }
  1599. func (VMPatient) TableName() string {
  1600. return "xt_patients"
  1601. }
  1602. func GetOrgPatients(user_org_id int64) (patient *[]VMPatient, err error) {
  1603. db := service.XTReadDB()
  1604. var tempPatient []VMPatient
  1605. findErr := db.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND lapseto = 1", user_org_id).Find(&tempPatient).Error
  1606. if findErr == gorm.ErrRecordNotFound {
  1607. return nil, nil
  1608. }
  1609. if findErr != nil {
  1610. return nil, findErr
  1611. }
  1612. return &tempPatient, nil
  1613. }
  1614. func FindOrgQualityControlStandardInspectionReferenceById(user_org_id int64, project_id int64, item_id int64) (references InspectionReference, err error) {
  1615. db := service.XTReadDB()
  1616. 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
  1617. return
  1618. }
  1619. func FindOrgInspectionCount(user_org_id int64) (count int64, err error) {
  1620. db := service.XTReadDB()
  1621. err = db.Model(&models.InspectionReference{}).Where("status = 1 AND org_id = ?", user_org_id).Count(&count).Error
  1622. return
  1623. }
  1624. func GetOrderDialysisCount(orgid int64, startime int64, endtime int64) (order []*models.BloodDialysisOrderOne, err error) {
  1625. db := service.XTReadDB()
  1626. table := db.Table("xt_schedule as s")
  1627. fmt.Println(table)
  1628. d := db.Table("xt_patients as p")
  1629. fmt.Println(d)
  1630. db = db.Table("xt_dialysis_order as o").Where("o.status = 1")
  1631. if orgid > 0 {
  1632. db = db.Where("o.user_org_id = ?", orgid)
  1633. }
  1634. if startime > 0 {
  1635. db = db.Where("o.dialysis_date>=?", startime)
  1636. }
  1637. if endtime > 0 {
  1638. db = db.Where("o.dialysis_date<=?", endtime)
  1639. }
  1640. 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
  1641. return order, err
  1642. }