patient_api_controller.go 143KB

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