mobile_dialysis_service.go 199KB

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