dialysis_api_controller.go 160KB

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