mobile_dialysis_service.go 168KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580
  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 MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  728. var record models.DialysisOrder
  729. redis := RedisClient()
  730. defer redis.Close()
  731. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_order"
  732. dialysis_order_str, _ := redis.Get(key).Result()
  733. if len(dialysis_order_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  734. 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
  735. if err != nil {
  736. if err == gorm.ErrRecordNotFound {
  737. return nil, nil
  738. } else {
  739. return nil, err
  740. }
  741. } else {
  742. if record.ID > 0 {
  743. //缓存数据
  744. dialysis_order_str, err := json.Marshal(record)
  745. if err == nil {
  746. redis.Set(key, dialysis_order_str, time.Second*60*60*18)
  747. }
  748. } else {
  749. redis.Set(key, "null", time.Second*60*60*18)
  750. }
  751. return &record, nil
  752. }
  753. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  754. if dialysis_order_str == "null" {
  755. 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
  756. return &record, nil
  757. } else {
  758. json.Unmarshal([]byte(dialysis_order_str), &record)
  759. return &record, nil
  760. }
  761. }
  762. }
  763. // 双人核对
  764. func MobileGetDoubleCheck(orgID int64, patientID int64, recordDate int64) (*models.DoubleCheck, error) {
  765. var record models.DoubleCheck
  766. redis := RedisClient()
  767. defer redis.Close()
  768. // cur_date := time.Now().Format("2006-01-02")
  769. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":double_check"
  770. double_check_str, _ := redis.Get(key).Result()
  771. if len(double_check_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  772. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  773. if err != nil {
  774. if err == gorm.ErrRecordNotFound {
  775. if record.ID <= 0 {
  776. redis.Set(key, "null", time.Second*60*60*18)
  777. }
  778. return nil, nil
  779. } else {
  780. return nil, err
  781. }
  782. } else {
  783. if record.ID > 0 {
  784. //缓存数据
  785. double_check_str, err := json.Marshal(record)
  786. if err == nil {
  787. redis.Set(key, double_check_str, time.Second*60*60*18)
  788. }
  789. } else {
  790. redis.Set(key, "null", time.Second*60*60*18)
  791. }
  792. return &record, nil
  793. }
  794. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  795. if double_check_str == "null" {
  796. return &record, nil
  797. } else {
  798. json.Unmarshal([]byte(double_check_str), &record)
  799. return &record, nil
  800. }
  801. }
  802. }
  803. // 透析监测记录
  804. func MobileGetMonitorRecords(orgID int64, patientID int64, recordDate int64) ([]*models.MonitoringRecord, error) {
  805. var records []*models.MonitoringRecord
  806. redis := RedisClient()
  807. defer redis.Close()
  808. // cur_date := time.Now().Format("2006-01-02")
  809. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":monitor_records"
  810. monitor_records_str, _ := redis.Get(key).Result()
  811. if len(monitor_records_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  812. 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
  813. if err != nil {
  814. if err == gorm.ErrRecordNotFound {
  815. //if len(records) <= 0 {
  816. // redis.Set(key, "null", time.Second*60*60*18)
  817. //}
  818. return nil, nil
  819. } else {
  820. return nil, err
  821. }
  822. } else {
  823. if len(records) > 0 {
  824. //缓存数据
  825. monitor_records_str, err := json.Marshal(records)
  826. if err == nil {
  827. redis.Set(key, monitor_records_str, time.Second*60*60*18)
  828. }
  829. } else {
  830. redis.Set(key, "null", time.Second*60*60*18)
  831. }
  832. return records, nil
  833. }
  834. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  835. if monitor_records_str == "null" {
  836. return records, nil
  837. } else {
  838. json.Unmarshal([]byte(monitor_records_str), &records)
  839. return records, nil
  840. }
  841. }
  842. }
  843. func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64) (*models.MonitoringRecord, error) {
  844. var records models.MonitoringRecord
  845. 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
  846. if err != nil {
  847. return nil, err
  848. }
  849. return &records, nil
  850. }
  851. func MobileGetLastMonitorRecordOne(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  852. var record models.MonitoringRecord
  853. 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
  854. if err != nil {
  855. if err == gorm.ErrRecordNotFound {
  856. return nil, nil
  857. } else {
  858. return nil, err
  859. }
  860. }
  861. return &record, nil
  862. }
  863. func MobileGetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  864. var record models.MonitoringRecord
  865. redis := RedisClient()
  866. defer redis.Close()
  867. // cur_date := time.Now().Format("2006-01-02")
  868. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(beforeDate, 10) + ":monitor_record_last"
  869. monitor_record_last_str, _ := redis.Get(key).Result()
  870. if len(monitor_record_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  871. 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
  872. if err != nil {
  873. if err == gorm.ErrRecordNotFound {
  874. if record.ID <= 0 {
  875. redis.Set(key, "null", time.Second*60*60*18)
  876. }
  877. return nil, nil
  878. } else {
  879. return nil, err
  880. }
  881. } else {
  882. if record.ID > 0 {
  883. //缓存数据
  884. monitor_record_last_str, err := json.Marshal(record)
  885. if err == nil {
  886. redis.Set(key, monitor_record_last_str, time.Second*60*60*18)
  887. }
  888. } else {
  889. redis.Set(key, "null", time.Second*60*60*18)
  890. }
  891. return &record, nil
  892. }
  893. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  894. if monitor_record_last_str == "null" {
  895. return &record, nil
  896. } else {
  897. json.Unmarshal([]byte(monitor_record_last_str), &record)
  898. return &record, nil
  899. }
  900. }
  901. }
  902. func MobileGetAssessmentAfterDislysisOne(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  903. var record models.AssessmentAfterDislysis
  904. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  905. if err != nil {
  906. if err == gorm.ErrRecordNotFound {
  907. return nil, nil
  908. } else {
  909. return nil, err
  910. }
  911. }
  912. return &record, nil
  913. }
  914. // 透后评估
  915. func MobileGetAssessmentAfterDislysis(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  916. var record models.AssessmentAfterDislysis
  917. redis := RedisClient()
  918. defer redis.Close()
  919. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_after_dislysis"
  920. assessment_after_dislysis_str, _ := redis.Get(key).Result()
  921. if len(assessment_after_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  922. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  923. if err != nil {
  924. if err == gorm.ErrRecordNotFound {
  925. if record.ID <= 0 {
  926. redis.Set(key, "null", time.Second*60*60*18)
  927. }
  928. return nil, nil
  929. } else {
  930. return nil, err
  931. }
  932. } else {
  933. if record.ID > 0 {
  934. //缓存数据
  935. assessment_after_dislysis_str, err := json.Marshal(record)
  936. if err == nil {
  937. redis.Set(key, assessment_after_dislysis_str, time.Second*60*60*18)
  938. }
  939. } else {
  940. redis.Set(key, "null", time.Second*60*60*18)
  941. }
  942. return &record, nil
  943. }
  944. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  945. if assessment_after_dislysis_str == "null" {
  946. return &record, nil
  947. } else {
  948. json.Unmarshal([]byte(assessment_after_dislysis_str), &record)
  949. return &record, nil
  950. }
  951. }
  952. }
  953. // 获取 maxDate 之前一次的透后评估记录
  954. func MobileGetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  955. var record models.AssessmentAfterDislysis
  956. redis := RedisClient()
  957. defer redis.Close()
  958. // cur_date := time.Now().Format("2006-01-02")
  959. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_after_dislysis_last"
  960. assessment_after_dislysis_last_str, _ := redis.Get(key).Result()
  961. if len(assessment_after_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  962. 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
  963. if err != nil {
  964. if err == gorm.ErrRecordNotFound {
  965. if record.ID <= 0 {
  966. redis.Set(key, "null", time.Second*60*60*18)
  967. }
  968. return nil, nil
  969. } else {
  970. return nil, err
  971. }
  972. } else {
  973. if record.ID > 0 {
  974. //缓存数据
  975. assessment_after_dislysis_last_str, err := json.Marshal(record)
  976. if err == nil {
  977. redis.Set(key, assessment_after_dislysis_last_str, time.Second*60*60*18)
  978. }
  979. } else {
  980. redis.Set(key, "null", time.Second*60*60*18)
  981. }
  982. return &record, nil
  983. }
  984. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  985. if assessment_after_dislysis_last_str == "null" {
  986. return &record, nil
  987. } else {
  988. json.Unmarshal([]byte(assessment_after_dislysis_last_str), &record)
  989. return &record, nil
  990. }
  991. }
  992. }
  993. func MobileGetLastTimeAssessmentAfterDislysisOne(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  994. var record models.AssessmentAfterDislysis
  995. 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
  996. if err != nil {
  997. if err == gorm.ErrRecordNotFound {
  998. return nil, nil
  999. } else {
  1000. return nil, err
  1001. }
  1002. }
  1003. return &record, nil
  1004. }
  1005. func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
  1006. dislysis := models.AssessmentAfterDislysis{}
  1007. 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
  1008. return dislysis, err
  1009. }
  1010. // 治疗小结
  1011. func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
  1012. var record models.TreatmentSummary
  1013. redis := RedisClient()
  1014. defer redis.Close()
  1015. // cur_date := time.Now().Format("2006-01-02")
  1016. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":treatment_summary"
  1017. treatment_summary_str, _ := redis.Get(key).Result()
  1018. if len(treatment_summary_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1019. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  1020. if err != nil {
  1021. if err == gorm.ErrRecordNotFound {
  1022. if record.ID <= 0 {
  1023. redis.Set(key, "null", time.Second*60*60*18)
  1024. }
  1025. return nil, nil
  1026. } else {
  1027. return nil, err
  1028. }
  1029. } else {
  1030. if record.ID > 0 {
  1031. //缓存数据
  1032. treatment_summary_str, err := json.Marshal(record)
  1033. if err == nil {
  1034. redis.Set(key, treatment_summary_str, time.Second*60*60*18)
  1035. }
  1036. } else {
  1037. redis.Set(key, "null", time.Second*60*60*18)
  1038. }
  1039. return &record, nil
  1040. }
  1041. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1042. if treatment_summary_str == "null" {
  1043. return &record, nil
  1044. } else {
  1045. json.Unmarshal([]byte(treatment_summary_str), &record)
  1046. return &record, nil
  1047. }
  1048. }
  1049. }
  1050. // 透析处方
  1051. func MobileGetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1052. var record models.DialysisPrescription
  1053. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&record).Error
  1054. if err != nil {
  1055. if err == gorm.ErrRecordNotFound {
  1056. return nil, nil
  1057. } else {
  1058. return nil, err
  1059. }
  1060. }
  1061. return &record, nil
  1062. }
  1063. func MobileGetDialysisSchedual(orgID int64, patientID int64, scheduleDate int64) (*models.XtSchedule, error) {
  1064. var schedule models.XtSchedule
  1065. err := readDb.Model(&models.XtSchedule{}).Where("patient_id = ? and user_org_id = ? and status = 1 and schedule_date = ?", patientID, orgID, scheduleDate).First(&schedule).Error
  1066. if err != nil {
  1067. if err == gorm.ErrRecordNotFound {
  1068. return nil, nil
  1069. } else {
  1070. return nil, err
  1071. }
  1072. }
  1073. return &schedule, nil
  1074. }
  1075. // 透析方案
  1076. func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
  1077. var record models.DialysisSolution
  1078. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1079. if err != nil {
  1080. if err == gorm.ErrRecordNotFound {
  1081. return nil, nil
  1082. } else {
  1083. return nil, err
  1084. }
  1085. }
  1086. return &record, nil
  1087. }
  1088. func MobileGetPatientById(orgID int64, patientID int64) (*models.Patients, error) {
  1089. var patient models.Patients
  1090. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id = ? and status = 1", patientID, orgID).First(&patient).Error
  1091. if err != nil {
  1092. if err == gorm.ErrRecordNotFound {
  1093. return nil, nil
  1094. } else {
  1095. return nil, err
  1096. }
  1097. }
  1098. return &patient, nil
  1099. }
  1100. func DisableMonitor(orgID int64, patientID int64, recordID int64, admin_user_id int64) error {
  1101. fmt.Println()
  1102. tx := writeDb.Begin()
  1103. updateTime := time.Now().Unix()
  1104. 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
  1105. if err != nil {
  1106. tx.Rollback()
  1107. return err
  1108. }
  1109. tx.Commit()
  1110. return nil
  1111. }
  1112. func GetMonitor(orgID int64, patientID int64, id int64) (*models.MonitoringRecord, error) {
  1113. var monitor models.MonitoringRecord
  1114. var err error
  1115. err = readDb.Model(&models.MonitoringRecord{}).Where("id = ? AND user_org_id = ? AND patient_id = ? AND status = 1 ", id, orgID, patientID).Find(&monitor).Error
  1116. if err == gorm.ErrRecordNotFound {
  1117. return nil, nil
  1118. }
  1119. if err != nil {
  1120. return nil, err
  1121. }
  1122. return &monitor, nil
  1123. }
  1124. type MScheduleDoctorAdviceVM struct {
  1125. ID int64 `gorm:"column:id" json:"id"`
  1126. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1127. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1128. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1129. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1130. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1131. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1132. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1133. Status int64 `gorm:"column:status" json:"status"`
  1134. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1135. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1136. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1137. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1138. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1139. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1140. }
  1141. func (MScheduleDoctorAdviceVM) TableName() string {
  1142. return "xt_schedule"
  1143. }
  1144. type MScheduleDoctorAdviceVMOne struct {
  1145. ID int64 `gorm:"column:id" json:"id"`
  1146. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1147. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  1148. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  1149. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1150. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1151. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1152. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1153. Status int64 `gorm:"column:status" json:"status"`
  1154. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1155. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1156. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1157. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1158. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1159. //DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1160. }
  1161. func (MScheduleDoctorAdviceVMOne) TableName() string {
  1162. return "xt_schedule"
  1163. }
  1164. type MDoctorAdviceVM struct {
  1165. ID int64 `gorm:"column:id" json:"id"`
  1166. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1167. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1168. AdviceType int64 `gorm:"column:advice_type" json:"advice_type"`
  1169. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date"`
  1170. StartTime int64 `gorm:"column:start_time" json:"start_time"`
  1171. AdviceName string `gorm:"column:advice_name" json:"advice_name"`
  1172. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc"`
  1173. ReminderDate int64 `gorm:"column:reminder_date" json:"reminder_date"`
  1174. SingleDose float64 `gorm:"column:single_dose" json:"single_dose"`
  1175. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit"`
  1176. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number"`
  1177. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit"`
  1178. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way"`
  1179. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency"`
  1180. AdviceDoctor int64 `gorm:"column:advice_doctor" json:"advice_doctor"`
  1181. Status int64 `gorm:"column:status" json:"status"`
  1182. CreatedTime int64 `gorm:"column:created_time" json:"created_time"`
  1183. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"`
  1184. AdviceAffirm string `gorm:"column:advice_affirm" json:"advice_affirm"`
  1185. Remark string `gorm:"column:remark" json:"remark"`
  1186. StopTime int64 `gorm:"column:stop_time" json:"stop_time"`
  1187. StopReason string `gorm:"column:stop_reason" json:"stop_reason"`
  1188. StopDoctor int64 `gorm:"column:stop_doctor" json:"stop_doctor"`
  1189. StopState int64 `gorm:"column:stop_state" json:"stop_state"`
  1190. ParentId int64 `gorm:"column:parent_id" json:"parent_id"`
  1191. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time"`
  1192. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff"`
  1193. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state"`
  1194. Checker int64 `gorm:"column:checker" json:"checker"`
  1195. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  1196. DialysisOrderId int64 `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
  1197. CheckTime int64 `gorm:"column:check_time" json:"check_time"`
  1198. CheckState int64 `gorm:"column:check_state" json:"check_state"`
  1199. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec"`
  1200. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit"`
  1201. Groupno int64 `gorm:"column:groupno" json:"groupno"`
  1202. RemindType int64 `gorm:"column:remind_type" json:"remind_type"`
  1203. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type"`
  1204. DayCount int64 `gorm:"column:day_count" json:"day_count"`
  1205. WeekDay string `gorm:"column:week_day" json:"week_day"`
  1206. TemplateId string `gorm:"column:template_id" json:"template_id"`
  1207. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1208. }
  1209. func (MDoctorAdviceVM) TableName() string {
  1210. return "xt_doctor_advice"
  1211. }
  1212. func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVM, error) {
  1213. var vms []*MScheduleDoctorAdviceVM
  1214. adviceWhere := ""
  1215. adviceCondition := []interface{}{}
  1216. if adviceType == 0 {
  1217. if patientType == 0 {
  1218. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1219. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1220. } else if patientType == 1 {
  1221. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1222. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1223. } else if patientType == 2 {
  1224. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1225. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1226. }
  1227. } else if adviceType == 1 {
  1228. if patientType == 0 {
  1229. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1230. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1231. } else if patientType == 1 {
  1232. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1233. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1234. } else if patientType == 2 {
  1235. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1236. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1237. }
  1238. } else if adviceType == 3 {
  1239. if patientType == 0 {
  1240. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1241. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1242. } else if patientType == 1 {
  1243. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1244. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1245. } else if patientType == 2 {
  1246. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1247. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1248. }
  1249. } else if adviceType == 2 && len(deliverWay) > 0 {
  1250. if patientType == 0 {
  1251. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1252. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1253. } else if patientType == 1 {
  1254. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1255. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1256. } else if patientType == 2 {
  1257. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1258. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1259. }
  1260. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1261. if patientType == 0 {
  1262. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1263. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1264. } else if patientType == 1 {
  1265. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1266. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1267. } else if patientType == 2 {
  1268. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1269. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1270. }
  1271. }
  1272. db := readDb.
  1273. Table("xt_schedule").
  1274. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1275. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1276. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1277. }).
  1278. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1279. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1280. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1281. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  1282. Preload("DoctorAdvices", adviceCondition...).
  1283. Where("status = 1 AND user_org_id = ?", orgID)
  1284. if scheduleDate != 0 {
  1285. db = db.Where("schedule_date = ?", scheduleDate)
  1286. }
  1287. err := db.Find(&vms).Error
  1288. return vms, err
  1289. }
  1290. func MobileGetScheduleDoctorAdvicesTwo(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVMOne, error) {
  1291. var vms []*MScheduleDoctorAdviceVMOne
  1292. adviceWhere := ""
  1293. adviceCondition := []interface{}{}
  1294. if adviceType == 0 {
  1295. if patientType == 0 {
  1296. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1297. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1298. } else if patientType == 1 {
  1299. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1300. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1301. } else if patientType == 2 {
  1302. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1303. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1304. }
  1305. } else if adviceType == 1 {
  1306. if patientType == 0 {
  1307. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1308. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1309. } else if patientType == 1 {
  1310. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1311. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1312. } else if patientType == 2 {
  1313. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1314. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1315. }
  1316. } else if adviceType == 3 {
  1317. if patientType == 0 {
  1318. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1319. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1320. } else if patientType == 1 {
  1321. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1322. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1323. } else if patientType == 2 {
  1324. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1325. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1326. }
  1327. } else if adviceType == 2 && len(deliverWay) > 0 {
  1328. if patientType == 0 {
  1329. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1330. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1331. } else if patientType == 1 {
  1332. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1333. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1334. } else if patientType == 2 {
  1335. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1336. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1337. }
  1338. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1339. if patientType == 0 {
  1340. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1341. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1342. } else if patientType == 1 {
  1343. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1344. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1345. } else if patientType == 2 {
  1346. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1347. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1348. }
  1349. }
  1350. db := readDb.
  1351. Table("xt_schedule").
  1352. //Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1353. //Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1354. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1355. //}).
  1356. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1357. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1358. //Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1359. Preload("DoctorAdvices", adviceCondition...).
  1360. Where("status = 1 AND user_org_id = ?", orgID)
  1361. if scheduleDate != 0 {
  1362. db = db.Where("schedule_date = ?", scheduleDate)
  1363. }
  1364. err := db.Find(&vms).Error
  1365. return vms, err
  1366. }
  1367. func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  1368. var vms []*HisMScheduleDoctorAdviceVM
  1369. if len(deliverWay) > 0 {
  1370. if patientType == 0 {
  1371. db := readDb.
  1372. Table("xt_schedule").
  1373. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1374. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1375. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1376. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1377. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1378. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1379. }).
  1380. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1381. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1382. Where("status = 1 AND user_org_id = ?", orgID)
  1383. if scheduleDate != 0 {
  1384. db = db.Where("schedule_date = ?", scheduleDate)
  1385. }
  1386. err = db.Find(&vms).Error
  1387. }
  1388. if patientType > 0 {
  1389. db := readDb.
  1390. Table("xt_schedule").
  1391. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1392. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1393. 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).
  1394. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1395. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1396. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1397. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1398. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1399. }).Where("status = 1 AND user_org_id = ?", orgID)
  1400. if scheduleDate != 0 {
  1401. db = db.Where("schedule_date = ?", scheduleDate)
  1402. }
  1403. err = db.Find(&vms).Error
  1404. }
  1405. } else {
  1406. if patientType == 0 {
  1407. db := readDb.
  1408. Table("xt_schedule").
  1409. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1410. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1411. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1412. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1413. }).
  1414. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1415. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1416. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1417. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1418. Where("status = 1 AND user_org_id = ?", orgID)
  1419. if scheduleDate != 0 {
  1420. db = db.Where("schedule_date = ?", scheduleDate)
  1421. }
  1422. err = db.Find(&vms).Error
  1423. }
  1424. if patientType > 0 {
  1425. db := readDb.
  1426. Table("xt_schedule").
  1427. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1428. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1429. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1430. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1431. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1432. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1433. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1434. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1435. Where("status = 1 AND user_org_id = ?", orgID)
  1436. if scheduleDate != 0 {
  1437. db = db.Where("schedule_date = ?", scheduleDate)
  1438. }
  1439. err = db.Find(&vms).Error
  1440. }
  1441. }
  1442. return vms, err
  1443. }
  1444. func GetHisDoctorAdvicesTwo(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVMOne, error) {
  1445. var vms []*HisMScheduleDoctorAdviceVMOne
  1446. if len(deliverWay) > 0 {
  1447. if patientType == 0 {
  1448. db := readDb.
  1449. Table("xt_schedule").
  1450. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1451. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1452. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1453. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1454. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1455. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1456. }).
  1457. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1458. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1459. Where("status = 1 AND user_org_id = ?", orgID)
  1460. if scheduleDate != 0 {
  1461. db = db.Where("schedule_date = ?", scheduleDate)
  1462. }
  1463. err = db.Find(&vms).Error
  1464. }
  1465. if patientType > 0 {
  1466. db := readDb.
  1467. Table("xt_schedule").
  1468. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1469. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1470. 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).
  1471. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1472. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1473. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1474. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1475. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1476. }).Where("status = 1 AND user_org_id = ?", orgID)
  1477. if scheduleDate != 0 {
  1478. db = db.Where("schedule_date = ?", scheduleDate)
  1479. }
  1480. err = db.Find(&vms).Error
  1481. }
  1482. } else {
  1483. if patientType == 0 {
  1484. db := readDb.
  1485. Table("xt_schedule").
  1486. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1487. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1488. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1489. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1490. }).
  1491. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1492. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1493. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1494. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1495. Where("status = 1 AND user_org_id = ?", orgID)
  1496. if scheduleDate != 0 {
  1497. db = db.Where("schedule_date = ?", scheduleDate)
  1498. }
  1499. err = db.Find(&vms).Error
  1500. }
  1501. if patientType > 0 {
  1502. db := readDb.
  1503. Table("xt_schedule").
  1504. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1505. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1506. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1507. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1508. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1509. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1510. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1511. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1512. Where("status = 1 AND user_org_id = ?", orgID)
  1513. if scheduleDate != 0 {
  1514. db = db.Where("schedule_date = ?", scheduleDate)
  1515. }
  1516. err = db.Find(&vms).Error
  1517. }
  1518. }
  1519. return vms, err
  1520. }
  1521. func GetMobileHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
  1522. var vms []*HisMScheduleProjectVM
  1523. //if patientType == 0 {
  1524. // db := readDb.
  1525. // Table("xt_schedule").
  1526. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1527. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1528. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1529. // }).
  1530. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1531. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1532. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1533. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1534. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1535. // }).
  1536. // Where("status = 1 AND user_org_id = ?", orgID)
  1537. // if scheduleDate != 0 {
  1538. // db = db.Where("schedule_date = ?", scheduleDate)
  1539. // }
  1540. // err = db.Find(&vms).Error
  1541. //}
  1542. //if patientType > 0 {
  1543. // db := readDb.
  1544. // Table("xt_schedule").
  1545. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1546. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1547. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1548. // }).
  1549. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1550. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1551. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1552. // Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1553. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1554. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1555. // }).
  1556. // Where("status = 1 AND user_org_id = ?", orgID)
  1557. // if scheduleDate != 0 {
  1558. // db = db.Where("schedule_date = ?", scheduleDate)
  1559. // }
  1560. // err = db.Find(&vms).Error
  1561. //}
  1562. db := readDb.Table("xt_schedule").Where("status = 1")
  1563. if orgID > 0 {
  1564. db = db.Where("user_org_id = ?", orgID)
  1565. }
  1566. if scheduleDate > 0 {
  1567. db = db.Where("schedule_date =?", scheduleDate)
  1568. }
  1569. err = db.Find(&vms).Error
  1570. if patientType == 0 {
  1571. db := readDb.
  1572. Table("xt_schedule").
  1573. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1574. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1575. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1576. }).
  1577. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1578. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1579. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1580. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1581. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1582. }).
  1583. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1584. 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")
  1585. }).
  1586. Where("status = 1 AND user_org_id = ?", orgID)
  1587. if scheduleDate != 0 {
  1588. db = db.Where("schedule_date = ?", scheduleDate)
  1589. }
  1590. err = db.Find(&vms).Error
  1591. }
  1592. if patientType > 0 {
  1593. db := readDb.
  1594. Table("xt_schedule").
  1595. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1596. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1597. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1598. }).
  1599. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1600. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1601. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1602. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1603. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1604. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1605. }).
  1606. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  1607. 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")
  1608. }).
  1609. Where("status = 1 AND user_org_id = ?", orgID)
  1610. if scheduleDate != 0 {
  1611. db = db.Where("schedule_date = ?", scheduleDate)
  1612. }
  1613. err = db.Find(&vms).Error
  1614. }
  1615. return vms, err
  1616. }
  1617. func MobileCreateDialysisOrder(orgID int64, patientID int64, order *models.DialysisOrder) error {
  1618. now := time.Now()
  1619. tx := writeDb.Begin()
  1620. if createOrderErr := tx.Model(&models.DialysisOrder{}).Create(order).Error; createOrderErr != nil {
  1621. tx.Rollback()
  1622. return createOrderErr
  1623. }
  1624. // 更新透析记录 ID
  1625. // 透析处方
  1626. 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 {
  1627. tx.Rollback()
  1628. return err
  1629. }
  1630. // 接诊评估
  1631. 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 {
  1632. tx.Rollback()
  1633. return err
  1634. }
  1635. // 透前评估
  1636. 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 {
  1637. tx.Rollback()
  1638. return err
  1639. }
  1640. // 临时医嘱
  1641. 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 {
  1642. tx.Rollback()
  1643. return err
  1644. }
  1645. // 双人核对
  1646. 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 {
  1647. tx.Rollback()
  1648. return err
  1649. }
  1650. // 透后评估
  1651. 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 {
  1652. tx.Rollback()
  1653. return err
  1654. }
  1655. // 治疗小结
  1656. 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 {
  1657. tx.Rollback()
  1658. return err
  1659. }
  1660. // 透析监测
  1661. 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 {
  1662. tx.Rollback()
  1663. return err
  1664. }
  1665. tx.Commit()
  1666. return nil
  1667. }
  1668. type MobileUrgentSchedulePatientVM struct {
  1669. ID int64 `gorm:"column:id" json:"id"`
  1670. Name string `gorm:"column:name" json:"name"`
  1671. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no"`
  1672. }
  1673. func (MobileUrgentSchedulePatientVM) TableName() string {
  1674. return "xt_patients"
  1675. }
  1676. type MobileUrgentScheduleTreatmentModeVM struct {
  1677. ID int64 `gorm:"column:id" json:"id"`
  1678. Name string `gorm:"column:name" json:"name"`
  1679. }
  1680. func (MobileUrgentScheduleTreatmentModeVM) TableName() string {
  1681. return "xt_treatment_mode"
  1682. }
  1683. func MobileGetAllPatientsForUrgentSchedule(orgID int64, record_date int64) ([]*MobileUrgentSchedulePatientVM, error) {
  1684. var vms []*MobileUrgentSchedulePatientVM = make([]*MobileUrgentSchedulePatientVM, 0)
  1685. 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()
  1686. defer rows.Close()
  1687. if err != nil {
  1688. return nil, err
  1689. }
  1690. for rows.Next() {
  1691. var vm MobileUrgentSchedulePatientVM
  1692. readDb.ScanRows(rows, &vm)
  1693. vms = append(vms, &vm)
  1694. }
  1695. return vms, nil
  1696. }
  1697. func MobileGetAllTrearmentModesForUrgentSchedule() ([]*MobileUrgentScheduleTreatmentModeVM, error) {
  1698. var modes []*MobileUrgentScheduleTreatmentModeVM
  1699. err := readDb.Model(&MobileUrgentScheduleTreatmentModeVM{}).Where("status = 1").Find(&modes).Error
  1700. if err != nil {
  1701. return nil, err
  1702. }
  1703. return modes, nil
  1704. }
  1705. type MobileUrgentScheduleScheduleListVM struct {
  1706. ID int64 `gorm:"column:id" json:"id"`
  1707. // ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
  1708. DeviceNumberID int64 `gorm:"column:bed_id" json:"bed_id"`
  1709. PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
  1710. ScheduleType int `gorm:"column:schedule_type" json:"schedule_type"`
  1711. DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
  1712. // DeviceZone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"device_zone"`
  1713. }
  1714. func (MobileUrgentScheduleScheduleListVM) TableName() string {
  1715. return "xt_schedule"
  1716. }
  1717. func MobileGetSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) (schedules []*MobileUrgentScheduleScheduleListVM, err error) {
  1718. db := readDb.
  1719. Model(&MobileUrgentScheduleScheduleListVM{}).
  1720. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1721. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND schedule_type = ? ", orgID, scheduleDate, schedule_type)
  1722. err = db.Find(&schedules).Error
  1723. if err != nil {
  1724. return nil, err
  1725. }
  1726. return schedules, nil
  1727. }
  1728. func MobileGetOtherSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) ([]*MobileUrgentScheduleScheduleListVM, error) {
  1729. var vms []*MobileUrgentScheduleScheduleListVM = make([]*MobileUrgentScheduleScheduleListVM, 0)
  1730. 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()
  1731. defer rows.Close()
  1732. if err != nil {
  1733. return nil, err
  1734. }
  1735. for rows.Next() {
  1736. var vm MobileUrgentScheduleScheduleListVM
  1737. readDb.ScanRows(rows, &vm)
  1738. vms = append(vms, &vm)
  1739. }
  1740. return vms, nil
  1741. }
  1742. type MobileUrgentScheduleDeviceNumberVM struct {
  1743. ID int64 `gorm:"column:id" json:"id"`
  1744. Number string `gorm:"column:number" json:"number"`
  1745. ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
  1746. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  1747. }
  1748. func (MobileUrgentScheduleDeviceNumberVM) TableName() string {
  1749. return "xt_device_number"
  1750. }
  1751. func MobileGetAllDeviceNumbersForUrgentSchedule(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  1752. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  1753. 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()
  1754. defer rows.Close()
  1755. if err != nil {
  1756. return nil, err
  1757. }
  1758. for rows.Next() {
  1759. var vm DeviceNumberViewModel
  1760. readDb.ScanRows(rows, &vm)
  1761. vms = append(vms, &vm)
  1762. }
  1763. return vms, nil
  1764. //var deviceNumbers []*MobileUrgentScheduleDeviceNumberVM
  1765. //db := readDb.
  1766. // Model(&MobileUrgentScheduleDeviceNumberVM{}).
  1767. // Preload("Zone", "status = 1 AND org_id = ?", orgID).
  1768. // Where("status = 1 AND org_id = ?", orgID)
  1769. //err := db.Order("zone_id asc").Find(&deviceNumbers).Error
  1770. //if err != nil {
  1771. // return nil, err
  1772. //}
  1773. //return deviceNumbers, nil
  1774. }
  1775. func GetValidScheduleMonitorRecordCount() (int64, error) {
  1776. var total int64
  1777. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Count(&total).Error
  1778. return total, err
  1779. }
  1780. func GetTop1000ValidScheduleMonitorRecord() ([]*models.MonitoringRecord, error) {
  1781. var monitors []*models.MonitoringRecord
  1782. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Order("id asc").Limit(100).Find(&monitors).Error
  1783. if err != nil {
  1784. return nil, err
  1785. }
  1786. return monitors, nil
  1787. }
  1788. func BatchUpdateMonitors(monitors []*models.MonitoringRecord) error {
  1789. tx := writeDb.Begin()
  1790. for index := 0; index < len(monitors); index++ {
  1791. tx.Save(monitors[index])
  1792. }
  1793. return tx.Commit().Error
  1794. }
  1795. func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
  1796. tx := writeDb.Begin()
  1797. updateTime := time.Now().Unix()
  1798. 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
  1799. if err != nil {
  1800. tx.Rollback()
  1801. return err
  1802. }
  1803. tx.Commit()
  1804. return err
  1805. }
  1806. func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
  1807. tx := writeDb.Begin()
  1808. updateTime := time.Now().Unix()
  1809. 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
  1810. if err != nil {
  1811. tx.Rollback()
  1812. return err
  1813. }
  1814. tx.Commit()
  1815. return err
  1816. }
  1817. func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  1818. var record models.SgjPatientDryweight
  1819. redis := RedisClient()
  1820. defer redis.Close()
  1821. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":last_dry_weight"
  1822. last_dry_weight_str, _ := redis.Get(key).Result()
  1823. if len(last_dry_weight_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1824. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1825. if err != nil {
  1826. if err == gorm.ErrRecordNotFound {
  1827. if record.ID <= 0 {
  1828. redis.Set(key, "null", time.Second*60*60*18)
  1829. }
  1830. return nil, nil
  1831. } else {
  1832. return nil, err
  1833. }
  1834. } else {
  1835. if record.ID > 0 {
  1836. //缓存数据
  1837. last_dry_weight_str, err := json.Marshal(record)
  1838. if err == nil {
  1839. redis.Set(key, last_dry_weight_str, time.Second*60*60*18)
  1840. return nil, err
  1841. }
  1842. } else {
  1843. redis.Set(key, "null", time.Second*60*60*18)
  1844. return nil, err
  1845. }
  1846. return &record, nil
  1847. }
  1848. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1849. if last_dry_weight_str == "null" {
  1850. return &record, nil
  1851. } else {
  1852. json.Unmarshal([]byte(last_dry_weight_str), &record)
  1853. return &record, nil
  1854. }
  1855. }
  1856. }
  1857. // 透析方案
  1858. func MobileGetDialysisSolutionByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  1859. var record models.DialysisSolution
  1860. 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
  1861. if err != nil {
  1862. if err == gorm.ErrRecordNotFound {
  1863. return nil, nil
  1864. } else {
  1865. return nil, err
  1866. }
  1867. }
  1868. return &record, nil
  1869. }
  1870. // 透析方案
  1871. func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  1872. var record models.DialysisSolution
  1873. redis := RedisClient()
  1874. defer redis.Close()
  1875. // cur_date := time.Now().Format("2006-01-02")
  1876. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1877. dialysis_solution_str, _ := redis.Get(key).Result()
  1878. if len(dialysis_solution_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1879. 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
  1880. if err != nil {
  1881. if err == gorm.ErrRecordNotFound {
  1882. if record.ID <= 0 {
  1883. redis.Set(key, "null", time.Second*60*60*18)
  1884. }
  1885. return nil, nil
  1886. } else {
  1887. return nil, err
  1888. }
  1889. } else {
  1890. if record.ID > 0 {
  1891. //缓存数据
  1892. dialysis_solution_str, err := json.Marshal(record)
  1893. if err == nil {
  1894. redis.Set(key, dialysis_solution_str, time.Second*60*60*18)
  1895. }
  1896. } else {
  1897. redis.Set(key, "null", time.Second*60*60*18)
  1898. }
  1899. return &record, nil
  1900. }
  1901. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1902. if dialysis_solution_str == "null" {
  1903. return &record, nil
  1904. } else {
  1905. json.Unmarshal([]byte(dialysis_solution_str), &record)
  1906. return &record, nil
  1907. }
  1908. }
  1909. }
  1910. // 透析处方
  1911. func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  1912. var record models.DialysisPrescription
  1913. redis := RedisClient()
  1914. defer redis.Close()
  1915. // cur_date := time.Now().Format("2006-01-02")
  1916. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1917. dialysis_prescribe_str, _ := redis.Get(key).Result()
  1918. if len(dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1919. 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
  1920. if err != nil {
  1921. if err == gorm.ErrRecordNotFound {
  1922. if record.ID <= 0 {
  1923. redis.Set(key, "null", time.Second*60*60*18)
  1924. }
  1925. return nil, nil
  1926. } else {
  1927. return nil, err
  1928. }
  1929. } else {
  1930. if record.ID > 0 {
  1931. //缓存数据
  1932. dialysis_prescribe_str, err := json.Marshal(record)
  1933. if err == nil {
  1934. redis.Set(key, dialysis_prescribe_str, time.Second*60*60*18)
  1935. }
  1936. } else {
  1937. redis.Set(key, "null", time.Second*60*60*18)
  1938. }
  1939. return &record, nil
  1940. }
  1941. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1942. if dialysis_prescribe_str == "null" {
  1943. return &record, nil
  1944. } else {
  1945. json.Unmarshal([]byte(dialysis_prescribe_str), &record)
  1946. return &record, nil
  1947. }
  1948. }
  1949. }
  1950. func MobileGetDialysisPrescribeByModeIdSix(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  1951. var record models.DialysisPrescription
  1952. 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
  1953. if err != nil {
  1954. if err == gorm.ErrRecordNotFound {
  1955. return nil, nil
  1956. } else {
  1957. return nil, err
  1958. }
  1959. }
  1960. return &record, nil
  1961. }
  1962. func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1963. var record models.DialysisPrescription
  1964. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  1965. if err != nil {
  1966. if err == gorm.ErrRecordNotFound {
  1967. return nil, nil
  1968. } else {
  1969. return nil, err
  1970. }
  1971. }
  1972. return &record, nil
  1973. }
  1974. //func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1975. // var record models.DialysisPrescription
  1976. // redis := RedisClient()
  1977. // defer redis.Close()
  1978. //
  1979. // // cur_date := time.Now().Format("2006-01-02")
  1980. // key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_prescribe_by_mode"
  1981. // dialysis_prescribe_by_mode_str, _ := redis.Get(key).Result()
  1982. //
  1983. // if len(dialysis_prescribe_by_mode_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1984. // err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  1985. // if err != nil {
  1986. // if err == gorm.ErrRecordNotFound {
  1987. // if record.ID <= 0 {
  1988. // redis.Set(key, "null", time.Second*60*60*18)
  1989. // }
  1990. // return nil, nil
  1991. // } else {
  1992. // return nil, err
  1993. // }
  1994. // } else {
  1995. //
  1996. // if record.ID > 0 {
  1997. // //缓存数据
  1998. // dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  1999. //
  2000. // if err == nil {
  2001. // redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2002. // return nil, err
  2003. // }
  2004. // } else {
  2005. // redis.Set(key, "null", time.Second*60*60*18)
  2006. // return nil, err
  2007. // }
  2008. // return &record, nil
  2009. // }
  2010. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2011. // if dialysis_prescribe_by_mode_str == "null" {
  2012. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2013. // return &record, nil
  2014. // } else {
  2015. // json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  2016. // return &record, nil
  2017. // }
  2018. //
  2019. // }
  2020. //}
  2021. func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
  2022. var record models.DialysisPrescription
  2023. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 ", patientID, orgID).Last(&record).Error
  2024. if err != nil {
  2025. if err == gorm.ErrRecordNotFound {
  2026. return nil, nil
  2027. } else {
  2028. return nil, err
  2029. }
  2030. }
  2031. return &record, nil
  2032. }
  2033. func MobileGetLastDialysisPrescribeByModeIdSix(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2034. var record models.DialysisPrescription
  2035. 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
  2036. if err != nil {
  2037. if err == gorm.ErrRecordNotFound {
  2038. return nil, nil
  2039. } else {
  2040. return nil, err
  2041. }
  2042. }
  2043. return &record, nil
  2044. }
  2045. func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2046. var record models.DialysisPrescription
  2047. redis := RedisClient()
  2048. defer redis.Close()
  2049. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2050. dialysis_prescribe_by_mode_id, _ := redis.Get(key).Result()
  2051. if len(dialysis_prescribe_by_mode_id) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2052. 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
  2053. if err != nil {
  2054. if err == gorm.ErrRecordNotFound {
  2055. if record.ID <= 0 {
  2056. redis.Set(key, "null", time.Second*60*60*18)
  2057. }
  2058. return nil, nil
  2059. } else {
  2060. return nil, err
  2061. }
  2062. } else {
  2063. if record.ID > 0 {
  2064. //缓存数据
  2065. dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  2066. if err == nil {
  2067. redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  2068. return nil, err
  2069. }
  2070. } else {
  2071. redis.Set(key, "null", time.Second*60*60*18)
  2072. return nil, err
  2073. }
  2074. return &record, nil
  2075. }
  2076. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2077. if dialysis_prescribe_by_mode_id == "null" {
  2078. return &record, nil
  2079. } else {
  2080. json.Unmarshal([]byte(dialysis_prescribe_by_mode_id), &record)
  2081. return &record, nil
  2082. }
  2083. }
  2084. }
  2085. func MobileGetLastDialysisPrescribeByModeIdOne(orgID int64, patientID int64, mode_id int64) (models.DialysisPrescription, error) {
  2086. var record models.DialysisPrescription
  2087. 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
  2088. return record, err
  2089. }
  2090. func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  2091. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  2092. 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()
  2093. defer rows.Close()
  2094. if err != nil {
  2095. return nil, err
  2096. }
  2097. for rows.Next() {
  2098. var vm DeviceNumberViewModel
  2099. readDb.ScanRows(rows, &vm)
  2100. vms = append(vms, &vm)
  2101. }
  2102. return vms, nil
  2103. }
  2104. // 获取 maxDate 之前一次的透前评估记录
  2105. func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  2106. var record models.PredialysisEvaluation
  2107. 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
  2108. if err != nil {
  2109. if err == gorm.ErrRecordNotFound {
  2110. return nil, nil
  2111. } else {
  2112. return nil, err
  2113. }
  2114. }
  2115. return &record, nil
  2116. }
  2117. func GetLastTimeOrder(orgID int64, patientID int64, maxDate int64) (*models.DialysisOrder, error) {
  2118. var record models.DialysisOrder
  2119. 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
  2120. if err != nil {
  2121. if err == gorm.ErrRecordNotFound {
  2122. return nil, nil
  2123. } else {
  2124. return nil, err
  2125. }
  2126. }
  2127. return &record, nil
  2128. }
  2129. func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  2130. var record models.MonitoringRecord
  2131. 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
  2132. if err != nil {
  2133. if err == gorm.ErrRecordNotFound {
  2134. return nil, nil
  2135. } else {
  2136. return nil, err
  2137. }
  2138. }
  2139. return &record, nil
  2140. }
  2141. // 获取 maxDate 之前一次的透后评估记录
  2142. func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  2143. var record models.AssessmentAfterDislysis
  2144. 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
  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. // 透析处方
  2155. func GetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  2156. var record models.DialysisPrescription
  2157. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).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 GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  2169. var record models.DialysisSolution
  2170. 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
  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. func GetDialysisSolutionOne(orgID int64, mode_id int64) (*models.DialysisSolution, error) {
  2181. var record models.DialysisSolution
  2182. err := readDb.Model(&models.DialysisSolution{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2183. if err != nil {
  2184. if err == gorm.ErrRecordNotFound {
  2185. return nil, nil
  2186. } else {
  2187. return nil, err
  2188. }
  2189. }
  2190. return &record, nil
  2191. }
  2192. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  2193. var record models.DialysisPrescription
  2194. 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
  2195. if err != nil {
  2196. if err == gorm.ErrRecordNotFound {
  2197. return nil, nil
  2198. } else {
  2199. return nil, err
  2200. }
  2201. }
  2202. return &record, nil
  2203. }
  2204. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  2205. var record models.SgjPatientDryweight
  2206. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  2207. if err != nil {
  2208. if err == gorm.ErrRecordNotFound {
  2209. return nil, nil
  2210. } else {
  2211. return nil, err
  2212. }
  2213. }
  2214. return &record, nil
  2215. }
  2216. func MobileGetSystemDialysisPrescribeByModeIdSix(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2217. var record models.SystemPrescription
  2218. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  2219. if err != nil {
  2220. if err == gorm.ErrRecordNotFound {
  2221. return nil, nil
  2222. } else {
  2223. return nil, err
  2224. }
  2225. }
  2226. return &record, nil
  2227. }
  2228. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2229. var record models.SystemPrescription
  2230. redis := RedisClient()
  2231. defer redis.Close()
  2232. // cur_date := time.Now().Format("2006-01-02")
  2233. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2234. system_dialysis_prescribe_str, _ := redis.Get(key).Result()
  2235. if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2236. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2237. if err != nil {
  2238. if err == gorm.ErrRecordNotFound {
  2239. if record.ID <= 0 {
  2240. redis.Set(key, "null", time.Second*60*60*18)
  2241. }
  2242. return nil, nil
  2243. } else {
  2244. return nil, err
  2245. }
  2246. } else {
  2247. if record.ID > 0 {
  2248. //缓存数据
  2249. system_dialysis_prescribe_str, err := json.Marshal(record)
  2250. if err == nil {
  2251. redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
  2252. }
  2253. } else {
  2254. redis.Set(key, "null", time.Second*60*60*18)
  2255. }
  2256. return &record, nil
  2257. }
  2258. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2259. if system_dialysis_prescribe_str == "null" {
  2260. return &record, nil
  2261. } else {
  2262. json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
  2263. return &record, nil
  2264. }
  2265. }
  2266. }
  2267. func MobileGetSystemDialysisPrescribeByModeIdOne(orgID int64, mode_id int64) (models.SystemPrescription, error) {
  2268. var record models.SystemPrescription
  2269. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2270. return record, err
  2271. }
  2272. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2273. var record models.SystemPrescription
  2274. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2275. if err != nil {
  2276. if err == gorm.ErrRecordNotFound {
  2277. return nil, nil
  2278. } else {
  2279. return nil, err
  2280. }
  2281. }
  2282. return &record, nil
  2283. }
  2284. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2285. 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
  2286. return
  2287. }
  2288. func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2289. 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
  2290. return
  2291. }
  2292. func GetFirstDateOfMonth(d time.Time) time.Time {
  2293. d = d.AddDate(0, 0, -d.Day()+1)
  2294. return GetZeroTime(d)
  2295. }
  2296. func GetZeroTime(d time.Time) time.Time {
  2297. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  2298. }
  2299. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  2300. db := XTReadDB().Table("xt_dialysis_order as o")
  2301. 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
  2302. return order, err
  2303. }
  2304. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2305. 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
  2306. return
  2307. }
  2308. func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2309. 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
  2310. return
  2311. }
  2312. func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
  2313. 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
  2314. return
  2315. }
  2316. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  2317. // 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
  2318. // return
  2319. //}
  2320. //
  2321. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  2322. 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
  2323. return
  2324. }
  2325. type GoodsType struct {
  2326. ID int64 `gorm:"column:id" json:"id"`
  2327. TypeName string `gorm:"column:type_name" json:"type_name"`
  2328. Remark string `gorm:"column:remark" json:"remark"`
  2329. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2330. Status int64 `gorm:"column:status" json:"status"`
  2331. Type int64 `gorm:"column:type" json:"type"`
  2332. }
  2333. func (GoodsType) TableName() string {
  2334. return "xt_goods_type"
  2335. }
  2336. type VMGoodInfo struct {
  2337. ID int64 `gorm:"column:id" json:"id"`
  2338. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  2339. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2340. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2341. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  2342. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  2343. Total float64 `gorm:"column:total" json:"total" form:"total"`
  2344. }
  2345. func (VMGoodInfo) TableName() string {
  2346. return "xt_good_information"
  2347. }
  2348. type AutomaticReduceDetail struct {
  2349. ID int64 `gorm:"column:id" json:"id"`
  2350. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2351. Status int64 `gorm:"column:status" json:"status"`
  2352. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  2353. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2354. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2355. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2356. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2357. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2358. Count int64 `gorm:"column:count" json:"count"`
  2359. }
  2360. func (AutomaticReduceDetail) TableName() string {
  2361. return "xt_automatic_reduce_detail"
  2362. }
  2363. type DialysisBeforePrepare struct {
  2364. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2365. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2366. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2367. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2368. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  2369. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  2370. Count int64 `gorm:"column:count" json:"count" form:"count"`
  2371. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  2372. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  2373. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  2374. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  2375. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2376. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2377. }
  2378. func (DialysisBeforePrepare) TableName() string {
  2379. return "dialysis_before_prepare"
  2380. }
  2381. type MDialysisGoodsVM struct {
  2382. ID int64 `gorm:"column:id" json:"id"`
  2383. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2384. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2385. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2386. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2387. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2388. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2389. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  2390. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2391. Status int64 `gorm:"column:status" json:"status"`
  2392. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2393. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  2394. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  2395. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  2396. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  2397. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  2398. Project []*models.HisPrescriptionProject `gorm:"-" json:"project"`
  2399. }
  2400. func (MDialysisGoodsVM) TableName() string {
  2401. return "xt_schedule"
  2402. }
  2403. type VMWarehouseOutInfo struct {
  2404. ID int64 `gorm:"column:id" json:"id"`
  2405. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  2406. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2407. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2408. Count int64 `gorm:"column:count" json:"count"`
  2409. Price float64 `gorm:"column:price" json:"price"`
  2410. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  2411. Status int64 `gorm:"column:status" json:"status"`
  2412. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2413. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  2414. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  2415. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  2416. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  2417. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  2418. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  2419. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  2420. }
  2421. func (VMWarehouseOutInfo) TableName() string {
  2422. return "xt_warehouse_out_info"
  2423. }
  2424. type DialysisGoodsDate struct {
  2425. RecordDate int64
  2426. }
  2427. type DialysisGoodsDetailDate struct {
  2428. RecordTime int64
  2429. }
  2430. 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) {
  2431. var vms []*MDialysisGoodsVM
  2432. var total int64
  2433. db := readDb.
  2434. Table("xt_schedule as sch").
  2435. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2436. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2437. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2438. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2439. 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)
  2440. }).
  2441. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2442. 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")
  2443. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  2444. if scheduleDate != 0 {
  2445. db = db.Where("schedule_date = ?", scheduleDate)
  2446. }
  2447. if schedule_type != 0 {
  2448. db = db.Where("schedule_type = ?", schedule_type)
  2449. }
  2450. if partition_id != 0 {
  2451. db = db.Where("partition_id = ?", partition_id)
  2452. }
  2453. if patient_id != 0 {
  2454. db = db.Where("patient_id = ?", patient_id)
  2455. }
  2456. //db = db.Count(&total)
  2457. //offset := (page - 1) * limit
  2458. //
  2459. //db = db.Offset(offset).Limit(limit)
  2460. err := db.Find(&vms).Error
  2461. return vms, err, total
  2462. }
  2463. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2464. var Id []*DialysisGoodsDetailDate
  2465. 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
  2466. if len(Id) > 0 {
  2467. 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
  2468. }
  2469. return
  2470. }
  2471. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2472. var Id []*DialysisGoodsDate
  2473. 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
  2474. if len(Id) > 0 {
  2475. 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
  2476. }
  2477. return
  2478. }
  2479. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  2480. db := readDb.Model(&models.StockInfo{})
  2481. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  2482. 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")
  2483. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  2484. 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)
  2485. })
  2486. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  2487. err = db.Order("ctime desc").Find(&list).Error
  2488. return
  2489. }
  2490. 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) {
  2491. var vms []*MDialysisGoodsVM
  2492. var total int64
  2493. db := readDb.
  2494. Model(&models.Schedule{}).
  2495. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2496. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2497. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2498. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2499. 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)
  2500. }).
  2501. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2502. 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)
  2503. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  2504. if scheduleDate != 0 {
  2505. db = db.Where("schedule_date = ?", scheduleDate)
  2506. }
  2507. if patient_id != 0 {
  2508. db = db.Where("patient_id = ?", patient_id)
  2509. }
  2510. if len(keywords) != 0 {
  2511. keywords = "%" + keywords + "%"
  2512. 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)
  2513. } else {
  2514. if schedule_type != 0 {
  2515. db = db.Where("schedule_type = ?", schedule_type)
  2516. }
  2517. if partition_id != 0 {
  2518. db = db.Where("partition_id = ?", partition_id)
  2519. }
  2520. db = db.Count(&total)
  2521. offset := (page - 1) * limit
  2522. db = db.Offset(offset).Limit(limit)
  2523. }
  2524. err := db.Find(&vms).Error
  2525. return vms, err, total
  2526. }
  2527. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2528. var Id []*DialysisGoodsDetailDate
  2529. 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
  2530. if len(Id) > 0 {
  2531. 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
  2532. }
  2533. return
  2534. }
  2535. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2536. var Id []*DialysisGoodsDate
  2537. 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
  2538. if len(Id) > 0 {
  2539. 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
  2540. }
  2541. return
  2542. }
  2543. func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
  2544. evaluation := models.PredialysisEvaluation{}
  2545. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2546. if err == gorm.ErrRecordNotFound {
  2547. return nil, err
  2548. }
  2549. if err != nil {
  2550. return nil, err
  2551. }
  2552. return &evaluation, nil
  2553. }
  2554. func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
  2555. redis := RedisClient()
  2556. defer redis.Close()
  2557. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientid, 10) + ":" + strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
  2558. his_doctor_advice_str, _ := redis.Get(key).Result()
  2559. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2560. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ?", patientid, orgid, recorddate).Find(&his).Error
  2561. if err != nil {
  2562. if err == gorm.ErrRecordNotFound {
  2563. if len(his) <= 0 {
  2564. redis.Set(key, "null", time.Second*60*60*18)
  2565. }
  2566. return his, nil
  2567. } else {
  2568. return his, err
  2569. }
  2570. } else {
  2571. if len(his) > 0 {
  2572. //缓存数据
  2573. his_doctor_advice_str, err := json.Marshal(his)
  2574. if err == nil {
  2575. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2576. }
  2577. } else {
  2578. redis.Set(key, "null", time.Second*60*60*18)
  2579. }
  2580. return his, nil
  2581. }
  2582. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2583. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2584. return his, nil
  2585. }
  2586. }
  2587. func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  2588. prescription := models.DialysisPrescription{}
  2589. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2590. if err == gorm.ErrRecordNotFound {
  2591. return nil, err
  2592. }
  2593. if err != nil {
  2594. return nil, err
  2595. }
  2596. return &prescription, nil
  2597. }
  2598. type HisMScheduleDoctorAdviceVM struct {
  2599. ID int64 `gorm:"column:id" json:"id"`
  2600. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2601. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2602. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2603. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2604. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2605. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2606. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2607. Status int64 `gorm:"column:status" json:"status"`
  2608. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2609. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2610. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2611. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2612. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2613. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2614. }
  2615. func (HisMScheduleDoctorAdviceVM) TableName() string {
  2616. return "xt_schedule"
  2617. }
  2618. type HisMScheduleDoctorAdviceVMOne struct {
  2619. ID int64 `gorm:"column:id" json:"id"`
  2620. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2621. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2622. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2623. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2624. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2625. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2626. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2627. Status int64 `gorm:"column:status" json:"status"`
  2628. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2629. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2630. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2631. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2632. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2633. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2634. }
  2635. func (HisMScheduleDoctorAdviceVMOne) TableName() string {
  2636. return "xt_schedule"
  2637. }
  2638. type HisMScheduleProjectVM struct {
  2639. ID int64 `gorm:"column:id" json:"id"`
  2640. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2641. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2642. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2643. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2644. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2645. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2646. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2647. Status int64 `gorm:"column:status" json:"status"`
  2648. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2649. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2650. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2651. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2652. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2653. HisPrescriptionTeamProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"team_project"`
  2654. }
  2655. func (HisMScheduleProjectVM) TableName() string {
  2656. return "xt_schedule"
  2657. }
  2658. func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
  2659. config := models.XtHisConfig{}
  2660. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  2661. return config, err
  2662. }
  2663. func GetHisDoctorPatientById(orgid int64, patientid int64, recordtime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  2664. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
  2665. if orgid > 0 {
  2666. db = db.Where("x.user_org_id = ?", orgid)
  2667. }
  2668. if patientid > 0 {
  2669. db = db.Where("x.patient_id =?", patientid)
  2670. }
  2671. if recordtime > 0 {
  2672. db = db.Where("x.advice_date = ?", recordtime)
  2673. }
  2674. 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
  2675. return advice, err
  2676. }
  2677. func GetDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2678. db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1 and x.advice_type =2")
  2679. if startime > 0 {
  2680. db = db.Where("x.advice_date >= ?", startime)
  2681. }
  2682. if endtime > 0 {
  2683. db = db.Where("x.advice_date<=?", endtime)
  2684. }
  2685. if orgid > 0 {
  2686. db = db.Where("x.user_org_id = ?", orgid)
  2687. }
  2688. if len(deliveway) > 0 {
  2689. db = db.Where("x.delivery_way = ?", deliveway)
  2690. }
  2691. 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
  2692. return advice, err
  2693. }
  2694. func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2695. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.advice_type =2")
  2696. if startime > 0 {
  2697. db = db.Where("x.advice_date >= ?", startime)
  2698. }
  2699. if endtime > 0 {
  2700. db = db.Where("x.advice_date<=?", endtime)
  2701. }
  2702. if orgid > 0 {
  2703. db = db.Where("x.user_org_id = ?", orgid)
  2704. }
  2705. if len(deliveway) > 0 {
  2706. db = db.Where("x.delivery_way = ?", deliveway)
  2707. }
  2708. 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
  2709. return advice, err
  2710. }
  2711. func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64) ([]*MScheduleDoctorAdviceVM, error) {
  2712. var vms []*MScheduleDoctorAdviceVM
  2713. adviceWhere := ""
  2714. adviceCondition := []interface{}{}
  2715. if adviceType == 0 {
  2716. if patientType == 0 {
  2717. if patient_id > 0 {
  2718. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
  2719. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2720. } else {
  2721. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  2722. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2723. }
  2724. } else if patientType == 1 {
  2725. if patient_id > 0 {
  2726. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
  2727. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  2728. } else {
  2729. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  2730. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  2731. }
  2732. } else if patientType == 2 {
  2733. if patient_id > 0 {
  2734. 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 = ?)"
  2735. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2736. } else {
  2737. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  2738. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2739. }
  2740. }
  2741. } else if adviceType == 1 {
  2742. if patientType == 0 {
  2743. if patient_id > 0 {
  2744. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
  2745. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2746. } else {
  2747. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  2748. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2749. }
  2750. } else if patientType == 1 {
  2751. if patient_id > 0 {
  2752. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
  2753. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  2754. } else {
  2755. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  2756. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  2757. }
  2758. } else if patientType == 2 {
  2759. if patient_id > 0 {
  2760. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
  2761. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2762. } else {
  2763. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  2764. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2765. }
  2766. }
  2767. } else if adviceType == 3 {
  2768. if patientType == 0 {
  2769. if patient_id > 0 {
  2770. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ? "
  2771. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2772. } else {
  2773. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  2774. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2775. }
  2776. } else if patientType == 1 {
  2777. if patient_id > 0 {
  2778. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
  2779. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  2780. } else {
  2781. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  2782. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  2783. }
  2784. } else if patientType == 2 {
  2785. if patient_id > 0 {
  2786. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0 and patient_id = ?"
  2787. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2788. } else {
  2789. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  2790. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2791. }
  2792. }
  2793. } else if adviceType == 2 && len(deliverWay) > 0 {
  2794. if patientType == 0 {
  2795. if patient_id > 0 {
  2796. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
  2797. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
  2798. } else {
  2799. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  2800. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  2801. }
  2802. } else if patientType == 1 {
  2803. if patient_id > 0 {
  2804. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? and patient_id = ?"
  2805. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
  2806. } else {
  2807. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  2808. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  2809. }
  2810. } else if patientType == 2 {
  2811. if patient_id > 0 {
  2812. } else {
  2813. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  2814. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  2815. }
  2816. }
  2817. } else if adviceType == 2 && len(deliverWay) <= 0 {
  2818. if patientType == 0 {
  2819. if patient_id > 0 {
  2820. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
  2821. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2822. } else {
  2823. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  2824. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2825. }
  2826. } else if patientType == 1 {
  2827. if patient_id > 0 {
  2828. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
  2829. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
  2830. } else {
  2831. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  2832. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  2833. }
  2834. } else if patientType == 2 {
  2835. if patient_id > 0 {
  2836. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and patient_id = ?"
  2837. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
  2838. } else {
  2839. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  2840. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2841. }
  2842. }
  2843. }
  2844. db := readDb.Table("xt_schedule")
  2845. if scheduleType > 0 {
  2846. db = db.Where("schedule_type = ?", scheduleType)
  2847. }
  2848. if partitonType > 0 {
  2849. db = db.Where("partition_id = ?", partitonType)
  2850. }
  2851. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2852. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  2853. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  2854. }).
  2855. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2856. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2857. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  2858. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  2859. Preload("DoctorAdvices", adviceCondition...).
  2860. Where("status = 1 AND user_org_id = ?", orgID)
  2861. if scheduleDate != 0 {
  2862. db = db.Where("schedule_date = ?", scheduleDate)
  2863. }
  2864. err := db.Find(&vms).Error
  2865. return vms, err
  2866. }
  2867. func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  2868. var vms []*HisMScheduleDoctorAdviceVM
  2869. if len(deliverWay) > 0 {
  2870. db := readDb.Table("xt_schedule")
  2871. if scheduleType > 0 {
  2872. db = db.Where("schedule_type = ?", scheduleType)
  2873. }
  2874. if partitionType > 0 {
  2875. db = db.Where("partition_id = ?", partitionType)
  2876. }
  2877. if patient_id > 0 {
  2878. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
  2879. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2880. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2881. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  2882. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
  2883. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  2884. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  2885. }).
  2886. Where("status = 1 AND user_org_id = ?", orgID)
  2887. if scheduleDate != 0 {
  2888. db = db.Where("schedule_date = ?", scheduleDate)
  2889. }
  2890. err = db.Find(&vms).Error
  2891. } else {
  2892. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  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 = ?", orgID, scheduleDate).
  2896. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  2897. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  2898. return db.Where("status = 1 AND user_org_id = ?", orgID).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. }
  2906. } else {
  2907. db := readDb.Table("xt_schedule")
  2908. if scheduleType > 0 {
  2909. db = db.Where("schedule_type = ?", scheduleType)
  2910. }
  2911. if partitionType > 0 {
  2912. db = db.Where("partition_id = ?", partitionType)
  2913. }
  2914. if patient_id > 0 {
  2915. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
  2916. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2917. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2918. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  2919. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  2920. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  2921. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  2922. }).
  2923. Where("status = 1 AND user_org_id = ?", orgID)
  2924. if scheduleDate != 0 {
  2925. db = db.Where("schedule_date = ?", scheduleDate)
  2926. }
  2927. err = db.Find(&vms).Error
  2928. } else {
  2929. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  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 = ?", orgID, scheduleDate).
  2933. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  2934. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  2935. return db.Where("status = 1 AND user_org_id = ?", orgID).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. }
  2943. }
  2944. return vms, err
  2945. }
  2946. func BatchDeleteMonitor(ids []string) (err error) {
  2947. if len(ids) == 1 {
  2948. err = XTWriteDB().Model(&models.MonitoringRecord{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  2949. } else {
  2950. err = XTWriteDB().Model(models.MonitoringRecord{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  2951. }
  2952. return
  2953. }
  2954. func GetPatientDialysisRecordList(patientid int64, startime int64, endtime int64) (order []*models.XtDialysisOrders, err error) {
  2955. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  2956. //table := XTReadDB().Table("xt_schedule as s")
  2957. //fmt.Println(table)
  2958. if patientid > 0 {
  2959. db = db.Where("x.patient_id = ?", patientid)
  2960. }
  2961. if startime > 0 {
  2962. db = db.Where("x.dialysis_date>=?", startime)
  2963. }
  2964. if endtime > 0 {
  2965. db = db.Where("x.dialysis_date <= ?", endtime)
  2966. }
  2967. 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
  2968. return order, err
  2969. }
  2970. func BatchDeleteAdvice(ids []string) (err error) {
  2971. if len(ids) == 1 {
  2972. err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  2973. } else {
  2974. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  2975. }
  2976. return
  2977. }
  2978. func BatchDeleteHisAdvice(ids []string) (err error) {
  2979. if len(ids) == 1 {
  2980. err = XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  2981. } else {
  2982. err = XTWriteDB().Model(models.HisDoctorAdviceInfo{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  2983. }
  2984. return
  2985. }
  2986. func UpdateAutoReduceDetail(good_id int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  2987. detail := models.AutomaticReduceDetail{}
  2988. 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
  2989. return detail, err
  2990. }
  2991. func DeleteAutoReduceDetail(good_id int64, record_time int64, patient_id int64) error {
  2992. detail := models.AutomaticReduceDetail{}
  2993. 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
  2994. return err
  2995. }
  2996. func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
  2997. detail := models.DialysisBeforePrepare{}
  2998. 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
  2999. return err
  3000. }
  3001. func BatchAdviceCheck(ids []string, creator int64) error {
  3002. advice := models.XtDoctorAdvice{}
  3003. 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
  3004. return err
  3005. }
  3006. func BatchHisAdviceCheck(ids []string, creator int64) error {
  3007. advice := models.HisDoctorAdviceInfo{}
  3008. 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
  3009. return err
  3010. }
  3011. func BatchAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3012. advice := models.XtDoctorAdvice{}
  3013. 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
  3014. return err
  3015. }
  3016. func BatchHisAdviceExecution(ids []string, creator int64, execution_state int64) error {
  3017. advice := models.HisDoctorAdviceInfo{}
  3018. 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
  3019. return err
  3020. }
  3021. func GetAdviceExecutionById(ids []string) (doctor []*models.XtDoctorAdvice, err error) {
  3022. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3023. return doctor, err
  3024. }
  3025. func GetHisAdviceExecutionById(ids []string) (doctor []*models.HisDoctorAdviceInfo, err error) {
  3026. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  3027. return doctor, err
  3028. }
  3029. func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
  3030. config := models.XtHisProjectConfig{}
  3031. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  3032. return config, err
  3033. }
  3034. func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
  3035. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  3036. return db.Preload("GoodsType", "status = 1").Where("status = 1 ")
  3037. }).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
  3038. return
  3039. }
  3040. func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64) ([]*HisMScheduleProjectVM, error) {
  3041. var vms []*HisMScheduleProjectVM
  3042. if patientType == 0 {
  3043. if patient_id > 0 {
  3044. db := readDb.
  3045. Table("xt_schedule").
  3046. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3047. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3048. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3049. }).
  3050. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3051. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3052. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3053. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3054. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3055. }).
  3056. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3057. 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")
  3058. }).Where("status = 1 AND user_org_id = ?", orgID)
  3059. if scheduleDate != 0 {
  3060. db = db.Where("schedule_date = ?", scheduleDate)
  3061. }
  3062. err = db.Find(&vms).Error
  3063. } else {
  3064. if patient_id > 0 {
  3065. db := readDb.
  3066. Table("xt_schedule").
  3067. Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
  3068. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3069. return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3070. }).
  3071. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3072. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3073. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
  3074. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3075. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3076. }).
  3077. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3078. 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")
  3079. }).Where("status = 1 AND user_org_id = ?", orgID)
  3080. if scheduleDate != 0 {
  3081. db = db.Where("schedule_date = ?", scheduleDate)
  3082. }
  3083. err = db.Find(&vms).Error
  3084. } else {
  3085. db := readDb.
  3086. Table("xt_schedule").
  3087. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3088. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3089. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3090. }).
  3091. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3092. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3093. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3094. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3095. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3096. }).
  3097. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3098. 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")
  3099. }).Where("status = 1 AND user_org_id = ?", orgID)
  3100. if scheduleDate != 0 {
  3101. db = db.Where("schedule_date = ?", scheduleDate)
  3102. }
  3103. err = db.Find(&vms).Error
  3104. }
  3105. }
  3106. }
  3107. if patientType > 0 {
  3108. db := readDb.
  3109. Table("xt_schedule").
  3110. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  3111. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  3112. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  3113. }).
  3114. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  3115. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  3116. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  3117. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  3118. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  3119. return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  3120. }).
  3121. Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
  3122. 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")
  3123. }).Where("status = 1 AND user_org_id = ?", orgID)
  3124. if scheduleDate != 0 {
  3125. db = db.Where("schedule_date = ?", scheduleDate)
  3126. }
  3127. err = db.Find(&vms).Error
  3128. }
  3129. return vms, err
  3130. }
  3131. func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3132. prepare := models.DialysisBeforePrepare{}
  3133. 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
  3134. return err
  3135. }
  3136. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  3137. detail := models.AutomaticReduceDetail{}
  3138. 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
  3139. return err
  3140. }
  3141. func MobileGetDialysisSolutionByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  3142. var record models.DialysisSolution
  3143. 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
  3144. if err != nil {
  3145. if err == gorm.ErrRecordNotFound {
  3146. return nil, nil
  3147. } else {
  3148. return nil, err
  3149. }
  3150. }
  3151. return &record, nil
  3152. }
  3153. func MobileGetLastDialysisPrescribeByModeIdSeven(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  3154. var record models.DialysisPrescription
  3155. 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
  3156. if err != nil {
  3157. if err == gorm.ErrRecordNotFound {
  3158. return nil, nil
  3159. } else {
  3160. return nil, err
  3161. }
  3162. }
  3163. return &record, nil
  3164. }
  3165. func MobileGetSystemDialysisPrescribeByModeIdSeven(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  3166. var record models.SystemPrescription
  3167. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  3168. if err != nil {
  3169. if err == gorm.ErrRecordNotFound {
  3170. return nil, nil
  3171. } else {
  3172. return nil, err
  3173. }
  3174. }
  3175. return &record, nil
  3176. }
  3177. // 透前评估
  3178. func MobileGetPredialysisEvaluationSeven(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  3179. fmt.Println("recordDate", recordDate)
  3180. var record models.PredialysisEvaluation
  3181. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).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. }