patient_api_controller.go 181KB

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