patient_api_controller.go 200KB

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