patient_api_controller.go 166KB

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