mobile_dialysis_service.go 196KB

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