mobile_dialysis_service.go 188KB

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