patient_api_controller.go 179KB

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