index_evaluation_service.go 88KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883
  1. package statistics_service
  2. import (
  3. "Xcx_New/models"
  4. "Xcx_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. switch statistics_type {
  992. case 1:
  993. var Total int64
  994. db.Table("xt_dialysis_prescription as p").Joins("join xt_schedule sch On sch.schedule_date = p.record_date AND sch.patient_id = p.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("p.user_org_id = ? AND p.status = 1 AND p.record_date >= ? AND p.record_date <= ? AND p.creater <> 0 ", user_org_id, start_time, end_time).Count(&Total)
  995. for _, item := range datas {
  996. var total int64
  997. db.Table("xt_dialysis_prescription as p").Joins("join xt_schedule sch On sch.schedule_date = p.record_date AND sch.patient_id = p.patient_id AND sch.user_org_id = ? AND sch.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 <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&total)
  998. item.PCount = total
  999. if math.IsNaN(float64(item.PCount) / float64(Total)) {
  1000. item.PRatio = "0.0"
  1001. } else {
  1002. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.PCount)/float64(Total))*100), 64)
  1003. item.PRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1004. }
  1005. }
  1006. break
  1007. case 2:
  1008. var Total int64
  1009. 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)
  1010. for _, item := range datas {
  1011. var total int64
  1012. 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)
  1013. item.CourseCount = total
  1014. if math.IsNaN(float64(item.CourseCount) / float64(Total)) {
  1015. item.CourseRatio = "0.0"
  1016. } else {
  1017. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.CourseCount)/float64(Total))*100), 64)
  1018. item.CourseRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1019. }
  1020. }
  1021. break
  1022. case 3:
  1023. var Total int64
  1024. 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)
  1025. for _, item := range datas {
  1026. var total int64
  1027. 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)
  1028. item.RescueCount = total
  1029. if math.IsNaN(float64(item.RescueCount) / float64(Total)) {
  1030. item.RescueRatio = "0.0"
  1031. } else {
  1032. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.RescueCount)/float64(Total))*100), 64)
  1033. item.RescueRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1034. }
  1035. }
  1036. break
  1037. }
  1038. if err != nil {
  1039. return nil, err
  1040. }
  1041. fmt.Println(datas)
  1042. return datas, nil
  1043. }
  1044. func GetDoctorWorkloadTableData(user_org_id int64, start_time int64, end_time int64, admin_user_id int64) (datas []*VMUserAdminRole, err error) {
  1045. userDb := service.UserReadDB()
  1046. db := service.XTReadDB()
  1047. if admin_user_id == 0 {
  1048. 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)
  1049. } else {
  1050. 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)
  1051. }
  1052. for _, item := range datas {
  1053. var Total int64
  1054. var TotalOne int64
  1055. var TotalTwo int64
  1056. db.Table("xt_dialysis_prescription as p").Joins("join xt_schedule sch On sch.schedule_date = p.record_date AND sch.patient_id = p.patient_id AND sch.user_org_id = ? AND sch.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 <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
  1057. 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)
  1058. 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)
  1059. item.PCount = Total
  1060. item.CourseCount = TotalOne
  1061. item.RescueCount = TotalTwo
  1062. }
  1063. if err != nil {
  1064. return nil, err
  1065. }
  1066. return datas, nil
  1067. }
  1068. func GetNurseWorkloadChartData(user_org_id int64, start_time int64, end_time int64, statistics_type int, admin_user_id int64) (datas []*VMUserAdminRole, err error) {
  1069. userDb := service.UserReadDB()
  1070. db := service.XTReadDB()
  1071. if admin_user_id == 0 {
  1072. 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)
  1073. } else {
  1074. 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)
  1075. }
  1076. var NewTotalOne int64
  1077. var NewTotalThree int64
  1078. var NewTotalFour int64
  1079. var NewTotalFive int64
  1080. var NewTotalSix int64
  1081. var NewTotalSeven int64
  1082. var NewTotalEight int64
  1083. 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)
  1084. 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)
  1085. 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)
  1086. 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)
  1087. 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)
  1088. 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)
  1089. 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)
  1090. switch statistics_type {
  1091. case 2:
  1092. for _, item := range datas {
  1093. var Total int64
  1094. 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)
  1095. item.PunctureCount = Total
  1096. if math.IsNaN(float64(item.PunctureCount) / float64(NewTotalOne)) {
  1097. item.PunctureRatio = "0.0"
  1098. } else {
  1099. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.PunctureCount)/float64(NewTotalOne))*100), 64)
  1100. item.PunctureRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1101. }
  1102. }
  1103. break
  1104. case 1:
  1105. for _, item := range datas {
  1106. var Total int64
  1107. 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)
  1108. item.CureCount = Total
  1109. if math.IsNaN(float64(item.CureCount) / float64(NewTotalThree)) {
  1110. item.CureRatio = "0.0"
  1111. } else {
  1112. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.CureCount)/float64(NewTotalThree))*100), 64)
  1113. item.CureRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1114. }
  1115. }
  1116. break
  1117. case 3:
  1118. for _, item := range datas {
  1119. var Total int64
  1120. 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)
  1121. item.MissionCount = Total
  1122. if math.IsNaN(float64(item.MissionCount) / float64(NewTotalFour)) {
  1123. item.MissionRatio = "0.0"
  1124. } else {
  1125. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.MissionCount)/float64(NewTotalFour))*100), 64)
  1126. item.MissionRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1127. }
  1128. }
  1129. break
  1130. case 4:
  1131. for _, item := range datas {
  1132. var Total int64
  1133. 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)
  1134. item.ChangeNuserCount = Total
  1135. if math.IsNaN(float64(item.ChangeNuserCount) / float64(NewTotalFive)) {
  1136. item.ChangeRatio = "0.0"
  1137. } else {
  1138. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.ChangeNuserCount)/float64(NewTotalFive))*100), 64)
  1139. item.ChangeRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1140. }
  1141. }
  1142. break
  1143. case 5:
  1144. for _, item := range datas {
  1145. var Total int64
  1146. 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)
  1147. item.DiffiCultPuntureNuserCount = Total
  1148. if math.IsNaN(float64(item.DiffiCultPuntureNuserCount) / float64(NewTotalSix)) {
  1149. item.DiffiCultNuserRatio = "0.0"
  1150. } else {
  1151. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.DiffiCultPuntureNuserCount)/float64(NewTotalSix))*100), 64)
  1152. item.DiffiCultNuserRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1153. }
  1154. }
  1155. break
  1156. case 6:
  1157. for _, item := range datas {
  1158. var Total int64
  1159. 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)
  1160. item.NewNuserCount = Total
  1161. if math.IsNaN(float64(item.NewNuserCount) / float64(NewTotalSeven)) {
  1162. item.NewNuserRatio = "0.0"
  1163. } else {
  1164. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.NewNuserCount)/float64(NewTotalSeven))*100), 64)
  1165. item.NewNuserRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1166. }
  1167. }
  1168. break
  1169. case 7:
  1170. for _, item := range datas {
  1171. var Total int64
  1172. 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)
  1173. item.StartNuserCount = Total
  1174. if math.IsNaN(float64(item.StartNuserCount) / float64(NewTotalEight)) {
  1175. item.StartNuserRatio = "0.0"
  1176. } else {
  1177. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.StartNuserCount)/float64(NewTotalEight))*100), 64)
  1178. item.StartNuserRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1179. }
  1180. }
  1181. break
  1182. }
  1183. if err != nil {
  1184. return nil, err
  1185. }
  1186. return datas, nil
  1187. }
  1188. 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) {
  1189. userDb := service.UserReadDB()
  1190. db := service.XTReadDB()
  1191. //var tempConfig models.Dataconfig
  1192. offset := (page - 1) * limit
  1193. //db.Model(&models.Dataconfig{}).Where("name = '血管通路' AND module = 'hemodialysis' AND field_name = 'vascular_access_desc' AND parent_id = 0").First(&tempConfig)
  1194. if admin_user_id == 0 {
  1195. 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)
  1196. } else {
  1197. 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)
  1198. }
  1199. for _, item := range datas {
  1200. var Total int64
  1201. var TotalTwo int64
  1202. var TotalThree int64
  1203. var TotalFour int64
  1204. var TotalFive int64
  1205. var TotalSix int64
  1206. var TotalSeven int64
  1207. //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)
  1208. //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)
  1209. 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)
  1210. 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)
  1211. 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)
  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.change_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalFour)
  1213. 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)
  1214. 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)
  1215. 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)
  1216. item.PunctureCount = Total
  1217. item.CureCount = TotalTwo
  1218. item.MissionCount = TotalThree
  1219. item.ChangeNuserCount = TotalFour
  1220. item.DiffiCultPuntureNuserCount = TotalFive
  1221. item.NewNuserCount = TotalSix
  1222. item.StartNuserCount = TotalSeven
  1223. }
  1224. if err != nil {
  1225. return nil, AdminTotal, err
  1226. }
  1227. return datas, AdminTotal, nil
  1228. }
  1229. //工作量统计
  1230. type AdminUser struct {
  1231. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1232. AdminUserId int64 `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
  1233. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  1234. UserName string `gorm:"column:user_name" json:"user_name" form:"user_name"`
  1235. UserType int64 `gorm:"column:user_type" json:"user_type" form:"user_type"`
  1236. }
  1237. func GetAllAdminUser(user_org_id int64) (datas []*AdminUser, err error) {
  1238. userDb := service.UserReadDB()
  1239. 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)
  1240. return datas, nil
  1241. }
  1242. //func FindOrgInspectionCount(user_org_id int64) (count int64, err error) {
  1243. // db := service.XTReadDB()
  1244. // err = db.Model(&models.QualityControlStandard{}).Where("status = 1 AND org_id = ? ", user_org_id).Count(&count).Error
  1245. // return
  1246. //}
  1247. type InspectionReference struct {
  1248. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1249. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  1250. ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
  1251. Project string `gorm:"column:project" json:"project" form:"project"`
  1252. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1253. ItemName string `gorm:"column:item_name" json:"item_name" form:"item_name"`
  1254. RangeType int64 `gorm:"column:range_type" json:"range_type" form:"range_type"`
  1255. RangeMin string `gorm:"column:range_min" json:"range_min" form:"range_min"`
  1256. RangeMax string `gorm:"column:range_max" json:"range_max" form:"range_max"`
  1257. RangeValue string `gorm:"column:range_value" json:"range_value" form:"range_value"`
  1258. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1259. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1260. }
  1261. func FindOrgQualityControlStandardInspectionReference(user_org_id int64) (references []*InspectionReference, err error) {
  1262. db := service.XTReadDB()
  1263. 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
  1264. return
  1265. }
  1266. func FindOrgInspectionReference(user_org_id int64, range_type int) (references []*models.InspectionReference, err error) {
  1267. db := service.XTReadDB()
  1268. if range_type == 1 {
  1269. 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
  1270. } else {
  1271. err = db.Model(&models.InspectionReference{}).Where("status = 1 AND org_id = ? AND range_type = 2", user_org_id).Find(&references).Error
  1272. }
  1273. return
  1274. }
  1275. func FindProcjectInspectionReference(user_org_id int64, project_id int64, item_id int64) (references models.InspectionReference, err error) {
  1276. db := service.XTReadDB()
  1277. 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
  1278. return
  1279. }
  1280. func FindOrgInspectionReferenceRangeTypeValue(user_org_id int64, project_id int64, item_id int64) (inspection []*models.Inspection, err error) {
  1281. db := service.XTReadDB()
  1282. 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
  1283. return
  1284. }
  1285. func FindOrgConfigRangeTypeValue(user_org_id int64, project_id int64, item_id int64) (qcs models.InspectionReference, err error) {
  1286. db := service.XTReadDB()
  1287. 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
  1288. return
  1289. }
  1290. 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) {
  1291. db := service.XTReadDB()
  1292. var items []*otherItemAmount
  1293. var tempErr error
  1294. var Total int64
  1295. selectContent := "CASE"
  1296. range_value_arr := strings.Split(range_value, ",")
  1297. 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)
  1298. if range_type == 1 {
  1299. 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).
  1300. Select("CASE WHEN inspect_value < " + range_value_arr[0] + " THEN " + "'" + "小于" + range_value_arr[0] + "'" +
  1301. " WHEN inspect_value >= " + range_value_arr[0] + " AND inspect_value <= " + range_value_arr[1] + " THEN " + "'" + range_value_arr[0] + "~" + range_value_arr[1] + "'" +
  1302. " WHEN inspect_value > " + range_value_arr[1] + " THEN " + "'" + "大于" + range_value_arr[1] + "'" +
  1303. " ELSE '未知' END AS name, COUNT(*) AS total",
  1304. ).Group("name").Scan(&items).Error
  1305. var isHasConditionOne bool = false
  1306. var isHasConditionTwo bool = false
  1307. var isHasConditionThree bool = false
  1308. for _, item := range items {
  1309. if item.Name == "大于"+range_value_arr[1] {
  1310. isHasConditionOne = true
  1311. }
  1312. if item.Name == "小于"+range_value_arr[0] {
  1313. isHasConditionTwo = true
  1314. }
  1315. if item.Name == range_value_arr[0]+"~"+range_value_arr[1] {
  1316. isHasConditionThree = true
  1317. }
  1318. }
  1319. if !isHasConditionOne {
  1320. newItem := &otherItemAmount{
  1321. Total: 0,
  1322. Name: "大于" + range_value_arr[1],
  1323. Ratio: "0",
  1324. }
  1325. items = append(items, newItem)
  1326. }
  1327. if !isHasConditionTwo {
  1328. newItem := &otherItemAmount{
  1329. Total: 0,
  1330. Name: "小于" + range_value_arr[0],
  1331. Ratio: "0",
  1332. }
  1333. items = append(items, newItem)
  1334. }
  1335. if !isHasConditionThree {
  1336. newItem := &otherItemAmount{
  1337. Total: 0,
  1338. Name: range_value_arr[0] + "~" + range_value_arr[1],
  1339. Ratio: "0",
  1340. }
  1341. items = append(items, newItem)
  1342. }
  1343. for _, item := range items {
  1344. if math.IsNaN(float64(item.Total) / float64(Total)) {
  1345. item.Ratio = "0.0"
  1346. } else {
  1347. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
  1348. item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1349. }
  1350. }
  1351. return items, tempErr
  1352. } else {
  1353. for _, item := range range_value_arr {
  1354. //selectContent = selectContent + " WHEN inspect_value =" + item + " THEN " + "'" + item + "'"
  1355. selectContent = selectContent + " WHEN inspect_value =" + "'" + item + "'" + " THEN " + "'" + item + "'"
  1356. }
  1357. 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).
  1358. Select(selectContent +
  1359. " ELSE '未知' END AS name, COUNT(*) AS total",
  1360. ).Group("name").Scan(&items).Error
  1361. for _, item := range items {
  1362. if math.IsNaN(float64(item.Total) / float64(Total)) {
  1363. item.Ratio = "0.0"
  1364. } else {
  1365. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
  1366. item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1367. }
  1368. }
  1369. return items, tempErr
  1370. }
  1371. }
  1372. type Inspection struct {
  1373. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1374. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1375. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  1376. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1377. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1378. ItemName string `gorm:"column:item_name" json:"item_name" form:"item_name"`
  1379. ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
  1380. InspectType int64 `gorm:"column:inspect_type" json:"inspect_type" form:"inspect_type"`
  1381. InspectValue string `gorm:"column:inspect_value" json:"inspect_value" form:"inspect_value"`
  1382. InspectDate int64 `gorm:"column:inspect_date" json:"inspect_date" form:"inspect_date"`
  1383. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1384. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1385. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  1386. Patient models.Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patient"`
  1387. }
  1388. func (Inspection) TableName() string {
  1389. return "xt_inspection"
  1390. }
  1391. 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) {
  1392. if range_type == 1 {
  1393. index := strings.Index(range_value, "小于")
  1394. indexTwo := strings.Index(range_value, "大于")
  1395. indexThree := strings.Index(range_value, "~")
  1396. if index != -1 {
  1397. value, _ := strconv.ParseFloat(strings.Replace(range_value, "小于", "", 1), 64)
  1398. db := service.XTReadDB()
  1399. offset := (page - 1) * limit
  1400. 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 {
  1401. return db.Where("status = 1 AND user_org_id = ?", user_org_id)
  1402. }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
  1403. return datas, total, err
  1404. } else if indexTwo != -1 {
  1405. value, _ := strconv.ParseFloat(strings.Replace(range_value, "大于", "", 1), 64)
  1406. db := service.XTReadDB()
  1407. offset := (page - 1) * limit
  1408. 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 {
  1409. return db.Where("status = 1 AND user_org_id = ?", user_org_id)
  1410. }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
  1411. return datas, total, err
  1412. } else if indexThree != -1 {
  1413. range_value_arr := strings.Split(range_value, "~")
  1414. fmt.Println(range_value_arr)
  1415. float1, err := strconv.ParseFloat(range_value_arr[0], 64)
  1416. float2, err := strconv.ParseFloat(range_value_arr[1], 64)
  1417. fmt.Println(err)
  1418. fmt.Println(float1)
  1419. fmt.Println(float2)
  1420. db := service.XTReadDB()
  1421. offset := (page - 1) * limit
  1422. 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 {
  1423. return db.Where("status = 1 AND user_org_id = ?", user_org_id)
  1424. }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
  1425. return datas, total, err
  1426. } else {
  1427. db := service.XTReadDB()
  1428. offset := (page - 1) * limit
  1429. 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 {
  1430. return db.Where("status = 1 AND user_org_id = ?", user_org_id)
  1431. }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
  1432. return datas, total, err
  1433. }
  1434. } else {
  1435. if range_value == "全部" {
  1436. db := service.XTReadDB()
  1437. offset := (page - 1) * limit
  1438. 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 {
  1439. return db.Where("status = 1 AND user_org_id = ?", user_org_id)
  1440. }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
  1441. return datas, total, err
  1442. } else {
  1443. db := service.XTReadDB()
  1444. offset := (page - 1) * limit
  1445. 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 {
  1446. return db.Where("status = 1 AND user_org_id = ?", user_org_id)
  1447. }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
  1448. return datas, total, err
  1449. }
  1450. }
  1451. }
  1452. type NewIndexDataStruct struct {
  1453. Date string `json:"date"`
  1454. Value string `json:"value"`
  1455. }
  1456. 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) {
  1457. db := service.XTReadDB()
  1458. 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
  1459. if err != nil {
  1460. return nil, err
  1461. }
  1462. return datas, nil
  1463. }
  1464. 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) {
  1465. db := service.XTReadDB()
  1466. var items []*otherItemAmount
  1467. var tempErr error
  1468. selectContent := "CASE"
  1469. range_value_arr := strings.Split(range_value, ",")
  1470. var Total int64
  1471. 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)
  1472. if range_type == 1 {
  1473. 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).
  1474. Select("CASE WHEN inspect_value < " + range_value_arr[0] + " THEN " + "'" + "小于" + range_value_arr[0] + "'" +
  1475. " WHEN inspect_value >= " + range_value_arr[0] + " AND inspect_value <= " + range_value_arr[1] + " THEN " + "'" + range_value_arr[0] + "~" + range_value_arr[1] + "'" +
  1476. " WHEN inspect_value > " + range_value_arr[1] + " THEN " + "'" + "大于" + range_value_arr[1] + "'" +
  1477. " ELSE '未知' END AS name, COUNT(*) AS total",
  1478. ).Group("name").Scan(&items).Error
  1479. var isHasConditionOne bool = false
  1480. var isHasConditionTwo bool = false
  1481. var isHasConditionThree bool = false
  1482. for _, item := range items {
  1483. if item.Name == "大于"+range_value_arr[1] {
  1484. isHasConditionOne = true
  1485. }
  1486. if item.Name == "小于"+range_value_arr[0] {
  1487. isHasConditionTwo = true
  1488. }
  1489. if item.Name == range_value_arr[0]+"~"+range_value_arr[1] {
  1490. isHasConditionThree = true
  1491. }
  1492. }
  1493. if !isHasConditionOne {
  1494. newItem := &otherItemAmount{
  1495. Total: 0,
  1496. Name: "大于" + range_value_arr[1],
  1497. Ratio: "0",
  1498. }
  1499. items = append(items, newItem)
  1500. }
  1501. if !isHasConditionTwo {
  1502. newItem := &otherItemAmount{
  1503. Total: 0,
  1504. Name: "小于" + range_value_arr[0],
  1505. Ratio: "0",
  1506. }
  1507. items = append(items, newItem)
  1508. }
  1509. if !isHasConditionThree {
  1510. newItem := &otherItemAmount{
  1511. Total: 0,
  1512. Name: range_value_arr[0] + "~" + range_value_arr[1],
  1513. Ratio: "0",
  1514. }
  1515. items = append(items, newItem)
  1516. }
  1517. for _, item := range items {
  1518. if math.IsNaN(float64(item.Total) / float64(Total)) {
  1519. item.Ratio = "0.0"
  1520. } else {
  1521. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
  1522. item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1523. }
  1524. }
  1525. return items, tempErr
  1526. } else {
  1527. for _, item := range range_value_arr {
  1528. selectContent = selectContent + " WHEN inspect_value =" + "'" + item + "'" + " THEN " + "'" + item + "'"
  1529. }
  1530. 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).
  1531. Select(selectContent +
  1532. " ELSE '未知' END AS name, COUNT(*) AS total",
  1533. ).Group("name").Scan(&items).Error
  1534. for _, item := range items {
  1535. if math.IsNaN(float64(item.Total) / float64(Total)) {
  1536. item.Ratio = "0.0"
  1537. } else {
  1538. float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
  1539. item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
  1540. }
  1541. }
  1542. return items, tempErr
  1543. }
  1544. }
  1545. type VMPatient struct {
  1546. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1547. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1548. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  1549. Name string `gorm:"column:name" json:"name" form:"name"`
  1550. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  1551. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1552. }
  1553. func (VMPatient) TableName() string {
  1554. return "xt_patients"
  1555. }
  1556. func GetOrgPatients(user_org_id int64) (patient *[]VMPatient, err error) {
  1557. db := service.XTReadDB()
  1558. var tempPatient []VMPatient
  1559. findErr := db.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND lapseto = 1", user_org_id).Find(&tempPatient).Error
  1560. if findErr == gorm.ErrRecordNotFound {
  1561. return nil, nil
  1562. }
  1563. if findErr != nil {
  1564. return nil, findErr
  1565. }
  1566. return &tempPatient, nil
  1567. }
  1568. func FindOrgQualityControlStandardInspectionReferenceById(user_org_id int64, project_id int64, item_id int64) (references InspectionReference, err error) {
  1569. db := service.XTReadDB()
  1570. 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
  1571. return
  1572. }
  1573. func FindOrgInspectionCount(user_org_id int64) (count int64, err error) {
  1574. db := service.XTReadDB()
  1575. err = db.Model(&models.InspectionReference{}).Where("status = 1 AND org_id = ?", user_org_id).Count(&count).Error
  1576. return
  1577. }
  1578. func GetOrderDialysisCount(orgid int64, startime int64, endtime int64) (order []*models.BloodDialysisOrderOne, err error) {
  1579. db := service.XTReadDB()
  1580. table := db.Table("xt_schedule as s")
  1581. fmt.Println(table)
  1582. d := db.Table("xt_patients as p")
  1583. fmt.Println(d)
  1584. db = db.Table("xt_dialysis_order as o").Where("o.status = 1")
  1585. if orgid > 0 {
  1586. db = db.Where("o.user_org_id = ?", orgid)
  1587. }
  1588. if startime > 0 {
  1589. db = db.Where("o.dialysis_date>=?", startime)
  1590. }
  1591. if endtime > 0 {
  1592. db = db.Where("o.dialysis_date<=?", endtime)
  1593. }
  1594. 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
  1595. return order, err
  1596. }