patient_api_controller.go 181KB

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