mobile_dialysis_service.go 148KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057
  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. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  30. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  31. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  32. // Preload("Advices", "status = 1 AND user_org_id = ? AND advice_type = 2 AND advice_date = ? ", orgID, scheduleDate).
  33. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  34. // Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
  35. // Preload("DialysisOrder", "status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).
  36. // Preload("DialysisOrder.DeviceNumber", "status = 1 AND org_id = ?", orgID).
  37. // Preload("TreatmentSummary", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  38. // Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).
  39. // Preload("HisAdvices", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  40. // Preload("DialysisOrder.MonitoringRecords", func(rdb *gorm.DB) *gorm.DB {
  41. // return rdb.Where("status = 1 AND user_org_id = ?", orgID).Order("operate_time DESC")
  42. // }).
  43. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  44. if scheduleDate != 0 {
  45. db = db.Where("schedule_date = ?", scheduleDate)
  46. }
  47. if scheduleType != 0 {
  48. db = db.Where("schedule_type = ?", scheduleType)
  49. }
  50. err := db.Find(&vms).Error
  51. return vms, err
  52. }
  53. func MobileGetWaitingScheduals(orgID int64, scheduleDate int64) ([]*MDialysisScheduleVM, error) {
  54. var vms []*MDialysisScheduleVM
  55. db := readDb.
  56. Table("xt_schedule as sch").
  57. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  58. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  59. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  60. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  61. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  62. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).
  63. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  64. Preload("Advices", "status = 1 AND user_org_id = ? AND advice_type = 2 ", orgID).
  65. Preload("TreatmentMode", "status = 1").
  66. Preload("TreatmentSummary", "status = 1 AND user_org_id = ?", orgID).
  67. Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  68. if scheduleDate != 0 {
  69. db = db.Where("schedule_date = ?", scheduleDate)
  70. }
  71. err := db.Find(&vms).Error
  72. return vms, err
  73. }
  74. type VMTreatmentSummary struct {
  75. ID int64 `gorm:"column:id" json:"id"`
  76. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  77. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  78. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  79. DialysisSummary string `gorm:"column:dialysis_summary" json:"dialysis_summary" form:"dialysis_summary"`
  80. }
  81. func (VMTreatmentSummary) TableName() string {
  82. return "xt_treatment_summary"
  83. }
  84. type AssessmentAfterDislysis struct {
  85. ID int64 `gorm:"column:id" json:"id"`
  86. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  87. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  88. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  89. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  90. Status int64 `gorm:"column:status" json:"status"`
  91. }
  92. func (AssessmentAfterDislysis) TableName() string {
  93. return "xt_assessment_after_dislysis"
  94. }
  95. type MDialysisScheduleVM struct {
  96. ID int64 `gorm:"column:id" json:"id"`
  97. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  98. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  99. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  100. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  101. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  102. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  103. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  104. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  105. Status int64 `gorm:"column:status" json:"status"`
  106. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  107. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  108. DialysisOrder *MDialysisOrderVMList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  109. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  110. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  111. AssessmentAfterDislysis *AssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  112. HisAdvices []*VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  113. Advices []*VMDoctorAdvice `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  114. TreatmentSummary *VMTreatmentSummary `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  115. }
  116. func (MDialysisScheduleVM) TableName() string {
  117. return "xt_schedule"
  118. }
  119. type MDialysisScheduleVMForList struct {
  120. ID int64 `gorm:"column:id" json:"id"`
  121. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  122. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  123. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  124. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  125. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  126. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  127. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  128. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  129. Status int64 `gorm:"column:status" json:"status"`
  130. SchedualPatient *models.MSchedualPatientList `gorm:"ForeignKey:PatientId" json:"patient"`
  131. DeviceNumber *models.MDeviceNumberForList `gorm:"ForeignKey:BedId" json:"device_number"`
  132. DialysisOrder *models.MDialysisOrderForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  133. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  134. AssessmentBeforeDislysis *models.PredialysisEvaluationList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  135. AssessmentAfterDislysis *models.VMAssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  136. HisAdvices []VMHisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"his_doctor_advice"`
  137. Advices []models.VMDoctorAdviceForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  138. TreatmentSummary *models.VMTreatmentSummaryForList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"treatment_summary"`
  139. }
  140. func (MDialysisScheduleVMForList) TableName() string {
  141. return "xt_schedule"
  142. }
  143. type MDeviceNumberVM struct {
  144. models.DeviceNumber
  145. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  146. }
  147. func (MDeviceNumberVM) TableName() string {
  148. return "xt_device_number"
  149. }
  150. type MSchedualPatientVMList struct {
  151. ID int64 `gorm:"column:id" json:"id" form:"id"`
  152. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  153. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  154. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  155. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  156. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  157. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  158. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  159. Age int64 `gorm:"column:age" json:"age"`
  160. Name string `gorm:"column:name" json:"name" form:"name"`
  161. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  162. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  163. }
  164. func (MSchedualPatientVMList) TableName() string {
  165. return "xt_patients"
  166. }
  167. type MSchedualPatientVM struct {
  168. ID int64 `gorm:"column:id" json:"id" form:"id"`
  169. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  170. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  171. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  172. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  173. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  174. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  175. Source int64 `gorm:"column:source" json:"source" form:"source"`
  176. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  177. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  178. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  179. Name string `gorm:"column:name" json:"name" form:"name"`
  180. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  181. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  182. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  183. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  184. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  185. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  186. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  187. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  188. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  189. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  190. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  191. Height int64 `gorm:"column:height" json:"height" form:"height"`
  192. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  193. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  194. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  195. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  196. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  197. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  198. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  199. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  200. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  201. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  202. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  203. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  204. Children int64 `gorm:"column:children" json:"children" form:"children"`
  205. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  206. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  207. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  208. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  209. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  210. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  211. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  212. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  213. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  214. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  215. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  216. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  217. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  218. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  219. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  220. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  221. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  222. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  223. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  224. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  225. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  226. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  227. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  228. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  229. Status int64 `gorm:"column:status" json:"status" form:"status"`
  230. Age int64 `gorm:"column:age" json:"age"`
  231. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  232. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  233. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  234. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  235. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  236. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  237. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  238. }
  239. func (MSchedualPatientVM) TableName() string {
  240. return "xt_patients"
  241. }
  242. type MDialysisOrderVM struct {
  243. ID int64 `gorm:"column:id" json:"id"`
  244. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  245. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  246. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  247. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  248. Stage int64 `gorm:"column:stage" json:"stage"`
  249. // Remark string `gorm:"column:remark" json:"remark"`
  250. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  251. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  252. FinishNurse int64 `gorm:"column:finish_nurse" json:"finish_nurse"`
  253. Status int64 `gorm:"column:status" json:"status"`
  254. PunctureNurse int64 `gorm:"column:puncture_nurse" json:"puncture_nurse"`
  255. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  256. MonitoringRecords []*models.MonitoringRecord `gorm:"ForeignKey:DialysisOrderId" json:"monitoring_records"`
  257. Creator int64 `gorm:"column:creator" json:"creator"`
  258. Modifier int64 `gorm:"column:modifier" json:"modifier"`
  259. FinishCreator int64 `gorm:"column:finish_creator" json:"finish_creator"`
  260. FinishModifier int64 `gorm:"column:finish_modifier" json:"finish_modifier"`
  261. SchedualType int64 `gorm:"column:schedual_type" json:"schedual_type"`
  262. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  263. }
  264. func (MDialysisOrderVM) TableName() string {
  265. return "xt_dialysis_order"
  266. }
  267. type MDialysisOrderVMList struct {
  268. ID int64 `gorm:"column:id" json:"id"`
  269. DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date"`
  270. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  271. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  272. // PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id"`
  273. Stage int64 `gorm:"column:stage" json:"stage"`
  274. // Remark string `gorm:"column:remark" json:"remark"`
  275. BedID int64 `gorm:"column:bed_id" json:"bed_id"`
  276. StartNurse int64 `gorm:"column:start_nurse" json:"start_nurse"`
  277. Status int64 `gorm:"column:status" json:"status"`
  278. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedID" json:"device_number"`
  279. Creator int64 `gorm:"column:creator" json:"creator"`
  280. WashpipeNurse int64 `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
  281. }
  282. func (MDialysisOrderVMList) TableName() string {
  283. return "xt_dialysis_order"
  284. }
  285. type VMDoctorAdvice struct {
  286. ID int64 `gorm:"column:id" json:"id" form:"id"`
  287. GroupNo int64 `gorm:"column:groupno" json:"groupno" form:"groupno"`
  288. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  289. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  290. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  291. Status int64 `gorm:"column:status" json:"status" form:"status"`
  292. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  293. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  294. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  295. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  296. ParentId int64 `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
  297. }
  298. func (VMDoctorAdvice) TableName() string {
  299. return "xt_doctor_advice"
  300. }
  301. type VMHisDoctorAdviceInfo struct {
  302. ID int64 `gorm:"column:id" json:"id" form:"id"`
  303. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  304. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  305. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  306. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  307. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  308. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  309. }
  310. func (VMHisDoctorAdviceInfo) TableName() string {
  311. return "his_doctor_advice_info"
  312. }
  313. type VMAssessmentAfterDislysis struct {
  314. ID int64 `gorm:"column:id" json:"id"`
  315. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  316. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  317. AssessmentDate int64 `gorm:"column:assessment_date" json:"assessment_date"`
  318. WeightAfter float64 `gorm:"column:weight_after" json:"weight_after"`
  319. Status int64 `gorm:"column:status" json:"status"`
  320. }
  321. func (VMAssessmentAfterDislysis) TableName() string {
  322. return "xt_assessment_after_dislysis"
  323. }
  324. // 获取透析记录
  325. func MobileGetDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  326. var record models.DialysisOrder
  327. err := readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgID, patientID, recordDate).First(&record).Error
  328. if err != nil {
  329. if err == gorm.ErrRecordNotFound {
  330. return nil, nil
  331. } else {
  332. return nil, err
  333. }
  334. }
  335. return &record, nil
  336. }
  337. // 用户基本信息
  338. func MobileGetPatientDetail(orgID int64, patientID int64) (*MPatient, error) {
  339. var patient MPatient
  340. //err := readDb.Model(&MPatient{}).Where("status = 1 AND user_org_id = ? AND id = ?", orgID, patientID).First(&patient).Error
  341. //if err != nil {
  342. // if err == gorm.ErrRecordNotFound {
  343. // return nil, nil
  344. // } else {
  345. // return nil, err
  346. // }
  347. //}
  348. //return &patient, nil
  349. redis := RedisClient()
  350. defer redis.Close()
  351. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":patient_info"
  352. patient_info_str, _ := redis.Get(key).Result()
  353. if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  354. err = readDb.Model(&patient).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  355. if err != nil {
  356. if err == gorm.ErrRecordNotFound {
  357. return &patient, nil
  358. } else {
  359. return &patient, err
  360. }
  361. } else {
  362. if patient.ID > 0 {
  363. //缓存数据
  364. patient_info_json, err := json.Marshal(&patient)
  365. if err == nil {
  366. redis.Set(key, patient_info_json, time.Second*60*60*18)
  367. }
  368. }
  369. return &patient, nil
  370. }
  371. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  372. json.Unmarshal([]byte(patient_info_str), &patient)
  373. return &patient, nil
  374. }
  375. }
  376. // 用户排班信息
  377. func MobileGetSchedualDetail(orgID int64, patientID int64, schedualDate int64) (*MDialysisScheduleVM, error) {
  378. redis := RedisClient()
  379. defer redis.Close()
  380. var vm MDialysisScheduleVM
  381. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(schedualDate, 10) + ":schedual_detail"
  382. schedual_detail_str, _ := redis.Get(key).Result()
  383. if len(schedual_detail_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  384. err := readDb.
  385. Table("xt_schedule").
  386. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  387. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  388. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  389. First(&vm).Error
  390. if err != nil {
  391. if err == gorm.ErrRecordNotFound {
  392. return nil, nil
  393. } else {
  394. return nil, err
  395. }
  396. } else {
  397. if vm.ID > 0 {
  398. //缓存数据
  399. schedual_detail_str, err := json.Marshal(vm)
  400. if err == nil {
  401. redis.Set(key, schedual_detail_str, time.Second*60*60*18)
  402. }
  403. } else {
  404. redis.Set(key, " ", time.Second*60*60*18)
  405. }
  406. return &vm, nil
  407. }
  408. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  409. json.Unmarshal([]byte(schedual_detail_str), &vm)
  410. return &vm, nil
  411. }
  412. }
  413. // 用户排班信息
  414. func MobileGetPatientSchedual(orgID int64, patientID int64, schedualDate int64) (*models.Schedule, error) {
  415. var schedule models.Schedule
  416. err := readDb.
  417. Table("xt_schedule").
  418. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND patient_id = ?", orgID, schedualDate, patientID).
  419. First(&schedule).Error
  420. if err != nil {
  421. if err == gorm.ErrRecordNotFound {
  422. return nil, nil
  423. } else {
  424. return nil, err
  425. }
  426. }
  427. return &schedule, nil
  428. }
  429. type MPatient struct {
  430. ID int64 `gorm:"column:id" json:"id" form:"id"`
  431. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  432. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  433. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  434. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  435. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  436. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  437. Source int64 `gorm:"column:source" json:"source" form:"source"`
  438. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  439. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  440. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  441. Name string `gorm:"column:name" json:"name" form:"name"`
  442. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  443. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  444. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  445. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  446. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  447. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  448. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  449. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  450. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  451. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  452. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  453. Height int64 `gorm:"column:height" json:"height" form:"height"`
  454. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  455. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  456. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  457. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  458. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  459. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  460. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  461. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  462. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  463. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  464. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  465. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  466. Children int64 `gorm:"column:children" json:"children" form:"children"`
  467. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  468. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  469. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  470. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  471. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  472. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  473. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  474. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  475. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  476. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  477. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  478. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  479. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  480. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  481. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  482. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  483. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains"` // 主诉
  484. PresentHistory string `gorm:"column:present_history" json:"present_history"` // 现病史
  485. PastHistory string `gorm:"column:past_history" json:"past_history"` // 既往史
  486. Temperature float64 `gorm:"column:temperature" json:"temperature"` // 体格检查-体温
  487. Pulse int64 `gorm:"column:pulse" json:"pulse"` // 体格检查-脉搏
  488. Respiratory int64 `gorm:"column:respiratory" json:"respiratory"` // 体格检查-呼吸频率
  489. SBP int64 `gorm:"column:sbp" json:"sbp"` // 体格检查-收缩压
  490. DBP int64 `gorm:"column:dbp" json:"dbp"` // 体格检查-舒张压
  491. Status int64 `gorm:"column:status" json:"status" form:"status"`
  492. Age int64 `gorm:"column:age" json:"age"`
  493. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind"`
  494. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  495. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  496. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  497. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  498. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  499. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  500. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  501. }
  502. func (MPatient) TableName() string {
  503. return "xt_patients"
  504. }
  505. // 接诊评估
  506. func MobileGetReceiverTreatmentAccessRecord(orgID int64, patientID int64, recordDate int64) (*models.ReceiveTreatmentAsses, error) {
  507. var record models.ReceiveTreatmentAsses
  508. redis := RedisClient()
  509. defer redis.Close()
  510. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":receive_treatment_asses"
  511. receive_treatment_asses_str, _ := redis.Get(key).Result()
  512. if len(receive_treatment_asses_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  513. err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  514. if err != nil {
  515. if err == gorm.ErrRecordNotFound {
  516. return nil, nil
  517. } else {
  518. return nil, err
  519. }
  520. } else {
  521. if record.ID > 0 {
  522. //缓存数据
  523. receive_treatment_asses_str, err := json.Marshal(record)
  524. if err == nil {
  525. redis.Set(key, receive_treatment_asses_str, time.Second*60*60*18)
  526. }
  527. } else {
  528. redis.Set(key, " ", time.Second*60*60*18)
  529. }
  530. return &record, nil
  531. }
  532. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  533. json.Unmarshal([]byte(receive_treatment_asses_str), &record)
  534. return &record, nil
  535. }
  536. }
  537. // 透前评估
  538. func MobileGetPredialysisEvaluation(orgID int64, patientID int64, recordDate int64) (*models.PredialysisEvaluation, error) {
  539. var record models.PredialysisEvaluation
  540. redis := RedisClient()
  541. defer redis.Close()
  542. // cur_date := time.Now().Format("2006-01-02")
  543. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_before_dislysis"
  544. assessment_before_dislysis_str, _ := redis.Get(key).Result()
  545. if len(assessment_before_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  546. err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  547. if err != nil {
  548. if err == gorm.ErrRecordNotFound {
  549. return nil, nil
  550. } else {
  551. return nil, err
  552. }
  553. } else {
  554. if record.ID > 0 {
  555. //缓存数据
  556. assessment_before_dislysis_str, err := json.Marshal(record)
  557. if err == nil {
  558. redis.Set(key, assessment_before_dislysis_str, time.Second*60*60*18)
  559. }
  560. } else {
  561. redis.Set(key, " ", time.Second*60*60*18)
  562. }
  563. return &record, nil
  564. }
  565. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  566. json.Unmarshal([]byte(assessment_before_dislysis_str), &record)
  567. return &record, nil
  568. }
  569. }
  570. // 获取 maxDate 之前一次的透前评估记录
  571. func MobileGetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  572. var record models.PredialysisEvaluation
  573. redis := RedisClient()
  574. defer redis.Close()
  575. // cur_date := time.Now().Format("2006-01-02")
  576. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_before_dislysis_last"
  577. assessment_before_dislysis_last_str, _ := redis.Get(key).Result()
  578. if len(assessment_before_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  579. 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
  580. if err != nil {
  581. if err == gorm.ErrRecordNotFound {
  582. return nil, nil
  583. } else {
  584. return nil, err
  585. }
  586. } else {
  587. if record.ID > 0 {
  588. //缓存数据
  589. assessment_before_dislysis_last_str, err := json.Marshal(record)
  590. if err == nil {
  591. redis.Set(key, assessment_before_dislysis_last_str, time.Second*60*60*4)
  592. }
  593. } else {
  594. redis.Set(key, " ", time.Second*60*60*18)
  595. }
  596. return &record, nil
  597. }
  598. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  599. json.Unmarshal([]byte(assessment_before_dislysis_last_str), &record)
  600. return &record, nil
  601. }
  602. }
  603. // 临时医嘱
  604. func MobileGetDoctorAdvices(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  605. var records []*models.DoctorAdvice
  606. // err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).Find(&records).Error
  607. err := readDb.
  608. Model(&models.DoctorAdvice{}).
  609. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientID, orgID, recordDate).
  610. 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").
  611. Order("start_time asc, groupno desc, advice_order desc, id").
  612. Scan(&records).Error
  613. if err != nil {
  614. return nil, err
  615. }
  616. return records, nil
  617. }
  618. func MobileGetDoctorAdvicesByGroups(orgID int64, patientID int64, recordDate int64) ([]*models.DoctorAdvice, error) {
  619. var records []*models.DoctorAdvice
  620. redis := RedisClient()
  621. defer redis.Close()
  622. // cur_date := time.Now().Format("2006-01-02")
  623. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":doctor_advices"
  624. doctor_advices_str, _ := redis.Get(key).Result()
  625. if len(doctor_advices_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  626. err := readDb.Model(&models.DoctorAdvice{}).
  627. Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ? and (advice_type = 2 || advice_type = 3)", patientID, orgID, recordDate).
  628. 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").
  629. Order("start_time asc, groupno desc, advice_order desc, id asc").
  630. Scan(&records).Error
  631. if err != nil {
  632. if err == gorm.ErrRecordNotFound {
  633. return nil, nil
  634. } else {
  635. return nil, err
  636. }
  637. } else {
  638. if len(records) > 0 {
  639. //缓存数据
  640. doctor_advices_str, err := json.Marshal(records)
  641. if err == nil {
  642. redis.Set(key, doctor_advices_str, time.Second*60*60*18)
  643. return records, nil
  644. }
  645. } else {
  646. redis.Set(key, " ", time.Second*60*60*18)
  647. return records, nil
  648. }
  649. return records, nil
  650. }
  651. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  652. json.Unmarshal([]byte(doctor_advices_str), &records)
  653. return records, nil
  654. }
  655. }
  656. // 透析记录
  657. func MobileGetSchedualDialysisRecord(orgID int64, patientID int64, recordDate int64) (*models.DialysisOrder, error) {
  658. var record models.DialysisOrder
  659. redis := RedisClient()
  660. defer redis.Close()
  661. // cur_date := time.Now().Format("2006-01-02")
  662. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_order"
  663. dialysis_order_str, _ := redis.Get(key).Result()
  664. if len(dialysis_order_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  665. 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
  666. if err != nil {
  667. if err == gorm.ErrRecordNotFound {
  668. return nil, nil
  669. } else {
  670. return nil, err
  671. }
  672. } else {
  673. if record.ID > 0 {
  674. //缓存数据
  675. dialysis_order_str, err := json.Marshal(record)
  676. if err == nil {
  677. redis.Set(key, dialysis_order_str, time.Second*60*60*18)
  678. }
  679. } else {
  680. redis.Set(key, " ", time.Second*60*60*18)
  681. }
  682. return &record, nil
  683. }
  684. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  685. json.Unmarshal([]byte(dialysis_order_str), &record)
  686. return &record, nil
  687. }
  688. }
  689. // 双人核对
  690. func MobileGetDoubleCheck(orgID int64, patientID int64, recordDate int64) (*models.DoubleCheck, error) {
  691. var record models.DoubleCheck
  692. redis := RedisClient()
  693. defer redis.Close()
  694. // cur_date := time.Now().Format("2006-01-02")
  695. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":double_check"
  696. double_check_str, _ := redis.Get(key).Result()
  697. if len(double_check_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  698. err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id = ? and status = 1 and check_date = ?", patientID, orgID, recordDate).First(&record).Error
  699. if err != nil {
  700. if err == gorm.ErrRecordNotFound {
  701. return nil, nil
  702. } else {
  703. return nil, err
  704. }
  705. } else {
  706. if record.ID > 0 {
  707. //缓存数据
  708. double_check_str, err := json.Marshal(record)
  709. if err == nil {
  710. redis.Set(key, double_check_str, time.Second*60*60*18)
  711. }
  712. } else {
  713. redis.Set(key, " ", time.Second*60*60*18)
  714. }
  715. return &record, nil
  716. }
  717. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  718. json.Unmarshal([]byte(double_check_str), &record)
  719. return &record, nil
  720. }
  721. }
  722. // 透析监测记录
  723. func MobileGetMonitorRecords(orgID int64, patientID int64, recordDate int64) ([]*models.MonitoringRecord, error) {
  724. var records []*models.MonitoringRecord
  725. redis := RedisClient()
  726. defer redis.Close()
  727. // cur_date := time.Now().Format("2006-01-02")
  728. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":monitor_records"
  729. monitor_records_str, _ := redis.Get(key).Result()
  730. if len(monitor_records_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  731. 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
  732. if err != nil {
  733. if err == gorm.ErrRecordNotFound {
  734. return nil, nil
  735. } else {
  736. return nil, err
  737. }
  738. } else {
  739. if len(records) > 0 {
  740. //缓存数据
  741. monitor_records_str, err := json.Marshal(records)
  742. if err == nil {
  743. redis.Set(key, monitor_records_str, time.Second*60*60*18)
  744. }
  745. } else {
  746. redis.Set(key, " ", time.Second*60*60*18)
  747. }
  748. return records, nil
  749. }
  750. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  751. json.Unmarshal([]byte(monitor_records_str), &records)
  752. return records, nil
  753. }
  754. }
  755. func MobileGetMonitorRecordFirst(orgID int64, patientID int64, recordDate int64) (*models.MonitoringRecord, error) {
  756. var records models.MonitoringRecord
  757. 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
  758. if err != nil {
  759. return nil, err
  760. }
  761. return &records, nil
  762. }
  763. func MobileGetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  764. var record models.MonitoringRecord
  765. redis := RedisClient()
  766. defer redis.Close()
  767. // cur_date := time.Now().Format("2006-01-02")
  768. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(beforeDate, 10) + ":monitor_record_last"
  769. monitor_record_last_str, _ := redis.Get(key).Result()
  770. if len(monitor_record_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  771. 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
  772. if err != nil {
  773. if err == gorm.ErrRecordNotFound {
  774. return nil, nil
  775. } else {
  776. return nil, err
  777. }
  778. } else {
  779. if record.ID > 0 {
  780. //缓存数据
  781. monitor_record_last_str, err := json.Marshal(record)
  782. if err == nil {
  783. redis.Set(key, monitor_record_last_str, time.Second*60*60*18)
  784. }
  785. } else {
  786. redis.Set(key, " ", time.Second*60*60*18)
  787. }
  788. return &record, nil
  789. }
  790. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  791. json.Unmarshal([]byte(monitor_record_last_str), &record)
  792. return &record, nil
  793. }
  794. }
  795. // 透后评估
  796. func MobileGetAssessmentAfterDislysis(orgID int64, patientID int64, recordDate int64) (*models.AssessmentAfterDislysis, error) {
  797. var record models.AssessmentAfterDislysis
  798. redis := RedisClient()
  799. defer redis.Close()
  800. // cur_date := time.Now().Format("2006-01-02")
  801. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":assessment_after_dislysis"
  802. assessment_after_dislysis_str, _ := redis.Get(key).Result()
  803. if len(assessment_after_dislysis_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  804. err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  805. if err != nil {
  806. if err == gorm.ErrRecordNotFound {
  807. return nil, nil
  808. } else {
  809. return nil, err
  810. }
  811. } else {
  812. if record.ID > 0 {
  813. //缓存数据
  814. assessment_after_dislysis_str, err := json.Marshal(record)
  815. if err == nil {
  816. redis.Set(key, assessment_after_dislysis_str, time.Second*60*60*18)
  817. }
  818. } else {
  819. redis.Set(key, " ", time.Second*60*60*18)
  820. }
  821. return &record, nil
  822. }
  823. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  824. json.Unmarshal([]byte(assessment_after_dislysis_str), &record)
  825. return &record, nil
  826. }
  827. }
  828. // 获取 maxDate 之前一次的透后评估记录
  829. func MobileGetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  830. var record models.AssessmentAfterDislysis
  831. redis := RedisClient()
  832. defer redis.Close()
  833. // cur_date := time.Now().Format("2006-01-02")
  834. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(maxDate, 10) + ":assessment_after_dislysis_last"
  835. assessment_after_dislysis_last_str, _ := redis.Get(key).Result()
  836. if len(assessment_after_dislysis_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  837. 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
  838. if err != nil {
  839. if err == gorm.ErrRecordNotFound {
  840. return nil, nil
  841. } else {
  842. return nil, err
  843. }
  844. } else {
  845. if record.ID > 0 {
  846. //缓存数据
  847. assessment_after_dislysis_last_str, err := json.Marshal(record)
  848. if err == nil {
  849. redis.Set(key, assessment_after_dislysis_last_str, time.Second*60*60*18)
  850. }
  851. } else {
  852. redis.Set(key, " ", time.Second*60*60*18)
  853. }
  854. return &record, nil
  855. }
  856. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  857. json.Unmarshal([]byte(assessment_after_dislysis_last_str), &record)
  858. return &record, nil
  859. }
  860. }
  861. func MobileGetLast(orgID int64, patientID int64, maxDate int64) (models.AssessmentAfterDislysis, error) {
  862. dislysis := models.AssessmentAfterDislysis{}
  863. 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
  864. return dislysis, err
  865. }
  866. // 治疗小结
  867. func MobileGetTreatmentSummary(orgID int64, patientID int64, recordDate int64) (*models.TreatmentSummary, error) {
  868. var record models.TreatmentSummary
  869. redis := RedisClient()
  870. defer redis.Close()
  871. // cur_date := time.Now().Format("2006-01-02")
  872. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":treatment_summary"
  873. treatment_summary_str, _ := redis.Get(key).Result()
  874. fmt.Println("质量洗哦啊稼23323232323232323233232322332", treatment_summary_str)
  875. if len(treatment_summary_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  876. err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id = ? and status = 1 and assessment_date = ?", patientID, orgID, recordDate).First(&record).Error
  877. if err != nil {
  878. if err == gorm.ErrRecordNotFound {
  879. return nil, nil
  880. } else {
  881. return nil, err
  882. }
  883. } else {
  884. if record.ID > 0 {
  885. //缓存数据
  886. treatment_summary_str, err := json.Marshal(record)
  887. if err == nil {
  888. redis.Set(key, treatment_summary_str, time.Second*60*60*18)
  889. }
  890. } else {
  891. redis.Set(key, " ", time.Second*60*60*18)
  892. }
  893. return &record, nil
  894. }
  895. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  896. json.Unmarshal([]byte(treatment_summary_str), &record)
  897. return &record, nil
  898. }
  899. }
  900. // 透析处方
  901. func MobileGetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  902. var record models.DialysisPrescription
  903. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  904. if err != nil {
  905. if err == gorm.ErrRecordNotFound {
  906. return nil, nil
  907. } else {
  908. return nil, err
  909. }
  910. }
  911. return &record, nil
  912. }
  913. func MobileGetDialysisSchedual(orgID int64, patientID int64, scheduleDate int64) (*models.XtSchedule, error) {
  914. var schedule models.XtSchedule
  915. err := readDb.Model(&models.XtSchedule{}).Where("patient_id = ? and user_org_id = ? and status = 1 and schedule_date = ?", patientID, orgID, scheduleDate).First(&schedule).Error
  916. if err != nil {
  917. if err == gorm.ErrRecordNotFound {
  918. return nil, nil
  919. } else {
  920. return nil, err
  921. }
  922. }
  923. return &schedule, nil
  924. }
  925. // 透析方案
  926. func MobileGetDialysisSolution(orgID int64, patientID int64) (*models.DialysisSolution, error) {
  927. var record models.DialysisSolution
  928. err := readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  929. if err != nil {
  930. if err == gorm.ErrRecordNotFound {
  931. return nil, nil
  932. } else {
  933. return nil, err
  934. }
  935. }
  936. return &record, nil
  937. }
  938. func MobileGetPatientById(orgID int64, patientID int64) (*models.Patients, error) {
  939. var patient models.Patients
  940. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id = ? and status = 1", patientID, orgID).First(&patient).Error
  941. if err != nil {
  942. if err == gorm.ErrRecordNotFound {
  943. return nil, nil
  944. } else {
  945. return nil, err
  946. }
  947. }
  948. return &patient, nil
  949. }
  950. func DisableMonitor(orgID int64, patientID int64, recordID int64, admin_user_id int64) error {
  951. fmt.Println()
  952. tx := writeDb.Begin()
  953. updateTime := time.Now().Unix()
  954. 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
  955. if err != nil {
  956. tx.Rollback()
  957. return err
  958. }
  959. tx.Commit()
  960. return nil
  961. }
  962. func GetMonitor(orgID int64, patientID int64, id int64) (*models.MonitoringRecord, error) {
  963. var monitor models.MonitoringRecord
  964. var err error
  965. err = readDb.Model(&models.MonitoringRecord{}).Where("id = ? AND user_org_id = ? AND patient_id = ? AND status = 1 ", id, orgID, patientID).Find(&monitor).Error
  966. if err == gorm.ErrRecordNotFound {
  967. return nil, nil
  968. }
  969. if err != nil {
  970. return nil, err
  971. }
  972. return &monitor, nil
  973. }
  974. type MScheduleDoctorAdviceVM struct {
  975. ID int64 `gorm:"column:id" json:"id"`
  976. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  977. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  978. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  979. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  980. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  981. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  982. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  983. Status int64 `gorm:"column:status" json:"status"`
  984. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  985. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  986. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  987. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  988. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  989. DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  990. }
  991. func (MScheduleDoctorAdviceVM) TableName() string {
  992. return "xt_schedule"
  993. }
  994. type MScheduleDoctorAdviceVMOne struct {
  995. ID int64 `gorm:"column:id" json:"id"`
  996. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  997. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  998. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  999. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1000. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  1001. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  1002. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  1003. Status int64 `gorm:"column:status" json:"status"`
  1004. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  1005. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1006. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  1007. DoctorAdvices []*MDoctorAdviceVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  1008. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  1009. //DialysisAssesmentBefor *models.DialysisAssesmentBefor `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysisassesmentbefor"`
  1010. }
  1011. func (MScheduleDoctorAdviceVMOne) TableName() string {
  1012. return "xt_schedule"
  1013. }
  1014. type MDoctorAdviceVM struct {
  1015. ID int64 `gorm:"column:id" json:"id"`
  1016. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  1017. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  1018. AdviceType int64 `gorm:"column:advice_type" json:"advice_type"`
  1019. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date"`
  1020. StartTime int64 `gorm:"column:start_time" json:"start_time"`
  1021. AdviceName string `gorm:"column:advice_name" json:"advice_name"`
  1022. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc"`
  1023. ReminderDate int64 `gorm:"column:reminder_date" json:"reminder_date"`
  1024. SingleDose float64 `gorm:"column:single_dose" json:"single_dose"`
  1025. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit"`
  1026. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number"`
  1027. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit"`
  1028. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way"`
  1029. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency"`
  1030. AdviceDoctor int64 `gorm:"column:advice_doctor" json:"advice_doctor"`
  1031. Status int64 `gorm:"column:status" json:"status"`
  1032. CreatedTime int64 `gorm:"column:created_time" json:"created_time"`
  1033. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time"`
  1034. AdviceAffirm string `gorm:"column:advice_affirm" json:"advice_affirm"`
  1035. Remark string `gorm:"column:remark" json:"remark"`
  1036. StopTime int64 `gorm:"column:stop_time" json:"stop_time"`
  1037. StopReason string `gorm:"column:stop_reason" json:"stop_reason"`
  1038. StopDoctor int64 `gorm:"column:stop_doctor" json:"stop_doctor"`
  1039. StopState int64 `gorm:"column:stop_state" json:"stop_state"`
  1040. ParentId int64 `gorm:"column:parent_id" json:"parent_id"`
  1041. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time"`
  1042. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff"`
  1043. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state"`
  1044. Checker int64 `gorm:"column:checker" json:"checker"`
  1045. RecordDate int64 `gorm:"column:record_date" json:"record_date"`
  1046. DialysisOrderId int64 `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
  1047. CheckTime int64 `gorm:"column:check_time" json:"check_time"`
  1048. CheckState int64 `gorm:"column:check_state" json:"check_state"`
  1049. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec"`
  1050. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit"`
  1051. Groupno int64 `gorm:"column:groupno" json:"groupno"`
  1052. RemindType int64 `gorm:"column:remind_type" json:"remind_type"`
  1053. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type"`
  1054. DayCount int64 `gorm:"column:day_count" json:"day_count"`
  1055. WeekDay string `gorm:"column:week_day" json:"week_day"`
  1056. TemplateId string `gorm:"column:template_id" json:"template_id"`
  1057. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1058. }
  1059. func (MDoctorAdviceVM) TableName() string {
  1060. return "xt_doctor_advice"
  1061. }
  1062. func MobileGetScheduleDoctorAdvices(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVM, error) {
  1063. var vms []*MScheduleDoctorAdviceVM
  1064. adviceWhere := ""
  1065. adviceCondition := []interface{}{}
  1066. if adviceType == 0 {
  1067. if patientType == 0 {
  1068. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1069. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1070. } else if patientType == 1 {
  1071. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1072. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1073. } else if patientType == 2 {
  1074. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1075. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1076. }
  1077. } else if adviceType == 1 {
  1078. if patientType == 0 {
  1079. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1080. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1081. } else if patientType == 1 {
  1082. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1083. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1084. } else if patientType == 2 {
  1085. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1086. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1087. }
  1088. } else if adviceType == 3 {
  1089. if patientType == 0 {
  1090. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1091. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1092. } else if patientType == 1 {
  1093. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1094. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1095. } else if patientType == 2 {
  1096. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1097. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1098. }
  1099. } else if adviceType == 2 && len(deliverWay) > 0 {
  1100. if patientType == 0 {
  1101. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1102. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1103. } else if patientType == 1 {
  1104. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1105. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1106. } else if patientType == 2 {
  1107. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1108. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1109. }
  1110. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1111. if patientType == 0 {
  1112. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1113. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1114. } else if patientType == 1 {
  1115. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1116. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1117. } else if patientType == 2 {
  1118. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1119. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1120. }
  1121. }
  1122. db := readDb.
  1123. Table("xt_schedule").
  1124. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1125. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1126. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1127. }).
  1128. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1129. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1130. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1131. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  1132. Preload("DoctorAdvices", adviceCondition...).
  1133. Where("status = 1 AND user_org_id = ?", orgID)
  1134. if scheduleDate != 0 {
  1135. db = db.Where("schedule_date = ?", scheduleDate)
  1136. }
  1137. err := db.Find(&vms).Error
  1138. return vms, err
  1139. }
  1140. func MobileGetScheduleDoctorAdvicesTwo(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string) ([]*MScheduleDoctorAdviceVMOne, error) {
  1141. var vms []*MScheduleDoctorAdviceVMOne
  1142. adviceWhere := ""
  1143. adviceCondition := []interface{}{}
  1144. if adviceType == 0 {
  1145. if patientType == 0 {
  1146. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  1147. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1148. } else if patientType == 1 {
  1149. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  1150. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1151. } else if patientType == 2 {
  1152. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  1153. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1154. }
  1155. } else if adviceType == 1 {
  1156. if patientType == 0 {
  1157. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  1158. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1159. } else if patientType == 1 {
  1160. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  1161. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1162. } else if patientType == 2 {
  1163. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  1164. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1165. }
  1166. } else if adviceType == 3 {
  1167. if patientType == 0 {
  1168. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  1169. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1170. } else if patientType == 1 {
  1171. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  1172. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  1173. } else if patientType == 2 {
  1174. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  1175. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1176. }
  1177. } else if adviceType == 2 && len(deliverWay) > 0 {
  1178. if patientType == 0 {
  1179. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  1180. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1181. } else if patientType == 1 {
  1182. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  1183. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  1184. } else if patientType == 2 {
  1185. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  1186. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  1187. }
  1188. } else if adviceType == 2 && len(deliverWay) <= 0 {
  1189. if patientType == 0 {
  1190. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  1191. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1192. } else if patientType == 1 {
  1193. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND (advice_doctor = ? or execution_staff = ?)"
  1194. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, adminUserId)
  1195. } else if patientType == 2 {
  1196. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  1197. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  1198. }
  1199. }
  1200. db := readDb.
  1201. Table("xt_schedule").
  1202. //Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1203. //Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1204. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1205. //}).
  1206. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1207. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1208. //Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1209. Preload("DoctorAdvices", adviceCondition...).
  1210. Where("status = 1 AND user_org_id = ?", orgID)
  1211. if scheduleDate != 0 {
  1212. db = db.Where("schedule_date = ?", scheduleDate)
  1213. }
  1214. err := db.Find(&vms).Error
  1215. return vms, err
  1216. }
  1217. func GetHisDoctorAdvices(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  1218. var vms []*HisMScheduleDoctorAdviceVM
  1219. if len(deliverWay) > 0 {
  1220. if patientType == 0 {
  1221. db := readDb.
  1222. Table("xt_schedule").
  1223. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1224. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1225. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1226. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1227. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1228. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1229. }).
  1230. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1231. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1232. Where("status = 1 AND user_org_id = ?", orgID)
  1233. if scheduleDate != 0 {
  1234. db = db.Where("schedule_date = ?", scheduleDate)
  1235. }
  1236. err = db.Find(&vms).Error
  1237. }
  1238. if patientType > 0 {
  1239. db := readDb.
  1240. Table("xt_schedule").
  1241. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1242. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1243. 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).
  1244. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1245. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1246. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1247. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1248. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1249. }).Where("status = 1 AND user_org_id = ?", orgID)
  1250. if scheduleDate != 0 {
  1251. db = db.Where("schedule_date = ?", scheduleDate)
  1252. }
  1253. err = db.Find(&vms).Error
  1254. }
  1255. } else {
  1256. if patientType == 0 {
  1257. db := readDb.
  1258. Table("xt_schedule").
  1259. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1260. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1261. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1262. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1263. }).
  1264. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1265. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1266. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1267. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1268. Where("status = 1 AND user_org_id = ?", orgID)
  1269. if scheduleDate != 0 {
  1270. db = db.Where("schedule_date = ?", scheduleDate)
  1271. }
  1272. err = db.Find(&vms).Error
  1273. }
  1274. if patientType > 0 {
  1275. db := readDb.
  1276. Table("xt_schedule").
  1277. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1278. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1279. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1280. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1281. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1282. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1283. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1284. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1285. Where("status = 1 AND user_org_id = ?", orgID)
  1286. if scheduleDate != 0 {
  1287. db = db.Where("schedule_date = ?", scheduleDate)
  1288. }
  1289. err = db.Find(&vms).Error
  1290. }
  1291. }
  1292. return vms, err
  1293. }
  1294. func GetHisDoctorAdvicesTwo(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleDoctorAdviceVMOne, error) {
  1295. var vms []*HisMScheduleDoctorAdviceVMOne
  1296. if len(deliverWay) > 0 {
  1297. if patientType == 0 {
  1298. db := readDb.
  1299. Table("xt_schedule").
  1300. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  1301. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1302. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1303. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1304. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1305. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1306. }).
  1307. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1308. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1309. Where("status = 1 AND user_org_id = ?", orgID)
  1310. if scheduleDate != 0 {
  1311. db = db.Where("schedule_date = ?", scheduleDate)
  1312. }
  1313. err = db.Find(&vms).Error
  1314. }
  1315. if patientType > 0 {
  1316. db := readDb.
  1317. Table("xt_schedule").
  1318. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1319. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1320. 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).
  1321. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1322. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1323. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1324. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1325. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1326. }).Where("status = 1 AND user_org_id = ?", orgID)
  1327. if scheduleDate != 0 {
  1328. db = db.Where("schedule_date = ?", scheduleDate)
  1329. }
  1330. err = db.Find(&vms).Error
  1331. }
  1332. } else {
  1333. if patientType == 0 {
  1334. db := readDb.
  1335. Table("xt_schedule").
  1336. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate).
  1337. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1338. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1339. return db.Where("status = 1 AND user_org_id = ? and dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1340. }).
  1341. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1342. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1343. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1344. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1345. Where("status = 1 AND user_org_id = ?", orgID)
  1346. if scheduleDate != 0 {
  1347. db = db.Where("schedule_date = ?", scheduleDate)
  1348. }
  1349. err = db.Find(&vms).Error
  1350. }
  1351. if patientType > 0 {
  1352. db := readDb.
  1353. Table("xt_schedule").
  1354. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1355. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1356. Preload("HisPrescriptionProject", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1357. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1358. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1359. return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1360. }).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1361. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1362. Where("status = 1 AND user_org_id = ?", orgID)
  1363. if scheduleDate != 0 {
  1364. db = db.Where("schedule_date = ?", scheduleDate)
  1365. }
  1366. err = db.Find(&vms).Error
  1367. }
  1368. }
  1369. return vms, err
  1370. }
  1371. func GetMobileHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
  1372. var vms []*HisMScheduleProjectVM
  1373. //if patientType == 0 {
  1374. // db := readDb.
  1375. // Table("xt_schedule").
  1376. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1377. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1378. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1379. // }).
  1380. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1381. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1382. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1383. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1384. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1385. // }).
  1386. // Where("status = 1 AND user_org_id = ?", orgID)
  1387. // if scheduleDate != 0 {
  1388. // db = db.Where("schedule_date = ?", scheduleDate)
  1389. // }
  1390. // err = db.Find(&vms).Error
  1391. //}
  1392. //if patientType > 0 {
  1393. // db := readDb.
  1394. // Table("xt_schedule").
  1395. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  1396. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  1397. // return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  1398. // }).
  1399. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1400. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  1401. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  1402. // Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  1403. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1404. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  1405. // }).
  1406. // Where("status = 1 AND user_org_id = ?", orgID)
  1407. // if scheduleDate != 0 {
  1408. // db = db.Where("schedule_date = ?", scheduleDate)
  1409. // }
  1410. // err = db.Find(&vms).Error
  1411. //}
  1412. db := readDb.Table("xt_schedule").Where("status = 1")
  1413. if orgID > 0 {
  1414. db = db.Where("user_org_id = ?", orgID)
  1415. }
  1416. if scheduleDate > 0 {
  1417. db = db.Where("schedule_date =?", scheduleDate)
  1418. }
  1419. err = db.Find(&vms).Error
  1420. return vms, err
  1421. }
  1422. func MobileCreateDialysisOrder(orgID int64, patientID int64, order *models.DialysisOrder) error {
  1423. now := time.Now()
  1424. tx := writeDb.Begin()
  1425. if createOrderErr := tx.Model(&models.DialysisOrder{}).Create(order).Error; createOrderErr != nil {
  1426. tx.Rollback()
  1427. return createOrderErr
  1428. }
  1429. // 更新透析记录 ID
  1430. // 透析处方
  1431. 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 {
  1432. tx.Rollback()
  1433. return err
  1434. }
  1435. // 接诊评估
  1436. 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 {
  1437. tx.Rollback()
  1438. return err
  1439. }
  1440. // 透前评估
  1441. 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 {
  1442. tx.Rollback()
  1443. return err
  1444. }
  1445. // 临时医嘱
  1446. 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 {
  1447. tx.Rollback()
  1448. return err
  1449. }
  1450. // 双人核对
  1451. 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 {
  1452. tx.Rollback()
  1453. return err
  1454. }
  1455. // 透后评估
  1456. 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 {
  1457. tx.Rollback()
  1458. return err
  1459. }
  1460. // 治疗小结
  1461. 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 {
  1462. tx.Rollback()
  1463. return err
  1464. }
  1465. // 透析监测
  1466. 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 {
  1467. tx.Rollback()
  1468. return err
  1469. }
  1470. tx.Commit()
  1471. return nil
  1472. }
  1473. type MobileUrgentSchedulePatientVM struct {
  1474. ID int64 `gorm:"column:id" json:"id"`
  1475. Name string `gorm:"column:name" json:"name"`
  1476. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no"`
  1477. }
  1478. func (MobileUrgentSchedulePatientVM) TableName() string {
  1479. return "xt_patients"
  1480. }
  1481. type MobileUrgentScheduleTreatmentModeVM struct {
  1482. ID int64 `gorm:"column:id" json:"id"`
  1483. Name string `gorm:"column:name" json:"name"`
  1484. }
  1485. func (MobileUrgentScheduleTreatmentModeVM) TableName() string {
  1486. return "xt_treatment_mode"
  1487. }
  1488. func MobileGetAllPatientsForUrgentSchedule(orgID int64, record_date int64) ([]*MobileUrgentSchedulePatientVM, error) {
  1489. var vms []*MobileUrgentSchedulePatientVM = make([]*MobileUrgentSchedulePatientVM, 0)
  1490. 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()
  1491. defer rows.Close()
  1492. if err != nil {
  1493. return nil, err
  1494. }
  1495. for rows.Next() {
  1496. var vm MobileUrgentSchedulePatientVM
  1497. readDb.ScanRows(rows, &vm)
  1498. vms = append(vms, &vm)
  1499. }
  1500. return vms, nil
  1501. }
  1502. func MobileGetAllTrearmentModesForUrgentSchedule() ([]*MobileUrgentScheduleTreatmentModeVM, error) {
  1503. var modes []*MobileUrgentScheduleTreatmentModeVM
  1504. err := readDb.Model(&MobileUrgentScheduleTreatmentModeVM{}).Where("status = 1").Find(&modes).Error
  1505. if err != nil {
  1506. return nil, err
  1507. }
  1508. return modes, nil
  1509. }
  1510. type MobileUrgentScheduleScheduleListVM struct {
  1511. ID int64 `gorm:"column:id" json:"id"`
  1512. // ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
  1513. DeviceNumberID int64 `gorm:"column:bed_id" json:"bed_id"`
  1514. PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
  1515. ScheduleType int `gorm:"column:schedule_type" json:"schedule_type"`
  1516. DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
  1517. // DeviceZone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"device_zone"`
  1518. }
  1519. func (MobileUrgentScheduleScheduleListVM) TableName() string {
  1520. return "xt_schedule"
  1521. }
  1522. func MobileGetSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) (schedules []*MobileUrgentScheduleScheduleListVM, err error) {
  1523. db := readDb.
  1524. Model(&MobileUrgentScheduleScheduleListVM{}).
  1525. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  1526. Where("status = 1 AND user_org_id = ? AND schedule_date = ? AND schedule_type = ? ", orgID, scheduleDate, schedule_type)
  1527. err = db.Find(&schedules).Error
  1528. if err != nil {
  1529. return nil, err
  1530. }
  1531. return schedules, nil
  1532. }
  1533. func MobileGetOtherSchedulesForUrgentSchedule(orgID int64, scheduleDate int64, schedule_type int) ([]*MobileUrgentScheduleScheduleListVM, error) {
  1534. var vms []*MobileUrgentScheduleScheduleListVM = make([]*MobileUrgentScheduleScheduleListVM, 0)
  1535. 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()
  1536. defer rows.Close()
  1537. if err != nil {
  1538. return nil, err
  1539. }
  1540. for rows.Next() {
  1541. var vm MobileUrgentScheduleScheduleListVM
  1542. readDb.ScanRows(rows, &vm)
  1543. vms = append(vms, &vm)
  1544. }
  1545. return vms, nil
  1546. }
  1547. type MobileUrgentScheduleDeviceNumberVM struct {
  1548. ID int64 `gorm:"column:id" json:"id"`
  1549. Number string `gorm:"column:number" json:"number"`
  1550. ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
  1551. Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
  1552. }
  1553. func (MobileUrgentScheduleDeviceNumberVM) TableName() string {
  1554. return "xt_device_number"
  1555. }
  1556. func MobileGetAllDeviceNumbersForUrgentSchedule(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  1557. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  1558. 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()
  1559. defer rows.Close()
  1560. if err != nil {
  1561. return nil, err
  1562. }
  1563. for rows.Next() {
  1564. var vm DeviceNumberViewModel
  1565. readDb.ScanRows(rows, &vm)
  1566. vms = append(vms, &vm)
  1567. }
  1568. return vms, nil
  1569. //var deviceNumbers []*MobileUrgentScheduleDeviceNumberVM
  1570. //db := readDb.
  1571. // Model(&MobileUrgentScheduleDeviceNumberVM{}).
  1572. // Preload("Zone", "status = 1 AND org_id = ?", orgID).
  1573. // Where("status = 1 AND org_id = ?", orgID)
  1574. //err := db.Order("zone_id asc").Find(&deviceNumbers).Error
  1575. //if err != nil {
  1576. // return nil, err
  1577. //}
  1578. //return deviceNumbers, nil
  1579. }
  1580. func GetValidScheduleMonitorRecordCount() (int64, error) {
  1581. var total int64
  1582. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Count(&total).Error
  1583. return total, err
  1584. }
  1585. func GetTop1000ValidScheduleMonitorRecord() ([]*models.MonitoringRecord, error) {
  1586. var monitors []*models.MonitoringRecord
  1587. err := readDb.Model(&models.MonitoringRecord{}).Where("status = 1 AND operate_time = 0 AND monitoring_date <> 0").Order("id asc").Limit(100).Find(&monitors).Error
  1588. if err != nil {
  1589. return nil, err
  1590. }
  1591. return monitors, nil
  1592. }
  1593. func BatchUpdateMonitors(monitors []*models.MonitoringRecord) error {
  1594. tx := writeDb.Begin()
  1595. for index := 0; index < len(monitors); index++ {
  1596. tx.Save(monitors[index])
  1597. }
  1598. return tx.Commit().Error
  1599. }
  1600. func ModifyStartDialysisOrder(order *models.DialysisOrder) error {
  1601. tx := writeDb.Begin()
  1602. updateTime := time.Now().Unix()
  1603. 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
  1604. if err != nil {
  1605. tx.Rollback()
  1606. return err
  1607. }
  1608. tx.Commit()
  1609. return err
  1610. }
  1611. func ModifyFinishDialysisOrder(order *models.DialysisOrder) error {
  1612. tx := writeDb.Begin()
  1613. updateTime := time.Now().Unix()
  1614. 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
  1615. if err != nil {
  1616. tx.Rollback()
  1617. return err
  1618. }
  1619. tx.Commit()
  1620. return err
  1621. }
  1622. func MobileGetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  1623. var record models.SgjPatientDryweight
  1624. redis := RedisClient()
  1625. defer redis.Close()
  1626. // cur_date := time.Now().Format("2006-01-02")
  1627. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":last_dry_weight"
  1628. last_dry_weight_str, _ := redis.Get(key).Result()
  1629. if len(last_dry_weight_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1630. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1631. if err != nil {
  1632. if err == gorm.ErrRecordNotFound {
  1633. return nil, nil
  1634. } else {
  1635. return nil, err
  1636. }
  1637. } else {
  1638. if record.ID > 0 {
  1639. //缓存数据
  1640. last_dry_weight_str, err := json.Marshal(record)
  1641. if err == nil {
  1642. redis.Set(key, last_dry_weight_str, time.Second*60*60*18)
  1643. return nil, err
  1644. }
  1645. } else {
  1646. redis.Set(key, " ", time.Second*60*60*18)
  1647. return nil, err
  1648. }
  1649. return &record, nil
  1650. }
  1651. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1652. json.Unmarshal([]byte(last_dry_weight_str), &record)
  1653. return &record, nil
  1654. }
  1655. }
  1656. // 透析方案
  1657. func MobileGetDialysisSolutionByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  1658. var record models.DialysisSolution
  1659. redis := RedisClient()
  1660. defer redis.Close()
  1661. // cur_date := time.Now().Format("2006-01-02")
  1662. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1663. dialysis_solution_str, _ := redis.Get(key).Result()
  1664. if len(dialysis_solution_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1665. 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
  1666. if err != nil {
  1667. if err == gorm.ErrRecordNotFound {
  1668. return nil, nil
  1669. } else {
  1670. return nil, err
  1671. }
  1672. } else {
  1673. if record.ID > 0 {
  1674. //缓存数据
  1675. dialysis_solution_str, err := json.Marshal(record)
  1676. if err == nil {
  1677. redis.Set(key, dialysis_solution_str, time.Second*60*60*18)
  1678. }
  1679. } else {
  1680. redis.Set(key, " ", time.Second*60*60*18)
  1681. }
  1682. return &record, nil
  1683. }
  1684. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1685. json.Unmarshal([]byte(dialysis_solution_str), &record)
  1686. return &record, nil
  1687. }
  1688. }
  1689. // 透析处方
  1690. func MobileGetDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64, mode_id int64) (*models.DialysisPrescription, error) {
  1691. var record models.DialysisPrescription
  1692. redis := RedisClient()
  1693. defer redis.Close()
  1694. // cur_date := time.Now().Format("2006-01-02")
  1695. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1696. dialysis_prescribe_str, _ := redis.Get(key).Result()
  1697. if len(dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1698. 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
  1699. if err != nil {
  1700. if err == gorm.ErrRecordNotFound {
  1701. return nil, nil
  1702. } else {
  1703. return nil, err
  1704. }
  1705. } else {
  1706. if record.ID > 0 {
  1707. //缓存数据
  1708. dialysis_prescribe_str, err := json.Marshal(record)
  1709. if err == nil {
  1710. redis.Set(key, dialysis_prescribe_str, time.Second*60*60*18)
  1711. }
  1712. } else {
  1713. redis.Set(key, " ", time.Second*60*60*18)
  1714. }
  1715. return &record, nil
  1716. }
  1717. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1718. json.Unmarshal([]byte(dialysis_prescribe_str), &record)
  1719. return &record, nil
  1720. }
  1721. }
  1722. func MobileGetDialysisPrescribeByModeIdOne(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1723. var record models.DialysisPrescription
  1724. redis := RedisClient()
  1725. defer redis.Close()
  1726. // cur_date := time.Now().Format("2006-01-02")
  1727. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":dialysis_prescribe_by_mode"
  1728. dialysis_prescribe_by_mode_str, _ := redis.Get(key).Result()
  1729. if len(dialysis_prescribe_by_mode_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1730. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  1731. if err != nil {
  1732. if err == gorm.ErrRecordNotFound {
  1733. return nil, nil
  1734. } else {
  1735. return nil, err
  1736. }
  1737. } else {
  1738. if record.ID > 0 {
  1739. //缓存数据
  1740. dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  1741. if err == nil {
  1742. redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  1743. return nil, err
  1744. }
  1745. } else {
  1746. redis.Set(key, " ", time.Second*60*60*18)
  1747. return nil, err
  1748. }
  1749. return &record, nil
  1750. }
  1751. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1752. json.Unmarshal([]byte(dialysis_prescribe_by_mode_str), &record)
  1753. return &record, nil
  1754. }
  1755. }
  1756. func MobileGetLastDialysisPrescribe(orgID int64, patientID int64) (*models.DialysisPrescription, error) {
  1757. var record models.DialysisPrescription
  1758. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 ", patientID, orgID).Last(&record).Error
  1759. if err != nil {
  1760. if err == gorm.ErrRecordNotFound {
  1761. return nil, nil
  1762. } else {
  1763. return nil, err
  1764. }
  1765. }
  1766. return &record, nil
  1767. }
  1768. func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  1769. //var record models.DialysisPrescription
  1770. //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
  1771. //if err != nil {
  1772. // if err == gorm.ErrRecordNotFound {
  1773. // return nil, nil
  1774. // } else {
  1775. // return nil, err
  1776. // }
  1777. //}
  1778. //return &record, nil
  1779. var record models.DialysisPrescription
  1780. redis := RedisClient()
  1781. defer redis.Close()
  1782. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  1783. dialysis_prescribe_by_mode_id, _ := redis.Get(key).Result()
  1784. if len(dialysis_prescribe_by_mode_id) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1785. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and mode_id = ?", patientID, orgID, mode_id).First(&record).Error
  1786. if err != nil {
  1787. if err == gorm.ErrRecordNotFound {
  1788. return nil, nil
  1789. } else {
  1790. return nil, err
  1791. }
  1792. } else {
  1793. if record.ID > 0 {
  1794. //缓存数据
  1795. dialysis_prescribe_by_mode_str, err := json.Marshal(record)
  1796. if err == nil {
  1797. redis.Set(key, dialysis_prescribe_by_mode_str, time.Second*60*60*18)
  1798. return nil, err
  1799. }
  1800. } else {
  1801. redis.Set(key, " ", time.Second*60*60*18)
  1802. return nil, err
  1803. }
  1804. return &record, nil
  1805. }
  1806. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1807. json.Unmarshal([]byte(dialysis_prescribe_by_mode_id), &record)
  1808. return &record, nil
  1809. }
  1810. }
  1811. //func MobileGetLastDialysisPrescribeByModeId(orgID int64, patientID int64, recordDate int64,mode_id int64) (*models.DialysisPrescription, error) {
  1812. // var record models.DialysisPrescription
  1813. // redis := RedisClient()
  1814. // defer redis.Close()
  1815. //
  1816. // // cur_date := time.Now().Format("2006-01-02")
  1817. // key := strconv.FormatInt(orgID, 10) + ":"+ strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_last"
  1818. // dialysis_prescribe_last_str, _ := redis.Get(key).Result()
  1819. //
  1820. // if len(dialysis_prescribe_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1821. // err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 AND mode_id = ? AND record_date < ?", patientID, orgID, mode_id,recordDate).Last(&record).Error
  1822. // if err != nil {
  1823. // if err == gorm.ErrRecordNotFound {
  1824. // return nil, nil
  1825. // } else {
  1826. // return nil, err
  1827. // }
  1828. // } else {
  1829. // if record.ID > 0 {
  1830. // //缓存数据
  1831. // dialysis_prescribe_last_str, err := json.Marshal(record)
  1832. // if err == nil {
  1833. // redis.Set(key, dialysis_prescribe_last_str, time.Second*60*60*18)
  1834. // }
  1835. // } else {
  1836. // redis.Set(key, " ", time.Second*60*60*18)
  1837. // }
  1838. // return &record, nil
  1839. // }
  1840. // } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1841. // json.Unmarshal([]byte(dialysis_prescribe_last_str), &record)
  1842. // return &record, nil
  1843. // }
  1844. //}
  1845. func GetAllAvaildDeviceNumbers(orgID int64, record_date int64, schedule_type int) ([]*DeviceNumberViewModel, error) {
  1846. var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
  1847. 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()
  1848. defer rows.Close()
  1849. if err != nil {
  1850. return nil, err
  1851. }
  1852. for rows.Next() {
  1853. var vm DeviceNumberViewModel
  1854. readDb.ScanRows(rows, &vm)
  1855. vms = append(vms, &vm)
  1856. }
  1857. return vms, nil
  1858. }
  1859. // 获取 maxDate 之前一次的透前评估记录
  1860. func GetLastTimePredialysisEvaluation(orgID int64, patientID int64, maxDate int64) (*models.PredialysisEvaluation, error) {
  1861. var record models.PredialysisEvaluation
  1862. 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
  1863. if err != nil {
  1864. if err == gorm.ErrRecordNotFound {
  1865. return nil, nil
  1866. } else {
  1867. return nil, err
  1868. }
  1869. }
  1870. return &record, nil
  1871. }
  1872. func GetLastTimeOrder(orgID int64, patientID int64, maxDate int64) (*models.DialysisOrder, error) {
  1873. var record models.DialysisOrder
  1874. 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
  1875. if err != nil {
  1876. if err == gorm.ErrRecordNotFound {
  1877. return nil, nil
  1878. } else {
  1879. return nil, err
  1880. }
  1881. }
  1882. return &record, nil
  1883. }
  1884. func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*models.MonitoringRecord, error) {
  1885. var record models.MonitoringRecord
  1886. 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
  1887. if err != nil {
  1888. if err == gorm.ErrRecordNotFound {
  1889. return nil, nil
  1890. } else {
  1891. return nil, err
  1892. }
  1893. }
  1894. return &record, nil
  1895. }
  1896. // 获取 maxDate 之前一次的透后评估记录
  1897. func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
  1898. var record models.AssessmentAfterDislysis
  1899. 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
  1900. if err != nil {
  1901. if err == gorm.ErrRecordNotFound {
  1902. return nil, nil
  1903. } else {
  1904. return nil, err
  1905. }
  1906. }
  1907. return &record, nil
  1908. }
  1909. // 透析处方
  1910. func GetDialysisPrescribe(orgID int64, patientID int64, recordDate int64) (*models.DialysisPrescription, error) {
  1911. var record models.DialysisPrescription
  1912. err := readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientID, orgID, recordDate).First(&record).Error
  1913. if err != nil {
  1914. if err == gorm.ErrRecordNotFound {
  1915. return nil, nil
  1916. } else {
  1917. return nil, err
  1918. }
  1919. }
  1920. return &record, nil
  1921. }
  1922. // 透析方案
  1923. func GetDialysisSolution(orgID int64, patientID int64, mode_id int64) (*models.DialysisSolution, error) {
  1924. var record models.DialysisSolution
  1925. 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
  1926. if err != nil {
  1927. if err == gorm.ErrRecordNotFound {
  1928. return nil, nil
  1929. } else {
  1930. return nil, err
  1931. }
  1932. }
  1933. return &record, nil
  1934. }
  1935. func GetDialysisSolutionOne(orgID int64, mode_id int64) (*models.DialysisSolution, error) {
  1936. var record models.DialysisSolution
  1937. err := readDb.Model(&models.DialysisSolution{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  1938. if err != nil {
  1939. if err == gorm.ErrRecordNotFound {
  1940. return nil, nil
  1941. } else {
  1942. return nil, err
  1943. }
  1944. }
  1945. return &record, nil
  1946. }
  1947. func GetLastDialysisPrescribeByModeId(orgID int64, patientID int64, mode_id int64) (*models.DialysisPrescription, error) {
  1948. var record models.DialysisPrescription
  1949. 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
  1950. if err != nil {
  1951. if err == gorm.ErrRecordNotFound {
  1952. return nil, nil
  1953. } else {
  1954. return nil, err
  1955. }
  1956. }
  1957. return &record, nil
  1958. }
  1959. func GetLastDryWeight(orgID int64, patientID int64) (*models.SgjPatientDryweight, error) {
  1960. var record models.SgjPatientDryweight
  1961. err := readDb.Model(&models.SgjPatientDryweight{}).Where("patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).Last(&record).Error
  1962. if err != nil {
  1963. if err == gorm.ErrRecordNotFound {
  1964. return nil, nil
  1965. } else {
  1966. return nil, err
  1967. }
  1968. }
  1969. return &record, nil
  1970. }
  1971. func MobileGetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  1972. var record models.SystemPrescription
  1973. redis := RedisClient()
  1974. defer redis.Close()
  1975. // cur_date := time.Now().Format("2006-01-02")
  1976. key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  1977. system_dialysis_prescribe_str, _ := redis.Get(key).Result()
  1978. if len(system_dialysis_prescribe_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1979. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).First(&record).Error
  1980. if err != nil {
  1981. if err == gorm.ErrRecordNotFound {
  1982. return nil, nil
  1983. } else {
  1984. return nil, err
  1985. }
  1986. } else {
  1987. if record.ID > 0 {
  1988. //缓存数据
  1989. system_dialysis_prescribe_str, err := json.Marshal(record)
  1990. if err == nil {
  1991. redis.Set(key, system_dialysis_prescribe_str, time.Second*60*60*18)
  1992. }
  1993. } else {
  1994. redis.Set(key, " ", time.Second*60*60*18)
  1995. }
  1996. return &record, nil
  1997. }
  1998. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1999. json.Unmarshal([]byte(system_dialysis_prescribe_str), &record)
  2000. return &record, nil
  2001. }
  2002. }
  2003. func GetSystemDialysisPrescribeByModeId(orgID int64, mode_id int64) (*models.SystemPrescription, error) {
  2004. var record models.SystemPrescription
  2005. err := readDb.Model(&models.SystemPrescription{}).Where("user_org_id = ? and status = 1 AND mode_id = ?", orgID, mode_id).Last(&record).Error
  2006. if err != nil {
  2007. if err == gorm.ErrRecordNotFound {
  2008. return nil, nil
  2009. } else {
  2010. return nil, err
  2011. }
  2012. }
  2013. return &record, nil
  2014. }
  2015. func GetDialysisOrderCount(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
  2016. 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
  2017. return
  2018. }
  2019. func GetFirstDateOfMonth(d time.Time) time.Time {
  2020. d = d.AddDate(0, 0, -d.Day()+1)
  2021. return GetZeroTime(d)
  2022. }
  2023. func GetZeroTime(d time.Time) time.Time {
  2024. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  2025. }
  2026. func GetDialysisCountByPatientId(startime int64, endtime int64, patientid int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  2027. db := XTReadDB().Table("xt_dialysis_order as o")
  2028. 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
  2029. return order, err
  2030. }
  2031. func FindConsumablesByDate(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2032. 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
  2033. return
  2034. }
  2035. func FindConsumablesByDateTwo(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error) {
  2036. 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
  2037. return
  2038. }
  2039. func FindConsumablesByDateThree(orgID int64, patient_id int64, recordDate int64) (consumables []*models.BloodAutomaticReduceDetail, err error) {
  2040. 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
  2041. return
  2042. }
  2043. //func FindLastConsumables(orgID int64, patient_id int64, recordDate int64) (consumables []*models.DialysisBeforePrepare, err error){
  2044. // 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
  2045. // return
  2046. //}
  2047. //
  2048. func GetLastTimeConsumables(orgID int64, patientID int64, maxDate int64) (prepare []*models.DialysisBeforePrepare, err error) {
  2049. 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
  2050. return
  2051. }
  2052. type GoodsType struct {
  2053. ID int64 `gorm:"column:id" json:"id"`
  2054. TypeName string `gorm:"column:type_name" json:"type_name"`
  2055. Remark string `gorm:"column:remark" json:"remark"`
  2056. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2057. Status int64 `gorm:"column:status" json:"status"`
  2058. Type int64 `gorm:"column:type" json:"type"`
  2059. }
  2060. func (GoodsType) TableName() string {
  2061. return "xt_goods_type"
  2062. }
  2063. type VMGoodInfo struct {
  2064. ID int64 `gorm:"column:id" json:"id"`
  2065. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  2066. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2067. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2068. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  2069. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  2070. Total float64 `gorm:"column:total" json:"total" form:"total"`
  2071. }
  2072. func (VMGoodInfo) TableName() string {
  2073. return "xt_good_information"
  2074. }
  2075. type AutomaticReduceDetail struct {
  2076. ID int64 `gorm:"column:id" json:"id"`
  2077. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2078. Status int64 `gorm:"column:status" json:"status"`
  2079. RecordTime int64 `gorm:"column:record_time" json:"record_time"`
  2080. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2081. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2082. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2083. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2084. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2085. Count int64 `gorm:"column:count" json:"count"`
  2086. }
  2087. func (AutomaticReduceDetail) TableName() string {
  2088. return "xt_automatic_reduce_detail"
  2089. }
  2090. type DialysisBeforePrepare struct {
  2091. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2092. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2093. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2094. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2095. GoodId int64 `gorm:"column:good_id" json:"good_id" form:"good_id"`
  2096. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id" form:"good_type_id"`
  2097. Count int64 `gorm:"column:count" json:"count" form:"count"`
  2098. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  2099. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  2100. Creater int64 `gorm:"column:creater" json:"creater" form:"creater"`
  2101. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  2102. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
  2103. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
  2104. }
  2105. func (DialysisBeforePrepare) TableName() string {
  2106. return "dialysis_before_prepare"
  2107. }
  2108. type MDialysisGoodsVM struct {
  2109. ID int64 `gorm:"column:id" json:"id"`
  2110. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2111. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2112. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2113. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2114. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2115. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2116. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
  2117. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2118. Status int64 `gorm:"column:status" json:"status"`
  2119. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2120. SchedualPatient *MSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
  2121. AutomaticReduceDetail []*AutomaticReduceDetail `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"good_user"`
  2122. LastAutomaticReduceDetail []*AutomaticReduceDetail `gorm:"-" json:"last_good_user"`
  2123. DialysisBeforePrepare []*DialysisBeforePrepare `gorm:"ForeignKey:PatientId,ScheduleDate;AssociationForeignKey:PatientId,RecordDate" json:"good_user_detail"`
  2124. LastDialysisBeforePrepare []*DialysisBeforePrepare `gorm:"-" json:"last_good_user_detail"`
  2125. Project []*models.HisPrescriptionProject `gorm:"-" json:"project"`
  2126. }
  2127. func (MDialysisGoodsVM) TableName() string {
  2128. return "xt_schedule"
  2129. }
  2130. type VMWarehouseOutInfo struct {
  2131. ID int64 `gorm:"column:id" json:"id"`
  2132. WarehouseOutId int64 `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
  2133. GoodId int64 `gorm:"column:good_id" json:"good_id"`
  2134. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  2135. Count int64 `gorm:"column:count" json:"count"`
  2136. Price float64 `gorm:"column:price" json:"price"`
  2137. TotalPrice float64 `gorm:"column:total_price" json:"total_price"`
  2138. Status int64 `gorm:"column:status" json:"status"`
  2139. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  2140. WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
  2141. GoodInfo VMGoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_info"`
  2142. GoodsType GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"good_type"`
  2143. IsSys int64 `gorm:"column:is_sys" json:"is_sys"`
  2144. SysRecordTime int64 `gorm:"column:sys_record_time" json:"sys_record_time"`
  2145. Mtime int64 `gorm:"column:mtime" json:"mtime"`
  2146. Ctime int64 `gorm:"column:ctime" json:"ctime"`
  2147. }
  2148. func (VMWarehouseOutInfo) TableName() string {
  2149. return "xt_warehouse_out_info"
  2150. }
  2151. type DialysisGoodsDate struct {
  2152. RecordDate int64
  2153. }
  2154. type DialysisGoodsDetailDate struct {
  2155. RecordTime int64
  2156. }
  2157. 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) {
  2158. var vms []*MDialysisGoodsVM
  2159. var total int64
  2160. db := readDb.
  2161. Table("xt_schedule as sch").
  2162. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2163. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2164. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2165. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2166. 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)
  2167. }).
  2168. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2169. 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")
  2170. }).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
  2171. if scheduleDate != 0 {
  2172. db = db.Where("schedule_date = ?", scheduleDate)
  2173. }
  2174. if schedule_type != 0 {
  2175. db = db.Where("schedule_type = ?", schedule_type)
  2176. }
  2177. if partition_id != 0 {
  2178. db = db.Where("partition_id = ?", partition_id)
  2179. }
  2180. if patient_id != 0 {
  2181. db = db.Where("patient_id = ?", patient_id)
  2182. }
  2183. //db = db.Count(&total)
  2184. //offset := (page - 1) * limit
  2185. //
  2186. //db = db.Offset(offset).Limit(limit)
  2187. err := db.Find(&vms).Error
  2188. return vms, err, total
  2189. }
  2190. func GetLastDialysisGoods(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2191. var Id []*DialysisGoodsDetailDate
  2192. 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
  2193. if len(Id) > 0 {
  2194. 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
  2195. }
  2196. return
  2197. }
  2198. func GetLastDialysisBeforePrepare(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2199. var Id []*DialysisGoodsDate
  2200. 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
  2201. if len(Id) > 0 {
  2202. 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
  2203. }
  2204. return
  2205. }
  2206. func MobileGetGoodsStatistics(orgID int64, start_time int64, end_time int64) (list []*models.StockInfo, err error) {
  2207. db := readDb.Model(&models.StockInfo{})
  2208. db = db.Where("xt_good_information.org_id = ? AND xt_good_information.status = 1", orgID)
  2209. 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")
  2210. db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
  2211. 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)
  2212. })
  2213. db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgID)
  2214. err = db.Order("ctime desc").Find(&list).Error
  2215. return
  2216. }
  2217. 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) {
  2218. var vms []*MDialysisGoodsVM
  2219. var total int64
  2220. db := readDb.
  2221. Model(&models.Schedule{}).
  2222. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2223. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2224. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2225. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  2226. 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)
  2227. }).
  2228. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  2229. 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)
  2230. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  2231. if scheduleDate != 0 {
  2232. db = db.Where("schedule_date = ?", scheduleDate)
  2233. }
  2234. if patient_id != 0 {
  2235. db = db.Where("patient_id = ?", patient_id)
  2236. }
  2237. if len(keywords) != 0 {
  2238. keywords = "%" + keywords + "%"
  2239. 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)
  2240. } else {
  2241. if schedule_type != 0 {
  2242. db = db.Where("schedule_type = ?", schedule_type)
  2243. }
  2244. if partition_id != 0 {
  2245. db = db.Where("partition_id = ?", partition_id)
  2246. }
  2247. db = db.Count(&total)
  2248. offset := (page - 1) * limit
  2249. db = db.Offset(offset).Limit(limit)
  2250. }
  2251. err := db.Find(&vms).Error
  2252. return vms, err, total
  2253. }
  2254. func GetLastDialysisGoodsTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*AutomaticReduceDetail, err error) {
  2255. var Id []*DialysisGoodsDetailDate
  2256. 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
  2257. if len(Id) > 0 {
  2258. 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
  2259. }
  2260. return
  2261. }
  2262. func GetLastDialysisBeforePrepareTwo(patient_id int64, orgID int64, record_time int64) (goodUser []*DialysisBeforePrepare, err error) {
  2263. var Id []*DialysisGoodsDate
  2264. 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
  2265. if len(Id) > 0 {
  2266. 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
  2267. }
  2268. return
  2269. }
  2270. func GetAssessmentBefor(orgid int64, patientid int64, recorddate int64) (*models.PredialysisEvaluation, error) {
  2271. evaluation := models.PredialysisEvaluation{}
  2272. err := XTReadDB().Model(&evaluation).Where("user_org_id = ? and patient_id = ? and assessment_date = ? and status = 1", orgid, patientid, recorddate).Find(&evaluation).Error
  2273. if err == gorm.ErrRecordNotFound {
  2274. return nil, err
  2275. }
  2276. if err != nil {
  2277. return nil, err
  2278. }
  2279. return &evaluation, nil
  2280. }
  2281. func GetAllHisDoctorAdvice(orgid int64, patientid int64, recorddate int64) (his []*models.HisDoctorAdviceInfo, err error) {
  2282. redis := RedisClient()
  2283. defer redis.Close()
  2284. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientid, 10) + ":" + strconv.FormatInt(recorddate, 10) + ":his_doctor_advice"
  2285. his_doctor_advice_str, _ := redis.Get(key).Result()
  2286. if len(his_doctor_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  2287. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ?", patientid, orgid, recorddate).Find(&his).Error
  2288. if err != nil {
  2289. if err == gorm.ErrRecordNotFound {
  2290. return his, nil
  2291. } else {
  2292. return his, err
  2293. }
  2294. } else {
  2295. if len(his) > 0 {
  2296. //缓存数据
  2297. his_doctor_advice_str, err := json.Marshal(his)
  2298. if err == nil {
  2299. redis.Set(key, his_doctor_advice_str, time.Second*60*60*18)
  2300. }
  2301. } else {
  2302. redis.Set(key, " ", time.Second*60*60*18)
  2303. }
  2304. return his, nil
  2305. }
  2306. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  2307. json.Unmarshal([]byte(his_doctor_advice_str), &his)
  2308. return his, nil
  2309. }
  2310. }
  2311. func GetLastDialysisPrescriptionByPatientId(orgid int64, patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
  2312. prescription := models.DialysisPrescription{}
  2313. err := readDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? and patient_id = ? and record_date = ? and status = 1", orgid, patientid, recorddate).Find(&prescription).Error
  2314. if err == gorm.ErrRecordNotFound {
  2315. return nil, err
  2316. }
  2317. if err != nil {
  2318. return nil, err
  2319. }
  2320. return &prescription, nil
  2321. }
  2322. type HisMScheduleDoctorAdviceVM struct {
  2323. ID int64 `gorm:"column:id" json:"id"`
  2324. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2325. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2326. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2327. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2328. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2329. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2330. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2331. Status int64 `gorm:"column:status" json:"status"`
  2332. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2333. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2334. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2335. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2336. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2337. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2338. }
  2339. func (HisMScheduleDoctorAdviceVM) TableName() string {
  2340. return "xt_schedule"
  2341. }
  2342. type HisMScheduleDoctorAdviceVMOne struct {
  2343. ID int64 `gorm:"column:id" json:"id"`
  2344. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2345. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2346. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2347. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2348. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2349. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2350. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2351. Status int64 `gorm:"column:status" json:"status"`
  2352. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2353. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2354. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2355. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2356. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"doctor_advice"`
  2357. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2358. }
  2359. func (HisMScheduleDoctorAdviceVMOne) TableName() string {
  2360. return "xt_schedule"
  2361. }
  2362. type HisMScheduleProjectVM struct {
  2363. ID int64 `gorm:"column:id" json:"id"`
  2364. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  2365. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  2366. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  2367. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  2368. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  2369. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  2370. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  2371. Status int64 `gorm:"column:status" json:"status"`
  2372. DialysisOrder *MDialysisOrderVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  2373. SchedualPatient *MSchedualPatientVM `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  2374. DeviceNumber *MDeviceNumberVM `gorm:"ForeignKey:BedId" json:"device_number"`
  2375. Prescription *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  2376. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
  2377. }
  2378. func (HisMScheduleProjectVM) TableName() string {
  2379. return "xt_schedule"
  2380. }
  2381. func GetHisDoctorConfig(orgid int64) (models.XtHisConfig, error) {
  2382. config := models.XtHisConfig{}
  2383. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  2384. return config, err
  2385. }
  2386. func GetHisDoctorPatientById(orgid int64, patientid int64, recordtime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  2387. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1")
  2388. if orgid > 0 {
  2389. db = db.Where("x.user_org_id = ?", orgid)
  2390. }
  2391. if patientid > 0 {
  2392. db = db.Where("x.patient_id =?", patientid)
  2393. }
  2394. if recordtime > 0 {
  2395. db = db.Where("x.advice_date = ?", recordtime)
  2396. }
  2397. 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
  2398. return advice, err
  2399. }
  2400. func GetDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2401. db := XTReadDB().Table("xt_doctor_advice as x").Where("x.status = 1 and x.advice_type =2")
  2402. if startime > 0 {
  2403. db = db.Where("x.advice_date >= ?", startime)
  2404. }
  2405. if endtime > 0 {
  2406. db = db.Where("x.advice_date<=?", endtime)
  2407. }
  2408. if orgid > 0 {
  2409. db = db.Where("x.user_org_id = ?", orgid)
  2410. }
  2411. if len(deliveway) > 0 {
  2412. db = db.Where("x.delivery_way = ?", deliveway)
  2413. }
  2414. 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
  2415. return advice, err
  2416. }
  2417. func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, orgid int64) (advice []*models.BloodDoctorAdvice, err error) {
  2418. db := XTReadDB().Table("his_doctor_advice_info as x").Where("x.status = 1 and x.advice_type =2")
  2419. if startime > 0 {
  2420. db = db.Where("x.advice_date >= ?", startime)
  2421. }
  2422. if endtime > 0 {
  2423. db = db.Where("x.advice_date<=?", endtime)
  2424. }
  2425. if orgid > 0 {
  2426. db = db.Where("x.user_org_id = ?", orgid)
  2427. }
  2428. if len(deliveway) > 0 {
  2429. db = db.Where("x.delivery_way = ?", deliveway)
  2430. }
  2431. 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
  2432. return advice, err
  2433. }
  2434. func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64) ([]*MScheduleDoctorAdviceVM, error) {
  2435. var vms []*MScheduleDoctorAdviceVM
  2436. adviceWhere := ""
  2437. adviceCondition := []interface{}{}
  2438. if adviceType == 0 {
  2439. if patientType == 0 {
  2440. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
  2441. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2442. } else if patientType == 1 {
  2443. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
  2444. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  2445. } else if patientType == 2 {
  2446. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
  2447. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2448. }
  2449. } else if adviceType == 1 {
  2450. if patientType == 0 {
  2451. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? "
  2452. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2453. } else if patientType == 1 {
  2454. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
  2455. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  2456. } else if patientType == 2 {
  2457. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
  2458. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2459. }
  2460. } else if adviceType == 3 {
  2461. if patientType == 0 {
  2462. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? "
  2463. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2464. } else if patientType == 1 {
  2465. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
  2466. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  2467. } else if patientType == 2 {
  2468. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND execution_staff = 0"
  2469. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2470. }
  2471. } else if adviceType == 2 && len(deliverWay) > 0 {
  2472. if patientType == 0 {
  2473. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
  2474. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  2475. } else if patientType == 1 {
  2476. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and delivery_way = ? "
  2477. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
  2478. } else if patientType == 2 {
  2479. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0 and delivery_way = ?"
  2480. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
  2481. }
  2482. } else if adviceType == 2 && len(deliverWay) <= 0 {
  2483. if patientType == 0 {
  2484. adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
  2485. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2486. } else if patientType == 1 {
  2487. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
  2488. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
  2489. } else if patientType == 2 {
  2490. adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND execution_staff = 0"
  2491. adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
  2492. }
  2493. }
  2494. db := readDb.Table("xt_schedule")
  2495. if scheduleType > 0 {
  2496. db = db.Where("schedule_type = ?", scheduleType)
  2497. }
  2498. if partitonType > 0 {
  2499. db = db.Where("partition_id = ?", partitonType)
  2500. }
  2501. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2502. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  2503. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  2504. }).
  2505. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2506. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2507. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  2508. Preload("DialysisAssesmentBefor", "status =1 AND user_org_id = ? and assessment_date =?", orgID, scheduleDate).
  2509. Preload("DoctorAdvices", adviceCondition...).
  2510. Where("status = 1 AND user_org_id = ?", orgID)
  2511. if scheduleDate != 0 {
  2512. db = db.Where("schedule_date = ?", scheduleDate)
  2513. }
  2514. err := db.Find(&vms).Error
  2515. return vms, err
  2516. }
  2517. func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64) ([]*HisMScheduleDoctorAdviceVM, error) {
  2518. var vms []*HisMScheduleDoctorAdviceVM
  2519. if len(deliverWay) > 0 {
  2520. db := readDb.Table("xt_schedule")
  2521. if scheduleType > 0 {
  2522. db = db.Where("schedule_type = ?", scheduleType)
  2523. }
  2524. if partitionType > 0 {
  2525. db = db.Where("partition_id = ?", partitionType)
  2526. }
  2527. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2528. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2529. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2530. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  2531. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
  2532. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  2533. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  2534. }).
  2535. Where("status = 1 AND user_org_id = ?", orgID)
  2536. if scheduleDate != 0 {
  2537. db = db.Where("schedule_date = ?", scheduleDate)
  2538. }
  2539. err = db.Find(&vms).Error
  2540. } else {
  2541. db := readDb.Table("xt_schedule")
  2542. if scheduleType > 0 {
  2543. db = db.Where("schedule_type = ?", scheduleType)
  2544. }
  2545. if partitionType > 0 {
  2546. db = db.Where("partition_id = ?", partitionType)
  2547. }
  2548. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2549. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2550. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2551. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  2552. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
  2553. Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  2554. return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  2555. }).
  2556. Where("status = 1 AND user_org_id = ?", orgID)
  2557. if scheduleDate != 0 {
  2558. db = db.Where("schedule_date = ?", scheduleDate)
  2559. }
  2560. err = db.Find(&vms).Error
  2561. }
  2562. return vms, err
  2563. }
  2564. func BatchDeleteMonitor(ids []string) (err error) {
  2565. if len(ids) == 1 {
  2566. err = XTWriteDB().Model(&models.MonitoringRecord{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  2567. } else {
  2568. err = XTWriteDB().Model(models.MonitoringRecord{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  2569. }
  2570. return
  2571. }
  2572. func GetPatientDialysisRecordList(patientid int64, startime int64, endtime int64) (order []*models.XtDialysisOrders, err error) {
  2573. db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
  2574. //table := XTReadDB().Table("xt_schedule as s")
  2575. //fmt.Println(table)
  2576. if patientid > 0 {
  2577. db = db.Where("x.patient_id = ?", patientid)
  2578. }
  2579. if startime > 0 {
  2580. db = db.Where("x.dialysis_date>=?", startime)
  2581. }
  2582. if endtime > 0 {
  2583. db = db.Where("x.dialysis_date <= ?", endtime)
  2584. }
  2585. 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
  2586. return order, err
  2587. }
  2588. func BatchDeleteAdvice(ids []string) (err error) {
  2589. if len(ids) == 1 {
  2590. err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("id=?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  2591. } else {
  2592. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  2593. }
  2594. return
  2595. }
  2596. func BatchDeleteHisAdvice(ids []string) (err error) {
  2597. if len(ids) == 1 {
  2598. err = XTWriteDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", ids[0]).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  2599. } else {
  2600. err = XTWriteDB().Model(models.HisDoctorAdviceInfo{}).Where("id IN(?)", ids).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  2601. }
  2602. return
  2603. }
  2604. func UpdateAutoReduceDetail(good_id int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
  2605. detail := models.AutomaticReduceDetail{}
  2606. 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
  2607. return detail, err
  2608. }
  2609. func DeleteAutoReduceDetail(good_id int64, record_time int64, patient_id int64) error {
  2610. detail := models.AutomaticReduceDetail{}
  2611. 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
  2612. return err
  2613. }
  2614. func DeleteDialysisBeforOne(good_id int64, record_time int64, patient_id int64) error {
  2615. detail := models.DialysisBeforePrepare{}
  2616. 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
  2617. return err
  2618. }
  2619. func BatchAdviceCheck(ids []string, creator int64) error {
  2620. advice := models.XtDoctorAdvice{}
  2621. 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
  2622. return err
  2623. }
  2624. func BatchHisAdviceCheck(ids []string, creator int64) error {
  2625. advice := models.HisDoctorAdviceInfo{}
  2626. 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
  2627. return err
  2628. }
  2629. func BatchAdviceExecution(ids []string, creator int64, execution_state int64) error {
  2630. advice := models.XtDoctorAdvice{}
  2631. 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
  2632. return err
  2633. }
  2634. func BatchHisAdviceExecution(ids []string, creator int64, execution_state int64) error {
  2635. advice := models.HisDoctorAdviceInfo{}
  2636. 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
  2637. return err
  2638. }
  2639. func GetAdviceExecutionById(ids []string) (doctor []*models.XtDoctorAdvice, err error) {
  2640. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  2641. return doctor, err
  2642. }
  2643. func GetHisAdviceExecutionById(ids []string) (doctor []*models.HisDoctorAdviceInfo, err error) {
  2644. err = XTReadDB().Model(&doctor).Where("id IN(?) AND status = 1", ids).Find(&doctor).Error
  2645. return doctor, err
  2646. }
  2647. func GetHisProjectConfig(orgid int64) (models.XtHisProjectConfig, error) {
  2648. config := models.XtHisProjectConfig{}
  2649. err := XTReadDB().Model(&config).Where("user_org_id = ? and status =1", orgid).Find(&config).Error
  2650. return config, err
  2651. }
  2652. func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64) (project []*models.HisPrescriptionProject, err error) {
  2653. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  2654. return db.Preload("GoodsType", "status = 1").Where("status = 1 ")
  2655. }).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
  2656. return
  2657. }
  2658. func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
  2659. var vms []*HisMScheduleProjectVM
  2660. //if patientType == 0 {
  2661. // db := readDb.
  2662. // Table("xt_schedule").
  2663. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2664. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  2665. // return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  2666. // }).
  2667. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2668. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2669. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  2670. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2671. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  2672. // }).Where("status = 1 AND user_org_id = ?", orgID)
  2673. // if scheduleDate != 0 {
  2674. // db = db.Where("schedule_date = ?", scheduleDate)
  2675. // }
  2676. // err = db.Find(&vms).Error
  2677. //}
  2678. //
  2679. //if patientType > 0 {
  2680. // db := readDb.
  2681. // Table("xt_schedule").
  2682. // Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  2683. // Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
  2684. // return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
  2685. // }).
  2686. // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  2687. // Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  2688. // Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
  2689. // Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
  2690. // Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2691. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
  2692. // }).
  2693. // Where("status = 1 AND user_org_id = ?", orgID)
  2694. // if scheduleDate != 0 {
  2695. // db = db.Where("schedule_date = ?", scheduleDate)
  2696. // }
  2697. // err = db.Find(&vms).Error
  2698. //}
  2699. db := readDb.Table("xt_schedule").Where("status = 1")
  2700. if scheduleDate > 0 {
  2701. db = db.Where("schedule_date = ?", scheduleDate)
  2702. }
  2703. if orgID > 0 {
  2704. db = db.Where("user_org_id = ?", orgID)
  2705. }
  2706. err = db.Find(&vms).Error
  2707. return vms, err
  2708. }
  2709. func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  2710. prepare := models.DialysisBeforePrepare{}
  2711. 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
  2712. return err
  2713. }
  2714. func UPdateAutoStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
  2715. detail := models.AutomaticReduceDetail{}
  2716. 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
  2717. return err
  2718. }