patient_api_controller.go 186KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250
  1. package mobile_api_controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/jinzhu/gorm"
  10. "math"
  11. "strings"
  12. // "fmt"
  13. "reflect"
  14. "strconv"
  15. "time"
  16. )
  17. type PatientApiController struct {
  18. MobileBaseAPIAuthController
  19. }
  20. func (c *PatientApiController) GetPatientInfoWithDiseases() {
  21. id, _ := c.GetInt64("patient", 0)
  22. if id <= 0 {
  23. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  24. return
  25. }
  26. adminUserInfo := c.GetMobileAdminUserInfo()
  27. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  28. if patient.ID == 0 {
  29. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  30. return
  31. }
  32. Registrars, err := service.GetAdminUser(adminUserInfo.Org.Id, adminUserInfo.App.Id, patient.RegistrarsId)
  33. if err != nil {
  34. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. return
  36. }
  37. if Registrars != nil {
  38. patient.Registrars = Registrars.Name
  39. }
  40. c.ServeSuccessJSON(map[string]interface{}{
  41. "patient": patient,
  42. })
  43. return
  44. }
  45. func (c *PatientApiController) CreateDialysisSolution() {
  46. id, _ := c.GetInt64("patient", 0)
  47. if id <= 0 {
  48. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  49. return
  50. }
  51. adminUserInfo := c.GetMobileAdminUserInfo()
  52. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  53. if patient.ID == 0 {
  54. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  55. return
  56. }
  57. //根据路由来做权限
  58. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  59. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  60. //if template.TemplateId == 2 || template.TemplateId == 6 {
  61. // if appRole.UserType == 3 {
  62. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  63. // if getPermissionErr != nil {
  64. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  65. // return
  66. // } else if headNursePermission == nil {
  67. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  68. // return
  69. // }
  70. // }
  71. //}
  72. var solution models.DialysisSolution
  73. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  74. if code > 0 {
  75. c.ServeFailJSONWithSGJErrorCode(code)
  76. return
  77. }
  78. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  79. solution.Doctor = adminUserInfo.AdminUser.Id
  80. solution.Status = 1
  81. solution.PatientId = id
  82. solution.CreatedTime = time.Now().Unix()
  83. solution.UserOrgId = adminUserInfo.Org.Id
  84. solution.UpdatedTime = time.Now().Unix()
  85. solution.SubName = ""
  86. solution.ParentId = 0
  87. err := service.CreatePatientDialysisSolution(&solution)
  88. if err != nil {
  89. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  90. return
  91. }
  92. c.ServeSuccessJSON(map[string]interface{}{
  93. "msg": "ok",
  94. "solution": solution,
  95. })
  96. return
  97. }
  98. func (c *PatientApiController) EditDialysisSolution() {
  99. id, _ := c.GetInt64("id", 0)
  100. if id <= 0 {
  101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  102. return
  103. }
  104. adminUserInfo := c.GetMobileAdminUserInfo()
  105. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.Org.Id, id)
  106. if solution.ID == 0 {
  107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  108. return
  109. }
  110. //if solution.Doctor != adminUserInfo.AdminUser.Id {
  111. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  112. // if getPermissionErr != nil {
  113. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  114. // return
  115. // } else if headNursePermission == nil {
  116. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  117. // return
  118. // }
  119. //}
  120. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "update")
  121. if code > 0 {
  122. c.ServeFailJSONWithSGJErrorCode(code)
  123. return
  124. }
  125. // solution.RegistrarsId = adminUserInfo.AdminUser.Id
  126. solution.Doctor = adminUserInfo.AdminUser.Id
  127. solution.Status = 1
  128. // solution.PatientId = id
  129. // solution.CreatedTime = time.Now().Unix()
  130. // solution.UserOrgId = adminUserInfo.Org.Id
  131. solution.UpdatedTime = time.Now().Unix()
  132. // solution.SubName = ""
  133. // solution.ParentId = 0
  134. err := service.UpdatePatientDialysisSolution(&solution)
  135. if err != nil {
  136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  137. return
  138. }
  139. c.ServeSuccessJSON(map[string]interface{}{
  140. "msg": "ok",
  141. "solution": solution,
  142. })
  143. return
  144. }
  145. func (c *PatientApiController) CreateDoctorAdvice() {
  146. patient, _ := c.GetInt64("id", 0)
  147. if patient <= 0 {
  148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  149. return
  150. }
  151. adminUserInfo := c.GetMobileAdminUserInfo()
  152. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  153. if patientInfo.ID == 0 {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  155. return
  156. }
  157. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  158. //if appRole.UserType == 3{
  159. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdvicePermissionDeniedModify)
  160. // return
  161. //}
  162. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  163. //
  164. //if appRole.UserType == 3 {
  165. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  166. // if getPermissionErr != nil {
  167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  168. // return
  169. // } else if headNursePermission == nil {
  170. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  171. // return
  172. // }
  173. //}
  174. var advice models.DoctorAdvice
  175. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  176. if code > 0 {
  177. c.ServeFailJSONWithSGJErrorCode(code)
  178. return
  179. }
  180. if advice.ParentId > 0 {
  181. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  182. if old.ID == 0 || old.PatientId != patient {
  183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  184. return
  185. }
  186. if old.StopState == 1 || old.ExecutionState == 1 {
  187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  188. return
  189. }
  190. if old.ParentId > 0 {
  191. advice.ParentId = old.ParentId
  192. }
  193. advice.StartTime = old.StartTime
  194. advice.AdviceDoctor = old.AdviceDoctor
  195. advice.DeliveryWay = old.DeliveryWay
  196. advice.ExecutionFrequency = old.ExecutionFrequency
  197. advice.GroupNo = old.GroupNo
  198. }
  199. advice.Status = 1
  200. advice.CreatedTime = time.Now().Unix()
  201. advice.UpdatedTime = time.Now().Unix()
  202. advice.StopState = 2
  203. advice.ExecutionState = 2
  204. advice.UserOrgId = adminUserInfo.Org.Id
  205. advice.PatientId = patient
  206. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  207. err := service.CreateDoctorAdvice(&advice)
  208. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  209. redis := service.RedisClient()
  210. defer redis.Close()
  211. redis.Set(key, "", time.Second)
  212. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  213. redis.Set(keyOne, "", time.Second)
  214. if err != nil {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  216. return
  217. }
  218. c.ServeSuccessJSON(map[string]interface{}{
  219. "msg": "ok",
  220. "advice": advice,
  221. })
  222. return
  223. }
  224. func (c *PatientApiController) EditDoctorAdvice() {
  225. id, _ := c.GetInt64("id", 0)
  226. patient_id, _ := c.GetInt64("patient_id")
  227. doc_advice_date, _ := c.GetInt64("advice_date")
  228. if id <= 0 {
  229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  230. return
  231. }
  232. redis := service.RedisClient()
  233. adminUserInfo := c.GetMobileAdminUserInfo()
  234. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  235. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  236. //
  237. //if appRole.UserType == 3 {
  238. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  239. // if getPermissionErr != nil {
  240. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  241. // return
  242. // } else if headNursePermission == nil {
  243. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  244. // return
  245. // }
  246. //}
  247. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  248. if advice.ID == 0 {
  249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  250. return
  251. }
  252. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  253. if code > 0 {
  254. c.ServeFailJSONWithSGJErrorCode(code)
  255. return
  256. }
  257. advice.Status = 1
  258. advice.UpdatedTime = time.Now().Unix()
  259. advice.UserOrgId = adminUserInfo.Org.Id
  260. advice.Modifier = adminUserInfo.AdminUser.Id
  261. //处理修改医嘱开始时间逻辑(不包括子医嘱)
  262. //1.一组医嘱内只有一条医嘱(不包括子医嘱)的情况下,只需要直接修改医嘱开始时间,不需要重新分配组号
  263. //2.一组医嘱内有多条医嘱(不包括子医嘱)的情况下,需要为修改的那条医嘱重新分配组号,并修改医嘱开始时间
  264. var err error
  265. var isChangeGroup bool
  266. if advice.ParentId == 0 {
  267. adviceSlice, _ := service.FindAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  268. sourceAdvice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice.ID)
  269. if len(adviceSlice) == 1 {
  270. // 查询信息规挡的设置天数
  271. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  272. if infor.ID > 0 {
  273. var cha_time int64
  274. timeNowStr := time.Now().Format("2006-01-02")
  275. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  276. //今日的日期减去设置的日期
  277. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  278. if cha_time >= sourceAdvice.AdviceDate {
  279. //查询审核是否允许
  280. infor, _ := service.GetDialysisInformationByRecordDate(id, sourceAdvice.AdviceDate, adminUserInfo.Org.Id)
  281. //申请状态不允许的情况 拒绝修改
  282. if infor.ApplicationStatus != 1 {
  283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  284. return
  285. }
  286. }
  287. }
  288. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要修改子医嘱的开始时间,如果相同直接修改,不需要修改子医嘱的开始时间
  289. if advice.StartTime == sourceAdvice.StartTime {
  290. err = service.UpdateDoctorAdvice(&advice)
  291. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  292. defer redis.Close()
  293. redis.Set(key, "", time.Second)
  294. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":advice_list_all"
  295. redis.Set(keyOne, "", time.Second)
  296. isChangeGroup = false
  297. } else {
  298. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  299. isChangeGroup = false
  300. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  301. defer redis.Close()
  302. redis.Set(key, "", time.Second)
  303. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  304. redis.Set(keyOne, "", time.Second)
  305. }
  306. } else if len(adviceSlice) > 1 {
  307. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  308. if infor.ID > 0 {
  309. var cha_time int64
  310. timeNowStr := time.Now().Format("2006-01-02")
  311. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  312. //今日的日期减去设置的日期
  313. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  314. if cha_time >= sourceAdvice.AdviceDate {
  315. //查询审核是否允许
  316. infor, _ := service.GetDialysisInformationByRecordDate(id, sourceAdvice.AdviceDate, adminUserInfo.Org.Id)
  317. //申请状态不允许的情况 拒绝修改
  318. if infor.ApplicationStatus != 1 {
  319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  320. return
  321. }
  322. }
  323. }
  324. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要重新分配组,如果相同直接修改,不需要分配组
  325. if advice.StartTime == sourceAdvice.StartTime {
  326. err = service.UpdateDoctorAdvice(&advice)
  327. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  328. defer redis.Close()
  329. redis.Set(key, "", time.Second)
  330. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  331. redis.Set(keyOne, "", time.Second)
  332. isChangeGroup = false
  333. } else {
  334. gruopNo := service.GetMaxAdviceGroupID(adminUserInfo.Org.Id)
  335. gruopNo = gruopNo + 1
  336. advice.GroupNo = gruopNo
  337. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  338. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  339. defer redis.Close()
  340. redis.Set(key, "", time.Second)
  341. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  342. redis.Set(keyOne, "", time.Second)
  343. isChangeGroup = true
  344. }
  345. }
  346. } else {
  347. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  348. if infor.ID > 0 {
  349. var cha_time int64
  350. timeNowStr := time.Now().Format("2006-01-02")
  351. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  352. //今日的日期减去设置的日期
  353. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  354. if cha_time >= advice.AdviceDate {
  355. //查询审核是否允许
  356. infor, _ := service.GetDialysisInformationByRecordDate(id, advice.AdviceDate, adminUserInfo.Org.Id)
  357. //申请状态不允许的情况 拒绝修改
  358. if infor.ApplicationStatus != 1 {
  359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  360. return
  361. }
  362. }
  363. }
  364. isChangeGroup = false
  365. err = service.UpdateDoctorAdvice(&advice)
  366. redis := service.RedisClient()
  367. defer redis.Close()
  368. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  369. redis.Set(key, "", time.Second)
  370. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  371. redis.Set(keyOne, "", time.Second)
  372. }
  373. if err != nil {
  374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  375. return
  376. }
  377. if !isChangeGroup {
  378. c.ServeSuccessJSON(map[string]interface{}{
  379. "msg": "ok",
  380. "advice": advice,
  381. "isChange": isChangeGroup, //方便前端处理数据
  382. })
  383. } else {
  384. newGroupAdvice, err := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  385. if err != nil {
  386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  387. return
  388. }
  389. c.ServeSuccessJSON(map[string]interface{}{
  390. "msg": "ok",
  391. "advice": newGroupAdvice,
  392. "isChange": isChangeGroup, //方便前端处理数据
  393. })
  394. }
  395. return
  396. }
  397. func (c *PatientApiController) StopDoctorAdvice() {
  398. id, _ := c.GetInt64("id", 0)
  399. if id <= 0 {
  400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  401. return
  402. }
  403. adminUserInfo := c.GetMobileAdminUserInfo()
  404. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  405. if advice.ID == 0 {
  406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  407. return
  408. }
  409. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  410. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  411. // return
  412. //}
  413. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  414. //
  415. //if appRole.UserType == 3 {
  416. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  417. // if getPermissionErr != nil {
  418. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  419. // return
  420. // } else if headNursePermission == nil {
  421. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  422. // return
  423. // }
  424. //}
  425. if advice.StopState == 1 {
  426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  427. return
  428. }
  429. dataBody := make(map[string]interface{}, 0)
  430. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  431. if err != nil {
  432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  433. return
  434. }
  435. timeLayout := "2006-01-02"
  436. loc, _ := time.LoadLocation("Local")
  437. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  438. utils.ErrorLog("stop_time")
  439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  440. return
  441. }
  442. stopTime, _ := dataBody["stop_time"].(string)
  443. if len(stopTime) == 0 {
  444. utils.ErrorLog("len(stop_time) == 0")
  445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  446. return
  447. }
  448. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  449. if err != nil {
  450. utils.ErrorLog(err.Error())
  451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  452. return
  453. }
  454. advice.StopTime = theTime.Unix()
  455. if dataBody["stop_reason"] == nil || reflect.TypeOf(dataBody["stop_reason"]).String() != "string" {
  456. utils.ErrorLog("stop_reason")
  457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  458. return
  459. }
  460. stopReason, _ := dataBody["stop_reason"].(string)
  461. if len(stopReason) == 0 {
  462. utils.ErrorLog("len(stop_reason) == 0")
  463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  464. return
  465. }
  466. advice.StopReason = stopReason
  467. advice.Status = 1
  468. advice.UpdatedTime = time.Now().Unix()
  469. advice.StopDoctor = adminUserInfo.AdminUser.Id
  470. advice.StopState = 1
  471. advice.StopTime = time.Now().Unix()
  472. advice.Modifier = adminUserInfo.AdminUser.Id
  473. err = service.StopDoctorAdvice(&advice)
  474. if err != nil {
  475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  476. return
  477. }
  478. c.ServeSuccessJSON(map[string]interface{}{
  479. "msg": "ok",
  480. "advice": advice,
  481. })
  482. return
  483. }
  484. func (c *PatientApiController) DeleteDoctorAdvice() {
  485. id, _ := c.GetInt64("id", 0)
  486. if id <= 0 {
  487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  488. return
  489. }
  490. adminUserInfo := c.GetMobileAdminUserInfo()
  491. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  492. if advice.ID == 0 {
  493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  494. return
  495. }
  496. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  497. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  498. // return
  499. //}
  500. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  501. //
  502. //if appRole.UserType == 3 {
  503. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  504. // if getPermissionErr != nil {
  505. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  506. // return
  507. // } else if headNursePermission == nil {
  508. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  509. // return
  510. // }
  511. //}
  512. advice.UpdatedTime = time.Now().Unix()
  513. advice.Status = 0
  514. advice.Modifier = adminUserInfo.AdminUser.Id
  515. err := service.DeleteDoctorAdvice(&advice)
  516. if err != nil {
  517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  518. return
  519. }
  520. c.ServeSuccessJSON(map[string]interface{}{
  521. "msg": "ok",
  522. })
  523. return
  524. }
  525. func (c *PatientApiController) ExecDoctorAdvice() {
  526. execution_time := c.GetString("execution_time")
  527. origin, _ := c.GetInt64("origin", 0)
  528. groupno, _ := c.GetInt64("groupno", -1)
  529. record_date, _ := c.GetInt64("record_date")
  530. if origin != 2 {
  531. adminUserInfo := c.GetMobileAdminUserInfo()
  532. execution_staff := adminUserInfo.AdminUser.Id
  533. var ids []string
  534. advice_ids := c.GetString("advice_id")
  535. if groupno == 0 {
  536. ids = strings.Split(advice_ids, ",")
  537. }
  538. if groupno < 0 {
  539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  540. return
  541. }
  542. if len(execution_time) <= 0 {
  543. utils.ErrorLog("execution_time")
  544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  545. return
  546. }
  547. timeLayout2 := "2006-01-02 15:04:05"
  548. loc, _ := time.LoadLocation("Local")
  549. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  550. if errs != nil {
  551. utils.ErrorLog(errs.Error())
  552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  553. return
  554. }
  555. var advice models.DoctorAdvice
  556. if groupno > 0 {
  557. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  558. for _, item := range advices {
  559. if item.ExecutionState == 2 {
  560. advice = item
  561. }
  562. }
  563. } else {
  564. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  565. for _, item := range advices {
  566. if item.ExecutionState == 2 {
  567. advice = item
  568. }
  569. }
  570. }
  571. if advice.ExecutionState == 1 {
  572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  573. return
  574. }
  575. if advice.Checker >= 0 && advice.Checker == adminUserInfo.AdminUser.Id {
  576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  577. return
  578. }
  579. if advice.StartTime > theTime.Unix() {
  580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  581. return
  582. }
  583. advices := models.DoctorAdvice{
  584. ExecutionStaff: execution_staff,
  585. ExecutionTime: theTime.Unix(),
  586. UpdatedTime: time.Now().Unix(),
  587. }
  588. var err error
  589. if groupno > 0 {
  590. // 查询信息规挡的设置天数
  591. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  592. if infor.ID > 0 {
  593. var cha_time int64
  594. timeNowStr := time.Now().Format("2006-01-02")
  595. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  596. //今日的日期减去设置的日期
  597. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  598. fmt.Println("cha_time----------------", cha_time)
  599. fmt.Println("advices.232323232222", record_date)
  600. if cha_time >= record_date {
  601. //查询审核是否允许
  602. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id)
  603. //申请状态不允许的情况 拒绝修改
  604. if infor.ApplicationStatus != 1 {
  605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  606. return
  607. }
  608. }
  609. }
  610. err = service.ExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  611. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  612. redis := service.RedisClient()
  613. //清空key 值
  614. redis.Set(key, "", time.Second)
  615. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  616. redis.Set(keyTwo, "", time.Second)
  617. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  618. redis.Set(keyThree, "", time.Second)
  619. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  620. theTime := toTime.Format("2006-01-02")
  621. fmt.Println("theTIME", theTime)
  622. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  623. redis.Set(keyFour, "", time.Second)
  624. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  625. redis.Set(keyFive, "", time.Second)
  626. defer redis.Close()
  627. } else {
  628. // 查询信息规挡的设置天数
  629. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  630. if infor.ID > 0 {
  631. var cha_time int64
  632. timeNowStr := time.Now().Format("2006-01-02")
  633. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  634. //今日的日期减去设置的日期
  635. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  636. if cha_time >= record_date {
  637. //查询审核是否允许
  638. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id)
  639. //申请状态不允许的情况 拒绝修改
  640. if infor.ApplicationStatus != 1 {
  641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  642. return
  643. }
  644. }
  645. }
  646. err = service.BatchExceOldDoctorAdvice(&advices, ids)
  647. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  648. redis := service.RedisClient()
  649. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  650. redis.Set(keyTwo, "", time.Second)
  651. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  652. redis.Set(keyThree, "", time.Second)
  653. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  654. theTime := toTime.Format("2006-01-02")
  655. fmt.Println("theTIME", theTime)
  656. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  657. redis.Set(keyFour, "", time.Second)
  658. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  659. redis.Set(keySix, "", time.Second)
  660. defer redis.Close()
  661. //清空key 值
  662. redis.Set(key, "", time.Second)
  663. }
  664. if err != nil {
  665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  666. return
  667. }
  668. advice.ExecutionStaff = execution_staff
  669. advice.ExecutionTime = theTime.Unix()
  670. advice.ExecutionState = 1
  671. advice.Modifier = adminUserInfo.AdminUser.Id
  672. //处理出库相关逻辑
  673. //1.判断是否启用药品管理和自备药出库功能
  674. //药品管理信息
  675. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  676. //自备药信息
  677. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
  678. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.Org.Id)
  679. if drugStockConfig.IsOpen == 1 {
  680. if groupno > 0 {
  681. advices, _ := service.FindAllDoctorAdviceByGoroupNoTwety(adminUserInfo.Org.Id, groupno)
  682. if len(advices) > 0 {
  683. var total int64
  684. var prescribing_number_total int64
  685. //出库
  686. for _, item := range advices {
  687. if item.Way == 1 {
  688. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  689. //查询该药品的剩余库存
  690. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  691. //查询改药品信息
  692. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  693. //判断单位是否相等
  694. if medical.MaxUnit == item.PrescribingNumberUnit {
  695. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  696. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  697. //转化为最小单位
  698. total = list.Count * medical.MinNumber
  699. prescribing_number_total = count * medical.MinNumber
  700. }
  701. if medical.MinUnit == item.PrescribingNumberUnit {
  702. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  703. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  704. total = list.Count*medical.MinNumber + list.StockMinNumber
  705. prescribing_number_total = count
  706. }
  707. if medical.IsUse == 1 {
  708. c.ServeSuccessJSON(map[string]interface{}{
  709. "msg": "1",
  710. "advice": advice,
  711. "ids": ids,
  712. })
  713. return
  714. }
  715. if medical.IsUse != 1 {
  716. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  717. if advice.UserOrgId != 10278 {
  718. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  719. advice.ExecutionTime = 0
  720. advice.ExecutionState = 2
  721. advice.ExecutionStaff = 0
  722. }
  723. c.ServeSuccessJSON(map[string]interface{}{
  724. "msg": "3",
  725. "advice": advice,
  726. "ids": ids,
  727. })
  728. return
  729. }
  730. if prescribing_number_total > total {
  731. if advice.UserOrgId != 10278 {
  732. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  733. advice.ExecutionTime = 0
  734. advice.ExecutionState = 2
  735. advice.ExecutionStaff = 0
  736. }
  737. c.ServeSuccessJSON(map[string]interface{}{
  738. "msg": "2",
  739. "advice": advice,
  740. "ids": ids,
  741. })
  742. return
  743. }
  744. }
  745. //查询是否出库按钮开启
  746. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  747. if adviceSetting.IsAdviceOpen == 1 {
  748. //查询是否出库按钮开启
  749. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  750. //患者发药
  751. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  752. if prescriptionConfig.IsOpen == 1 {
  753. if medical.IsUse == 2 {
  754. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  755. //查询今日是否出库
  756. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  757. if drugOutInfo.ID == 0 {
  758. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  759. }
  760. }
  761. if pharmacyConfig.IsOpen != 1 {
  762. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  763. if drugOutInfo.ID == 0 {
  764. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  765. }
  766. }
  767. //更新字典里面的库存
  768. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  769. var sum_count int64
  770. for _, its := range stockInfo {
  771. if its.MaxUnit == medical.MaxUnit {
  772. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  773. }
  774. sum_count += its.StockMaxNumber + its.StockMinNumber
  775. }
  776. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  777. //剩余库存
  778. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  779. }
  780. }
  781. } else {
  782. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  783. if medical.IsUse == 2 {
  784. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  785. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  786. if drugOutInfo.ID == 0 {
  787. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  788. }
  789. }
  790. if pharmacyConfig.IsOpen != 1 {
  791. drugError := models.XtDrugError{
  792. ID: 0,
  793. UserOrgId: item.UserOrgId,
  794. DrugId: item.DrugId,
  795. RecordDate: item.AdviceDate,
  796. PatientId: item.PatientId,
  797. Remark: "恒泰中医院出库开始",
  798. Status: 1,
  799. Ctime: time.Now().Unix(),
  800. Mtime: 0,
  801. Prescribingnumber: item.PrescribingNumber,
  802. PrescribingNumberUnit: item.PrescribingNumberUnit,
  803. SumCount: 0,
  804. }
  805. service.CreateDrugError(drugError)
  806. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  807. if drugOutInfo.ID == 0 {
  808. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  809. }
  810. }
  811. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  812. var sum_count int64
  813. for _, its := range stockInfo {
  814. if its.MaxUnit == medical.MaxUnit {
  815. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  816. }
  817. sum_count += its.StockMaxNumber + its.StockMinNumber
  818. }
  819. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  820. //剩余库存
  821. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  822. }
  823. }
  824. }
  825. }
  826. }
  827. c.ServeSuccessJSON(map[string]interface{}{
  828. "msg": "1",
  829. "advice": advice,
  830. "ids": ids,
  831. })
  832. return
  833. } else {
  834. advices, _ := service.FindDoctorAdviceByIdsTwety(adminUserInfo.Org.Id, ids)
  835. if len(advices) > 0 {
  836. var total int64
  837. var prescribing_number_total int64
  838. for _, item := range advices {
  839. if item.Way == 1 {
  840. //查询改药品信息
  841. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  842. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  843. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  844. //查询该药品的剩余库存
  845. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  846. //判断单位是否相等
  847. if medical.MaxUnit == item.PrescribingNumberUnit {
  848. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  849. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  850. //转化为最小单位
  851. total = list.Count*medical.MinNumber + list.StockMinNumber
  852. prescribing_number_total = count * medical.MinNumber
  853. }
  854. if medical.MinUnit == item.PrescribingNumberUnit {
  855. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  856. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  857. total = list.Count*medical.MinNumber + list.StockMinNumber
  858. prescribing_number_total = count
  859. }
  860. if medical.IsUse == 1 {
  861. c.ServeSuccessJSON(map[string]interface{}{
  862. "msg": "1",
  863. "advice": advice,
  864. "ids": ids,
  865. })
  866. return
  867. }
  868. if medical.IsUse != 1 {
  869. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  870. if advice.UserOrgId != 10278 {
  871. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  872. advice.ExecutionTime = 0
  873. advice.ExecutionState = 2
  874. advice.ExecutionStaff = 0
  875. }
  876. c.ServeSuccessJSON(map[string]interface{}{
  877. "msg": "3",
  878. "advice": advice,
  879. "ids": ids,
  880. })
  881. return
  882. }
  883. if prescribing_number_total > total {
  884. if advice.UserOrgId != 10278 {
  885. service.UpdateDoctorAdviceByExcecute(advice.ID, advice.UserOrgId)
  886. advice.ExecutionTime = 0
  887. advice.ExecutionState = 2
  888. advice.ExecutionStaff = 0
  889. }
  890. c.ServeSuccessJSON(map[string]interface{}{
  891. "msg": "2",
  892. "advice": advice,
  893. "ids": ids,
  894. })
  895. return
  896. }
  897. }
  898. if medical.IsUse == 2 {
  899. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  900. //查询今日是否出库
  901. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  902. if drugOutInfo.ID == 0 {
  903. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  904. }
  905. }
  906. if pharmacyConfig.IsOpen != 1 {
  907. //查询今日是否出库
  908. drugOutInfo, _ := service.GetAdviceIsOut(item.ID, item.UserOrgId, item.PatientId, item.AdviceDate, item.DrugId)
  909. if drugOutInfo.ID == 0 {
  910. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  911. }
  912. }
  913. //更新字典里面的库存
  914. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  915. var sum_count int64
  916. for _, its := range stockInfo {
  917. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  918. if its.MaxUnit == baseDrug.MaxUnit {
  919. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  920. }
  921. sum_count += its.StockMaxNumber + its.StockMinNumber
  922. }
  923. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  924. //剩余库存
  925. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  926. }
  927. if medical.IsUse == 1 {
  928. c.ServeSuccessJSON(map[string]interface{}{
  929. "msg": "1",
  930. "advice": advice,
  931. "ids": ids,
  932. })
  933. return
  934. }
  935. }
  936. }
  937. }
  938. c.ServeSuccessJSON(map[string]interface{}{
  939. "msg": "1",
  940. "advice": advice,
  941. "ids": ids,
  942. })
  943. return
  944. }
  945. }
  946. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  947. if groupno > 0 {
  948. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  949. for _, item := range advices {
  950. if item.ExecutionState == 1 && item.Way == 2 {
  951. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  952. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  953. timeStr := time.Now().Format("2006-01-02")
  954. timeArr := strings.Split(timeStr, "-")
  955. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  956. total = total + 1
  957. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  958. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  959. number = number + total
  960. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  961. //插入自备药出库单
  962. outStock := models.XtSelfOutStock{
  963. DrugName: item.AdviceName,
  964. DrugNameId: item.DrugNameId,
  965. DrugSpec: item.AdviceDesc,
  966. OutstoreNumber: count,
  967. AdminUserId: adminUserInfo.AdminUser.Id,
  968. StorckTime: item.AdviceDate,
  969. UserOrgId: adminUserInfo.Org.Id,
  970. CreatedTime: time.Now().Unix(),
  971. Status: 1,
  972. PatientId: item.PatientId,
  973. ExitMode: 2,
  974. MedicId: item.DrugId,
  975. StockOutNumber: warehousing_out_order,
  976. }
  977. //查询 该患者是否已出库
  978. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  979. if errcode == gorm.ErrRecordNotFound {
  980. service.CreateOutStock(&outStock)
  981. } else if errcode == nil {
  982. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  983. fmt.Println("err", err)
  984. }
  985. }
  986. }
  987. } else {
  988. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  989. for _, item := range advices {
  990. if item.ExecutionState == 1 && item.Way == 2 {
  991. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  992. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  993. timeStr := time.Now().Format("2006-01-02")
  994. timeArr := strings.Split(timeStr, "-")
  995. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  996. total = total + 1
  997. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  998. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  999. number = number + total
  1000. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1001. //插入自备药出库单
  1002. outStock := models.XtSelfOutStock{
  1003. DrugName: item.AdviceName,
  1004. DrugNameId: item.DrugNameId,
  1005. DrugSpec: item.AdviceDesc,
  1006. OutstoreNumber: count,
  1007. AdminUserId: adminUserInfo.AdminUser.Id,
  1008. StorckTime: item.AdviceDate,
  1009. UserOrgId: adminUserInfo.Org.Id,
  1010. CreatedTime: time.Now().Unix(),
  1011. Status: 1,
  1012. PatientId: item.PatientId,
  1013. ExitMode: 2,
  1014. MedicId: item.DrugId,
  1015. StockOutNumber: warehousing_out_order,
  1016. }
  1017. //查询 该患者是否已出库
  1018. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  1019. if errcode == gorm.ErrRecordNotFound {
  1020. service.CreateOutStock(&outStock)
  1021. } else if errcode == nil {
  1022. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  1023. fmt.Println("err", err)
  1024. }
  1025. }
  1026. }
  1027. c.ServeSuccessJSON(map[string]interface{}{
  1028. "msg": "1",
  1029. "advice": advice,
  1030. "ids": ids,
  1031. })
  1032. return
  1033. }
  1034. }
  1035. c.ServeSuccessJSON(map[string]interface{}{
  1036. "msg": "1",
  1037. "advice": advice,
  1038. "ids": ids,
  1039. })
  1040. return
  1041. } else if origin == 2 {
  1042. adminInfo := c.GetMobileAdminUserInfo()
  1043. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  1044. var ids []string
  1045. advice_ids := c.GetString("advice_id")
  1046. ids = strings.Split(advice_ids, ",")
  1047. if len(execution_time) <= 0 {
  1048. utils.ErrorLog("execution_time")
  1049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1050. return
  1051. }
  1052. timeLayout2 := "2006-01-02 15:04:05"
  1053. loc, _ := time.LoadLocation("Local")
  1054. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1055. if errs != nil {
  1056. utils.ErrorLog(errs.Error())
  1057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1058. return
  1059. }
  1060. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  1061. var err error
  1062. for _, item := range advices {
  1063. if item.ExecutionState == 1 {
  1064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1065. return
  1066. }
  1067. if item.Checker >= 0 && item.Checker == adminInfo.AdminUser.Id {
  1068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1069. return
  1070. }
  1071. if item.StartTime > theTime.Unix() {
  1072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1073. return
  1074. }
  1075. item.ExecutionState = 1
  1076. item.ExecutionStaff = adminInfo.AdminUser.Id
  1077. item.ExecutionTime = theTime.Unix()
  1078. item.IsMobile = 1
  1079. // 查询信息规挡的设置天数
  1080. infor, _ := service.GetDialysisInformationSetting(item.UserOrgId)
  1081. if infor.ID > 0 {
  1082. var cha_time int64
  1083. timeNowStr := time.Now().Format("2006-01-02")
  1084. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1085. //今日的日期减去设置的日期
  1086. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1087. if cha_time >= item.AdviceDate {
  1088. //查询审核是否允许
  1089. infor, _ := service.GetDialysisInformationByRecordDate(item.PatientId, item.AdviceDate, item.UserOrgId)
  1090. //申请状态不允许的情况 拒绝修改
  1091. if infor.ApplicationStatus != 1 {
  1092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1093. return
  1094. }
  1095. }
  1096. }
  1097. err = service.SaveHisDoctorAdvice(item)
  1098. if err == nil {
  1099. drugError := models.XtDrugError{
  1100. UserOrgId: adminInfo.Org.Id,
  1101. DrugId: item.DrugId,
  1102. RecordDate: item.AdviceDate,
  1103. PatientId: item.PatientId,
  1104. Remark: "执行成功",
  1105. Status: 1,
  1106. Ctime: time.Now().Unix(),
  1107. Mtime: 0,
  1108. SumCount: 0,
  1109. Prescribingnumber: item.PrescribingNumber,
  1110. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1111. }
  1112. service.CreateDrugError(drugError)
  1113. }
  1114. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1115. redis := service.RedisClient()
  1116. //清空key 值
  1117. redis.Set(key, "", time.Second)
  1118. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1119. redis.Set(keyTwo, "", time.Second)
  1120. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1121. redis.Set(keyThree, "", time.Second)
  1122. recordDate := theTime.Format("2006-01-02")
  1123. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  1124. redis.Set(keyFour, "", time.Second)
  1125. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1126. redis.Set(keyFive, "", time.Second)
  1127. defer redis.Close()
  1128. }
  1129. if err == nil {
  1130. //药品管理信息
  1131. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  1132. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  1133. if drugStockConfig.IsOpen == 1 {
  1134. for _, item := range advices {
  1135. //查询改药品信息
  1136. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1137. //判断单位是否合格
  1138. if item.PrescribingNumberUnit != medical.MaxUnit && item.PrescribingNumberUnit != medical.MinUnit {
  1139. //查询该药品是否有出库记录
  1140. flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)
  1141. if len(flowMap) == 0 {
  1142. errs := service.UpdateHisAdviceById(item.ID)
  1143. if errs != nil {
  1144. drugError := models.XtDrugError{
  1145. UserOrgId: adminInfo.Org.Id,
  1146. DrugId: item.DrugId,
  1147. RecordDate: item.AdviceDate,
  1148. PatientId: item.PatientId,
  1149. Remark: "单位不统一,执行失败",
  1150. Status: 1,
  1151. Ctime: time.Now().Unix(),
  1152. Mtime: 0,
  1153. SumCount: 0,
  1154. Prescribingnumber: item.PrescribingNumber,
  1155. PrescribingNumberUnit: item.PrescribingNumberUnit,
  1156. }
  1157. service.CreateDrugError(drugError)
  1158. }
  1159. }
  1160. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1161. c.ServeSuccessJSON(map[string]interface{}{
  1162. "msg": "7",
  1163. "advice": advice,
  1164. "ids": ids,
  1165. })
  1166. return
  1167. }
  1168. //查询这个患者这个患者这个药已经出库的所有数量
  1169. advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1170. drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1171. var total_count int64
  1172. var drug_count int64
  1173. for _, it := range advicelist {
  1174. if it.PrescribingNumberUnit == medical.MaxUnit {
  1175. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1176. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1177. total_count += prenumber * medical.MinNumber
  1178. }
  1179. if it.PrescribingNumberUnit == medical.MinUnit {
  1180. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1181. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1182. total_count += prenumber
  1183. }
  1184. }
  1185. for _, its := range drugoutlist {
  1186. if its.CountUnit == medical.MaxUnit {
  1187. drug_count += its.Count * medical.MinNumber
  1188. }
  1189. if its.CountUnit == medical.MinUnit {
  1190. drug_count += its.Count
  1191. }
  1192. }
  1193. if total_count == drug_count {
  1194. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1195. c.ServeSuccessJSON(map[string]interface{}{
  1196. "msg": "1",
  1197. "advice": advice,
  1198. "ids": ids,
  1199. })
  1200. return
  1201. }
  1202. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1203. var total int64
  1204. var prescribing_number_total int64
  1205. config, _ := service.GetDrugOpenConfigOne(adminInfo.Org.Id)
  1206. if config.IsOpen != 1 {
  1207. //查询该药品是否有库存
  1208. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  1209. list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
  1210. //判断单位是否相等
  1211. if medical.MaxUnit == advice.PrescribingNumberUnit {
  1212. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1213. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1214. //转化为最小单位
  1215. total = list.Count*medical.MinNumber + list.StockMinNumber
  1216. prescribing_number_total = count * medical.MinNumber
  1217. }
  1218. //fmt.Println("医嘱开的数量", total)
  1219. if medical.MinUnit == advice.PrescribingNumberUnit {
  1220. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1221. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1222. total = list.Count*medical.MinNumber + list.StockMinNumber
  1223. prescribing_number_total = count
  1224. }
  1225. if medical.IsUse == 1 {
  1226. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1227. drugError := models.XtDrugError{
  1228. UserOrgId: adminInfo.Org.Id,
  1229. DrugId: item.DrugId,
  1230. RecordDate: item.AdviceDate,
  1231. PatientId: item.PatientId,
  1232. Remark: "零用药品库存不足",
  1233. Status: 1,
  1234. Ctime: time.Now().Unix(),
  1235. Mtime: 0,
  1236. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1237. Prescribingnumber: advice.PrescribingNumber,
  1238. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1239. }
  1240. service.CreateDrugError(drugError)
  1241. c.ServeSuccessJSON(map[string]interface{}{
  1242. "msg": "1",
  1243. "advice": advice,
  1244. "ids": ids,
  1245. })
  1246. return
  1247. }
  1248. }
  1249. if medical.IsUse != 1 {
  1250. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1251. drugError := models.XtDrugError{
  1252. UserOrgId: adminInfo.Org.Id,
  1253. DrugId: item.DrugId,
  1254. RecordDate: item.AdviceDate,
  1255. PatientId: item.PatientId,
  1256. Remark: "药品库存不足",
  1257. Status: 1,
  1258. Ctime: time.Now().Unix(),
  1259. Mtime: 0,
  1260. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1261. Prescribingnumber: advice.PrescribingNumber,
  1262. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1263. }
  1264. service.CreateDrugError(drugError)
  1265. c.ServeSuccessJSON(map[string]interface{}{
  1266. "msg": "3",
  1267. "advice": advice,
  1268. "ids": ids,
  1269. })
  1270. return
  1271. }
  1272. if prescribing_number_total > total {
  1273. drugError := models.XtDrugError{
  1274. UserOrgId: adminInfo.Org.Id,
  1275. DrugId: item.DrugId,
  1276. RecordDate: item.AdviceDate,
  1277. PatientId: item.PatientId,
  1278. Remark: "出库数量大于库存",
  1279. Status: 1,
  1280. Ctime: time.Now().Unix(),
  1281. Mtime: 0,
  1282. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1283. Prescribingnumber: advice.PrescribingNumber,
  1284. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1285. }
  1286. service.CreateDrugError(drugError)
  1287. c.ServeSuccessJSON(map[string]interface{}{
  1288. "msg": "2",
  1289. "advice": advice,
  1290. "ids": ids,
  1291. })
  1292. return
  1293. }
  1294. }
  1295. if prescribing_number_total <= total {
  1296. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  1297. //判断药品是否零用
  1298. if medical.IsUse == 2 {
  1299. if config.IsOpen != 1 {
  1300. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1301. service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1302. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1303. //查询该药品是否有出库记录
  1304. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  1305. if len(flowMap) == 0 {
  1306. errs := service.UpdateHisAdviceById(advice.ID)
  1307. if errs != nil {
  1308. drugError := models.XtDrugError{
  1309. UserOrgId: adminInfo.Org.Id,
  1310. DrugId: item.DrugId,
  1311. RecordDate: item.AdviceDate,
  1312. PatientId: item.PatientId,
  1313. Remark: "出库记录为空,更新执行人失败",
  1314. Status: 1,
  1315. Ctime: time.Now().Unix(),
  1316. Mtime: 0,
  1317. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1318. Prescribingnumber: advice.PrescribingNumber,
  1319. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1320. }
  1321. service.CreateDrugError(drugError)
  1322. }
  1323. c.ServeSuccessJSON(map[string]interface{}{
  1324. "msg": "6",
  1325. "advice": advice,
  1326. "ids": ids,
  1327. })
  1328. return
  1329. }
  1330. }
  1331. }
  1332. if pharmacyConfig.IsOpen != 1 {
  1333. service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1334. if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
  1335. //查询该药品是否有出库记录
  1336. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  1337. if len(flowMap) == 0 {
  1338. errs := service.UpdateHisAdviceById(advice.ID)
  1339. if errs != nil {
  1340. drugError := models.XtDrugError{
  1341. UserOrgId: adminInfo.Org.Id,
  1342. DrugId: item.DrugId,
  1343. RecordDate: item.AdviceDate,
  1344. PatientId: item.PatientId,
  1345. Remark: "出库记录为空,更新执行人失败",
  1346. Status: 1,
  1347. Ctime: time.Now().Unix(),
  1348. Mtime: 0,
  1349. SumCount: list.Count*medical.MinNumber + list.StockMinNumber,
  1350. Prescribingnumber: advice.PrescribingNumber,
  1351. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  1352. }
  1353. service.CreateDrugError(drugError)
  1354. }
  1355. c.ServeSuccessJSON(map[string]interface{}{
  1356. "msg": "6",
  1357. "advice": advice,
  1358. "ids": ids,
  1359. })
  1360. return
  1361. }
  1362. }
  1363. }
  1364. //更新字典里面的库存
  1365. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1366. var sum_count int64
  1367. for _, its := range stockInfo {
  1368. if its.MaxUnit == medical.MaxUnit {
  1369. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1370. }
  1371. sum_count += its.StockMaxNumber + its.StockMinNumber
  1372. }
  1373. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1374. //剩余库存
  1375. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1376. }
  1377. }
  1378. }
  1379. }
  1380. //
  1381. //if config.IsOpen == 1 && item.UserOrgId == 10188 {
  1382. //
  1383. // service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1384. // //更新字典里面的库存
  1385. // stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1386. // var sum_count int64
  1387. // for _, its := range stockInfo {
  1388. // if its.MaxUnit == medical.MaxUnit {
  1389. // its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1390. // }
  1391. // sum_count += its.StockMaxNumber + its.StockMinNumber
  1392. // }
  1393. // service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1394. // //剩余库存
  1395. // service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1396. //}
  1397. }
  1398. }
  1399. for _, item := range advices {
  1400. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1401. c.ServeSuccessJSON(map[string]interface{}{
  1402. "msg": "1",
  1403. "advice": advice,
  1404. "ids": ids,
  1405. })
  1406. }
  1407. } else {
  1408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1409. }
  1410. }
  1411. }
  1412. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  1413. execution_time := c.GetString("execution_time")
  1414. fmt.Println("execution_time", execution_time)
  1415. groupno, _ := c.GetInt64("groupno", -1)
  1416. //patient_id, _ := c.GetInt64("patient_id")
  1417. advice_date, _ := c.GetInt64("advice_date")
  1418. var ids []string
  1419. if groupno == 0 {
  1420. advice_ids := c.GetString("advice_id")
  1421. ids = strings.Split(advice_ids, ",")
  1422. }
  1423. if groupno < 0 {
  1424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1425. return
  1426. }
  1427. if len(execution_time) <= 0 {
  1428. utils.ErrorLog("execution_time")
  1429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1430. return
  1431. }
  1432. timeLayout2 := "2006-01-02 15:04:05"
  1433. loc, _ := time.LoadLocation("Local")
  1434. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1435. if errs != nil {
  1436. utils.ErrorLog(errs.Error())
  1437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1438. return
  1439. }
  1440. adminUserInfo := c.GetMobileAdminUserInfo()
  1441. var advice models.DoctorAdvice
  1442. if groupno > 0 {
  1443. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1444. for _, item := range advices {
  1445. if item.ExecutionState == 1 {
  1446. advice = item
  1447. }
  1448. }
  1449. } else {
  1450. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1451. for _, item := range advices {
  1452. if item.ExecutionState == 1 {
  1453. advice = item
  1454. }
  1455. }
  1456. }
  1457. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  1458. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1459. // if getPermissionErr != nil {
  1460. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1461. // return
  1462. // } else if headNursePermission == nil {
  1463. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1464. // return
  1465. // }
  1466. //}
  1467. if advice.StartTime > theTime.Unix() {
  1468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1469. return
  1470. }
  1471. advices := models.DoctorAdvice{
  1472. ExecutionTime: theTime.Unix(),
  1473. UpdatedTime: time.Now().Unix(),
  1474. }
  1475. var err error
  1476. if groupno > 0 {
  1477. // 查询信息规挡的设置天数
  1478. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1479. if infor.ID > 0 {
  1480. var cha_time int64
  1481. timeNowStr := time.Now().Format("2006-01-02")
  1482. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1483. //今日的日期减去设置的日期
  1484. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1485. if cha_time >= advices.AdviceDate {
  1486. //查询审核是否允许
  1487. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id)
  1488. //申请状态不允许的情况 拒绝修改
  1489. if infor.ApplicationStatus != 1 {
  1490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1491. return
  1492. }
  1493. }
  1494. }
  1495. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1496. redis := service.RedisClient()
  1497. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1498. redis.Set(key, "", time.Second)
  1499. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1500. redis.Set(keyOne, "", time.Second)
  1501. defer redis.Close()
  1502. } else {
  1503. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1504. if infor.ID > 0 {
  1505. var cha_time int64
  1506. timeNowStr := time.Now().Format("2006-01-02")
  1507. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1508. //今日的日期减去设置的日期
  1509. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1510. if cha_time >= advices.AdviceDate {
  1511. //查询审核是否允许
  1512. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advices.AdviceDate, adminUserInfo.Org.Id)
  1513. //申请状态不允许的情况 拒绝修改
  1514. if infor.ApplicationStatus != 1 {
  1515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1516. return
  1517. }
  1518. }
  1519. }
  1520. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  1521. err = service.ModifyExceDoctorAdviceByGroupNoOne(&advices, ids)
  1522. redis := service.RedisClient()
  1523. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1524. redis.Set(key, "", time.Second)
  1525. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice_date, 10) + ":advice_list_all"
  1526. redis.Set(keyOne, "", time.Second)
  1527. defer redis.Close()
  1528. }
  1529. //判断是否开启his
  1530. errs, config := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  1531. //如果开启去修改执行时间
  1532. if config.IsOpen == 1 {
  1533. advicesinfo := models.HisDoctorAdviceInfo{
  1534. ExecutionTime: theTime.Unix(),
  1535. UpdatedTime: time.Now().Unix(),
  1536. }
  1537. var advicehis models.HisDoctorAdviceInfo
  1538. service.ModifyExceDoctorAdviceById(&advicesinfo, ids)
  1539. his_advices, _ := service.FindHisDoctorAdviceByIdOne(adminUserInfo.Org.Id, ids)
  1540. for _, item := range his_advices {
  1541. if item.ExecutionState == 1 {
  1542. advicehis = item
  1543. }
  1544. }
  1545. redis := service.RedisClient()
  1546. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.PatientId, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_doctor_advice"
  1547. redis.Set(keyThree, "", time.Second)
  1548. recordDate := theTime.Format("2006-01-02")
  1549. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1550. redis.Set(keyFour, "", time.Second)
  1551. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_advices_list_all"
  1552. redis.Set(keyFive, "", time.Second)
  1553. defer redis.Close()
  1554. project := models.HisPrescriptionProject{
  1555. ExecutionTime: theTime.Unix(),
  1556. Mtime: time.Now().Unix(),
  1557. }
  1558. service.ModifyHisPrescriptionProject(&project, ids)
  1559. keyEnd := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.PatientId, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_doctor_advice"
  1560. redis.Set(keyEnd, "", time.Second)
  1561. keyFours := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1562. redis.Set(keyFours, "", time.Second)
  1563. keyFives := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_advices_list_all"
  1564. redis.Set(keyFives, "", time.Second)
  1565. defer redis.Close()
  1566. }
  1567. if err != nil {
  1568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1569. return
  1570. }
  1571. advice.ExecutionTime = theTime.Unix()
  1572. c.ServeSuccessJSON(map[string]interface{}{
  1573. "msg": "ok",
  1574. "advice": advice,
  1575. "ids": ids,
  1576. })
  1577. return
  1578. }
  1579. func (c *PatientApiController) CheckDoctorAdvice() {
  1580. origin, _ := c.GetInt64("origin", 0)
  1581. record_date, _ := c.GetInt64("record_date")
  1582. patient_id, _ := c.GetInt64("patient_id")
  1583. if origin != 2 {
  1584. groupno, _ := c.GetInt64("groupno", -1)
  1585. var ids []string
  1586. if groupno == 0 {
  1587. advice_ids := c.GetString("advice_id")
  1588. if advice_ids == "" {
  1589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1590. return
  1591. } else {
  1592. ids = strings.Split(advice_ids, ",")
  1593. if len(ids) <= 0 {
  1594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1595. return
  1596. }
  1597. }
  1598. }
  1599. if groupno < 0 {
  1600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1601. return
  1602. }
  1603. adminUserInfo := c.GetMobileAdminUserInfo()
  1604. var advice models.DoctorAdvice
  1605. if groupno > 0 {
  1606. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1607. for _, item := range advices {
  1608. if item.CheckState == 0 {
  1609. advice = item
  1610. }
  1611. }
  1612. if advice.CheckState == 1 {
  1613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1614. return
  1615. }
  1616. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1618. return
  1619. }
  1620. } else {
  1621. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1622. for _, item := range advices {
  1623. if item.CheckState == 0 {
  1624. advice = item
  1625. }
  1626. }
  1627. if advice.CheckState == 1 {
  1628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1629. return
  1630. }
  1631. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1633. return
  1634. }
  1635. }
  1636. checker := adminUserInfo.AdminUser.Id
  1637. theTime := time.Now()
  1638. advices := models.DoctorAdvice{
  1639. CheckTime: theTime.Unix(),
  1640. Checker: checker,
  1641. UpdatedTime: time.Now().Unix(),
  1642. }
  1643. var err error
  1644. if groupno > 0 {
  1645. // 查询信息规挡的设置天数
  1646. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1647. if infor.ID > 0 {
  1648. var cha_time int64
  1649. timeNowStr := time.Now().Format("2006-01-02")
  1650. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1651. //今日的日期减去设置的日期
  1652. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1653. if cha_time >= record_date {
  1654. //查询审核是否允许
  1655. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminUserInfo.Org.Id)
  1656. //申请状态不允许的情况 拒绝修改
  1657. if infor.ApplicationStatus != 1 {
  1658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1659. return
  1660. }
  1661. }
  1662. }
  1663. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1664. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1665. redis := service.RedisClient()
  1666. //清空key 值
  1667. redis.Set(key, "", time.Second)
  1668. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1669. redis.Set(keyTwo, "", time.Second)
  1670. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1671. redis.Set(keyThree, "", time.Second)
  1672. recordDate := theTime.Format("2006-01-02")
  1673. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1674. redis.Set(keyFour, "", time.Second)
  1675. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1676. redis.Set(keyFive, "", time.Second)
  1677. defer redis.Close()
  1678. } else {
  1679. if len(ids[0]) <= 0 {
  1680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1681. return
  1682. } else {
  1683. //t := time.Now().Format("2006-01-02")/**/
  1684. //timeLayout2 := "2006-01-02"
  1685. //loc, _ := time.LoadLocation("Local")
  1686. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  1687. // 查询信息规挡的设置天数
  1688. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1689. if infor.ID > 0 {
  1690. var cha_time int64
  1691. timeNowStr := time.Now().Format("2006-01-02")
  1692. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1693. //今日的日期减去设置的日期
  1694. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1695. if cha_time >= advices.AdviceDate {
  1696. //查询审核是否允许
  1697. infor, _ := service.GetDialysisInformationByRecordDate(advices.PatientId, advices.AdviceDate, adminUserInfo.Org.Id)
  1698. //申请状态不允许的情况 拒绝修改
  1699. if infor.ApplicationStatus != 1 {
  1700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1701. return
  1702. }
  1703. }
  1704. }
  1705. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  1706. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1707. redis := service.RedisClient()
  1708. //清空key 值
  1709. redis.Set(key, "", time.Second)
  1710. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1711. redis.Set(keyTwo, "", time.Second)
  1712. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1713. redis.Set(keyThree, "", time.Second)
  1714. recordDate := theTime.Format("2006-01-02")
  1715. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1716. redis.Set(keyFour, "", time.Second)
  1717. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1718. redis.Set(keyFive, "", time.Second)
  1719. defer redis.Close()
  1720. }
  1721. }
  1722. if err != nil {
  1723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1724. return
  1725. }
  1726. advice.Checker = checker
  1727. advice.CheckTime = theTime.Unix()
  1728. advice.CheckState = 1
  1729. c.ServeSuccessJSON(map[string]interface{}{
  1730. "msg": "ok",
  1731. "advice": advice,
  1732. })
  1733. } else if origin == 2 {
  1734. adminInfo := c.GetMobileAdminUserInfo()
  1735. var ids []string
  1736. advice_ids := c.GetString("advice_id")
  1737. ids = strings.Split(advice_ids, ",")
  1738. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  1739. var err error
  1740. for _, item := range advices {
  1741. if item.CheckState == 1 {
  1742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1743. return
  1744. }
  1745. if item.ExecutionStaff >= 0 && item.ExecutionStaff == adminInfo.AdminUser.Id {
  1746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1747. return
  1748. }
  1749. item.Checker = adminInfo.AdminUser.Id
  1750. item.CheckTime = time.Now().Unix()
  1751. item.CheckState = 1
  1752. // 查询信息规挡的设置天数
  1753. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  1754. if infor.ID > 0 {
  1755. var cha_time int64
  1756. timeNowStr := time.Now().Format("2006-01-02")
  1757. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1758. //今日的日期减去设置的日期
  1759. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1760. if cha_time >= record_date {
  1761. //查询审核是否允许
  1762. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, adminInfo.Org.Id)
  1763. //申请状态不允许的情况 拒绝修改
  1764. if infor.ApplicationStatus != 1 {
  1765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1766. return
  1767. }
  1768. }
  1769. }
  1770. err = service.SaveHisDoctorAdvice(item)
  1771. redis := service.RedisClient()
  1772. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1773. //清空key 值
  1774. redis.Set(key, "", time.Second)
  1775. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1776. redis.Set(keyTwo, "", time.Second)
  1777. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1778. redis.Set(keyThree, "", time.Second)
  1779. theTime := time.Now()
  1780. recordDate := theTime.Format("2006-01-02")
  1781. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  1782. redis.Set(keyFour, "", time.Second)
  1783. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1784. redis.Set(keyFive, "", time.Second)
  1785. defer redis.Close()
  1786. }
  1787. if err == nil {
  1788. c.ServeSuccessJSON(map[string]interface{}{
  1789. "msg": "ok",
  1790. "advice": advices,
  1791. })
  1792. } else {
  1793. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1794. return
  1795. }
  1796. }
  1797. return
  1798. }
  1799. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  1800. id, _ := c.GetInt64("patient", 0)
  1801. assessmentDate := c.GetString("assessment_date", "")
  1802. if id <= 0 || len(assessmentDate) != 10 {
  1803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1804. return
  1805. }
  1806. timeLayout := "2006-01-02"
  1807. loc, _ := time.LoadLocation("Local")
  1808. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  1809. if err != nil {
  1810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1811. return
  1812. }
  1813. theAssessmentDateTime := theTime.Unix()
  1814. adminUserInfo := c.GetMobileAdminUserInfo()
  1815. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1816. if patient.ID == 0 {
  1817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1818. return
  1819. }
  1820. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationSeven(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  1821. if getPEErr != nil {
  1822. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  1823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1824. return
  1825. }
  1826. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1827. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1828. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1829. var evaluation models.PredialysisEvaluation
  1830. if theEvaluation != nil {
  1831. evaluation = *theEvaluation
  1832. }
  1833. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  1834. if code > 0 {
  1835. c.ServeFailJSONWithSGJErrorCode(code)
  1836. return
  1837. }
  1838. if theEvaluation == nil {
  1839. evaluation.CreatedTime = time.Now().Unix()
  1840. evaluation.Status = 1
  1841. evaluation.AssessmentDate = theAssessmentDateTime
  1842. evaluation.PatientId = id
  1843. evaluation.UserOrgId = adminUserInfo.Org.Id
  1844. if appRole.UserType == 2 || appRole.UserType == 1 {
  1845. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1846. evaluation.AssessmentTime = time.Now().Unix()
  1847. } else {
  1848. evaluation.Creater = adminUserInfo.AdminUser.Id
  1849. }
  1850. } else {
  1851. evaluation.UpdatedTime = time.Now().Unix()
  1852. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  1853. if appRole.UserType == 2 || appRole.UserType == 1 {
  1854. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1855. evaluation.AssessmentTime = time.Now().Unix()
  1856. } else {
  1857. evaluation.Modifier = adminUserInfo.AdminUser.Id
  1858. if evaluation.Creater == 0 {
  1859. evaluation.Creater = adminUserInfo.AdminUser.Id
  1860. }
  1861. }
  1862. }
  1863. //新增逻辑
  1864. var dewater_amount float64
  1865. dewater_amount = 0
  1866. if evaluation.DryWeight > 0 {
  1867. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  1868. if template.TemplateId == 17 || template.TemplateId == 22 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 34 || template.TemplateId == 32 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 3877 {
  1869. dewater_amount = dewater_amount * 1000
  1870. }
  1871. if dewater_amount <= 0 {
  1872. dewater_amount = 0
  1873. }
  1874. } else {
  1875. dewater_amount = 0
  1876. }
  1877. // 计算透析处方的相关超滤量
  1878. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  1879. lastDialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient.ID, adminUserInfo.Org.Id)
  1880. var lastDialysisPrescribe *models.DialysisPrescription
  1881. var dialysisSolution *models.DialysisSolution
  1882. var dialysisPrescribe *models.DialysisPrescription
  1883. var system_dialysisPrescribe *models.SystemPrescription
  1884. var mode_id int64
  1885. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  1886. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  1887. if schedual != nil {
  1888. // 获取透析模版
  1889. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  1890. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, schedual.ModeId)
  1891. mode_id = schedual.ModeId
  1892. } else {
  1893. // 获取透析模版
  1894. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  1895. if dialysisPrescribe == nil && dialysisSolution != nil {
  1896. mode_id = dialysisSolution.ModeId
  1897. }
  1898. if dialysisPrescribe == nil && dialysisSolution == nil {
  1899. mode_id = 0
  1900. }
  1901. }
  1902. // 插入透析处方
  1903. if dialysisPrescribe == nil && dialysisSolution != nil {
  1904. var newprescribe models.DialysisPrescription
  1905. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  1906. newprescribe.PatientId = dialysisSolution.PatientId
  1907. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  1908. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  1909. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  1910. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  1911. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  1912. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  1913. newprescribe.ModeId = dialysisSolution.ModeId
  1914. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  1915. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  1916. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  1917. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  1918. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  1919. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  1920. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  1921. newprescribe.Glucose = dialysisSolution.Glucose
  1922. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  1923. newprescribe.Kalium = dialysisSolution.Kalium
  1924. newprescribe.Sodium = dialysisSolution.Sodium
  1925. newprescribe.Calcium = dialysisSolution.Calcium
  1926. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  1927. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  1928. newprescribe.Conductivity = dialysisSolution.Conductivity
  1929. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  1930. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  1931. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  1932. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  1933. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  1934. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  1935. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  1936. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  1937. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  1938. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  1939. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  1940. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  1941. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  1942. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  1943. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  1944. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  1945. newprescribe.CreatedTime = time.Now().Unix()
  1946. newprescribe.UpdatedTime = time.Now().Unix()
  1947. newprescribe.RecordDate = theAssessmentDateTime
  1948. newprescribe.DewaterAmount = dewater_amount
  1949. newprescribe.TargetUltrafiltration = dewater_amount
  1950. newprescribe.Status = 1
  1951. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  1952. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  1953. newprescribe.Remark = lastDialysisPrescription.Remark
  1954. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  1955. newprescribe.ID = dialysisPrescription.ID
  1956. if dialysisPrescription.ID == 0 {
  1957. if adminUserInfo.Org.Id == 10340 {
  1958. newprescribe.Sodium = 138
  1959. newprescribe.Bicarbonate = 31.1
  1960. newprescribe.DialysateFlow = 500
  1961. newprescribe.PrescribingNumber = 1
  1962. }
  1963. err := service.AddSigleRecord(&newprescribe)
  1964. //获取key,清空redis
  1965. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1966. redis := service.RedisClient()
  1967. //清空key 值
  1968. redis.Set(key, "", time.Second)
  1969. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1970. //清空key 值
  1971. redis.Set(keyOne, "", time.Second)
  1972. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1973. //清空key 值
  1974. redis.Set(keyTwo, "", time.Second)
  1975. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1976. redis.Set(keySix, "", time.Second)
  1977. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1978. redis.Set(keySeven, "", time.Second)
  1979. if err != nil {
  1980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1981. }
  1982. } else {
  1983. if adminUserInfo.Org.Id == 10340 {
  1984. newprescribe.Sodium = 138
  1985. newprescribe.Bicarbonate = 31.1
  1986. newprescribe.DialysateFlow = 500
  1987. }
  1988. err := service.UpDateDialysisPrescription(&newprescribe)
  1989. //获取key,清空redis
  1990. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1991. redis := service.RedisClient()
  1992. //清空key 值
  1993. redis.Set(key, "", time.Second)
  1994. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1995. //清空key 值
  1996. redis.Set(keyOne, "", time.Second)
  1997. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1998. //清空key 值
  1999. redis.Set(keyTwo, "", time.Second)
  2000. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2001. redis.Set(keySix, "", time.Second)
  2002. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2003. redis.Set(keySeven, "", time.Second)
  2004. if err != nil {
  2005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2006. }
  2007. }
  2008. }
  2009. if dialysisPrescribe == nil && dialysisSolution == nil {
  2010. if lastDialysisPrescribe != nil {
  2011. var newprescribe models.DialysisPrescription
  2012. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  2013. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  2014. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2015. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2016. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2017. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2018. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2019. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2020. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2021. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2022. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2023. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2024. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2025. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2026. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2027. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2028. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2029. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2030. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2031. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2032. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2033. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2034. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2035. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2036. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2037. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2038. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2039. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2040. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2041. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2042. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2043. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2044. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2045. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2046. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2047. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2048. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2049. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2050. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2051. newprescribe.CreatedTime = time.Now().Unix()
  2052. newprescribe.UpdatedTime = time.Now().Unix()
  2053. newprescribe.RecordDate = theAssessmentDateTime
  2054. newprescribe.DewaterAmount = dewater_amount
  2055. newprescribe.TargetUltrafiltration = dewater_amount
  2056. newprescribe.Status = 1
  2057. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  2058. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  2059. newprescribe.Remark = lastDialysisPrescription.Remark
  2060. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2061. newprescribe.ID = dialysisPrescription.ID
  2062. if dialysisPrescription.ID == 0 {
  2063. if adminUserInfo.Org.Id == 10340 {
  2064. newprescribe.Sodium = 138
  2065. newprescribe.Bicarbonate = 31.1
  2066. newprescribe.DialysateFlow = 500
  2067. }
  2068. err := service.AddSigleRecord(&newprescribe)
  2069. //获取key,清空redis
  2070. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2071. redis := service.RedisClient()
  2072. //清空key 值
  2073. redis.Set(key, "", time.Second)
  2074. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2075. //清空key 值
  2076. redis.Set(keyOne, "", time.Second)
  2077. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2078. //清空key 值
  2079. redis.Set(keyTwo, "", time.Second)
  2080. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2081. redis.Set(keySix, "", time.Second)
  2082. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2083. redis.Set(keySeven, "", time.Second)
  2084. if err != nil {
  2085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2086. }
  2087. } else {
  2088. err := service.UpDateDialysisPrescription(&newprescribe)
  2089. //获取key,清空redis
  2090. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2091. redis := service.RedisClient()
  2092. //清空key 值
  2093. redis.Set(key, "", time.Second)
  2094. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2095. //清空key 值
  2096. redis.Set(keyOne, "", time.Second)
  2097. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2098. //清空key 值
  2099. redis.Set(keyTwo, "", time.Second)
  2100. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2101. redis.Set(keySix, "", time.Second)
  2102. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2103. redis.Set(keySeven, "", time.Second)
  2104. if err != nil {
  2105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2106. }
  2107. }
  2108. if err != nil {
  2109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2110. }
  2111. } else if system_dialysisPrescribe != nil {
  2112. var newprescribe models.DialysisPrescription
  2113. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  2114. newprescribe.PatientId = id
  2115. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  2116. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  2117. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  2118. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  2119. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  2120. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  2121. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  2122. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  2123. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  2124. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  2125. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  2126. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  2127. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  2128. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  2129. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  2130. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  2131. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  2132. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  2133. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  2134. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  2135. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  2136. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  2137. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  2138. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  2139. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  2140. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  2141. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  2142. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  2143. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  2144. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  2145. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  2146. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  2147. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  2148. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  2149. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  2150. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  2151. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  2152. newprescribe.CreatedTime = time.Now().Unix()
  2153. newprescribe.UpdatedTime = time.Now().Unix()
  2154. newprescribe.RecordDate = theAssessmentDateTime
  2155. newprescribe.DewaterAmount = dewater_amount
  2156. newprescribe.TargetUltrafiltration = dewater_amount
  2157. newprescribe.Status = 1
  2158. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  2159. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  2160. newprescribe.Remark = lastDialysisPrescription.Remark
  2161. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2162. newprescribe.ID = dialysisPrescription.ID
  2163. if dialysisPrescription.ID == 0 {
  2164. if adminUserInfo.Org.Id == 10340 {
  2165. newprescribe.Sodium = 138
  2166. newprescribe.Bicarbonate = 31.1
  2167. newprescribe.DialysateFlow = 500
  2168. }
  2169. err := service.AddSigleRecord(&newprescribe)
  2170. //获取key,清空redis
  2171. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2172. redis := service.RedisClient()
  2173. //清空key 值
  2174. redis.Set(key, "", time.Second)
  2175. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2176. //清空key 值
  2177. redis.Set(keyOne, "", time.Second)
  2178. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2179. //清空key 值
  2180. redis.Set(keyTwo, "", time.Second)
  2181. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2182. redis.Set(keySix, "", time.Second)
  2183. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2184. redis.Set(keySeven, "", time.Second)
  2185. if err != nil {
  2186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2187. }
  2188. } else {
  2189. if adminUserInfo.Org.Id == 10340 {
  2190. newprescribe.Sodium = 138
  2191. newprescribe.Bicarbonate = 31.1
  2192. newprescribe.DialysateFlow = 500
  2193. }
  2194. err := service.UpDateDialysisPrescription(&newprescribe)
  2195. //获取key,清空redis
  2196. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2197. redis := service.RedisClient()
  2198. //清空key 值
  2199. redis.Set(key, "", time.Second)
  2200. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2201. //清空key 值
  2202. redis.Set(keyOne, "", time.Second)
  2203. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2204. //清空key 值
  2205. redis.Set(keyTwo, "", time.Second)
  2206. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2207. redis.Set(keySix, "", time.Second)
  2208. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2209. redis.Set(keySeven, "", time.Second)
  2210. if err != nil {
  2211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2212. }
  2213. }
  2214. if err != nil {
  2215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2216. }
  2217. } else {
  2218. var newprescribe models.DialysisPrescription
  2219. newprescribe.UserOrgId = adminUserInfo.Org.Id
  2220. newprescribe.PatientId = id
  2221. newprescribe.ModeId = mode_id
  2222. newprescribe.CreatedTime = time.Now().Unix()
  2223. newprescribe.UpdatedTime = time.Now().Unix()
  2224. newprescribe.RecordDate = theAssessmentDateTime
  2225. newprescribe.DewaterAmount = dewater_amount
  2226. newprescribe.TargetUltrafiltration = dewater_amount
  2227. newprescribe.Status = 1
  2228. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  2229. newprescribe.ID = dialysisPrescription.ID
  2230. if dialysisPrescription.ID == 0 {
  2231. if adminUserInfo.Org.Id == 10340 {
  2232. newprescribe.Sodium = 138
  2233. newprescribe.Bicarbonate = 31.1
  2234. newprescribe.DialysateFlow = 500
  2235. }
  2236. err := service.AddSigleRecord(&newprescribe)
  2237. //获取key,清空redis
  2238. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2239. redis := service.RedisClient()
  2240. //清空key 值
  2241. redis.Set(key, "", time.Second)
  2242. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2243. //清空key 值
  2244. redis.Set(keyOne, "", time.Second)
  2245. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2246. //清空key 值
  2247. redis.Set(keyTwo, "", time.Second)
  2248. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2249. redis.Set(keySix, "", time.Second)
  2250. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2251. redis.Set(keySeven, "", time.Second)
  2252. if err != nil {
  2253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2254. }
  2255. } else {
  2256. if adminUserInfo.Org.Id == 10340 {
  2257. newprescribe.Sodium = 138
  2258. newprescribe.Bicarbonate = 31.1
  2259. newprescribe.DialysateFlow = 500
  2260. }
  2261. err := service.UpDateDialysisPrescription(&newprescribe)
  2262. //获取key,清空redis
  2263. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2264. redis := service.RedisClient()
  2265. //清空key 值
  2266. redis.Set(key, "", time.Second)
  2267. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2268. //清空key 值
  2269. redis.Set(keyOne, "", time.Second)
  2270. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2271. //清空key 值
  2272. redis.Set(keyTwo, "", time.Second)
  2273. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  2274. redis.Set(keySix, "", time.Second)
  2275. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  2276. redis.Set(keySeven, "", time.Second)
  2277. if err != nil {
  2278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2279. }
  2280. }
  2281. if err != nil {
  2282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2283. }
  2284. }
  2285. }
  2286. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  2287. // if dialysisPrescribe != nil {
  2288. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  2289. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  2290. // dialysisPrescribe.DewaterAmount = dewater_amount
  2291. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  2292. // dialysisPrescribe.Status = 1
  2293. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  2294. // if updateErr != nil {
  2295. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2296. // }
  2297. // }
  2298. // 查询信息规挡的设置天数
  2299. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2300. if infor.ID > 0 {
  2301. var cha_time int64
  2302. timeNowStr := time.Now().Format("2006-01-02")
  2303. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2304. //今日的日期减去设置的日期
  2305. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2306. if cha_time >= evaluation.AssessmentDate {
  2307. //查询审核是否允许
  2308. infor, _ := service.GetDialysisInformationByRecordDate(id, evaluation.AssessmentDate, adminUserInfo.Org.Id)
  2309. //申请状态不允许的情况 拒绝修改
  2310. if infor.ApplicationStatus != 1 {
  2311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2312. return
  2313. }
  2314. }
  2315. }
  2316. err = service.UpadatePredialysisEvaluation(&evaluation)
  2317. finish := models.XtDialysisFinish{
  2318. IsFinish: 1,
  2319. UserOrgId: adminUserInfo.Org.Id,
  2320. Status: 1,
  2321. Ctime: time.Now().Unix(),
  2322. Mtime: 0,
  2323. Module: 3,
  2324. RecordDate: evaluation.AssessmentDate,
  2325. Sourse: 1,
  2326. PatientId: id,
  2327. }
  2328. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, evaluation.AssessmentDate, 3, id)
  2329. if dialysisFinish.ID == 0 {
  2330. service.CreateDialysisFinish(finish)
  2331. }
  2332. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  2333. redis := service.RedisClient()
  2334. defer redis.Close()
  2335. //清空key 值
  2336. redis.Set(key, "", time.Second)
  2337. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  2338. redis.Set(keyOne, "", time.Second)
  2339. keyTwo := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2340. redis.Set(keyTwo, "", time.Second)
  2341. if err != nil {
  2342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  2343. return
  2344. }
  2345. c.ServeSuccessJSON(map[string]interface{}{
  2346. "msg": "ok",
  2347. "evaluation": evaluation,
  2348. })
  2349. return
  2350. }
  2351. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  2352. dataBody := make(map[string]interface{}, 0)
  2353. err := json.Unmarshal(data, &dataBody)
  2354. utils.InfoLog(string(data))
  2355. if err != nil {
  2356. utils.ErrorLog(err.Error())
  2357. code = enums.ErrorCodeParamWrong
  2358. return
  2359. }
  2360. // if method == "create" {
  2361. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  2362. utils.ErrorLog("mode")
  2363. code = enums.ErrorCodeParamWrong
  2364. return
  2365. }
  2366. mode := int64(dataBody["mode"].(float64))
  2367. if mode <= 0 {
  2368. utils.ErrorLog("mode <= 0")
  2369. code = enums.ErrorCodeParamWrong
  2370. return
  2371. }
  2372. solution.ModeId = mode
  2373. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  2374. utils.ErrorLog("mode_name")
  2375. code = enums.ErrorCodeParamWrong
  2376. return
  2377. }
  2378. modeName, _ := dataBody["mode_name"].(string)
  2379. if len(modeName) == 0 {
  2380. utils.ErrorLog("len(mode_name) == 0")
  2381. code = enums.ErrorCodeParamWrong
  2382. return
  2383. }
  2384. solution.ModeName = modeName
  2385. solution.Name = modeName
  2386. // }
  2387. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2388. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2389. solution.DialysisDuration = dialysisDuration
  2390. }
  2391. if dataBody["dialysis_duration"] != nil {
  2392. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2393. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2394. solution.DialysisDuration = dialysisDuration
  2395. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  2396. dialysisDuration := dataBody["dialysis_duration"].(float64)
  2397. solution.DialysisDuration = dialysisDuration
  2398. }
  2399. }
  2400. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  2401. dialyzer := int64(dataBody["dialyzer"].(float64))
  2402. solution.Dialyzer = dialyzer
  2403. }
  2404. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  2405. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  2406. solution.PerfusionApparatus = perfusionApparatus
  2407. }
  2408. if dataBody["blood_flow_volume"] != nil {
  2409. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  2410. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  2411. solution.BloodFlowVolume = bloodFlowVolume
  2412. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  2413. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  2414. solution.BloodFlowVolume = bloodFlowVolume
  2415. }
  2416. }
  2417. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  2418. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  2419. solution.HemodialysisMachine = hemodialysisMachine
  2420. }
  2421. if dataBody["dewater"] != nil {
  2422. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  2423. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  2424. solution.Dewater = dewater
  2425. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  2426. dewater := dataBody["dewater"].(float64)
  2427. solution.Dewater = dewater
  2428. }
  2429. }
  2430. if dataBody["replacement_total"] != nil {
  2431. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  2432. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  2433. solution.ReplacementTotal = replacementTotal
  2434. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  2435. replacementTotal := dataBody["replacement_total"].(float64)
  2436. solution.ReplacementTotal = replacementTotal
  2437. }
  2438. }
  2439. if dataBody["displace_liqui"] != nil {
  2440. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  2441. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  2442. solution.DisplaceLiqui = displaceLiqui
  2443. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  2444. displaceLiqui := dataBody["displace_liqui"].(float64)
  2445. solution.DisplaceLiqui = displaceLiqui
  2446. }
  2447. }
  2448. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  2449. replacementWay := int64(dataBody["replacement_way"].(float64))
  2450. solution.ReplacementWay = replacementWay
  2451. }
  2452. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  2453. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  2454. solution.Anticoagulant = anticoagulant
  2455. }
  2456. if dataBody["anticoagulant_shouji"] != nil {
  2457. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  2458. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  2459. solution.AnticoagulantShouji = anticoagulantShouji
  2460. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  2461. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  2462. solution.AnticoagulantShouji = anticoagulantShouji
  2463. }
  2464. }
  2465. if dataBody["anticoagulant_weichi"] != nil {
  2466. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  2467. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  2468. solution.AnticoagulantWeichi = anticoagulantWeichi
  2469. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  2470. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  2471. solution.AnticoagulantWeichi = anticoagulantWeichi
  2472. }
  2473. }
  2474. if dataBody["anticoagulant_zongliang"] != nil {
  2475. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  2476. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  2477. solution.AnticoagulantZongliang = anticoagulantZongliang
  2478. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  2479. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  2480. solution.AnticoagulantZongliang = anticoagulantZongliang
  2481. }
  2482. }
  2483. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  2484. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  2485. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  2486. }
  2487. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  2488. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  2489. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  2490. }
  2491. if dataBody["kalium"] != nil {
  2492. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  2493. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  2494. solution.Kalium = kalium
  2495. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  2496. kalium := dataBody["kalium"].(float64)
  2497. solution.Kalium = kalium
  2498. }
  2499. }
  2500. if dataBody["sodium"] != nil {
  2501. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  2502. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  2503. solution.Sodium = sodium
  2504. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  2505. sodium := dataBody["sodium"].(float64)
  2506. solution.Sodium = sodium
  2507. }
  2508. }
  2509. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  2510. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  2511. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  2512. solution.Calcium = calcium
  2513. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  2514. calcium := dataBody["calcium"].(float64)
  2515. solution.Calcium = calcium
  2516. }
  2517. }
  2518. if dataBody["bicarbonate"] != nil {
  2519. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  2520. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  2521. solution.Bicarbonate = bicarbonate
  2522. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  2523. bicarbonate := dataBody["bicarbonate"].(float64)
  2524. solution.Bicarbonate = bicarbonate
  2525. }
  2526. }
  2527. if dataBody["glucose"] != nil {
  2528. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  2529. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  2530. solution.Glucose = glucose
  2531. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  2532. glucose := dataBody["glucose"].(float64)
  2533. solution.Glucose = glucose
  2534. }
  2535. }
  2536. // if dataBody["dry_weight"] != nil {
  2537. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  2538. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  2539. // solution.DryWeight = dryWeight
  2540. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  2541. // dryWeight := dataBody["dry_weight"].(float64)
  2542. // solution.DryWeight = dryWeight
  2543. // }
  2544. // }
  2545. if dataBody["dialysate_flow"] != nil {
  2546. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  2547. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  2548. solution.DialysateFlow = dialysateFlow
  2549. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  2550. dialysateFlow := dataBody["dialysate_flow"].(float64)
  2551. solution.DialysateFlow = dialysateFlow
  2552. }
  2553. }
  2554. if dataBody["dialysate_temperature"] != nil {
  2555. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  2556. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  2557. solution.DialysateTemperature = dialysateTemperature
  2558. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  2559. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  2560. solution.DialysateTemperature = dialysateTemperature
  2561. }
  2562. }
  2563. if dataBody["conductivity"] != nil {
  2564. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  2565. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  2566. solution.Conductivity = conductivity
  2567. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  2568. conductivity := dataBody["conductivity"].(float64)
  2569. solution.Conductivity = conductivity
  2570. }
  2571. }
  2572. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2573. remark := dataBody["remark"].(string)
  2574. solution.Remark = remark
  2575. }
  2576. if dataBody["dialysis_duration_hour"] != nil {
  2577. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  2578. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  2579. solution.DialysisDurationHour = dialysisDurationHour
  2580. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  2581. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  2582. solution.DialysisDurationHour = int64(dialysisDurationHour)
  2583. }
  2584. }
  2585. if dataBody["dialysis_duration_minute"] != nil {
  2586. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  2587. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  2588. solution.DialysisDurationMinute = dialysisDurationMinute
  2589. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  2590. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  2591. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  2592. }
  2593. }
  2594. if dataBody["target_ultrafiltration"] != nil {
  2595. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  2596. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  2597. solution.TargetUltrafiltration = targetUltrafiltration
  2598. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  2599. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  2600. solution.TargetUltrafiltration = targetUltrafiltration
  2601. }
  2602. }
  2603. if dataBody["dialysate_formulation"] != nil {
  2604. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  2605. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  2606. solution.DialysateFormulation = dialysateFormulation
  2607. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  2608. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  2609. solution.DialysateFormulation = int64(dialysateFormulation)
  2610. }
  2611. }
  2612. return
  2613. }
  2614. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  2615. dataBody := make(map[string]interface{}, 0)
  2616. err := json.Unmarshal(data, &dataBody)
  2617. utils.InfoLog(string(data))
  2618. if err != nil {
  2619. utils.ErrorLog(err.Error())
  2620. code = enums.ErrorCodeParamWrong
  2621. return
  2622. }
  2623. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  2624. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  2625. evaluation.WeightBefore = weightVefore
  2626. }
  2627. // fmt.Println(dataBody["dry_weight"])
  2628. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  2629. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  2630. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  2631. fmt.Println(additionalWeight)
  2632. evaluation.DryWeight = additionalWeight
  2633. }
  2634. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  2635. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  2636. fmt.Println(additionalWeight)
  2637. evaluation.AdditionalWeight = additionalWeight
  2638. }
  2639. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  2640. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  2641. evaluation.Temperature = Temperature
  2642. }
  2643. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  2644. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  2645. evaluation.SystolicBloodPressure = systolicBloodPressure
  2646. }
  2647. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  2648. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  2649. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  2650. }
  2651. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  2652. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  2653. evaluation.PulseFrequency = pulseFrequency
  2654. }
  2655. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  2656. breathingRate := dataBody["breathing_rate"].(string)
  2657. evaluation.BreathingRate = breathingRate
  2658. }
  2659. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  2660. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  2661. evaluation.LastPostDialysis = lastPostDialysis
  2662. }
  2663. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  2664. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  2665. evaluation.DialysisInterphase = dialysisInterphase
  2666. }
  2667. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  2668. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  2669. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  2670. }
  2671. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  2672. catheter, _ := dataBody["catheter"].(string)
  2673. evaluation.Catheter = catheter
  2674. }
  2675. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  2676. catheter_bend := int(dataBody["catheter_bend"].(float64))
  2677. evaluation.CatheterBend = catheter_bend
  2678. }
  2679. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  2680. Complication, _ := dataBody["complication"].(string)
  2681. evaluation.Complication = Complication
  2682. }
  2683. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2684. remark := dataBody["remark"].(string)
  2685. evaluation.Remark = remark
  2686. }
  2687. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  2688. machine_type := dataBody["machine_type"].(string)
  2689. evaluation.MachineType = machine_type
  2690. }
  2691. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  2692. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  2693. evaluation.BloodAccessPartId = blood_access_part_id
  2694. }
  2695. //if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  2696. // blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  2697. // evaluation.BloodAccessPartId = blood_access_part_id
  2698. //}
  2699. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  2700. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  2701. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  2702. }
  2703. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  2704. internal_fistula, _ := dataBody["internal_fistula"].(string)
  2705. evaluation.InternalFistula = internal_fistula
  2706. }
  2707. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  2708. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  2709. evaluation.InternalFistulaSkin = internal_fistula_skin
  2710. }
  2711. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "string" {
  2712. ishemorrhage, _ := dataBody["is_hemorrhage"].(string)
  2713. is_hemorrhage, _ := strconv.ParseInt(ishemorrhage, 10, 64)
  2714. evaluation.IsHemorrhage = is_hemorrhage
  2715. //if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  2716. // is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  2717. // fmt.Println("is_hemorrhage2222222222222222",is_hemorrhage)
  2718. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  2719. is_hemorrhage = 0
  2720. }
  2721. evaluation.IsHemorrhage = is_hemorrhage
  2722. if is_hemorrhage == 1 {
  2723. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  2724. hemorrhage, _ := dataBody["hemorrhage"].(string)
  2725. evaluation.Hemorrhage = hemorrhage
  2726. }
  2727. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  2728. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  2729. evaluation.HemorrhageOther = hemorrhage_other
  2730. }
  2731. }
  2732. } else {
  2733. evaluation.IsHemorrhage = 0
  2734. }
  2735. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  2736. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  2737. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  2738. }
  2739. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  2740. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  2741. evaluation.InternalFistulaOther = internal_fistula_other
  2742. }
  2743. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  2744. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  2745. evaluation.BloodAccessNoise = blood_access_noise
  2746. }
  2747. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "string" {
  2748. //puncture_way := int64(dataBody["puncture_way"].(float64))
  2749. puncture_way := dataBody["puncture_way"].(string)
  2750. evaluation.PunctureWay = puncture_way
  2751. }
  2752. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  2753. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  2754. evaluation.VenousCatheterization = venous_catheterization
  2755. }
  2756. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  2757. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  2758. evaluation.VenousCatheterizationPart = venous_catheterization_part
  2759. }
  2760. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  2761. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  2762. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  2763. }
  2764. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  2765. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  2766. evaluation.DuctusArantii = ductus_arantii
  2767. }
  2768. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  2769. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  2770. evaluation.EmergencyTreatment = emergency_treatment
  2771. }
  2772. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  2773. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  2774. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  2775. }
  2776. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  2777. dialysis_count, _ := dataBody["dialysis_count"].(string)
  2778. //count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  2779. evaluation.DialysisCount = dialysis_count
  2780. }
  2781. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  2782. is_infect, _ := dataBody["is_infect"].(string)
  2783. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  2784. evaluation.IsInfect = infect
  2785. }
  2786. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  2787. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  2788. evaluation.Exposed = exposed
  2789. }
  2790. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  2791. skin, _ := dataBody["skin"].(string)
  2792. //skins, _ := strconv.ParseInt(skin, 10, 64)
  2793. evaluation.Skin = skin
  2794. }
  2795. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  2796. skin_other, _ := dataBody["skin_other"].(string)
  2797. evaluation.SkinOther = skin_other
  2798. }
  2799. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  2800. infect_other, _ := dataBody["infect_other"].(string)
  2801. evaluation.InfectOther = infect_other
  2802. }
  2803. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  2804. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  2805. evaluation.DuctusArantiiOther = ductus_arantii_other
  2806. }
  2807. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  2808. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  2809. evaluation.PunctureNeedle = punctureNeedle
  2810. }
  2811. if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "string" {
  2812. humor_excessive_symptom, _ := dataBody["humor_excessive_symptom"].(string)
  2813. evaluation.HumorExcessiveSymptom = humor_excessive_symptom
  2814. }
  2815. if dataBody["pinholing"] != nil && reflect.TypeOf(dataBody["pinholing"]).String() == "string" {
  2816. pinholing := dataBody["pinholing"].(string)
  2817. evaluation.Phinholing = pinholing
  2818. }
  2819. if dataBody["catheter_suture"] != nil && reflect.TypeOf(dataBody["catheter_suture"]).String() == "string" {
  2820. catheter_suture := dataBody["catheter_suture"].(string)
  2821. evaluation.CatheterSuture = catheter_suture
  2822. }
  2823. if dataBody["catheter_suture_other"] != nil && reflect.TypeOf(dataBody["catheter_suture_other"]).String() == "string" {
  2824. catheter_suture_other := dataBody["catheter_suture_other"].(string)
  2825. evaluation.CatheterSutureOther = catheter_suture_other
  2826. }
  2827. if dataBody["urine_volume"] != nil && reflect.TypeOf(dataBody["urine_volume"]).String() == "string" {
  2828. urine_volume, _ := strconv.ParseFloat(dataBody["urine_volume"].(string), 64)
  2829. evaluation.UrineVolume = urine_volume
  2830. }
  2831. if dataBody["edema"] != nil && reflect.TypeOf(dataBody["edema"]).String() == "string" {
  2832. edema := dataBody["edema"].(string)
  2833. evaluation.Edema = edema
  2834. }
  2835. if dataBody["special_treatment"] != nil && reflect.TypeOf(dataBody["special_treatment"]).String() == "string" {
  2836. specialTreatment := dataBody["special_treatment"].(string)
  2837. evaluation.SpecialTreatment = specialTreatment
  2838. }
  2839. if dataBody["catheter_maintenance"] != nil && reflect.TypeOf(dataBody["catheter_maintenance"]).String() == "string" {
  2840. catheter_maintenance := dataBody["catheter_maintenance"].(string)
  2841. evaluation.CatheterMaintenance = catheter_maintenance
  2842. }
  2843. if dataBody["thromubus_type"] != nil && reflect.TypeOf(dataBody["thromubus_type"]).String() == "float64" {
  2844. thromubusType := int64(dataBody["thromubus_type"].(float64))
  2845. evaluation.ThromubusType = thromubusType
  2846. }
  2847. if dataBody["thrombus_av"] != nil && reflect.TypeOf(dataBody["thrombus_av"]).String() == "string" {
  2848. thrombus_av := dataBody["thrombus_av"].(string)
  2849. evaluation.ThrombusAv = thrombus_av
  2850. }
  2851. if dataBody["thromubus_a"] != nil && reflect.TypeOf(dataBody["thromubus_a"]).String() == "string" {
  2852. thromubus_a := dataBody["thromubus_a"].(string)
  2853. evaluation.ThromubusA = thromubus_a
  2854. }
  2855. if dataBody["thromubus_v"] != nil && reflect.TypeOf(dataBody["thromubus_v"]).String() == "string" {
  2856. thromubus_v := dataBody["thromubus_v"].(string)
  2857. evaluation.ThromubusV = thromubus_v
  2858. }
  2859. if dataBody["dehydration"] != nil && reflect.TypeOf(dataBody["dehydration"]).String() == "string" {
  2860. dehydration := dataBody["dehydration"].(string)
  2861. evaluation.Dehydration = dehydration
  2862. }
  2863. if dataBody["period"] != nil && reflect.TypeOf(dataBody["period"]).String() == "float64" {
  2864. period := int64(dataBody["period"].(float64))
  2865. evaluation.Period = period
  2866. }
  2867. if dataBody["estimated_food_intake"] != nil && reflect.TypeOf(dataBody["estimated_food_intake"]).String() == "string" {
  2868. estimated_food_intake := dataBody["estimated_food_intake"].(string)
  2869. evaluation.EstimatedFoodIntake = estimated_food_intake
  2870. }
  2871. if dataBody["blood_pressure_during_dialysis"] != nil && reflect.TypeOf(dataBody["blood_pressure_during_dialysis"]).String() == "string" {
  2872. blood_pressure_during_dialysis := dataBody["blood_pressure_during_dialysis"].(string)
  2873. evaluation.BloodPressureDuringDialysis = blood_pressure_during_dialysis
  2874. }
  2875. if dataBody["pre_dialysis_drugs"] != nil && reflect.TypeOf(dataBody["pre_dialysis_drugs"]).String() == "string" {
  2876. pre_dialysis_drugs := dataBody["pre_dialysis_drugs"].(string)
  2877. evaluation.PreDialysisDrugs = pre_dialysis_drugs
  2878. }
  2879. if dataBody["urea_befor"] != nil && reflect.TypeOf(dataBody["urea_befor"]).String() == "string" {
  2880. urea_befor := dataBody["urea_befor"].(string)
  2881. evaluation.UreaBefor = urea_befor
  2882. }
  2883. if dataBody["suction"] != nil && reflect.TypeOf(dataBody["suction"]).String() == "string" {
  2884. suction := dataBody["suction"].(string)
  2885. evaluation.Suction = suction
  2886. }
  2887. if dataBody["weight_befor_remake"] != nil && reflect.TypeOf(dataBody["weight_befor_remake"]).String() == "string" {
  2888. weight_befor_remake := dataBody["weight_befor_remake"].(string)
  2889. evaluation.WeightBeforRemake = weight_befor_remake
  2890. }
  2891. if dataBody["height"] != nil && reflect.TypeOf(dataBody["height"]).String() == "string" {
  2892. height := dataBody["height"].(string)
  2893. evaluation.Height = height
  2894. }
  2895. if dataBody["age"] != nil && reflect.TypeOf(dataBody["age"]).String() == "string" {
  2896. age := dataBody["age"].(string)
  2897. evaluation.Age = age
  2898. }
  2899. if dataBody["his_department"] != nil && reflect.TypeOf(dataBody["his_department"]).String() == "string" {
  2900. his_department := dataBody["his_department"].(string)
  2901. evaluation.HisDepartment = his_department
  2902. }
  2903. if dataBody["his_bed"] != nil && reflect.TypeOf(dataBody["his_bed"]).String() == "string" {
  2904. his_bed := dataBody["his_bed"].(string)
  2905. evaluation.HisBed = his_bed
  2906. }
  2907. if dataBody["point_puncture"] != nil && reflect.TypeOf(dataBody["point_puncture"]).String() == "string" {
  2908. point_puncture := dataBody["point_puncture"].(string)
  2909. evaluation.PointPuncture = point_puncture
  2910. }
  2911. if dataBody["catheter_evaluation_program"] != nil && reflect.TypeOf(dataBody["catheter_evaluation_program"]).String() == "string" {
  2912. catheter_evaluation_program := dataBody["catheter_evaluation_program"].(string)
  2913. evaluation.CatheterEvaluationProgram = catheter_evaluation_program
  2914. }
  2915. if dataBody["skin_site_catheterization"] != nil && reflect.TypeOf(dataBody["skin_site_catheterization"]).String() == "string" {
  2916. skin_site_catheterization := dataBody["skin_site_catheterization"].(string)
  2917. evaluation.SkinSiteCatheterization = skin_site_catheterization
  2918. }
  2919. if dataBody["whether_unobstructed"] != nil && reflect.TypeOf(dataBody["whether_unobstructed"]).String() == "float64" {
  2920. whether_unobstructed := int64(dataBody["whether_unobstructed"].(float64))
  2921. evaluation.WhetherUnobstructed = whether_unobstructed
  2922. }
  2923. if dataBody["lien_necessary"] != nil && reflect.TypeOf(dataBody["lien_necessary"]).String() == "float64" {
  2924. lien_necessary := int64(dataBody["lien_necessary"].(float64))
  2925. evaluation.LienNecessary = lien_necessary
  2926. }
  2927. if dataBody["pathway_formation_time"] != nil && reflect.TypeOf(dataBody["pathway_formation_time"]).String() == "string" {
  2928. pathway_formation_time := dataBody["pathway_formation_time"].(string)
  2929. timeLayout := "2006-01-02"
  2930. loc, _ := time.LoadLocation("Local")
  2931. var startTime int64
  2932. if len(pathway_formation_time) > 0 {
  2933. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", pathway_formation_time+" 00:00:00", loc)
  2934. startTime = theTime.Unix()
  2935. }
  2936. evaluation.PathwayFormationTime = startTime
  2937. }
  2938. if dataBody["befor_symptoms"] != nil && reflect.TypeOf(dataBody["befor_symptoms"]).String() == "string" {
  2939. befor_symptoms := dataBody["befor_symptoms"].(string)
  2940. evaluation.BeforSymptoms = befor_symptoms
  2941. fmt.Println("befor_symptomsss23333333333333333333333333", befor_symptoms)
  2942. }
  2943. return
  2944. }
  2945. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  2946. dataBody := make(map[string]interface{}, 0)
  2947. err := json.Unmarshal(data, &dataBody)
  2948. if err != nil {
  2949. utils.ErrorLog(err.Error())
  2950. code = enums.ErrorCodeParamWrong
  2951. return
  2952. }
  2953. timeLayout := "2006-01-02"
  2954. loc, _ := time.LoadLocation("Local")
  2955. isChild := false
  2956. if action == "create" {
  2957. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2958. utils.ErrorLog("advice_type")
  2959. code = enums.ErrorCodeParamWrong
  2960. return
  2961. }
  2962. adviceType := int64(dataBody["advice_type"].(float64))
  2963. if adviceType != 1 && adviceType != 2 {
  2964. utils.ErrorLog("advice_type != 1&&2")
  2965. code = enums.ErrorCodeParamWrong
  2966. return
  2967. }
  2968. advice.AdviceType = adviceType
  2969. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2970. utils.ErrorLog("advice_date")
  2971. code = enums.ErrorCodeParamWrong
  2972. return
  2973. }
  2974. adviceDate, _ := dataBody["advice_date"].(string)
  2975. if len(adviceDate) == 0 {
  2976. utils.ErrorLog("len(adviceDate) == 0")
  2977. code = enums.ErrorCodeParamWrong
  2978. return
  2979. }
  2980. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2981. if err != nil {
  2982. utils.ErrorLog(err.Error())
  2983. code = enums.ErrorCodeParamWrong
  2984. return
  2985. }
  2986. advice.AdviceDate = theTime.Unix()
  2987. advice.RecordDate = theTime.Unix()
  2988. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  2989. parentId := int64(dataBody["parent_id"].(float64))
  2990. advice.ParentId = parentId
  2991. if parentId > 0 {
  2992. isChild = true
  2993. }
  2994. }
  2995. } else {
  2996. isChild = advice.ParentId > 0
  2997. }
  2998. if !isChild {
  2999. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3000. utils.ErrorLog("start_time")
  3001. code = enums.ErrorCodeParamWrong
  3002. return
  3003. }
  3004. startTime, _ := dataBody["start_time"].(string)
  3005. if len(startTime) == 0 {
  3006. utils.ErrorLog("len(start_time) == 0")
  3007. code = enums.ErrorCodeParamWrong
  3008. return
  3009. }
  3010. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  3011. if err != nil {
  3012. utils.ErrorLog(err.Error())
  3013. code = enums.ErrorCodeParamWrong
  3014. return
  3015. }
  3016. advice.StartTime = theTime.Unix()
  3017. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  3018. deliveryWay, _ := dataBody["delivery_way"].(string)
  3019. advice.DeliveryWay = deliveryWay
  3020. }
  3021. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  3022. executionFrequency, _ := dataBody["execution_frequency"].(string)
  3023. advice.ExecutionFrequency = executionFrequency
  3024. }
  3025. }
  3026. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  3027. deliveryWay, _ := dataBody["delivery_way"].(string)
  3028. advice.DeliveryWay = deliveryWay
  3029. }
  3030. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  3031. executionFrequency, _ := dataBody["execution_frequency"].(string)
  3032. advice.ExecutionFrequency = executionFrequency
  3033. }
  3034. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  3035. utils.ErrorLog("advice_name")
  3036. code = enums.ErrorCodeParamWrong
  3037. return
  3038. }
  3039. adviceName, _ := dataBody["advice_name"].(string)
  3040. if len(adviceName) == 0 {
  3041. utils.ErrorLog("len(advice_name) == 0")
  3042. code = enums.ErrorCodeParamWrong
  3043. return
  3044. }
  3045. advice.AdviceName = adviceName
  3046. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3047. adviceDsc, _ := dataBody["advice_desc"].(string)
  3048. advice.AdviceDesc = adviceDsc
  3049. }
  3050. if dataBody["way"] == nil {
  3051. advice.Way = 0
  3052. } else {
  3053. if dataBody["way"] != nil || reflect.TypeOf(dataBody["way"]).String() == "float64" {
  3054. way := int64(dataBody["way"].(float64))
  3055. advice.Way = way
  3056. }
  3057. }
  3058. if dataBody["drug_id"] == nil {
  3059. advice.DrugId = 0
  3060. } else {
  3061. if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  3062. drug_id := int64(dataBody["drug_id"].(float64))
  3063. advice.DrugId = drug_id
  3064. }
  3065. }
  3066. if dataBody["drug_name_id"] == nil {
  3067. advice.DrugNameId = 0
  3068. } else {
  3069. if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  3070. drug_name_id := int64(dataBody["drug_name_id"].(float64))
  3071. advice.DrugNameId = drug_name_id
  3072. }
  3073. }
  3074. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3075. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3076. advice.SingleDose = singleDose
  3077. }
  3078. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3079. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3080. advice.SingleDoseUnit = singleDoseUnit
  3081. }
  3082. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  3083. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  3084. advice.DrugSpec = drugSpec
  3085. }
  3086. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3087. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3088. advice.DrugSpecUnit = drugSpecUnit
  3089. }
  3090. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3091. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3092. advice.PrescribingNumber = prescribingNumber
  3093. }
  3094. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3095. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3096. advice.PrescribingNumberUnit = prescribingNumberUnit
  3097. }
  3098. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3099. remark, _ := dataBody["remark"].(string)
  3100. advice.Remark = remark
  3101. }
  3102. return
  3103. }
  3104. func (c *PatientApiController) GetPatientEducation() {
  3105. patientID, _ := c.GetInt64("patient_id", 0)
  3106. page, _ := c.GetInt64("page", 0)
  3107. limit, _ := c.GetInt64("limit", 0)
  3108. startTime := c.GetString("start_time", "")
  3109. endTime := c.GetString("end_time", "")
  3110. if page <= 0 {
  3111. page = 1
  3112. }
  3113. if limit <= 0 {
  3114. limit = 10
  3115. }
  3116. if patientID <= 0 {
  3117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3118. return
  3119. }
  3120. timeLayout := "2006-01-02"
  3121. loc, _ := time.LoadLocation("Local")
  3122. var theStartTIme int64
  3123. if len(startTime) > 0 {
  3124. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3125. if err != nil {
  3126. theStartTIme = 0
  3127. }
  3128. theStartTIme = theTime.Unix()
  3129. }
  3130. var theEndtTIme int64
  3131. if len(endTime) > 0 {
  3132. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3133. if err != nil {
  3134. theEndtTIme = 0
  3135. }
  3136. theEndtTIme = theTime.Unix()
  3137. }
  3138. adminUserInfo := c.GetMobileAdminUserInfo()
  3139. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  3140. c.ServeSuccessJSON(map[string]interface{}{
  3141. "total": total,
  3142. "edus": edus,
  3143. })
  3144. return
  3145. }
  3146. func (c *PatientApiController) GetPatientSchedulesList() {
  3147. patientID, _ := c.GetInt64("patient_id", 0)
  3148. page, _ := c.GetInt64("page", 0)
  3149. limit, _ := c.GetInt64("limit", 0)
  3150. if patientID <= 0 {
  3151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3152. return
  3153. }
  3154. adminUserInfo := c.GetMobileAdminUserInfo()
  3155. todayTime := time.Now().Format("2006-01-02")
  3156. timeLayout := "2006-01-02 15:04:05"
  3157. loc, _ := time.LoadLocation("Local")
  3158. var theStartTime int64
  3159. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  3160. theStartTime = theTime.Unix()
  3161. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  3162. if len(schedules) > 0 {
  3163. for index, item := range schedules {
  3164. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  3165. schedules[index].Week = int64(week)
  3166. }
  3167. }
  3168. c.ServeSuccessJSON(map[string]interface{}{
  3169. "schedules": schedules,
  3170. })
  3171. return
  3172. }
  3173. func (c *PatientApiController) GetRecords() {
  3174. patientID, _ := c.GetInt64("patient_id", 0)
  3175. page, _ := c.GetInt64("page", 0)
  3176. limit, _ := c.GetInt64("limit", 0)
  3177. startTime := c.GetString("start_time", "")
  3178. endTime := c.GetString("end_time", "")
  3179. mode_id, _ := c.GetInt64("mode_id", 0)
  3180. if page <= 0 {
  3181. page = 1
  3182. }
  3183. if limit <= 0 {
  3184. limit = 10
  3185. }
  3186. if patientID <= 0 {
  3187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3188. return
  3189. }
  3190. timeLayout := "2006-01-02"
  3191. loc, _ := time.LoadLocation("Local")
  3192. var theStartTIme int64
  3193. if len(startTime) > 0 {
  3194. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3195. if err != nil {
  3196. theStartTIme = 0
  3197. }
  3198. theStartTIme = theTime.Unix()
  3199. }
  3200. var theEndtTIme int64
  3201. if len(endTime) > 0 {
  3202. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3203. if err != nil {
  3204. theEndtTIme = 0
  3205. }
  3206. theEndtTIme = theTime.Unix()
  3207. }
  3208. adminUserInfo := c.GetMobileAdminUserInfo()
  3209. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  3210. c.ServeSuccessJSON(map[string]interface{}{
  3211. "total": total,
  3212. "records": records,
  3213. })
  3214. return
  3215. }
  3216. func (c *PatientApiController) GetPatientMonitor() {
  3217. partition, _ := c.GetInt64("partition")
  3218. monitorDate := c.GetString("date")
  3219. patient_id, _ := c.GetInt64("patient_id")
  3220. timeLayout := "2006-01-02"
  3221. loc, _ := time.LoadLocation("Local")
  3222. var theStartTime int64
  3223. if len(monitorDate) > 0 {
  3224. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  3225. if err != nil {
  3226. theStartTime = 0
  3227. }
  3228. theStartTime = theTime.Unix()
  3229. }
  3230. adminInfo := c.GetMobileAdminUserInfo()
  3231. orgID := adminInfo.Org.Id
  3232. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition, patient_id)
  3233. fmt.Println("monitor-------------------", monitor)
  3234. if err != nil {
  3235. c.ErrorLog("获取排班信息失败:%v", err)
  3236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3237. } else {
  3238. if len(monitor) > 0 {
  3239. //获取所有床位
  3240. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  3241. //获取所有分区
  3242. zoneList, _ := service.GetAllZoneByList(orgID)
  3243. //获取透析处方
  3244. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  3245. //获取透前评估
  3246. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  3247. //获取上机
  3248. dialysisOrders, _ := service.GetAllDialysisOrdersByListSix(orgID, theStartTime)
  3249. //获取透后
  3250. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  3251. //获取透后监测
  3252. monitorlist, _ := service.GetAllMonitorList(orgID, theStartTime)
  3253. //获取所有的患者
  3254. patients, _ := service.GetAllPatientListByListOne(orgID)
  3255. //获取所有透析模式
  3256. treatments, _ := service.GetAllTreatModeByList(orgID)
  3257. for key, item := range monitor {
  3258. // 获取床位信息
  3259. for _, it := range numberList {
  3260. if item.BedId == it.ID {
  3261. monitor[key].DeviceNumber = it
  3262. break
  3263. }
  3264. }
  3265. //获取分区信息
  3266. for _, it := range zoneList {
  3267. if item.PartitionId == it.ID {
  3268. monitor[key].DeviceZone = it
  3269. }
  3270. }
  3271. for _, prescription := range prescriptions {
  3272. if item.PatientId == prescription.PatientId {
  3273. monitor[key].Prescription = prescription
  3274. break
  3275. }
  3276. }
  3277. // 透前评估
  3278. for _, assessmentBefore := range assessmentBefores {
  3279. if item.PatientId == assessmentBefore.PatientId {
  3280. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  3281. break
  3282. }
  3283. }
  3284. // 透析上下机
  3285. for _, dialysisOrder := range dialysisOrders {
  3286. if item.PatientId == dialysisOrder.PatientId {
  3287. monitor[key].DialysisOrder = dialysisOrder
  3288. break
  3289. }
  3290. }
  3291. // 治疗小节
  3292. for _, afterDislysis := range AssessmentAfterDislysis {
  3293. if item.PatientId == afterDislysis.PatientId {
  3294. monitor[key].AssessmentAfterDislysis = afterDislysis
  3295. break
  3296. }
  3297. }
  3298. for _, it := range monitorlist {
  3299. if item.PatientId == it.PatientId {
  3300. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  3301. }
  3302. }
  3303. for _, patient := range patients {
  3304. if item.PatientId == patient.ID {
  3305. monitor[key].MonitorPatients = patient
  3306. break
  3307. }
  3308. }
  3309. for _, treatment := range treatments {
  3310. if item.ModeId == treatment.ID {
  3311. monitor[key].TreatmentMode = treatment
  3312. break
  3313. }
  3314. }
  3315. }
  3316. }
  3317. }
  3318. //获取患者的透析次数
  3319. count, err := service.GetDialysisCount(orgID, partition)
  3320. patients, err := service.GetAllpatientThirty(orgID)
  3321. if err == nil {
  3322. c.ServeSuccessJSON(map[string]interface{}{
  3323. "monitor": monitor,
  3324. "patientCount": count,
  3325. "patients": patients,
  3326. })
  3327. } else {
  3328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3329. }
  3330. }
  3331. // /m/api/monitor/patient [get] 搜索病人的测量记录
  3332. // @param keyword:string 病人姓名或透析号
  3333. // @param page:int
  3334. func (this *PatientApiController) SearchMonitorPatient() {
  3335. keyword := this.GetString("keyword")
  3336. page, _ := this.GetInt("page")
  3337. if page <= 0 {
  3338. page = 1
  3339. }
  3340. if len(keyword) == 0 {
  3341. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3342. return
  3343. }
  3344. adminUserInfo := this.GetMobileAdminUserInfo()
  3345. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  3346. if getMonitorErr != nil {
  3347. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3348. return
  3349. } else {
  3350. this.ServeSuccessJSON(map[string]interface{}{
  3351. "monitor": monitors,
  3352. })
  3353. }
  3354. }
  3355. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  3356. id, _ := c.GetInt64("id", 0)
  3357. page, _ := c.GetInt64("page", 0)
  3358. limit, _ := c.GetInt64("limit", 0)
  3359. if id <= 0 {
  3360. c.ServeSuccessJSON(map[string]interface{}{
  3361. "solutions": nil,
  3362. })
  3363. return
  3364. }
  3365. if page <= 0 {
  3366. page = 1
  3367. }
  3368. if limit <= 0 {
  3369. limit = 10
  3370. }
  3371. adminInfo := c.GetMobileAdminUserInfo()
  3372. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  3373. c.ServeSuccessJSON(map[string]interface{}{
  3374. "solutions": solutions,
  3375. "total": total,
  3376. })
  3377. return
  3378. }
  3379. // GetDoctorAdvices 医嘱列表
  3380. func (c *PatientApiController) GetDoctorAdvices() {
  3381. id, _ := c.GetInt64("id", 0)
  3382. adviceType, _ := c.GetInt64("advice_type", 0)
  3383. stopType, _ := c.GetInt64("stop_state", 0)
  3384. startTime := c.GetString("start_time", "")
  3385. endTime := c.GetString("end_time", "")
  3386. keywords := c.GetString("keywords", "")
  3387. need, _ := c.GetInt64("need_doctor", 0)
  3388. adminUserInfo := c.GetMobileAdminUserInfo()
  3389. timeLayout := "2006-01-02"
  3390. loc, _ := time.LoadLocation("Local")
  3391. var theStartTIme int64
  3392. if len(startTime) > 0 {
  3393. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  3394. if err != nil {
  3395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3396. return
  3397. }
  3398. theStartTIme = theTime.Unix()
  3399. }
  3400. var theEndtTIme int64
  3401. if len(endTime) > 0 {
  3402. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  3403. if err != nil {
  3404. utils.ErrorLog(err.Error())
  3405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3406. return
  3407. }
  3408. theEndtTIme = theTime.Unix()
  3409. }
  3410. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  3411. if need == 1 {
  3412. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  3413. c.ServeSuccessJSON(map[string]interface{}{
  3414. "advices": advices,
  3415. "total": total,
  3416. "users": users,
  3417. })
  3418. } else {
  3419. c.ServeSuccessJSON(map[string]interface{}{
  3420. "advices": advices,
  3421. "total": total,
  3422. "users": []string{},
  3423. })
  3424. }
  3425. return
  3426. }
  3427. func (c *PatientApiController) GetPrintDialysisOrder() {
  3428. xtno := c.GetString("xtno")
  3429. xtdate := c.GetString("xtdate")
  3430. timeLayout := "2006-01-02"
  3431. loc, _ := time.LoadLocation("Local")
  3432. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  3433. if err != nil {
  3434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3435. return
  3436. }
  3437. xttime := theTime.Unix()
  3438. //获取当前日期月份的第一天
  3439. firstmonth := service.GetFirstDateOfMonth(theTime)
  3440. firstMonthDate := firstmonth.Unix()
  3441. operatorIDs := make([]int64, 0)
  3442. adminUserInfo := c.GetMobileAdminUserInfo()
  3443. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  3444. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  3445. //透析单
  3446. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3447. if dialysisOrder != nil {
  3448. if dialysisOrder.FinishNurse > 0 {
  3449. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  3450. }
  3451. if dialysisOrder.StartNurse > 0 {
  3452. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  3453. }
  3454. }
  3455. last_order, _ := service.GetLastTimeOrder(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3456. //透前评估
  3457. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3458. //透后评估
  3459. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3460. if AssessmentAfterDislysis.Modifier > 0 {
  3461. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  3462. }
  3463. //透析处方
  3464. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3465. if dialysisPrescription.PrescriptionDoctor > 0 {
  3466. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  3467. }
  3468. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3469. patientInfo.TotalDialysis = dialysis_count
  3470. //临时医嘱
  3471. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3472. fmt.Println("DoctorAdvice3223323323232323223323323223332232332wode", DoctorAdvice)
  3473. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3474. config, err := service.GetHisDoctorConfig(adminUserInfo.Org.Id)
  3475. project_config, _ := service.GetHisProjectConfig(adminUserInfo.Org.Id)
  3476. projects, _ := service.FindAllHisProjectById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3477. if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  3478. for _, item := range projects {
  3479. cnt, _ := strconv.ParseFloat(item.Count, 64)
  3480. var advice models.HisDoctorAdviceInfo
  3481. advice.ID = item.ID
  3482. advice.Checker = item.Checker
  3483. advice.CheckTime = item.CheckTime
  3484. advice.CheckState = item.CheckState
  3485. advice.ExecutionState = item.ExecutionState
  3486. advice.ExecutionStaff = item.ExecutionStaff
  3487. //advice.PrescribingNumber = float64(item.Count)
  3488. advice.PrescribingNumber = cnt
  3489. advice.PrescribingNumberUnit = item.Unit
  3490. advice.AdviceDoctor = item.Doctor
  3491. if item.Type == 3 {
  3492. advice.AdviceName = item.GoodInfo.GoodName
  3493. advice.PrescribingNumberUnit = item.GoodInfo.PackingUnit
  3494. } else if item.Type == 2 {
  3495. advice.AdviceName = item.HisProject.ProjectName
  3496. }
  3497. advice.StartTime = item.StartTime
  3498. hisAdvice = append(hisAdvice, &advice)
  3499. }
  3500. }
  3501. if len(DoctorAdvice) > 0 {
  3502. for _, item := range DoctorAdvice {
  3503. if item.AdviceDoctor > 0 {
  3504. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3505. }
  3506. if item.ExecutionStaff > 0 {
  3507. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3508. }
  3509. if item.Checker > 0 {
  3510. operatorIDs = append(operatorIDs, item.Checker)
  3511. }
  3512. }
  3513. }
  3514. //DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3515. //透析监测
  3516. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3517. //透析小结
  3518. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3519. //接诊评估
  3520. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3521. //相关操作对应的操作人
  3522. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  3523. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  3524. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3525. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3526. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.Org.Id)
  3527. lastWeight, _ := service.MobileGetLast(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3528. if config.IsOpen == 1 {
  3529. c.ServeSuccessJSON(map[string]interface{}{
  3530. "users": adminUser,
  3531. "patientInfo": patientInfo,
  3532. "PredialysisEvaluation": PredialysisEvaluation,
  3533. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3534. "dialysisPrescription": dialysisPrescription,
  3535. "advices": hisAdvice,
  3536. "monitors": Record,
  3537. "summary": TreatmentSummary,
  3538. "receiverTreatmentAccess": receiverTreatmentAccess,
  3539. "dialysisOrder": dialysisOrder,
  3540. "operators": operators,
  3541. "org_template_info": templateInfo,
  3542. "check": check,
  3543. "dialysiscount": dialysiscount,
  3544. "last_order": last_order,
  3545. "projects": projects,
  3546. "project_config": project_config,
  3547. "lastWeight": lastWeight,
  3548. })
  3549. }
  3550. if config.IsOpen == 0 || config.IsOpen == 2 {
  3551. c.ServeSuccessJSON(map[string]interface{}{
  3552. "users": adminUser,
  3553. "patientInfo": patientInfo,
  3554. "PredialysisEvaluation": PredialysisEvaluation,
  3555. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3556. "dialysisPrescription": dialysisPrescription,
  3557. "advices": DoctorAdvice,
  3558. "monitors": Record,
  3559. "summary": TreatmentSummary,
  3560. "receiverTreatmentAccess": receiverTreatmentAccess,
  3561. "dialysisOrder": dialysisOrder,
  3562. "operators": operators,
  3563. "org_template_info": templateInfo,
  3564. "check": check,
  3565. "dialysiscount": dialysiscount,
  3566. "last_order": last_order,
  3567. "projects": projects,
  3568. "project_config": project_config,
  3569. "lastWeight": lastWeight,
  3570. })
  3571. }
  3572. }
  3573. func (c *PatientApiController) CreateGroupAdvice() {
  3574. is_child, _ := c.GetInt64("is_child", 0)
  3575. if is_child == 1 {
  3576. patient, _ := c.GetInt64("id", 0)
  3577. if patient <= 0 {
  3578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3579. return
  3580. }
  3581. adminUserInfo := c.GetMobileAdminUserInfo()
  3582. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  3583. if patientInfo.ID == 0 {
  3584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3585. return
  3586. }
  3587. group_no, _ := c.GetInt64("group_no")
  3588. if group_no <= 0 {
  3589. group_no = 0
  3590. }
  3591. dataBody := make(map[string]interface{}, 0)
  3592. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3593. if err != nil {
  3594. utils.ErrorLog(err.Error())
  3595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3596. return
  3597. }
  3598. timeLayout := "2006-01-02"
  3599. loc, _ := time.LoadLocation("Local")
  3600. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3601. utils.ErrorLog("advice_type")
  3602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3603. return
  3604. }
  3605. adviceType := int64(dataBody["advice_type"].(float64))
  3606. if adviceType != 1 && adviceType != 2 {
  3607. utils.ErrorLog("advice_type != 1&&2")
  3608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3609. return
  3610. }
  3611. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3612. utils.ErrorLog("start_time")
  3613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3614. return
  3615. }
  3616. startTime2, _ := dataBody["start_time"].(string)
  3617. time_arr := strings.Split(startTime2, " ")
  3618. if len(time_arr) > 0 {
  3619. startTime2 = time_arr[0]
  3620. }
  3621. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3622. utils.ErrorLog("advice_date")
  3623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3624. return
  3625. }
  3626. advice_date, _ := dataBody["advice_date"].(string)
  3627. var advicedateunix int64
  3628. if len(advice_date) > 0 {
  3629. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  3630. if err != nil {
  3631. fmt.Println(err)
  3632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3633. return
  3634. }
  3635. advicedateunix = theTime.Unix()
  3636. }
  3637. adviceDate := startTime2
  3638. if len(adviceDate) == 0 {
  3639. utils.ErrorLog("len(adviceDate) == 0")
  3640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3641. return
  3642. }
  3643. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3644. if err != nil {
  3645. utils.ErrorLog(err.Error())
  3646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3647. return
  3648. }
  3649. AdviceDate := advicedateunix
  3650. RecordDate := advicedateunix
  3651. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3652. utils.ErrorLog("start_time")
  3653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3654. return
  3655. }
  3656. startTime, _ := dataBody["start_time"].(string)
  3657. if len(startTime) == 0 {
  3658. utils.ErrorLog("len(start_time) == 0")
  3659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3660. return
  3661. }
  3662. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  3663. theTimeOne, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime2+" 00:00:00", loc)
  3664. if err != nil {
  3665. utils.ErrorLog(err.Error())
  3666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3667. return
  3668. }
  3669. StartTime := theTime.Unix()
  3670. Remark := ""
  3671. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3672. remark, _ := dataBody["remark"].(string)
  3673. Remark = remark
  3674. }
  3675. Startdate := int64(dataBody["record_date"].(float64))
  3676. var advices []*models.GroupAdvice
  3677. // utils.TraceLog("%+v", dataBody["adviceNames"])
  3678. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  3679. utils.ErrorLog("adviceNames")
  3680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3681. return
  3682. }
  3683. adviceNames := dataBody["adviceNames"].([]interface{})
  3684. for _, adviceNameMap := range adviceNames {
  3685. adviceNameM := adviceNameMap.(map[string]interface{})
  3686. var advice models.GroupAdvice
  3687. advice.Remark = Remark
  3688. advice.AdviceType = adviceType
  3689. advice.StartTime = StartTime
  3690. if adminUserInfo.Org.Id == 10340 {
  3691. advice.AdviceDate = AdviceDate
  3692. advice.RecordDate = RecordDate
  3693. }
  3694. if adminUserInfo.Org.Id != 10340 {
  3695. advice.AdviceDate = theTimeOne.Unix()
  3696. advice.RecordDate = theTimeOne.Unix()
  3697. }
  3698. advice.Status = 1
  3699. advice.CreatedTime = time.Now().Unix()
  3700. advice.UpdatedTime = time.Now().Unix()
  3701. advice.StopState = 2
  3702. advice.ExecutionState = 2
  3703. advice.UserOrgId = adminUserInfo.Org.Id
  3704. advice.PatientId = patientInfo.ID
  3705. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3706. advice.IsSettle = 2
  3707. //入口
  3708. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  3709. if errcode > 0 {
  3710. c.ServeFailJSONWithSGJErrorCode(errcode)
  3711. return
  3712. }
  3713. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  3714. subdrugs := adviceNameM["subdrugs"].([]interface{})
  3715. if len(subdrugs) > 0 {
  3716. for _, subdrug := range subdrugs {
  3717. var s models.GroupAdvice
  3718. s.Remark = Remark
  3719. s.AdviceType = adviceType
  3720. s.StartTime = StartTime
  3721. s.AdviceDate = AdviceDate
  3722. s.RecordDate = RecordDate
  3723. s.Status = 1
  3724. s.CreatedTime = time.Now().Unix()
  3725. s.UpdatedTime = time.Now().Unix()
  3726. s.StopState = 2
  3727. s.ExecutionState = 2
  3728. s.UserOrgId = adminUserInfo.Org.Id
  3729. s.PatientId = patientInfo.ID
  3730. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  3731. s.IsSettle = 2
  3732. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  3733. if errcode > 0 {
  3734. c.ServeFailJSONWithSGJErrorCode(errcode)
  3735. return
  3736. }
  3737. advice.Children = append(advice.Children, &s)
  3738. }
  3739. }
  3740. }
  3741. //长沙南雅
  3742. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  3743. //查询该患者今日有没有双人核对
  3744. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, RecordDate)
  3745. if check.ID > 0 {
  3746. advice.Checker = check.Modifier
  3747. advice.CheckState = 1
  3748. advice.CheckTime = time.Now().Unix()
  3749. }
  3750. }
  3751. advices = append(advices, &advice)
  3752. }
  3753. // 查询信息规挡的设置天数
  3754. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3755. if infor.ID > 0 {
  3756. var cha_time int64
  3757. timeNowStr := time.Now().Format("2006-01-02")
  3758. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3759. //今日的日期减去设置的日期
  3760. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3761. if cha_time >= Startdate {
  3762. //查询审核是否允许
  3763. infor, _ := service.GetDialysisInformationByRecordDate(patient, Startdate, adminUserInfo.Org.Id)
  3764. //申请状态不允许的情况 拒绝修改
  3765. if infor.ApplicationStatus != 1 {
  3766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3767. return
  3768. }
  3769. }
  3770. }
  3771. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  3772. finish := models.XtDialysisFinish{
  3773. IsFinish: 1,
  3774. UserOrgId: adminUserInfo.Org.Id,
  3775. Status: 1,
  3776. Ctime: time.Now().Unix(),
  3777. Mtime: 0,
  3778. Module: 4,
  3779. RecordDate: advicedateunix,
  3780. Sourse: 1,
  3781. PatientId: patient,
  3782. }
  3783. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, advicedateunix, 4, patient)
  3784. if dialysisFinish.ID == 0 {
  3785. service.CreateDialysisFinish(finish)
  3786. }
  3787. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  3788. redis := service.RedisClient()
  3789. //清空key 值
  3790. redis.Set(key, "", time.Second)
  3791. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  3792. redis.Set(keyOne, "", time.Second)
  3793. defer redis.Close()
  3794. if createErr != nil {
  3795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3796. return
  3797. }
  3798. c.ServeSuccessJSON(map[string]interface{}{
  3799. "msg": "ok",
  3800. "advices": newAdvices,
  3801. })
  3802. return
  3803. } else if is_child == 2 {
  3804. patient, _ := c.GetInt64("id", 0)
  3805. if patient <= 0 {
  3806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3807. return
  3808. }
  3809. adminUserInfo := c.GetMobileAdminUserInfo()
  3810. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  3811. if patientInfo.ID == 0 {
  3812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3813. return
  3814. }
  3815. var advice models.DoctorAdvice
  3816. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  3817. if code > 0 {
  3818. c.ServeFailJSONWithSGJErrorCode(code)
  3819. return
  3820. }
  3821. if advice.ParentId > 0 {
  3822. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  3823. if old.ID == 0 || old.PatientId != patient {
  3824. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3825. return
  3826. }
  3827. if old.StopState == 1 || old.ExecutionState == 1 {
  3828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3829. return
  3830. }
  3831. if old.ParentId > 0 {
  3832. advice.ParentId = old.ParentId
  3833. }
  3834. advice.StartTime = old.StartTime
  3835. advice.AdviceDoctor = old.AdviceDoctor
  3836. advice.DeliveryWay = old.DeliveryWay
  3837. advice.ExecutionFrequency = old.ExecutionFrequency
  3838. advice.GroupNo = old.GroupNo
  3839. }
  3840. advice.Status = 1
  3841. advice.CreatedTime = time.Now().Unix()
  3842. advice.UpdatedTime = time.Now().Unix()
  3843. advice.StopState = 2
  3844. advice.ExecutionState = 2
  3845. advice.UserOrgId = adminUserInfo.Org.Id
  3846. advice.PatientId = patient
  3847. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3848. advice.IsSettle = 2
  3849. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  3850. if advice.PrescribingNumber == 0 {
  3851. advice.PrescribingNumber = 1
  3852. }
  3853. //查询该患者今日有没有双人核对
  3854. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, advice.AdviceDate)
  3855. if check.ID > 0 {
  3856. advice.Checker = check.Modifier
  3857. advice.CheckState = 1
  3858. advice.CheckTime = time.Now().Unix()
  3859. }
  3860. }
  3861. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3862. if infor.ID > 0 {
  3863. var cha_time int64
  3864. timeNowStr := time.Now().Format("2006-01-02")
  3865. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3866. //今日的日期减去设置的日期
  3867. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3868. if cha_time >= advice.RecordDate {
  3869. //查询审核是否允许
  3870. infor, _ := service.GetDialysisInformationByRecordDate(patient, advice.RecordDate, adminUserInfo.Org.Id)
  3871. //申请状态不允许的情况 拒绝修改
  3872. if infor.ApplicationStatus != 1 {
  3873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3874. return
  3875. }
  3876. }
  3877. }
  3878. err := service.CreateDoctorAdvice(&advice)
  3879. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3880. redis := service.RedisClient()
  3881. //清空key 值
  3882. redis.Set(key, "", time.Second)
  3883. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3884. redis.Set(keyOne, "", time.Second)
  3885. defer redis.Close()
  3886. if err != nil {
  3887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3888. return
  3889. }
  3890. c.ServeSuccessJSON(map[string]interface{}{
  3891. "msg": "ok",
  3892. "advice": advice,
  3893. })
  3894. return
  3895. }
  3896. }
  3897. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  3898. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  3899. utils.ErrorLog("advice_name")
  3900. return enums.ErrorCodeParamWrong
  3901. }
  3902. adviceName, _ := json["advice_name"].(string)
  3903. if len(adviceName) == 0 {
  3904. utils.ErrorLog("len(advice_name) == 0")
  3905. return enums.ErrorCodeParamWrong
  3906. }
  3907. advice.AdviceName = adviceName
  3908. adviceDesc, _ := json["advice_desc"].(string)
  3909. advice.AdviceDesc = adviceDesc
  3910. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3911. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3912. advice.DrugSpec = drugSpec
  3913. }
  3914. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3915. remark, _ := json["remark"].(string)
  3916. advice.Remark = remark
  3917. }
  3918. //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
  3919. // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
  3920. // advice.Way = src_type
  3921. //}
  3922. if json["way"] == nil {
  3923. advice.Way = 0
  3924. } else {
  3925. if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
  3926. way := int64(json["way"].(float64))
  3927. advice.Way = way
  3928. }
  3929. }
  3930. if json["drug_id"] == nil {
  3931. advice.DrugId = 0
  3932. } else {
  3933. if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
  3934. drug_id := int64(json["drug_id"].(float64))
  3935. advice.DrugId = drug_id
  3936. }
  3937. }
  3938. if json["drug_name_id"] == nil {
  3939. advice.DrugNameId = 0
  3940. } else {
  3941. if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
  3942. drug_name_id := int64(json["drug_name_id"].(float64))
  3943. advice.DrugNameId = drug_name_id
  3944. }
  3945. }
  3946. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  3947. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  3948. advice.DrugSpecUnit = drugSpecUnit
  3949. }
  3950. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3951. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3952. advice.SingleDose = singleDose
  3953. }
  3954. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3955. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3956. advice.SingleDoseUnit = singleDoseUnit
  3957. }
  3958. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3959. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3960. advice.PrescribingNumber = prescribingNumber
  3961. }
  3962. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3963. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3964. advice.PrescribingNumberUnit = prescribingNumberUnit
  3965. }
  3966. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3967. deliveryWay, _ := json["delivery_way"].(string)
  3968. advice.DeliveryWay = deliveryWay
  3969. }
  3970. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3971. executionFrequency, _ := json["execution_frequency"].(string)
  3972. advice.ExecutionFrequency = executionFrequency
  3973. }
  3974. return 0
  3975. }
  3976. func (c *PatientApiController) DelDoctorAdvice() {
  3977. groupno, _ := c.GetInt64("groupno", -1)
  3978. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  3979. patient_id, _ := c.GetInt64("patient_id")
  3980. doc_advice_date, _ := c.GetInt64("advice_date")
  3981. redis := service.RedisClient()
  3982. if is_sub == 1 { //是
  3983. advice_id, _ := c.GetInt64("advice_id")
  3984. adminUserInfo := c.GetMobileAdminUserInfo()
  3985. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  3986. if advice.ID == 0 {
  3987. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3988. return
  3989. }
  3990. advice.Status = 0
  3991. advice.UpdatedTime = time.Now().Unix()
  3992. advice.Modifier = adminUserInfo.AdminUser.Id
  3993. // 查询信息规挡的设置天数
  3994. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3995. if infor.ID > 0 {
  3996. var cha_time int64
  3997. timeNowStr := time.Now().Format("2006-01-02")
  3998. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3999. //今日的日期减去设置的日期
  4000. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4001. if cha_time >= advice.AdviceDate {
  4002. //查询审核是否允许
  4003. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id)
  4004. //申请状态不允许的情况 拒绝修改
  4005. if infor.ApplicationStatus != 1 {
  4006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4007. return
  4008. }
  4009. }
  4010. }
  4011. err := service.DeleteDoctorAdvice(&advice)
  4012. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  4013. redis.Set(key, "", time.Second)
  4014. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  4015. redis.Set(keyTwo, "", time.Second)
  4016. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  4017. redis.Set(keyThree, "", time.Second)
  4018. redis.Close()
  4019. if err != nil {
  4020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  4021. return
  4022. }
  4023. c.ServeSuccessJSON(map[string]interface{}{
  4024. "msg": "ok",
  4025. })
  4026. return
  4027. } else { //
  4028. var ids []string
  4029. if groupno == 0 {
  4030. advice_id := c.GetString("advice_id")
  4031. ids = strings.Split(advice_id, ",")
  4032. if len(ids) <= 0 {
  4033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4034. return
  4035. }
  4036. }
  4037. if groupno < 0 {
  4038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4039. return
  4040. }
  4041. adminUserInfo := c.GetMobileAdminUserInfo()
  4042. var advice models.DoctorAdvice
  4043. if groupno > 0 {
  4044. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  4045. if advice.ID == 0 {
  4046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4047. return
  4048. }
  4049. } else {
  4050. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  4051. for _, item := range advices {
  4052. if item.ID == 0 {
  4053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4054. return
  4055. }
  4056. }
  4057. }
  4058. advice.UpdatedTime = time.Now().Unix()
  4059. advice.Status = 0
  4060. advice.GroupNo = groupno
  4061. advice.Modifier = adminUserInfo.AdminUser.Id
  4062. var err error
  4063. if groupno > 0 {
  4064. // 查询信息规挡的设置天数
  4065. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4066. if infor.ID > 0 {
  4067. var cha_time int64
  4068. timeNowStr := time.Now().Format("2006-01-02")
  4069. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4070. //今日的日期减去设置的日期
  4071. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4072. if cha_time >= advice.AdviceDate {
  4073. //查询审核是否允许
  4074. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id)
  4075. //申请状态不允许的情况 拒绝修改
  4076. if infor.ApplicationStatus != 1 {
  4077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4078. return
  4079. }
  4080. }
  4081. }
  4082. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  4083. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  4084. redis.Set(key, "", time.Second)
  4085. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  4086. redis.Set(keyTwo, "", time.Second)
  4087. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  4088. redis.Set(keyThree, "", time.Second)
  4089. } else {
  4090. // 查询信息规挡的设置天数
  4091. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4092. if infor.ID > 0 {
  4093. var cha_time int64
  4094. timeNowStr := time.Now().Format("2006-01-02")
  4095. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4096. //今日的日期减去设置的日期
  4097. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4098. if cha_time >= advice.AdviceDate {
  4099. //查询审核是否允许
  4100. infor, _ := service.GetDialysisInformationByRecordDate(advice.PatientId, advice.AdviceDate, adminUserInfo.Org.Id)
  4101. //申请状态不允许的情况 拒绝修改
  4102. if infor.ApplicationStatus != 1 {
  4103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4104. return
  4105. }
  4106. }
  4107. }
  4108. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  4109. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  4110. redis.Set(key, "", time.Second)
  4111. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  4112. redis.Set(keyTwo, "", time.Second)
  4113. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  4114. redis.Set(keyThree, "", time.Second)
  4115. redis.Close()
  4116. }
  4117. if err != nil {
  4118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  4119. return
  4120. }
  4121. c.ServeSuccessJSON(map[string]interface{}{
  4122. "msg": "ok",
  4123. })
  4124. return
  4125. }
  4126. }
  4127. // /m/api/advice/group/modify_starttime [post]
  4128. // @param group_no:int
  4129. // @param start_time:string yyyy-MM-dd hh:mm:ss
  4130. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  4131. group_no, _ := this.GetInt64("group_no")
  4132. start_time_str := this.GetString("start_time")
  4133. if group_no <= 0 || len(start_time_str) == 0 {
  4134. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4135. return
  4136. }
  4137. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  4138. if parseTimeErr != nil {
  4139. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  4140. return
  4141. }
  4142. adminUserInfo := this.GetMobileAdminUserInfo()
  4143. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  4144. if updateStartTimeErr != nil {
  4145. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  4146. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4147. return
  4148. }
  4149. this.ServeSuccessJSON(map[string]interface{}{
  4150. "start_time": startTime.Unix(),
  4151. })
  4152. }
  4153. func (this *PatientApiController) DelSubDoctorAdvice() {
  4154. advice_id, _ := this.GetInt64("advice_id")
  4155. adminUserInfo := this.GetMobileAdminUserInfo()
  4156. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  4157. if advice.ID == 0 {
  4158. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  4159. return
  4160. }
  4161. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  4162. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  4163. // return
  4164. //}
  4165. advice.Status = 0
  4166. advice.UpdatedTime = time.Now().Unix()
  4167. advice.Modifier = adminUserInfo.AdminUser.Id
  4168. err := service.DeleteDoctorAdvice(&advice)
  4169. if err != nil {
  4170. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  4171. return
  4172. }
  4173. this.ServeSuccessJSON(map[string]interface{}{
  4174. "msg": "ok",
  4175. })
  4176. return
  4177. }
  4178. func (this *PatientApiController) GetAdviceUnReadMessage() {
  4179. //adminUserInfo := this.GetMobileAdminUserInfo()
  4180. //service.FindUnReadDoctorAdviceMessage()
  4181. }
  4182. func (this *PatientApiController) GetPatientsByKeyWord() {
  4183. keyWord := this.GetString("keyword")
  4184. adminUserInfo := this.GetMobileAdminUserInfo()
  4185. today := utils.ZeroHourTimeOfDay(time.Now())
  4186. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  4187. if err != nil {
  4188. utils.ErrorLog(err.Error())
  4189. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4190. return
  4191. }
  4192. this.ServeSuccessJSON(map[string]interface{}{
  4193. "patient": patient,
  4194. })
  4195. }
  4196. func (this *PatientApiController) GetSearchPatient() {
  4197. keyWord := this.GetString("keyword")
  4198. adminUserInfo := this.GetMobileAdminUserInfo()
  4199. patient, err := service.GetPatientsByKey(adminUserInfo.Org.Id, keyWord)
  4200. if err != nil {
  4201. utils.ErrorLog(err.Error())
  4202. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4203. return
  4204. }
  4205. this.ServeSuccessJSON(map[string]interface{}{
  4206. "patient": patient,
  4207. })
  4208. }
  4209. func (c *PatientApiController) ExecProject() {
  4210. execution_time := c.GetString("execution_time")
  4211. project_id, _ := c.GetInt64("project_id")
  4212. team_id, _ := c.GetInt64("team_id")
  4213. is_check_team, _ := c.GetInt64("is_check_team")
  4214. if len(execution_time) <= 0 {
  4215. utils.ErrorLog("execution_time")
  4216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4217. return
  4218. }
  4219. timeLayout2 := "2006-01-02 15:04:05"
  4220. loc, _ := time.LoadLocation("Local")
  4221. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  4222. if errs != nil {
  4223. utils.ErrorLog(errs.Error())
  4224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4225. return
  4226. }
  4227. adminInfo := c.GetMobileAdminUserInfo()
  4228. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  4229. if project.Type == 3 {
  4230. good, _ := service.GetGoodInformationByGoodId(project.ProjectId)
  4231. if good.IsUser != 1 {
  4232. //查询开关是否开启
  4233. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  4234. //开关已经开启
  4235. if stockSetting.IsType == 1 {
  4236. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  4237. scheduleDateStart := theTime.Format("2006-01-02")
  4238. timeLayout3 := "2006-01-02"
  4239. loc, _ := time.LoadLocation("Local")
  4240. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  4241. //查询该耗材是否已经出库
  4242. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  4243. if auto.ID == 0 {
  4244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  4245. return
  4246. }
  4247. }
  4248. }
  4249. if good.IsUser == 1 && good.IsWarehouse == 1 {
  4250. //查询开关是否开启
  4251. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  4252. //开关已经开启
  4253. if stockSetting.IsType == 1 {
  4254. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  4255. scheduleDateStart := theTime.Format("2006-01-02")
  4256. timeLayout3 := "2006-01-02"
  4257. loc, _ := time.LoadLocation("Local")
  4258. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  4259. //查询该耗材是否已经出库
  4260. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  4261. if auto.ID == 0 {
  4262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  4263. return
  4264. }
  4265. }
  4266. }
  4267. }
  4268. if project.ExecutionState == 1 {
  4269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  4270. return
  4271. }
  4272. if project.Checker >= 0 && project.Checker == adminInfo.AdminUser.Id {
  4273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  4274. return
  4275. }
  4276. project.ExecutionState = 1
  4277. project.ExecutionStaff = adminInfo.AdminUser.Id
  4278. project.ExecutionTime = theTime.Unix()
  4279. if team_id == 0 {
  4280. // 查询信息规挡的设置天数
  4281. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4282. if infor.ID > 0 {
  4283. var cha_time int64
  4284. timeNowStr := time.Now().Format("2006-01-02")
  4285. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4286. //今日的日期减去设置的日期
  4287. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4288. if cha_time >= project.RecordDate {
  4289. //查询审核是否允许
  4290. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId)
  4291. //申请状态不允许的情况 拒绝修改
  4292. if infor.ApplicationStatus != 1 {
  4293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4294. return
  4295. }
  4296. }
  4297. }
  4298. err := service.SaveHisProject(&project)
  4299. if err == nil {
  4300. c.ServeSuccessJSON(map[string]interface{}{
  4301. "project": project,
  4302. })
  4303. } else {
  4304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4305. return
  4306. }
  4307. } else {
  4308. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  4309. // 查询信息规挡的设置天数
  4310. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4311. if infor.ID > 0 {
  4312. var cha_time int64
  4313. timeNowStr := time.Now().Format("2006-01-02")
  4314. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4315. //今日的日期减去设置的日期
  4316. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4317. if cha_time >= project.RecordDate {
  4318. //查询审核是否允许
  4319. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId)
  4320. //申请状态不允许的情况 拒绝修改
  4321. if infor.ApplicationStatus != 1 {
  4322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4323. return
  4324. }
  4325. }
  4326. }
  4327. err := service.SaveHisProject(&project)
  4328. if err == nil {
  4329. c.ServeSuccessJSON(map[string]interface{}{
  4330. "project": project,
  4331. })
  4332. } else {
  4333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4334. return
  4335. }
  4336. } else {
  4337. // 查询信息规挡的设置天数
  4338. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4339. if infor.ID > 0 {
  4340. var cha_time int64
  4341. timeNowStr := time.Now().Format("2006-01-02")
  4342. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4343. //今日的日期减去设置的日期
  4344. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4345. if cha_time >= project.RecordDate {
  4346. //查询审核是否允许
  4347. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId)
  4348. //申请状态不允许的情况 拒绝修改
  4349. if infor.ApplicationStatus != 1 {
  4350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4351. return
  4352. }
  4353. }
  4354. }
  4355. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  4356. var ids []int64
  4357. for _, items := range ps {
  4358. ids = append(ids, items.ID)
  4359. }
  4360. err := service.UpdateTeamProjectExceStatus(ids, adminInfo.AdminUser.Id, theTime.Unix())
  4361. if err == nil {
  4362. c.ServeSuccessJSON(map[string]interface{}{
  4363. "project": project,
  4364. })
  4365. } else {
  4366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4367. return
  4368. }
  4369. }
  4370. }
  4371. }
  4372. func (c *PatientApiController) CheckProject() {
  4373. adminInfo := c.GetMobileAdminUserInfo()
  4374. project_id, _ := c.GetInt64("project_id")
  4375. team_id, _ := c.GetInt64("team_id")
  4376. is_check_team, _ := c.GetInt64("is_check_team")
  4377. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  4378. if project.CheckState == 1 {
  4379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  4380. return
  4381. }
  4382. if project.ExecutionStaff >= 0 && project.ExecutionStaff == adminInfo.AdminUser.Id {
  4383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  4384. return
  4385. }
  4386. project.Checker = adminInfo.AdminUser.Id
  4387. project.CheckTime = time.Now().Unix()
  4388. project.CheckState = 1
  4389. if team_id == 0 {
  4390. // 查询信息规挡的设置天数
  4391. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4392. if infor.ID > 0 {
  4393. var cha_time int64
  4394. timeNowStr := time.Now().Format("2006-01-02")
  4395. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4396. //今日的日期减去设置的日期
  4397. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4398. if cha_time >= project.RecordDate {
  4399. //查询审核是否允许
  4400. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId)
  4401. //申请状态不允许的情况 拒绝修改
  4402. if infor.ApplicationStatus != 1 {
  4403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4404. return
  4405. }
  4406. }
  4407. }
  4408. err := service.SaveHisProject(&project)
  4409. if err == nil {
  4410. c.ServeSuccessJSON(map[string]interface{}{
  4411. "msg": "ok",
  4412. "project": project,
  4413. })
  4414. } else {
  4415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4416. return
  4417. }
  4418. } else {
  4419. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  4420. // 查询信息规挡的设置天数
  4421. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4422. if infor.ID > 0 {
  4423. var cha_time int64
  4424. timeNowStr := time.Now().Format("2006-01-02")
  4425. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4426. //今日的日期减去设置的日期
  4427. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4428. if cha_time >= project.RecordDate {
  4429. //查询审核是否允许
  4430. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId)
  4431. //申请状态不允许的情况 拒绝修改
  4432. if infor.ApplicationStatus != 1 {
  4433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4434. return
  4435. }
  4436. }
  4437. }
  4438. err := service.SaveHisProject(&project)
  4439. if err == nil {
  4440. c.ServeSuccessJSON(map[string]interface{}{
  4441. "msg": "ok",
  4442. "project": project,
  4443. })
  4444. } else {
  4445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4446. return
  4447. }
  4448. } else {
  4449. // 查询信息规挡的设置天数
  4450. infor, _ := service.GetDialysisInformationSetting(project.RecordDate)
  4451. if infor.ID > 0 {
  4452. var cha_time int64
  4453. timeNowStr := time.Now().Format("2006-01-02")
  4454. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4455. //今日的日期减去设置的日期
  4456. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4457. if cha_time >= project.RecordDate {
  4458. //查询审核是否允许
  4459. infor, _ := service.GetDialysisInformationByRecordDate(project.PatientId, project.PatientId, project.UserOrgId)
  4460. //申请状态不允许的情况 拒绝修改
  4461. if infor.ApplicationStatus != 1 {
  4462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4463. return
  4464. }
  4465. }
  4466. }
  4467. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  4468. var ids []int64
  4469. for _, items := range ps {
  4470. ids = append(ids, items.ID)
  4471. }
  4472. err := service.UpdateTeamProjectCheckStatus(ids, project.PatientId, project.RecordDate, project.UserOrgId, adminInfo.AdminUser.Id, time.Now().Unix())
  4473. if err == nil {
  4474. c.ServeSuccessJSON(map[string]interface{}{
  4475. "project": project,
  4476. })
  4477. } else {
  4478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4479. return
  4480. }
  4481. }
  4482. }
  4483. }