patient_api_controller.go 163KB

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