patient_api_controller.go 174KB

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