patient_api_controller.go 163KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773
  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. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  1509. break
  1510. c.ServeSuccessJSON(map[string]interface{}{
  1511. "msg": "1",
  1512. "advice": advice,
  1513. })
  1514. return
  1515. }
  1516. }
  1517. }
  1518. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  1519. for _, item := range advices {
  1520. if item.Way == 2 {
  1521. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  1522. //adviceName, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1523. if item.ExecutionState == 1 {
  1524. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1525. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1526. timeStr := time.Now().Format("2006-01-02")
  1527. timeArr := strings.Split(timeStr, "-")
  1528. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1529. total = total + 1
  1530. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1531. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1532. number = number + total
  1533. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1534. //插入自备药出库单
  1535. outStock := models.XtSelfOutStock{
  1536. DrugName: item.AdviceName,
  1537. DrugNameId: item.DrugId,
  1538. DrugSpec: item.AdviceDesc,
  1539. OutstoreNumber: count,
  1540. AdminUserId: adminUserInfo.AdminUser.Id,
  1541. StorckTime: item.RecordDate,
  1542. UserOrgId: adminUserInfo.CurrentOrgId,
  1543. CreatedTime: time.Now().Unix(),
  1544. Status: 1,
  1545. PatientId: item.PatientId,
  1546. ExitMode: 2,
  1547. MedicId: item.DrugId,
  1548. StockOutNumber: warehousing_out_order,
  1549. }
  1550. service.CreateOutStock(&outStock)
  1551. }
  1552. }
  1553. }
  1554. }
  1555. c.ServeSuccessJSON(map[string]interface{}{
  1556. "msg": "1",
  1557. "advice": advice,
  1558. })
  1559. return
  1560. } else {
  1561. if id <= 0 || patient <= 0 {
  1562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1563. return
  1564. }
  1565. if len(executionTime) <= 0 {
  1566. utils.ErrorLog("execution_time")
  1567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1568. return
  1569. }
  1570. adminUserInfo := c.GetAdminUserInfo()
  1571. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1572. if advice.ID == 0 || advice.PatientId != patient {
  1573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1574. return
  1575. }
  1576. //医嘱已执行
  1577. if advice.ExecutionState == 1 {
  1578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1579. return
  1580. }
  1581. executionStaff := adminUserInfo.AdminUser.Id
  1582. timeLayout := "2006-01-02 15:04:05"
  1583. loc, _ := time.LoadLocation("Local")
  1584. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1585. if err != nil {
  1586. utils.ErrorLog(err.Error())
  1587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1588. return
  1589. }
  1590. if advice.StartTime > theTime.Unix() {
  1591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1592. return
  1593. }
  1594. exceAdvice := models.HisDoctorAdviceInfo{
  1595. ExecutionStaff: executionStaff,
  1596. ExecutionTime: theTime.Unix(),
  1597. // Checker: checker,
  1598. UpdatedTime: time.Now().Unix(),
  1599. }
  1600. if advice.ParentId > 0 {
  1601. err = service.ExceHidDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1602. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1603. redis := service.RedisClient()
  1604. //清空key 值
  1605. redis.Set(key, "", time.Second)
  1606. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1607. redis.Set(keyTwo, "", time.Second)
  1608. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1609. redis.Set(keyThree, "", time.Second)
  1610. theTimes := theTime.Format("2006-01-02")
  1611. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1612. redis.Set(keyFour, "", time.Second)
  1613. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1614. redis.Set(keyFive, "", time.Second)
  1615. defer redis.Close()
  1616. } else {
  1617. err = service.ExceHidDoctorAdviceById(&exceAdvice, id, patient)
  1618. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1619. redis := service.RedisClient()
  1620. //清空key 值
  1621. redis.Set(key, "", time.Second)
  1622. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1623. redis.Set(keyTwo, "", time.Second)
  1624. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1625. redis.Set(keyThree, "", time.Second)
  1626. theTimes := theTime.Format("2006-01-02")
  1627. fmt.Println("theTIME", theTime)
  1628. keyFour := "scheduals_" + theTimes + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1629. redis.Set(keyFour, "", time.Second)
  1630. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1631. redis.Set(keyFive, "", time.Second)
  1632. defer redis.Close()
  1633. }
  1634. if err != nil {
  1635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1636. return
  1637. }
  1638. advice.ExecutionStaff = executionStaff
  1639. advice.ExecutionTime = theTime.Unix()
  1640. // advice.Checker = checker
  1641. //处理出库相关逻辑
  1642. //1.判断是否启用药品管理和自备药出库功能
  1643. //药品管理信息
  1644. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1645. if drugStockConfig.IsOpen == 1 {
  1646. //查询已经执行的医嘱
  1647. advices, _ := service.GetHisExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  1648. for _, item := range advices {
  1649. medical, _ := service.GetBaseDrugMedical(advice.DrugId)
  1650. //查询这个患者这个患者这个药已经出库的所有数量
  1651. advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1652. drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  1653. var total_count int64
  1654. var drug_count int64
  1655. for _, it := range advicelist {
  1656. if it.PrescribingNumberUnit == medical.MaxUnit {
  1657. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1658. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1659. total_count += prenumber * medical.MinNumber
  1660. }
  1661. if it.PrescribingNumberUnit == medical.MinUnit {
  1662. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  1663. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1664. total_count += prenumber
  1665. }
  1666. }
  1667. for _, its := range drugoutlist {
  1668. if its.CountUnit == medical.MaxUnit {
  1669. drug_count += its.Count * medical.MinNumber
  1670. }
  1671. if its.CountUnit == medical.MinUnit {
  1672. drug_count += its.Count
  1673. }
  1674. }
  1675. if total_count == drug_count {
  1676. c.ServeSuccessJSON(map[string]interface{}{
  1677. "msg": "1",
  1678. "advice": advice,
  1679. })
  1680. return
  1681. }
  1682. var total int64
  1683. var prescribing_number_total int64
  1684. //查询该药品是否有库存
  1685. list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId)
  1686. //判断单位是否相等
  1687. if medical.MaxUnit == advice.PrescribingNumberUnit {
  1688. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1689. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1690. //转化为最小单位
  1691. total = list.Count*medical.MinNumber + list.StockMinNumber
  1692. prescribing_number_total = count * medical.MinNumber
  1693. }
  1694. if medical.MinUnit == advice.PrescribingNumberUnit {
  1695. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1696. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1697. total = list.Count*medical.MinNumber + list.StockMinNumber
  1698. prescribing_number_total = count
  1699. }
  1700. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1701. c.ServeSuccessJSON(map[string]interface{}{
  1702. "msg": "3",
  1703. "advice": advice,
  1704. })
  1705. return
  1706. }
  1707. if prescribing_number_total > total {
  1708. c.ServeSuccessJSON(map[string]interface{}{
  1709. "msg": "2",
  1710. "advice": advice,
  1711. })
  1712. return
  1713. }
  1714. if prescribing_number_total <= total {
  1715. service.HisDrugsDelivery(adminUserInfo.CurrentOrgId, item.ExecutionStaff, item)
  1716. break
  1717. c.ServeSuccessJSON(map[string]interface{}{
  1718. "msg": "1",
  1719. "advice": advice,
  1720. })
  1721. return
  1722. }
  1723. }
  1724. }
  1725. c.ServeSuccessJSON(map[string]interface{}{
  1726. "msg": "1",
  1727. "advice": advice,
  1728. })
  1729. return
  1730. }
  1731. }
  1732. func (c *PatientApiController) CheckGroupAdvice() {
  1733. groupno, _ := c.GetInt64("groupno", 0)
  1734. if groupno <= 0 {
  1735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1736. return
  1737. }
  1738. adminUserInfo := c.GetAdminUserInfo()
  1739. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupno)
  1740. if advice.ID == 0 {
  1741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1742. return
  1743. }
  1744. if advice.CheckState == 1 {
  1745. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1746. return
  1747. }
  1748. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1750. return
  1751. }
  1752. checker := adminUserInfo.AdminUser.Id
  1753. theTime := time.Now()
  1754. exceAdvice := models.DoctorAdvice{
  1755. Checker: checker,
  1756. CheckTime: theTime.Unix(),
  1757. UpdatedTime: time.Now().Unix(),
  1758. }
  1759. var err error
  1760. err = service.CheckDoctorAdviceByGroupNo(&exceAdvice, groupno, adminUserInfo.CurrentOrgId)
  1761. if err != nil {
  1762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1763. return
  1764. }
  1765. // advice.ExecutionStaff = executionStaff
  1766. // advice.ExecutionTime = theTime.Unix()
  1767. advice.Checker = checker
  1768. advice.CheckTime = theTime.Unix()
  1769. c.ServeSuccessJSON(map[string]interface{}{
  1770. "msg": "ok",
  1771. "advice": advice,
  1772. })
  1773. return
  1774. }
  1775. func (c *PatientApiController) CheckDoctorAdvice() {
  1776. patient, _ := c.GetInt64("patient", 0)
  1777. id, _ := c.GetInt64("id", 0)
  1778. origin, _ := c.GetInt64("origin", 0)
  1779. if origin != 2 {
  1780. // executionTime := c.GetString("execution_time")
  1781. if id <= 0 || patient <= 0 {
  1782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1783. return
  1784. }
  1785. adminUserInfo := c.GetAdminUserInfo()
  1786. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1787. if advice.ID == 0 || advice.PatientId != patient {
  1788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1789. return
  1790. }
  1791. if advice.CheckState == 1 {
  1792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1793. return
  1794. }
  1795. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1797. return
  1798. }
  1799. // executionStaff := adminUserInfo.AdminUser.Id
  1800. checker := adminUserInfo.AdminUser.Id
  1801. // timeLayout := "2006-01-02 15:04:05"
  1802. // loc, _ := time.LoadLocation("Local")
  1803. // theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1804. // if err != nil {
  1805. // utils.ErrorLog(err.Error())
  1806. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1807. // return
  1808. // }
  1809. theTime := time.Now()
  1810. if advice.ExecutionTime > theTime.Unix() {
  1811. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1812. return
  1813. }
  1814. exceAdvice := models.DoctorAdvice{
  1815. Checker: checker,
  1816. CheckTime: theTime.Unix(),
  1817. UpdatedTime: time.Now().Unix(),
  1818. }
  1819. var err error
  1820. if advice.ParentId > 0 {
  1821. err = service.CheckDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1822. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1823. redis := service.RedisClient()
  1824. //清空key 值
  1825. redis.Set(key, "", time.Second)
  1826. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1827. redis.Set(keyTwo, "", time.Second)
  1828. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1829. redis.Set(keyThree, "", time.Second)
  1830. recordDate := theTime.Format("2006-01-02")
  1831. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1832. redis.Set(keyFour, "", time.Second)
  1833. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1834. redis.Set(keyFive, "", time.Second)
  1835. } else {
  1836. err = service.CheckDoctorAdviceById(&exceAdvice, id, patient)
  1837. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1838. redis := service.RedisClient()
  1839. //清空key 值
  1840. redis.Set(key, "", time.Second)
  1841. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1842. redis.Set(keyTwo, "", time.Second)
  1843. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1844. redis.Set(keyThree, "", time.Second)
  1845. recordDate := theTime.Format("2006-01-02")
  1846. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1847. redis.Set(keyFour, "", time.Second)
  1848. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1849. redis.Set(keyFive, "", time.Second)
  1850. }
  1851. if err != nil {
  1852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1853. return
  1854. }
  1855. // advice.ExecutionStaff = executionStaff
  1856. // advice.ExecutionTime = theTime.Unix()
  1857. advice.Checker = checker
  1858. advice.CheckTime = theTime.Unix()
  1859. c.ServeSuccessJSON(map[string]interface{}{
  1860. "msg": "ok",
  1861. "advice": advice,
  1862. })
  1863. return
  1864. } else {
  1865. if id <= 0 || patient <= 0 {
  1866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1867. return
  1868. }
  1869. adminUserInfo := c.GetAdminUserInfo()
  1870. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1871. if advice.ID == 0 || advice.PatientId != patient {
  1872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1873. return
  1874. }
  1875. if advice.CheckState == 1 {
  1876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1877. return
  1878. }
  1879. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1881. return
  1882. }
  1883. checker := adminUserInfo.AdminUser.Id
  1884. theTime := time.Now()
  1885. if advice.ExecutionTime > theTime.Unix() {
  1886. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1887. return
  1888. }
  1889. exceAdvice := models.HisDoctorAdviceInfo{
  1890. Checker: checker,
  1891. CheckTime: theTime.Unix(),
  1892. UpdatedTime: time.Now().Unix(),
  1893. }
  1894. var err error
  1895. if advice.ParentId > 0 {
  1896. err = service.CheckHisDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1897. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1898. redis := service.RedisClient()
  1899. //清空key 值
  1900. redis.Set(key, "", time.Second)
  1901. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1902. redis.Set(keyTwo, "", time.Second)
  1903. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1904. redis.Set(keyThree, "", time.Second)
  1905. recordDate := theTime.Format("2006-01-02")
  1906. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1907. redis.Set(keyFour, "", time.Second)
  1908. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1909. redis.Set(keyFive, "", time.Second)
  1910. } else {
  1911. err = service.CheckHisDoctorAdviceById(&exceAdvice, id, patient)
  1912. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1913. redis := service.RedisClient()
  1914. //清空key 值
  1915. redis.Set(key, "", time.Second)
  1916. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1917. redis.Set(keyTwo, "", time.Second)
  1918. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1919. redis.Set(keyThree, "", time.Second)
  1920. recordDate := theTime.Format("2006-01-02")
  1921. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1922. redis.Set(keyFour, "", time.Second)
  1923. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1924. redis.Set(keyFive, "", time.Second)
  1925. }
  1926. if err != nil {
  1927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1928. return
  1929. }
  1930. // advice.ExecutionStaff = executionStaff
  1931. // advice.ExecutionTime = theTime.Unix()
  1932. advice.Checker = checker
  1933. advice.CheckTime = theTime.Unix()
  1934. c.ServeSuccessJSON(map[string]interface{}{
  1935. "msg": "ok",
  1936. "advice": advice,
  1937. })
  1938. return
  1939. }
  1940. }
  1941. func (c *PatientApiController) UpdateDoctorAdvice() {
  1942. patient, _ := c.GetInt64("patient", 0)
  1943. id, _ := c.GetInt64("id", 0)
  1944. if id <= 0 || patient <= 0 {
  1945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1946. return
  1947. }
  1948. adminUserInfo := c.GetAdminUserInfo()
  1949. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1950. if advice.ID == 0 || advice.PatientId != patient {
  1951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1952. return
  1953. }
  1954. //if advice.AdviceType == 1 {
  1955. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeLongTimeAdviceNotCanntEdit)
  1956. // return
  1957. //}
  1958. if advice.StopState == 1 || advice.ExecutionState == 1 {
  1959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1960. return
  1961. }
  1962. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1963. //if appRole.UserType == 3 {
  1964. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1965. // if getPermissionErr != nil {
  1966. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1967. // return
  1968. // } else if headNursePermission == nil {
  1969. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1970. // return
  1971. // }
  1972. //}
  1973. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  1974. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCanotEditOtherAdvice)
  1975. // return
  1976. //}
  1977. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  1978. if code > 0 {
  1979. c.ServeFailJSONWithSGJErrorCode(code)
  1980. return
  1981. }
  1982. advice.UpdatedTime = time.Now().Unix()
  1983. advice.Modifier = adminUserInfo.AdminUser.Id
  1984. err := service.UpdateDoctorAdvice(&advice)
  1985. redis := service.RedisClient()
  1986. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1987. redis.Set(key, "", time.Second)
  1988. fmt.Println("key2332233232322332", key)
  1989. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1990. redis.Set(keyOne, "", time.Second)
  1991. fmt.Println("key3333333333333333", keyOne)
  1992. defer redis.Close()
  1993. if err != nil {
  1994. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1995. return
  1996. }
  1997. c.ServeSuccessJSON(map[string]interface{}{
  1998. "msg": "ok",
  1999. "advice": advice,
  2000. })
  2001. return
  2002. }
  2003. func (c *PatientApiController) StopGroupAdvice() {
  2004. groupNo, _ := c.GetInt64("groupno", 0)
  2005. if groupNo <= 0 {
  2006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2007. return
  2008. }
  2009. adminUserInfo := c.GetAdminUserInfo()
  2010. advice, _ := service.FindDoctorAdviceByGoroupNo(adminUserInfo.CurrentOrgId, groupNo)
  2011. if advice.ID == 0 {
  2012. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2013. return
  2014. }
  2015. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2017. return
  2018. }
  2019. dataBody := make(map[string]interface{}, 0)
  2020. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2021. if err != nil {
  2022. utils.ErrorLog(err.Error())
  2023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2024. return
  2025. }
  2026. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  2027. utils.ErrorLog("stop_time")
  2028. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2029. return
  2030. }
  2031. stopTime, _ := dataBody["stop_time"].(string)
  2032. if len(stopTime) == 0 {
  2033. utils.ErrorLog("len(stop_time) == 0")
  2034. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2035. return
  2036. }
  2037. timeLayout := "2006-01-02"
  2038. loc, _ := time.LoadLocation("Local")
  2039. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  2040. if err != nil {
  2041. utils.ErrorLog(err.Error())
  2042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2043. return
  2044. }
  2045. advice.StopTime = theTime.Unix()
  2046. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  2047. stopReason, _ := dataBody["stop_reason"].(string)
  2048. advice.StopReason = stopReason
  2049. }
  2050. advice.UpdatedTime = time.Now().Unix()
  2051. advice.StopDoctor = adminUserInfo.AdminUser.Id
  2052. advice.StopState = 1
  2053. err = service.StopGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, &advice)
  2054. if err != nil {
  2055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  2056. return
  2057. }
  2058. c.ServeSuccessJSON(map[string]interface{}{
  2059. "msg": "ok",
  2060. })
  2061. return
  2062. }
  2063. func (c *PatientApiController) StopDoctorAdvice() {
  2064. id, _ := c.GetInt64("id", 0)
  2065. if id <= 0 {
  2066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2067. return
  2068. }
  2069. adminUserInfo := c.GetAdminUserInfo()
  2070. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2071. //
  2072. //if appRole.UserType == 3 {
  2073. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2074. // if getPermissionErr != nil {
  2075. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2076. // return
  2077. // } else if headNursePermission == nil {
  2078. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2079. // return
  2080. // }
  2081. //}
  2082. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2083. if advice.ID == 0 {
  2084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2085. return
  2086. }
  2087. if advice.StopState == 1 || advice.ExecutionState == 1 {
  2088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2089. return
  2090. }
  2091. dataBody := make(map[string]interface{}, 0)
  2092. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2093. if err != nil {
  2094. utils.ErrorLog(err.Error())
  2095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2096. return
  2097. }
  2098. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  2099. utils.ErrorLog("stop_time")
  2100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2101. return
  2102. }
  2103. stopTime, _ := dataBody["stop_time"].(string)
  2104. if len(stopTime) == 0 {
  2105. utils.ErrorLog("len(stop_time) == 0")
  2106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2107. return
  2108. }
  2109. timeLayout := "2006-01-02"
  2110. loc, _ := time.LoadLocation("Local")
  2111. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  2112. if err != nil {
  2113. utils.ErrorLog(err.Error())
  2114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2115. return
  2116. }
  2117. advice.StopTime = theTime.Unix()
  2118. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  2119. stopReason, _ := dataBody["stop_reason"].(string)
  2120. advice.StopReason = stopReason
  2121. }
  2122. advice.UpdatedTime = time.Now().Unix()
  2123. advice.StopDoctor = adminUserInfo.AdminUser.Id
  2124. advice.StopState = 1
  2125. err = service.StopDoctorAdvice(&advice)
  2126. if err != nil {
  2127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  2128. return
  2129. }
  2130. c.ServeSuccessJSON(map[string]interface{}{
  2131. "msg": "ok",
  2132. "advice": advice,
  2133. })
  2134. return
  2135. }
  2136. func (c *PatientApiController) DeleteDoctorAdvice() {
  2137. id, _ := c.GetInt64("id", 0)
  2138. if id <= 0 {
  2139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2140. return
  2141. }
  2142. adminUserInfo := c.GetAdminUserInfo()
  2143. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2144. if advice.ID == 0 {
  2145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2146. return
  2147. }
  2148. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  2149. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2150. // return
  2151. //}
  2152. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2153. //
  2154. //if appRole.UserType == 3 {
  2155. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2156. // if getPermissionErr != nil {
  2157. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2158. // return
  2159. // } else if headNursePermission == nil {
  2160. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2161. // return
  2162. // }
  2163. //}
  2164. advice.UpdatedTime = time.Now().Unix()
  2165. advice.Status = 0
  2166. advice.Modifier = adminUserInfo.AdminUser.Id
  2167. err := service.DeleteDoctorAdvice(&advice)
  2168. redis := service.RedisClient()
  2169. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2170. redis.Set(keyOne, "", time.Second)
  2171. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2172. redis.Set(key, "", time.Second)
  2173. redis.Close()
  2174. if err != nil {
  2175. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2176. return
  2177. }
  2178. c.ServeSuccessJSON(map[string]interface{}{
  2179. "msg": "ok",
  2180. })
  2181. return
  2182. }
  2183. func (c *PatientApiController) DeleteGroupAdvice() {
  2184. groupNo, _ := c.GetInt64("groupno", 0)
  2185. if groupNo <= 0 {
  2186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2187. return
  2188. }
  2189. adminUserInfo := c.GetAdminUserInfo()
  2190. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  2191. if advice.ID == 0 {
  2192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2193. return
  2194. }
  2195. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2196. //if appRole.UserType == 3 {
  2197. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2198. // if getPermissionErr != nil {
  2199. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2200. // return
  2201. // } else if headNursePermission == nil {
  2202. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2203. // return
  2204. // }
  2205. //}
  2206. err := service.DeleteGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, adminUserInfo.AdminUser.Id)
  2207. key := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  2208. redis := service.RedisClient()
  2209. redis.Set(key, "", time.Second)
  2210. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  2211. redis.Set(keyOne, "", time.Second)
  2212. defer redis.Close()
  2213. if err != nil {
  2214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2215. return
  2216. }
  2217. c.ServeSuccessJSON(map[string]interface{}{
  2218. "msg": "ok",
  2219. })
  2220. return
  2221. }
  2222. //GetDoctorAdvices 医嘱列表
  2223. func (c *PatientApiController) GetDoctorAdvices() {
  2224. id, _ := c.GetInt64("id", 0)
  2225. adviceType, _ := c.GetInt64("advice_type", 0)
  2226. stopType, _ := c.GetInt64("stop_state", 0)
  2227. startTime := c.GetString("start_time", "")
  2228. endTime := c.GetString("end_time", "")
  2229. keywords := c.GetString("keywords", "")
  2230. page, _ := c.GetInt64("page")
  2231. fmt.Println("page", page)
  2232. limit, _ := c.GetInt64("limit")
  2233. fmt.Println("limit", limit)
  2234. adminUserInfo := c.GetAdminUserInfo()
  2235. operatorIDs := make([]int64, 0)
  2236. timeLayout := "2006-01-02"
  2237. loc, _ := time.LoadLocation("Local")
  2238. var theStartTIme int64
  2239. if len(startTime) > 0 {
  2240. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2241. if err != nil {
  2242. utils.ErrorLog(err.Error())
  2243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2244. return
  2245. }
  2246. theStartTIme = theTime.Unix()
  2247. }
  2248. var theEndtTIme int64
  2249. if len(endTime) > 0 {
  2250. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2251. if err != nil {
  2252. utils.ErrorLog(err.Error())
  2253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2254. return
  2255. }
  2256. theEndtTIme = theTime.Unix()
  2257. }
  2258. hisconfig, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  2259. if hisconfig.IsOpen == 1 {
  2260. advices, total, _ := service.GetDoctorAdviceListThree(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  2261. advicestwo, _, _ := service.GetDoctorAdviceListFour(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  2262. if len(advices) > 0 {
  2263. for _, item := range advices {
  2264. if item.AdviceDoctor > 0 {
  2265. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  2266. }
  2267. if item.ExecutionStaff > 0 {
  2268. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  2269. }
  2270. if item.Checker > 0 {
  2271. operatorIDs = append(operatorIDs, item.Checker)
  2272. }
  2273. if item.StopDoctor > 0 {
  2274. operatorIDs = append(operatorIDs, item.StopDoctor)
  2275. }
  2276. }
  2277. }
  2278. //相关操作对应的操作人
  2279. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  2280. c.ServeSuccessJSON(map[string]interface{}{
  2281. "advices": advices,
  2282. "operators": operators,
  2283. "total": total,
  2284. "advicetwo": advicestwo,
  2285. })
  2286. return
  2287. } else {
  2288. advices, total, _ := service.GetDoctorAdviceListOne(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  2289. advicestwo, _, _ := service.GetDoctorAdviceListTwo(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  2290. if len(advices) > 0 {
  2291. for _, item := range advices {
  2292. if item.AdviceDoctor > 0 {
  2293. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  2294. }
  2295. if item.ExecutionStaff > 0 {
  2296. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  2297. }
  2298. if item.Checker > 0 {
  2299. operatorIDs = append(operatorIDs, item.Checker)
  2300. }
  2301. if item.StopDoctor > 0 {
  2302. operatorIDs = append(operatorIDs, item.StopDoctor)
  2303. }
  2304. }
  2305. }
  2306. //相关操作对应的操作人
  2307. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  2308. c.ServeSuccessJSON(map[string]interface{}{
  2309. "advices": advices,
  2310. "operators": operators,
  2311. "total": total,
  2312. "advicetwo": advicestwo,
  2313. })
  2314. return
  2315. }
  2316. }
  2317. func (c *PatientApiController) GetPatientSchedules() {
  2318. id, _ := c.GetInt64("id", 0)
  2319. if id <= 0 {
  2320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2321. return
  2322. }
  2323. adminUserInfo := c.GetAdminUserInfo()
  2324. todayTime := time.Now().Format("2006-01-02")
  2325. timeLayout := "2006-01-02 15:04:05"
  2326. loc, _ := time.LoadLocation("Local")
  2327. var theStartTime int64
  2328. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  2329. theStartTime = theTime.Unix()
  2330. schedules, _ := service.GetPatientScheduleFormToday(adminUserInfo.CurrentOrgId, id, theStartTime)
  2331. if len(schedules) > 0 {
  2332. for index, item := range schedules {
  2333. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  2334. schedules[index].Week = int64(week)
  2335. }
  2336. }
  2337. c.ServeSuccessJSON(map[string]interface{}{
  2338. "schedules": schedules,
  2339. })
  2340. return
  2341. }
  2342. func (c *PatientApiController) GetPatientDialysisRecords() {
  2343. patientID, _ := c.GetInt64("patient_id", 0)
  2344. page, _ := c.GetInt64("page", 0)
  2345. limit, _ := c.GetInt64("limit", 0)
  2346. startTime := c.GetString("start_time", "")
  2347. endTime := c.GetString("end_time", "")
  2348. mode_id, _ := c.GetInt64("mode_id", 0)
  2349. if page <= 0 {
  2350. page = 1
  2351. }
  2352. if limit <= 0 {
  2353. limit = 10
  2354. }
  2355. if patientID <= 0 {
  2356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2357. return
  2358. }
  2359. timeLayout := "2006-01-02"
  2360. loc, _ := time.LoadLocation("Local")
  2361. var theStartTIme int64
  2362. if len(startTime) > 0 {
  2363. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2364. if err != nil {
  2365. theStartTIme = 0
  2366. }
  2367. theStartTIme = theTime.Unix()
  2368. }
  2369. var theEndtTIme int64
  2370. if len(endTime) > 0 {
  2371. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2372. if err != nil {
  2373. theEndtTIme = 0
  2374. }
  2375. theEndtTIme = theTime.Unix()
  2376. }
  2377. adminInfo := c.GetAdminUserInfo()
  2378. records, total, _ := service.GetPatientDialysisRecord(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  2379. c.ServeSuccessJSON(map[string]interface{}{
  2380. "total": total,
  2381. "records": records,
  2382. })
  2383. return
  2384. }
  2385. func (c *PatientApiController) ProEducation() {
  2386. patientID, _ := c.GetInt64("patient_id", 0)
  2387. page, _ := c.GetInt64("page", 0)
  2388. limit, _ := c.GetInt64("limit", 0)
  2389. startTime := c.GetString("start_time", "")
  2390. endTime := c.GetString("end_time", "")
  2391. if page <= 0 {
  2392. page = 1
  2393. }
  2394. if limit <= 0 {
  2395. limit = 10
  2396. }
  2397. if patientID <= 0 {
  2398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2399. return
  2400. }
  2401. timeLayout := "2006-01-02"
  2402. loc, _ := time.LoadLocation("Local")
  2403. var theStartTIme int64
  2404. if len(startTime) > 0 {
  2405. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2406. if err != nil {
  2407. theStartTIme = 0
  2408. }
  2409. theStartTIme = theTime.Unix()
  2410. }
  2411. var theEndtTIme int64
  2412. if len(endTime) > 0 {
  2413. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2414. if err != nil {
  2415. theEndtTIme = 0
  2416. }
  2417. theEndtTIme = theTime.Unix()
  2418. }
  2419. adminInfo := c.GetAdminUserInfo()
  2420. edus, total, _ := service.GetPatientTreatmentSummaryList(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme)
  2421. c.ServeSuccessJSON(map[string]interface{}{
  2422. "total": total,
  2423. "edus": edus,
  2424. })
  2425. return
  2426. }
  2427. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  2428. dataBody := make(map[string]interface{}, 0)
  2429. err := json.Unmarshal(data, &dataBody)
  2430. if err != nil {
  2431. utils.ErrorLog(err.Error())
  2432. code = enums.ErrorCodeParamWrong
  2433. return
  2434. }
  2435. timeLayout := "2006-01-02"
  2436. loc, _ := time.LoadLocation("Local")
  2437. isChild := false
  2438. if action == "create" {
  2439. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2440. utils.ErrorLog("advice_type")
  2441. code = enums.ErrorCodeParamWrong
  2442. return
  2443. }
  2444. adviceType := int64(dataBody["advice_type"].(float64))
  2445. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  2446. utils.ErrorLog("advice_type != 1&&2")
  2447. code = enums.ErrorCodeParamWrong
  2448. return
  2449. }
  2450. advice.AdviceType = adviceType
  2451. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2452. utils.ErrorLog("advice_date")
  2453. code = enums.ErrorCodeParamWrong
  2454. return
  2455. }
  2456. adviceDate, _ := dataBody["advice_date"].(string)
  2457. if len(adviceDate) == 0 {
  2458. utils.ErrorLog("len(adviceDate) == 0")
  2459. code = enums.ErrorCodeParamWrong
  2460. return
  2461. }
  2462. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2463. if err != nil {
  2464. utils.ErrorLog(err.Error())
  2465. code = enums.ErrorCodeParamWrong
  2466. return
  2467. }
  2468. advice.AdviceDate = theTime.Unix()
  2469. advice.RecordDate = theTime.Unix()
  2470. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  2471. parentId := int64(dataBody["parent_id"].(float64))
  2472. advice.ParentId = parentId
  2473. if parentId > 0 {
  2474. isChild = true
  2475. }
  2476. }
  2477. }
  2478. if !isChild {
  2479. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2480. utils.ErrorLog("start_time")
  2481. code = enums.ErrorCodeParamWrong
  2482. return
  2483. }
  2484. startTime, _ := dataBody["start_time"].(string)
  2485. if len(startTime) == 0 {
  2486. utils.ErrorLog("len(start_time) == 0")
  2487. code = enums.ErrorCodeParamWrong
  2488. return
  2489. }
  2490. theTime, err := time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  2491. if err != nil {
  2492. utils.ErrorLog(err.Error())
  2493. code = enums.ErrorCodeParamWrong
  2494. return
  2495. }
  2496. advice.StartTime = theTime.Unix()
  2497. // if dataBody["advice_doctor"] == nil || reflect.TypeOf(dataBody["advice_doctor"]).String() != "float64" {
  2498. // utils.ErrorLog("advice_doctor")
  2499. // code = enums.ErrorCodeParamWrong
  2500. // return
  2501. // }
  2502. // adviceDoctor := int64(dataBody["advice_doctor"].(float64))
  2503. // if adviceDoctor <= 0 {
  2504. // utils.ErrorLog("advice_doctor <=0")
  2505. // code = enums.ErrorCodeParamWrong
  2506. // return
  2507. // }
  2508. // advice.AdviceDoctor = adviceDoctor
  2509. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  2510. deliveryWay, _ := dataBody["delivery_way"].(string)
  2511. advice.DeliveryWay = deliveryWay
  2512. }
  2513. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  2514. executionFrequency, _ := dataBody["execution_frequency"].(string)
  2515. advice.ExecutionFrequency = executionFrequency
  2516. }
  2517. if advice.AdviceType == 1 && advice.ParentId == 0 {
  2518. if dataBody["frequency_type"] != nil || reflect.TypeOf(dataBody["frequency_type"]).String() == "float64" {
  2519. frequency_type := int64(dataBody["frequency_type"].(float64))
  2520. advice.FrequencyType = frequency_type
  2521. }
  2522. if dataBody["day_count"] != nil || reflect.TypeOf(dataBody["day_count"]).String() == "string" {
  2523. day_count, _ := strconv.ParseInt(dataBody["day_count"].(string), 10, 64)
  2524. advice.DayCount = day_count
  2525. }
  2526. if dataBody["week_days"] != nil && reflect.TypeOf(dataBody["week_days"]).String() == "string" {
  2527. week_day, _ := dataBody["week_days"].(string)
  2528. advice.WeekDay = week_day
  2529. }
  2530. }
  2531. }
  2532. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  2533. utils.ErrorLog("advice_name")
  2534. code = enums.ErrorCodeParamWrong
  2535. return
  2536. }
  2537. adviceName, _ := dataBody["advice_name"].(string)
  2538. if len(adviceName) == 0 {
  2539. utils.ErrorLog("len(advice_name) == 0")
  2540. code = enums.ErrorCodeParamWrong
  2541. return
  2542. }
  2543. advice.AdviceName = adviceName
  2544. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  2545. adviceDsc, _ := dataBody["advice_desc"].(string)
  2546. advice.AdviceDesc = adviceDsc
  2547. }
  2548. if dataBody["dialysis_order_id"] != nil && reflect.TypeOf(dataBody["dialysis_order_id"]).String() == "float64" {
  2549. dialysisOrderId, _ := dataBody["dialysis_order_id"].(float64)
  2550. advice.DialysisOrderId = int64(dialysisOrderId)
  2551. }
  2552. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  2553. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  2554. advice.SingleDose = singleDose
  2555. }
  2556. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  2557. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  2558. advice.SingleDoseUnit = singleDoseUnit
  2559. }
  2560. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  2561. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  2562. advice.DrugSpec = drugSpec
  2563. }
  2564. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  2565. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  2566. advice.DrugSpecUnit = drugSpecUnit
  2567. }
  2568. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  2569. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  2570. advice.PrescribingNumber = prescribingNumber
  2571. }
  2572. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  2573. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  2574. advice.PrescribingNumberUnit = prescribingNumberUnit
  2575. }
  2576. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2577. remark, _ := dataBody["remark"].(string)
  2578. advice.Remark = remark
  2579. }
  2580. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  2581. drug_id, _ := dataBody["drug_id"].(float64)
  2582. advice.DrugId = int64(drug_id)
  2583. }
  2584. if dataBody["drug_name_id"] != nil && reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  2585. drug_name_id, _ := dataBody["drug_name_id"].(float64)
  2586. advice.DrugNameId = int64(drug_name_id)
  2587. }
  2588. if dataBody["way"] != nil && reflect.TypeOf(dataBody["way"]).String() == "float64" {
  2589. way, _ := dataBody["way"].(float64)
  2590. advice.Way = int64(way)
  2591. }
  2592. return
  2593. }
  2594. func solutionFormData(solution *models.DialysisSolution, data []byte) (code int) {
  2595. dataBody := make(map[string]interface{}, 0)
  2596. err := json.Unmarshal(data, &dataBody)
  2597. utils.InfoLog(string(data))
  2598. if err != nil {
  2599. utils.ErrorLog(err.Error())
  2600. code = enums.ErrorCodeParamWrong
  2601. return
  2602. }
  2603. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2604. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2605. solution.DialysisDuration = dialysisDuration
  2606. }
  2607. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  2608. replacementWay := int64(dataBody["replacement_way"].(float64))
  2609. solution.ReplacementWay = replacementWay
  2610. }
  2611. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  2612. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  2613. solution.BloodFlowVolume = bloodFlowVolume
  2614. }
  2615. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  2616. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  2617. solution.HemodialysisMachine = hemodialysisMachine
  2618. }
  2619. if dataBody["blood_filter"] != nil && reflect.TypeOf(dataBody["blood_filter"]).String() == "float64" {
  2620. bloodFilter := int64(dataBody["blood_filter"].(float64))
  2621. solution.BloodFilter = bloodFilter
  2622. }
  2623. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  2624. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  2625. solution.PerfusionApparatus = perfusionApparatus
  2626. }
  2627. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  2628. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  2629. solution.DialysateFlow = dialysateFlow
  2630. }
  2631. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  2632. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  2633. solution.Kalium = kalium
  2634. }
  2635. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  2636. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  2637. solution.Sodium = sodium
  2638. }
  2639. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  2640. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  2641. solution.Calcium = calcium
  2642. }
  2643. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  2644. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  2645. solution.Bicarbonate = bicarbonate
  2646. }
  2647. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  2648. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  2649. solution.Anticoagulant = anticoagulant
  2650. }
  2651. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  2652. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  2653. solution.AnticoagulantShouji = anticoagulantShouji
  2654. }
  2655. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  2656. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  2657. solution.AnticoagulantWeichi = anticoagulantWeichi
  2658. }
  2659. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  2660. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  2661. solution.AnticoagulantZongliang = anticoagulantZongliang
  2662. }
  2663. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  2664. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  2665. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  2666. }
  2667. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  2668. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  2669. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  2670. }
  2671. return
  2672. }
  2673. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  2674. dataBody := make(map[string]interface{}, 0)
  2675. err := json.Unmarshal(data, &dataBody)
  2676. utils.InfoLog(string(data))
  2677. if err != nil {
  2678. utils.ErrorLog(err.Error())
  2679. code = enums.ErrorCodeParamWrong
  2680. return
  2681. }
  2682. if method == "create" {
  2683. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  2684. utils.ErrorLog("mode")
  2685. code = enums.ErrorCodeParamWrong
  2686. return
  2687. }
  2688. mode := int64(dataBody["mode"].(float64))
  2689. if mode <= 0 {
  2690. utils.ErrorLog("mode <= 0")
  2691. code = enums.ErrorCodeParamWrong
  2692. return
  2693. }
  2694. solution.ModeId = mode
  2695. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  2696. utils.ErrorLog("mode_name")
  2697. code = enums.ErrorCodeParamWrong
  2698. return
  2699. }
  2700. modeName, _ := dataBody["mode_name"].(string)
  2701. if len(modeName) == 0 {
  2702. utils.ErrorLog("len(mode_name) == 0")
  2703. code = enums.ErrorCodeParamWrong
  2704. return
  2705. }
  2706. solution.ModeName = modeName
  2707. solution.Name = modeName
  2708. }
  2709. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2710. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2711. solution.DialysisDuration = dialysisDuration
  2712. }
  2713. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  2714. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  2715. solution.TargetUltrafiltration = targetUltrafiltration
  2716. }
  2717. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  2718. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  2719. solution.DialysateFormulation = dialysateFormulation
  2720. }
  2721. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  2722. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  2723. solution.DialysisDurationHour = int64(dialysisDurationHour)
  2724. }
  2725. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  2726. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  2727. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  2728. }
  2729. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  2730. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  2731. solution.HemodialysisMachine = hemodialysisMachine
  2732. }
  2733. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  2734. dialyzer := int64(dataBody["dialyzer"].(float64))
  2735. solution.Dialyzer = dialyzer
  2736. }
  2737. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  2738. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  2739. solution.PerfusionApparatus = perfusionApparatus
  2740. }
  2741. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  2742. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  2743. solution.BloodFlowVolume = bloodFlowVolume
  2744. }
  2745. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  2746. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  2747. solution.Dewater = dewater
  2748. }
  2749. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  2750. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  2751. solution.DisplaceLiqui = displaceLiqui
  2752. }
  2753. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  2754. replacementWay := int64(dataBody["replacement_way"].(float64))
  2755. solution.ReplacementWay = replacementWay
  2756. }
  2757. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  2758. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  2759. solution.Anticoagulant = anticoagulant
  2760. }
  2761. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  2762. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  2763. solution.AnticoagulantShouji = anticoagulantShouji
  2764. }
  2765. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  2766. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  2767. solution.AnticoagulantWeichi = anticoagulantWeichi
  2768. }
  2769. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  2770. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  2771. solution.AnticoagulantZongliang = anticoagulantZongliang
  2772. }
  2773. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  2774. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  2775. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  2776. }
  2777. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  2778. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  2779. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  2780. }
  2781. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  2782. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  2783. solution.Kalium = kalium
  2784. }
  2785. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  2786. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  2787. solution.Sodium = sodium
  2788. }
  2789. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  2790. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  2791. solution.Calcium = calcium
  2792. }
  2793. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  2794. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  2795. solution.Bicarbonate = bicarbonate
  2796. }
  2797. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  2798. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  2799. solution.Glucose = glucose
  2800. }
  2801. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  2802. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  2803. // solution.DryWeight = dryWeight
  2804. // }
  2805. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  2806. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  2807. solution.DialysateFlow = dialysateFlow
  2808. }
  2809. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  2810. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  2811. solution.DialysateTemperature = dialysateTemperature
  2812. }
  2813. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  2814. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  2815. solution.Conductivity = conductivity
  2816. }
  2817. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  2818. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  2819. solution.ReplacementTotal = replacementTotal
  2820. }
  2821. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  2822. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  2823. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  2824. }
  2825. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  2826. body_fluid := int64(dataBody["body_fluid"].(float64))
  2827. solution.BodyFluid = body_fluid
  2828. }
  2829. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  2830. body_fluid_other := dataBody["body_fluid_other"].(string)
  2831. solution.BodyFluidOther = body_fluid_other
  2832. }
  2833. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  2834. special_medicine := int64(dataBody["special_medicine"].(float64))
  2835. solution.SpecialMedicine = special_medicine
  2836. }
  2837. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  2838. special_medicine_other := dataBody["special_medicine_other"].(string)
  2839. solution.SpecialMedicineOther = special_medicine_other
  2840. }
  2841. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  2842. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  2843. solution.DisplaceLiquiPart = displace_liqui_part
  2844. }
  2845. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  2846. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  2847. solution.DisplaceLiquiValue = displace_liqui_value
  2848. }
  2849. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  2850. blood_access := int64(dataBody["blood_access"].(float64))
  2851. solution.BloodAccess = blood_access
  2852. }
  2853. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  2854. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  2855. solution.Ultrafiltration = ultrafiltration
  2856. }
  2857. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  2858. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  2859. solution.TargetKtv = target_ktv
  2860. }
  2861. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2862. remark := dataBody["remark"].(string)
  2863. solution.Remark = remark
  2864. }
  2865. if dataBody["hemodialysis_pipelines"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines"]).String() == "string" {
  2866. hemodialysis_pipelines := dataBody["hemodialysis_pipelines"].(string)
  2867. solution.HemodialysisPipelines = hemodialysis_pipelines
  2868. }
  2869. if dataBody["hemodialysis_pipelines_count"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines_count"]).String() == "string" {
  2870. hemodialysis_pipelines_count, _ := strconv.ParseFloat(dataBody["hemodialysis_pipelines_count"].(string), 64)
  2871. solution.HemodialysisPipelinesCount = hemodialysis_pipelines_count
  2872. }
  2873. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  2874. puncture_needle := dataBody["puncture_needle"].(string)
  2875. solution.PunctureNeedle = puncture_needle
  2876. }
  2877. if dataBody["puncture_needle_count"] != nil && reflect.TypeOf(dataBody["puncture_needle_count"]).String() == "string" {
  2878. puncture_needle_count, _ := strconv.ParseFloat(dataBody["puncture_needle_count"].(string), 64)
  2879. solution.PunctureNeedleCount = puncture_needle_count
  2880. }
  2881. if dataBody["epo"] != nil && reflect.TypeOf(dataBody["epo"]).String() == "string" {
  2882. epo := dataBody["epo"].(string)
  2883. solution.Epo = epo
  2884. }
  2885. if dataBody["epo_count"] != nil && reflect.TypeOf(dataBody["epo_count"]).String() == "string" {
  2886. epo_count, _ := strconv.ParseFloat(dataBody["epo_count"].(string), 64)
  2887. solution.EpoCount = epo_count
  2888. }
  2889. if dataBody["created_time"] != nil && reflect.TypeOf(dataBody["created_time"]).String() == "float64" {
  2890. created_time := int64(dataBody["created_time"].(float64))
  2891. solution.CreatedTime = created_time
  2892. }
  2893. if dataBody["dialysis_dialyszers"] != nil && reflect.TypeOf(dataBody["dialysis_dialyszers"]).String() == "string" {
  2894. dialysisDialyszers := dataBody["dialysis_dialyszers"].(string)
  2895. solution.DialysisDialyszers = dialysisDialyszers
  2896. }
  2897. if dataBody["dialysis_irrigation"] != nil && reflect.TypeOf(dataBody["dialysis_irrigation"]).String() == "string" {
  2898. dialysisIrrigation := dataBody["dialysis_irrigation"].(string)
  2899. solution.DialysisIrrigation = dialysisIrrigation
  2900. }
  2901. if dataBody["plasma_separator"] != nil && reflect.TypeOf(dataBody["plasma_separator"]).String() == "string" {
  2902. plasmaSeparator := dataBody["plasma_separator"].(string)
  2903. solution.PlasmaSeparator = plasmaSeparator
  2904. }
  2905. if dataBody["bilirubin_adsorption_column"] != nil && reflect.TypeOf(dataBody["bilirubin_adsorption_column"]).String() == "string" {
  2906. bilirubinAdsorptionColumn := dataBody["bilirubin_adsorption_column"].(string)
  2907. solution.BilirubinAdsorptionColumn = bilirubinAdsorptionColumn
  2908. }
  2909. if dataBody["oxygen_uptake"] != nil && reflect.TypeOf(dataBody["oxygen_uptake"]).String() == "float64" {
  2910. oxygen_uptake := int64(dataBody["oxygen_uptake"].(float64))
  2911. solution.OxygenUptake = oxygen_uptake
  2912. }
  2913. if dataBody["oxygen_flow"] != nil && reflect.TypeOf(dataBody["oxygen_flow"]).String() == "string" {
  2914. oxygen_flow := dataBody["oxygen_flow"].(string)
  2915. solution.OxygenFlow = oxygen_flow
  2916. }
  2917. if dataBody["oxygen_time"] != nil && reflect.TypeOf(dataBody["oxygen_time"]).String() == "string" {
  2918. oxygen_time := dataBody["oxygen_time"].(string)
  2919. solution.OxygenTime = oxygen_time
  2920. }
  2921. if dataBody["max_ultrafiltration_rate"] != nil && reflect.TypeOf(dataBody["max_ultrafiltration_rate"]).String() == "string" {
  2922. max_ultrafiltration_rate, _ := strconv.ParseFloat(dataBody["max_ultrafiltration_rate"].(string), 64)
  2923. solution.MaxUltrafiltrationRate = max_ultrafiltration_rate
  2924. }
  2925. return
  2926. }
  2927. func childSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  2928. dataBody := make(map[string]interface{}, 0)
  2929. err := json.Unmarshal(data, &dataBody)
  2930. utils.InfoLog(string(data))
  2931. if err != nil {
  2932. utils.ErrorLog(err.Error())
  2933. code = enums.ErrorCodeParamWrong
  2934. return
  2935. }
  2936. if method == "create" {
  2937. if dataBody["parent_id"] == nil || reflect.TypeOf(dataBody["parent_id"]).String() != "float64" {
  2938. utils.ErrorLog("parent_id")
  2939. code = enums.ErrorCodeParamWrong
  2940. return
  2941. }
  2942. parentID := int64(dataBody["parent_id"].(float64))
  2943. if parentID <= 0 {
  2944. utils.ErrorLog("parentID <= 0")
  2945. code = enums.ErrorCodeParamWrong
  2946. return
  2947. }
  2948. solution.ParentId = parentID
  2949. if dataBody["sub_name"] == nil || reflect.TypeOf(dataBody["sub_name"]).String() != "string" {
  2950. utils.ErrorLog("sub_name")
  2951. code = enums.ErrorCodeParamWrong
  2952. return
  2953. }
  2954. subName, _ := dataBody["sub_name"].(string)
  2955. if len(subName) == 0 {
  2956. utils.ErrorLog("len(sub_name) == 0")
  2957. code = enums.ErrorCodeParamWrong
  2958. return
  2959. }
  2960. solution.SubName = subName
  2961. }
  2962. if dataBody["initiate_mode"] == nil || reflect.TypeOf(dataBody["initiate_mode"]).String() != "float64" {
  2963. utils.ErrorLog("initiate_mode")
  2964. code = enums.ErrorCodeParamWrong
  2965. return
  2966. }
  2967. initiateMode := int64(dataBody["initiate_mode"].(float64))
  2968. if initiateMode != 1 && initiateMode != 2 {
  2969. utils.ErrorLog("initiateMode != 1 && initiateMode != 2")
  2970. code = enums.ErrorCodeParamWrong
  2971. return
  2972. }
  2973. solution.InitiateMode = initiateMode
  2974. if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  2975. utils.ErrorLog("doctor")
  2976. code = enums.ErrorCodeParamWrong
  2977. return
  2978. }
  2979. doctor := int64(dataBody["doctor"].(float64))
  2980. if doctor <= 0 {
  2981. utils.ErrorLog("doctor <= 0")
  2982. code = enums.ErrorCodeParamWrong
  2983. return
  2984. }
  2985. solution.Doctor = doctor
  2986. return
  2987. }
  2988. func patientFormData(patient *models.Patients, data []byte, method string) (contagions []int64, diseases []int64, code int, formItems []*models.FormItem) {
  2989. patientBody := make(map[string]interface{}, 0)
  2990. err := json.Unmarshal(data, &patientBody)
  2991. if err != nil {
  2992. utils.ErrorLog(err.Error())
  2993. code = enums.ErrorCodeParamWrong
  2994. return
  2995. }
  2996. if patientBody["formItem"] != nil && reflect.TypeOf(patientBody["formItem"]).String() == "[]interface {}" {
  2997. formItem, _ := patientBody["formItem"].([]interface{})
  2998. if len(formItem) > 0 {
  2999. for _, item := range formItem {
  3000. items := item.(map[string]interface{})
  3001. project_name, _ := items["project_name"].(string)
  3002. fmt.Println(project_name)
  3003. range_type := int64(items["range_type"].(float64))
  3004. fmt.Println(range_type)
  3005. project_id := int64(items["project_id"].(float64))
  3006. fmt.Println(project_id)
  3007. item_id := int64(items["item_id"].(float64))
  3008. fmt.Println(item_id)
  3009. item, _ := items["item"].(string)
  3010. fmt.Println(items["item"].(string))
  3011. item_name, _ := items["item_name"].(string)
  3012. fmt.Println(item_name)
  3013. value, _ := items["value"].(string)
  3014. fmt.Println(items["value"].(string))
  3015. var form models.FormItem
  3016. form.ProjectName = project_name
  3017. form.RangeType = range_type
  3018. form.ProjectId = project_id
  3019. form.ItemId = item_id
  3020. form.Item = item
  3021. form.ItemName = item_name
  3022. form.Value = value
  3023. formItems = append(formItems, &form)
  3024. }
  3025. }
  3026. }
  3027. if patientBody["avatar"] == nil || reflect.TypeOf(patientBody["avatar"]).String() != "string" {
  3028. utils.ErrorLog("avatar")
  3029. code = enums.ErrorCodeParamWrong
  3030. return
  3031. }
  3032. avatar, _ := patientBody["avatar"].(string)
  3033. if len(avatar) == 0 {
  3034. utils.ErrorLog("len(avatar) == 0")
  3035. code = enums.ErrorCodeParamWrong
  3036. return
  3037. }
  3038. patient.Avatar = avatar
  3039. if patientBody["name"] == nil || reflect.TypeOf(patientBody["name"]).String() != "string" {
  3040. utils.ErrorLog("name")
  3041. code = enums.ErrorCodeParamWrong
  3042. return
  3043. }
  3044. name, _ := patientBody["name"].(string)
  3045. if len(name) == 0 {
  3046. utils.ErrorLog("len(name) == 0")
  3047. code = enums.ErrorCodeParamWrong
  3048. return
  3049. }
  3050. patient.Name = name
  3051. if patientBody["alias"] != nil && reflect.TypeOf(patientBody["alias"]).String() == "string" {
  3052. alias := patientBody["alias"].(string)
  3053. patient.Alias = alias
  3054. }
  3055. if patientBody["nation"] != nil && reflect.TypeOf(patientBody["nation"]).String() == "string" {
  3056. nation := patientBody["nation"].(string)
  3057. patient.Nation = nation
  3058. }
  3059. if patientBody["native_place"] != nil && reflect.TypeOf(patientBody["native_place"]).String() == "string" {
  3060. native_place := patientBody["native_place"].(string)
  3061. patient.NativePlace = native_place
  3062. }
  3063. if patientBody["idCardNo"] == nil || reflect.TypeOf(patientBody["idCardNo"]).String() != "string" {
  3064. utils.ErrorLog("idCardNo")
  3065. code = enums.ErrorCodeParamWrong
  3066. return
  3067. }
  3068. idCardNo, _ := patientBody["idCardNo"].(string)
  3069. if len(idCardNo) == 0 {
  3070. utils.ErrorLog("len(idCardNo) == 0")
  3071. code = enums.ErrorCodeParamWrong
  3072. return
  3073. }
  3074. patient.IdCardNo = idCardNo
  3075. patient.PatientType = 1
  3076. if patientBody["dialysisNo"] == nil || reflect.TypeOf(patientBody["dialysisNo"]).String() != "string" {
  3077. utils.ErrorLog("dialysisNo")
  3078. code = enums.ErrorCodeParamWrong
  3079. return
  3080. }
  3081. dialysisNo, _ := patientBody["dialysisNo"].(string)
  3082. if len(dialysisNo) == 0 {
  3083. utils.ErrorLog("len(dialysisNo) == 0")
  3084. code = enums.ErrorCodeParamWrong
  3085. return
  3086. }
  3087. patient.DialysisNo = dialysisNo
  3088. // }
  3089. if patientBody["lapseto"] == nil || reflect.TypeOf(patientBody["lapseto"]).String() != "float64" {
  3090. utils.ErrorLog("lapseto")
  3091. code = enums.ErrorCodeParamWrong
  3092. return
  3093. }
  3094. lapseto := int64(patientBody["lapseto"].(float64))
  3095. if lapseto <= 0 {
  3096. utils.ErrorLog("lapseto == 0")
  3097. code = enums.ErrorCodeParamWrong
  3098. return
  3099. }
  3100. patient.Lapseto = lapseto
  3101. if patientBody["gender"] == nil || reflect.TypeOf(patientBody["gender"]).String() != "float64" {
  3102. utils.ErrorLog("gender")
  3103. code = enums.ErrorCodeParamWrong
  3104. return
  3105. }
  3106. gender := int64(patientBody["gender"].(float64))
  3107. if gender <= 0 {
  3108. utils.ErrorLog("gender <= 0")
  3109. code = enums.ErrorCodeParamWrong
  3110. return
  3111. }
  3112. patient.Gender = gender
  3113. if patientBody["response_result"] != nil && reflect.TypeOf(patientBody["response_result"]).String() == "string" {
  3114. response_result := patientBody["response_result"].(string)
  3115. patient.ResponseResult = response_result
  3116. }
  3117. if patientBody["age"] == nil || reflect.TypeOf(patientBody["age"]).String() != "float64" {
  3118. utils.ErrorLog("age")
  3119. code = enums.ErrorCodeParamWrong
  3120. return
  3121. }
  3122. age := int64(patientBody["age"].(float64))
  3123. patient.Age = age
  3124. if patientBody["user_sys_before_count"] != nil || reflect.TypeOf(patientBody["user_sys_before_count"]).String() == "string" {
  3125. user_sys_before_count := patientBody["user_sys_before_count"].(string)
  3126. count, _ := strconv.ParseInt(user_sys_before_count, 10, 64)
  3127. patient.UserSysBeforeCount = count
  3128. }
  3129. timeLayout := "2006-01-02"
  3130. loc, _ := time.LoadLocation("Local")
  3131. if patientBody["birth"] == nil || reflect.TypeOf(patientBody["birth"]).String() != "string" {
  3132. utils.ErrorLog("birth")
  3133. code = enums.ErrorCodeParamWrong
  3134. return
  3135. }
  3136. birth, _ := patientBody["birth"].(string)
  3137. if len(birth) == 0 {
  3138. utils.ErrorLog("len(birth) == 0")
  3139. code = enums.ErrorCodeParamWrong
  3140. return
  3141. }
  3142. birthTime, err := time.ParseInLocation(timeLayout, birth, loc)
  3143. if err != nil {
  3144. utils.ErrorLog("birthTime")
  3145. code = enums.ErrorCodeParamWrong
  3146. return
  3147. }
  3148. patient.Birthday = birthTime.Unix()
  3149. if patientBody["height"] != nil && reflect.TypeOf(patientBody["height"]).String() == "string" {
  3150. height, _ := strconv.ParseInt(patientBody["height"].(string), 10, 64)
  3151. patient.Height = height
  3152. }
  3153. if patientBody["maritalStatus"] != nil && reflect.TypeOf(patientBody["maritalStatus"]).String() == "float64" {
  3154. maritalStatus := int64(patientBody["maritalStatus"].(float64))
  3155. patient.MaritalStatus = maritalStatus
  3156. }
  3157. if patientBody["children"] != nil && reflect.TypeOf(patientBody["children"]).String() == "string" {
  3158. children, _ := strconv.ParseInt(patientBody["children"].(string), 10, 64)
  3159. patient.Children = children
  3160. }
  3161. if patientBody["admissionNumber"] != nil && reflect.TypeOf(patientBody["admissionNumber"]).String() == "string" {
  3162. admissionNumber, _ := patientBody["admissionNumber"].(string)
  3163. patient.AdmissionNumber = admissionNumber
  3164. }
  3165. if patientBody["reimbursementWayID"] != nil && reflect.TypeOf(patientBody["reimbursementWayID"]).String() == "float64" {
  3166. reimbursementWayID := int64(patientBody["reimbursementWayID"].(float64))
  3167. patient.ReimbursementWayId = reimbursementWayID
  3168. }
  3169. if patientBody["healthCareNo"] != nil && reflect.TypeOf(patientBody["healthCareNo"]).String() == "string" {
  3170. healthCareNo := patientBody["healthCareNo"].(string)
  3171. patient.HealthCareNo = healthCareNo
  3172. }
  3173. if patientBody["phone"] == nil || reflect.TypeOf(patientBody["phone"]).String() != "string" {
  3174. utils.ErrorLog("phone")
  3175. code = enums.ErrorCodeParamWrong
  3176. return
  3177. }
  3178. phone := patientBody["phone"].(string)
  3179. if len(phone) == 0 {
  3180. utils.ErrorLog("len(phone) == 0")
  3181. code = enums.ErrorCodeParamWrong
  3182. return
  3183. }
  3184. if !utils.CheckMobile(phone) {
  3185. utils.ErrorLog("!phone")
  3186. code = enums.ErrorCodeMobileFormat
  3187. return
  3188. }
  3189. patient.Phone = phone
  3190. if patientBody["homeTelephone"] != nil && reflect.TypeOf(patientBody["homeTelephone"]).String() == "string" {
  3191. homeTelephone := patientBody["homeTelephone"].(string)
  3192. patient.HomeTelephone = homeTelephone
  3193. }
  3194. if patientBody["relative_phone"] != nil && reflect.TypeOf(patientBody["relative_phone"]).String() == "string" {
  3195. relativePhone := patientBody["relative_phone"].(string)
  3196. patient.RelativePhone = relativePhone
  3197. }
  3198. if patientBody["relative_relations"] != nil && reflect.TypeOf(patientBody["relative_relations"]).String() == "string" {
  3199. relativeRelations := patientBody["relative_relations"].(string)
  3200. patient.RelativeRelations = relativeRelations
  3201. }
  3202. if patientBody["homeAddress"] != nil && reflect.TypeOf(patientBody["homeAddress"]).String() == "string" {
  3203. homeAddress := patientBody["homeAddress"].(string)
  3204. patient.HomeAddress = homeAddress
  3205. }
  3206. if patientBody["work"] != nil && reflect.TypeOf(patientBody["work"]).String() == "string" {
  3207. work := patientBody["work"].(string)
  3208. patient.WorkUnit = work
  3209. }
  3210. if patientBody["unit_address"] != nil && reflect.TypeOf(patientBody["unit_address"]).String() == "string" {
  3211. unitAddress := patientBody["unit_address"].(string)
  3212. patient.UnitAddress = unitAddress
  3213. }
  3214. if patientBody["profession"] != nil && reflect.TypeOf(patientBody["profession"]).String() == "float64" {
  3215. profession := int64(patientBody["profession"].(float64))
  3216. patient.Profession = profession
  3217. }
  3218. if patientBody["education"] != nil && reflect.TypeOf(patientBody["education"]).String() == "float64" {
  3219. education := int64(patientBody["education"].(float64))
  3220. patient.EducationLevel = education
  3221. }
  3222. if patientBody["source"] == nil || reflect.TypeOf(patientBody["source"]).String() != "float64" {
  3223. utils.ErrorLog("source")
  3224. code = enums.ErrorCodeParamWrong
  3225. return
  3226. }
  3227. source := int64(patientBody["source"].(float64))
  3228. if source <= 0 {
  3229. utils.ErrorLog("source <= 0")
  3230. code = enums.ErrorCodeParamWrong
  3231. return
  3232. }
  3233. patient.Source = source
  3234. if patientBody["is_hospital_first_dialysis"] != nil && reflect.TypeOf(patientBody["is_hospital_first_dialysis"]).String() == "float64" {
  3235. isHospitalFirstDialysis := int64(patientBody["is_hospital_first_dialysis"].(float64))
  3236. patient.IsHospitalFirstDialysis = isHospitalFirstDialysis
  3237. }
  3238. if patientBody["firstDialysisDate"] != nil && reflect.TypeOf(patientBody["firstDialysisDate"]).String() == "string" {
  3239. firstDialysisDate := patientBody["firstDialysisDate"].(string)
  3240. firstDialysisDateTime, err := time.ParseInLocation(timeLayout, firstDialysisDate, loc)
  3241. if err == nil {
  3242. patient.FirstDialysisDate = firstDialysisDateTime.Unix()
  3243. }
  3244. }
  3245. if patientBody["first_dialysis_hospital"] != nil && reflect.TypeOf(patientBody["first_dialysis_hospital"]).String() == "string" {
  3246. firstDialysisHospital := patientBody["first_dialysis_hospital"].(string)
  3247. patient.FirstDialysisHospital = firstDialysisHospital
  3248. }
  3249. if patientBody["predialysis_condition"] != nil && reflect.TypeOf(patientBody["predialysis_condition"]).String() == "[]interface {}" {
  3250. thePredialysisCondition, _ := patientBody["predialysis_condition"].([]interface{})
  3251. if len(thePredialysisCondition) > 0 {
  3252. conditions := make([]string, 0)
  3253. for _, item := range thePredialysisCondition {
  3254. if reflect.TypeOf(item).String() != "string" {
  3255. continue
  3256. }
  3257. condition := item.(string)
  3258. if len(condition) > 0 {
  3259. conditions = append(conditions, condition)
  3260. }
  3261. }
  3262. patient.PredialysisCondition = strings.Join(conditions, ",")
  3263. }
  3264. }
  3265. if patientBody["pre_hospital_dialysis_frequency"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_frequency"]).String() == "string" {
  3266. preHospitalDialysisFrequency := patientBody["pre_hospital_dialysis_frequency"].(string)
  3267. patient.PreHospitalDialysisFrequency = preHospitalDialysisFrequency
  3268. }
  3269. if patientBody["pre_hospital_dialysis_times"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_times"]).String() == "string" {
  3270. preHospitalDialysisTimes, _ := strconv.ParseInt(patientBody["pre_hospital_dialysis_times"].(string), 10, 64)
  3271. patient.PreHospitalDialysisTimes = preHospitalDialysisTimes
  3272. }
  3273. if patientBody["hospital_first_dialysis_date"] != nil && reflect.TypeOf(patientBody["hospital_first_dialysis_date"]).String() == "string" {
  3274. hospitalFirstDialysisDate := patientBody["hospital_first_dialysis_date"].(string)
  3275. hospitalFirstDialysisDateTime, err := time.ParseInLocation(timeLayout, hospitalFirstDialysisDate, loc)
  3276. if err == nil {
  3277. patient.HospitalFirstDialysisDate = hospitalFirstDialysisDateTime.Unix()
  3278. }
  3279. }
  3280. if patientBody["partition"] != nil && reflect.TypeOf(patientBody["partition"]).String() == "float64" {
  3281. partition := int64(patientBody["partition"].(float64))
  3282. patient.PartitionId = partition
  3283. }
  3284. if patientBody["bed"] != nil && reflect.TypeOf(patientBody["bed"]).String() == "string" {
  3285. bed, _ := strconv.ParseInt(patientBody["bed"].(string), 10, 64)
  3286. patient.BedId = bed
  3287. }
  3288. if patientBody["healthCareDueDate"] != nil && reflect.TypeOf(patientBody["healthCareDueDate"]).String() == "string" {
  3289. healthCareDueDate := patientBody["healthCareDueDate"].(string)
  3290. healthCareDueDateTime, err := time.ParseInLocation(timeLayout, healthCareDueDate, loc)
  3291. if err == nil {
  3292. patient.HealthCareDueDate = healthCareDueDateTime.Unix()
  3293. }
  3294. }
  3295. if patientBody["blood"] != nil && reflect.TypeOf(patientBody["blood"]).String() == "float64" {
  3296. blood := int64(patientBody["blood"].(float64))
  3297. patient.BloodType = blood
  3298. }
  3299. if patientBody["rh"] != nil && reflect.TypeOf(patientBody["rh"]).String() == "float64" {
  3300. rh := int64(patientBody["rh"].(float64))
  3301. patient.Rh = rh
  3302. }
  3303. if patientBody["healthCareDueAlertDate"] != nil && reflect.TypeOf(patientBody["healthCareDueAlertDate"]).String() == "string" {
  3304. healthCareDueAlertDate := patientBody["healthCareDueAlertDate"].(string)
  3305. healthCareDueAlertDateTime, err := time.ParseInLocation(timeLayout, healthCareDueAlertDate, loc)
  3306. if err == nil {
  3307. patient.HealthCareDueAlertDate = healthCareDueAlertDateTime.Unix()
  3308. }
  3309. }
  3310. if patientBody["receivingDate"] != nil && reflect.TypeOf(patientBody["receivingDate"]).String() == "string" {
  3311. receivingDate := patientBody["receivingDate"].(string)
  3312. receivingDateTime, err := time.ParseInLocation(timeLayout, receivingDate, loc)
  3313. if err == nil {
  3314. patient.ReceivingDate = receivingDateTime.Unix()
  3315. }
  3316. }
  3317. if patientBody["induction"] != nil && reflect.TypeOf(patientBody["induction"]).String() == "float64" {
  3318. induction := int64(patientBody["induction"].(float64))
  3319. patient.InductionPeriod = induction
  3320. }
  3321. if patientBody["initial"] != nil && reflect.TypeOf(patientBody["initial"]).String() == "string" {
  3322. initial, _ := strconv.ParseInt(patientBody["initial"].(string), 10, 64)
  3323. patient.InitialDialysis = initial
  3324. }
  3325. if patientBody["dialysisTotal"] != nil && reflect.TypeOf(patientBody["dialysisTotal"]).String() == "string" {
  3326. dialysisTotal, _ := strconv.ParseInt(patientBody["dialysisTotal"].(string), 10, 64)
  3327. patient.TotalDialysis = dialysisTotal
  3328. }
  3329. if patientBody["contagions"] != nil && reflect.TypeOf(patientBody["contagions"]).String() == "[]interface {}" {
  3330. thisContagions, _ := patientBody["contagions"].([]interface{})
  3331. if len(thisContagions) > 0 {
  3332. for _, item := range thisContagions {
  3333. if reflect.TypeOf(item).String() != "float64" {
  3334. continue
  3335. }
  3336. contagion := int64(item.(float64))
  3337. if contagion > 0 {
  3338. contagions = append(contagions, contagion)
  3339. }
  3340. }
  3341. }
  3342. }
  3343. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  3344. doctor := int64(patientBody["doctor"].(float64))
  3345. patient.AttendingDoctorId = doctor
  3346. }
  3347. if patientBody["nurse"] != nil && reflect.TypeOf(patientBody["nurse"]).String() == "float64" {
  3348. nurse := int64(patientBody["nurse"].(float64))
  3349. patient.HeadNurseId = nurse
  3350. }
  3351. if patientBody["assessment"] != nil && reflect.TypeOf(patientBody["assessment"]).String() == "string" {
  3352. assessment := patientBody["assessment"].(string)
  3353. patient.Evaluate = assessment
  3354. }
  3355. if patientBody["diseases"] != nil && reflect.TypeOf(patientBody["diseases"]).String() == "[]interface {}" {
  3356. thisDiseases, _ := patientBody["diseases"].([]interface{})
  3357. if len(thisDiseases) > 0 {
  3358. for _, item := range thisDiseases {
  3359. if reflect.TypeOf(item).String() != "float64" {
  3360. continue
  3361. }
  3362. disease := int64(item.(float64))
  3363. if disease > 0 {
  3364. diseases = append(diseases, disease)
  3365. }
  3366. }
  3367. }
  3368. }
  3369. if patientBody["diagnose"] != nil && reflect.TypeOf(patientBody["diagnose"]).String() == "string" {
  3370. diagnose := patientBody["diagnose"].(string)
  3371. patient.Diagnose = diagnose
  3372. }
  3373. if patientBody["remark"] != nil && reflect.TypeOf(patientBody["remark"]).String() == "string" {
  3374. remark := patientBody["remark"].(string)
  3375. patient.Remark = remark
  3376. }
  3377. if patientBody["sch_remark"] != nil && reflect.TypeOf(patientBody["sch_remark"]).String() == "string" {
  3378. sch_remark := patientBody["sch_remark"].(string)
  3379. patient.SchRemark = sch_remark
  3380. }
  3381. if patientBody["patient_complains"] != nil && reflect.TypeOf(patientBody["patient_complains"]).String() == "string" {
  3382. patient_complains := patientBody["patient_complains"].(string)
  3383. patient.PatientComplains = patient_complains
  3384. }
  3385. if patientBody["present_history"] != nil && reflect.TypeOf(patientBody["present_history"]).String() == "string" {
  3386. present_history := patientBody["present_history"].(string)
  3387. patient.PresentHistory = present_history
  3388. }
  3389. if patientBody["past_history"] != nil && reflect.TypeOf(patientBody["past_history"]).String() == "string" {
  3390. past_history := patientBody["past_history"].(string)
  3391. patient.PastHistory = past_history
  3392. }
  3393. if patientBody["temperature"] != nil && reflect.TypeOf(patientBody["temperature"]).String() == "string" {
  3394. temperature, _ := strconv.ParseFloat(patientBody["temperature"].(string), 64)
  3395. patient.Temperature = temperature
  3396. }
  3397. if patientBody["pulse"] != nil && reflect.TypeOf(patientBody["pulse"]).String() == "string" {
  3398. pulse, _ := strconv.ParseInt(patientBody["pulse"].(string), 10, 64)
  3399. patient.Pulse = pulse
  3400. }
  3401. if patientBody["respiratory"] != nil && reflect.TypeOf(patientBody["respiratory"]).String() == "string" {
  3402. respiratory, _ := strconv.ParseInt(patientBody["respiratory"].(string), 10, 64)
  3403. patient.Respiratory = respiratory
  3404. }
  3405. if patientBody["sbp"] != nil && reflect.TypeOf(patientBody["sbp"]).String() == "string" {
  3406. sbp, _ := strconv.ParseInt(patientBody["sbp"].(string), 10, 64)
  3407. patient.SBP = sbp
  3408. }
  3409. if patientBody["dbp"] != nil && reflect.TypeOf(patientBody["dbp"]).String() == "string" {
  3410. dbp, _ := strconv.ParseInt(patientBody["dbp"].(string), 10, 64)
  3411. patient.DBP = dbp
  3412. }
  3413. if patientBody["dialysis_age"] != nil && reflect.TypeOf(patientBody["dialysis_age"]).String() == "string" {
  3414. dialysis_age, _ := strconv.ParseInt(patientBody["dialysis_age"].(string), 10, 64)
  3415. patient.DialysisAge = dialysis_age
  3416. }
  3417. fmt.Println(patient.DialysisAge)
  3418. if patientBody["first_treatment_date"] != nil && reflect.TypeOf(patientBody["first_treatment_date"]).String() == "string" {
  3419. first_treatment_date := patientBody["first_treatment_date"].(string)
  3420. first_treatment_time, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  3421. if err == nil {
  3422. patient.FirstTreatmentDate = first_treatment_time.Unix()
  3423. }
  3424. }
  3425. if patientBody["expense_kind"] != nil && reflect.TypeOf(patientBody["expense_kind"]).String() == "float64" {
  3426. expense_kind := int64(patientBody["expense_kind"].(float64))
  3427. patient.ExpenseKind = expense_kind
  3428. }
  3429. fmt.Println(patient.ExpenseKind)
  3430. if patientBody["tell_phone"] != nil && reflect.TypeOf(patientBody["tell_phone"]).String() == "string" {
  3431. tell_phone := patientBody["tell_phone"].(string)
  3432. patient.TellPhone = tell_phone
  3433. }
  3434. if patientBody["contact_name"] != nil && reflect.TypeOf(patientBody["contact_name"]).String() == "string" {
  3435. contact_name := patientBody["contact_name"].(string)
  3436. patient.ContactName = contact_name
  3437. }
  3438. return
  3439. }
  3440. func (c *PatientApiController) GetPatientsByKeyWord() {
  3441. keyWord := c.GetString("keyword")
  3442. adminUserInfo := c.GetAdminUserInfo()
  3443. patient, err := service.GetPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  3444. if err != nil {
  3445. utils.ErrorLog(err.Error())
  3446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3447. return
  3448. }
  3449. c.ServeSuccessJSON(map[string]interface{}{
  3450. "patient": patient,
  3451. })
  3452. }
  3453. func (c *PatientApiController) QueryPatientById() {
  3454. id, _ := c.GetInt64("id")
  3455. fmt.Println(id)
  3456. patientInfo := service.QueryPatientById(id)
  3457. c.ServeSuccessJSON(map[string]interface{}{
  3458. "patient": patientInfo,
  3459. })
  3460. return
  3461. }
  3462. func (c *PatientApiController) GetRemindPatientList() {
  3463. page, _ := c.GetInt64("page", 1)
  3464. limit, _ := c.GetInt64("limit", 10)
  3465. adminUserInfo := c.GetAdminUserInfo()
  3466. total, patients, _ := service.GetAllWaitRemindPatient(adminUserInfo.CurrentOrgId, page, limit)
  3467. fmt.Println("机构ID2222222222222", c.GetAdminUserInfo().CurrentOrgId)
  3468. _, errcode := service.GetOrgFollowIsExist(c.GetAdminUserInfo().CurrentOrgId)
  3469. fmt.Println("机构ID2222222222222", errcode)
  3470. if errcode == gorm.ErrRecordNotFound {
  3471. information, err := service.GetAdminUserRoleInformation(0)
  3472. if err != nil {
  3473. utils.ErrorLog(err.Error())
  3474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3475. return
  3476. }
  3477. c.ServeSuccessJSON(map[string]interface{}{
  3478. "total": total,
  3479. "patients": patients,
  3480. "information": information,
  3481. })
  3482. } else if errcode == nil {
  3483. information, err := service.GetAdminUserRoleInformation(c.GetAdminUserInfo().CurrentOrgId)
  3484. if err != nil {
  3485. utils.ErrorLog(err.Error())
  3486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3487. return
  3488. }
  3489. c.ServeSuccessJSON(map[string]interface{}{
  3490. "total": total,
  3491. "patients": patients,
  3492. "information": information,
  3493. })
  3494. }
  3495. }
  3496. func (c *PatientApiController) PostIsOpenRemind() {
  3497. patient_id, _ := c.GetInt64("id", 1)
  3498. is_open_remind, _ := c.GetInt64("is_open_remind", 1)
  3499. adminUserInfo := c.GetAdminUserInfo()
  3500. err := service.UpdatePatientRemindStatus(patient_id, is_open_remind, adminUserInfo.CurrentOrgId)
  3501. if err == nil {
  3502. c.ServeSuccessJSON(map[string]interface{}{
  3503. "msg": "成功",
  3504. "is_open_remind": is_open_remind,
  3505. })
  3506. } else if err != nil {
  3507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3508. }
  3509. }
  3510. func (c *PatientApiController) GetPatientScheduleOne() {
  3511. id, _ := c.GetInt64("id")
  3512. //查询该病人是否当天是排班
  3513. nowDateTime := time.Now()
  3514. nowDate := nowDateTime.Format("2006-01-02")
  3515. nowDate += " 00:00:00"
  3516. timeLayout := "2006-01-02"
  3517. loc, _ := time.LoadLocation("Local")
  3518. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  3519. nowdate := theTime.Unix()
  3520. fmt.Println("nowdate", nowdate)
  3521. adminUser := c.GetAdminUserInfo()
  3522. orgId := adminUser.CurrentOrgId
  3523. fmt.Println("orgid", orgId)
  3524. scheduls, err := service.GetPatientScheduleOne(id, nowdate, orgId)
  3525. if err != nil {
  3526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3527. return
  3528. }
  3529. c.ServeSuccessJSON(map[string]interface{}{
  3530. "scheduls": scheduls,
  3531. })
  3532. }
  3533. func (c *PatientApiController) ExportPatients() {
  3534. dataBody := make(map[string]interface{}, 0)
  3535. all_patient, _, _ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId)
  3536. //all_patient, _,_ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId )
  3537. org, _ := service.GetOrgById(c.GetAdminUserInfo().CurrentOrgId)
  3538. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3539. if err != nil {
  3540. utils.ErrorLog(err.Error())
  3541. return
  3542. }
  3543. utils.ErrorLog("%v", dataBody)
  3544. export_time := time.Now().Unix()
  3545. var patients []*models.Patients
  3546. var total_patients []interface{}
  3547. if dataBody["patients"] != nil || reflect.TypeOf(dataBody["patients"]).String() == "[]interface {}" {
  3548. tempPatients := dataBody["patients"].([]interface{})
  3549. total_patients = tempPatients
  3550. for index, patientMap := range tempPatients {
  3551. patientNameM := patientMap.(map[string]interface{})
  3552. var patient models.Patients
  3553. if patientNameM["name"] == nil || reflect.TypeOf(patientNameM["name"]).String() != "string" {
  3554. utils.ErrorLog("name")
  3555. return
  3556. }
  3557. name, _ := patientNameM["name"].(string)
  3558. if len(name) == 0 { //名字为空则生成一条导入错误日志
  3559. err_log := models.ExportErrLog{
  3560. LogType: 1,
  3561. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3562. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的姓名不能为空",
  3563. Status: 1,
  3564. CreateTime: time.Now().Unix(),
  3565. UpdateTime: time.Now().Unix(),
  3566. ExportTime: export_time,
  3567. }
  3568. service.CreateExportErrLog(&err_log)
  3569. continue
  3570. }
  3571. patient.Name = name
  3572. if patientNameM["gender"] != nil || reflect.TypeOf(patientNameM["gender"]).String() == "string" {
  3573. gender, _ := strconv.ParseInt(patientNameM["gender"].(string), 10, 64)
  3574. if gender == 0 { //性别不符合要求则生成一条导入错误日志
  3575. err_log := models.ExportErrLog{
  3576. LogType: 1,
  3577. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3578. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的性别不符合要求",
  3579. Status: 1,
  3580. CreateTime: time.Now().Unix(),
  3581. UpdateTime: time.Now().Unix(),
  3582. ExportTime: export_time,
  3583. }
  3584. service.CreateExportErrLog(&err_log)
  3585. continue
  3586. } else {
  3587. patient.Gender = gender
  3588. }
  3589. }
  3590. if patientNameM["phone"] != nil || reflect.TypeOf(patientNameM["phone"]).String() == "string" {
  3591. phone, _ := patientNameM["phone"].(string)
  3592. if utils.CellPhoneRegexp().MatchString(phone) == false { //手机号码不符合要求则生成一条导入错误日志
  3593. if len(phone) == 0 {
  3594. err_log := models.ExportErrLog{
  3595. LogType: 1,
  3596. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3597. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码不能为空",
  3598. Status: 1,
  3599. CreateTime: time.Now().Unix(),
  3600. UpdateTime: time.Now().Unix(),
  3601. ExportTime: export_time,
  3602. }
  3603. service.CreateExportErrLog(&err_log)
  3604. continue
  3605. } else {
  3606. err_log := models.ExportErrLog{
  3607. LogType: 1,
  3608. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3609. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码格式不符合要求",
  3610. Status: 1,
  3611. CreateTime: time.Now().Unix(),
  3612. UpdateTime: time.Now().Unix(),
  3613. ExportTime: export_time,
  3614. }
  3615. service.CreateExportErrLog(&err_log)
  3616. continue
  3617. }
  3618. } else {
  3619. //var tempPatient *models.Patients
  3620. //for _, item := range all_patient {
  3621. // if item.Phone == phone {
  3622. // tempPatient = item
  3623. // }
  3624. //}
  3625. //需要判断该号码是否已经在系统内存在了,存在了则生成一条导入错误日志
  3626. count := service.FindPatientPhoneIsExist(phone, c.GetAdminUserInfo().CurrentOrgId)
  3627. if count >= 1 {
  3628. err_log := models.ExportErrLog{
  3629. LogType: 1,
  3630. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3631. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码在系统中已经存在",
  3632. Status: 1,
  3633. CreateTime: time.Now().Unix(),
  3634. UpdateTime: time.Now().Unix(),
  3635. ExportTime: export_time,
  3636. }
  3637. service.CreateExportErrLog(&err_log)
  3638. continue
  3639. }
  3640. patient.Phone = phone
  3641. }
  3642. }
  3643. if patientNameM["id_card_no"] != nil || reflect.TypeOf(patientNameM["id_card_no"]).String() == "string" {
  3644. id_card_no, _ := patientNameM["id_card_no"].(string)
  3645. if IsIdCard(id_card_no) == false { //身份证号码不符合要求则生成一条导入错误日志
  3646. if len(id_card_no) == 0 {
  3647. err_log := models.ExportErrLog{
  3648. LogType: 1,
  3649. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3650. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码不能为空",
  3651. Status: 1,
  3652. CreateTime: time.Now().Unix(),
  3653. UpdateTime: time.Now().Unix(),
  3654. ExportTime: export_time,
  3655. }
  3656. service.CreateExportErrLog(&err_log)
  3657. continue
  3658. } else {
  3659. err_log := models.ExportErrLog{
  3660. LogType: 1,
  3661. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3662. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码格式不符合要求",
  3663. Status: 1,
  3664. CreateTime: time.Now().Unix(),
  3665. UpdateTime: time.Now().Unix(),
  3666. ExportTime: export_time,
  3667. }
  3668. service.CreateExportErrLog(&err_log)
  3669. continue
  3670. }
  3671. } else {
  3672. //var tempPatient *models.Patients
  3673. //for _, item := range all_patient {
  3674. // if item.IdCardNo == id_card_no {
  3675. // tempPatient = item
  3676. // }
  3677. //}
  3678. count := service.FindPatientIdCardNoIsExist(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  3679. if count >= 1 {
  3680. //if tempPatient != nil && tempPatient.ID > 0 {
  3681. err_log := models.ExportErrLog{
  3682. LogType: 1,
  3683. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3684. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码在系统中已经存在",
  3685. Status: 1,
  3686. CreateTime: time.Now().Unix(),
  3687. UpdateTime: time.Now().Unix(),
  3688. ExportTime: export_time,
  3689. }
  3690. service.CreateExportErrLog(&err_log)
  3691. continue
  3692. }
  3693. //}
  3694. patient.IdCardNo = id_card_no
  3695. //patient.Birthday = GetBirthDay(id_card_no).Unix()
  3696. if GetBirthDay(id_card_no) == nil {
  3697. patient.Birthday = 0
  3698. } else {
  3699. patient.Birthday = GetBirthDay(id_card_no).Unix()
  3700. }
  3701. }
  3702. }
  3703. fmt.Println("111112222")
  3704. if patientNameM["first_treatment_date"] != nil || reflect.TypeOf(patientNameM["first_treatment_date"]).String() == "string" {
  3705. first_treatment_date, _ := patientNameM["first_treatment_date"].(string)
  3706. timeLayout := "2006/01/02"
  3707. loc, _ := time.LoadLocation("Local")
  3708. first_dialysis_date, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  3709. if err != nil { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  3710. if len(first_treatment_date) == 0 {
  3711. err_log := models.ExportErrLog{
  3712. LogType: 1,
  3713. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3714. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  3715. Status: 1,
  3716. CreateTime: time.Now().Unix(),
  3717. UpdateTime: time.Now().Unix(),
  3718. ExportTime: export_time,
  3719. }
  3720. service.CreateExportErrLog(&err_log)
  3721. continue
  3722. } else {
  3723. err_log := models.ExportErrLog{
  3724. LogType: 1,
  3725. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3726. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  3727. Status: 1,
  3728. CreateTime: time.Now().Unix(),
  3729. UpdateTime: time.Now().Unix(),
  3730. ExportTime: export_time,
  3731. }
  3732. service.CreateExportErrLog(&err_log)
  3733. continue
  3734. }
  3735. } else {
  3736. if len(first_treatment_date) == 0 {
  3737. err_log := models.ExportErrLog{
  3738. LogType: 1,
  3739. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3740. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  3741. Status: 1,
  3742. CreateTime: time.Now().Unix(),
  3743. UpdateTime: time.Now().Unix(),
  3744. ExportTime: export_time,
  3745. }
  3746. service.CreateExportErrLog(&err_log)
  3747. continue
  3748. } else {
  3749. if first_dialysis_date.Unix() == 0 { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  3750. err_log := models.ExportErrLog{
  3751. LogType: 1,
  3752. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3753. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  3754. Status: 1,
  3755. CreateTime: time.Now().Unix(),
  3756. UpdateTime: time.Now().Unix(),
  3757. ExportTime: export_time,
  3758. }
  3759. service.CreateExportErrLog(&err_log)
  3760. continue
  3761. } else {
  3762. patient.FirstDialysisDate = first_dialysis_date.Unix()
  3763. }
  3764. }
  3765. }
  3766. }
  3767. if patientNameM["source"] != nil || reflect.TypeOf(patientNameM["source"]).String() == "string" {
  3768. source, _ := strconv.ParseInt(patientNameM["source"].(string), 10, 64)
  3769. if source == 0 { //患者来源不符合要求则生成一条导入错误日志
  3770. err_log := models.ExportErrLog{
  3771. LogType: 1,
  3772. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3773. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不符合要求",
  3774. Status: 1,
  3775. CreateTime: time.Now().Unix(),
  3776. UpdateTime: time.Now().Unix(),
  3777. ExportTime: export_time,
  3778. }
  3779. service.CreateExportErrLog(&err_log)
  3780. continue
  3781. } else if source == 3 {
  3782. err_log := models.ExportErrLog{
  3783. LogType: 1,
  3784. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3785. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不能为空",
  3786. Status: 1,
  3787. CreateTime: time.Now().Unix(),
  3788. UpdateTime: time.Now().Unix(),
  3789. ExportTime: export_time,
  3790. }
  3791. service.CreateExportErrLog(&err_log)
  3792. continue
  3793. } else {
  3794. patient.Source = source
  3795. }
  3796. }
  3797. if patientNameM["lapseto"] != nil || reflect.TypeOf(patientNameM["lapseto"]).String() == "string" {
  3798. lapseto, _ := strconv.ParseInt(patientNameM["lapseto"].(string), 10, 64)
  3799. if lapseto == 0 { //治疗状态不符合要求则生成一条导入错误日志
  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 if lapseto == 3 {
  3812. err_log := models.ExportErrLog{
  3813. LogType: 1,
  3814. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3815. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不能为空",
  3816. Status: 1,
  3817. CreateTime: time.Now().Unix(),
  3818. UpdateTime: time.Now().Unix(),
  3819. ExportTime: export_time,
  3820. }
  3821. service.CreateExportErrLog(&err_log)
  3822. continue
  3823. } else {
  3824. patient.Lapseto = lapseto
  3825. }
  3826. }
  3827. if patientNameM["is_infectious"] != nil || reflect.TypeOf(patientNameM["is_infectious"]).String() == "string" {
  3828. is_infectious, _ := strconv.ParseInt(patientNameM["is_infectious"].(string), 10, 64)
  3829. if is_infectious == 0 { //传染病不符合要求则生成一条导入错误日志
  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 if is_infectious == 3 {
  3842. err_log := models.ExportErrLog{
  3843. LogType: 1,
  3844. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3845. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不能为空",
  3846. Status: 1,
  3847. CreateTime: time.Now().Unix(),
  3848. UpdateTime: time.Now().Unix(),
  3849. ExportTime: export_time,
  3850. }
  3851. service.CreateExportErrLog(&err_log)
  3852. continue
  3853. } else {
  3854. patient.IsInfectious = is_infectious
  3855. }
  3856. }
  3857. if patientNameM["contagions"] != nil && reflect.TypeOf(patientNameM["contagions"]).String() == "[]interface {}" {
  3858. var contagions []int64
  3859. thisContagions, _ := patientNameM["contagions"].([]interface{})
  3860. if len(thisContagions) > 0 {
  3861. for _, item := range thisContagions {
  3862. if reflect.TypeOf(item).String() != "float64" {
  3863. continue
  3864. }
  3865. contagion := int64(item.(float64))
  3866. if contagion > 0 {
  3867. contagions = append(contagions, contagion)
  3868. }
  3869. }
  3870. }
  3871. patient.ContagionIds = contagions
  3872. }
  3873. if patientNameM["diagnose"] != nil || reflect.TypeOf(patientNameM["diagnose"]).String() == "string" {
  3874. diagnose, _ := patientNameM["diagnose"].(string)
  3875. patient.Diagnose = diagnose
  3876. }
  3877. if patientNameM["dialysis_no"] != nil || reflect.TypeOf(patientNameM["dialysis_no"]).String() == "string" {
  3878. dialysis_no, _ := patientNameM["dialysis_no"].(string)
  3879. var tempPatient *models.Patients
  3880. for _, item := range all_patient {
  3881. if item.DialysisNo == dialysis_no {
  3882. tempPatient = item
  3883. }
  3884. }
  3885. if tempPatient != nil && tempPatient.ID > 0 {
  3886. patient.DialysisNo = GenerateDialysisNoTwo(patients)
  3887. } else {
  3888. patient.DialysisNo = dialysis_no
  3889. }
  3890. }
  3891. if patientNameM["height"] != nil || reflect.TypeOf(patientNameM["height"]).String() == "string" {
  3892. height, _ := patientNameM["height"].(string)
  3893. heights, _ := strconv.ParseFloat(height, 64)
  3894. patient.Height = int64(heights)
  3895. }
  3896. if patientNameM["home_address"] != nil || reflect.TypeOf(patientNameM["home_address"]).String() == "string" {
  3897. home_address, _ := patientNameM["home_address"].(string)
  3898. patient.HomeAddress = home_address
  3899. }
  3900. if patientNameM["dry_weight"] != nil || reflect.TypeOf(patientNameM["dry_weight"]).String() == "string" {
  3901. dry_weight, _ := patientNameM["dry_weight"].(string)
  3902. dry_weights, _ := strconv.ParseFloat(dry_weight, 64)
  3903. patient.DryWeight = dry_weights
  3904. }
  3905. patient.CreatedTime = time.Now().Unix()
  3906. patient.UpdatedTime = time.Now().Unix()
  3907. patient.Status = 1
  3908. patient.Avatar = "https://images.shengws.com/201809182128111.png"
  3909. patient.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
  3910. patient.IsExcelExport = 1
  3911. patient.PatientType = 1
  3912. patients = append(patients, &patient)
  3913. }
  3914. }
  3915. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  3916. if len(patients) > 0 {
  3917. for _, item := range patients {
  3918. service.CreateExportPatient(item, item.ContagionIds, org.Creator)
  3919. }
  3920. log := models.ExportLog{
  3921. LogType: 1,
  3922. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3923. TotalNum: int64(len(total_patients)),
  3924. FailNum: int64(len(errLogs)),
  3925. SuccessNum: int64(len(patients)),
  3926. CreateTime: time.Now().Unix(),
  3927. UpdateTime: time.Now().Unix(),
  3928. ExportTime: export_time,
  3929. Status: 1,
  3930. }
  3931. service.CreateExportLog(&log)
  3932. c.ServeSuccessJSON(map[string]interface{}{
  3933. "msg": "导入成功",
  3934. "total_num": len(total_patients),
  3935. "success_num": len(patients),
  3936. "fail_num": int64(len(errLogs)),
  3937. })
  3938. } else {
  3939. log := models.ExportLog{
  3940. LogType: 1,
  3941. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3942. TotalNum: int64(len(total_patients)),
  3943. FailNum: int64(len(errLogs)),
  3944. SuccessNum: int64(len(patients)),
  3945. CreateTime: time.Now().Unix(),
  3946. UpdateTime: time.Now().Unix(),
  3947. ExportTime: export_time,
  3948. Status: 1,
  3949. }
  3950. service.CreateExportLog(&log)
  3951. c.ServeSuccessJSON(map[string]interface{}{
  3952. "msg": "导入成功",
  3953. "total_num": len(total_patients),
  3954. "success_num": len(patients),
  3955. "fail_num": int64(len(errLogs)),
  3956. })
  3957. }
  3958. }
  3959. func GetBirthDay(IDCardNo string) *time.Time {
  3960. dayStr := IDCardNo[6:14]
  3961. birthDay, err := time.Parse("20060102", dayStr)
  3962. if err != nil {
  3963. fmt.Println(err)
  3964. return nil
  3965. }
  3966. return &birthDay
  3967. }
  3968. func IsIdCard(id string) (res bool) {
  3969. id = strings.ToUpper(id)
  3970. if len(id) != 15 && len(id) != 18 {
  3971. fmt.Println("1111111")
  3972. return false
  3973. }
  3974. r := regexp.MustCompile("(\\d{15})|(\\d{17}([0-9]|X))")
  3975. if !r.MatchString(id) {
  3976. fmt.Println("222222")
  3977. return false
  3978. }
  3979. if len(id) == 15 {
  3980. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[8:10])+"/"+string([]byte(id)[10:12])+"/"+"19"+string([]byte(id)[6:8]))
  3981. if tm2.Unix() == 0 {
  3982. fmt.Println("44444443333")
  3983. return false
  3984. }
  3985. return true
  3986. } else {
  3987. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[10:12])+"/"+string([]byte(id)[12:14])+"/"+string([]byte(id)[6:10]))
  3988. fmt.Println(string([]byte(id)[10:12]) + "/" + string([]byte(id)[12:14]) + "/" + string([]byte(id)[6:10]))
  3989. fmt.Println(tm2.Unix())
  3990. if tm2.Unix() == 0 {
  3991. fmt.Println("44445555555")
  3992. return false
  3993. }
  3994. //检验18位身份证的校验码是否正确。
  3995. //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
  3996. arr_int := []int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
  3997. arr_ch := []string{"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}
  3998. sign := 0
  3999. for k, v := range arr_int {
  4000. int_temp, _ := strconv.Atoi(string([]byte(id)[k : k+1]))
  4001. sign += int_temp * v
  4002. }
  4003. n := sign % 11
  4004. val_num := arr_ch[n]
  4005. if val_num != string([]byte(id)[17:18]) {
  4006. fmt.Println("5556666666")
  4007. return false
  4008. }
  4009. return true
  4010. }
  4011. }
  4012. func (c *PatientApiController) SaveEditAdvices() {
  4013. adminInfo := c.GetAdminUserInfo()
  4014. orgid := adminInfo.CurrentOrgId
  4015. startTime := c.GetString("start_time")
  4016. theTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", startTime)
  4017. groupno, _ := c.GetInt64("groupno")
  4018. fmt.Println("组", groupno)
  4019. date, _ := c.GetInt64("date")
  4020. fmt.Println("date", date)
  4021. patient_id, _ := c.GetInt64("patient_id")
  4022. fmt.Println("paitent_id", patient_id)
  4023. advice := models.XtDoctorAdvice{
  4024. StartTime: theTime.Unix(),
  4025. }
  4026. err := service.UpdateDoctorEditAdvice(advice, orgid, groupno, date, patient_id)
  4027. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(date, 10) + ":doctor_advices"
  4028. redis := service.RedisClient()
  4029. redis.Set(key, "", time.Second)
  4030. keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(date, 10) + ":advice_list_all"
  4031. redis.Set(keyOne, "", time.Second)
  4032. scheduleTime := theTime.Format("2006-01-02")
  4033. keyFour := "scheduals_" + scheduleTime + "_" + strconv.FormatInt(orgid, 10)
  4034. fmt.Println("keyFour323223323232323232", keyFour)
  4035. redis.Set(keyFour, "", time.Second)
  4036. defer redis.Close()
  4037. if err != nil {
  4038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4039. return
  4040. }
  4041. c.ServeSuccessJSON(map[string]interface{}{
  4042. "advice": advice,
  4043. })
  4044. }
  4045. func (c *PatientApiController) GetMaxDialysisNo() {
  4046. dialysisNo := service.ChechLastDialysisNo(c.GetAdminUserInfo().CurrentOrgId)
  4047. c.ServeSuccessJSON(map[string]interface{}{
  4048. "dialysis_no": dialysisNo,
  4049. })
  4050. }
  4051. func GenerateDialysisNoTwo(patients []*models.Patients) string {
  4052. dialysisNo2 := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
  4053. var tempPatient *models.Patients
  4054. for _, item := range patients {
  4055. if item.DialysisNo == dialysisNo2 {
  4056. tempPatient = item
  4057. }
  4058. }
  4059. if tempPatient == nil || tempPatient.ID == 0 {
  4060. return dialysisNo2
  4061. }
  4062. return GenerateDialysisNoTwo(patients)
  4063. }
  4064. func (c *PatientApiController) GetBanner() {
  4065. orgId := c.GetAdminUserInfo().CurrentOrgId
  4066. _, errcodes := service.GetOrgFollowIsExist(orgId)
  4067. if errcodes == gorm.ErrRecordNotFound {
  4068. information, err := service.GetAdminUserRoleInformation(0)
  4069. if err != nil {
  4070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4071. return
  4072. }
  4073. c.ServeSuccessJSON(map[string]interface{}{
  4074. "information": information,
  4075. })
  4076. } else if errcodes == nil {
  4077. information, err := service.GetAdminUserRoleInformation(orgId)
  4078. if err != nil {
  4079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4080. return
  4081. }
  4082. c.ServeSuccessJSON(map[string]interface{}{
  4083. "information": information,
  4084. })
  4085. }
  4086. }