patient_api_controller.go 138KB

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