mobile_dialysis_service.go 170KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619
  1. package service
  2. import (
  3. "XT_New/models"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/jinzhu/gorm"
  7. "strconv"
  8. "time"
  9. )
  10. // func GetSchedualPatients(orgID int64) ([]*MDialysisScheduleVM, error) {
  11. // var vms []*MDialysisScheduleVM
  12. // err := readDb.
  13. // Table("xt_schedule as sch").
  14. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  15. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  16. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  17. // Preload("TreatmentMode", "status = 1").
  18. // Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  19. // Preload("DialysisOrder.MonitoringRecords", "status = 1 AND user_org_id = ?", orgID).
  20. // Where("sch.status = 1 AND sch.user_org_id = ? AND schedule_date = 1536768000", orgID).
  21. // Find(&vms).
  22. // Error
  23. // return vms, err
  24. // }
  25. func MobileGetDialysisScheduals(orgID int64, scheduleDate int64, scheduleType int64) ([]*MDialysisScheduleVMForList, error) {
  26. var vms []*MDialysisScheduleVMForList
  27. db := readDb.
  28. Table("xt_schedule as sch").
  29. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  30. if scheduleDate != 0 {
  31. db = db.Where("schedule_date = ?", scheduleDate)
  32. }
  33. if scheduleType != 0 {
  34. db = db.Where("schedule_type = ?", scheduleType)
  35. }
  36. err := db.Find(&vms).Error
  37. return vms, err
  38. }
  39. func MobileGetWaitingScheduals(orgID int64, scheduleDate int64) ([]*MDialysisScheduleVM, error) {
  40. var vms []*MDialysisScheduleVM
  41. db := readDb.
  42. Table("xt_schedule as sch").
  43. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  44. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  45. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  46. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  47. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  48. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
  49. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  50. Preload("Advices", "status = 1 AND user_org_id = ? AND advice_type = 2 ", orgID).
  51. Preload("TreatmentMode", "status = 1").
  52. Preload("TreatmentSummary", "status = 1 AND user_org_id = ?", orgID).
  53. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  54. if scheduleDate != 0 {
  55. db = db.Where("schedule_date = ?", scheduleDate)
  56. }
  57. err := db.Find(&vms).Error
  58. return vms, err
  59. }
  60. type VMTreatmentSummary struct {
  61. ID int64 `gorm:"column:id" json:"id"`
  62. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  63. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  64. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  65. DialysisSummary string `gorm:"column:dialysis_summary" json:"dialysis_summary" form:"dialysis_summary"`
  66. }
  67. func (VMTreatmentSummary) TableName() string {
  68. return "xt_treatment_summary"
  69. }
  70. type AssessmentAfterDislysis struct {
  71. ID int64 `gorm:"column:id" json:"id"`
  72. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  73. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  74. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  75. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  76. Status int64 `gorm:"column:status" json:"status"`
  77. }
  78. func (AssessmentAfterDislysis) TableName() string {
  79. return "xt_assessment_after_dislysis"
  80. }
  81. type MDialysisScheduleVM struct {
  82. ID int64 `gorm:"column:id" json:"id"`
  83. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  84. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  85. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  86. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  87. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  88. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  89. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  90. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  91. Status int64 `gorm:"column:status" json:"status"`
  92. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  93. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  94. DialysisOrder *MDialysisOrderVMList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  95. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  96. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  97. AssessmentAfterDislysis *AssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  98. HisAdvices []*VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  99. Advices []*VMDoctorAdvice `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  100. TreatmentSummary *VMTreatmentSummary `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  101. }
  102. func (MDialysisScheduleVM) TableName() string {
  103. return "xt_schedule"
  104. }
  105. type MDialysisScheduleVMForList struct {
  106. ID int64 `gorm:"column:id" json:"id"`
  107. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  108. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  109. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  110. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  111. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  112. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  113. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  114. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  115. Status int64 `gorm:"column:status" json:"status"`
  116. SchedualPatient *models.MSchedualPatientList `gorm:"ForeignKey:PatientId" json:"patient"`
  117. DeviceNumber *models.MDeviceNumberForList `gorm:"ForeignKey:BedId" json:"device_number"`
  118. DialysisOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  119. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  120. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  121. AssessmentAfterDislysis *models.VMAssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  122. HisAdvices []VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  123. Advices []models.VMDoctorAdviceForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  124. TreatmentSummary *models.VMTreatmentSummaryForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  125. }
  126. func (MDialysisScheduleVMForList) TableName() string {
  127. return "xt_schedule"
  128. }
  129. type MDeviceNumberVM struct {
  130. models.DeviceNumber
  131. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  132. }
  133. func (MDeviceNumberVM) TableName() string {
  134. return "xt_device_number"
  135. }
  136. type MSchedualPatientVMList struct {
  137. ID int64 `gorm:"column:id" json:"id" form:"id"`
  138. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  139. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  140. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  141. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  142. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  143. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  144. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  145. Age int64 `gorm:"column:age" json:"age"`
  146. Name string `gorm:"column:name" json:"name" form:"name"`
  147. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  148. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  149. }
  150. func (MSchedualPatientVMList) TableName() string {
  151. return "xt_patients"
  152. }
  153. type MSchedualPatientVM struct {
  154. ID int64 `gorm:"column:id" json:"id" form:"id"`
  155. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  156. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  157. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  158. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  159. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  160. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  161. Source int64 `gorm:"column:source" json:"source" form:"source"`
  162. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  163. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  164. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  165. Name string `gorm:"column:name" json:"name" form:"name"`
  166. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  167. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  168. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  169. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  170. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  171. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  172. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  173. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  174. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  175. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  176. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  177. Height int64 `gorm:"column:height" json:"height" form:"height"`
  178. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  179. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  180. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  181. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  182. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  183. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  184. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  185. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  186. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  187. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  188. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  189. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  190. Children int64 `gorm:"column:children" json:"children" form:"children"`
  191. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  192. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  193. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  194. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  195. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  196. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  197. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  198. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  199. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  200. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  201. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  202. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  203. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  204. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  205. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  206. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  207. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  208. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  209. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  210. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  211. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  212. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  213. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  214. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  215. Status int64 `gorm:"column:status" json:"status" form:"status"`
  216. Age int64 `gorm:"column:age" json:"age"`
  217. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  218. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  219. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  220. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  221. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  222. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  223. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  224. }
  225. func (MSchedualPatientVM) TableName() string {
  226. return "xt_patients"
  227. }
  228. type MDialysisOrderVM struct {
  229. ID int64 `gorm:"column:id" json:"id"`
  230. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  231. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  232. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  233. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  234. Stage int64 `gorm:"column:stage" json:"stage"`
  235. // Remark string `gorm:"column:remark" json:"remark"`
  236. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  237. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  238. FinishNurse int64 `gorm:"column:finish_nurse" json:"finish_nurse"`
  239. Status int64 `gorm:"column:status" json:"status"`
  240. PunctureNurse int64 `gorm:"column:puncture_nurse" json:"puncture_nurse"`
  241. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  242. MonitoringRecords []*models.MonitoringRecord `gorm:"ForeignKey:DialysisOrderId" json:"monitoring_records"`
  243. Creator int64 `gorm:"column:creator" json:"creator"`
  244. Modifier int64 `gorm:"column:modifier" json:"modifier"`
  245. FinishCreator int64 `gorm:"column:finish_creator" json:"finish_creator"`
  246. FinishModifier int64 `gorm:"column:finish_modifier" json:"finish_modifier"`
  247. SchedualType int64 `gorm:"column:schedual_type" json:"schedual_type"`
  248. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  249. }
  250. func (MDialysisOrderVM) TableName() string {
  251. return "xt_dialysis_order"
  252. }
  253. type MDialysisOrderVMList struct {
  254. ID int64 `gorm:"column:id" json:"id"`
  255. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  256. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  257. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  258. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  259. Stage int64 `gorm:"column:stage" json:"stage"`
  260. // Remark string `gorm:"column:remark" json:"remark"`
  261. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  262. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  263. Status int64 `gorm:"column:status" json:"status"`
  264. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  265. Creator int64 `gorm:"column:creator" json:"creator"`
  266. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  267. }
  268. func (MDialysisOrderVMList) TableName() string {
  269. return "xt_dialysis_order"
  270. }
  271. type VMDoctorAdvice struct {
  272. ID int64 `gorm:"column:id" json:"id" form:"id"`
  273. GroupNo int64 `gorm:"column:groupno" json:"groupno" form:"groupno"`
  274. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  275. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  276. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  277. Status int64 `gorm:"column:status" json:"status" form:"status"`
  278. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  279. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  280. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  281. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  282. ParentId int64 `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
  283. }
  284. func (VMDoctorAdvice) TableName() string {
  285. return "xt_doctor_advice"
  286. }
  287. type VMHisDoctorAdviceInfo struct {
  288. ID int64 `gorm:"column:id" json:"id" form:"id"`
  289. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  290. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  291. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  292. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  293. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  294. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  295. }
  296. func (VMHisDoctorAdviceInfo) TableName() string {
  297. return "his_doctor_advice_info"
  298. }
  299. type VMAssessmentAfterDislysis struct {
  300. ID int64 `gorm:"column:id" json:"id"`
  301. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  302. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  303. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  304. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  305. Status int64 `gorm:"column:status" json:"status"`
  306. }
  307. func (VMAssessmentAfterDislysis) TableName() string {
  308. return "xt_assessment_after_dislysis"
  309. }
  310. // 获取透析记录
  311. func MobileGetDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  312. var record models.DialysisOrder
  313. err := readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  314. if err != nil {
  315. if err == gorm.ErrRecordNotFound {
  316. return nil, nil
  317. } else {
  318. return nil, err
  319. }
  320. }
  321. return &record, nil
  322. }
  323. // 用户基本信息
  324. func MobileGetPatientDetail(orgID int64, patientID int64) (*MPatient, error) {
  325. var patient MPatient
  326. //err := readDb.Model(&MPatient{}).Where("status = 1 AND user_org_id = ? AND id = ?", orgID, patientID).First(&patient).Error
  327. //if err != nil {
  328. // if err == gorm.ErrRecordNotFound {
  329. // return nil, nil
  330. // } else {
  331. // return nil, err
  332. // }
  333. //}
  334. //return &patient, nil
  335. redis := RedisClient()
  336. defer redis.Close()
  337. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":patient_info"
  338. patient_info_str, _ := redis.Get(key).Result()
  339. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  340. err = readDb.Model(&patient).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  341. if err != nil {
  342. if err == gorm.ErrRecordNotFound {
  343. return &patient, nil
  344. } else {
  345. return &patient, err
  346. }
  347. } else {
  348. if patient.ID > 0 {
  349. //缓存数据
  350. patient_info_json, err := json.Marshal(&patient)
  351. if err == nil {
  352. redis.Set(key, patient_info_json, time.Second*60*60*18)
  353. }
  354. }
  355. return &patient, nil
  356. }
  357. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  358. json.Unmarshal([]byte(patient_info_str), &patient)
  359. return &patient, nil
  360. }
  361. }
  362. func MobileGetSchedualDetailOne(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  363. var vm MDialysisScheduleVM
  364. err := readDb.
  365. Table("xt_schedule").
  366. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  367. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  368. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  369. First(&vm).Error
  370. return &vm, err
  371. }
  372. // 用户排班信息
  373. func MobileGetSchedualDetailSix(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  374. var vm MDialysisScheduleVM
  375. err := readDb.
  376. Table("xt_schedule").
  377. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  378. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  379. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  380. First(&vm).Error
  381. if err != nil {
  382. if err == gorm.ErrRecordNotFound {
  383. return nil, nil
  384. } else {
  385. return nil, err
  386. }
  387. }
  388. return &vm, err
  389. }
  390. // 用户排班信息
  391. func MobileGetSchedualDetail(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  392. redis := RedisClient()
  393. defer redis.Close()
  394. var vm MDialysisScheduleVM
  395. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(schedualDate, 10) + ":schedual_detail"
  396. schedual_detail_str, _ := redis.Get(key).Result()
  397. if len(schedual_detail_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  398. err := readDb.
  399. Table("xt_schedule").
  400. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  401. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  402. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  403. First(&vm).Error
  404. if err != nil {
  405. if err == gorm.ErrRecordNotFound {
  406. return nil, nil
  407. } else {
  408. return nil, err
  409. }
  410. } else {
  411. if vm.ID > 0 {
  412. //缓存数据
  413. schedual_detail_str, err := json.Marshal(vm)
  414. if err == nil {
  415. redis.Set(key, schedual_detail_str, time.Second*60*60*18)
  416. }
  417. } else {
  418. redis.Set(key, "null", time.Second*60*60*18)
  419. }
  420. return &vm, nil
  421. }
  422. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  423. if schedual_detail_str == "null" {
  424. return &vm, nil
  425. }
  426. json.Unmarshal([]byte(schedual_detail_str), &vm)
  427. return &vm, nil
  428. }
  429. }
  430. // 用户排班信息
  431. func MobileGetPatientSchedual(orgID int64, patientID int64, schedualDate int64) (*models.Schedule, error) {
  432. var schedule models.Schedule
  433. err := readDb.
  434. Table("xt_schedule").
  435. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  436. First(&schedule).Error
  437. if err != nil {
  438. if err == gorm.ErrRecordNotFound {
  439. return nil, nil
  440. } else {
  441. return nil, err
  442. }
  443. }
  444. return &schedule, nil
  445. }
  446. type MPatient struct {
  447. ID int64 `gorm:"column:id" json:"id" form:"id"`
  448. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  449. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  450. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  451. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  452. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  453. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  454. Source int64 `gorm:"column:source" json:"source" form:"source"`
  455. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  456. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  457. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  458. Name string `gorm:"column:name" json:"name" form:"name"`
  459. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  460. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  461. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  462. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  463. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  464. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  465. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  466. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  467. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  468. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  469. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  470. Height int64 `gorm:"column:height" json:"height" form:"height"`
  471. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  472. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  473. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  474. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  475. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  476. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  477. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  478. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  479. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  480. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  481. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  482. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  483. Children int64 `gorm:"column:children" json:"children" form:"children"`
  484. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  485. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  486. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  487. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  488. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  489. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  490. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  491. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  492. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  493. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  494. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  495. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  496. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  497. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  498. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  499. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  500. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  501. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  502. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  503. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  504. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  505. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  506. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  507. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  508. Status int64 `gorm:"column:status" json:"status" form:"status"`
  509. Age int64 `gorm:"column:age" json:"age"`
  510. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  511. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  512. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  513. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  514. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  515. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  516. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  517. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  518. }
  519. func (MPatient) TableName() string {
  520. return "xt_patients"
  521. }
  522. // 接诊评估
  523. func MobileGetReceiverTreatmentAccessRecord(orgID int64, patientID int64, recordDate int64) (*models.ReceiveTreatmentAsses, error) {
  524. var record models.ReceiveTreatmentAsses
  525. redis := RedisClient()
  526. defer redis.Close()
  527. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":receive_treatment_asses"
  528. receive_treatment_asses_str, _ := redis.Get(key).Result()
  529. if len(receive_treatment_asses_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  530. err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  531. if err != nil {
  532. if err == gorm.ErrRecordNotFound {
  533. if record.ID <= 0 {
  534. redis.Set(key, "", time.Second*60*60*18)
  535. }
  536. return nil, nil
  537. } else {
  538. return nil, err
  539. }
  540. } else {
  541. if record.ID > 0 {
  542. //缓存数据
  543. receive_treatment_asses_str, err := json.Marshal(record)
  544. if err == nil {
  545. redis.Set(key, receive_treatment_asses_str, time.Second*60*60*18)
  546. }
  547. } else {
  548. redis.Set(key, "null", time.Second*60*60*18)
  549. }
  550. return &record, nil
  551. }
  552. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  553. if receive_treatment_asses_str == "null" {
  554. return &record, nil
  555. }
  556. json.Unmarshal([]byte(receive_treatment_asses_str), &record)
  557. return &record, nil
  558. }
  559. }
  560. // 透前评估
  561. func MobileGetPredialysisEvaluationOne(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  562. fmt.Println("recordDate", recordDate)
  563. var record models.PredialysisEvaluation
  564. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  565. if err != nil {
  566. if err == gorm.ErrRecordNotFound {
  567. return nil, nil
  568. } else {
  569. return nil, err
  570. }
  571. }
  572. return &record, nil
  573. }
  574. // 透前评估
  575. func MobileGetPredialysisEvaluation(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  576. var record models.PredialysisEvaluation
  577. redis := RedisClient()
  578. defer redis.Close()
  579. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_before_dislysis"
  580. assessment_before_dislysis_str, _ := redis.Get(key).Result()
  581. if len(assessment_before_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  582. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  583. if err != nil {
  584. if err == gorm.ErrRecordNotFound {
  585. if record.ID <= 0 {
  586. redis.Set(key, "", time.Second*60*60*18)
  587. }
  588. return nil, nil
  589. } else {
  590. return nil, err
  591. }
  592. } else {
  593. if record.ID > 0 {
  594. //缓存数据
  595. assessment_before_dislysis_str, err := json.Marshal(record)
  596. if err == nil {
  597. redis.Set(key, assessment_before_dislysis_str, time.Second*60*60*18)
  598. }
  599. } else {
  600. redis.Set(key, "null", time.Second*60*60*18)
  601. }
  602. return &record, nil
  603. }
  604. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  605. if assessment_before_dislysis_str == "null" {
  606. return &record, nil
  607. } else {
  608. json.Unmarshal([]byte(assessment_before_dislysis_str), &record)
  609. return &record, nil
  610. }
  611. }
  612. }
  613. // 获取 maxDate 之前一次的透前评估记录
  614. func MobileGetLastTimePredialysisEvaluationOne(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  615. var record models.PredialysisEvaluation
  616. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  617. if err != nil {
  618. if err == gorm.ErrRecordNotFound {
  619. return nil, nil
  620. } else {
  621. return nil, err
  622. }
  623. }
  624. return &record, nil
  625. }
  626. // 获取 maxDate 之前一次的透前评估记录
  627. func MobileGetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  628. var record models.PredialysisEvaluation
  629. redis := RedisClient()
  630. defer redis.Close()
  631. // cur_date := time.Now().Format("2006-01-02")
  632. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_before_dislysis_last"
  633. assessment_before_dislysis_last_str, _ := redis.Get(key).Result()
  634. if len(assessment_before_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  635. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  636. if err != nil {
  637. if err == gorm.ErrRecordNotFound {
  638. if record.ID <= 0 {
  639. redis.Set(key, "", time.Second*60*60*18)
  640. }
  641. return nil, nil
  642. } else {
  643. return nil, err
  644. }
  645. } else {
  646. if record.ID > 0 {
  647. //缓存数据
  648. assessment_before_dislysis_last_str, err := json.Marshal(record)
  649. if err == nil {
  650. redis.Set(key, assessment_before_dislysis_last_str, time.Second*60*60*4)
  651. }
  652. } else {
  653. redis.Set(key, "null", time.Second*60*60*18)
  654. }
  655. return &record, nil
  656. }
  657. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  658. if assessment_before_dislysis_last_str == "null" {
  659. return &record, nil
  660. } else {
  661. json.Unmarshal([]byte(assessment_before_dislysis_last_str), &record)
  662. return &record, nil
  663. }
  664. }
  665. }
  666. // 临时医嘱
  667. func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  668. var records []*models.DoctorAdvice
  669. // err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&records).Error
  670. err := readDb.
  671. Model(&models.DoctorAdvice{}).
  672. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientID, orgID, recordDate).
  673. Select("id,user_org_id,patient_id,advice_type,advice_date,record_date,start_time,advice_name,advice_desc,reminder_date, drug_spec, drug_spec_unit,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,advice_doctor,status,created_time,updated_time,advice_affirm,remark,stop_time,stop_reason,stop_doctor,stop_state,parent_id,execution_time,execution_staff,execution_state,checker, check_state, check_time,way,drug_id,drug_name_id,IF(parent_id>0, parent_id, id) as advice_order,groupno").
  674. Order("start_time asc, groupno desc, advice_order desc, id").
  675. Scan(&records).Error
  676. if err != nil {
  677. return nil, err
  678. }
  679. return records, nil
  680. }
  681. func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  682. var records []*models.DoctorAdvice
  683. redis := RedisClient()
  684. defer redis.Close()
  685. // cur_date := time.Now().Format("2006-01-02")
  686. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":doctor_advices"
  687. doctor_advices_str, _ := redis.Get(key).Result()
  688. if len(doctor_advices_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  689. err := readDb.Model(&models.DoctorAdvice{}).
  690. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 || advice_type = 3)", patientID, orgID, recordDate).
  691. Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, single_dose, single_dose_unit, prescribing_number, prescribing_number_unit, delivery_way, execution_frequency, advice_doctor, status, created_time,updated_time, advice_affirm, remark, stop_time, stop_reason, stop_doctor, stop_state, parent_id, execution_time, execution_staff, execution_state, checker, check_state, check_time, groupno,way,drug_id,drug_name_id, IF(parent_id > 0, parent_id, id) as advice_order").
  692. Order("start_time asc, groupno desc, advice_order desc, id asc").
  693. Scan(&records).Error
  694. if err != nil {
  695. if err == gorm.ErrRecordNotFound {
  696. if len(records) <= 0 {
  697. redis.Set(key, "", time.Second*60*60*18)
  698. }
  699. return nil, nil
  700. } else {
  701. return nil, err
  702. }
  703. } else {
  704. if len(records) > 0 {
  705. //缓存数据
  706. doctor_advices_str, err := json.Marshal(records)
  707. if err == nil {
  708. redis.Set(key, doctor_advices_str, time.Second*60*60*18)
  709. return records, nil
  710. }
  711. } else {
  712. redis.Set(key, "null", time.Second*60*60*18)
  713. return records, nil
  714. }
  715. return records, nil
  716. }
  717. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  718. if doctor_advices_str == "null" {
  719. return records, nil
  720. } else {
  721. json.Unmarshal([]byte(doctor_advices_str), &records)
  722. return records, nil
  723. }
  724. }
  725. }
  726. // 透析记录
  727. func MobileGetSchedualDialysisRecordTen(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  728. var record models.DialysisOrder
  729. err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND status = 1", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  730. if err != nil {
  731. if err == gorm.ErrRecordNotFound {
  732. return nil, nil
  733. } else {
  734. return nil, err
  735. }
  736. }
  737. return &record, nil
  738. }
  739. // 透析记录
  740. func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  741. var record models.DialysisOrder
  742. redis := RedisClient()
  743. defer redis.Close()
  744. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_order"
  745. dialysis_order_str, _ := redis.Get(key).Result()
  746. if len(dialysis_order_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  747. err := readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND status = 1", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  748. if err != nil {
  749. if err == gorm.ErrRecordNotFound {
  750. return nil, nil
  751. } else {
  752. return nil, err
  753. }
  754. } else {
  755. if record.ID > 0 {
  756. //缓存数据
  757. dialysis_order_str, err := json.Marshal(record)
  758. if err == nil {
  759. redis.Set(key, dialysis_order_str, time.Second*60*60*18)
  760. }
  761. } else {
  762. redis.Set(key, "null", time.Second*60*60*18)
  763. }
  764. return &record, nil
  765. }
  766. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  767. if dialysis_order_str == "null" {
  768. err = readDb.Model(&models.DialysisOrder{}).Preload("DeviceNumber", "org_id = ? AND status = 1", orgID).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  769. return &record, nil
  770. } else {
  771. json.Unmarshal([]byte(dialysis_order_str), &record)
  772. return &record, nil
  773. }
  774. }
  775. }
  776. // 双人核对
  777. func MobileGetDoubleCheck(orgID int64, patientID int64, recordDate int64) (*models.DoubleCheck, error) {
  778. var record models.DoubleCheck
  779. redis := RedisClient()
  780. defer redis.Close()
  781. // cur_date := time.Now().Format("2006-01-02")
  782. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":double_check"
  783. double_check_str, _ := redis.Get(key).Result()
  784. if len(double_check_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  785. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  786. if err != nil {
  787. if err == gorm.ErrRecordNotFound {
  788. if record.ID <= 0 {
  789. redis.Set(key, "null", time.Second*60*60*18)
  790. }
  791. return nil, nil
  792. } else {
  793. return nil, err
  794. }
  795. } else {
  796. if record.ID > 0 {
  797. //缓存数据
  798. double_check_str, err := json.Marshal(record)
  799. if err == nil {
  800. redis.Set(key, double_check_str, time.Second*60*60*18)
  801. }
  802. } else {
  803. redis.Set(key, "null", time.Second*60*60*18)
  804. }
  805. return &record, nil
  806. }
  807. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  808. if double_check_str == "null" {
  809. return &record, nil
  810. } else {
  811. json.Unmarshal([]byte(double_check_str), &record)
  812. return &record, nil
  813. }
  814. }
  815. }
  816. // 透析监测记录
  817. func MobileGetMonitorRecords(orgID int64, patientID int64, recordDate int64) ([]*models.MonitoringRecord, error) {
  818. var records []*models.MonitoringRecord
  819. redis := RedisClient()
  820. defer redis.Close()
  821. // cur_date := time.Now().Format("2006-01-02")
  822. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":monitor_records"
  823. monitor_records_str, _ := redis.Get(key).Result()
  824. if len(monitor_records_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  825. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, recordDate).Order("operate_time asc").Find(&records).Error
  826. if err != nil {
  827. if err == gorm.ErrRecordNotFound {
  828. //if len(records) <= 0 {
  829. // redis.Set(key, "null", time.Second*60*60*18)
  830. //}
  831. return nil, nil
  832. } else {
  833. return nil, err
  834. }
  835. } else {
  836. if len(records) > 0 {
  837. //缓存数据
  838. monitor_records_str, err := json.Marshal(records)
  839. if err == nil {
  840. redis.Set(key, monitor_records_str, time.Second*60*60*18)
  841. }
  842. } else {
  843. redis.Set(key, "null", time.Second*60*60*18)
  844. }
  845. return records, nil
  846. }
  847. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  848. if monitor_records_str == "null" {
  849. return records, nil
  850. } else {
  851. json.Unmarshal([]byte(monitor_records_str), &records)
  852. return records, nil
  853. }
  854. }
  855. }
  856. func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64) (*models.MonitoringRecord, error) {
  857. var records models.MonitoringRecord
  858. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, recordDate).Order("operate_time asc").First(&records).Error
  859. if err != nil {
  860. return nil, err
  861. }
  862. return &records, nil
  863. }
  864. func MobileGetLastMonitorRecordOne(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  865. var record models.MonitoringRecord
  866. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  867. if err != nil {
  868. if err == gorm.ErrRecordNotFound {
  869. return nil, nil
  870. } else {
  871. return nil, err
  872. }
  873. }
  874. return &record, nil
  875. }
  876. func MobileGetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  877. var record models.MonitoringRecord
  878. redis := RedisClient()
  879. defer redis.Close()
  880. // cur_date := time.Now().Format("2006-01-02")
  881. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(beforeDate, 10) + ":monitor_record_last"
  882. monitor_record_last_str, _ := redis.Get(key).Result()
  883. if len(monitor_record_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  884. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  885. if err != nil {
  886. if err == gorm.ErrRecordNotFound {
  887. if record.ID <= 0 {
  888. redis.Set(key, "null", time.Second*60*60*18)
  889. }
  890. return nil, nil
  891. } else {
  892. return nil, err
  893. }
  894. } else {
  895. if record.ID > 0 {
  896. //缓存数据
  897. monitor_record_last_str, err := json.Marshal(record)
  898. if err == nil {
  899. redis.Set(key, monitor_record_last_str, time.Second*60*60*18)
  900. }
  901. } else {
  902. redis.Set(key, "null", time.Second*60*60*18)
  903. }
  904. return &record, nil
  905. }
  906. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  907. if monitor_record_last_str == "null" {
  908. return &record, nil
  909. } else {
  910. json.Unmarshal([]byte(monitor_record_last_str), &record)
  911. return &record, nil
  912. }
  913. }
  914. }
  915. func MobileGetAssessmentAfterDislysisOne(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  916. var record models.AssessmentAfterDislysis
  917. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  918. if err != nil {
  919. if err == gorm.ErrRecordNotFound {
  920. return nil, nil
  921. } else {
  922. return nil, err
  923. }
  924. }
  925. return &record, nil
  926. }
  927. // 透后评估
  928. func MobileGetAssessmentAfterDislysis(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  929. var record models.AssessmentAfterDislysis
  930. redis := RedisClient()
  931. defer redis.Close()
  932. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_after_dislysis"
  933. assessment_after_dislysis_str, _ := redis.Get(key).Result()
  934. if len(assessment_after_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  935. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  936. if err != nil {
  937. if err == gorm.ErrRecordNotFound {
  938. if record.ID <= 0 {
  939. redis.Set(key, "null", time.Second*60*60*18)
  940. }
  941. return nil, nil
  942. } else {
  943. return nil, err
  944. }
  945. } else {
  946. if record.ID > 0 {
  947. //缓存数据
  948. assessment_after_dislysis_str, err := json.Marshal(record)
  949. if err == nil {
  950. redis.Set(key, assessment_after_dislysis_str, time.Second*60*60*18)
  951. }
  952. } else {
  953. redis.Set(key, "null", time.Second*60*60*18)
  954. }
  955. return &record, nil
  956. }
  957. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  958. if assessment_after_dislysis_str == "null" {
  959. return &record, nil
  960. } else {
  961. json.Unmarshal([]byte(assessment_after_dislysis_str), &record)
  962. return &record, nil
  963. }
  964. }
  965. }
  966. // 获取 maxDate 之前一次的透后评估记录
  967. func MobileGetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  968. var record models.AssessmentAfterDislysis
  969. redis := RedisClient()
  970. defer redis.Close()
  971. // cur_date := time.Now().Format("2006-01-02")
  972. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_after_dislysis_last"
  973. assessment_after_dislysis_last_str, _ := redis.Get(key).Result()
  974. if len(assessment_after_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  975. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  976. if err != nil {
  977. if err == gorm.ErrRecordNotFound {
  978. if record.ID <= 0 {
  979. redis.Set(key, "null", time.Second*60*60*18)
  980. }
  981. return nil, nil
  982. } else {
  983. return nil, err
  984. }
  985. } else {
  986. if record.ID > 0 {
  987. //缓存数据
  988. assessment_after_dislysis_last_str, err := json.Marshal(record)
  989. if err == nil {
  990. redis.Set(key, assessment_after_dislysis_last_str, time.Second*60*60*18)
  991. }
  992. } else {
  993. redis.Set(key, "null", time.Second*60*60*18)
  994. }
  995. return &record, nil
  996. }
  997. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  998. if assessment_after_dislysis_last_str == "null" {
  999. return &record, nil
  1000. } else {
  1001. json.Unmarshal([]byte(assessment_after_dislysis_last_str), &record)
  1002. return &record, nil
  1003. }
  1004. }
  1005. }
  1006. func MobileGetLastTimeAssessmentAfterDislysisOne(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1007. var record models.AssessmentAfterDislysis
  1008. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  1009. if err != nil {
  1010. if err == gorm.ErrRecordNotFound {
  1011. return nil, nil
  1012. } else {
  1013. return nil, err
  1014. }
  1015. }
  1016. return &record, nil
  1017. }
  1018. func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
  1019. dislysis := models.AssessmentAfterDislysis{}
  1020. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&dislysis).Error
  1021. return dislysis, err
  1022. }
  1023. // 治疗小结
  1024. func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
  1025. var record models.TreatmentSummary
  1026. redis := RedisClient()
  1027. defer redis.Close()
  1028. // cur_date := time.Now().Format("2006-01-02")
  1029. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":treatment_summary"
  1030. treatment_summary_str, _ := redis.Get(key).Result()
  1031. if len(treatment_summary_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1032. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1033. if err != nil {
  1034. if err == gorm.ErrRecordNotFound {
  1035. if record.ID <= 0 {
  1036. redis.Set(key, "null", time.Second*60*60*18)
  1037. }
  1038. return nil, nil
  1039. } else {
  1040. return nil, err
  1041. }
  1042. } else {
  1043. if record.ID > 0 {
  1044. //缓存数据
  1045. treatment_summary_str, err := json.Marshal(record)
  1046. if err == nil {
  1047. redis.Set(key, treatment_summary_str, time.Second*60*60*18)
  1048. }
  1049. } else {
  1050. redis.Set(key, "null", time.Second*60*60*18)
  1051. }
  1052. return &record, nil
  1053. }
  1054. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1055. if treatment_summary_str == "null" {
  1056. return &record, nil
  1057. } else {
  1058. json.Unmarshal([]byte(treatment_summary_str), &record)
  1059. return &record, nil
  1060. }
  1061. }
  1062. }
  1063. // 透析处方
  1064. func MobileGetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1065. var record models.DialysisPrescription
  1066. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1067. if err != nil {
  1068. if err == gorm.ErrRecordNotFound {
  1069. return nil, nil
  1070. } else {
  1071. return nil, err
  1072. }
  1073. }
  1074. return &record, nil
  1075. }
  1076. func MobileGetDialysisSchedual(orgID int64, patientID int64, scheduleDate int64) (*models.XtSchedule, error) {
  1077. var schedule models.XtSchedule
  1078. err := readDb.Model(&models.XtSchedule{}).Where("patient_id = ? and user_org_id = ? and status = 1 and schedule_date = ?", patientID, orgID, scheduleDate).First(&schedule).Error
  1079. if err != nil {
  1080. if err == gorm.ErrRecordNotFound {
  1081. return nil, nil
  1082. } else {
  1083. return nil, err
  1084. }
  1085. }
  1086. return &schedule, nil
  1087. }
  1088. // 透析方案
  1089. func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
  1090. var record models.DialysisSolution
  1091. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1092. if err != nil {
  1093. if err == gorm.ErrRecordNotFound {
  1094. return nil, nil
  1095. } else {
  1096. return nil, err
  1097. }
  1098. }
  1099. return &record, nil
  1100. }
  1101. func MobileGetPatientById(orgID int64, patientID int64) (*models.Patients, error) {
  1102. var patient models.Patients
  1103. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id = ? and status = 1", patientID, orgID).First(&patient).Error
  1104. if err != nil {
  1105. if err == gorm.ErrRecordNotFound {
  1106. return nil, nil
  1107. } else {
  1108. return nil, err
  1109. }
  1110. }
  1111. return &patient, nil
  1112. }
  1113. func DisableMonitor(orgID int64, patientID int64, recordID int64, admin_user_id int64) error {
  1114. fmt.Println()
  1115. tx := writeDb.Begin()
  1116. updateTime := time.Now().Unix()
  1117. err := tx.Model(&models.MonitoringRecord{}).Where("user_org_id = ? AND patient_id = ? AND id = ? AND status = 1 ", orgID, patientID, recordID).Updates(map[string]interface{}{"status": 0, "updated_time": updateTime, "modify": admin_user_id}).Error
  1118. if err != nil {
  1119. tx.Rollback()
  1120. return err
  1121. }
  1122. tx.Commit()
  1123. return nil
  1124. }
  1125. func GetMonitor(orgID int64, patientID int64, id int64) (*models.MonitoringRecord, error) {
  1126. var monitor models.MonitoringRecord
  1127. var err error
  1128. err = readDb.Model(&models.MonitoringRecord{}).Where("id = ? AND user_org_id = ? AND patient_id = ? AND status = 1 ", id, orgID, patientID).Find(&monitor).Error
  1129. if err == gorm.ErrRecordNotFound {
  1130. return nil, nil
  1131. }
  1132. if err != nil {
  1133. return nil, err
  1134. }
  1135. return &monitor, nil
  1136. }
  1137. type MScheduleDoctorAdviceVM struct {
  1138. ID int64 `gorm:"column:id" json:"id"`
  1139. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1140. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1141. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1142. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1143. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1144. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1145. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1146. Status int64 `gorm:"column:status" json:"status"`
  1147. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1148. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1149. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1150. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1151. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1152. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1153. }
  1154. func (MScheduleDoctorAdviceVM) TableName() string {
  1155. return "xt_schedule"
  1156. }
  1157. type MScheduleDoctorAdviceVMOne struct {
  1158. ID int64 `gorm:"column:id" json:"id"`
  1159. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1160. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1161. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1162. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1163. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1164. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1165. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1166. Status int64 `gorm:"column:status" json:"status"`
  1167. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1168. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1169. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1170. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1171. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1172. //DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1173. }
  1174. func (MScheduleDoctorAdviceVMOne) TableName() string {
  1175. return "xt_schedule"
  1176. }
  1177. type MDoctorAdviceVM struct {
  1178. ID int64 `gorm:"column:id" json:"id"`
  1179. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1180. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1181. AdviceType int64 `gorm:"column:advice_type" json:"advice_type"`
  1182. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date"`
  1183. StartTime int64 `gorm:"column:start_time" json:"start_time"`
  1184. AdviceName string `gorm:"column:advice_name" json:"advice_name"`
  1185. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc"`
  1186. ReminderDate int64 `gorm:"column:reminder_date" json:"reminder_date"`
  1187. SingleDose float64 `gorm:"column:single_dose" json:"single_dose"`
  1188. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit"`
  1189. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number"`
  1190. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit"`
  1191. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way"`
  1192. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency"`
  1193. AdviceDoctor int64 `gorm:"column:advice_doctor" json:"advice_doctor"`
  1194. Status int64 `gorm:"column:status" json:"status"`
  1195. CreatedTime int64 `gorm:"column:created_time" json:"created_time"`
  1196. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"`
  1197. AdviceAffirm string `gorm:"column:advice_affirm" json:"advice_affirm"`
  1198. Remark string `gorm:"column:remark" json:"remark"`
  1199. StopTime int64 `gorm:"column:stop_time" json:"stop_time"`
  1200. StopReason string `gorm:"column:stop_reason" json:"stop_reason"`
  1201. StopDoctor int64 `gorm:"column:stop_doctor" json:"stop_doctor"`
  1202. StopState int64 `gorm:"column:stop_state" json:"stop_state"`
  1203. ParentId int64 `gorm:"column:parent_id" json:"parent_id"`
  1204. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time"`
  1205. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff"`
  1206. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state"`
  1207. Checker int64 `gorm:"column:checker" json:"checker"`
  1208. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  1209. DialysisOrderId int64 `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
  1210. CheckTime int64 `gorm:"column:check_time" json:"check_time"`
  1211. CheckState int64 `gorm:"column:check_state" json:"check_state"`
  1212. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec"`
  1213. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit"`
  1214. Groupno int64 `gorm:"column:groupno" json:"groupno"`
  1215. RemindType int64 `gorm:"column:remind_type" json:"remind_type"`
  1216. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type"`
  1217. DayCount int64 `gorm:"column:day_count" json:"day_count"`
  1218. WeekDay string `gorm:"column:week_day" json:"week_day"`
  1219. TemplateId string `gorm:"column:template_id" json:"template_id"`
  1220. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1221. }
  1222. func (MDoctorAdviceVM) TableName() string {
  1223. return "xt_doctor_advice"
  1224. }
  1225. func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVM, error) {
  1226. var vms []*MScheduleDoctorAdviceVM
  1227. adviceWhere := ""
  1228. adviceCondition := []interface{}{}
  1229. if adviceType == 0 {
  1230. if patientType == 0 {
  1231. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1232. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1233. } else if patientType == 1 {
  1234. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1235. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1236. } else if patientType == 2 {
  1237. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1238. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1239. }
  1240. } else if adviceType == 1 {
  1241. if patientType == 0 {
  1242. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1243. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1244. } else if patientType == 1 {
  1245. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1246. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1247. } else if patientType == 2 {
  1248. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1249. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1250. }
  1251. } else if adviceType == 3 {
  1252. if patientType == 0 {
  1253. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1254. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1255. } else if patientType == 1 {
  1256. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1257. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1258. } else if patientType == 2 {
  1259. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1260. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1261. }
  1262. } else if adviceType == 2 && len(deliverWay) > 0 {
  1263. if patientType == 0 {
  1264. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1265. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1266. } else if patientType == 1 {
  1267. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1268. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1269. } else if patientType == 2 {
  1270. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1271. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1272. }
  1273. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1274. if patientType == 0 {
  1275. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1276. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1277. } else if patientType == 1 {
  1278. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1279. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1280. } else if patientType == 2 {
  1281. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1282. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1283. }
  1284. }
  1285. db := readDb.
  1286. Table("xt_schedule").
  1287. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1288. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1289. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1290. }).
  1291. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1292. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1293. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1294. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  1295. Preload("DoctorAdvices", adviceCondition...).
  1296. Where("status = 1 AND user_org_id = ?", orgID)
  1297. if scheduleDate != 0 {
  1298. db = db.Where("schedule_date = ?", scheduleDate)
  1299. }
  1300. err := db.Find(&vms).Error
  1301. return vms, err
  1302. }
  1303. func MobileGetScheduleDoctorAdvicesTwo(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVMOne, error) {
  1304. var vms []*MScheduleDoctorAdviceVMOne
  1305. adviceWhere := ""
  1306. adviceCondition := []interface{}{}
  1307. if adviceType == 0 {
  1308. if patientType == 0 {
  1309. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1310. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1311. } else if patientType == 1 {
  1312. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1313. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1314. } else if patientType == 2 {
  1315. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1316. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1317. }
  1318. } else if adviceType == 1 {
  1319. if patientType == 0 {
  1320. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1321. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1322. } else if patientType == 1 {
  1323. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1324. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1325. } else if patientType == 2 {
  1326. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1327. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1328. }
  1329. } else if adviceType == 3 {
  1330. if patientType == 0 {
  1331. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1332. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1333. } else if patientType == 1 {
  1334. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1335. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1336. } else if patientType == 2 {
  1337. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1338. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1339. }
  1340. } else if adviceType == 2 && len(deliverWay) > 0 {
  1341. if patientType == 0 {
  1342. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1343. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1344. } else if patientType == 1 {
  1345. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1346. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1347. } else if patientType == 2 {
  1348. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1349. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1350. }
  1351. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1352. if patientType == 0 {
  1353. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1354. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1355. } else if patientType == 1 {
  1356. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1357. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1358. } else if patientType == 2 {
  1359. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1360. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1361. }
  1362. }
  1363. db := readDb.
  1364. Table("xt_schedule").
  1365. //Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1366. //Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1367. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1368. //}).
  1369. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1370. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1371. //Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1372. Preload("DoctorAdvices", adviceCondition...).
  1373. Where("status = 1 AND user_org_id = ?", orgID)
  1374. if scheduleDate != 0 {
  1375. db = db.Where("schedule_date = ?", scheduleDate)
  1376. }
  1377. err := db.Find(&vms).Error
  1378. return vms, err
  1379. }
  1380. func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  1381. var vms []*HisMScheduleDoctorAdviceVM
  1382. if len(deliverWay) > 0 {
  1383. if patientType == 0 {
  1384. db := readDb.
  1385. Table("xt_schedule").
  1386. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1387. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1388. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1389. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1390. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1391. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1392. }).
  1393. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1394. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1395. Where("status = 1 AND user_org_id = ?", orgID)
  1396. if scheduleDate != 0 {
  1397. db = db.Where("schedule_date = ?", scheduleDate)
  1398. }
  1399. err = db.Find(&vms).Error
  1400. }
  1401. if patientType > 0 {
  1402. db := readDb.
  1403. Table("xt_schedule").
  1404. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1405. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1406. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
  1407. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1408. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1409. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1410. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1411. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1412. }).Where("status = 1 AND user_org_id = ?", orgID)
  1413. if scheduleDate != 0 {
  1414. db = db.Where("schedule_date = ?", scheduleDate)
  1415. }
  1416. err = db.Find(&vms).Error
  1417. }
  1418. } else {
  1419. if patientType == 0 {
  1420. db := readDb.
  1421. Table("xt_schedule").
  1422. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1423. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1424. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1425. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1426. }).
  1427. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1428. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1429. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1430. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1431. Where("status = 1 AND user_org_id = ?", orgID)
  1432. if scheduleDate != 0 {
  1433. db = db.Where("schedule_date = ?", scheduleDate)
  1434. }
  1435. err = db.Find(&vms).Error
  1436. }
  1437. if patientType > 0 {
  1438. db := readDb.
  1439. Table("xt_schedule").
  1440. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1441. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1442. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1443. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1444. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1445. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1446. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1447. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1448. Where("status = 1 AND user_org_id = ?", orgID)
  1449. if scheduleDate != 0 {
  1450. db = db.Where("schedule_date = ?", scheduleDate)
  1451. }
  1452. err = db.Find(&vms).Error
  1453. }
  1454. }
  1455. return vms, err
  1456. }
  1457. func GetHisDoctorAdvicesTwo(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVMOne, error) {
  1458. var vms []*HisMScheduleDoctorAdviceVMOne
  1459. if len(deliverWay) > 0 {
  1460. if patientType == 0 {
  1461. db := readDb.
  1462. Table("xt_schedule").
  1463. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1464. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1465. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1466. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1467. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1468. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1469. }).
  1470. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1471. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1472. Where("status = 1 AND user_org_id = ?", orgID)
  1473. if scheduleDate != 0 {
  1474. db = db.Where("schedule_date = ?", scheduleDate)
  1475. }
  1476. err = db.Find(&vms).Error
  1477. }
  1478. if patientType > 0 {
  1479. db := readDb.
  1480. Table("xt_schedule").
  1481. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1482. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1483. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, deliverWay, adminUserId, adminUserId).
  1484. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1485. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1486. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1487. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1488. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1489. }).Where("status = 1 AND user_org_id = ?", orgID)
  1490. if scheduleDate != 0 {
  1491. db = db.Where("schedule_date = ?", scheduleDate)
  1492. }
  1493. err = db.Find(&vms).Error
  1494. }
  1495. } else {
  1496. if patientType == 0 {
  1497. db := readDb.
  1498. Table("xt_schedule").
  1499. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1500. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1501. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1502. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1503. }).
  1504. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1505. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1506. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1507. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1508. Where("status = 1 AND user_org_id = ?", orgID)
  1509. if scheduleDate != 0 {
  1510. db = db.Where("schedule_date = ?", scheduleDate)
  1511. }
  1512. err = db.Find(&vms).Error
  1513. }
  1514. if patientType > 0 {
  1515. db := readDb.
  1516. Table("xt_schedule").
  1517. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1518. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1519. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1520. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1521. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1522. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1523. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1524. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1525. Where("status = 1 AND user_org_id = ?", orgID)
  1526. if scheduleDate != 0 {
  1527. db = db.Where("schedule_date = ?", scheduleDate)
  1528. }
  1529. err = db.Find(&vms).Error
  1530. }
  1531. }
  1532. return vms, err
  1533. }
  1534. func GetMobileHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
  1535. var vms []*HisMScheduleProjectVM
  1536. //if patientType == 0 {
  1537. // db := readDb.
  1538. // Table("xt_schedule").
  1539. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1540. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1541. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1542. // }).
  1543. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1544. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1545. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1546. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1547. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1548. // }).
  1549. // Where("status = 1 AND user_org_id = ?", orgID)
  1550. // if scheduleDate != 0 {
  1551. // db = db.Where("schedule_date = ?", scheduleDate)
  1552. // }
  1553. // err = db.Find(&vms).Error
  1554. //}
  1555. //if patientType > 0 {
  1556. // db := readDb.
  1557. // Table("xt_schedule").
  1558. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1559. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1560. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1561. // }).
  1562. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1563. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1564. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1565. // Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1566. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1567. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1568. // }).
  1569. // Where("status = 1 AND user_org_id = ?", orgID)
  1570. // if scheduleDate != 0 {
  1571. // db = db.Where("schedule_date = ?", scheduleDate)
  1572. // }
  1573. // err = db.Find(&vms).Error
  1574. //}
  1575. db := readDb.Table("xt_schedule").Where("status = 1")
  1576. if orgID > 0 {
  1577. db = db.Where("user_org_id = ?", orgID)
  1578. }
  1579. if scheduleDate > 0 {
  1580. db = db.Where("schedule_date =?", scheduleDate)
  1581. }
  1582. err = db.Find(&vms).Error
  1583. if patientType == 0 {
  1584. db := readDb.
  1585. Table("xt_schedule").
  1586. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1587. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1588. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1589. }).
  1590. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1591. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1592. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1593. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1594. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1595. }).
  1596. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1597. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  1598. }).
  1599. Where("status = 1 AND user_org_id = ?", orgID)
  1600. if scheduleDate != 0 {
  1601. db = db.Where("schedule_date = ?", scheduleDate)
  1602. }
  1603. err = db.Find(&vms).Error
  1604. }
  1605. if patientType > 0 {
  1606. db := readDb.
  1607. Table("xt_schedule").
  1608. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1609. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1610. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1611. }).
  1612. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1613. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1614. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1615. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1616. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1617. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1618. }).
  1619. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1620. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  1621. }).
  1622. Where("status = 1 AND user_org_id = ?", orgID)
  1623. if scheduleDate != 0 {
  1624. db = db.Where("schedule_date = ?", scheduleDate)
  1625. }
  1626. err = db.Find(&vms).Error
  1627. }
  1628. return vms, err
  1629. }
  1630. func MobileCreateDialysisOrder(orgID int64, patientID int64, order *models.DialysisOrder) error {
  1631. now := time.Now()
  1632. tx := writeDb.Begin()
  1633. if createOrderErr := tx.Model(&models.DialysisOrder{}).Create(order).Error; createOrderErr != nil {
  1634. tx.Rollback()
  1635. return createOrderErr
  1636. }
  1637. // 更新透析记录 ID
  1638. // 透析处方
  1639. if err := tx.Model(&models.DialysisPrescription{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"record_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  1640. tx.Rollback()
  1641. return err
  1642. }
  1643. // 接诊评估
  1644. if err := tx.Model(&models.ReceiveTreatmentAsses{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"record_id": order.ID, "update_time": now.Unix()}).Error; err != nil {
  1645. tx.Rollback()
  1646. return err
  1647. }
  1648. // 透前评估
  1649. if err := tx.Model(&models.PredialysisEvaluation{}).Where("user_org_id = ? AND patient_id = ? AND assessment_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  1650. tx.Rollback()
  1651. return err
  1652. }
  1653. // 临时医嘱
  1654. if err := tx.Model(&models.DoctorAdvice{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND advice_type = 2", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  1655. tx.Rollback()
  1656. return err
  1657. }
  1658. // 双人核对
  1659. if err := tx.Model(&models.DoubleCheck{}).Where("user_org_id = ? AND patient_id = ? AND check_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  1660. tx.Rollback()
  1661. return err
  1662. }
  1663. // 透后评估
  1664. if err := tx.Model(&models.AssessmentAfterDislysis{}).Where("user_org_id = ? AND patient_id = ? AND assessment_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  1665. tx.Rollback()
  1666. return err
  1667. }
  1668. // 治疗小结
  1669. if err := tx.Model(&models.TreatmentSummary{}).Where("user_org_id = ? AND patient_id = ? AND assessment_date = ? AND status = 1", orgID, patientID, order.DialysisDate).Updates(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  1670. tx.Rollback()
  1671. return err
  1672. }
  1673. // 透析监测
  1674. if err := tx.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id=? and status=1 and monitoring_date = ?", patientID, orgID, order.DialysisDate).Update(map[string]interface{}{"dialysis_order_id": order.ID, "updated_time": now.Unix()}).Error; err != nil {
  1675. tx.Rollback()
  1676. return err
  1677. }
  1678. tx.Commit()
  1679. return nil
  1680. }
  1681. type MobileUrgentSchedulePatientVM struct {
  1682. ID int64 `gorm:"column:id" json:"id"`
  1683. Name string `gorm:"column:name" json:"name"`
  1684. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no"`
  1685. }
  1686. func (MobileUrgentSchedulePatientVM) TableName() string {
  1687. return "xt_patients"
  1688. }
  1689. type MobileUrgentScheduleTreatmentModeVM struct {
  1690. ID int64 `gorm:"column:id" json:"id"`
  1691. Name string `gorm:"column:name" json:"name"`
  1692. }
  1693. func (MobileUrgentScheduleTreatmentModeVM) TableName() string {
  1694. return "xt_treatment_mode"
  1695. }
  1696. func MobileGetAllPatientsForUrgentSchedule(orgID int64, record_date int64) ([]*MobileUrgentSchedulePatientVM, error) {
  1697. var vms []*MobileUrgentSchedulePatientVM = make([]*MobileUrgentSchedulePatientVM, 0)
  1698. rows, err := readDb.Raw("SELECT p.* FROM xt_patients as p WHERE (p.user_org_id = ? AND p.status = 1 AND p.lapseto = 1) AND NOT EXISTS (Select * FROM `xt_dialysis_order` as d Where d.`dialysis_date` = ? AND d.`status` = 1 AND d.`patient_id` = p.id AND d.user_org_id = p.user_org_id )", orgID, record_date).Rows()
  1699. defer rows.Close()
  1700. if err != nil {
  1701. return nil, err
  1702. }
  1703. for rows.Next() {
  1704. var vm MobileUrgentSchedulePatientVM
  1705. readDb.ScanRows(rows, &vm)
  1706. vms = append(vms, &vm)
  1707. }
  1708. return vms, nil
  1709. }
  1710. func MobileGetAllTrearmentModesForUrgentSchedule() ([]*MobileUrgentScheduleTreatmentModeVM, error) {
  1711. var modes []*MobileUrgentScheduleTreatmentModeVM
  1712. err := readDb.Model(&MobileUrgentScheduleTreatmentModeVM{}).Where("status = 1").Find(&modes).Error
  1713. if err != nil {
  1714. return nil, err
  1715. }
  1716. return modes, nil
  1717. }
  1718. type MobileUrgentScheduleScheduleListVM struct {
  1719. ID int64 `gorm:"column:id" json:"id"`
  1720. // ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
  1721. DeviceNumberID int64 `gorm:"column:bed_id" json:"bed_id"`
  1722. PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
  1723. ScheduleType int `gorm:"column:schedule_type" json:"schedule_type"`
  1724. DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
  1725. // DeviceZone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"device_zone"`
  1726. }
  1727. func (MobileUrgentScheduleScheduleListVM) TableName() string {
  1728. return "xt_schedule"
  1729. }
  1730. func MobileGetSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) (schedules []*MobileUrgentScheduleScheduleListVM, err error) {
  1731. db := readDb.
  1732. Model(&MobileUrgentScheduleScheduleListVM{}).
  1733. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1734. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND schedule_type = ? ", orgID, scheduleDate, schedule_type)
  1735. err = db.Find(&schedules).Error
  1736. if err != nil {
  1737. return nil, err
  1738. }
  1739. return schedules, nil
  1740. }
  1741. func MobileGetOtherSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) ([]*MobileUrgentScheduleScheduleListVM, error) {
  1742. var vms []*MobileUrgentScheduleScheduleListVM = make([]*MobileUrgentScheduleScheduleListVM, 0)
  1743. rows, err := readDb.Raw("SELECT * FROM xt_schedule as s WHERE s.user_org_id = ? AND s.status = 1 AND s.schedule_date = ? ", orgID, scheduleDate).Rows()
  1744. defer rows.Close()
  1745. if err != nil {
  1746. return nil, err
  1747. }
  1748. for rows.Next() {
  1749. var vm MobileUrgentScheduleScheduleListVM
  1750. readDb.ScanRows(rows, &vm)
  1751. vms = append(vms, &vm)
  1752. }
  1753. return vms, nil
  1754. }
  1755. type MobileUrgentScheduleDeviceNumberVM struct {
  1756. ID int64 `gorm:"column:id" json:"id"`
  1757. Number string `gorm:"column:number" json:"number"`
  1758. ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
  1759. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  1760. }
  1761. func (MobileUrgentScheduleDeviceNumberVM) TableName() string {
  1762. return "xt_device_number"
  1763. }
  1764. func MobileGetAllDeviceNumbersForUrgentSchedule(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  1765. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  1766. rows, err := readDb.Raw("SELECT n.*, z.name as zone_name, g.name as group_name FROM xt_device_number as n join xt_device_zone as z on z.id = n.zone_id join xt_device_group as g on g.id = n.group_id WHERE (n.org_id = ? AND n.status = 1) AND NOT EXISTS (Select * FROM xt_schedule as s Where s.`schedule_date` = ? AND s.user_org_id = n.org_id AND s.`bed_id` = n.id AND s.`schedule_type` = ? AND s.status = 1 )", orgID, record_date, schedule_type).Rows()
  1767. defer rows.Close()
  1768. if err != nil {
  1769. return nil, err
  1770. }
  1771. for rows.Next() {
  1772. var vm DeviceNumberViewModel
  1773. readDb.ScanRows(rows, &vm)
  1774. vms = append(vms, &vm)
  1775. }
  1776. return vms, nil
  1777. //var deviceNumbers []*MobileUrgentScheduleDeviceNumberVM
  1778. //db := readDb.
  1779. // Model(&MobileUrgentScheduleDeviceNumberVM{}).
  1780. // Preload("Zone", "status = 1 AND org_id = ?", orgID).
  1781. // Where("status = 1 AND org_id = ?", orgID)
  1782. //err := db.Order("zone_id asc").Find(&deviceNumbers).Error
  1783. //if err != nil {
  1784. // return nil, err
  1785. //}
  1786. //return deviceNumbers, nil
  1787. }
  1788. func GetValidScheduleMonitorRecordCount() (int64, error) {
  1789. var total int64
  1790. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Count(&total).Error
  1791. return total, err
  1792. }
  1793. func GetTop1000ValidScheduleMonitorRecord() ([]*models.MonitoringRecord, error) {
  1794. var monitors []*models.MonitoringRecord
  1795. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Order("id asc").Limit(100).Find(&monitors).Error
  1796. if err != nil {
  1797. return nil, err
  1798. }
  1799. return monitors, nil
  1800. }
  1801. func BatchUpdateMonitors(monitors []*models.MonitoringRecord) error {
  1802. tx := writeDb.Begin()
  1803. for index := 0; index < len(monitors); index++ {
  1804. tx.Save(monitors[index])
  1805. }
  1806. return tx.Commit().Error
  1807. }
  1808. func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
  1809. tx := writeDb.Begin()
  1810. updateTime := time.Now().Unix()
  1811. err := tx.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND id = ? AND status = 1 ", order.UserOrgId, order.ID).Updates(map[string]interface{}{"start_nurse": order.StartNurse, "updated_time": updateTime, "bed_id": order.BedID, "puncture_nurse": order.PunctureNurse, "start_time": order.StartTime, "modifier": order.Modifier, "schedual_type": order.SchedualType, "washpipe_nurse": order.WashpipeNurse, "change_nurse": order.ChangeNurse, "difficult_puncture_nurse": order.DifficultPunctureNurse, "new_fistula_nurse": order.NewFistulaNurse}).Error
  1812. if err != nil {
  1813. tx.Rollback()
  1814. return err
  1815. }
  1816. tx.Commit()
  1817. return err
  1818. }
  1819. func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
  1820. tx := writeDb.Begin()
  1821. updateTime := time.Now().Unix()
  1822. err := tx.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND id = ? AND status = 1 ", order.UserOrgId, order.ID).Updates(map[string]interface{}{"finish_nurse": order.FinishNurse, "updated_time": updateTime, "end_time": order.EndTime, "finish_modifier": order.FinishModifier}).Error
  1823. if err != nil {
  1824. tx.Rollback()
  1825. return err
  1826. }
  1827. tx.Commit()
  1828. return err
  1829. }
  1830. func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  1831. var record models.SgjPatientDryweight
  1832. redis := RedisClient()
  1833. defer redis.Close()
  1834. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":last_dry_weight"
  1835. last_dry_weight_str, _ := redis.Get(key).Result()
  1836. if len(last_dry_weight_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1837. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1838. if err != nil {
  1839. if err == gorm.ErrRecordNotFound {
  1840. if record.ID <= 0 {
  1841. redis.Set(key, "null", time.Second*60*60*18)
  1842. }
  1843. return nil, nil
  1844. } else {
  1845. return nil, err
  1846. }
  1847. } else {
  1848. if record.ID > 0 {
  1849. //缓存数据
  1850. last_dry_weight_str, err := json.Marshal(record)
  1851. if err == nil {
  1852. redis.Set(key, last_dry_weight_str, time.Second*60*60*18)
  1853. return nil, err
  1854. }
  1855. } else {
  1856. redis.Set(key, "null", time.Second*60*60*18)
  1857. return nil, err
  1858. }
  1859. return &record, nil
  1860. }
  1861. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1862. if last_dry_weight_str == "null" {
  1863. return &record, nil
  1864. } else {
  1865. json.Unmarshal([]byte(last_dry_weight_str), &record)
  1866. return &record, nil
  1867. }
  1868. }
  1869. }
  1870. // 透析方案
  1871. func MobileGetDialysisSolutionByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  1872. var record models.DialysisSolution
  1873. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  1874. if err != nil {
  1875. if err == gorm.ErrRecordNotFound {
  1876. return nil, nil
  1877. } else {
  1878. return nil, err
  1879. }
  1880. }
  1881. return &record, nil
  1882. }
  1883. // 透析方案
  1884. func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  1885. var record models.DialysisSolution
  1886. redis := RedisClient()
  1887. defer redis.Close()
  1888. // cur_date := time.Now().Format("2006-01-02")
  1889. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1890. dialysis_solution_str, _ := redis.Get(key).Result()
  1891. if len(dialysis_solution_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1892. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  1893. if err != nil {
  1894. if err == gorm.ErrRecordNotFound {
  1895. if record.ID <= 0 {
  1896. redis.Set(key, "null", time.Second*60*60*18)
  1897. }
  1898. return nil, nil
  1899. } else {
  1900. return nil, err
  1901. }
  1902. } else {
  1903. if record.ID > 0 {
  1904. //缓存数据
  1905. dialysis_solution_str, err := json.Marshal(record)
  1906. if err == nil {
  1907. redis.Set(key, dialysis_solution_str, time.Second*60*60*18)
  1908. }
  1909. } else {
  1910. redis.Set(key, "null", time.Second*60*60*18)
  1911. }
  1912. return &record, nil
  1913. }
  1914. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1915. if dialysis_solution_str == "null" {
  1916. return &record, nil
  1917. } else {
  1918. json.Unmarshal([]byte(dialysis_solution_str), &record)
  1919. return &record, nil
  1920. }
  1921. }
  1922. }
  1923. // 透析处方
  1924. func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  1925. var record models.DialysisPrescription
  1926. redis := RedisClient()
  1927. defer redis.Close()
  1928. // cur_date := time.Now().Format("2006-01-02")
  1929. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1930. dialysis_prescribe_str, _ := redis.Get(key).Result()
  1931. if len(dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1932. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? AND mode_id = ?", patientID, orgID, recordDate, mode_id).First(&record).Error
  1933. if err != nil {
  1934. if err == gorm.ErrRecordNotFound {
  1935. if record.ID <= 0 {
  1936. redis.Set(key, "null", time.Second*60*60*18)
  1937. }
  1938. return nil, nil
  1939. } else {
  1940. return nil, err
  1941. }
  1942. } else {
  1943. if record.ID > 0 {
  1944. //缓存数据
  1945. dialysis_prescribe_str, err := json.Marshal(record)
  1946. if err == nil {
  1947. redis.Set(key, dialysis_prescribe_str, time.Second*60*60*18)
  1948. }
  1949. } else {
  1950. redis.Set(key, "null", time.Second*60*60*18)
  1951. }
  1952. return &record, nil
  1953. }
  1954. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1955. if dialysis_prescribe_str == "null" {
  1956. return &record, nil
  1957. } else {
  1958. json.Unmarshal([]byte(dialysis_prescribe_str), &record)
  1959. return &record, nil
  1960. }
  1961. }
  1962. }
  1963. func MobileGetDialysisPrescribeByModeIdSix(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  1964. var record models.DialysisPrescription
  1965. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? AND mode_id = ?", patientID, orgID, recordDate, mode_id).First(&record).Error
  1966. if err != nil {
  1967. if err == gorm.ErrRecordNotFound {
  1968. return nil, nil
  1969. } else {
  1970. return nil, err
  1971. }
  1972. }
  1973. return &record, nil
  1974. }
  1975. func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1976. var record models.DialysisPrescription
  1977. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  1978. if err != nil {
  1979. if err == gorm.ErrRecordNotFound {
  1980. return nil, nil
  1981. } else {
  1982. return nil, err
  1983. }
  1984. }
  1985. return &record, nil
  1986. }
  1987. //func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1988. // var record models.DialysisPrescription
  1989. // redis := RedisClient()
  1990. // defer redis.Close()
  1991. //
  1992. // // cur_date := time.Now().Format("2006-01-02")
  1993. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_prescribe_by_mode"
  1994. // dialysis_prescribe_by_mode_str, _ := redis.Get(key).Result()
  1995. //
  1996. // if len(dialysis_prescribe_by_mode_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1997. // err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  1998. // if err != nil {
  1999. // if err == gorm.ErrRecordNotFound {
  2000. // if record.ID <= 0 {
  2001. // redis.Set(key, "null", time.Second*60*60*18)
  2002. // }
  2003. // return nil, nil
  2004. // } else {
  2005. // return nil, err
  2006. // }
  2007. // } else {
  2008. //
  2009. // if record.ID > 0 {
  2010. // //缓存数据
  2011. // dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2012. //
  2013. // if err == nil {
  2014. // redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2015. // return nil, err
  2016. // }
  2017. // } else {
  2018. // redis.Set(key, "null", time.Second*60*60*18)
  2019. // return nil, err
  2020. // }
  2021. // return &record, nil
  2022. // }
  2023. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2024. // if dialysis_prescribe_by_mode_str == "null" {
  2025. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2026. // return &record, nil
  2027. // } else {
  2028. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2029. // return &record, nil
  2030. // }
  2031. //
  2032. // }
  2033. //}
  2034. func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
  2035. var record models.DialysisPrescription
  2036. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 ", patientID, orgID).Last(&record).Error
  2037. if err != nil {
  2038. if err == gorm.ErrRecordNotFound {
  2039. return nil, nil
  2040. } else {
  2041. return nil, err
  2042. }
  2043. }
  2044. return &record, nil
  2045. }
  2046. func MobileGetLastDialysisPrescribeByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2047. var record models.DialysisPrescription
  2048. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  2049. if err != nil {
  2050. if err == gorm.ErrRecordNotFound {
  2051. return nil, nil
  2052. } else {
  2053. return nil, err
  2054. }
  2055. }
  2056. return &record, nil
  2057. }
  2058. func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2059. var record models.DialysisPrescription
  2060. redis := RedisClient()
  2061. defer redis.Close()
  2062. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2063. dialysis_prescribe_by_mode_id, _ := redis.Get(key).Result()
  2064. if len(dialysis_prescribe_by_mode_id) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2065. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  2066. if err != nil {
  2067. if err == gorm.ErrRecordNotFound {
  2068. if record.ID <= 0 {
  2069. redis.Set(key, "null", time.Second*60*60*18)
  2070. }
  2071. return nil, nil
  2072. } else {
  2073. return nil, err
  2074. }
  2075. } else {
  2076. if record.ID > 0 {
  2077. //缓存数据
  2078. dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2079. if err == nil {
  2080. redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2081. return nil, err
  2082. }
  2083. } else {
  2084. redis.Set(key, "null", time.Second*60*60*18)
  2085. return nil, err
  2086. }
  2087. return &record, nil
  2088. }
  2089. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2090. if dialysis_prescribe_by_mode_id == "null" {
  2091. return &record, nil
  2092. } else {
  2093. json.Unmarshal([]byte(dialysis_prescribe_by_mode_id), &record)
  2094. return &record, nil
  2095. }
  2096. }
  2097. }
  2098. func MobileGetLastDialysisPrescribeByModeIdOne(orgID int64, patientID int64, mode_id int64) (models.DialysisPrescription, error) {
  2099. var record models.DialysisPrescription
  2100. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  2101. return record, err
  2102. }
  2103. func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2104. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2105. rows, err := readDb.Raw("SELECT n.*, z.name as zone_name, g.name as group_name FROM xt_device_number as n join xt_device_zone as z on z.id = n.zone_id join xt_device_group as g on g.id = n.group_id WHERE (n.org_id = ? AND n.status = 1) AND NOT EXISTS (Select * FROM xt_schedule as s Where s.`schedule_date` = ? AND s.user_org_id = n.org_id AND s.`bed_id` = n.id AND s.`schedule_type` = ? AND s.status = 1 )", orgID, record_date, schedule_type).Rows()
  2106. defer rows.Close()
  2107. if err != nil {
  2108. return nil, err
  2109. }
  2110. for rows.Next() {
  2111. var vm DeviceNumberViewModel
  2112. readDb.ScanRows(rows, &vm)
  2113. vms = append(vms, &vm)
  2114. }
  2115. return vms, nil
  2116. }
  2117. // 获取 maxDate 之前一次的透前评估记录
  2118. func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  2119. var record models.PredialysisEvaluation
  2120. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  2121. if err != nil {
  2122. if err == gorm.ErrRecordNotFound {
  2123. return nil, nil
  2124. } else {
  2125. return nil, err
  2126. }
  2127. }
  2128. return &record, nil
  2129. }
  2130. func GetLastTimeOrder(orgID int64, patientID int64, maxDate int64) (*models.DialysisOrder, error) {
  2131. var record models.DialysisOrder
  2132. err := readDb.Model(&models.DialysisOrder{}).Where("patient_id = ? and user_org_id = ? and status = 1 and dialysis_date < ?", patientID, orgID, maxDate).Order("dialysis_date desc").First(&record).Error
  2133. if err != nil {
  2134. if err == gorm.ErrRecordNotFound {
  2135. return nil, nil
  2136. } else {
  2137. return nil, err
  2138. }
  2139. }
  2140. return &record, nil
  2141. }
  2142. func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  2143. var record models.MonitoringRecord
  2144. err := readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ?", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
  2145. if err != nil {
  2146. if err == gorm.ErrRecordNotFound {
  2147. return nil, nil
  2148. } else {
  2149. return nil, err
  2150. }
  2151. }
  2152. return &record, nil
  2153. }
  2154. // 获取 maxDate 之前一次的透后评估记录
  2155. func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  2156. var record models.AssessmentAfterDislysis
  2157. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date < ?", patientID, orgID, maxDate).Order("assessment_date desc").First(&record).Error
  2158. if err != nil {
  2159. if err == gorm.ErrRecordNotFound {
  2160. return nil, nil
  2161. } else {
  2162. return nil, err
  2163. }
  2164. }
  2165. return &record, nil
  2166. }
  2167. // 透析处方
  2168. func GetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2169. var record models.DialysisPrescription
  2170. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  2171. if err != nil {
  2172. if err == gorm.ErrRecordNotFound {
  2173. return nil, nil
  2174. } else {
  2175. return nil, err
  2176. }
  2177. }
  2178. return &record, nil
  2179. }
  2180. // 透析方案
  2181. func GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2182. var record models.DialysisSolution
  2183. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  2184. if err != nil {
  2185. if err == gorm.ErrRecordNotFound {
  2186. return nil, nil
  2187. } else {
  2188. return nil, err
  2189. }
  2190. }
  2191. return &record, nil
  2192. }
  2193. func GetDialysisSolutionOne(orgID int64, mode_id int64) (*models.DialysisSolution, error) {
  2194. var record models.DialysisSolution
  2195. err := readDb.Model(&models.DialysisSolution{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2196. if err != nil {
  2197. if err == gorm.ErrRecordNotFound {
  2198. return nil, nil
  2199. } else {
  2200. return nil, err
  2201. }
  2202. }
  2203. return &record, nil
  2204. }
  2205. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2206. var record models.DialysisPrescription
  2207. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  2208. if err != nil {
  2209. if err == gorm.ErrRecordNotFound {
  2210. return nil, nil
  2211. } else {
  2212. return nil, err
  2213. }
  2214. }
  2215. return &record, nil
  2216. }
  2217. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2218. var record models.SgjPatientDryweight
  2219. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2220. if err != nil {
  2221. if err == gorm.ErrRecordNotFound {
  2222. return nil, nil
  2223. } else {
  2224. return nil, err
  2225. }
  2226. }
  2227. return &record, nil
  2228. }
  2229. func MobileGetSystemDialysisPrescribeByModeIdSix(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2230. var record models.SystemPrescription
  2231. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  2232. if err != nil {
  2233. if err == gorm.ErrRecordNotFound {
  2234. return nil, nil
  2235. } else {
  2236. return nil, err
  2237. }
  2238. }
  2239. return &record, nil
  2240. }
  2241. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2242. var record models.SystemPrescription
  2243. redis := RedisClient()
  2244. defer redis.Close()
  2245. // cur_date := time.Now().Format("2006-01-02")
  2246. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2247. system_dialysis_prescribe_str, _ := redis.Get(key).Result()
  2248. if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2249. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2250. if err != nil {
  2251. if err == gorm.ErrRecordNotFound {
  2252. if record.ID <= 0 {
  2253. redis.Set(key, "null", time.Second*60*60*18)
  2254. }
  2255. return nil, nil
  2256. } else {
  2257. return nil, err
  2258. }
  2259. } else {
  2260. if record.ID > 0 {
  2261. //缓存数据
  2262. system_dialysis_prescribe_str, err := json.Marshal(record)
  2263. if err == nil {
  2264. redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
  2265. }
  2266. } else {
  2267. redis.Set(key, "null", time.Second*60*60*18)
  2268. }
  2269. return &record, nil
  2270. }
  2271. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2272. if system_dialysis_prescribe_str == "null" {
  2273. return &record, nil
  2274. } else {
  2275. json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
  2276. return &record, nil
  2277. }
  2278. }
  2279. }
  2280. func MobileGetSystemDialysisPrescribeByModeIdOne(orgID int64, mode_id int64) (models.SystemPrescription, error) {
  2281. var record models.SystemPrescription
  2282. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2283. return record, err
  2284. }
  2285. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2286. var record models.SystemPrescription
  2287. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2288. if err != nil {
  2289. if err == gorm.ErrRecordNotFound {
  2290. return nil, nil
  2291. } else {
  2292. return nil, err
  2293. }
  2294. }
  2295. return &record, nil
  2296. }
  2297. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2298. err = readDb.Model(&models.DialysisOrder{}).Where("dialysis_date <= ? AND status = 1 AND stage = 2 AND user_org_id = ? AND patient_id = ?", recordDate, orgID, patient_id).Count(&count).Error
  2299. return
  2300. }
  2301. func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2302. err = readDb.Model(&models.DialysisOrder{}).Where("dialysis_date>=1640966400 and dialysis_date <= ? AND status = 1 AND stage = 2 AND user_org_id = ? AND patient_id = ?", recordDate, orgID, patient_id).Count(&count).Error
  2303. return
  2304. }
  2305. func GetFirstDateOfMonth(d time.Time) time.Time {
  2306. d = d.AddDate(0, 0, -d.Day()+1)
  2307. return GetZeroTime(d)
  2308. }
  2309. func GetZeroTime(d time.Time) time.Time {
  2310. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  2311. }
  2312. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  2313. db := XTReadDB().Table("xt_dialysis_order as o")
  2314. err = db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule AS x ON x.patient_id = o.patient_id where o.status = 1 and o.dialysis_date>=? and o.dialysis_date<=? and o.user_org_id = ? and x.schedule_date = o.dialysis_date and x.status = 1 and o.patient_id = ?", startime, endtime, orgid, patientid).Scan(&order).Group("o.patient_id").Error
  2315. return order, err
  2316. }
  2317. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2318. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND count<>0", orgID, patient_id, recordDate).Find(&consumables).Error
  2319. return
  2320. }
  2321. func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2322. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND count > 0", orgID, patient_id, recordDate).Find(&consumables).Error
  2323. return
  2324. }
  2325. func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
  2326. err = readDb.Model(&models.BloodAutomaticReduceDetail{}).Where("org_id = ? AND patient_id = ? AND record_time = ? AND status = 1 AND count > 0", orgID, patient_id, recordDate).Find(&consumables).Error
  2327. return
  2328. }
  2329. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  2330. // err = readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1", orgID, patient_id,recordDate).Find(&consumables).Error
  2331. // return
  2332. //}
  2333. //
  2334. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  2335. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date < ?", patientID, orgID, maxDate).Order("record_date desc").Find(&prepare).Error
  2336. return
  2337. }
  2338. type GoodsType struct {
  2339. ID int64 `gorm:"column:id" json:"id"`
  2340. TypeName string `gorm:"column:type_name" json:"type_name"`
  2341. Remark string `gorm:"column:remark" json:"remark"`
  2342. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2343. Status int64 `gorm:"column:status" json:"status"`
  2344. Type int64 `gorm:"column:type" json:"type"`
  2345. }
  2346. func (GoodsType) TableName() string {
  2347. return "xt_goods_type"
  2348. }
  2349. type VMGoodInfo struct {
  2350. ID int64 `gorm:"column:id" json:"id"`
  2351. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  2352. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2353. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2354. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  2355. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  2356. Total float64 `gorm:"column:total" json:"total" form:"total"`
  2357. }
  2358. func (VMGoodInfo) TableName() string {
  2359. return "xt_good_information"
  2360. }
  2361. type AutomaticReduceDetail struct {
  2362. ID int64 `gorm:"column:id" json:"id"`
  2363. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2364. Status int64 `gorm:"column:status" json:"status"`
  2365. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  2366. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2367. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2368. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2369. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2370. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2371. Count int64 `gorm:"column:count" json:"count"`
  2372. }
  2373. func (AutomaticReduceDetail) TableName() string {
  2374. return "xt_automatic_reduce_detail"
  2375. }
  2376. type DialysisBeforePrepare struct {
  2377. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2378. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2379. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2380. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2381. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  2382. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  2383. Count int64 `gorm:"column:count" json:"count" form:"count"`
  2384. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  2385. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  2386. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  2387. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  2388. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2389. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2390. }
  2391. func (DialysisBeforePrepare) TableName() string {
  2392. return "dialysis_before_prepare"
  2393. }
  2394. type MDialysisGoodsVM struct {
  2395. ID int64 `gorm:"column:id" json:"id"`
  2396. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2397. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2398. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2399. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2400. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2401. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2402. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  2403. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2404. Status int64 `gorm:"column:status" json:"status"`
  2405. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2406. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  2407. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  2408. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  2409. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  2410. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  2411. Project []*models.HisPrescriptionProject `gorm:"-" json:"project"`
  2412. }
  2413. func (MDialysisGoodsVM) TableName() string {
  2414. return "xt_schedule"
  2415. }
  2416. type VMWarehouseOutInfo struct {
  2417. ID int64 `gorm:"column:id" json:"id"`
  2418. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  2419. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2420. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2421. Count int64 `gorm:"column:count" json:"count"`
  2422. Price float64 `gorm:"column:price" json:"price"`
  2423. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  2424. Status int64 `gorm:"column:status" json:"status"`
  2425. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2426. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  2427. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  2428. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  2429. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  2430. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  2431. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  2432. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  2433. }
  2434. func (VMWarehouseOutInfo) TableName() string {
  2435. return "xt_warehouse_out_info"
  2436. }
  2437. type DialysisGoodsDate struct {
  2438. RecordDate int64
  2439. }
  2440. type DialysisGoodsDetailDate struct {
  2441. RecordTime int64
  2442. }
  2443. func MobileGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, partition_id int64, page int, limit int, patient_id int64, keywords string, end_time int64) ([]*MDialysisGoodsVM, error, int64) {
  2444. var vms []*MDialysisGoodsVM
  2445. var total int64
  2446. db := readDb.
  2447. Table("xt_schedule as sch").
  2448. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2449. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2450. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2451. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2452. return db.Preload("VMGoodInfo", "status = 1 AND org_id = ?", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND user_org_id = ? AND record_date = ? AND count > 0 ", orgID, scheduleDate)
  2453. }).
  2454. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2455. return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND org_id = ? AND count > 0 AND record_time >= ? AND record_time <= ? ", orgID, scheduleDate, end_time).Group("patient_id,good_id")
  2456. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  2457. if scheduleDate != 0 {
  2458. db = db.Where("schedule_date = ?", scheduleDate)
  2459. }
  2460. if schedule_type != 0 {
  2461. db = db.Where("schedule_type = ?", schedule_type)
  2462. }
  2463. if partition_id != 0 {
  2464. db = db.Where("partition_id = ?", partition_id)
  2465. }
  2466. if patient_id != 0 {
  2467. db = db.Where("patient_id = ?", patient_id)
  2468. }
  2469. //db = db.Count(&total)
  2470. //offset := (page - 1) * limit
  2471. //
  2472. //db = db.Offset(offset).Limit(limit)
  2473. err := db.Find(&vms).Error
  2474. return vms, err, total
  2475. }
  2476. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2477. var Id []*DialysisGoodsDetailDate
  2478. err = readDb.Model(&AutomaticReduceDetail{}).Where("patient_id = ? AND org_id = ? AND status=1 AND record_time < ? AND count > 0", patient_id, orgID, record_time).Select("record_time").Group("record_time").Order("record_time asc").Scan(&Id).Error
  2479. if len(Id) > 0 {
  2480. fmt.Println("ids232323223322233233233322332", Id)
  2481. err = readDb.Model(&AutomaticReduceDetail{}).Where("patient_id = ? AND org_id = ? AND status=1 AND record_time = ? AND count > 0", patient_id, orgID, Id[len(Id)-1].RecordTime).Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Find(&goodUser).Error
  2482. }
  2483. return
  2484. }
  2485. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2486. var Id []*DialysisGoodsDate
  2487. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date < ? AND count > 0", patient_id, orgID, record_time).Select("record_date").Group("record_date").Order("record_date asc").Scan(&Id).Error
  2488. if len(Id) > 0 {
  2489. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? AND count > 0", patient_id, orgID, Id[len(Id)-1].RecordDate).Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Find(&goodUser).Error
  2490. }
  2491. return
  2492. }
  2493. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  2494. db := readDb.Model(&models.StockInfo{})
  2495. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  2496. db = db.Joins("JOIN xt_warehouse_out_info AS info ON info.good_id=xt_good_information.id AND info.status = 1 AND info.org_id = ?", orgID).Group("xt_good_information.id")
  2497. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  2498. return db.Where("xt_warehouse_out_info.org_id = ? AND xt_warehouse_out_info.status = 1 AND xt_warehouse_out_info.sys_record_time >= ? AND xt_warehouse_out_info.sys_record_time <= ?", orgID, start_time, end_time)
  2499. })
  2500. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  2501. err = db.Order("ctime desc").Find(&list).Error
  2502. return
  2503. }
  2504. func PCGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, partition_id int64, page int, limit int, patient_id int64, keywords string, end_time int64) ([]*MDialysisGoodsVM, error, int64) {
  2505. var vms []*MDialysisGoodsVM
  2506. var total int64
  2507. db := readDb.
  2508. Model(&models.Schedule{}).
  2509. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2510. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2511. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2512. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2513. return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND user_org_id = ? AND record_date = ? AND count > 0 ", orgID, scheduleDate)
  2514. }).
  2515. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2516. return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND org_id = ? AND record_time >= ? AND record_time <=? AND count > 0", orgID, scheduleDate, end_time)
  2517. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  2518. if scheduleDate != 0 {
  2519. db = db.Where("schedule_date = ?", scheduleDate)
  2520. }
  2521. if patient_id != 0 {
  2522. db = db.Where("patient_id = ?", patient_id)
  2523. }
  2524. if len(keywords) != 0 {
  2525. keywords = "%" + keywords + "%"
  2526. db = db.Joins("JOIN xt_patients AS patient ON patient.id=xt_schedule.patient_id AND patient.status = 1 AND patient.user_org_id = ? AND patient.name Like ?", orgID, keywords)
  2527. } else {
  2528. if schedule_type != 0 {
  2529. db = db.Where("schedule_type = ?", schedule_type)
  2530. }
  2531. if partition_id != 0 {
  2532. db = db.Where("partition_id = ?", partition_id)
  2533. }
  2534. db = db.Count(&total)
  2535. offset := (page - 1) * limit
  2536. db = db.Offset(offset).Limit(limit)
  2537. }
  2538. err := db.Find(&vms).Error
  2539. return vms, err, total
  2540. }
  2541. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2542. var Id []*DialysisGoodsDetailDate
  2543. err = readDb.Model(&AutomaticReduceDetail{}).Where("patient_id = ? AND org_id = ? AND status=1 AND record_time < ? AND count > 0", patient_id, orgID, record_time).Select("record_time").Group("record_time").Order("record_time asc").Scan(&Id).Error
  2544. if len(Id) > 0 {
  2545. err = readDb.Model(&AutomaticReduceDetail{}).Where("patient_id = ? AND org_id = ? AND status=1 AND record_time = ? AND count > 0", patient_id, orgID, Id[len(Id)-1].RecordTime).Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Find(&goodUser).Error
  2546. }
  2547. return
  2548. }
  2549. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2550. var Id []*DialysisGoodsDate
  2551. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date < ? AND count > 0", patient_id, orgID, record_time).Select("record_date").Group("record_date").Order("record_date asc").Scan(&Id).Error
  2552. if len(Id) > 0 {
  2553. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? AND count > 0", patient_id, orgID, Id[len(Id)-1].RecordDate).Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Find(&goodUser).Error
  2554. }
  2555. return
  2556. }
  2557. func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
  2558. evaluation := models.PredialysisEvaluation{}
  2559. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2560. if err == gorm.ErrRecordNotFound {
  2561. return nil, err
  2562. }
  2563. if err != nil {
  2564. return nil, err
  2565. }
  2566. return &evaluation, nil
  2567. }
  2568. func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
  2569. redis := RedisClient()
  2570. defer redis.Close()
  2571. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientid, 10) + ":" + strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
  2572. his_doctor_advice_str, _ := redis.Get(key).Result()
  2573. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2574. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ?", patientid, orgid, recorddate).Find(&his).Error
  2575. if err != nil {
  2576. if err == gorm.ErrRecordNotFound {
  2577. if len(his) <= 0 {
  2578. redis.Set(key, "null", time.Second*60*60*18)
  2579. }
  2580. return his, nil
  2581. } else {
  2582. return his, err
  2583. }
  2584. } else {
  2585. if len(his) > 0 {
  2586. //缓存数据
  2587. his_doctor_advice_str, err := json.Marshal(his)
  2588. if err == nil {
  2589. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2590. }
  2591. } else {
  2592. redis.Set(key, "null", time.Second*60*60*18)
  2593. }
  2594. return his, nil
  2595. }
  2596. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2597. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2598. return his, nil
  2599. }
  2600. }
  2601. func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  2602. prescription := models.DialysisPrescription{}
  2603. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2604. if err == gorm.ErrRecordNotFound {
  2605. return nil, err
  2606. }
  2607. if err != nil {
  2608. return nil, err
  2609. }
  2610. return &prescription, nil
  2611. }
  2612. type HisMScheduleDoctorAdviceVM struct {
  2613. ID int64 `gorm:"column:id" json:"id"`
  2614. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2615. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2616. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2617. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2618. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2619. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2620. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2621. Status int64 `gorm:"column:status" json:"status"`
  2622. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2623. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2624. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2625. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2626. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2627. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2628. }
  2629. func (HisMScheduleDoctorAdviceVM) TableName() string {
  2630. return "xt_schedule"
  2631. }
  2632. type HisMScheduleDoctorAdviceVMOne struct {
  2633. ID int64 `gorm:"column:id" json:"id"`
  2634. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2635. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2636. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2637. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2638. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2639. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2640. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2641. Status int64 `gorm:"column:status" json:"status"`
  2642. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2643. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2644. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2645. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2646. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2647. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2648. }
  2649. func (HisMScheduleDoctorAdviceVMOne) TableName() string {
  2650. return "xt_schedule"
  2651. }
  2652. type HisMScheduleProjectVM struct {
  2653. ID int64 `gorm:"column:id" json:"id"`
  2654. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2655. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2656. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2657. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2658. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2659. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2660. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2661. Status int64 `gorm:"column:status" json:"status"`
  2662. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2663. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2664. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2665. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2666. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2667. HisPrescriptionTeamProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"team_project"`
  2668. }
  2669. func (HisMScheduleProjectVM) TableName() string {
  2670. return "xt_schedule"
  2671. }
  2672. func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
  2673. config := models.XtHisConfig{}
  2674. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  2675. return config, err
  2676. }
  2677. func GetHisDoctorPatientById(orgid int64, patientid int64, recordtime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  2678. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
  2679. if orgid > 0 {
  2680. db = db.Where("x.user_org_id = ?", orgid)
  2681. }
  2682. if patientid > 0 {
  2683. db = db.Where("x.patient_id =?", patientid)
  2684. }
  2685. if recordtime > 0 {
  2686. db = db.Where("x.advice_date = ?", recordtime)
  2687. }
  2688. err = db.Select("x.id,x.user_org_id,x.patient_id,x.his_patient_id,x.advice_type,x.advice_date,x.start_time,x.advice_name,x.advice_desc,x.reminder_date,x.single_dose,x.single_dose_unit,x.single_dose_unit,x.prescribing_number_unit,x.prescribing_number,x.delivery_way,x.execution_frequency,x.advice_doctor,x.status,x.advice_affirm,x.remark,x.stop_time,x.stop_reason,x.stop_doctor,x.stop_state,x.parent_id,x.execution_time,x.execution_staff,x.checker,x.record_date,x.dialysis_order_id,x.check_time,x.check_state,x.drug_spec,x.drug_spec_unit,x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.template_id,x.modifier,x.drug_id,x.price,x.prescription_id,x.med_list_codg,x.feedetl_sn,x.day").Find(&advice).Error
  2689. return advice, err
  2690. }
  2691. func GetDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2692. db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1 and x.advice_type =2")
  2693. if startime > 0 {
  2694. db = db.Where("x.advice_date >= ?", startime)
  2695. }
  2696. if endtime > 0 {
  2697. db = db.Where("x.advice_date<=?", endtime)
  2698. }
  2699. if orgid > 0 {
  2700. db = db.Where("x.user_org_id = ?", orgid)
  2701. }
  2702. if len(deliveway) > 0 {
  2703. db = db.Where("x.delivery_way = ?", deliveway)
  2704. }
  2705. err = db.Select("x.advice_name,x.advice_desc,x.delivery_way,count(x.id) as total").Group("x.advice_name,x.advice_desc").Scan(&advice).Error
  2706. return advice, err
  2707. }
  2708. func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2709. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.advice_type =2")
  2710. if startime > 0 {
  2711. db = db.Where("x.advice_date >= ?", startime)
  2712. }
  2713. if endtime > 0 {
  2714. db = db.Where("x.advice_date<=?", endtime)
  2715. }
  2716. if orgid > 0 {
  2717. db = db.Where("x.user_org_id = ?", orgid)
  2718. }
  2719. if len(deliveway) > 0 {
  2720. db = db.Where("x.delivery_way = ?", deliveway)
  2721. }
  2722. err = db.Select("x.advice_name,x.advice_desc,x.delivery_way,count(x.id) as total").Group("x.advice_name,x.advice_desc").Scan(&advice).Error
  2723. return advice, err
  2724. }
  2725. func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64) ([]*MScheduleDoctorAdviceVM, error) {
  2726. var vms []*MScheduleDoctorAdviceVM
  2727. adviceWhere := ""
  2728. adviceCondition := []interface{}{}
  2729. if adviceType == 0 {
  2730. if patientType == 0 {
  2731. if patient_id > 0 {
  2732. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  2733. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2734. } else {
  2735. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  2736. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2737. }
  2738. } else if patientType == 1 {
  2739. if patient_id > 0 {
  2740. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  2741. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  2742. } else {
  2743. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  2744. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  2745. }
  2746. } else if patientType == 2 {
  2747. if patient_id > 0 {
  2748. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?)"
  2749. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2750. } else {
  2751. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  2752. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2753. }
  2754. }
  2755. } else if adviceType == 1 {
  2756. if patientType == 0 {
  2757. if patient_id > 0 {
  2758. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  2759. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2760. } else {
  2761. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  2762. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2763. }
  2764. } else if patientType == 1 {
  2765. if patient_id > 0 {
  2766. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  2767. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  2768. } else {
  2769. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  2770. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  2771. }
  2772. } else if patientType == 2 {
  2773. if patient_id > 0 {
  2774. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  2775. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2776. } else {
  2777. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  2778. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2779. }
  2780. }
  2781. } else if adviceType == 3 {
  2782. if patientType == 0 {
  2783. if patient_id > 0 {
  2784. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  2785. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2786. } else {
  2787. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  2788. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2789. }
  2790. } else if patientType == 1 {
  2791. if patient_id > 0 {
  2792. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  2793. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  2794. } else {
  2795. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  2796. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  2797. }
  2798. } else if patientType == 2 {
  2799. if patient_id > 0 {
  2800. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  2801. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2802. } else {
  2803. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  2804. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2805. }
  2806. }
  2807. } else if adviceType == 2 && len(deliverWay) > 0 {
  2808. if patientType == 0 {
  2809. if patient_id > 0 {
  2810. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  2811. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  2812. } else {
  2813. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  2814. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  2815. }
  2816. } else if patientType == 1 {
  2817. if patient_id > 0 {
  2818. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  2819. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  2820. } else {
  2821. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  2822. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  2823. }
  2824. } else if patientType == 2 {
  2825. if patient_id > 0 {
  2826. } else {
  2827. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  2828. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  2829. }
  2830. }
  2831. } else if adviceType == 2 && len(deliverWay) <= 0 {
  2832. if patientType == 0 {
  2833. if patient_id > 0 {
  2834. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  2835. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2836. } else {
  2837. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  2838. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2839. }
  2840. } else if patientType == 1 {
  2841. if patient_id > 0 {
  2842. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  2843. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  2844. } else {
  2845. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  2846. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  2847. }
  2848. } else if patientType == 2 {
  2849. if patient_id > 0 {
  2850. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  2851. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2852. } else {
  2853. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  2854. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2855. }
  2856. }
  2857. }
  2858. db := readDb.Table("xt_schedule")
  2859. if scheduleType > 0 {
  2860. db = db.Where("schedule_type = ?", scheduleType)
  2861. }
  2862. if partitonType > 0 {
  2863. db = db.Where("partition_id = ?", partitonType)
  2864. }
  2865. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2866. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  2867. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  2868. }).
  2869. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2870. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2871. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  2872. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  2873. Preload("DoctorAdvices", adviceCondition...).
  2874. Where("status = 1 AND user_org_id = ?", orgID)
  2875. if scheduleDate != 0 {
  2876. db = db.Where("schedule_date = ?", scheduleDate)
  2877. }
  2878. err := db.Find(&vms).Error
  2879. return vms, err
  2880. }
  2881. func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  2882. var vms []*HisMScheduleDoctorAdviceVM
  2883. if len(deliverWay) > 0 {
  2884. db := readDb.Table("xt_schedule")
  2885. if scheduleType > 0 {
  2886. db = db.Where("schedule_type = ?", scheduleType)
  2887. }
  2888. if partitionType > 0 {
  2889. db = db.Where("partition_id = ?", partitionType)
  2890. }
  2891. if patient_id > 0 {
  2892. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  2893. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2894. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2895. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  2896. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  2897. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  2898. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  2899. }).
  2900. Where("status = 1 AND user_org_id = ?", orgID)
  2901. if scheduleDate != 0 {
  2902. db = db.Where("schedule_date = ?", scheduleDate)
  2903. }
  2904. err = db.Find(&vms).Error
  2905. } else {
  2906. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2907. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2908. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2909. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  2910. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  2911. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  2912. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  2913. }).
  2914. Where("status = 1 AND user_org_id = ?", orgID)
  2915. if scheduleDate != 0 {
  2916. db = db.Where("schedule_date = ?", scheduleDate)
  2917. }
  2918. err = db.Find(&vms).Error
  2919. }
  2920. } else {
  2921. db := readDb.Table("xt_schedule")
  2922. if scheduleType > 0 {
  2923. db = db.Where("schedule_type = ?", scheduleType)
  2924. }
  2925. if partitionType > 0 {
  2926. db = db.Where("partition_id = ?", partitionType)
  2927. }
  2928. if patient_id > 0 {
  2929. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  2930. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2931. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2932. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  2933. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  2934. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  2935. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  2936. }).
  2937. Where("status = 1 AND user_org_id = ?", orgID)
  2938. if scheduleDate != 0 {
  2939. db = db.Where("schedule_date = ?", scheduleDate)
  2940. }
  2941. err = db.Find(&vms).Error
  2942. } else {
  2943. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2944. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2945. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2946. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  2947. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  2948. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  2949. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  2950. }).
  2951. Where("status = 1 AND user_org_id = ?", orgID)
  2952. if scheduleDate != 0 {
  2953. db = db.Where("schedule_date = ?", scheduleDate)
  2954. }
  2955. err = db.Find(&vms).Error
  2956. }
  2957. }
  2958. return vms, err
  2959. }
  2960. func BatchDeleteMonitor(ids []string) (err error) {
  2961. if len(ids) == 1 {
  2962. err = XTWriteDB().Model(&models.MonitoringRecord{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  2963. } else {
  2964. err = XTWriteDB().Model(models.MonitoringRecord{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  2965. }
  2966. return
  2967. }
  2968. func GetPatientDialysisRecordList(patientid int64, startime int64, endtime int64) (order []*models.XtDialysisOrders, err error) {
  2969. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  2970. //table := XTReadDB().Table("xt_schedule as s")
  2971. //fmt.Println(table)
  2972. if patientid > 0 {
  2973. db = db.Where("x.patient_id = ?", patientid)
  2974. }
  2975. if startime > 0 {
  2976. db = db.Where("x.dialysis_date>=?", startime)
  2977. }
  2978. if endtime > 0 {
  2979. db = db.Where("x.dialysis_date <= ?", endtime)
  2980. }
  2981. err = db.Select("x.id,x.dialysis_date,x.schedual_type,s.mode_id").Joins("left join xt_schedule as s on x.patient_id = s.patient_id and x.dialysis_date = s.schedule_date ").Scan(&order).Error
  2982. return order, err
  2983. }
  2984. func BatchDeleteAdvice(ids []string) (err error) {
  2985. if len(ids) == 1 {
  2986. err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  2987. } else {
  2988. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  2989. }
  2990. return
  2991. }
  2992. func BatchDeleteHisAdvice(ids []string) (err error) {
  2993. if len(ids) == 1 {
  2994. err = XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  2995. } else {
  2996. err = XTWriteDB().Model(models.HisDoctorAdviceInfo{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  2997. }
  2998. return
  2999. }
  3000. func UpdateAutoReduceDetail(good_id int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  3001. detail := models.AutomaticReduceDetail{}
  3002. err := XTWriteDB().Model(&detail).Where("good_id = ? and status = 1 and record_time = ? and patient_id = ?", good_id, record_time, patient_id).Updates(map[string]interface{}{"count": count}).Error
  3003. return detail, err
  3004. }
  3005. func DeleteAutoReduceDetail(good_id int64, record_time int64, patient_id int64) error {
  3006. detail := models.AutomaticReduceDetail{}
  3007. err := XTWriteDB().Model(&detail).Where("good_id = ? and status = 1 and record_time = ? and patient_id = ?", good_id, record_time, patient_id).Updates(map[string]interface{}{"status": 0}).Error
  3008. return err
  3009. }
  3010. func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
  3011. detail := models.DialysisBeforePrepare{}
  3012. err := XTWriteDB().Model(&detail).Where("good_id = ? and status = 1 and record_date = ? and patient_id = ?", good_id, record_time, patient_id).Updates(map[string]interface{}{"status": 0}).Error
  3013. return err
  3014. }
  3015. func BatchAdviceCheck(ids []string, creator int64) error {
  3016. advice := models.XtDoctorAdvice{}
  3017. err := XTWriteDB().Model(&advice).Where("id IN(?) and status = 1", ids).Updates(map[string]interface{}{"check_state": 1, "checker": creator, "check_time": time.Now().Unix()}).Error
  3018. return err
  3019. }
  3020. func BatchHisAdviceCheck(ids []string, creator int64) error {
  3021. advice := models.HisDoctorAdviceInfo{}
  3022. err := XTWriteDB().Model(&advice).Where("id IN(?) and status = 1", ids).Updates(map[string]interface{}{"check_state": 1, "checker": creator, "check_time": time.Now().Unix()}).Error
  3023. return err
  3024. }
  3025. func BatchAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3026. advice := models.XtDoctorAdvice{}
  3027. err := XTWriteDB().Model(&advice).Where("id IN(?) and status = 1", ids).Updates(map[string]interface{}{"execution_state": 1, "execution_staff": creator, "execution_time": execution_state}).Error
  3028. return err
  3029. }
  3030. func BatchHisAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3031. advice := models.HisDoctorAdviceInfo{}
  3032. err := XTWriteDB().Model(&advice).Where("id IN(?) and status = 1", ids).Updates(map[string]interface{}{"execution_state": 1, "execution_staff": creator, "execution_time": execution_state}).Error
  3033. return err
  3034. }
  3035. func GetAdviceExecutionById(ids []string) (doctor []*models.XtDoctorAdvice, err error) {
  3036. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3037. return doctor, err
  3038. }
  3039. func GetHisAdviceExecutionById(ids []string) (doctor []*models.HisDoctorAdviceInfo, err error) {
  3040. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3041. return doctor, err
  3042. }
  3043. func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
  3044. config := models.XtHisProjectConfig{}
  3045. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3046. return config, err
  3047. }
  3048. func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
  3049. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  3050. return db.Preload("GoodsType", "status = 1").Where("status = 1 ")
  3051. }).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND type = 3", org_id, record_date, patient_id).Find(&project).Error
  3052. return
  3053. }
  3054. func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64) ([]*HisMScheduleProjectVM, error) {
  3055. var vms []*HisMScheduleProjectVM
  3056. if patientType == 0 {
  3057. if patient_id > 0 {
  3058. db := readDb.
  3059. Table("xt_schedule").
  3060. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3061. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3062. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3063. }).
  3064. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3065. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3066. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3067. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3068. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3069. }).
  3070. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3071. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3072. }).Where("status = 1 AND user_org_id = ?", orgID)
  3073. if scheduleDate != 0 {
  3074. db = db.Where("schedule_date = ?", scheduleDate)
  3075. }
  3076. err = db.Find(&vms).Error
  3077. } else {
  3078. if patient_id > 0 {
  3079. db := readDb.
  3080. Table("xt_schedule").
  3081. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3082. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3083. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3084. }).
  3085. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3086. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3087. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3088. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3089. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3090. }).
  3091. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3092. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3093. }).Where("status = 1 AND user_org_id = ?", orgID)
  3094. if scheduleDate != 0 {
  3095. db = db.Where("schedule_date = ?", scheduleDate)
  3096. }
  3097. err = db.Find(&vms).Error
  3098. } else {
  3099. db := readDb.
  3100. Table("xt_schedule").
  3101. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3102. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3103. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3104. }).
  3105. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3106. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3107. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3108. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3109. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3110. }).
  3111. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3112. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3113. }).Where("status = 1 AND user_org_id = ?", orgID)
  3114. if scheduleDate != 0 {
  3115. db = db.Where("schedule_date = ?", scheduleDate)
  3116. }
  3117. err = db.Find(&vms).Error
  3118. }
  3119. }
  3120. }
  3121. if patientType > 0 {
  3122. db := readDb.
  3123. Table("xt_schedule").
  3124. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3125. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3126. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3127. }).
  3128. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3129. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3130. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3131. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3132. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3133. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3134. }).
  3135. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3136. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  3137. }).Where("status = 1 AND user_org_id = ?", orgID)
  3138. if scheduleDate != 0 {
  3139. db = db.Where("schedule_date = ?", scheduleDate)
  3140. }
  3141. err = db.Find(&vms).Error
  3142. }
  3143. return vms, err
  3144. }
  3145. func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3146. prepare := models.DialysisBeforePrepare{}
  3147. err := XTWriteDB().Model(&prepare).Where("good_id= ? and record_date = ? and patient_id = ? and count <> 0 and status = 1", good_id, record_time, patient_id).Updates(map[string]interface{}{"count": count}).Error
  3148. return err
  3149. }
  3150. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3151. detail := models.AutomaticReduceDetail{}
  3152. err := XTWriteDB().Model(&detail).Where("good_id = ? and record_time = ? and patient_id = ? and count <> 0 and status = 1", good_id, record_time, patient_id).Updates(map[string]interface{}{"count": count}).Error
  3153. return err
  3154. }
  3155. func MobileGetDialysisSolutionByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  3156. var record models.DialysisSolution
  3157. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  3158. if err != nil {
  3159. if err == gorm.ErrRecordNotFound {
  3160. return nil, nil
  3161. } else {
  3162. return nil, err
  3163. }
  3164. }
  3165. return &record, nil
  3166. }
  3167. func MobileGetLastDialysisPrescribeByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  3168. var record models.DialysisPrescription
  3169. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ?", patientID, orgID, mode_id).Last(&record).Error
  3170. if err != nil {
  3171. if err == gorm.ErrRecordNotFound {
  3172. return nil, nil
  3173. } else {
  3174. return nil, err
  3175. }
  3176. }
  3177. return &record, nil
  3178. }
  3179. func MobileGetSystemDialysisPrescribeByModeIdSeven(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  3180. var record models.SystemPrescription
  3181. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  3182. if err != nil {
  3183. if err == gorm.ErrRecordNotFound {
  3184. return nil, nil
  3185. } else {
  3186. return nil, err
  3187. }
  3188. }
  3189. return &record, nil
  3190. }
  3191. // 透前评估
  3192. func MobileGetPredialysisEvaluationSeven(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  3193. var record models.PredialysisEvaluation
  3194. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  3195. if err != nil {
  3196. if err == gorm.ErrRecordNotFound {
  3197. return nil, nil
  3198. } else {
  3199. return nil, err
  3200. }
  3201. }
  3202. return &record, nil
  3203. }
  3204. func MobileGetDialysisGoodsSeven(orgID int64, scheduleDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  3205. db := readDb.Table("dialysis_before_prepare as p").Where("status = 1")
  3206. if orgID > 0 {
  3207. db = db.Where("p.user_org_id = ?", orgID)
  3208. }
  3209. if scheduleDate > 0 {
  3210. db = db.Where("p.record_date<= ?", scheduleDate)
  3211. }
  3212. err = db.Select("p.patient_id,p.good_id,Max(p.record_date) as record_date").Group("patient_id").Order("id desc").Find(&prepare).Error
  3213. return prepare, err
  3214. }
  3215. func MobileGetDialysisGoodsSix(orgID int64, scheduleDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  3216. err = readDb.Where("user_org_id = ? AND status=1 AND record_date <= ? AND count > 0", orgID, scheduleDate).Select("patient_id,good_id,record_date").Find(&prepare).Error
  3217. return prepare, err
  3218. }
  3219. func GetMobileAutoReduce(orgID int64, scheduleDate int64) (auto []*models.AutomaticReduceDetail, err error) {
  3220. err = readDb.Where("org_id = ? and status = 1 and record_time = ?", orgID, scheduleDate).Find(&auto).Error
  3221. return auto, err
  3222. }