mobile_dialysis_service.go 197KB

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