mobile_dialysis_service.go 170KB

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