patient_api_controller.go 156KB

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