mobile_dialysis_service.go 196KB

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