dialysis_api_controller.go 169KB

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