dialysis_api_controller.go 168KB

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