dialysis_api_controller.go 159KB

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