patient_api_controller.go 171KB

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