patient_api_controller.go 176KB

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