patient_api_controller.go 148KB

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