mobile_dialysis_service.go 170KB

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