dialysis_api_controller.go 175KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "XT_New/enums"
  11. "XT_New/models"
  12. "XT_New/service"
  13. "XT_New/utils"
  14. "github.com/astaxie/beego"
  15. "math"
  16. "net/http"
  17. "net/url"
  18. )
  19. // type DialysisTestAPIController struct {
  20. // MobileBaseAPIController
  21. // }
  22. // [get]/m/api/test
  23. // func (this *DialysisTestAPIController) Test() {
  24. // orgID := int64(3907)
  25. // now := time.Now()
  26. // nextWeek := now.AddDate(0, 0, 7)
  27. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  28. // nextTwoWeek := now.AddDate(0, 0, 14)
  29. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  30. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  31. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  32. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  33. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  34. // return
  35. // }
  36. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  37. // if exchangeErr != nil {
  38. // this.ErrorLog("%v", exchangeErr)
  39. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  40. // return
  41. // }
  42. // this.ServeSuccessJSON(map[string]interface{}{
  43. // // "now": now,
  44. // // "next_week": nextWeek,f
  45. // // "next_week_mon": nextWeekMon,
  46. // // "next_week_sun": nextWeekSun,
  47. // // "next_two_week_mon": nextTwoWeekMon,
  48. // // "next_two_week_sun": nextTwoWeekSun,
  49. // "next_week_schs": nextWeekSchs,
  50. // "next_two_week_schs": nextTwoWeekSchs,
  51. // })
  52. // }
  53. type DialysisAPIController struct {
  54. MobileBaseAPIAuthController
  55. }
  56. // /m/api/scheduals [get]
  57. // @param type:int
  58. // @param date:string
  59. func (this *DialysisAPIController) Scheduals() {
  60. schedualType, _ := this.GetInt64("type")
  61. schedualDate := this.GetString("date")
  62. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  63. schedualType = 0
  64. }
  65. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  66. if parseDateErr != nil {
  67. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  68. return
  69. }
  70. adminInfo := this.GetMobileAdminUserInfo()
  71. orgID := adminInfo.Org.Id
  72. redis := service.RedisClient()
  73. defer redis.Close()
  74. // cur_date := time.Now().Format("2006-01-02")
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. scheduals_json_str, _ := redis.Get(key).Result()
  77. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  78. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  79. if err != nil {
  80. this.ErrorLog("获取排班信息失败:%v", err)
  81. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  82. } else {
  83. if len(scheduals) > 0 {
  84. //缓存数据
  85. scheduals_json, err := json.Marshal(scheduals)
  86. if err == nil {
  87. redis.Set(key, scheduals_json, time.Second*30)
  88. }
  89. }
  90. this.ServeSuccessJSON(map[string]interface{}{
  91. "scheduals": scheduals,
  92. })
  93. }
  94. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  95. var dat []map[string]interface{}
  96. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  97. } else {
  98. }
  99. this.ServeSuccessJSON(map[string]interface{}{
  100. "scheduals": dat,
  101. "redis": "true",
  102. "date": schedualDate,
  103. })
  104. }
  105. }
  106. // /m/api/waiting_scheduals [get]
  107. // @param date:string
  108. func (this *DialysisAPIController) WaitingScheduals() {
  109. schedualDate := this.GetString("date")
  110. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  111. if parseDateErr != nil && len(schedualDate) != 0 {
  112. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  113. return
  114. }
  115. adminInfo := this.GetMobileAdminUserInfo()
  116. orgID := adminInfo.Org.Id
  117. redis := service.RedisClient()
  118. defer redis.Close()
  119. // cur_date := time.Now().Format("2006-01-02")
  120. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  121. wait_scheduals, _ := redis.Get(key).Result()
  122. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  123. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  124. if err != nil {
  125. this.ErrorLog("获取排班信息失败:%v", err)
  126. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  127. } else {
  128. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  129. for _, s := range scheduals {
  130. returnScheduals = append(returnScheduals, s)
  131. }
  132. if len(returnScheduals) > 0 {
  133. //缓存数据
  134. wait_scheduals_json, err := json.Marshal(scheduals)
  135. if err == nil {
  136. redis.Set(key, wait_scheduals_json, time.Second*30)
  137. }
  138. }
  139. this.ServeSuccessJSON(map[string]interface{}{
  140. "scheduals": scheduals,
  141. })
  142. }
  143. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  144. var dat []map[string]interface{}
  145. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  146. } else {
  147. }
  148. this.ServeSuccessJSON(map[string]interface{}{
  149. "scheduals": dat,
  150. "redis": "true",
  151. "date": schedualDate,
  152. })
  153. }
  154. }
  155. //else{
  156. // fmt.Println("33333333")
  157. //
  158. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  159. // if err != nil {
  160. // this.ErrorLog("获取排班信息失败:%v", err)
  161. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  162. // } else {
  163. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  164. // for _, s := range scheduals {
  165. //
  166. // returnScheduals = append(returnScheduals, s)
  167. // }
  168. //
  169. // this.ServeSuccessJSON(map[string]interface{}{
  170. // "scheduals": returnScheduals,
  171. // })
  172. // }
  173. //
  174. // }
  175. //if err == nil{
  176. //
  177. //
  178. //
  179. //
  180. //
  181. //}else{
  182. //}
  183. // /m/api/dialysis/record [get]
  184. // @param patient_id:int
  185. // @param date:string (yyyy-MM-dd)
  186. func (this *DialysisAPIController) DialysisRecord() {
  187. patientID, _ := this.GetInt64("patient_id")
  188. recordDateStr := this.GetString("date")
  189. if patientID <= 0 {
  190. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  191. return
  192. }
  193. if len(recordDateStr) == 0 {
  194. recordDateStr = time.Now().Format("2006-01-02")
  195. }
  196. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  197. if parseDateErr != nil {
  198. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  199. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  200. return
  201. }
  202. adminInfo := this.GetMobileAdminUserInfo()
  203. patient, getPatientErr := service.MobileGetPatientDetail(adminInfo.Org.Id, patientID)
  204. if getPatientErr != nil {
  205. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  206. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  207. return
  208. } else if patient == nil {
  209. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  210. return
  211. }
  212. schedual, getSchedualErr := service.MobileGetSchedualDetail(adminInfo.Org.Id, patientID, date.Unix())
  213. if getSchedualErr != nil {
  214. this.ErrorLog("获取患者排班信息失败:%v", getSchedualErr)
  215. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  216. return
  217. }
  218. receiverTreatmentAccess, getRTARErr := service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  219. if getRTARErr != nil {
  220. this.ErrorLog("获取接诊评估失败:%v", getRTARErr)
  221. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  222. return
  223. }
  224. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  225. if getPEErr != nil {
  226. this.ErrorLog("获取透前评估失败:%v", getPEErr)
  227. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  228. return
  229. }
  230. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  231. if getLPEErr != nil {
  232. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  233. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  234. return
  235. }
  236. doctorAdvices, getDoctorAdvicesErr := service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  237. if getDoctorAdvicesErr != nil {
  238. this.ErrorLog("获取临时医嘱失败:%v", getDoctorAdvicesErr)
  239. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  240. return
  241. }
  242. dialysisOrder, getDialysisOrderErr := service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  243. if getDialysisOrderErr != nil {
  244. this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
  245. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  246. return
  247. }
  248. doubleCheck, getDoubleCheckErr := service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  249. if getDoubleCheckErr != nil {
  250. this.ErrorLog("获取双人核对记录失败:%v", getDoubleCheckErr)
  251. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  252. return
  253. }
  254. monitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  255. if getMonitorRecordsErr != nil {
  256. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  257. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  258. return
  259. }
  260. var lastMonitorRecord *models.MonitoringRecord
  261. lastMonitorRecord, getLastErr := service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  262. if getLastErr != nil {
  263. this.ErrorLog("获取上一次透析的监测记录失败:%v", getLastErr)
  264. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  265. return
  266. }
  267. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  268. if getAADErr != nil {
  269. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  270. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  271. return
  272. }
  273. lastAssessmentAfterDislysis, getLAADErr := service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  274. if getLAADErr != nil {
  275. this.ErrorLog("获取上一次透后评估失败:%v", getLAADErr)
  276. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  277. return
  278. }
  279. treatmentSummary, getTreatmentSummaryErr := service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  280. if getTreatmentSummaryErr != nil {
  281. this.ErrorLog("获取治疗小结失败:%v", getTreatmentSummaryErr)
  282. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  283. return
  284. }
  285. dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  286. //if getDialysisPrescribeErr != nil {
  287. // this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  288. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  289. // return
  290. //}
  291. dialysisSolution, _ := service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  292. //if getDialysisSolutionErr != nil {
  293. // this.ErrorLog("获取透析方案失败:%v", getDialysisSolutionErr)
  294. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  295. // return
  296. //}
  297. lastDialysisPrescribe, _ := service.MobileGetLastDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  298. //fmt.Println("上次透析处方",lastDialysisPrescribe.DialyzerPerfusionApparatus)
  299. //if getDialysisPrescribeErr != nil {
  300. // this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  301. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  302. // return
  303. //}
  304. //获取系统透析处方模版
  305. systemDialysisPrescribe, _ := service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  306. //if getSystemDialysisPrescribeErr != nil {
  307. // this.ErrorLog("获取系统透析处方失败:%v", getSystemDialysisPrescribeErr)
  308. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  309. // return
  310. //}
  311. //dialysisSolution, getDialysisSolutionErr := service.MobileGetDialysisSolution(adminInfo.Org.Id, patientID)
  312. //operators, _ := service.GetAllAdminUserES(adminInfo.Org.Id, adminInfo.App.Id)
  313. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  314. _, is_project_open_config := service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  315. projects, _ := service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  316. stockType, _ := service.GetStockType(adminInfo.Org.Id)
  317. prepare, _ := service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  318. //获取最后一次血管通路
  319. lastAssessment, parseDateErr := service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  320. prescribeOne, parseDateErr := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  321. var his_advices []*models.HisDoctorAdviceInfo
  322. if is_open_config.IsOpen == 1 {
  323. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  324. }
  325. if getLPEErr != nil {
  326. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  327. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  328. return
  329. }
  330. lastDryWeightDislysis, getDryErr := service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  331. if getDryErr != nil {
  332. this.ErrorLog("获取最后一条干体重失败:%v", getDryErr)
  333. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  334. return
  335. }
  336. //headNurses, _ := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminInfo.Org.Id, adminInfo.App.Id, models.SpecialPermissionTypeHeadNurse)
  337. _, gobalConfig := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  338. //goodTypes, _ := service.FindAllGoodTypeByType(1) //查出所有库存配置的系统类型
  339. //goodInfos, _ := service.FindAllGoodInfo(adminInfo.Org.Id) //查出所有库存配置的系统类型
  340. operators, _ := service.GetAllStarfEs(adminInfo.Org.Id)
  341. //consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patientID, date.Unix())
  342. //lastConsumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patientID, date.Unix())
  343. returnData := map[string]interface{}{
  344. "patient": patient,
  345. "schedual": schedual,
  346. "prescription": dialysisPrescribe,
  347. "solution": dialysisSolution,
  348. "last_prescription": lastDialysisPrescribe,
  349. "receiver_treatment_access": receiverTreatmentAccess,
  350. "predialysis_evaluation": predialysisEvaluation,
  351. "doctor_advices": doctorAdvices,
  352. "double_check": doubleCheck,
  353. "assessment_after_dislysis": assessmentAfterDislysis,
  354. "treatment_summary": treatmentSummary,
  355. "monitor_records": monitorRecords,
  356. "dialysis_order": dialysisOrder,
  357. "operators": operators,
  358. "last_predialysis_evaluation": lastPredialysisEvaluation,
  359. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  360. "last_monitor_record": lastMonitorRecord,
  361. "config": gobalConfig,
  362. "dry_weight": lastDryWeightDislysis,
  363. "system_prescription": systemDialysisPrescribe,
  364. "his_advices": his_advices,
  365. "is_open_config": is_open_config,
  366. "stockType": stockType,
  367. "prepare": prepare,
  368. "lastAssessment": lastAssessment,
  369. "prescribeOne": prescribeOne,
  370. "is_project_open_config": is_project_open_config,
  371. "project": projects,
  372. }
  373. this.ServeSuccessJSON(returnData)
  374. }
  375. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  376. adminInfo := c.GetMobileAdminUserInfo()
  377. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  378. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  379. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  380. returnData := map[string]interface{}{
  381. "admin_users": adminUsers,
  382. "devices": devices,
  383. "device_numbers": device_numbers,
  384. }
  385. c.ServeSuccessJSON(returnData)
  386. }
  387. func (c *DialysisAPIController) PostAtreatmentInfo() {
  388. id, _ := c.GetInt64("patient", 0)
  389. recordDateStr := c.GetString("record_date")
  390. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  391. summaryContent := c.GetString("summaryContent")
  392. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  393. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  394. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  395. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  396. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  397. nursingRecord := c.GetString("nursing_record")
  398. fmt.Println("护理记录", nursingRecord)
  399. specialRecord := c.GetString("special_record")
  400. fmt.Println("特殊记录", specialRecord)
  401. adminUserInfo := c.GetMobileAdminUserInfo()
  402. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  403. checkStaffId = adminUserInfo.AdminUser.Id
  404. deboardNurseId = adminUserInfo.AdminUser.Id
  405. treatDoctor = adminUserInfo.AdminUser.Id
  406. if id <= 0 {
  407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  408. return
  409. }
  410. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  411. if patient.ID == 0 {
  412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  413. return
  414. }
  415. if len(recordDateStr) == 0 {
  416. recordDateStr = time.Now().Format("2006-01-02")
  417. }
  418. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  419. if parseDateErr != nil {
  420. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  422. return
  423. }
  424. //now := time.Now()
  425. //year, month, day := now.Date()
  426. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  427. //todayTimeStamp := today_time.Unix()
  428. summary := models.TreatmentSummary{
  429. UserOrgId: adminUserInfo.Org.Id,
  430. PatientId: id,
  431. AssessmentDate: recordDate.Unix(),
  432. Mission: propagandaAndEducationContent,
  433. DialysisSummary: summaryContent,
  434. SjNurse: changeMedicalNurseId,
  435. ZlNurse: treatNurseId,
  436. HdNurse: checkStaffId,
  437. XjNurse: deboardNurseId,
  438. ZlDoctor: treatDoctor,
  439. CreatedTime: time.Now().Unix(),
  440. Status: 1,
  441. NursingRecord: nursingRecord,
  442. SpecialRecord: specialRecord,
  443. }
  444. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  445. if treatmentSummary.ID == 0 { //新增
  446. summary.Creater = adminUserInfo.AdminUser.Id
  447. service.AddSigleSummaryRecord(&summary)
  448. c.ServeSuccessJSON(map[string]interface{}{
  449. "summary": summary,
  450. })
  451. } else { //修改
  452. //if treatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  453. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  454. // if getPermissionErr != nil {
  455. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  456. // return
  457. // } else if headNursePermission == nil {
  458. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  459. // return
  460. // }
  461. //}
  462. summary.Creater = treatmentSummary.Creater
  463. summary.CreatedTime = treatmentSummary.CreatedTime
  464. summary.Modifier = adminUserInfo.AdminUser.Id
  465. summary.ID = treatmentSummary.ID
  466. service.UpdateSummeRecord(&summary)
  467. c.ServeSuccessJSON(map[string]interface{}{
  468. "summary": summary,
  469. })
  470. }
  471. }
  472. func (c *DialysisAPIController) PostDoubleCheck() {
  473. id, _ := c.GetInt64("patient", 0)
  474. recordDateStr := c.GetString("record_date")
  475. checkTimeStr := c.GetString("check_time")
  476. firstCheckTimeStr := c.GetString("first_check_time")
  477. creater, _ := c.GetInt64("creater", 0)
  478. modifier, _ := c.GetInt64("modifier", 0)
  479. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  480. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  481. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  482. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  483. dialysis_item_desc := c.GetString("dialysis_item_desc")
  484. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  485. vascular_access_desc := c.GetString("vascular_access_desc")
  486. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  487. collator, _ := c.GetInt64("collator", 0)
  488. if id <= 0 {
  489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  490. return
  491. }
  492. adminUserInfo := c.GetMobileAdminUserInfo()
  493. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  494. if patient.ID == 0 {
  495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  496. return
  497. }
  498. if len(recordDateStr) == 0 {
  499. recordDateStr = time.Now().Format("2006-01-02")
  500. }
  501. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  502. if parseDateErr != nil {
  503. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  505. return
  506. }
  507. var checkDate int64
  508. if len(checkTimeStr) == 0 {
  509. checkDate = 0
  510. } else {
  511. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  512. checkDate = checkDateUnix.Unix()
  513. }
  514. var firstCheckDate int64
  515. if len(firstCheckTimeStr) == 0 {
  516. firstCheckDate = 0
  517. } else {
  518. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  519. firstCheckDate = firstCheckDateUnix.Unix()
  520. }
  521. //now := time.Now()
  522. //year, month, day := now.Date()
  523. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  524. //todayTimeStamp := today_time.Unix()
  525. doubleCheck := models.DoubleCheck{
  526. UserOrgId: adminUserInfo.Org.Id,
  527. PatientId: id,
  528. DialysisItemCheck: dialysis_item_check,
  529. DialysisParameterCheck: dialysis_parameter_check,
  530. VascularAccessVerification: vascular_access_verification,
  531. PipelineConnectionCheck: pipeline_connection_check,
  532. DialysisItemDesc: dialysis_item_desc,
  533. DialysisParameterDesc: dialysis_parameter_desc,
  534. VascularAccessDesc: vascular_access_desc,
  535. PipelineConnectionDesc: pipeline_connection_desc,
  536. Collator: collator,
  537. Status: 1,
  538. CreatedTime: time.Now().Unix(),
  539. CheckDate: recordDate.Unix(),
  540. UpdatedTime: time.Now().Unix(),
  541. }
  542. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  543. if check.ID == 0 { //新增
  544. doubleCheck.FirstCheckTime = firstCheckDate
  545. doubleCheck.CheckTime = checkDate
  546. doubleCheck.Creater = creater
  547. doubleCheck.Modifier = modifier
  548. err := service.AddSigleDoubleCheck(&doubleCheck)
  549. if err == nil {
  550. c.ServeSuccessJSON(map[string]interface{}{
  551. "doubleCheck": &doubleCheck,
  552. })
  553. }
  554. } else { //修改
  555. doubleCheck.FirstCheckTime = firstCheckDate
  556. doubleCheck.CheckTime = checkDate
  557. doubleCheck.Creater = creater
  558. doubleCheck.Modifier = modifier
  559. doubleCheck.CreatedTime = check.CreatedTime
  560. doubleCheck.ID = check.ID
  561. err := service.UpdateDoubleCheck(&doubleCheck)
  562. if err == nil {
  563. c.ServeSuccessJSON(map[string]interface{}{
  564. "doubleCheck": &doubleCheck,
  565. })
  566. }
  567. }
  568. }
  569. func (c *DialysisAPIController) PostAcceptsAssessment() {
  570. id, _ := c.GetInt64("patient", 0)
  571. recordDateStr := c.GetString("record_date")
  572. way, _ := c.GetInt64("way", 0)
  573. consciousness, _ := c.GetInt64("consciousness", 0)
  574. appetite, _ := c.GetInt64("appetite", 0)
  575. condition, _ := c.GetInt64("condition", 0)
  576. posture, _ := c.GetInt64("posture")
  577. sick_condition, _ := c.GetInt64("sick_condition", 0)
  578. danger_level, _ := c.GetInt64("danger_level", 0)
  579. intake, _ := c.GetInt64("intake", 0)
  580. nutrition, _ := c.GetInt64("nutrition", 0)
  581. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  582. psychological_assessment_other := c.GetString("psychological_assessment_other")
  583. score := c.GetString("score")
  584. sick_condition_other := c.GetString("sick_condition_other")
  585. //precaution, _ := c.GetInt64("precaution", 0)
  586. precaution := c.GetString("precaution")
  587. precaution_other := c.GetString("precaution_other")
  588. psychological_other := c.GetString("psychological_other")
  589. admission_number := c.GetString("admission_number")
  590. if id <= 0 {
  591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  592. return
  593. }
  594. adminUserInfo := c.GetMobileAdminUserInfo()
  595. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  596. if patient.ID == 0 {
  597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  598. return
  599. }
  600. //now := time.Now()
  601. //year, month, day := now.Date()
  602. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  603. //todayTimeStamp := today_time.Unix()
  604. if len(recordDateStr) == 0 {
  605. recordDateStr = time.Now().Format("2006-01-02")
  606. }
  607. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  608. if parseDateErr != nil {
  609. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  611. return
  612. }
  613. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  614. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  615. UserOrgId: adminUserInfo.Org.Id,
  616. PatientId: id,
  617. RecordDate: recordDate.Unix(),
  618. Way: way,
  619. Consciousness: consciousness,
  620. Appetite: appetite,
  621. Condition: condition,
  622. SickCondition: sick_condition,
  623. DangerLevel: danger_level,
  624. Intake: intake,
  625. Nutrition: nutrition,
  626. PsychologicalAssessment: psychological_assessment,
  627. PsychologicalAssessmentOther: psychological_assessment_other,
  628. SickConditionOther: sick_condition_other,
  629. Posture: posture,
  630. CreatedTime: time.Now().Unix(),
  631. UpdateTime: time.Now().Unix(),
  632. Status: 1,
  633. Score: score,
  634. Precaution: precaution,
  635. PrecautionOther: precaution_other,
  636. PsychologicalOther: psychological_other,
  637. AdmissionNumber: admission_number,
  638. }
  639. if receiveTreatment.ID == 0 { //新增
  640. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  641. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  642. if err == nil {
  643. c.ServeSuccessJSON(map[string]interface{}{
  644. "receiveTreatmentAsses": receiveTreatmentAsses,
  645. })
  646. }
  647. } else { //修改
  648. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  649. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  650. // if getPermissionErr != nil {
  651. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  652. // return
  653. // } else if headNursePermission == nil {
  654. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  655. // return
  656. // }
  657. //}
  658. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  659. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  660. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  661. receiveTreatmentAsses.ID = receiveTreatment.ID
  662. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  663. if err == nil {
  664. c.ServeSuccessJSON(map[string]interface{}{
  665. "receiveTreatmentAsses": receiveTreatmentAsses,
  666. })
  667. }
  668. }
  669. }
  670. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  671. id, _ := c.GetInt64("patient", 0)
  672. recordDateStr := c.GetString("record_date")
  673. weightAfter, _ := c.GetFloat("weight_after", 0)
  674. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  675. weightReduce, _ := c.GetFloat("weight_loss", 0)
  676. temperature, _ := c.GetFloat("temperature", 0)
  677. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  678. breathing_rate, _ := c.GetFloat("breathing_rate", 0)
  679. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  680. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  681. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  682. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  683. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  684. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  685. cruor := c.GetString("cruor")
  686. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  687. internalFistula := c.GetString("internal_fistula")
  688. catheter := c.GetString("catheter")
  689. complications := c.GetString("complication")
  690. remark := c.GetString("remark")
  691. dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  692. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  693. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  694. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  695. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  696. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  697. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  698. patientGose, _ := c.GetInt64("patient_gose", 0)
  699. inpatientDepartment := c.GetString("inpatient_department")
  700. observationContent := c.GetString("observation_content")
  701. observationContentOther := c.GetString("observation_content_other")
  702. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  703. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  704. in_advance_reason := c.GetString("in_advance_reason")
  705. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  706. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  707. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  708. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  709. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  710. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  711. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  712. dialyzer, _ := c.GetInt64("dialyzer", 0)
  713. in_advance_reason_other := c.GetString("in_advance_reason_other")
  714. is_eat, _ := c.GetInt64("is_eat", 0)
  715. cvc_a, _ := c.GetFloat("cvc_a", 0)
  716. cvc_v, _ := c.GetFloat("cvc_v", 0)
  717. channels, _ := c.GetInt64("channel", 0)
  718. return_blood, _ := c.GetInt64("return_blood", 0)
  719. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  720. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  721. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  722. blood_flow, _ := c.GetInt64("blood_flow", 0)
  723. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  724. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  725. sealing_fluid_special := c.GetString("sealing_fluid_special")
  726. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  727. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  728. setting_pressure := c.GetString("setting_pressure")
  729. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  730. diastolic_pressure := c.GetString("diastolic_pressure")
  731. other_complication := c.GetString("other_complication")
  732. ktv := c.GetString("ktv")
  733. if id <= 0 {
  734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  735. return
  736. }
  737. adminUserInfo := c.GetMobileAdminUserInfo()
  738. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  739. if patient.ID == 0 {
  740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  741. return
  742. }
  743. if len(recordDateStr) == 0 {
  744. recordDateStr = time.Now().Format("2006-01-02")
  745. }
  746. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  747. if parseDateErr != nil {
  748. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  750. return
  751. }
  752. //now := time.Now()
  753. //year, month, day := now.Date()
  754. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  755. //todayTimeStamp := today_time.Unix()
  756. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  757. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  758. UserOrgId: adminUserInfo.Org.Id,
  759. PatientId: id,
  760. AssessmentDate: recordDate.Unix(),
  761. Temperature: temperature,
  762. PulseFrequency: pulse_frequency,
  763. BreathingRate: breathing_rate,
  764. SystolicBloodPressure: systolic_blood_pressure,
  765. DiastolicBloodPressure: diastolic_blood_pressure,
  766. ActualUltrafiltration: actual_ultrafiltration,
  767. ActualDisplacement: actual_displacement,
  768. ActualTreatmentHour: actualtreatHour,
  769. ActualTreatmentMinute: actualtreatmin,
  770. WeightAfter: weightAfter,
  771. AdditionalWeight: additionalWeight,
  772. WeightLoss: weightReduce,
  773. Cruor: cruor,
  774. SymptomAfterDialysis: symptomsAfterDialysi,
  775. InternalFistula: internalFistula,
  776. Catheter: catheter,
  777. Complication: complications,
  778. DialysisIntakes: dialysateVolume,
  779. CreatedTime: time.Now().Unix(),
  780. Status: 1,
  781. Remark: remark,
  782. BloodAccessPartId: blood_access_part_id,
  783. BloodAccessPartOperaId: blood_access_part_opera_id,
  784. DialysisIntakesUnit: dialysis_intakes_unit,
  785. PuncturePointOozingBlood: puncturePointOozingBlood,
  786. PuncturePointHaematoma: puncturePointHaematoma,
  787. InternalFistulaTremorAc: internalFistulaTremorAc,
  788. PatientGose: patientGose,
  789. InpatientDepartment: inpatientDepartment,
  790. ObservationContent: observationContent,
  791. ObservationContentOther: observationContentOther,
  792. DialysisProcess: dialysis_process,
  793. InAdvanceMinute: in_advance_minute,
  794. InAdvanceReason: in_advance_reason,
  795. HemostasisMinute: hemostasis_minute,
  796. HemostasisOpera: hemostasis_opera,
  797. TremorNoise: tremor_noise,
  798. DisequilibriumSyndrome: disequilibrium_syndrome,
  799. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  800. ArterialTube: arterial_tube,
  801. IntravenousTube: intravenous_tube,
  802. Dialyzer: dialyzer,
  803. InAdvanceReasonOther: in_advance_reason_other,
  804. IsEat: is_eat,
  805. CvcA: cvc_a,
  806. CvcV: cvc_v,
  807. Channel: channels,
  808. ReturnBlood: return_blood,
  809. RehydrationVolume: rehydration_volume,
  810. DialysisDuring: dialysis_during,
  811. StrokeVolume: stroke_volume,
  812. BloodFlow: blood_flow,
  813. SealingFluidDispose: sealing_fluid_dispose,
  814. SealingFluidSpecial: sealing_fluid_special,
  815. DosageOfAnticoagulants: dosage_of_anticoagulants,
  816. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  817. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  818. SettingPressure: setting_pressure,
  819. DiastolicPressure: diastolic_pressure,
  820. OtherComplication: other_complication,
  821. Ktv: ktv,
  822. }
  823. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  824. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  825. if assessmentAfter.ID == 0 { //新增
  826. if appRole.UserType == 2 || appRole.UserType == 1 {
  827. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  828. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  829. } else {
  830. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  831. }
  832. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  833. if err == nil {
  834. c.ServeSuccessJSON(map[string]interface{}{
  835. "assessmentAfterDislysis": assessmentAfterDislysis,
  836. })
  837. }
  838. } else { //修改
  839. if appRole.UserType == 2 || appRole.UserType == 1 {
  840. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  841. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  842. } else {
  843. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  844. if assessmentAfterDislysis.Creater == 0 {
  845. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  846. }
  847. }
  848. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  849. assessmentAfterDislysis.ID = assessmentAfter.ID
  850. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  851. if err == nil {
  852. c.ServeSuccessJSON(map[string]interface{}{
  853. "assessmentAfterDislysis": assessmentAfterDislysis,
  854. })
  855. }
  856. }
  857. }
  858. func (c *DialysisAPIController) PostDialysisPrescription() {
  859. id, _ := c.GetInt64("patient", 0)
  860. recordDateStr := c.GetString("record_date")
  861. if id <= 0 {
  862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  863. return
  864. }
  865. adminUserInfo := c.GetMobileAdminUserInfo()
  866. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  867. if patient.ID == 0 {
  868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  869. return
  870. }
  871. if len(recordDateStr) == 0 {
  872. recordDateStr = time.Now().Format("2006-01-02")
  873. }
  874. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  875. if parseDateErr != nil {
  876. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  878. return
  879. }
  880. mode_id, _ := c.GetInt64("mode_id", 0)
  881. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  882. dialyzer, _ := c.GetInt64("dialyzer", 0)
  883. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  884. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  885. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  886. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  887. replacement_total, _ := c.GetFloat("replacement_total", 0)
  888. replacement_way, _ := c.GetInt64("replacement_way", 0)
  889. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  890. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  891. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  892. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  893. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  894. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  895. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  896. kalium, _ := c.GetFloat("kalium", 0)
  897. sodium, _ := c.GetFloat("sodium", 0)
  898. calcium, _ := c.GetFloat("calcium", 0)
  899. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  900. glucose, _ := c.GetFloat("glucose", 0)
  901. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  902. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  903. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  904. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  905. conductivity, _ := c.GetFloat("conductivity", 0)
  906. remark := c.GetString("remark")
  907. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  908. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  909. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  910. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  911. body_fluid, _ := c.GetInt64("body_fluid", 0)
  912. special_medicine, _ := c.GetInt64("special_medicine", 0)
  913. special_medicine_other := c.GetString("special_medicine_other")
  914. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  915. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  916. blood_access, _ := c.GetInt64("blood_access", 0)
  917. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  918. body_fluid_other := c.GetString("body_fluid_other")
  919. niprocart, _ := c.GetInt64("niprocart", 0)
  920. jms, _ := c.GetInt64("jms", 0)
  921. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  922. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  923. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  924. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  925. filtryzer, _ := c.GetInt64("filtryzer", 0)
  926. target_ktv, _ := c.GetFloat("target_ktv", 0)
  927. dialyzers, _ := c.GetInt64("dialyzers", 0)
  928. injector, _ := c.GetInt64("injector", 0)
  929. bloodlines, _ := c.GetInt64("bloodlines", 0)
  930. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  931. safe_package, _ := c.GetInt64("package", 0)
  932. a_liquid, _ := c.GetInt64("a_liquid", 0)
  933. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  934. fmt.Println("预冲量", pre_impulse)
  935. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  936. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  937. blood := c.GetString("blood")
  938. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  939. dialysis_irrigation := c.GetString("dialysis_irrigation")
  940. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  941. displace_speed := c.GetString("displace_speed")
  942. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  943. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  944. //
  945. //if template.TemplateId == 2 || template.TemplateId == 6 {
  946. // if appRole.UserType == 3 {
  947. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  948. // if getPermissionErr != nil {
  949. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  950. // return
  951. // } else if headNursePermission == nil {
  952. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  953. // return
  954. // }
  955. // }
  956. //}
  957. //TODO 需要根据角色去判断
  958. prescription := models.DialysisPrescription{
  959. UserOrgId: adminUserInfo.Org.Id,
  960. PatientId: id,
  961. RecordDate: recordDate.Unix(),
  962. ModeId: mode_id,
  963. DialysisDuration: dialysis_duration,
  964. Dialyzer: dialyzer,
  965. PerfusionApparatus: perfusion_apparatus,
  966. BloodFlowVolume: blood_flow_volume,
  967. DewaterAmount: dewater_amount,
  968. DisplaceLiqui: displace_liqui,
  969. ReplacementWay: replacement_way,
  970. Anticoagulant: anticoagulant,
  971. AnticoagulantShouji: anticoagulant_shouji,
  972. AnticoagulantWeichi: anticoagulant_weichi,
  973. AnticoagulantZongliang: anticoagulant_zongliang,
  974. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  975. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  976. Kalium: kalium,
  977. Sodium: sodium,
  978. Calcium: calcium,
  979. Bicarbonate: bicarbonate,
  980. Glucose: glucose,
  981. // DryWeight: dry_weight,
  982. DialysateFlow: dialysate_flow,
  983. DialysateTemperature: dialysate_temperature,
  984. // PrescriptionDoctor: prescription_doctor,
  985. ReplacementTotal: replacement_total,
  986. Conductivity: conductivity,
  987. Remark: remark,
  988. Status: 1,
  989. CreatedTime: time.Now().Unix(),
  990. UpdatedTime: time.Now().Unix(),
  991. DialysisDurationMinute: dialysisDurationMinute,
  992. DialysisDurationHour: dialysisDurationHour,
  993. TargetUltrafiltration: targetUltrafiltration,
  994. DialysateFormulation: dialysateFormulation,
  995. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  996. BodyFluid: body_fluid,
  997. SpecialMedicine: special_medicine,
  998. SpecialMedicineOther: special_medicine_other,
  999. DisplaceLiquiPart: displace_liqui_part,
  1000. DisplaceLiquiValue: displace_liqui_value,
  1001. BloodAccess: blood_access,
  1002. Ultrafiltration: ultrafiltration,
  1003. BodyFluidOther: body_fluid_other,
  1004. Niprocart: niprocart,
  1005. Jms: jms,
  1006. FistulaNeedleSet: fistula_needle_set,
  1007. FistulaNeedleSet16: fistula_needle_set_16,
  1008. Hemoperfusion: hemoperfusion,
  1009. DialyserSterilised: dialyser_sterilised,
  1010. Filtryzer: filtryzer,
  1011. Dialyzers: dialyzers,
  1012. Injector: injector,
  1013. Bloodlines: bloodlines,
  1014. TubingHemodialysis: tubing_hemodialysis,
  1015. Package: safe_package,
  1016. ALiquid: a_liquid,
  1017. TargetKtv: target_ktv,
  1018. PreImpulse: pre_impulse,
  1019. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1020. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1021. Blood: blood,
  1022. DialysisDialyszers: dialysis_dialyszers,
  1023. DialysisIrrigation: dialysis_irrigation,
  1024. AntioxidantCommodityName: antioxidant_commodity_name,
  1025. DisplaceSpeed: displace_speed,
  1026. }
  1027. //查询最近透析准备表里是否存在 透析器 灌流器
  1028. //
  1029. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1030. //
  1031. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1032. //
  1033. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1034. //if len(mation)>0{
  1035. // for _, item := range splitStr {
  1036. // for _,it := range mation{
  1037. // if(item == it.SpecificationName){
  1038. //
  1039. // //查询最近一次的透析器
  1040. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1041. //
  1042. // if errcode == gorm.ErrRecordNotFound{
  1043. // //插入数据
  1044. // prepare := models.DialysisBeforePrepare{
  1045. // UserOrgId: adminUserInfo.Org.Id,
  1046. // PatientId: id,
  1047. // RecordDate: recordDate.Unix(),
  1048. // GoodTypeId: it.GoodTypeId,
  1049. // GoodId: it.ID,
  1050. // Count: 1,
  1051. // Ctime: time.Now().Unix(),
  1052. // Creater: adminUserInfo.AdminUser.Id,
  1053. // Status:1,
  1054. //
  1055. // }
  1056. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1057. // fmt.Println("",errcode)
  1058. // }
  1059. // }
  1060. // }
  1061. //
  1062. // }
  1063. //
  1064. // for _, item := range splitIrrigation {
  1065. // for _,it := range mation{
  1066. // if(item == it.SpecificationName){
  1067. // //查询最近一次的透析器
  1068. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1069. // if errcode == gorm.ErrRecordNotFound{
  1070. // //插入数据
  1071. // prepare := models.DialysisBeforePrepare{
  1072. // UserOrgId: adminUserInfo.Org.Id,
  1073. // PatientId: id,
  1074. // RecordDate: recordDate.Unix(),
  1075. // GoodTypeId: it.GoodTypeId,
  1076. // GoodId: it.ID,
  1077. // Count: 1,
  1078. // Ctime: time.Now().Unix(),
  1079. // Creater: adminUserInfo.AdminUser.Id,
  1080. // Status:1,
  1081. //
  1082. // }
  1083. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1084. // fmt.Println(errcode)
  1085. // }
  1086. // }
  1087. // }
  1088. // }
  1089. //}
  1090. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1091. if dialysisPrescription.ID == 0 { //新增
  1092. //if mode_id > 0 {
  1093. // //service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1094. //}
  1095. if appRole.UserType == 2 || appRole.UserType == 1 {
  1096. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1097. }
  1098. prescription.Creater = adminUserInfo.AdminUser.Id
  1099. err := service.AddSigleRecord(&prescription)
  1100. if err == nil {
  1101. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1102. if updateErr != nil {
  1103. utils.ErrorLog("%v", updateErr)
  1104. }
  1105. c.ServeSuccessJSON(map[string]interface{}{
  1106. "prescription": prescription,
  1107. })
  1108. }
  1109. } else { //修改
  1110. //if mode_id > 0 {
  1111. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1112. //}
  1113. //if template.TemplateId == 1 {
  1114. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1115. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1116. // if getPermissionErr != nil {
  1117. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1118. // return
  1119. // } else if headNursePermission == nil {
  1120. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1121. // return
  1122. // }
  1123. // }
  1124. //}
  1125. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1126. prescription.Modifier = adminUserInfo.AdminUser.Id
  1127. if appRole.UserType == 2 || appRole.UserType == 1 {
  1128. prescription_doctor := adminUserInfo.AdminUser.Id
  1129. prescription.PrescriptionDoctor = prescription_doctor
  1130. } else {
  1131. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  1132. }
  1133. if dialysisPrescription.Creater == 0 { //体重称
  1134. prescription.Creater = adminUserInfo.AdminUser.Id
  1135. } else {
  1136. prescription.Creater = dialysisPrescription.Creater
  1137. }
  1138. prescription.ID = dialysisPrescription.ID
  1139. err := service.UpDateDialysisPrescription(&prescription)
  1140. if err == nil {
  1141. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1142. if updateErr != nil {
  1143. utils.ErrorLog("%v", updateErr)
  1144. }
  1145. c.ServeSuccessJSON(map[string]interface{}{
  1146. "prescription": prescription,
  1147. })
  1148. }
  1149. }
  1150. }
  1151. func (c *DialysisAPIController) Finish() {
  1152. id, _ := c.GetInt64("patient", 0)
  1153. recordDateStr := c.GetString("record_date")
  1154. nurseID, _ := c.GetInt64("nurse")
  1155. end_time := c.GetString("end_time")
  1156. if id <= 0 || nurseID <= 0 {
  1157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1158. return
  1159. }
  1160. adminUserInfo := c.GetMobileAdminUserInfo()
  1161. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1162. if patient.ID == 0 {
  1163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1164. return
  1165. }
  1166. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1167. if getNurseErr != nil {
  1168. c.ErrorLog("获取护士失败:%v", getNurseErr)
  1169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1170. return
  1171. } else if nurse == nil {
  1172. c.ErrorLog("护士不存在")
  1173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1174. return
  1175. }
  1176. if len(recordDateStr) == 0 {
  1177. recordDateStr = time.Now().Format("2006-01-02")
  1178. }
  1179. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1180. if parseDateErr != nil {
  1181. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1183. return
  1184. }
  1185. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  1186. if parseEndDateErr != nil {
  1187. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  1188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1189. return
  1190. }
  1191. //now := time.Now()
  1192. //year, month, day := now.Date()
  1193. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1194. //todayTimeStamp := today_time.Unix()
  1195. // 获取当天的第一条透析纪录
  1196. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  1197. if getMonitorRecordsErr != nil {
  1198. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1200. return
  1201. }
  1202. // 获取当前的最后一条透析纪录
  1203. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.Org.Id, id, recordDate.Unix())
  1204. if getMonitorRecordsErr != nil {
  1205. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  1206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1207. return
  1208. }
  1209. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  1210. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.Org.Id, id, recordDate.Unix())
  1211. if getAADErr != nil {
  1212. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  1213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1214. return
  1215. }
  1216. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.Org.Id, id, recordDate.Unix())
  1217. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  1218. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  1219. if assessmentAfterDislysis != nil {
  1220. tempassessmentAfterDislysis = *assessmentAfterDislysis
  1221. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  1222. } else {
  1223. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  1224. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  1225. tempassessmentAfterDislysis.Status = 1
  1226. tempassessmentAfterDislysis.PatientId = id
  1227. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  1228. }
  1229. if dialysisOrder.Stage == 1 {
  1230. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  1231. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  1232. fmt.Println(value)
  1233. a, b := math.Modf(value)
  1234. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  1235. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  1236. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  1237. fmt.Println(hour)
  1238. fmt.Println(minute)
  1239. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  1240. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  1241. }
  1242. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  1243. //var num1 int64
  1244. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  1245. //fmt.Println(num1)
  1246. //sub := float64(num1 / 3600)
  1247. //fmt.Println(sub)
  1248. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  1249. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  1250. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  1251. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  1252. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  1253. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  1254. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  1255. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  1256. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1257. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  1258. }
  1259. if adminUserInfo.Org.Id == 9583 {
  1260. //获取透析处方的最后一条数据
  1261. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  1262. if diaerr != nil {
  1263. c.ErrorLog("获取透析处方失败:%v", diaerr)
  1264. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1265. return
  1266. }
  1267. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  1268. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  1269. }
  1270. }
  1271. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  1272. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  1273. }
  1274. if lastAssessmentAfterDislysis != nil {
  1275. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  1276. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  1277. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  1278. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  1279. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  1280. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  1281. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  1282. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  1283. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  1284. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  1285. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  1286. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  1287. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  1288. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  1289. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  1290. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  1291. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  1292. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  1293. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  1294. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  1295. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  1296. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  1297. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  1298. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  1299. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  1300. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  1301. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  1302. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  1303. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  1304. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  1305. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  1306. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  1307. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  1308. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  1309. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  1310. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  1311. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  1312. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  1313. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  1314. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  1315. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  1316. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  1317. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  1318. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  1319. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  1320. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  1321. }
  1322. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  1323. if err != nil {
  1324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1325. return
  1326. }
  1327. if dialysisOrder == nil {
  1328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  1329. return
  1330. }
  1331. if dialysisOrder.Stage == 2 {
  1332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  1333. return
  1334. }
  1335. if dialysisOrder.Stage == 1 {
  1336. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id)
  1337. //结束时候透析次数加1
  1338. service.UpdateSolutionByPatientId(id)
  1339. dialysisOrder.Stage = 2
  1340. dialysisOrder.FinishNurse = nurseID
  1341. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  1342. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  1343. dialysisOrder.EndTime = endDate.Unix()
  1344. go func() {
  1345. ssoDomain := beego.AppConfig.String("call_domain")
  1346. api := ssoDomain + "/index/downpatient"
  1347. values := make(url.Values)
  1348. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  1349. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  1350. values.Set("patient_id", strconv.FormatInt(id, 10))
  1351. http.PostForm(api, values)
  1352. }()
  1353. if err == nil {
  1354. c.ServeSuccessJSON(map[string]interface{}{
  1355. "dialysisOrder": dialysisOrder,
  1356. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  1357. })
  1358. } else {
  1359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1360. }
  1361. }
  1362. }
  1363. func (c *DialysisAPIController) GetAllZone() {
  1364. adminUserInfo := c.GetMobileAdminUserInfo()
  1365. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  1366. if err == nil {
  1367. c.ServeSuccessJSON(map[string]interface{}{
  1368. "zone": zone,
  1369. })
  1370. }
  1371. }
  1372. func (c *DialysisAPIController) GetSchedualPatientsList() {
  1373. adminUserInfo := c.GetMobileAdminUserInfo()
  1374. page, _ := c.GetInt64("page", 1)
  1375. limit, _ := c.GetInt64("limit", 10)
  1376. schedulType, _ := c.GetInt64("schedul_type", 0)
  1377. startTime, _ := c.GetInt64("schedul_time", 0)
  1378. partitionType, _ := c.GetInt64("partition_type", 0)
  1379. keywords := c.GetString("keywords")
  1380. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  1381. if err == nil {
  1382. c.ServeSuccessJSON(map[string]interface{}{
  1383. "schedule": dialysisSchedule,
  1384. })
  1385. }
  1386. return
  1387. }
  1388. // /m/api/dialysis/start [post]
  1389. // @param patient_id:int
  1390. // @param record_date:string 排班时间 (yyyy-mm-dd)
  1391. // @param nurse:int 上机护士
  1392. // @param bed:int 床位号
  1393. func (this *DialysisAPIController) StartDialysis() {
  1394. patientID, _ := this.GetInt64("patient_id")
  1395. recordDateStr := this.GetString("record_date")
  1396. nurseID, _ := this.GetInt64("nurse")
  1397. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  1398. blood_drawing, _ := this.GetInt64("blood_drawing")
  1399. schedual_type, _ := this.GetInt64("schedual_type")
  1400. bedID, _ := this.GetInt64("bed")
  1401. start_time := this.GetString("start_time")
  1402. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  1403. change_nurse, _ := this.GetInt64("change_nurse")
  1404. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  1405. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  1406. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  1407. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1408. return
  1409. }
  1410. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1411. if parseStartDateErr != nil {
  1412. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  1413. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1414. return
  1415. }
  1416. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1417. if parseErr != nil {
  1418. this.ErrorLog("时间解析失败:%v", parseErr)
  1419. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1420. return
  1421. }
  1422. adminUserInfo := this.GetMobileAdminUserInfo()
  1423. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  1424. if getPatientErr != nil {
  1425. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  1426. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1427. return
  1428. } else if patient == nil {
  1429. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1430. return
  1431. }
  1432. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  1433. if getNurseErr != nil {
  1434. this.ErrorLog("获取护士失败:%v", getNurseErr)
  1435. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1436. return
  1437. } else if nurse == nil {
  1438. this.ErrorLog("护士不存在")
  1439. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1440. return
  1441. }
  1442. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  1443. //if getNurseErr != nil {
  1444. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  1445. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1446. // return
  1447. //} else if nurse == nil {
  1448. // this.ErrorLog("护士不存在")
  1449. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1450. // return
  1451. //}
  1452. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  1453. if getDeviceNumberErr != nil {
  1454. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  1455. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1456. return
  1457. } else if deviceNumber == nil {
  1458. this.ErrorLog("床位号不存在")
  1459. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1460. return
  1461. }
  1462. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  1463. if getRecordErr != nil {
  1464. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  1465. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1466. return
  1467. } else if dialysisRecord != nil {
  1468. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  1469. return
  1470. }
  1471. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  1472. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  1473. timeLayout := "2006-01-02 15:04:05"
  1474. loc, _ := time.LoadLocation("Local")
  1475. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1476. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1477. schedulestartTime := theStartTime.Unix()
  1478. scheduleendTime := theEndTime.Unix()
  1479. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1480. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  1481. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  1482. //查询该床位是否有人用了
  1483. order, order_err := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  1484. if err == gorm.ErrRecordNotFound { //空床位
  1485. // 修改了床位逻辑
  1486. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1487. if daySchedule.ID > 0 {
  1488. daySchedule.PartitionId = deviceNumber.ZoneID
  1489. daySchedule.BedId = bedID
  1490. daySchedule.ScheduleType = schedual_type
  1491. daySchedule.UpdatedTime = time.Now().Unix()
  1492. err := service.UpdateSchedule(&daySchedule)
  1493. if err != nil {
  1494. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1495. return
  1496. }
  1497. }
  1498. } else if err == nil {
  1499. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  1500. if order_err == nil {
  1501. if order.ID > 0 { //该机位被其他人占用了
  1502. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1503. return
  1504. } else {
  1505. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1506. if daySchedule.ID > 0 {
  1507. daySchedule.PartitionId = deviceNumber.ZoneID
  1508. daySchedule.BedId = bedID
  1509. daySchedule.ScheduleType = schedual_type
  1510. daySchedule.UpdatedTime = time.Now().Unix()
  1511. err := service.UpdateSchedule(&daySchedule)
  1512. if err != nil {
  1513. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1514. return
  1515. }
  1516. }
  1517. }
  1518. } else if order_err == gorm.ErrRecordNotFound { //该床位没被占用
  1519. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  1520. if daySchedule.ID > 0 {
  1521. daySchedule.PartitionId = deviceNumber.ZoneID
  1522. daySchedule.BedId = bedID
  1523. daySchedule.ScheduleType = schedual_type
  1524. daySchedule.UpdatedTime = time.Now().Unix()
  1525. err := service.UpdateSchedule(&daySchedule)
  1526. if err != nil {
  1527. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1528. return
  1529. }
  1530. }
  1531. }
  1532. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  1533. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  1534. return
  1535. }
  1536. } else if err != nil {
  1537. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1538. return
  1539. }
  1540. dialysisRecord = &models.DialysisOrder{
  1541. DialysisDate: recordDate.Unix(),
  1542. UserOrgId: adminUserInfo.Org.Id,
  1543. PatientId: patientID,
  1544. Stage: 1,
  1545. BedID: bedID,
  1546. StartNurse: nurseID,
  1547. Status: 1,
  1548. StartTime: startDate.Unix(),
  1549. CreatedTime: time.Now().Unix(),
  1550. UpdatedTime: time.Now().Unix(),
  1551. PunctureNurse: puncture_nurse,
  1552. Creator: adminUserInfo.AdminUser.Id,
  1553. Modifier: adminUserInfo.AdminUser.Id,
  1554. SchedualType: schedual_type,
  1555. WashpipeNurse: washpipe_nurse,
  1556. ChangeNurse: change_nurse,
  1557. DifficultPunctureNurse: difficult_puncture_nurse,
  1558. NewFistulaNurse: new_fistula_nurse,
  1559. }
  1560. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  1561. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  1562. var tempdispose string
  1563. // 只针对中能建
  1564. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  1565. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  1566. }
  1567. var ultrafiltration_rate float64
  1568. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  1569. if prescription.ID > 0 {
  1570. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  1571. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  1572. if template.TemplateId == 6 || template.TemplateId == 32 { //adminUserInfo.Org.Id == 9538
  1573. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  1574. }
  1575. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  1576. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  1577. }
  1578. // 只针对方济医院
  1579. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  1580. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  1581. ultrafiltration_rate = value
  1582. }
  1583. }
  1584. }
  1585. record := models.MonitoringRecord{
  1586. UserOrgId: adminUserInfo.Org.Id,
  1587. PatientId: patientID,
  1588. DialysisOrderId: dialysisRecord.ID,
  1589. MonitoringDate: schedulestartTime,
  1590. OperateTime: startDate.Unix(),
  1591. // MonitoringTime: recordTime,
  1592. MonitoringNurse: nurseID,
  1593. Dispose: tempdispose,
  1594. UltrafiltrationRate: ultrafiltration_rate,
  1595. UltrafiltrationVolume: 0,
  1596. Status: 1,
  1597. CreatedTime: time.Now().Unix(),
  1598. UpdatedTime: time.Now().Unix(),
  1599. }
  1600. //只针对广慈医院
  1601. if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 || template.TemplateId == 32 {
  1602. // 查询病人是否有透前评估数据
  1603. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  1604. //如果有数据就插入
  1605. if errcode == nil {
  1606. record.SystolicBloodPressure = befor.SystolicBloodPressure
  1607. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  1608. record.BreathingRate = befor.BreathingRate
  1609. record.PulseFrequency = befor.PulseFrequency
  1610. record.Temperature = befor.Temperature
  1611. }
  1612. }
  1613. // 如果当天有插入数据,则不再往透析纪录里插入数据
  1614. if newdialysisRecord.ID > 0 {
  1615. err := service.CreateMonitor(&record)
  1616. if err != nil {
  1617. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  1618. return
  1619. }
  1620. }
  1621. go func() {
  1622. ssoDomain := beego.AppConfig.String("call_domain")
  1623. api := ssoDomain + "/index/uppatient"
  1624. values := make(url.Values)
  1625. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  1626. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  1627. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  1628. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  1629. http.PostForm(api, values)
  1630. }()
  1631. if createErr != nil {
  1632. this.ErrorLog("上机失败:%v", createErr)
  1633. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1634. return
  1635. }
  1636. this.ServeSuccessJSON(map[string]interface{}{
  1637. "dialysis_order": newdialysisRecord,
  1638. "monitor": record,
  1639. })
  1640. }
  1641. func (c *DialysisAPIController) PostSolution() {
  1642. id, _ := c.GetInt64("patient", 0)
  1643. recordDateStr := c.GetString("record_date")
  1644. if id <= 0 {
  1645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1646. return
  1647. }
  1648. adminUserInfo := c.GetMobileAdminUserInfo()
  1649. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1650. if patient.ID == 0 {
  1651. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1652. return
  1653. }
  1654. if len(recordDateStr) == 0 {
  1655. recordDateStr = time.Now().Format("2006-01-02")
  1656. }
  1657. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1658. if parseDateErr != nil {
  1659. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1661. return
  1662. }
  1663. mode_id, _ := c.GetInt64("mode_id", 0)
  1664. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1665. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1666. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1667. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1668. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1669. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1670. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1671. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1672. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1673. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1674. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1675. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1676. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1677. kalium, _ := c.GetFloat("kalium", 0)
  1678. sodium, _ := c.GetFloat("sodium", 0)
  1679. calcium, _ := c.GetFloat("calcium", 0)
  1680. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1681. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1682. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1683. glucose, _ := c.GetFloat("glucose", 0)
  1684. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1685. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1686. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1687. conductivity, _ := c.GetFloat("conductivity", 0)
  1688. remark := c.GetString("remark")
  1689. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1690. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1691. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1692. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1693. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1694. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1695. special_medicine_other := c.GetString("special_medicine_other")
  1696. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1697. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1698. blood_access, _ := c.GetInt64("blood_access", 0)
  1699. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1700. body_fluid_other := c.GetString("body_fluid_other")
  1701. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1702. niprocart, _ := c.GetInt64("niprocart", 0)
  1703. jms, _ := c.GetInt64("jms", 0)
  1704. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1705. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1706. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1707. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1708. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1709. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1710. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1711. injector, _ := c.GetInt64("injector", 0)
  1712. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1713. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1714. safe_package, _ := c.GetInt64("package", 0)
  1715. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1716. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1717. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1718. blood := c.GetString("blood")
  1719. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1720. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1721. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1722. displace_speed := c.GetString("displace_speed")
  1723. if mode_id > 0 {
  1724. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1725. }
  1726. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1727. //
  1728. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1729. // if appRole.UserType == 3 {
  1730. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1731. // if getPermissionErr != nil {
  1732. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1733. // return
  1734. // } else if headNursePermission == nil {
  1735. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1736. // return
  1737. // }
  1738. // }
  1739. //}
  1740. prescription := models.DialysisPrescription{
  1741. UserOrgId: adminUserInfo.Org.Id,
  1742. PatientId: id,
  1743. RecordDate: recordDate.Unix(),
  1744. ModeId: mode_id,
  1745. DialysisDuration: dialysis_duration,
  1746. Dialyzer: dialyzer,
  1747. PerfusionApparatus: perfusion_apparatus,
  1748. BloodFlowVolume: blood_flow_volume,
  1749. DewaterAmount: dewater_amount,
  1750. DisplaceLiqui: displace_liqui,
  1751. ReplacementWay: replacement_way,
  1752. Anticoagulant: anticoagulant,
  1753. AnticoagulantShouji: anticoagulant_shouji,
  1754. AnticoagulantWeichi: anticoagulant_weichi,
  1755. AnticoagulantZongliang: anticoagulant_zongliang,
  1756. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1757. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1758. Kalium: kalium,
  1759. Sodium: sodium,
  1760. Calcium: calcium,
  1761. Bicarbonate: bicarbonate,
  1762. Glucose: glucose,
  1763. // DryWeight: dry_weight,
  1764. DialysateFlow: dialysate_flow,
  1765. DialysateTemperature: dialysate_temperature,
  1766. Conductivity: conductivity,
  1767. Remark: remark,
  1768. Status: 1,
  1769. CreatedTime: time.Now().Unix(),
  1770. UpdatedTime: time.Now().Unix(),
  1771. DialysisDurationMinute: dialysisDurationMinute,
  1772. DialysisDurationHour: dialysisDurationHour,
  1773. TargetUltrafiltration: targetUltrafiltration,
  1774. DialysateFormulation: dialysateFormulation,
  1775. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1776. BodyFluid: body_fluid,
  1777. SpecialMedicine: special_medicine,
  1778. SpecialMedicineOther: special_medicine_other,
  1779. DisplaceLiquiPart: displace_liqui_part,
  1780. DisplaceLiquiValue: displace_liqui_value,
  1781. BloodAccess: blood_access,
  1782. Ultrafiltration: ultrafiltration,
  1783. BodyFluidOther: body_fluid_other,
  1784. ReplacementTotal: replacement_total,
  1785. Niprocart: niprocart,
  1786. Jms: jms,
  1787. FistulaNeedleSet: fistula_needle_set,
  1788. FistulaNeedleSet16: fistula_needle_set_16,
  1789. Hemoperfusion: hemoperfusion,
  1790. DialyserSterilised: dialyser_sterilised,
  1791. Filtryzer: filtryzer,
  1792. TargetKtv: target_ktv,
  1793. Dialyzers: dialyzers,
  1794. Injector: injector,
  1795. Bloodlines: bloodlines,
  1796. TubingHemodialysis: tubing_hemodialysis,
  1797. Package: safe_package,
  1798. ALiquid: a_liquid,
  1799. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1800. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1801. Blood: blood,
  1802. DialysisDialyszers: dialysis_dialyszers,
  1803. DialysisIrrigation: dialysis_irrigation,
  1804. AntioxidantCommodityName: antioxidant_commodity_name,
  1805. DisplaceSpeed: displace_speed,
  1806. }
  1807. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1808. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1809. //
  1810. if appRole.UserType == 2 || appRole.UserType == 1 {
  1811. prescription_doctor = adminUserInfo.AdminUser.Id
  1812. prescription.PrescriptionDoctor = prescription_doctor
  1813. }
  1814. if dialysisPrescription.ID == 0 { //新增
  1815. prescription.Creater = adminUserInfo.AdminUser.Id
  1816. } else { //修改
  1817. if dialysisPrescription.Creater == 0 {
  1818. prescription.Creater = adminUserInfo.AdminUser.Id
  1819. } else {
  1820. prescription.Creater = dialysisPrescription.Creater
  1821. }
  1822. //if/**/
  1823. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1824. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  1825. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1826. // if getPermissionErr != nil {
  1827. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1828. // return
  1829. // } else if headNursePermission == nil {
  1830. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1831. // return
  1832. // }
  1833. //}
  1834. //prescription.Creater = dialysisPrescription.Creater
  1835. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1836. prescription.Modifier = adminUserInfo.AdminUser.Id
  1837. prescription.ID = dialysisPrescription.ID
  1838. }
  1839. solution := models.DialysisSolution{
  1840. RegistrarsId: adminUserInfo.AdminUser.Id,
  1841. UserOrgId: adminUserInfo.Org.Id,
  1842. Doctor: prescription_doctor,
  1843. PatientId: id,
  1844. ModeId: mode_id,
  1845. DialysisDuration: dialysis_duration,
  1846. PerfusionApparatus: perfusion_apparatus,
  1847. BloodFlowVolume: blood_flow_volume,
  1848. Dewater: dewater_amount,
  1849. DisplaceLiqui: displace_liqui,
  1850. ReplacementWay: replacement_way,
  1851. Anticoagulant: anticoagulant,
  1852. AnticoagulantShouji: anticoagulant_shouji,
  1853. AnticoagulantWeichi: anticoagulant_weichi,
  1854. AnticoagulantZongliang: anticoagulant_zongliang,
  1855. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1856. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1857. Kalium: kalium,
  1858. Sodium: sodium,
  1859. Calcium: calcium,
  1860. Bicarbonate: bicarbonate,
  1861. Glucose: glucose,
  1862. // DryWeight: dry_weight,
  1863. DialysateFlow: dialysate_flow,
  1864. DialysateTemperature: dialysate_temperature,
  1865. Conductivity: conductivity,
  1866. Remark: remark,
  1867. Status: 1,
  1868. CreatedTime: time.Now().Unix(),
  1869. UpdatedTime: time.Now().Unix(),
  1870. DialysisDurationMinute: dialysisDurationMinute,
  1871. DialysisDurationHour: dialysisDurationHour,
  1872. TargetUltrafiltration: targetUltrafiltration,
  1873. DialysateFormulation: dialysateFormulation,
  1874. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1875. BodyFluid: body_fluid,
  1876. SpecialMedicine: special_medicine,
  1877. SpecialMedicineOther: special_medicine_other,
  1878. DisplaceLiquiPart: displace_liqui_part,
  1879. DisplaceLiquiValue: displace_liqui_value,
  1880. BloodAccess: blood_access,
  1881. Ultrafiltration: ultrafiltration,
  1882. BodyFluidOther: body_fluid_other,
  1883. ReplacementTotal: replacement_total,
  1884. TargetKtv: target_ktv,
  1885. DialysisDialyszers: dialysis_dialyszers,
  1886. DialysisIrrigation: dialysis_irrigation,
  1887. }
  1888. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  1889. //查询最近透析准备表里是否存在 透析器 灌流器
  1890. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1891. //
  1892. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1893. //
  1894. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1895. //if len(mation)>0{
  1896. // for _, item := range splitStr {
  1897. // for _,it := range mation{
  1898. // if(item == it.SpecificationName){
  1899. //
  1900. // //查询最近一次的透析器
  1901. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1902. //
  1903. // if errcode == gorm.ErrRecordNotFound{
  1904. // //插入数据
  1905. // prepare := models.DialysisBeforePrepare{
  1906. // UserOrgId: adminUserInfo.Org.Id,
  1907. // PatientId: id,
  1908. // RecordDate: recordDate.Unix(),
  1909. // GoodTypeId: it.GoodTypeId,
  1910. // GoodId: it.ID,
  1911. // Count: 1,
  1912. // Ctime: time.Now().Unix(),
  1913. // Creater: adminUserInfo.AdminUser.Id,
  1914. // Status:1,
  1915. //
  1916. // }
  1917. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1918. // fmt.Println("",errcode)
  1919. // }
  1920. // }
  1921. // }
  1922. //
  1923. // }
  1924. //
  1925. // for _, item := range splitIrrigation {
  1926. // for _,it := range mation{
  1927. // if(item == it.SpecificationName){
  1928. // //查询最近一次的透析器
  1929. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1930. // if errcode == gorm.ErrRecordNotFound{
  1931. // //插入数据
  1932. // prepare := models.DialysisBeforePrepare{
  1933. // UserOrgId: adminUserInfo.Org.Id,
  1934. // PatientId: id,
  1935. // RecordDate: recordDate.Unix(),
  1936. // GoodTypeId: it.GoodTypeId,
  1937. // GoodId: it.ID,
  1938. // Count: 1,
  1939. // Ctime: time.Now().Unix(),
  1940. // Creater: adminUserInfo.AdminUser.Id,
  1941. // Status:1,
  1942. //
  1943. // }
  1944. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1945. // fmt.Println(errcode)
  1946. // }
  1947. // }
  1948. // }
  1949. // }
  1950. //}
  1951. c.ServeSuccessJSON(map[string]interface{}{
  1952. "solution": &solution,
  1953. "prescription": &prescription,
  1954. })
  1955. }
  1956. func (c *DialysisAPIController) GetAcceptsAssessment() {
  1957. patient, _ := c.GetInt64("patient", 0)
  1958. adminUserInfo := c.GetMobileAdminUserInfo()
  1959. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  1960. c.ServeSuccessJSON(map[string]interface{}{
  1961. "receiveTreatmentAsses": receiveTreatmentAsses,
  1962. })
  1963. }
  1964. func (this *DialysisAPIController) PostSignInfo() {
  1965. patientID, _ := this.GetInt64("patient_id")
  1966. recordDateStr := this.GetString("date")
  1967. if patientID <= 0 {
  1968. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1969. return
  1970. }
  1971. if len(recordDateStr) == 0 {
  1972. recordDateStr = time.Now().Format("2006-01-02")
  1973. }
  1974. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1975. if parseDateErr != nil {
  1976. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1977. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1978. return
  1979. }
  1980. adminInfo := this.GetMobileAdminUserInfo()
  1981. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  1982. if err != nil {
  1983. this.ErrorLog("签名失败:%v", err)
  1984. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1985. return
  1986. }
  1987. this.ServeSuccessJSON(map[string]interface{}{
  1988. "doctor_id": adminInfo.AdminUser.Id,
  1989. })
  1990. }
  1991. func (this *DialysisAPIController) GetLastMonitorRecord() {
  1992. patientID, _ := this.GetInt64("patient_id")
  1993. adminInfo := this.GetMobileAdminUserInfo()
  1994. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  1995. this.ServeSuccessJSON(map[string]interface{}{
  1996. "monitor": record,
  1997. })
  1998. }
  1999. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  2000. thisTime := time.Now()
  2001. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  2002. timeLayout := "2006-01-02 15:04:05"
  2003. loc, _ := time.LoadLocation("Local")
  2004. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2005. theAssessmentDateTime := theStartTime.Unix()
  2006. patientID, _ := this.GetInt64("patient_id")
  2007. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  2008. adminInfo := this.GetMobileAdminUserInfo()
  2009. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  2010. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  2011. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  2012. var ultrafiltration_rate float64
  2013. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  2014. if prescription.ID > 0 {
  2015. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2016. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2017. if template.TemplateId == 6 {
  2018. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2019. record.UltrafiltrationRate = ultrafiltration_rate
  2020. }
  2021. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  2022. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  2023. record.UltrafiltrationRate = ultrafiltration_rate
  2024. }
  2025. if template.TemplateId == 20 || template.TemplateId == 22 {
  2026. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2027. record.UltrafiltrationRate = ultrafiltration_rate
  2028. }
  2029. // 只针对方济医院
  2030. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  2031. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2032. ultrafiltration_rate = value
  2033. record.UltrafiltrationRate = ultrafiltration_rate
  2034. }
  2035. }
  2036. }
  2037. // record.UltrafiltrationRate = ultrafiltration_rate
  2038. record.UltrafiltrationVolume = 0
  2039. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 { //adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535
  2040. if ultrafiltration_rate > 0 {
  2041. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  2042. record.UltrafiltrationVolume = value
  2043. }
  2044. }
  2045. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 { //adminInfo.Org.Id == 9538
  2046. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  2047. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  2048. record.UltrafiltrationVolume = ultrafiltration_volume
  2049. }
  2050. }
  2051. this.ServeSuccessJSON(map[string]interface{}{
  2052. "monitor": record,
  2053. })
  2054. }
  2055. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  2056. record_id, _ := this.GetInt64("id")
  2057. nurseID, _ := this.GetInt64("nurse")
  2058. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2059. bedID, _ := this.GetInt64("bed")
  2060. start_time := this.GetString("start_time")
  2061. schedual_type, _ := this.GetInt64("schedual_type")
  2062. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2063. change_nurse, _ := this.GetInt64("change_nurse")
  2064. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2065. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2066. if record_id == 0 {
  2067. this.ErrorLog("id:%v", record_id)
  2068. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2069. return
  2070. }
  2071. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2072. if parseStartDateErr != nil {
  2073. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2074. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2075. return
  2076. }
  2077. adminUserInfo := this.GetMobileAdminUserInfo()
  2078. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2079. if getNurseErr != nil {
  2080. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2081. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2082. return
  2083. } else if nurse == nil {
  2084. this.ErrorLog("护士不存在")
  2085. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2086. return
  2087. }
  2088. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2089. //if getNurseErr != nil {
  2090. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  2091. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2092. // return
  2093. //} else if nurse == nil {
  2094. // this.ErrorLog("护士不存在")
  2095. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2096. // return
  2097. //}
  2098. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2099. if getDeviceNumberErr != nil {
  2100. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2101. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2102. return
  2103. } else if deviceNumber == nil {
  2104. this.ErrorLog("床位号不存在")
  2105. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2106. return
  2107. }
  2108. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  2109. //
  2110. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  2111. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2112. // if getPermissionErr != nil {
  2113. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2114. // return
  2115. // } else if headNursePermission == nil {
  2116. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2117. // return
  2118. // }
  2119. //}
  2120. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2121. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2122. timeLayout := "2006-01-02 15:04:05"
  2123. loc, _ := time.LoadLocation("Local")
  2124. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2125. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2126. schedulestartTime := theStartTime.Unix()
  2127. scheduleendTime := theEndTime.Unix()
  2128. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2129. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2130. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2131. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  2132. if err == gorm.ErrRecordNotFound { //空床位
  2133. // 修改了床位逻辑
  2134. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2135. if daySchedule.ID > 0 {
  2136. daySchedule.BedId = bedID
  2137. daySchedule.PartitionId = deviceNumber.ZoneID
  2138. daySchedule.ScheduleType = schedual_type
  2139. daySchedule.UpdatedTime = time.Now().Unix()
  2140. err := service.UpdateSchedule(&daySchedule)
  2141. if err != nil {
  2142. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2143. return
  2144. }
  2145. }
  2146. } else if err == nil {
  2147. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2148. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  2149. if daySchedule.ID > 0 {
  2150. daySchedule.BedId = bedID
  2151. daySchedule.PartitionId = deviceNumber.ZoneID
  2152. daySchedule.ScheduleType = schedual_type
  2153. daySchedule.UpdatedTime = time.Now().Unix()
  2154. err := service.UpdateSchedule(&daySchedule)
  2155. if err != nil {
  2156. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2157. return
  2158. }
  2159. }
  2160. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2161. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2162. return
  2163. }
  2164. } else if err != nil {
  2165. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2166. return
  2167. }
  2168. }
  2169. dialysisRecord := &models.DialysisOrder{
  2170. ID: record_id,
  2171. UserOrgId: adminUserInfo.Org.Id,
  2172. BedID: bedID,
  2173. StartNurse: nurseID,
  2174. StartTime: startDate.Unix(),
  2175. PunctureNurse: puncture_nurse,
  2176. Creator: adminUserInfo.AdminUser.Id,
  2177. Modifier: adminUserInfo.AdminUser.Id,
  2178. WashpipeNurse: washpipe_nurse,
  2179. SchedualType: schedual_type,
  2180. ChangeNurse: change_nurse,
  2181. DifficultPunctureNurse: difficult_puncture_nurse,
  2182. NewFistulaNurse: new_fistula_nurse,
  2183. }
  2184. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  2185. if updateErr != nil {
  2186. this.ErrorLog("修改上机失败:%v", updateErr)
  2187. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2188. return
  2189. }
  2190. if updateErr == nil {
  2191. if tempDialysisRecord.Stage == 2 {
  2192. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  2193. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2194. fmt.Println(value)
  2195. a, b := math.Modf(value)
  2196. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2197. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2198. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  2199. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  2200. if updateAssessmentErr != nil {
  2201. utils.ErrorLog("%v", updateAssessmentErr)
  2202. }
  2203. }
  2204. }
  2205. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  2206. this.ServeSuccessJSON(map[string]interface{}{
  2207. "dialysis_order": dialysisRecords,
  2208. })
  2209. }
  2210. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  2211. record_id, _ := c.GetInt64("id")
  2212. nurseID, _ := c.GetInt64("nurse")
  2213. end_time := c.GetString("end_time")
  2214. if record_id <= 0 || nurseID <= 0 {
  2215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2216. return
  2217. }
  2218. adminUserInfo := c.GetMobileAdminUserInfo()
  2219. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2220. if getNurseErr != nil {
  2221. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2223. return
  2224. } else if nurse == nil {
  2225. c.ErrorLog("护士不存在")
  2226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2227. return
  2228. }
  2229. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2230. if parseEndDateErr != nil {
  2231. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2233. return
  2234. }
  2235. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  2236. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  2237. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2238. // if getPermissionErr != nil {
  2239. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2240. // return
  2241. // } else if headNursePermission == nil {
  2242. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2243. // return
  2244. // }
  2245. //}
  2246. dialysisRecord := &models.DialysisOrder{
  2247. ID: record_id,
  2248. UserOrgId: adminUserInfo.Org.Id,
  2249. EndTime: endDate.Unix(),
  2250. FinishNurse: nurseID,
  2251. FinishModifier: adminUserInfo.AdminUser.Id,
  2252. }
  2253. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  2254. if updateErr != nil {
  2255. c.ErrorLog("修改下机失败:%v", updateErr)
  2256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2257. return
  2258. }
  2259. if updateErr == nil {
  2260. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  2261. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2262. a, b := math.Modf(value)
  2263. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2264. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2265. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  2266. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  2267. if updateAssessmentErr != nil {
  2268. utils.ErrorLog("%v", updateAssessmentErr)
  2269. }
  2270. }
  2271. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  2272. c.ServeSuccessJSON(map[string]interface{}{
  2273. "dialysis_order": dialysisRecords,
  2274. })
  2275. }
  2276. func (c *DialysisAPIController) GetLongAdvice() {
  2277. patient_id, _ := c.GetInt64("id")
  2278. adminUserInfo := c.GetMobileAdminUserInfo()
  2279. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  2280. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  2281. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  2282. c.ServeSuccessJSON(map[string]interface{}{
  2283. "status": "1",
  2284. })
  2285. return
  2286. } else { //开启推送提醒
  2287. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  2288. var advice_three []*models.DoctorAdvice
  2289. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  2290. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id)
  2291. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id)
  2292. for _, advice := range advices {
  2293. if advice.FrequencyType == 3 {
  2294. t := time.Now()
  2295. week := int(t.Weekday())
  2296. fmt.Println(t.Weekday())
  2297. fmt.Println(week)
  2298. switch week {
  2299. case 1:
  2300. if strings.Index(advice.WeekDay, "周一") == -1 {
  2301. advice_three = append(advice_three, advice)
  2302. }
  2303. break
  2304. case 2:
  2305. if strings.Index(advice.WeekDay, "周二") == -1 {
  2306. advice_three = append(advice_three, advice)
  2307. }
  2308. break
  2309. case 3:
  2310. if strings.Index(advice.WeekDay, "周三") == -1 {
  2311. advice_three = append(advice_three, advice)
  2312. }
  2313. break
  2314. case 4:
  2315. if strings.Index(advice.WeekDay, "周四") == -1 {
  2316. advice_three = append(advice_three, advice)
  2317. }
  2318. break
  2319. case 5:
  2320. if strings.Index(advice.WeekDay, "周五") == -1 {
  2321. advice_three = append(advice_three, advice)
  2322. }
  2323. break
  2324. case 6:
  2325. if strings.Index(advice.WeekDay, "周六") == -1 {
  2326. advice_three = append(advice_three, advice)
  2327. }
  2328. break
  2329. case 0:
  2330. if strings.Index(advice.WeekDay, "周日") == -1 {
  2331. advice_three = append(advice_three, advice)
  2332. }
  2333. break
  2334. }
  2335. }
  2336. }
  2337. for _, advice := range advices_two {
  2338. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  2339. now := p.Unix()
  2340. dayStr := strconv.FormatInt(advice.DayCount, 10)
  2341. dayStr2 := "-" + dayStr
  2342. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  2343. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  2344. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  2345. for _, ad := range advices {
  2346. advice_three = append(advice_three, ad)
  2347. }
  2348. }
  2349. if err == nil {
  2350. c.ServeSuccessJSON(map[string]interface{}{
  2351. "status": "2",
  2352. "advices": advices,
  2353. "advices_two": RemoveRepeatedElement(advice_three),
  2354. "is_open_remind": config.IsOpenRemind,
  2355. })
  2356. }
  2357. }
  2358. }
  2359. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  2360. newArr = make([]*models.DoctorAdvice, 0)
  2361. for i := 0; i < len(arr); i++ {
  2362. repeat := false
  2363. for j := i + 1; j < len(arr); j++ {
  2364. if arr[i].ID == arr[j].ID {
  2365. repeat = true
  2366. break
  2367. }
  2368. }
  2369. if !repeat {
  2370. newArr = append(newArr, arr[i])
  2371. }
  2372. }
  2373. return
  2374. }
  2375. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  2376. patient, _ := c.GetInt64("id", 0)
  2377. groupNo, _ := c.GetInt64("groupno", 0)
  2378. if patient <= 0 {
  2379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2380. return
  2381. }
  2382. adminUserInfo := c.GetMobileAdminUserInfo()
  2383. dataBody := make(map[string]interface{}, 0)
  2384. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2385. if err != nil {
  2386. utils.ErrorLog(err.Error())
  2387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2388. return
  2389. }
  2390. utils.ErrorLog("%v", dataBody)
  2391. timeLayout := "2006-01-02 15:04"
  2392. loc, _ := time.LoadLocation("Local")
  2393. timeLayout2 := "2006-01-02"
  2394. loc2, _ := time.LoadLocation("Local")
  2395. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2396. utils.ErrorLog("advice_type")
  2397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2398. return
  2399. }
  2400. adviceType := int64(2)
  2401. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2402. utils.ErrorLog("advice_date")
  2403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2404. return
  2405. }
  2406. adviceDate, _ := dataBody["advice_date"].(string)
  2407. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  2408. AdviceDate := theTime.Unix()
  2409. RecordDate := theTime.Unix()
  2410. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2411. utils.ErrorLog("start_time")
  2412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2413. return
  2414. }
  2415. startTime, _ := dataBody["start_time"].(string)
  2416. if len(startTime) == 0 {
  2417. utils.ErrorLog("len(start_time) == 0")
  2418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2419. return
  2420. }
  2421. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  2422. if err != nil {
  2423. utils.ErrorLog(err.Error())
  2424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2425. return
  2426. }
  2427. StartTime := theTime.Unix()
  2428. Remark := ""
  2429. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2430. remark, _ := dataBody["remark"].(string)
  2431. Remark = remark
  2432. }
  2433. var advices []*models.GroupAdvice
  2434. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  2435. utils.ErrorLog("advices")
  2436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2437. return
  2438. }
  2439. adviceNames := dataBody["advices"].([]interface{})
  2440. for _, adviceNameMap := range adviceNames {
  2441. adviceNameM := adviceNameMap.(map[string]interface{})
  2442. var advice models.GroupAdvice
  2443. advice.Remark = Remark
  2444. advice.AdviceType = adviceType
  2445. advice.StartTime = StartTime
  2446. advice.AdviceDate = AdviceDate
  2447. advice.RecordDate = RecordDate
  2448. advice.Status = 1
  2449. advice.CreatedTime = time.Now().Unix()
  2450. advice.UpdatedTime = time.Now().Unix()
  2451. advice.StopState = 2
  2452. advice.ExecutionState = 2
  2453. advice.UserOrgId = adminUserInfo.Org.Id
  2454. advice.PatientId = patient
  2455. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2456. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  2457. utils.ErrorLog("advice_name")
  2458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2459. return
  2460. }
  2461. adviceName, _ := adviceNameM["advice_name"].(string)
  2462. if len(adviceName) == 0 {
  2463. utils.ErrorLog("len(advice_name) == 0")
  2464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2465. return
  2466. }
  2467. advice.AdviceName = adviceName
  2468. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  2469. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  2470. advice.DrugSpec = drugSpec
  2471. }
  2472. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  2473. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  2474. advice.AdviceDesc = adviceDesc
  2475. }
  2476. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  2477. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  2478. advice.DrugSpecUnit = drugSpecUnit
  2479. }
  2480. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  2481. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  2482. // advice.SingleDose = singleDose
  2483. //}
  2484. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  2485. //single_dose := int64(adviceNameM["single_dose"].(float64))
  2486. advice.SingleDose = adviceNameM["single_dose"].(float64)
  2487. }
  2488. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  2489. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  2490. advice.SingleDoseUnit = singleDoseUnit
  2491. }
  2492. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  2493. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  2494. // advice.PrescribingNumber = prescribingNumber
  2495. //}
  2496. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  2497. //single_dose := int64(adviceNameM["single_dose"].(float64))
  2498. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  2499. }
  2500. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  2501. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  2502. advice.PrescribingNumberUnit = prescribingNumberUnit
  2503. }
  2504. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  2505. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  2506. advice.DeliveryWay = deliveryWay
  2507. }
  2508. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  2509. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  2510. advice.ExecutionFrequency = executionFrequency
  2511. }
  2512. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  2513. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  2514. advice.FrequencyType = frequency_type
  2515. }
  2516. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  2517. day_count := int64(adviceNameM["day_count"].(float64))
  2518. advice.DayCount = day_count
  2519. }
  2520. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  2521. week_day, _ := adviceNameM["week_day"].(string)
  2522. advice.WeekDay = week_day
  2523. }
  2524. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  2525. way := int64(adviceNameM["way"].(float64))
  2526. advice.Way = way
  2527. }
  2528. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  2529. drug_id := int64(adviceNameM["drug_id"].(float64))
  2530. advice.DrugId = drug_id
  2531. }
  2532. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  2533. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  2534. advice.DrugNameId = drug_name_id
  2535. }
  2536. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  2537. template_id, _ := adviceNameM["template_id"].(string)
  2538. advice.TemplateId = template_id
  2539. }
  2540. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  2541. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  2542. advice.ExecutionFrequency = executionFrequency
  2543. }
  2544. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  2545. children := adviceNameM["child"].([]interface{})
  2546. if len(children) > 0 {
  2547. for _, childrenMap := range children {
  2548. childMap := childrenMap.(map[string]interface{})
  2549. var child models.GroupAdvice
  2550. child.Remark = Remark
  2551. child.AdviceType = adviceType
  2552. child.StartTime = StartTime
  2553. child.AdviceDate = AdviceDate
  2554. child.RecordDate = RecordDate
  2555. child.Status = 1
  2556. child.CreatedTime = time.Now().Unix()
  2557. child.UpdatedTime = time.Now().Unix()
  2558. child.StopState = 2
  2559. child.ExecutionState = 2
  2560. child.UserOrgId = adminUserInfo.Org.Id
  2561. child.PatientId = patient
  2562. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  2563. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  2564. utils.ErrorLog("child advice_name")
  2565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2566. return
  2567. }
  2568. childAdviceName, _ := childMap["advice_name"].(string)
  2569. if len(childAdviceName) == 0 {
  2570. utils.ErrorLog("len(child advice_name) == 0")
  2571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2572. return
  2573. }
  2574. child.AdviceName = childAdviceName
  2575. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  2576. childAdviceDesc, _ := childMap["advice_desc"].(string)
  2577. child.AdviceDesc = childAdviceDesc
  2578. }
  2579. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  2580. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  2581. child.DrugSpec = childDrugSpec
  2582. }
  2583. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  2584. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  2585. child.DrugSpecUnit = childDrugSpecUnit
  2586. }
  2587. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  2588. child.SingleDose = childMap["single_dose"].(float64)
  2589. }
  2590. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  2591. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  2592. child.SingleDoseUnit = childSingleDoseUnit
  2593. }
  2594. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  2595. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  2596. }
  2597. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  2598. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  2599. child.PrescribingNumberUnit = childPrescribingNumberUnit
  2600. }
  2601. child.DeliveryWay = advice.DeliveryWay
  2602. child.ExecutionFrequency = advice.ExecutionFrequency
  2603. advice.Children = append(advice.Children, &child)
  2604. }
  2605. }
  2606. }
  2607. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  2608. if temp_advice.ID == 0 {
  2609. advices = append(advices, &advice)
  2610. }
  2611. }
  2612. if len(advices) > 0 {
  2613. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  2614. if err != nil {
  2615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2616. return
  2617. }
  2618. c.ServeSuccessJSON(map[string]interface{}{
  2619. "msg": "ok",
  2620. "advices": list,
  2621. })
  2622. } else {
  2623. c.ServeSuccessJSON(map[string]interface{}{
  2624. "msg": "ok",
  2625. })
  2626. }
  2627. return
  2628. }
  2629. func (c *DialysisAPIController) UploadDryWeight() {
  2630. patient_id, _ := c.GetInt64("id")
  2631. dry_weight, _ := c.GetFloat("dry_weight")
  2632. doctor_id, _ := c.GetInt64("doctor_id")
  2633. remark := c.GetString("remark")
  2634. adminUserInfo := c.GetMobileAdminUserInfo()
  2635. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  2636. if err == gorm.ErrRecordNotFound {
  2637. dryWeight := &models.SgjPatientDryweight{
  2638. PatientId: patient_id,
  2639. DryWeight: dry_weight,
  2640. Remakes: remark,
  2641. Ctime: time.Now().Unix(),
  2642. Mtime: time.Now().Unix(),
  2643. Creator: doctor_id,
  2644. Status: 1,
  2645. UserOrgId: adminUserInfo.Org.Id,
  2646. AdjustedValue: "/",
  2647. UserId: adminUserInfo.AdminUser.Id,
  2648. }
  2649. createErr := service.CreatePatientWeightAdjust(dryWeight)
  2650. if createErr == nil {
  2651. c.ServeSuccessJSON(map[string]interface{}{
  2652. "msg": "提交成功",
  2653. "weight": dryWeight,
  2654. })
  2655. }
  2656. } else {
  2657. dryWeight := &models.SgjPatientDryweight{
  2658. PatientId: patient_id,
  2659. DryWeight: dry_weight,
  2660. Remakes: remark,
  2661. Ctime: time.Now().Unix(),
  2662. Mtime: time.Now().Unix(),
  2663. Creator: doctor_id,
  2664. Status: 1,
  2665. UserOrgId: adminUserInfo.Org.Id,
  2666. AdjustedValue: "/",
  2667. UserId: adminUserInfo.AdminUser.Id,
  2668. }
  2669. var value float64
  2670. value = dry_weight - weightAdjust.DryWeight
  2671. if value < 0 {
  2672. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  2673. } else if value == 0 {
  2674. dryWeight.AdjustedValue = "/"
  2675. } else if value > 0 {
  2676. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  2677. }
  2678. createErr := service.CreatePatientWeightAdjust(dryWeight)
  2679. if createErr == nil {
  2680. c.ServeSuccessJSON(map[string]interface{}{
  2681. "msg": "提交成功",
  2682. "weight": dryWeight,
  2683. })
  2684. }
  2685. }
  2686. }
  2687. func (c *DialysisAPIController) GetSolution() {
  2688. patient_id, _ := c.GetInt64("patient_id")
  2689. mode_id, _ := c.GetInt64("mode_id")
  2690. adminUserInfo := c.GetMobileAdminUserInfo()
  2691. solution, err := service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  2692. prescription, err := service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  2693. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.Org.Id, mode_id)
  2694. if err != nil {
  2695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2696. return
  2697. }
  2698. c.ServeSuccessJSON(map[string]interface{}{
  2699. "solution": solution,
  2700. "prescription": prescription,
  2701. "system_prescription": system_prescription,
  2702. })
  2703. }
  2704. func (c *DialysisAPIController) GetSchedule() {
  2705. schedual_type, _ := c.GetInt64("schedual_type")
  2706. adminUserInfo := c.GetMobileAdminUserInfo()
  2707. //timeLayout := "2006-01-02 15:04:05"
  2708. //
  2709. //date := time.Now().Format("2006-01-02") + " 00:00:00"
  2710. //loc, _ := time.LoadLocation("Local")
  2711. //theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  2712. //scheduleTime := theStartTime.Unix()
  2713. scheduleTime, _ := c.GetInt64("record_date")
  2714. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  2715. c.ServeSuccessJSON(map[string]interface{}{
  2716. "number": deviceNumber,
  2717. })
  2718. }
  2719. func (c *DialysisAPIController) GetPatientId() {
  2720. id, _ := c.GetInt64("id")
  2721. patientId, _ := service.GetPatientId(id)
  2722. //获取该患者的所有传染病
  2723. list, _ := service.GetPatientInfectious(id)
  2724. c.ServeSuccessJSON(map[string]interface{}{
  2725. "patient": patientId,
  2726. "infectioulist": list,
  2727. })
  2728. }
  2729. func (this *DialysisAPIController) GetDialysisSchedule() {
  2730. schedualDate := this.GetString("date")
  2731. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  2732. if parseDateErr != nil {
  2733. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2734. return
  2735. }
  2736. adminInfo := this.GetMobileAdminUserInfo()
  2737. orgID := adminInfo.Org.Id
  2738. redis := service.RedisClient()
  2739. defer redis.Close()
  2740. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  2741. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  2742. if len(scheduals) > 0 {
  2743. //缓存数据
  2744. scheduals_json, err := json.Marshal(scheduals)
  2745. if err == nil {
  2746. redis.Set(key, scheduals_json, time.Second*30)
  2747. }
  2748. }
  2749. this.ServeSuccessJSON(map[string]interface{}{
  2750. "scheduals": scheduals,
  2751. })
  2752. }
  2753. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  2754. change_type, _ := this.GetInt64("type", 0)
  2755. record_date := this.GetString("record_time")
  2756. patient_id, _ := this.GetInt64("patient_id", 0)
  2757. timeLayout := "2006-01-02"
  2758. loc, _ := time.LoadLocation("Local")
  2759. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2760. record_time := theAdviceRecordTime.Unix()
  2761. adminUserInfo := this.GetMobileAdminUserInfo()
  2762. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  2763. if err == nil {
  2764. if len(advices) == 0 {
  2765. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  2766. return
  2767. } else {
  2768. this.ServeSuccessJSON(map[string]interface{}{
  2769. "advices": advices,
  2770. "schedule": sch,
  2771. })
  2772. return
  2773. }
  2774. } else {
  2775. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2776. return
  2777. }
  2778. }
  2779. func (c *DialysisAPIController) CreateConsumables() {
  2780. record_date := c.GetString("record_time")
  2781. patient_id, _ := c.GetInt64("patient_id", 0)
  2782. adminUser := c.GetMobileAdminUserInfo()
  2783. timeLayout := "2006-01-02"
  2784. loc, _ := time.LoadLocation("Local")
  2785. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2786. record_time := theRecordTime.Unix()
  2787. dataBody := make(map[string]interface{}, 0)
  2788. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2789. if err != nil {
  2790. utils.ErrorLog(err.Error())
  2791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2792. return
  2793. }
  2794. var beforePrepares []*models.DialysisBeforePrepare
  2795. var updateBeforePrepares []*models.DialysisBeforePrepare
  2796. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  2797. goods, _ := dataBody["goods"].([]interface{})
  2798. if len(goods) > 0 {
  2799. for _, item := range goods {
  2800. items := item.(map[string]interface{})
  2801. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  2802. utils.ErrorLog("good_id")
  2803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2804. return
  2805. }
  2806. good_id := int64(items["good_id"].(float64))
  2807. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  2808. utils.ErrorLog("good_type_id")
  2809. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2810. return
  2811. }
  2812. good_type_id := int64(items["good_type_id"].(float64))
  2813. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2814. utils.ErrorLog("count")
  2815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2816. return
  2817. }
  2818. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2819. commdity_code := items["commdity_code"].(string)
  2820. adminUser := c.GetMobileAdminUserInfo()
  2821. prepare := &models.DialysisBeforePrepare{
  2822. UserOrgId: adminUser.Org.Id,
  2823. PatientId: patient_id,
  2824. RecordDate: record_time,
  2825. GoodId: good_id,
  2826. GoodTypeId: good_type_id,
  2827. Count: count,
  2828. Ctime: time.Now().Unix(),
  2829. Mtime: time.Now().Unix(),
  2830. Creater: adminUser.AdminUser.Id,
  2831. Modifier: 0,
  2832. CommdityCode: commdity_code,
  2833. }
  2834. //问题点
  2835. record_count := service.FindDialysisBeforePrepare(prepare.PatientId, prepare.GoodId, prepare.GoodTypeId, adminUser.Org.Id, record_time)
  2836. if record_count == 0 {
  2837. beforePrepares = append(beforePrepares, prepare)
  2838. }
  2839. }
  2840. }
  2841. }
  2842. if len(beforePrepares) > 0 {
  2843. service.CreateDialysisBeforePrepare(beforePrepares)
  2844. }
  2845. var errs error
  2846. if dataBody["update_goods"] != nil && reflect.TypeOf(dataBody["update_goods"]).String() == "[]interface {}" {
  2847. goods, _ := dataBody["update_goods"].([]interface{})
  2848. if len(goods) > 0 {
  2849. for _, item := range goods {
  2850. items := item.(map[string]interface{})
  2851. if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" {
  2852. utils.ErrorLog("record_time")
  2853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2854. return
  2855. }
  2856. record_time := int64(items["record_time"].(float64))
  2857. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2858. utils.ErrorLog("id")
  2859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2860. return
  2861. }
  2862. id := int64(items["id"].(float64))
  2863. if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" {
  2864. utils.ErrorLog("patient_id")
  2865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2866. return
  2867. }
  2868. patient_id := int64(items["patient_id"].(float64))
  2869. if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" {
  2870. utils.ErrorLog("creater")
  2871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2872. return
  2873. }
  2874. creater := int64(items["creater"].(float64))
  2875. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  2876. utils.ErrorLog("good_id")
  2877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2878. return
  2879. }
  2880. good_id := int64(items["good_id"].(float64))
  2881. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  2882. utils.ErrorLog("good_type_id")
  2883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2884. return
  2885. }
  2886. good_type_id := int64(items["good_type_id"].(float64))
  2887. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  2888. utils.ErrorLog("count")
  2889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2890. return
  2891. }
  2892. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  2893. if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" {
  2894. utils.ErrorLog("ctime")
  2895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2896. return
  2897. }
  2898. ctime := int64(items["ctime"].(float64))
  2899. commdity_code := items["commdity_code"].(string)
  2900. prepare := &models.DialysisBeforePrepare{
  2901. ID: id,
  2902. UserOrgId: adminUser.Org.Id,
  2903. PatientId: patient_id,
  2904. RecordDate: record_time,
  2905. GoodId: good_id,
  2906. GoodTypeId: good_type_id,
  2907. Count: count,
  2908. Ctime: ctime,
  2909. Mtime: time.Now().Unix(),
  2910. Creater: creater,
  2911. Modifier: adminUser.AdminUser.Id,
  2912. Status: 1,
  2913. CommdityCode: commdity_code,
  2914. }
  2915. updateBeforePrepares = append(updateBeforePrepares, prepare)
  2916. }
  2917. }
  2918. //去重
  2919. updateBeforePrepares = RemoveRepeatedGood(updateBeforePrepares)
  2920. if len(updateBeforePrepares) > 0 {
  2921. for _, item := range updateBeforePrepares {
  2922. errs = service.UpdateDialysisBeforePrepareTwo(item)
  2923. }
  2924. }
  2925. }
  2926. if errs == nil {
  2927. c.ServeSuccessJSON(map[string]interface{}{
  2928. "msg": "提交成功",
  2929. })
  2930. return
  2931. } else {
  2932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2933. return
  2934. }
  2935. }
  2936. func (c *DialysisAPIController) CreateStockOutInfo() {
  2937. patient_id, _ := c.GetInt64("patient_id", 0)
  2938. record_date := c.GetString("record_time")
  2939. if patient_id <= 0 {
  2940. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2941. return
  2942. }
  2943. adminInfo := c.GetMobileAdminUserInfo()
  2944. timeLayout := "2006-01-02"
  2945. loc, _ := time.LoadLocation("Local")
  2946. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2947. record_time := theRecordTime.Unix()
  2948. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  2949. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  2950. consumables = RemoveRepeatedGood(consumables)
  2951. if record.IsOpen == 1 {
  2952. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  2953. if err == gorm.ErrRecordNotFound {
  2954. //没有记录,则创建出库单
  2955. timeStr := time.Now().Format("2006-01-02")
  2956. timeArr := strings.Split(timeStr, "-")
  2957. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  2958. total = total + 1
  2959. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2960. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2961. number = number + total
  2962. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2963. creater := adminInfo.AdminUser.Id
  2964. warehouseOut := models.WarehouseOut{
  2965. WarehouseOutOrderNumber: warehousing_out_order,
  2966. OperationTime: time.Now().Unix(),
  2967. OrgId: adminInfo.Org.Id,
  2968. Creater: creater,
  2969. Ctime: time.Now().Unix(),
  2970. Status: 1,
  2971. WarehouseOutTime: record_time,
  2972. Dealer: 0,
  2973. Manufacturer: 0,
  2974. Type: 1,
  2975. IsSys: 1,
  2976. }
  2977. err := service.AddSigleWarehouseOut(&warehouseOut)
  2978. if err != nil {
  2979. utils.TraceLog("创建出库单失败 err = %v", err)
  2980. } else {
  2981. for _, item := range consumables {
  2982. if item.Count > 0 {
  2983. warehouseOutInfo := &models.WarehouseOutInfo{
  2984. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2985. WarehouseOutId: warehouseOut.ID,
  2986. Status: 1,
  2987. Ctime: time.Now().Unix(),
  2988. Remark: "",
  2989. OrgId: adminInfo.Org.Id,
  2990. Type: 1,
  2991. Manufacturer: 0,
  2992. Dealer: 0,
  2993. IsSys: 1,
  2994. SysRecordTime: record_time,
  2995. GoodTypeId: item.GoodTypeId,
  2996. GoodId: item.GoodId,
  2997. }
  2998. warehouseOutInfo.Count = item.Count
  2999. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3000. warehouseOutInfo.Price = stockInInfo.Price
  3001. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3002. if err == nil {
  3003. details := &models.AutomaticReduceDetail{
  3004. WarehouseOutId: warehouseOutInfo.ID,
  3005. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3006. PatientId: patient_id,
  3007. Ctime: time.Now().Unix(),
  3008. Mtime: time.Now().Unix(),
  3009. Status: 1,
  3010. RecordTime: record_time,
  3011. OrgId: adminInfo.Org.Id,
  3012. GoodId: item.GoodId,
  3013. GoodTypeId: item.GoodTypeId,
  3014. Count: item.Count,
  3015. }
  3016. service.AddSigleAutoReduceRecordInfo(details)
  3017. }
  3018. }
  3019. }
  3020. }
  3021. } else if err == nil {
  3022. for _, item := range consumables {
  3023. outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber)
  3024. if err == gorm.ErrRecordNotFound {
  3025. warehouseOutInfo := &models.WarehouseOutInfo{
  3026. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3027. WarehouseOutId: out.ID,
  3028. Status: 1,
  3029. Ctime: time.Now().Unix(),
  3030. Remark: "",
  3031. OrgId: adminInfo.Org.Id,
  3032. Type: 1,
  3033. Manufacturer: 0,
  3034. Dealer: 0,
  3035. IsSys: 1,
  3036. SysRecordTime: record_time,
  3037. }
  3038. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3039. warehouseOutInfo.Price = stockInInfo.Price
  3040. warehouseOutInfo.GoodId = item.GoodId
  3041. warehouseOutInfo.GoodTypeId = item.GoodTypeId
  3042. warehouseOutInfo.Count = item.Count
  3043. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3044. if err == nil {
  3045. details := &models.AutomaticReduceDetail{
  3046. WarehouseOutId: warehouseOutInfo.ID,
  3047. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3048. PatientId: patient_id,
  3049. Ctime: time.Now().Unix(),
  3050. Mtime: time.Now().Unix(),
  3051. Status: 1,
  3052. RecordTime: record_time,
  3053. OrgId: adminInfo.Org.Id,
  3054. GoodId: item.GoodId,
  3055. GoodTypeId: item.GoodTypeId,
  3056. Count: item.Count,
  3057. }
  3058. service.AddSigleAutoReduceRecordInfo(details)
  3059. }
  3060. } else if err == nil { //记录存在,则将增加数量
  3061. if outInfo.ID > 0 {
  3062. service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count)
  3063. }
  3064. count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id)
  3065. if count == 0 {
  3066. details := &models.AutomaticReduceDetail{
  3067. WarehouseOutId: outInfo.ID,
  3068. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3069. PatientId: patient_id,
  3070. Ctime: time.Now().Unix(),
  3071. Mtime: time.Now().Unix(),
  3072. Status: 1,
  3073. RecordTime: record_time,
  3074. OrgId: adminInfo.Org.Id,
  3075. GoodId: item.GoodId,
  3076. GoodTypeId: item.GoodTypeId,
  3077. Count: item.Count,
  3078. }
  3079. service.AddSigleAutoReduceRecordInfo(details)
  3080. } else if count == 1 {
  3081. service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo)
  3082. }
  3083. }
  3084. }
  3085. }
  3086. c.ServeSuccessJSON(map[string]interface{}{
  3087. "msg": "提交成功",
  3088. })
  3089. return
  3090. } else {
  3091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  3092. return
  3093. }
  3094. }
  3095. func (c *DialysisAPIController) EditConsumables() {
  3096. patient_id, _ := c.GetInt64("patient_id", 0)
  3097. record_date := c.GetString("record_time")
  3098. if patient_id <= 0 {
  3099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3100. return
  3101. }
  3102. adminInfo := c.GetMobileAdminUserInfo()
  3103. timeLayout := "2006-01-02"
  3104. loc, _ := time.LoadLocation("Local")
  3105. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3106. record_time := theRecordTime.Unix()
  3107. dataBody := make(map[string]interface{}, 0)
  3108. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3109. if err != nil {
  3110. utils.ErrorLog(err.Error())
  3111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3112. return
  3113. }
  3114. var beforePrepares []*models.DialysisBeforePrepare
  3115. var newBeforePrepares []*models.DialysisBeforePrepare
  3116. //判断是否开启自动出库
  3117. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  3118. if record.IsOpen == 1 {
  3119. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  3120. goods, _ := dataBody["goods"].([]interface{})
  3121. fmt.Println("goods2222222222222", goods)
  3122. if len(goods) > 0 {
  3123. for _, item := range goods {
  3124. items := item.(map[string]interface{})
  3125. if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" {
  3126. utils.ErrorLog("record_time")
  3127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3128. return
  3129. }
  3130. record_time := int64(items["record_time"].(float64))
  3131. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3132. utils.ErrorLog("id")
  3133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3134. return
  3135. }
  3136. id := int64(items["id"].(float64))
  3137. if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" {
  3138. utils.ErrorLog("patient_id")
  3139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3140. return
  3141. }
  3142. patient_id := int64(items["patient_id"].(float64))
  3143. if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" {
  3144. utils.ErrorLog("creater")
  3145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3146. return
  3147. }
  3148. creater := int64(items["creater"].(float64))
  3149. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3150. utils.ErrorLog("good_id")
  3151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3152. return
  3153. }
  3154. good_id := int64(items["good_id"].(float64))
  3155. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3156. utils.ErrorLog("good_type_id")
  3157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3158. return
  3159. }
  3160. good_type_id := int64(items["good_type_id"].(float64))
  3161. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3162. utils.ErrorLog("count")
  3163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3164. return
  3165. }
  3166. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3167. if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" {
  3168. utils.ErrorLog("ctime")
  3169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3170. return
  3171. }
  3172. ctime := int64(items["ctime"].(float64))
  3173. commdity_code := items["commdity_code"].(string)
  3174. adminUser := c.GetMobileAdminUserInfo()
  3175. prepare := &models.DialysisBeforePrepare{
  3176. ID: id,
  3177. UserOrgId: adminUser.Org.Id,
  3178. PatientId: patient_id,
  3179. RecordDate: record_time,
  3180. GoodId: good_id,
  3181. GoodTypeId: good_type_id,
  3182. Count: count,
  3183. Ctime: ctime,
  3184. Mtime: time.Now().Unix(),
  3185. Creater: creater,
  3186. Modifier: adminUser.AdminUser.Id,
  3187. Status: 1,
  3188. CommdityCode: commdity_code,
  3189. }
  3190. beforePrepares = append(beforePrepares, prepare)
  3191. }
  3192. }
  3193. }
  3194. fmt.Println("hhhhhhhhhhhhhhhhhhhh", beforePrepares)
  3195. //查询今日患者出库列表
  3196. consumables_source, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  3197. if dataBody["new_goods"] != nil && reflect.TypeOf(dataBody["new_goods"]).String() == "[]interface {}" {
  3198. goods, _ := dataBody["new_goods"].([]interface{})
  3199. if len(goods) > 0 {
  3200. for _, item := range goods {
  3201. items := item.(map[string]interface{})
  3202. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3203. utils.ErrorLog("good_id")
  3204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3205. return
  3206. }
  3207. good_id := int64(items["good_id"].(float64))
  3208. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3209. utils.ErrorLog("good_type_id")
  3210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3211. return
  3212. }
  3213. good_type_id := int64(items["good_type_id"].(float64))
  3214. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3215. utils.ErrorLog("count")
  3216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3217. return
  3218. }
  3219. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3220. commdity_code := items["commdity_code"].(string)
  3221. fmt.Println("commdityecode", commdity_code)
  3222. adminUser := c.GetMobileAdminUserInfo()
  3223. prepare := &models.DialysisBeforePrepare{
  3224. UserOrgId: adminUser.Org.Id,
  3225. PatientId: patient_id,
  3226. RecordDate: record_time,
  3227. GoodId: good_id,
  3228. GoodTypeId: good_type_id,
  3229. Count: count,
  3230. Ctime: time.Now().Unix(),
  3231. Mtime: time.Now().Unix(),
  3232. Creater: adminUser.AdminUser.Id,
  3233. Modifier: 0,
  3234. CommdityCode: commdity_code,
  3235. }
  3236. newBeforePrepares = append(newBeforePrepares, prepare)
  3237. }
  3238. newBeforePrepares = RemoveRepeatedGood(newBeforePrepares)
  3239. }
  3240. //创建数据
  3241. service.CreateDialysisBeforePrepare(newBeforePrepares)
  3242. }
  3243. //查询是否有出库单
  3244. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  3245. fmt.Println("是否有出库单22222222222222222222222", err)
  3246. if err == gorm.ErrRecordNotFound {
  3247. //没有记录,则创建出库单
  3248. timeStr := time.Now().Format("2006-01-02")
  3249. timeArr := strings.Split(timeStr, "-")
  3250. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  3251. total = total + 1
  3252. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3253. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3254. number = number + total
  3255. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3256. creater := adminInfo.AdminUser.Id
  3257. warehouseOut := models.WarehouseOut{
  3258. WarehouseOutOrderNumber: warehousing_out_order,
  3259. OperationTime: time.Now().Unix(),
  3260. OrgId: adminInfo.Org.Id,
  3261. Creater: creater,
  3262. Ctime: time.Now().Unix(),
  3263. Status: 1,
  3264. WarehouseOutTime: record_time,
  3265. Dealer: 0,
  3266. Manufacturer: 0,
  3267. Type: 1,
  3268. IsSys: 1,
  3269. }
  3270. //创建出库单
  3271. err := service.AddSigleWarehouseOut(&warehouseOut)
  3272. fmt.Println("err", err)
  3273. if err != nil {
  3274. utils.TraceLog("创建出库单失败 err = %v", err)
  3275. } else {
  3276. for _, item := range beforePrepares {
  3277. if item.Count > 0 {
  3278. warehouseOutInfo := &models.WarehouseOutInfo{
  3279. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  3280. WarehouseOutId: warehouseOut.ID,
  3281. Count: 1,
  3282. Status: 1,
  3283. Ctime: time.Now().Unix(),
  3284. Remark: "",
  3285. OrgId: adminInfo.Org.Id,
  3286. Type: 1,
  3287. Manufacturer: 0,
  3288. Dealer: 0,
  3289. IsSys: 1,
  3290. SysRecordTime: record_time,
  3291. GoodTypeId: item.GoodTypeId,
  3292. GoodId: item.GoodId,
  3293. }
  3294. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3295. warehouseOutInfo.Price = stockInInfo.Price
  3296. //创建出库详情
  3297. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3298. if err == nil {
  3299. details := &models.AutomaticReduceDetail{
  3300. WarehouseOutId: warehouseOutInfo.ID,
  3301. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3302. PatientId: patient_id,
  3303. Ctime: time.Now().Unix(),
  3304. Mtime: time.Now().Unix(),
  3305. Status: 1,
  3306. RecordTime: record_time,
  3307. OrgId: adminInfo.Org.Id,
  3308. GoodId: item.GoodId,
  3309. GoodTypeId: item.GoodTypeId,
  3310. }
  3311. service.AddSigleAutoReduceRecordInfo(details)
  3312. }
  3313. }
  3314. }
  3315. }
  3316. //没有出库单创建
  3317. } else if err == nil {
  3318. if len(newBeforePrepares) > 0 { //新增
  3319. for _, item := range newBeforePrepares {
  3320. outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber)
  3321. if err == gorm.ErrRecordNotFound {
  3322. warehouseOutInfo := &models.WarehouseOutInfo{
  3323. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3324. WarehouseOutId: out.ID,
  3325. Status: 1,
  3326. Ctime: time.Now().Unix(),
  3327. Remark: "",
  3328. OrgId: adminInfo.Org.Id,
  3329. Type: 1,
  3330. Manufacturer: 0,
  3331. Dealer: 0,
  3332. IsSys: 1,
  3333. SysRecordTime: record_time,
  3334. }
  3335. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3336. warehouseOutInfo.Price = stockInInfo.Price
  3337. warehouseOutInfo.GoodId = item.GoodId
  3338. warehouseOutInfo.GoodTypeId = item.GoodTypeId
  3339. warehouseOutInfo.Count = item.Count
  3340. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3341. if err == nil {
  3342. count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id)
  3343. if count == 0 {
  3344. details := &models.AutomaticReduceDetail{
  3345. WarehouseOutId: warehouseOutInfo.ID,
  3346. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3347. PatientId: patient_id,
  3348. Ctime: time.Now().Unix(),
  3349. Mtime: time.Now().Unix(),
  3350. Status: 1,
  3351. RecordTime: record_time,
  3352. OrgId: adminInfo.Org.Id,
  3353. GoodId: item.GoodId,
  3354. GoodTypeId: item.GoodTypeId,
  3355. Count: item.Count,
  3356. }
  3357. service.AddSigleAutoReduceRecordInfo(details)
  3358. } else if count == 1 {
  3359. service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo)
  3360. }
  3361. }
  3362. } else if err == nil { //记录存在,则将加数量
  3363. if outInfo.ID > 0 {
  3364. service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count)
  3365. }
  3366. count, _ := service.FindPatientAutomaticReduceRecord(adminInfo.Org.Id, record_time, item.GoodId, item.GoodTypeId, patient_id)
  3367. if count == 0 {
  3368. details := &models.AutomaticReduceDetail{
  3369. WarehouseOutId: outInfo.ID,
  3370. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3371. PatientId: patient_id,
  3372. Ctime: time.Now().Unix(),
  3373. Mtime: time.Now().Unix(),
  3374. Status: 1,
  3375. RecordTime: record_time,
  3376. OrgId: adminInfo.Org.Id,
  3377. GoodId: item.GoodId,
  3378. GoodTypeId: item.GoodTypeId,
  3379. Count: item.Count,
  3380. }
  3381. service.AddSigleAutoReduceRecordInfo(details)
  3382. } else if count == 1 {
  3383. fmt.Println("llllllllllllllllllllll")
  3384. service.UpdateUserInfoDetails(item.GoodTypeId, item.GoodId, record_time, adminInfo.Org.Id, patient_id, item.Count, &outInfo)
  3385. }
  3386. //details := &models.AutomaticReduceDetail{
  3387. // WarehouseOutId: outInfo.ID,
  3388. // WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3389. // PatientId: patient_id,
  3390. // Ctime: time.Now().Unix(),
  3391. // Mtime: time.Now().Unix(),
  3392. // Status: 1,
  3393. // RecordTime: record_time,
  3394. // OrgId: adminInfo.Org.Id,
  3395. // GoodId: item.GoodId,
  3396. // GoodTypeId: item.GoodTypeId,
  3397. // Count: item.Count,
  3398. //}
  3399. //service.AddSigleAutoReduceRecordInfo(details)
  3400. }
  3401. }
  3402. }
  3403. if len(beforePrepares) > 0 { //修改
  3404. for _, consumable := range consumables_source {
  3405. for _, before := range beforePrepares {
  3406. if consumable.GoodId == before.GoodId {
  3407. if consumable.Count != before.Count {
  3408. _, out := service.FindStockOutOrderNumberByTime(record_time, adminInfo.Org.Id)
  3409. //_, out := service.FindOldOrderInfoByGoodId(record_time, adminInfo.Org.Id)
  3410. //判断前端更改后的商品id的出库记录在数据库中是否存在
  3411. err, newOut := service.FindOrderInfoByGoodId(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id)
  3412. fmt.Println("err222222222222222222", err)
  3413. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  3414. warehouseOutInfo := &models.WarehouseOutInfo{
  3415. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3416. WarehouseOutId: out.ID,
  3417. Count: before.Count,
  3418. Status: 1,
  3419. Ctime: time.Now().Unix(),
  3420. Remark: "",
  3421. OrgId: adminInfo.Org.Id,
  3422. Type: 1,
  3423. Manufacturer: 0,
  3424. Dealer: 0,
  3425. IsSys: 1,
  3426. SysRecordTime: record_time,
  3427. }
  3428. stockInInfo, _ := service.FindLastStockInInfoRecord(before.GoodId, adminInfo.Org.Id)
  3429. warehouseOutInfo.Price = stockInInfo.Price
  3430. warehouseOutInfo.GoodId = before.GoodId
  3431. warehouseOutInfo.GoodTypeId = before.GoodTypeId
  3432. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3433. fmt.Println("err2223444444444444444444", err)
  3434. if err == nil {
  3435. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  3436. user, err := service.FindGoodUserById(before.GoodTypeId, before.GoodId, patient_id, adminInfo.Org.Id, record_time)
  3437. if err == gorm.ErrRecordNotFound {
  3438. details := &models.AutomaticReduceDetail{
  3439. WarehouseOutId: warehouseOutInfo.ID,
  3440. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3441. PatientId: patient_id,
  3442. Ctime: time.Now().Unix(),
  3443. Mtime: time.Now().Unix(),
  3444. Status: 1,
  3445. RecordTime: record_time,
  3446. OrgId: adminInfo.Org.Id,
  3447. GoodId: consumable.GoodId,
  3448. GoodTypeId: consumable.GoodTypeId,
  3449. Count: before.Count,
  3450. }
  3451. service.AddSigleAutoReduceRecordInfo(details)
  3452. } else if err == nil {
  3453. if user.ID > 0 {
  3454. //service.UpdateOrderInfoDetails( consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, a_liquid, warehouseOutInfo)
  3455. service.UpdateUserInfoDetails(consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, before.Count, warehouseOutInfo)
  3456. }
  3457. }
  3458. }
  3459. } else if err == nil { //存在,则更改使用人商品信息
  3460. fmt.Println("333333333")
  3461. //处理原来的数据
  3462. if newOut.ID > 0 {
  3463. if consumable.Count > before.Count { // 减少
  3464. num := int64(0)
  3465. if consumable.Count-before.Count > 0 {
  3466. num = consumable.Count - before.Count
  3467. } else {
  3468. num = before.Count - consumable.Count
  3469. }
  3470. service.UpdateOrderCountSub(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id, num)
  3471. } else if consumable.Count < before.Count { //增加
  3472. service.UpdateOrderCountAdd(consumable.GoodTypeId, consumable.GoodId, out.WarehouseOutOrderNumber, adminInfo.Org.Id, before.Count-consumable.Count)
  3473. }
  3474. user, err := service.FindGoodUserById(consumable.GoodTypeId, consumable.GoodId, patient_id, adminInfo.Org.Id, record_time)
  3475. if err == gorm.ErrRecordNotFound {
  3476. details := &models.AutomaticReduceDetail{
  3477. WarehouseOutId: newOut.ID,
  3478. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  3479. PatientId: patient_id,
  3480. Ctime: time.Now().Unix(),
  3481. Mtime: time.Now().Unix(),
  3482. Status: 1,
  3483. RecordTime: record_time,
  3484. OrgId: adminInfo.Org.Id,
  3485. GoodId: consumable.GoodId,
  3486. GoodTypeId: consumable.GoodTypeId,
  3487. Count: before.Count,
  3488. }
  3489. service.AddSigleAutoReduceRecordInfo(details)
  3490. } else if err == nil {
  3491. if user.ID > 0 {
  3492. service.UpdateUserInfoDetails(consumable.GoodTypeId, consumable.GoodId, record_time, adminInfo.Org.Id, patient_id, before.Count, &newOut)
  3493. }
  3494. }
  3495. }
  3496. }
  3497. }
  3498. }
  3499. }
  3500. }
  3501. }
  3502. }
  3503. //更新自动出库的地方
  3504. var errs error
  3505. if len(beforePrepares) > 0 {
  3506. for _, item := range beforePrepares {
  3507. errs = service.UpdateDialysisBeforePrepareTwo(item)
  3508. detail := models.AutomaticReduceDetail{
  3509. PatientId: item.PatientId,
  3510. Status: 1,
  3511. RecordTime: item.RecordDate,
  3512. OrgId: item.UserOrgId,
  3513. GoodId: item.GoodId,
  3514. GoodTypeId: item.GoodTypeId,
  3515. Count: item.Count,
  3516. }
  3517. service.UpdateAutoReduceDetailSix(&detail)
  3518. }
  3519. }
  3520. if errs == nil {
  3521. c.ServeSuccessJSON(map[string]interface{}{
  3522. "msg": "修改成功",
  3523. })
  3524. return
  3525. } else {
  3526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3527. return
  3528. }
  3529. } else {
  3530. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  3531. goods, _ := dataBody["goods"].([]interface{})
  3532. if len(goods) > 0 {
  3533. for _, item := range goods {
  3534. items := item.(map[string]interface{})
  3535. if items["record_time"] == nil || reflect.TypeOf(items["record_time"]).String() != "float64" {
  3536. utils.ErrorLog("record_time")
  3537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3538. return
  3539. }
  3540. record_time := int64(items["record_time"].(float64))
  3541. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3542. utils.ErrorLog("id")
  3543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3544. return
  3545. }
  3546. id := int64(items["id"].(float64))
  3547. if items["patient_id"] == nil || reflect.TypeOf(items["patient_id"]).String() != "float64" {
  3548. utils.ErrorLog("patient_id")
  3549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3550. return
  3551. }
  3552. patient_id := int64(items["patient_id"].(float64))
  3553. if items["creater"] == nil || reflect.TypeOf(items["creater"]).String() != "float64" {
  3554. utils.ErrorLog("creater")
  3555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3556. return
  3557. }
  3558. creater := int64(items["creater"].(float64))
  3559. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3560. utils.ErrorLog("good_id")
  3561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3562. return
  3563. }
  3564. good_id := int64(items["good_id"].(float64))
  3565. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3566. utils.ErrorLog("good_type_id")
  3567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3568. return
  3569. }
  3570. good_type_id := int64(items["good_type_id"].(float64))
  3571. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3572. utils.ErrorLog("count")
  3573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3574. return
  3575. }
  3576. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3577. if items["ctime"] == nil || reflect.TypeOf(items["ctime"]).String() != "float64" {
  3578. utils.ErrorLog("ctime")
  3579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3580. return
  3581. }
  3582. ctime := int64(items["ctime"].(float64))
  3583. adminUser := c.GetMobileAdminUserInfo()
  3584. prepare := &models.DialysisBeforePrepare{
  3585. ID: id,
  3586. UserOrgId: adminUser.Org.Id,
  3587. PatientId: patient_id,
  3588. RecordDate: record_time,
  3589. GoodId: good_id,
  3590. GoodTypeId: good_type_id,
  3591. Count: count,
  3592. Ctime: ctime,
  3593. Mtime: time.Now().Unix(),
  3594. Creater: creater,
  3595. Modifier: adminUser.AdminUser.Id,
  3596. Status: 1,
  3597. }
  3598. beforePrepares = append(beforePrepares, prepare)
  3599. }
  3600. }
  3601. }
  3602. if dataBody["new_goods"] != nil && reflect.TypeOf(dataBody["new_goods"]).String() == "[]interface {}" {
  3603. goods, _ := dataBody["new_goods"].([]interface{})
  3604. if len(goods) > 0 {
  3605. for _, item := range goods {
  3606. items := item.(map[string]interface{})
  3607. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3608. utils.ErrorLog("good_id")
  3609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3610. return
  3611. }
  3612. good_id := int64(items["good_id"].(float64))
  3613. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3614. utils.ErrorLog("good_type_id")
  3615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3616. return
  3617. }
  3618. good_type_id := int64(items["good_type_id"].(float64))
  3619. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3620. utils.ErrorLog("count")
  3621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3622. return
  3623. }
  3624. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3625. adminUser := c.GetMobileAdminUserInfo()
  3626. prepare := &models.DialysisBeforePrepare{
  3627. UserOrgId: adminUser.Org.Id,
  3628. PatientId: patient_id,
  3629. RecordDate: record_time,
  3630. GoodId: good_id,
  3631. GoodTypeId: good_type_id,
  3632. Count: count,
  3633. Ctime: time.Now().Unix(),
  3634. Mtime: time.Now().Unix(),
  3635. Creater: adminUser.AdminUser.Id,
  3636. Modifier: 0,
  3637. }
  3638. newBeforePrepares = append(newBeforePrepares, prepare)
  3639. }
  3640. }
  3641. service.CreateDialysisBeforePrepare(newBeforePrepares)
  3642. }
  3643. var errs error
  3644. if len(beforePrepares) > 0 {
  3645. for _, item := range beforePrepares {
  3646. errs = service.UpdateDialysisBeforePrepareTwo(item)
  3647. }
  3648. }
  3649. if errs == nil {
  3650. c.ServeSuccessJSON(map[string]interface{}{
  3651. "msg": "修改成功",
  3652. })
  3653. return
  3654. } else {
  3655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3656. return
  3657. }
  3658. }
  3659. }
  3660. func (c *DialysisAPIController) GetDialysisGoods() {
  3661. schedualDate := c.GetString("schedule_date")
  3662. schedule_type, _ := c.GetInt64("schedule_type")
  3663. partition_id, _ := c.GetInt64("partition_id")
  3664. page, _ := c.GetInt("page")
  3665. patient_id, _ := c.GetInt64("patient_id")
  3666. schedualEndDate := int64(0)
  3667. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  3668. if parseDateErr != nil && len(schedualDate) != 0 {
  3669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3670. return
  3671. }
  3672. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  3673. if parseDateErr != nil && len(schedualDate) != 0 {
  3674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3675. return
  3676. }
  3677. schedualEndDate = endDate.Unix()
  3678. adminUser := c.GetMobileAdminUserInfo()
  3679. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  3680. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  3681. //获取当天该病人的透析处方
  3682. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  3683. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  3684. if err == gorm.ErrRecordNotFound {
  3685. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  3686. if patient_id != 0 {
  3687. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  3688. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  3689. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  3690. item.LastAutomaticReduceDetail = goodUser
  3691. item.LastDialysisBeforePrepare = lastGoodUserDetial
  3692. }
  3693. }
  3694. c.ServeSuccessJSON(map[string]interface{}{
  3695. "dialysis_goods": dialysisGoods,
  3696. "good_type": goodTypes,
  3697. "total": total,
  3698. "prescribe": prescribe,
  3699. "good_info": good_info,
  3700. })
  3701. return
  3702. } else if err == nil {
  3703. //获取当天排班的每个患者的库存使用情况
  3704. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  3705. if patient_id != 0 {
  3706. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  3707. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  3708. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  3709. fmt.Println(goodUser)
  3710. fmt.Println(lastGoodUserDetial)
  3711. item.LastAutomaticReduceDetail = goodUser
  3712. item.LastDialysisBeforePrepare = lastGoodUserDetial
  3713. }
  3714. }
  3715. if err == nil {
  3716. c.ServeSuccessJSON(map[string]interface{}{
  3717. "dialysis_goods": dialysisGoods,
  3718. "good_type": goodTypes,
  3719. "total": total,
  3720. "prescribe": prescribe,
  3721. "good_info": good_info,
  3722. })
  3723. return
  3724. } else {
  3725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3726. return
  3727. }
  3728. } else if err != nil {
  3729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3730. return
  3731. }
  3732. }
  3733. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  3734. start_time := c.GetString("start_time")
  3735. end_time := c.GetString("end_time")
  3736. timeLayout := "2006-01-02"
  3737. loc, _ := time.LoadLocation("Local")
  3738. var theStartTime int64
  3739. if len(start_time) > 0 {
  3740. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3741. if err != nil {
  3742. utils.ErrorLog(err.Error())
  3743. }
  3744. theStartTime = theTime.Unix()
  3745. }
  3746. var theEndtTime int64
  3747. if len(end_time) > 0 {
  3748. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3749. if err != nil {
  3750. utils.ErrorLog(err.Error())
  3751. }
  3752. theEndtTime = theTime.Unix()
  3753. }
  3754. adminUser := c.GetMobileAdminUserInfo()
  3755. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  3756. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  3757. if err == nil {
  3758. c.ServeSuccessJSON(map[string]interface{}{
  3759. "stock_out": outInfo,
  3760. "stockCount": stockCount,
  3761. })
  3762. return
  3763. } else {
  3764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3765. return
  3766. }
  3767. }
  3768. func (c *DialysisAPIController) GetStockInGoodInfo() {
  3769. patient_id, _ := c.GetInt64("patient_id", 0)
  3770. record_time := c.GetString("record_time")
  3771. adminUser := c.GetMobileAdminUserInfo()
  3772. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  3773. if parseDateErr != nil && len(record_time) != 0 {
  3774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3775. return
  3776. }
  3777. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  3778. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  3779. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  3780. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  3781. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  3782. //获取今日患者的透析处方参数
  3783. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  3784. c.ServeSuccessJSON(map[string]interface{}{
  3785. "good_type": goodTypes,
  3786. "good_user": goodUser,
  3787. "good_info": good_info,
  3788. "last_good_user": lastGoodUserDetial,
  3789. "project": project,
  3790. "prescription": prescribe,
  3791. })
  3792. return
  3793. }
  3794. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  3795. patient_id, _ := c.GetInt64("patient_id", 0)
  3796. record_date := c.GetString("record_time")
  3797. if patient_id <= 0 {
  3798. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3799. return
  3800. }
  3801. adminInfo := c.GetMobileAdminUserInfo()
  3802. timeLayout := "2006-01-02"
  3803. loc, _ := time.LoadLocation("Local")
  3804. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3805. record_time := theRecordTime.Unix()
  3806. dataBody := make(map[string]interface{}, 0)
  3807. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3808. if err != nil {
  3809. utils.ErrorLog(err.Error())
  3810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3811. return
  3812. }
  3813. var beforePrepares []*models.DialysisBeforePrepare
  3814. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  3815. goods, _ := dataBody["goods"].([]interface{})
  3816. if len(goods) > 0 {
  3817. for _, item := range goods {
  3818. items := item.(map[string]interface{})
  3819. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  3820. utils.ErrorLog("good_id")
  3821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3822. return
  3823. }
  3824. good_id := int64(items["good_id"].(float64))
  3825. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  3826. utils.ErrorLog("good_type_id")
  3827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3828. return
  3829. }
  3830. good_type_id := int64(items["good_type_id"].(float64))
  3831. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  3832. utils.ErrorLog("count")
  3833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3834. return
  3835. }
  3836. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  3837. adminUser := c.GetMobileAdminUserInfo()
  3838. prepare := &models.DialysisBeforePrepare{
  3839. UserOrgId: adminUser.Org.Id,
  3840. PatientId: patient_id,
  3841. RecordDate: record_time,
  3842. GoodId: good_id,
  3843. GoodTypeId: good_type_id,
  3844. Count: count,
  3845. Ctime: time.Now().Unix(),
  3846. Mtime: time.Now().Unix(),
  3847. Creater: adminUser.AdminUser.Id,
  3848. Modifier: 0,
  3849. }
  3850. record_count := service.FindDialysisBeforePrepare(prepare.PatientId, prepare.GoodId, prepare.GoodTypeId, adminUser.Org.Id, record_time)
  3851. if record_count == 0 {
  3852. beforePrepares = append(beforePrepares, prepare)
  3853. } else if record_count == 1 {
  3854. service.UpdateDialysisBeforePrepareTwo(prepare)
  3855. }
  3856. }
  3857. }
  3858. }
  3859. beforePrepares = RemoveRepeatedGood(beforePrepares)
  3860. if len(beforePrepares) > 0 {
  3861. service.CreateDialysisBeforePrepare(beforePrepares)
  3862. }
  3863. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  3864. //去重
  3865. consumables = RemoveRepeatedGood(consumables)
  3866. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  3867. if record.IsOpen == 1 {
  3868. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  3869. if err == gorm.ErrRecordNotFound {
  3870. //没有记录,则创建出库单
  3871. timeStr := time.Now().Format("2006-01-02")
  3872. timeArr := strings.Split(timeStr, "-")
  3873. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  3874. total = total + 1
  3875. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3876. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3877. number = number + total
  3878. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3879. creater := adminInfo.AdminUser.Id
  3880. warehouseOut := models.WarehouseOut{
  3881. WarehouseOutOrderNumber: warehousing_out_order,
  3882. OperationTime: time.Now().Unix(),
  3883. OrgId: adminInfo.Org.Id,
  3884. Creater: creater,
  3885. Ctime: time.Now().Unix(),
  3886. Status: 1,
  3887. WarehouseOutTime: record_time,
  3888. Dealer: 0,
  3889. Manufacturer: 0,
  3890. Type: 1,
  3891. IsSys: 1,
  3892. }
  3893. err := service.AddSigleWarehouseOut(&warehouseOut)
  3894. if err != nil {
  3895. utils.TraceLog("创建出库单失败 err = %v", err)
  3896. } else {
  3897. for _, item := range consumables {
  3898. if item.Count > 0 {
  3899. warehouseOutInfo := &models.WarehouseOutInfo{
  3900. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  3901. WarehouseOutId: warehouseOut.ID,
  3902. Status: 1,
  3903. Ctime: time.Now().Unix(),
  3904. Remark: "",
  3905. OrgId: adminInfo.Org.Id,
  3906. Type: 1,
  3907. Manufacturer: 0,
  3908. Dealer: 0,
  3909. IsSys: 1,
  3910. SysRecordTime: record_time,
  3911. GoodTypeId: item.GoodTypeId,
  3912. GoodId: item.GoodId,
  3913. }
  3914. warehouseOutInfo.Count = item.Count
  3915. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3916. warehouseOutInfo.Price = stockInInfo.Price
  3917. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3918. if err == nil {
  3919. details := &models.AutomaticReduceDetail{
  3920. WarehouseOutId: warehouseOutInfo.ID,
  3921. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3922. PatientId: patient_id,
  3923. Ctime: time.Now().Unix(),
  3924. Mtime: time.Now().Unix(),
  3925. Status: 1,
  3926. RecordTime: record_time,
  3927. OrgId: adminInfo.Org.Id,
  3928. GoodId: item.GoodId,
  3929. GoodTypeId: item.GoodTypeId,
  3930. Count: item.Count,
  3931. }
  3932. service.AddSigleAutoReduceRecordInfo(details)
  3933. }
  3934. }
  3935. }
  3936. }
  3937. } else if err == nil {
  3938. for _, item := range consumables {
  3939. outInfo, err := service.FindStockOutInfoByTypeId(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, out.ID, out.WarehouseOutOrderNumber)
  3940. if err == gorm.ErrRecordNotFound {
  3941. warehouseOutInfo := &models.WarehouseOutInfo{
  3942. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3943. WarehouseOutId: out.ID,
  3944. Status: 1,
  3945. Ctime: time.Now().Unix(),
  3946. Remark: "",
  3947. OrgId: adminInfo.Org.Id,
  3948. Type: 1,
  3949. Manufacturer: 0,
  3950. Dealer: 0,
  3951. IsSys: 1,
  3952. SysRecordTime: record_time,
  3953. }
  3954. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  3955. warehouseOutInfo.Price = stockInInfo.Price
  3956. warehouseOutInfo.GoodId = item.GoodId
  3957. warehouseOutInfo.GoodTypeId = item.GoodTypeId
  3958. warehouseOutInfo.Count = item.Count
  3959. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3960. if err == nil {
  3961. details := &models.AutomaticReduceDetail{
  3962. WarehouseOutId: warehouseOutInfo.ID,
  3963. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3964. PatientId: patient_id,
  3965. Ctime: time.Now().Unix(),
  3966. Mtime: time.Now().Unix(),
  3967. Status: 1,
  3968. RecordTime: record_time,
  3969. OrgId: adminInfo.Org.Id,
  3970. GoodId: item.GoodId,
  3971. GoodTypeId: item.GoodTypeId,
  3972. Count: item.Count,
  3973. }
  3974. service.AddSigleAutoReduceRecordInfo(details)
  3975. }
  3976. } else if err == nil { //记录存在,则将增加数量
  3977. if outInfo.ID > 0 {
  3978. service.UpdateStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, item.Count)
  3979. }
  3980. details := &models.AutomaticReduceDetail{
  3981. WarehouseOutId: outInfo.ID,
  3982. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3983. PatientId: patient_id,
  3984. Ctime: time.Now().Unix(),
  3985. Mtime: time.Now().Unix(),
  3986. Status: 1,
  3987. RecordTime: record_time,
  3988. OrgId: adminInfo.Org.Id,
  3989. GoodId: item.GoodId,
  3990. GoodTypeId: item.GoodTypeId,
  3991. Count: item.Count,
  3992. }
  3993. service.AddSigleAutoReduceRecordInfo(details)
  3994. }
  3995. }
  3996. }
  3997. c.ServeSuccessJSON(map[string]interface{}{
  3998. "msg": "提交成功",
  3999. })
  4000. return
  4001. } else {
  4002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  4003. return
  4004. }
  4005. }
  4006. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  4007. newArr = make([]*models.DialysisBeforePrepare, 0)
  4008. for i := 0; i < len(arr); i++ {
  4009. repeat := false
  4010. for j := i + 1; j < len(arr); j++ {
  4011. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  4012. repeat = true
  4013. break
  4014. }
  4015. }
  4016. if !repeat {
  4017. newArr = append(newArr, arr[i])
  4018. }
  4019. }
  4020. return
  4021. }
  4022. func (c *DialysisAPIController) GetAllDrug() {
  4023. patient_id, _ := c.GetInt64("patient_id", 0)
  4024. adminInfo := c.GetMobileAdminUserInfo()
  4025. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  4026. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  4027. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  4028. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  4029. c.ServeSuccessJSON(map[string]interface{}{
  4030. "base_drug_config": drugStockConfig,
  4031. "private_drug_config": privateDrugConfig,
  4032. "base_drug_list": drugList,
  4033. "private_drug_list": privateDrugList,
  4034. })
  4035. }
  4036. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  4037. newArr = make([]*models.DialysisBeforePrepare, 0)
  4038. for i := 0; i < len(arr); i++ {
  4039. repeat := false
  4040. for j := i + 1; j < len(arr); j++ {
  4041. if arr[i].GoodId == arr[j].GoodId {
  4042. repeat = true
  4043. break
  4044. }
  4045. }
  4046. if !repeat {
  4047. newArr = append(newArr, arr[i])
  4048. }
  4049. }
  4050. return
  4051. }
  4052. func (c *DialysisAPIController) GetDepartment() {
  4053. adminInfo := c.GetMobileAdminUserInfo()
  4054. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  4055. if err == nil {
  4056. c.ServeSuccessJSON(map[string]interface{}{
  4057. "departments": departments,
  4058. })
  4059. } else {
  4060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4061. return
  4062. }
  4063. }
  4064. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  4065. types, _ := c.GetInt("type", 0)
  4066. start_time := c.GetString("start_time")
  4067. end_time := c.GetString("end_time")
  4068. orgId := c.GetMobileAdminUserInfo().Org.Id
  4069. timeLayout := "2006-01-02"
  4070. loc, _ := time.LoadLocation("Local")
  4071. var startTime int64
  4072. if len(start_time) > 0 {
  4073. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4074. if err != nil {
  4075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4076. return
  4077. }
  4078. startTime = theTime.Unix()
  4079. }
  4080. var endTime int64
  4081. if len(end_time) > 0 {
  4082. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4083. if err != nil {
  4084. utils.ErrorLog(err.Error())
  4085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4086. return
  4087. }
  4088. endTime = theTime.Unix()
  4089. }
  4090. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  4091. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  4092. if err != nil {
  4093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4094. } else {
  4095. c.ServeSuccessJSON(map[string]interface{}{
  4096. "list": list,
  4097. "type": types,
  4098. "stockTotal": stockTotal,
  4099. })
  4100. }
  4101. }
  4102. func (c *DialysisAPIController) BatchDeleteMonitor() {
  4103. fmt.Println("jin2222245555555555")
  4104. ids := c.GetString("ids")
  4105. fmt.Println("dis22222222", ids)
  4106. idArray := strings.Split(ids, ",")
  4107. err := service.BatchDeleteMonitor(idArray)
  4108. fmt.Print("err", err)
  4109. c.ServeSuccessJSON(map[string]interface{}{
  4110. "msg": "批量删除成功",
  4111. })
  4112. return
  4113. }
  4114. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  4115. id, _ := c.GetInt64("id")
  4116. fmt.Println(id)
  4117. timeLayout := "2006-01-02"
  4118. loc, _ := time.LoadLocation("Local")
  4119. start_time := time.Now().Format("2006-01-02")
  4120. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4121. fmt.Println("start_timestart_time", start_time)
  4122. nowTime := time.Now()
  4123. endTime := nowTime.AddDate(-1, 0, 0)
  4124. endTimes := endTime.Format("2006-01-02")
  4125. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", endTimes+" 00:00:00", loc)
  4126. list, _ := service.GetPatientDialysisRecordList(id, endtime.Unix(), startime.Unix())
  4127. c.ServeSuccessJSON(map[string]interface{}{
  4128. "list": list,
  4129. })
  4130. return
  4131. }
  4132. func (c *DialysisAPIController) BathDeleteAdviceList() {
  4133. dataBody := make(map[string]interface{}, 0)
  4134. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4135. ids := c.GetString("ids")
  4136. fmt.Println("dis22222222", ids)
  4137. idArray := strings.Split(ids, ",")
  4138. origin, _ := c.GetInt64("origin")
  4139. if origin == 1 {
  4140. err = service.BatchDeleteAdvice(idArray)
  4141. fmt.Print("err", err)
  4142. c.ServeSuccessJSON(map[string]interface{}{
  4143. "msg": "批量删除成功",
  4144. })
  4145. return
  4146. }
  4147. if origin == 2 {
  4148. service.BatchDeleteHisAdvice(idArray)
  4149. }
  4150. }
  4151. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  4152. good_id, _ := c.GetInt64("good_id")
  4153. count, _ := c.GetInt64("count")
  4154. record_time, _ := c.GetInt64("record_time")
  4155. patient_id, _ := c.GetInt64("patient_id")
  4156. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  4157. c.ServeSuccessJSON(map[string]interface{}{
  4158. "detail": detail,
  4159. })
  4160. return
  4161. }
  4162. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  4163. good_id, _ := c.GetInt64("good_id")
  4164. record_time, _ := c.GetInt64("record_time")
  4165. patient_id, _ := c.GetInt64("patient_id")
  4166. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  4167. fmt.Print("err", err)
  4168. c.ServeSuccessJSON(map[string]interface{}{
  4169. "msg": "批量删除成功",
  4170. })
  4171. return
  4172. }
  4173. func (c *DialysisAPIController) BatchAdviceCheck() {
  4174. ids := c.GetString("ids")
  4175. idArray := strings.Split(ids, ",")
  4176. creator, _ := c.GetInt64("creator")
  4177. origin, _ := c.GetInt64("origin")
  4178. if origin == 1 {
  4179. err := service.BatchAdviceCheck(idArray, creator)
  4180. fmt.Println(err)
  4181. list, _ := service.GetAdviceExecutionById(idArray)
  4182. c.ServeSuccessJSON(map[string]interface{}{
  4183. "list": list,
  4184. })
  4185. return
  4186. }
  4187. if origin == 2 {
  4188. service.BatchHisAdviceCheck(idArray, creator)
  4189. list, _ := service.GetHisAdviceExecutionById(idArray)
  4190. c.ServeSuccessJSON(map[string]interface{}{
  4191. "list": list,
  4192. })
  4193. return
  4194. }
  4195. }
  4196. func (c *DialysisAPIController) BatchAdviceExecution() {
  4197. ids := c.GetString("ids")
  4198. fmt.Println("dis22222222", ids)
  4199. idArray := strings.Split(ids, ",")
  4200. executionTime := c.GetString("execution_time")
  4201. fmt.Println("333333333", executionTime)
  4202. creator, _ := c.GetInt64("creator")
  4203. timeLayout := "2006-01-02 15:04:05"
  4204. loc, _ := time.LoadLocation("Local")
  4205. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  4206. orgin, _ := c.GetInt64("origin")
  4207. if orgin == 1 {
  4208. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  4209. list, _ := service.GetAdviceExecutionById(idArray)
  4210. fmt.Println(err)
  4211. c.ServeSuccessJSON(map[string]interface{}{
  4212. "list": list,
  4213. })
  4214. return
  4215. }
  4216. if orgin == 2 {
  4217. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  4218. list, _ := service.GetHisAdviceExecutionById(idArray)
  4219. fmt.Println(err)
  4220. c.ServeSuccessJSON(map[string]interface{}{
  4221. "list": list,
  4222. })
  4223. return
  4224. }
  4225. }