patient_api_controller.go 187KB

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