patient_api_controller.go 131KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984
  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. "math/rand"
  9. "reflect"
  10. "regexp"
  11. "strconv"
  12. "strings"
  13. "time"
  14. "fmt"
  15. "github.com/astaxie/beego"
  16. )
  17. type PatientApiController struct {
  18. BaseAuthAPIController
  19. }
  20. func PatientApiRegistRouters() {
  21. beego.Router("/api/patients", &PatientApiController{}, "get:GetPatientsList")
  22. beego.Router("/api/patients/all", &PatientApiController{}, "get:GetPatientsAllList")
  23. beego.Router("/api/patients/generatedialysisno", &PatientApiController{}, "get:GenerateDialysisNo")
  24. beego.Router("/api/patients/create", &PatientApiController{}, "Post:CreatePatient")
  25. beego.Router("/api/patients/total", &PatientApiController{}, "Get:GetPatientTotal")
  26. beego.Router("/api/patients/get", &PatientApiController{}, "Get:GetPatient")
  27. beego.Router("/api/patients/edit", &PatientApiController{}, "Put:EditPatient")
  28. beego.Router("/api/patients/dialysissolution/create", &PatientApiController{}, "Post:CreateDialysisSolution")
  29. beego.Router("/api/patients/dialysissolution/edit", &PatientApiController{}, "Put:UpdateDialysisSolution")
  30. beego.Router("/api/patients/dialysissolutions", &PatientApiController{}, "get:GetPatientDialysisSolutionList")
  31. beego.Router("/api/patients/dialysissolution/detail/edit", &PatientApiController{}, "Put:UpdateDialysisSolutionDetail")
  32. // beego.Router("/api/patients/dialysissolution/delete", &PatientApiController{}, "Delete:DeleteDialysisSolution")
  33. beego.Router("/api/patients/dryweight/get", &PatientApiController{}, "get:GetDryWeights")
  34. beego.Router("/api/patients/dryweight/create", &PatientApiController{}, "Post:CreateDryWeights")
  35. beego.Router("/api/patients/advice/create", &PatientApiController{}, "Post:CreateDoctorAdvice")
  36. beego.Router("/api/patients/advice/edit", &PatientApiController{}, "Put:UpdateDoctorAdvice")
  37. beego.Router("/api/patients/advice/exec", &PatientApiController{}, "Post:ExecDoctorAdvice")
  38. beego.Router("/api/patients/advice/check", &PatientApiController{}, "Post:CheckDoctorAdvice")
  39. beego.Router("/api/patients/advices", &PatientApiController{}, "Get:GetDoctorAdvices")
  40. beego.Router("/api/patients/advice/stop", &PatientApiController{}, "Post:StopDoctorAdvice")
  41. beego.Router("/api/patients/advice/delete", &PatientApiController{}, "Delete:DeleteDoctorAdvice")
  42. beego.Router("/api/patients/advice/creategroup", &PatientApiController{}, "Post:CreateGroupAdvice")
  43. beego.Router("/api/patients/advice/deletegroup", &PatientApiController{}, "Delete:DeleteGroupAdvice")
  44. beego.Router("/api/patients/advice/stopgroup", &PatientApiController{}, "Post:StopGroupAdvice")
  45. beego.Router("/api/patients/advice/execgroup", &PatientApiController{}, "Post:ExecGroupAdvice")
  46. beego.Router("/api/patients/advice/checkgroup", &PatientApiController{}, "Post:CheckGroupAdvice")
  47. beego.Router("/api/patients/schedules", &PatientApiController{}, "Get:GetPatientSchedules")
  48. beego.Router("/api/patients/dialysisrecords", &PatientApiController{}, "Get:GetPatientDialysisRecords")
  49. beego.Router("/api/patients/proeducation", &PatientApiController{}, "Get:ProEducation")
  50. beego.Router("/api/patients/lapseto/edit", &PatientApiController{}, "Post:EditLapseto")
  51. beego.Router("/api/patients/search", &PatientApiController{}, "Post:GetPatientsByKeyWord")
  52. beego.Router("/api/patients/querypatientbyId", &PatientApiController{}, "Get:QueryPatientById")
  53. beego.Router("/api/infectious/remind", &PatientApiController{}, "Get:GetRemindPatientList")
  54. beego.Router("/api/remind/is_open", &PatientApiController{}, "Post:PostIsOpenRemind")
  55. beego.Router("/api/patients/advices/getpatientschedules", &PatientApiController{}, "Get:GetPatientScheduleOne")
  56. beego.Router("/api/patients/export", &PatientApiController{}, "Post:ExportPatients")
  57. beego.Router("/api/patients/advices/saveditadvices", &PatientApiController{}, "Get:SaveEditAdvices")
  58. beego.Router("/api/patients/dialysis_no", &PatientApiController{}, "Get:GetMaxDialysisNo")
  59. }
  60. //GetPatientsList 取患者列表
  61. func (c *PatientApiController) GetPatientsList() {
  62. page, _ := c.GetInt64("page", 1)
  63. limit, _ := c.GetInt64("limit", 10)
  64. schedulType, _ := c.GetInt64("schedul_type", 0)
  65. bindingState, _ := c.GetInt64("binding_state", 0)
  66. lapseto, _ := c.GetInt64("lapseto", 0)
  67. source, _ := c.GetInt64("source", 0)
  68. startTime := c.GetString("start_time", "")
  69. endTime := c.GetString("end_time", "")
  70. keywords := c.GetString("keywords", "")
  71. contagion, _ := c.GetInt64("contagion", 0)
  72. reimbursement_way, _ := c.GetInt64("reimbursement_way", 0)
  73. isscheduling, _ := c.GetInt64("isscheduling", 0)
  74. isprescription, _ := c.GetInt64("isprescription", 0)
  75. if page <= 0 {
  76. page = 1
  77. }
  78. if limit <= 0 {
  79. limit = 10
  80. }
  81. adminUserInfo := c.GetAdminUserInfo()
  82. timeLayout := "2006-01-02"
  83. loc, _ := time.LoadLocation("Local")
  84. var isStartTime bool
  85. var theStartTIme int64
  86. if len(startTime) > 0 {
  87. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  88. if err != nil {
  89. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  90. return
  91. }
  92. isStartTime = true
  93. theStartTIme = theTime.Unix()
  94. }
  95. var isEndTime bool
  96. var theEndtTIme int64
  97. if len(endTime) > 0 {
  98. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  99. if err != nil {
  100. utils.ErrorLog(err.Error())
  101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  102. return
  103. }
  104. isEndTime = true
  105. theEndtTIme = theTime.Unix()
  106. }
  107. patients, total, _ := service.GetPatientList(adminUserInfo.CurrentOrgId, keywords, page, limit, schedulType, bindingState, lapseto, source, theStartTIme, theEndtTIme, contagion, reimbursement_way, isscheduling, isprescription, isStartTime, isEndTime)
  108. c.ServeSuccessJSON(map[string]interface{}{
  109. "patients": patients,
  110. "total": total,
  111. })
  112. return
  113. }
  114. //GetPatientTotal
  115. func (c *PatientApiController) GetPatientTotal() {
  116. adminUserInfo := c.GetAdminUserInfo()
  117. total := service.GetPatientCount(adminUserInfo.CurrentOrgId)
  118. c.ServeSuccessJSON(map[string]interface{}{
  119. "total": total,
  120. })
  121. return
  122. }
  123. func (c *PatientApiController) GetPatientsAllList() {
  124. adminUserInfo := c.GetAdminUserInfo()
  125. patients, total, _ := service.GetAllPatientList(adminUserInfo.CurrentOrgId)
  126. c.ServeSuccessJSON(map[string]interface{}{
  127. "patients": patients,
  128. "total": total,
  129. })
  130. return
  131. }
  132. //GenerateDialysisNo 生成透析号
  133. func (c *PatientApiController) GenerateDialysisNo() {
  134. adminUserInfo := c.GetAdminUserInfo()
  135. dialysisNo := service.ChechLastDialysisNo(adminUserInfo.CurrentOrgId)
  136. if dialysisNo == 0 {
  137. dialysisNo = 1
  138. } else {
  139. dialysisNo++
  140. }
  141. no := strconv.FormatInt(dialysisNo, 10)
  142. rep := 3 - len(no)
  143. if rep > 0 {
  144. no = strings.Repeat("0", rep) + no
  145. }
  146. c.ServeSuccessJSON(map[string]interface{}{
  147. "no": no,
  148. })
  149. return
  150. }
  151. //CreatePatient 创建患者
  152. func (c *PatientApiController) CreatePatient() {
  153. record_date := c.GetString("record_date")
  154. is_infectious, _ := c.GetInt64("is_infectious")
  155. remind_cycle, _ := c.GetInt64("remind_cycle")
  156. adminUserInfo := c.GetAdminUserInfo()
  157. //patientTotal := service.GetLapsetoPatientCount(adminUserInfo.CurrentOrgId, 1)
  158. //subscibes := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
  159. //if subscibes.State == 2 && patientTotal >= 20 { //免费试用版,不过期,限制患者数20
  160. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  161. // return
  162. //} else if subscibes.State == 1 && patientTotal >= 60 { //标准版,不过期,限制患者数60
  163. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  164. // return
  165. //}
  166. var patient models.Patients
  167. contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "create")
  168. fmt.Println(code)
  169. fmt.Println(patient)
  170. fmt.Println("contagions是什么", contagions)
  171. if code > 0 {
  172. c.ServeFailJSONWithSGJErrorCode(code)
  173. return
  174. }
  175. thisPatient, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
  176. if thisPatient.ID > 0 {
  177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
  178. return
  179. }
  180. thisPatient, _ = service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
  181. if thisPatient.ID > 0 {
  182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
  183. return
  184. }
  185. thisPatient, _ = service.FindPatientByMobile(adminUserInfo.CurrentOrgId, patient.Phone)
  186. if thisPatient.ID > 0 {
  187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientPhoneUsed)
  188. return
  189. }
  190. patient.RemindCycle = remind_cycle
  191. patient.IsInfectious = is_infectious
  192. patient.RegistrarsId = adminUserInfo.AdminUser.Id
  193. patient.Status = 1
  194. patient.CreatedTime = time.Now().Unix()
  195. patient.UserOrgId = adminUserInfo.CurrentOrgId
  196. patient.UpdatedTime = time.Now().Unix()
  197. patient.BindingState = 2
  198. // patient.Lapseto = 1
  199. err := service.CreatePatient(&patient, contagions, diseases)
  200. fmt.Println("创建病人失败err")
  201. if err != nil {
  202. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePatient)
  203. return
  204. }
  205. //获取老表的最后一条数据
  206. patients, err := service.GetLastPatientData(adminUserInfo.CurrentOrgId)
  207. patientsNew := models.XtPatientsNew{
  208. UserOrgId: adminUserInfo.CurrentOrgId,
  209. UserId: 0,
  210. Avatar: patients.Avatar,
  211. PatientType: patients.PatientType,
  212. DialysisNo: patients.DialysisNo,
  213. AdmissionNumber: patients.AdmissionNumber,
  214. Source: patients.Source,
  215. Lapseto: patients.Lapseto,
  216. PartitionId: patients.PartitionId,
  217. BedId: patients.BedId,
  218. Name: patients.Name,
  219. Alias: patients.Alias,
  220. Gender: patients.Gender,
  221. MaritalStatus: patients.MaritalStatus,
  222. IdCardNo: patients.IdCardNo,
  223. Birthday: patients.Birthday,
  224. ReimbursementWayId: patients.ReimbursementWayId,
  225. HealthCareType: patients.HealthCareType,
  226. HealthCareNo: patients.HealthCareNo,
  227. HealthCareDueDate: patients.HealthCareDueDate,
  228. Height: patients.Height,
  229. BloodType: patients.BloodType,
  230. Rh: patients.Rh,
  231. HealthCareDueAlertDate: patients.HealthCareDueAlertDate,
  232. EducationLevel: patients.EducationLevel,
  233. Profession: patients.Profession,
  234. Phone: patients.Phone,
  235. HomeTelephone: patients.HomeTelephone,
  236. RelativePhone: patients.RelativePhone,
  237. RelativeRelations: patients.RelativeRelations,
  238. HomeAddress: patients.HomeAddress,
  239. WorkUnit: patients.WorkUnit,
  240. UnitAddress: patients.UnitAddress,
  241. Children: patients.Children,
  242. ReceivingDate: patients.ReceivingDate,
  243. IsHospitalFirstDialysis: patients.IsHospitalFirstDialysis,
  244. FirstDialysisDate: patients.FirstDialysisDate,
  245. FirstDialysisHospital: patients.FirstDialysisHospital,
  246. PredialysisCondition: patients.PredialysisCondition,
  247. PreHospitalDialysisFrequency: patients.PreHospitalDialysisFrequency,
  248. PreHospitalDialysisTimes: patients.PreHospitalDialysisTimes,
  249. HospitalFirstDialysisDate: patients.HospitalFirstDialysisDate,
  250. InductionPeriod: patients.InductionPeriod,
  251. InitialDialysis: patients.InitialDialysis,
  252. TotalDialysis: patients.TotalDialysis,
  253. AttendingDoctorId: patients.AttendingDoctorId,
  254. HeadNurseId: patients.HeadNurseId,
  255. Evaluate: patients.Evaluate,
  256. Diagnose: patients.Diagnose,
  257. Remark: patients.Remark,
  258. RegistrarsId: patients.RegistrarsId,
  259. Registrars: patients.Registrars,
  260. QrCode: patients.QrCode,
  261. BindingState: patients.BindingState,
  262. PatientComplains: patients.PatientComplains,
  263. PresentHistory: patients.PresentHistory,
  264. PastHistory: patients.PresentHistory,
  265. Temperature: patients.Temperature,
  266. Pulse: patients.Pulse,
  267. Respiratory: patients.Respiratory,
  268. Sbp: patients.SBP,
  269. Dbp: patients.DBP,
  270. Status: patients.Status,
  271. CreatedTime: patients.CreatedTime,
  272. UpdatedTime: patients.UpdatedTime,
  273. Nation: patients.Nation,
  274. NativePlace: patients.NativePlace,
  275. Age: patients.Age,
  276. InfectiousNextRecordTime: patients.InfectiousNextRecordTime,
  277. IsInfectious: patients.IsInfectious,
  278. RemindCycle: patients.RemindCycle,
  279. ResponseResult: patients.ResponseResult,
  280. IsOpenRemind: patients.IsOpenRemind,
  281. FirstTreatmentDate: patients.FirstTreatmentDate,
  282. DialysisAge: patients.DialysisAge,
  283. ExpenseKind: patients.ExpenseKind,
  284. TellPhone: patients.TellPhone,
  285. ContactName: patients.ContactName,
  286. BloodPatients: 1,
  287. SlowPatients: 0,
  288. MemberPatients: 0,
  289. EcommerPatients: "",
  290. BloodId: patients.ID,
  291. SlowId: 0,
  292. MemberId: 0,
  293. MemberFistdate: 0,
  294. MemberPatienttype: 0,
  295. MemberTreatement: 0,
  296. EquitmentId: "",
  297. UserSysBeforeCount: patient.UserSysBeforeCount,
  298. }
  299. err = service.CreatePatientsNew(&patientsNew)
  300. fmt.Print("创建失败", err)
  301. if len(record_date) > 0 {
  302. var recordTime int64
  303. timeLayout := "2006-01-02"
  304. loc, _ := time.LoadLocation("Local")
  305. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  306. if err != nil {
  307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  308. return
  309. }
  310. recordTime = theTime.Unix()
  311. inspections := make([]models.Inspection, 0)
  312. for _, item := range formItems {
  313. var inspection models.Inspection
  314. inspection.OrgId = adminUserInfo.CurrentOrgId
  315. inspection.PatientId = patient.ID
  316. inspection.ProjectId = item.ProjectId
  317. inspection.ItemId = item.ItemId
  318. inspection.ItemName = item.ItemName
  319. inspection.ProjectName = item.ProjectName
  320. inspection.InspectType = item.RangeType
  321. inspection.InspectValue = item.Value
  322. inspection.InspectDate = recordTime
  323. inspection.Status = 1
  324. inspection.CreatedTime = time.Now().Unix()
  325. inspection.UpdatedTime = time.Now().Unix()
  326. inspections = append(inspections, inspection)
  327. }
  328. err = service.CreatePatientInspection(inspections)
  329. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  330. var record_time int64
  331. switch remind_cycle {
  332. case 1: //1个月
  333. ts := time.Unix(infectiousRecord.InspectDate, 0)
  334. record_time = ts.AddDate(0, 1, 0).Unix()
  335. break
  336. case 2: //2个月
  337. ts := time.Unix(infectiousRecord.InspectDate, 0)
  338. record_time = ts.AddDate(0, 2, 0).Unix()
  339. break
  340. case 3: //3个月
  341. ts := time.Unix(infectiousRecord.InspectDate, 0)
  342. record_time = ts.AddDate(0, 3, 0).Unix()
  343. break
  344. case 4: //6个月
  345. ts := time.Unix(infectiousRecord.InspectDate, 0)
  346. record_time = ts.AddDate(0, 6, 0).Unix()
  347. break
  348. case 5: //12个月
  349. ts := time.Unix(infectiousRecord.InspectDate, 0)
  350. record_time = ts.AddDate(0, 12, 0).Unix()
  351. break
  352. }
  353. errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
  354. if errs != nil {
  355. utils.ErrorLog("更新日期出错:%v", errs)
  356. }
  357. }
  358. redis := service.RedisClient()
  359. defer redis.Close()
  360. redis.SAdd("sgj_patient:new_user_set", patient.UserId)
  361. c.ServeSuccessJSON(map[string]interface{}{
  362. "msg": "ok",
  363. })
  364. return
  365. }
  366. //EditPatient 修改
  367. func (c *PatientApiController) EditPatient() {
  368. id, _ := c.GetInt64("id", 0)
  369. record_date := c.GetString("record_date")
  370. is_infectious, _ := c.GetInt64("is_infectious")
  371. remind_cycle, _ := c.GetInt64("remind_cycle")
  372. if id <= 0 {
  373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  374. return
  375. }
  376. adminUserInfo := c.GetAdminUserInfo()
  377. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  378. if patient.ID == 0 {
  379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  380. return
  381. }
  382. contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "edit")
  383. if code > 0 {
  384. c.ServeFailJSONWithSGJErrorCode(code)
  385. return
  386. }
  387. thisPatientother, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
  388. if thisPatientother.ID > 0 && thisPatientother.ID != patient.ID {
  389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
  390. return
  391. }
  392. thisPatient, _ := service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
  393. if thisPatient.ID > 0 && thisPatient.ID != patient.ID {
  394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
  395. return
  396. }
  397. patient.UpdatedTime = time.Now().Unix()
  398. patient.IsInfectious = is_infectious
  399. patient.RemindCycle = remind_cycle
  400. err := service.UpdatePatient(&patient, contagions, diseases)
  401. if err != nil {
  402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
  403. return
  404. }
  405. //更新转归状态
  406. fmt.Println("病人id--------------------------------------------------------------", patient.ID)
  407. lapseto := models.PatientLapseto{
  408. LapsetoType: patient.Lapseto,
  409. LapsetoTime: time.Now().Unix(),
  410. UpdatedTime: time.Now().Unix(),
  411. }
  412. err = service.UpdatePatientLapseto(patient.ID, lapseto)
  413. fmt.Println("更新转归失败", err)
  414. if err != nil {
  415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
  416. return
  417. }
  418. patientsNew := models.XtPatientsNew{
  419. UserOrgId: patient.UserOrgId,
  420. UserId: patient.UserId,
  421. Avatar: patient.Avatar,
  422. PatientType: patient.PatientType,
  423. DialysisNo: patient.DialysisNo,
  424. AdmissionNumber: patient.AdmissionNumber,
  425. Source: patient.Source,
  426. Lapseto: patient.Lapseto,
  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. }
  495. // //更新病人ID获取新表病人ID
  496. err = service.UpdatepatientTwo(&patientsNew, id)
  497. fmt.Println("更新病人失败---------------------------------------", err)
  498. if len(record_date) > 0 {
  499. var recordTime int64
  500. timeLayout := "2006-01-02"
  501. loc, _ := time.LoadLocation("Local")
  502. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  503. if err != nil {
  504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  505. return
  506. }
  507. recordTime = theTime.Unix()
  508. inspections := make([]models.Inspection, 0)
  509. for _, item := range formItems {
  510. var inspection models.Inspection
  511. inspection.OrgId = adminUserInfo.CurrentOrgId
  512. inspection.PatientId = patient.ID
  513. inspection.ProjectId = item.ProjectId
  514. inspection.ItemId = item.ItemId
  515. inspection.ItemName = item.ItemName
  516. inspection.ProjectName = item.ProjectName
  517. inspection.InspectType = item.RangeType
  518. inspection.InspectValue = item.Value
  519. inspection.InspectDate = recordTime
  520. inspection.Status = 1
  521. inspection.CreatedTime = time.Now().Unix()
  522. inspection.UpdatedTime = time.Now().Unix()
  523. inspections = append(inspections, inspection)
  524. }
  525. err = service.CreatePatientInspection(inspections)
  526. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  527. var record_time int64
  528. switch remind_cycle {
  529. case 1: //1个月
  530. ts := time.Unix(infectiousRecord.InspectDate, 0)
  531. record_time = ts.AddDate(0, 1, 0).Unix()
  532. break
  533. case 2: //2个月
  534. ts := time.Unix(infectiousRecord.InspectDate, 0)
  535. record_time = ts.AddDate(0, 2, 0).Unix()
  536. break
  537. case 3: //3个月
  538. ts := time.Unix(infectiousRecord.InspectDate, 0)
  539. record_time = ts.AddDate(0, 3, 0).Unix()
  540. break
  541. case 4: //6个月
  542. ts := time.Unix(infectiousRecord.InspectDate, 0)
  543. record_time = ts.AddDate(0, 6, 0).Unix()
  544. break
  545. case 5: //12个月
  546. ts := time.Unix(infectiousRecord.InspectDate, 0)
  547. record_time = ts.AddDate(0, 12, 0).Unix()
  548. break
  549. }
  550. errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
  551. if errs != nil {
  552. utils.ErrorLog("更新日期出错:%v", errs)
  553. }
  554. }
  555. c.ServeSuccessJSON(map[string]interface{}{
  556. "msg": "ok",
  557. })
  558. return
  559. }
  560. func (c *PatientApiController) EditLapseto() {
  561. id, _ := c.GetInt64("id", 0)
  562. fmt.Println("id===========", id)
  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 adviceType == 1 {
  1072. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  1073. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  1074. advice.FrequencyType = frequency_type
  1075. }
  1076. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "string" {
  1077. day_count, _ := strconv.ParseInt(adviceNameM["day_count"].(string), 10, 64)
  1078. advice.DayCount = day_count
  1079. }
  1080. if adviceNameM["week_days"] != nil && reflect.TypeOf(adviceNameM["week_days"]).String() == "string" {
  1081. week_day, _ := adviceNameM["week_days"].(string)
  1082. advice.WeekDay = week_day
  1083. }
  1084. }
  1085. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "string" {
  1086. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  1087. advice.ExecutionFrequency = executionFrequency
  1088. }
  1089. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "[]interface {}" {
  1090. children := adviceNameM["children"].([]interface{})
  1091. if len(children) > 0 {
  1092. for _, childrenMap := range children {
  1093. childMap := childrenMap.(map[string]interface{})
  1094. var child models.GroupAdvice
  1095. child.Remark = Remark
  1096. child.AdviceType = adviceType
  1097. child.StartTime = StartTime
  1098. child.AdviceDate = AdviceDate
  1099. child.RecordDate = RecordDate
  1100. child.Status = 1
  1101. child.CreatedTime = time.Now().Unix()
  1102. child.UpdatedTime = time.Now().Unix()
  1103. child.StopState = 2
  1104. child.ExecutionState = 2
  1105. child.UserOrgId = adminUserInfo.CurrentOrgId
  1106. child.PatientId = patientInfo.ID
  1107. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  1108. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  1109. utils.ErrorLog("child advice_name")
  1110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1111. return
  1112. }
  1113. childAdviceName, _ := childMap["advice_name"].(string)
  1114. if len(childAdviceName) == 0 {
  1115. utils.ErrorLog("len(child advice_name) == 0")
  1116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1117. return
  1118. }
  1119. child.AdviceName = childAdviceName
  1120. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  1121. childAdviceDesc, _ := childMap["advice_desc"].(string)
  1122. child.AdviceDesc = childAdviceDesc
  1123. }
  1124. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  1125. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  1126. child.DrugSpec = childDrugSpec
  1127. }
  1128. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  1129. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  1130. child.DrugSpecUnit = childDrugSpecUnit
  1131. }
  1132. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  1133. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  1134. child.SingleDose = childSingleDose
  1135. }
  1136. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  1137. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  1138. child.SingleDoseUnit = childSingleDoseUnit
  1139. }
  1140. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  1141. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  1142. child.PrescribingNumber = childPrescribingNumber
  1143. }
  1144. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  1145. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  1146. child.PrescribingNumberUnit = childPrescribingNumberUnit
  1147. }
  1148. child.DeliveryWay = advice.DeliveryWay
  1149. child.ExecutionFrequency = advice.ExecutionFrequency
  1150. advice.Children = append(advice.Children, &child)
  1151. }
  1152. }
  1153. }
  1154. advices = append(advices, &advice)
  1155. }
  1156. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  1157. if err != nil {
  1158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1159. return
  1160. }
  1161. c.ServeSuccessJSON(map[string]interface{}{
  1162. "msg": "ok",
  1163. "advices": list,
  1164. })
  1165. return
  1166. }
  1167. func (c *PatientApiController) CreateDoctorAdvice() {
  1168. patient, _ := c.GetInt64("id", 0)
  1169. if patient <= 0 {
  1170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1171. return
  1172. }
  1173. adminUserInfo := c.GetAdminUserInfo()
  1174. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1175. if patientInfo.ID == 0 {
  1176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1177. return
  1178. }
  1179. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1180. if appRole.UserType == 3 {
  1181. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1182. if getPermissionErr != nil {
  1183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1184. return
  1185. } else if headNursePermission == nil {
  1186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1187. return
  1188. }
  1189. }
  1190. var advice models.DoctorAdvice
  1191. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  1192. if code > 0 {
  1193. c.ServeFailJSONWithSGJErrorCode(code)
  1194. return
  1195. }
  1196. if advice.ParentId > 0 {
  1197. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  1198. if old.ID == 0 || old.PatientId != patient {
  1199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  1200. return
  1201. }
  1202. if old.StopState == 1 || old.ExecutionState == 1 {
  1203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1204. return
  1205. }
  1206. if old.ParentId > 0 {
  1207. advice.ParentId = old.ParentId
  1208. }
  1209. advice.StartTime = old.StartTime
  1210. advice.AdviceDoctor = old.AdviceDoctor
  1211. advice.DeliveryWay = old.DeliveryWay
  1212. advice.ExecutionFrequency = old.ExecutionFrequency
  1213. advice.GroupNo = old.GroupNo
  1214. }
  1215. advice.Status = 1
  1216. advice.CreatedTime = time.Now().Unix()
  1217. advice.UpdatedTime = time.Now().Unix()
  1218. advice.StopState = 2
  1219. advice.ExecutionState = 2
  1220. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1221. advice.PatientId = patient
  1222. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1223. err := service.CreateDoctorAdvice(&advice)
  1224. if err != nil {
  1225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1226. return
  1227. }
  1228. c.ServeSuccessJSON(map[string]interface{}{
  1229. "msg": "ok",
  1230. "advice": advice,
  1231. })
  1232. return
  1233. }
  1234. func (c *PatientApiController) ExecGroupAdvice() {
  1235. groupNo, _ := c.GetInt64("groupno", 0)
  1236. executionTime := c.GetString("execution_time")
  1237. if groupNo <= 0 {
  1238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1239. return
  1240. }
  1241. if len(executionTime) <= 0 {
  1242. utils.ErrorLog("execution_time")
  1243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1244. return
  1245. }
  1246. adminUserInfo := c.GetAdminUserInfo()
  1247. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  1248. if advice.ID == 0 {
  1249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1250. return
  1251. }
  1252. if advice.ExecutionState == 1 {
  1253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1254. return
  1255. }
  1256. executionStaff := adminUserInfo.AdminUser.Id
  1257. // checker := adminUserInfo.AdminUser.Id
  1258. timeLayout := "2006-01-02 15:04:05"
  1259. loc, _ := time.LoadLocation("Local")
  1260. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1261. if err != nil {
  1262. utils.ErrorLog(err.Error())
  1263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1264. return
  1265. }
  1266. if advice.StartTime > theTime.Unix() {
  1267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1268. return
  1269. }
  1270. exceAdvice := models.DoctorAdvice{
  1271. ExecutionStaff: executionStaff,
  1272. ExecutionTime: theTime.Unix(),
  1273. // Checker: checker,
  1274. UpdatedTime: time.Now().Unix(),
  1275. }
  1276. err = service.ExceDoctorAdviceByGroupNo(&exceAdvice, groupNo, adminUserInfo.CurrentOrgId)
  1277. if err != nil {
  1278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1279. return
  1280. }
  1281. advice.ExecutionStaff = executionStaff
  1282. advice.ExecutionTime = theTime.Unix()
  1283. // advice.Checker = checker
  1284. c.ServeSuccessJSON(map[string]interface{}{
  1285. "msg": "ok",
  1286. "advice": advice,
  1287. })
  1288. return
  1289. }
  1290. func (c *PatientApiController) ExecDoctorAdvice() {
  1291. patient, _ := c.GetInt64("patient", 0)
  1292. id, _ := c.GetInt64("id", 0)
  1293. executionTime := c.GetString("execution_time")
  1294. if id <= 0 || patient <= 0 {
  1295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1296. return
  1297. }
  1298. if len(executionTime) <= 0 {
  1299. utils.ErrorLog("execution_time")
  1300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1301. return
  1302. }
  1303. adminUserInfo := c.GetAdminUserInfo()
  1304. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1305. if advice.ID == 0 || advice.PatientId != patient {
  1306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1307. return
  1308. }
  1309. if advice.ExecutionState == 1 {
  1310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1311. return
  1312. }
  1313. executionStaff := adminUserInfo.AdminUser.Id
  1314. // checker := adminUserInfo.AdminUser.Id
  1315. timeLayout := "2006-01-02 15:04:05"
  1316. loc, _ := time.LoadLocation("Local")
  1317. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1318. if err != nil {
  1319. utils.ErrorLog(err.Error())
  1320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1321. return
  1322. }
  1323. if advice.StartTime > theTime.Unix() {
  1324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1325. return
  1326. }
  1327. exceAdvice := models.DoctorAdvice{
  1328. ExecutionStaff: executionStaff,
  1329. ExecutionTime: theTime.Unix(),
  1330. // Checker: checker,
  1331. UpdatedTime: time.Now().Unix(),
  1332. }
  1333. if advice.ParentId > 0 {
  1334. err = service.ExceDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1335. } else {
  1336. err = service.ExceDoctorAdviceById(&exceAdvice, id, patient)
  1337. }
  1338. if err != nil {
  1339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1340. return
  1341. }
  1342. advice.ExecutionStaff = executionStaff
  1343. advice.ExecutionTime = theTime.Unix()
  1344. // advice.Checker = checker
  1345. c.ServeSuccessJSON(map[string]interface{}{
  1346. "msg": "ok",
  1347. "advice": advice,
  1348. })
  1349. return
  1350. }
  1351. func (c *PatientApiController) CheckGroupAdvice() {
  1352. groupno, _ := c.GetInt64("groupno", 0)
  1353. if groupno <= 0 {
  1354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1355. return
  1356. }
  1357. adminUserInfo := c.GetAdminUserInfo()
  1358. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupno)
  1359. if advice.ID == 0 {
  1360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1361. return
  1362. }
  1363. if advice.CheckState == 1 {
  1364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1365. return
  1366. }
  1367. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1369. return
  1370. }
  1371. checker := adminUserInfo.AdminUser.Id
  1372. theTime := time.Now()
  1373. exceAdvice := models.DoctorAdvice{
  1374. Checker: checker,
  1375. CheckTime: theTime.Unix(),
  1376. UpdatedTime: time.Now().Unix(),
  1377. }
  1378. var err error
  1379. err = service.CheckDoctorAdviceByGroupNo(&exceAdvice, groupno, adminUserInfo.CurrentOrgId)
  1380. if err != nil {
  1381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1382. return
  1383. }
  1384. // advice.ExecutionStaff = executionStaff
  1385. // advice.ExecutionTime = theTime.Unix()
  1386. advice.Checker = checker
  1387. advice.CheckTime = theTime.Unix()
  1388. c.ServeSuccessJSON(map[string]interface{}{
  1389. "msg": "ok",
  1390. "advice": advice,
  1391. })
  1392. return
  1393. }
  1394. func (c *PatientApiController) CheckDoctorAdvice() {
  1395. patient, _ := c.GetInt64("patient", 0)
  1396. id, _ := c.GetInt64("id", 0)
  1397. // executionTime := c.GetString("execution_time")
  1398. if id <= 0 || patient <= 0 {
  1399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1400. return
  1401. }
  1402. adminUserInfo := c.GetAdminUserInfo()
  1403. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1404. if advice.ID == 0 || advice.PatientId != patient {
  1405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1406. return
  1407. }
  1408. if advice.CheckState == 1 {
  1409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1410. return
  1411. }
  1412. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1414. return
  1415. }
  1416. // executionStaff := adminUserInfo.AdminUser.Id
  1417. checker := adminUserInfo.AdminUser.Id
  1418. // timeLayout := "2006-01-02 15:04:05"
  1419. // loc, _ := time.LoadLocation("Local")
  1420. // theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1421. // if err != nil {
  1422. // utils.ErrorLog(err.Error())
  1423. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1424. // return
  1425. // }
  1426. theTime := time.Now()
  1427. if advice.ExecutionTime > theTime.Unix() {
  1428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1429. return
  1430. }
  1431. exceAdvice := models.DoctorAdvice{
  1432. Checker: checker,
  1433. CheckTime: theTime.Unix(),
  1434. UpdatedTime: time.Now().Unix(),
  1435. }
  1436. var err error
  1437. if advice.ParentId > 0 {
  1438. err = service.CheckDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1439. } else {
  1440. err = service.CheckDoctorAdviceById(&exceAdvice, id, patient)
  1441. }
  1442. if err != nil {
  1443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1444. return
  1445. }
  1446. // advice.ExecutionStaff = executionStaff
  1447. // advice.ExecutionTime = theTime.Unix()
  1448. advice.Checker = checker
  1449. advice.CheckTime = theTime.Unix()
  1450. c.ServeSuccessJSON(map[string]interface{}{
  1451. "msg": "ok",
  1452. "advice": advice,
  1453. })
  1454. return
  1455. }
  1456. func (c *PatientApiController) UpdateDoctorAdvice() {
  1457. patient, _ := c.GetInt64("patient", 0)
  1458. id, _ := c.GetInt64("id", 0)
  1459. if id <= 0 || patient <= 0 {
  1460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1461. return
  1462. }
  1463. adminUserInfo := c.GetAdminUserInfo()
  1464. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1465. if advice.ID == 0 || advice.PatientId != patient {
  1466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1467. return
  1468. }
  1469. //if advice.AdviceType == 1 {
  1470. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeLongTimeAdviceNotCanntEdit)
  1471. // return
  1472. //}
  1473. if advice.StopState == 1 || advice.ExecutionState == 1 {
  1474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1475. return
  1476. }
  1477. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1478. //if appRole.UserType == 3 {
  1479. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1480. // if getPermissionErr != nil {
  1481. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1482. // return
  1483. // } else if headNursePermission == nil {
  1484. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1485. // return
  1486. // }
  1487. //}
  1488. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  1489. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCanotEditOtherAdvice)
  1490. // return
  1491. //}
  1492. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  1493. if code > 0 {
  1494. c.ServeFailJSONWithSGJErrorCode(code)
  1495. return
  1496. }
  1497. advice.UpdatedTime = time.Now().Unix()
  1498. advice.Modifier = adminUserInfo.AdminUser.Id
  1499. err := service.UpdateDoctorAdvice(&advice)
  1500. if err != nil {
  1501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1502. return
  1503. }
  1504. c.ServeSuccessJSON(map[string]interface{}{
  1505. "msg": "ok",
  1506. "advice": advice,
  1507. })
  1508. return
  1509. }
  1510. func (c *PatientApiController) StopGroupAdvice() {
  1511. groupNo, _ := c.GetInt64("groupno", 0)
  1512. if groupNo <= 0 {
  1513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1514. return
  1515. }
  1516. adminUserInfo := c.GetAdminUserInfo()
  1517. advice, _ := service.FindDoctorAdviceByGoroupNo(adminUserInfo.CurrentOrgId, groupNo)
  1518. if advice.ID == 0 {
  1519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1520. return
  1521. }
  1522. if advice.StopState == 1 || advice.ExecutionState == 1 {
  1523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1524. return
  1525. }
  1526. dataBody := make(map[string]interface{}, 0)
  1527. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1528. if err != nil {
  1529. utils.ErrorLog(err.Error())
  1530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1531. return
  1532. }
  1533. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  1534. utils.ErrorLog("stop_time")
  1535. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1536. return
  1537. }
  1538. stopTime, _ := dataBody["stop_time"].(string)
  1539. if len(stopTime) == 0 {
  1540. utils.ErrorLog("len(stop_time) == 0")
  1541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1542. return
  1543. }
  1544. timeLayout := "2006-01-02"
  1545. loc, _ := time.LoadLocation("Local")
  1546. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  1547. if err != nil {
  1548. utils.ErrorLog(err.Error())
  1549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1550. return
  1551. }
  1552. advice.StopTime = theTime.Unix()
  1553. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  1554. stopReason, _ := dataBody["stop_reason"].(string)
  1555. advice.StopReason = stopReason
  1556. }
  1557. advice.UpdatedTime = time.Now().Unix()
  1558. advice.StopDoctor = adminUserInfo.AdminUser.Id
  1559. advice.StopState = 1
  1560. err = service.StopGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, &advice)
  1561. if err != nil {
  1562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  1563. return
  1564. }
  1565. c.ServeSuccessJSON(map[string]interface{}{
  1566. "msg": "ok",
  1567. })
  1568. return
  1569. }
  1570. func (c *PatientApiController) StopDoctorAdvice() {
  1571. id, _ := c.GetInt64("id", 0)
  1572. if id <= 0 {
  1573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1574. return
  1575. }
  1576. adminUserInfo := c.GetAdminUserInfo()
  1577. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1578. //
  1579. //if appRole.UserType == 3 {
  1580. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1581. // if getPermissionErr != nil {
  1582. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1583. // return
  1584. // } else if headNursePermission == nil {
  1585. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1586. // return
  1587. // }
  1588. //}
  1589. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1590. if advice.ID == 0 {
  1591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1592. return
  1593. }
  1594. if advice.StopState == 1 || advice.ExecutionState == 1 {
  1595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1596. return
  1597. }
  1598. dataBody := make(map[string]interface{}, 0)
  1599. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1600. if err != nil {
  1601. utils.ErrorLog(err.Error())
  1602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1603. return
  1604. }
  1605. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  1606. utils.ErrorLog("stop_time")
  1607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1608. return
  1609. }
  1610. stopTime, _ := dataBody["stop_time"].(string)
  1611. if len(stopTime) == 0 {
  1612. utils.ErrorLog("len(stop_time) == 0")
  1613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1614. return
  1615. }
  1616. timeLayout := "2006-01-02"
  1617. loc, _ := time.LoadLocation("Local")
  1618. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  1619. if err != nil {
  1620. utils.ErrorLog(err.Error())
  1621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1622. return
  1623. }
  1624. advice.StopTime = theTime.Unix()
  1625. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  1626. stopReason, _ := dataBody["stop_reason"].(string)
  1627. advice.StopReason = stopReason
  1628. }
  1629. advice.UpdatedTime = time.Now().Unix()
  1630. advice.StopDoctor = adminUserInfo.AdminUser.Id
  1631. advice.StopState = 1
  1632. err = service.StopDoctorAdvice(&advice)
  1633. if err != nil {
  1634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  1635. return
  1636. }
  1637. c.ServeSuccessJSON(map[string]interface{}{
  1638. "msg": "ok",
  1639. "advice": advice,
  1640. })
  1641. return
  1642. }
  1643. func (c *PatientApiController) DeleteDoctorAdvice() {
  1644. id, _ := c.GetInt64("id", 0)
  1645. if id <= 0 {
  1646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1647. return
  1648. }
  1649. adminUserInfo := c.GetAdminUserInfo()
  1650. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1651. if advice.ID == 0 {
  1652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1653. return
  1654. }
  1655. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  1656. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1657. // return
  1658. //}
  1659. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1660. //
  1661. //if appRole.UserType == 3 {
  1662. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1663. // if getPermissionErr != nil {
  1664. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1665. // return
  1666. // } else if headNursePermission == nil {
  1667. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1668. // return
  1669. // }
  1670. //}
  1671. advice.UpdatedTime = time.Now().Unix()
  1672. advice.Status = 0
  1673. advice.Modifier = adminUserInfo.AdminUser.Id
  1674. err := service.DeleteDoctorAdvice(&advice)
  1675. if err != nil {
  1676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  1677. return
  1678. }
  1679. c.ServeSuccessJSON(map[string]interface{}{
  1680. "msg": "ok",
  1681. })
  1682. return
  1683. }
  1684. func (c *PatientApiController) DeleteGroupAdvice() {
  1685. groupNo, _ := c.GetInt64("groupno", 0)
  1686. if groupNo <= 0 {
  1687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1688. return
  1689. }
  1690. adminUserInfo := c.GetAdminUserInfo()
  1691. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  1692. if advice.ID == 0 {
  1693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1694. return
  1695. }
  1696. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1697. //if appRole.UserType == 3 {
  1698. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1699. // if getPermissionErr != nil {
  1700. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1701. // return
  1702. // } else if headNursePermission == nil {
  1703. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1704. // return
  1705. // }
  1706. //}
  1707. err := service.DeleteGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, adminUserInfo.AdminUser.Id)
  1708. if err != nil {
  1709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  1710. return
  1711. }
  1712. c.ServeSuccessJSON(map[string]interface{}{
  1713. "msg": "ok",
  1714. })
  1715. return
  1716. }
  1717. //GetDoctorAdvices 医嘱列表
  1718. func (c *PatientApiController) GetDoctorAdvices() {
  1719. id, _ := c.GetInt64("id", 0)
  1720. adviceType, _ := c.GetInt64("advice_type", 0)
  1721. stopType, _ := c.GetInt64("stop_state", 0)
  1722. startTime := c.GetString("start_time", "")
  1723. endTime := c.GetString("end_time", "")
  1724. keywords := c.GetString("keywords", "")
  1725. page, _ := c.GetInt64("page")
  1726. fmt.Println("page", page)
  1727. limit, _ := c.GetInt64("limit")
  1728. fmt.Println("limit", limit)
  1729. adminUserInfo := c.GetAdminUserInfo()
  1730. operatorIDs := make([]int64, 0)
  1731. timeLayout := "2006-01-02"
  1732. loc, _ := time.LoadLocation("Local")
  1733. var theStartTIme int64
  1734. if len(startTime) > 0 {
  1735. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  1736. if err != nil {
  1737. utils.ErrorLog(err.Error())
  1738. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1739. return
  1740. }
  1741. theStartTIme = theTime.Unix()
  1742. }
  1743. var theEndtTIme int64
  1744. if len(endTime) > 0 {
  1745. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  1746. if err != nil {
  1747. utils.ErrorLog(err.Error())
  1748. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1749. return
  1750. }
  1751. theEndtTIme = theTime.Unix()
  1752. }
  1753. advices, total, _ := service.GetDoctorAdviceListOne(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  1754. advicestwo, _, _ := service.GetDoctorAdviceListTwo(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  1755. if len(advices) > 0 {
  1756. for _, item := range advices {
  1757. if item.AdviceDoctor > 0 {
  1758. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  1759. }
  1760. if item.ExecutionStaff > 0 {
  1761. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  1762. }
  1763. if item.Checker > 0 {
  1764. operatorIDs = append(operatorIDs, item.Checker)
  1765. }
  1766. if item.StopDoctor > 0 {
  1767. operatorIDs = append(operatorIDs, item.StopDoctor)
  1768. }
  1769. }
  1770. }
  1771. //相关操作对应的操作人
  1772. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  1773. c.ServeSuccessJSON(map[string]interface{}{
  1774. "advices": advices,
  1775. "operators": operators,
  1776. "total": total,
  1777. "advicetwo": advicestwo,
  1778. })
  1779. return
  1780. }
  1781. func (c *PatientApiController) GetPatientSchedules() {
  1782. id, _ := c.GetInt64("id", 0)
  1783. if id <= 0 {
  1784. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1785. return
  1786. }
  1787. adminUserInfo := c.GetAdminUserInfo()
  1788. todayTime := time.Now().Format("2006-01-02")
  1789. timeLayout := "2006-01-02 15:04:05"
  1790. loc, _ := time.LoadLocation("Local")
  1791. var theStartTime int64
  1792. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  1793. theStartTime = theTime.Unix()
  1794. schedules, _ := service.GetPatientScheduleFormToday(adminUserInfo.CurrentOrgId, id, theStartTime)
  1795. if len(schedules) > 0 {
  1796. for index, item := range schedules {
  1797. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  1798. schedules[index].Week = int64(week)
  1799. }
  1800. }
  1801. c.ServeSuccessJSON(map[string]interface{}{
  1802. "schedules": schedules,
  1803. })
  1804. return
  1805. }
  1806. func (c *PatientApiController) GetPatientDialysisRecords() {
  1807. patientID, _ := c.GetInt64("patient_id", 0)
  1808. page, _ := c.GetInt64("page", 0)
  1809. limit, _ := c.GetInt64("limit", 0)
  1810. startTime := c.GetString("start_time", "")
  1811. endTime := c.GetString("end_time", "")
  1812. mode_id, _ := c.GetInt64("mode_id", 0)
  1813. if page <= 0 {
  1814. page = 1
  1815. }
  1816. if limit <= 0 {
  1817. limit = 10
  1818. }
  1819. if patientID <= 0 {
  1820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1821. return
  1822. }
  1823. timeLayout := "2006-01-02"
  1824. loc, _ := time.LoadLocation("Local")
  1825. var theStartTIme int64
  1826. if len(startTime) > 0 {
  1827. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  1828. if err != nil {
  1829. theStartTIme = 0
  1830. }
  1831. theStartTIme = theTime.Unix()
  1832. }
  1833. var theEndtTIme int64
  1834. if len(endTime) > 0 {
  1835. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  1836. if err != nil {
  1837. theEndtTIme = 0
  1838. }
  1839. theEndtTIme = theTime.Unix()
  1840. }
  1841. adminInfo := c.GetAdminUserInfo()
  1842. records, total, _ := service.GetPatientDialysisRecord(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  1843. c.ServeSuccessJSON(map[string]interface{}{
  1844. "total": total,
  1845. "records": records,
  1846. })
  1847. return
  1848. }
  1849. func (c *PatientApiController) ProEducation() {
  1850. patientID, _ := c.GetInt64("patient_id", 0)
  1851. page, _ := c.GetInt64("page", 0)
  1852. limit, _ := c.GetInt64("limit", 0)
  1853. startTime := c.GetString("start_time", "")
  1854. endTime := c.GetString("end_time", "")
  1855. if page <= 0 {
  1856. page = 1
  1857. }
  1858. if limit <= 0 {
  1859. limit = 10
  1860. }
  1861. if patientID <= 0 {
  1862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1863. return
  1864. }
  1865. timeLayout := "2006-01-02"
  1866. loc, _ := time.LoadLocation("Local")
  1867. var theStartTIme int64
  1868. if len(startTime) > 0 {
  1869. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  1870. if err != nil {
  1871. theStartTIme = 0
  1872. }
  1873. theStartTIme = theTime.Unix()
  1874. }
  1875. var theEndtTIme int64
  1876. if len(endTime) > 0 {
  1877. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  1878. if err != nil {
  1879. theEndtTIme = 0
  1880. }
  1881. theEndtTIme = theTime.Unix()
  1882. }
  1883. adminInfo := c.GetAdminUserInfo()
  1884. edus, total, _ := service.GetPatientTreatmentSummaryList(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme)
  1885. c.ServeSuccessJSON(map[string]interface{}{
  1886. "total": total,
  1887. "edus": edus,
  1888. })
  1889. return
  1890. }
  1891. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  1892. dataBody := make(map[string]interface{}, 0)
  1893. err := json.Unmarshal(data, &dataBody)
  1894. if err != nil {
  1895. utils.ErrorLog(err.Error())
  1896. code = enums.ErrorCodeParamWrong
  1897. return
  1898. }
  1899. timeLayout := "2006-01-02"
  1900. loc, _ := time.LoadLocation("Local")
  1901. isChild := false
  1902. if action == "create" {
  1903. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  1904. utils.ErrorLog("advice_type")
  1905. code = enums.ErrorCodeParamWrong
  1906. return
  1907. }
  1908. adviceType := int64(dataBody["advice_type"].(float64))
  1909. if adviceType != 1 && adviceType != 2 && adviceType != 3 {
  1910. utils.ErrorLog("advice_type != 1&&2")
  1911. code = enums.ErrorCodeParamWrong
  1912. return
  1913. }
  1914. advice.AdviceType = adviceType
  1915. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1916. utils.ErrorLog("advice_date")
  1917. code = enums.ErrorCodeParamWrong
  1918. return
  1919. }
  1920. adviceDate, _ := dataBody["advice_date"].(string)
  1921. if len(adviceDate) == 0 {
  1922. utils.ErrorLog("len(adviceDate) == 0")
  1923. code = enums.ErrorCodeParamWrong
  1924. return
  1925. }
  1926. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  1927. if err != nil {
  1928. utils.ErrorLog(err.Error())
  1929. code = enums.ErrorCodeParamWrong
  1930. return
  1931. }
  1932. advice.AdviceDate = theTime.Unix()
  1933. advice.RecordDate = theTime.Unix()
  1934. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  1935. parentId := int64(dataBody["parent_id"].(float64))
  1936. advice.ParentId = parentId
  1937. if parentId > 0 {
  1938. isChild = true
  1939. }
  1940. }
  1941. }
  1942. if !isChild {
  1943. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1944. utils.ErrorLog("start_time")
  1945. code = enums.ErrorCodeParamWrong
  1946. return
  1947. }
  1948. startTime, _ := dataBody["start_time"].(string)
  1949. if len(startTime) == 0 {
  1950. utils.ErrorLog("len(start_time) == 0")
  1951. code = enums.ErrorCodeParamWrong
  1952. return
  1953. }
  1954. theTime, err := time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  1955. if err != nil {
  1956. utils.ErrorLog(err.Error())
  1957. code = enums.ErrorCodeParamWrong
  1958. return
  1959. }
  1960. advice.StartTime = theTime.Unix()
  1961. // if dataBody["advice_doctor"] == nil || reflect.TypeOf(dataBody["advice_doctor"]).String() != "float64" {
  1962. // utils.ErrorLog("advice_doctor")
  1963. // code = enums.ErrorCodeParamWrong
  1964. // return
  1965. // }
  1966. // adviceDoctor := int64(dataBody["advice_doctor"].(float64))
  1967. // if adviceDoctor <= 0 {
  1968. // utils.ErrorLog("advice_doctor <=0")
  1969. // code = enums.ErrorCodeParamWrong
  1970. // return
  1971. // }
  1972. // advice.AdviceDoctor = adviceDoctor
  1973. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  1974. deliveryWay, _ := dataBody["delivery_way"].(string)
  1975. advice.DeliveryWay = deliveryWay
  1976. }
  1977. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  1978. executionFrequency, _ := dataBody["execution_frequency"].(string)
  1979. advice.ExecutionFrequency = executionFrequency
  1980. }
  1981. if advice.AdviceType == 1 && advice.ParentId == 0 {
  1982. if dataBody["frequency_type"] != nil || reflect.TypeOf(dataBody["frequency_type"]).String() == "float64" {
  1983. frequency_type := int64(dataBody["frequency_type"].(float64))
  1984. advice.FrequencyType = frequency_type
  1985. }
  1986. if dataBody["day_count"] != nil || reflect.TypeOf(dataBody["day_count"]).String() == "string" {
  1987. day_count, _ := strconv.ParseInt(dataBody["day_count"].(string), 10, 64)
  1988. advice.DayCount = day_count
  1989. }
  1990. if dataBody["week_days"] != nil && reflect.TypeOf(dataBody["week_days"]).String() == "string" {
  1991. week_day, _ := dataBody["week_days"].(string)
  1992. advice.WeekDay = week_day
  1993. }
  1994. }
  1995. }
  1996. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  1997. utils.ErrorLog("advice_name")
  1998. code = enums.ErrorCodeParamWrong
  1999. return
  2000. }
  2001. adviceName, _ := dataBody["advice_name"].(string)
  2002. if len(adviceName) == 0 {
  2003. utils.ErrorLog("len(advice_name) == 0")
  2004. code = enums.ErrorCodeParamWrong
  2005. return
  2006. }
  2007. advice.AdviceName = adviceName
  2008. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  2009. adviceDsc, _ := dataBody["advice_desc"].(string)
  2010. advice.AdviceDesc = adviceDsc
  2011. }
  2012. if dataBody["dialysis_order_id"] != nil && reflect.TypeOf(dataBody["dialysis_order_id"]).String() == "float64" {
  2013. dialysisOrderId, _ := dataBody["dialysis_order_id"].(float64)
  2014. advice.DialysisOrderId = int64(dialysisOrderId)
  2015. }
  2016. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  2017. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  2018. advice.SingleDose = singleDose
  2019. }
  2020. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  2021. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  2022. advice.SingleDoseUnit = singleDoseUnit
  2023. }
  2024. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  2025. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  2026. advice.DrugSpec = drugSpec
  2027. }
  2028. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  2029. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  2030. advice.DrugSpecUnit = drugSpecUnit
  2031. }
  2032. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  2033. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  2034. advice.PrescribingNumber = prescribingNumber
  2035. }
  2036. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  2037. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  2038. advice.PrescribingNumberUnit = prescribingNumberUnit
  2039. }
  2040. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2041. remark, _ := dataBody["remark"].(string)
  2042. advice.Remark = remark
  2043. }
  2044. return
  2045. }
  2046. func solutionFormData(solution *models.DialysisSolution, data []byte) (code int) {
  2047. dataBody := make(map[string]interface{}, 0)
  2048. err := json.Unmarshal(data, &dataBody)
  2049. utils.InfoLog(string(data))
  2050. if err != nil {
  2051. utils.ErrorLog(err.Error())
  2052. code = enums.ErrorCodeParamWrong
  2053. return
  2054. }
  2055. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2056. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2057. solution.DialysisDuration = dialysisDuration
  2058. }
  2059. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  2060. replacementWay := int64(dataBody["replacement_way"].(float64))
  2061. solution.ReplacementWay = replacementWay
  2062. }
  2063. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  2064. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  2065. solution.BloodFlowVolume = bloodFlowVolume
  2066. }
  2067. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  2068. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  2069. solution.HemodialysisMachine = hemodialysisMachine
  2070. }
  2071. if dataBody["blood_filter"] != nil && reflect.TypeOf(dataBody["blood_filter"]).String() == "float64" {
  2072. bloodFilter := int64(dataBody["blood_filter"].(float64))
  2073. solution.BloodFilter = bloodFilter
  2074. }
  2075. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  2076. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  2077. solution.PerfusionApparatus = perfusionApparatus
  2078. }
  2079. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  2080. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  2081. solution.DialysateFlow = dialysateFlow
  2082. }
  2083. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  2084. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  2085. solution.Kalium = kalium
  2086. }
  2087. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  2088. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  2089. solution.Sodium = sodium
  2090. }
  2091. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  2092. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  2093. solution.Calcium = calcium
  2094. }
  2095. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  2096. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  2097. solution.Bicarbonate = bicarbonate
  2098. }
  2099. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  2100. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  2101. solution.Anticoagulant = anticoagulant
  2102. }
  2103. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  2104. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  2105. solution.AnticoagulantShouji = anticoagulantShouji
  2106. }
  2107. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  2108. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  2109. solution.AnticoagulantWeichi = anticoagulantWeichi
  2110. }
  2111. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  2112. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  2113. solution.AnticoagulantZongliang = anticoagulantZongliang
  2114. }
  2115. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  2116. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  2117. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  2118. }
  2119. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  2120. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  2121. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  2122. }
  2123. return
  2124. }
  2125. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  2126. dataBody := make(map[string]interface{}, 0)
  2127. err := json.Unmarshal(data, &dataBody)
  2128. utils.InfoLog(string(data))
  2129. if err != nil {
  2130. utils.ErrorLog(err.Error())
  2131. code = enums.ErrorCodeParamWrong
  2132. return
  2133. }
  2134. if method == "create" {
  2135. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  2136. utils.ErrorLog("mode")
  2137. code = enums.ErrorCodeParamWrong
  2138. return
  2139. }
  2140. mode := int64(dataBody["mode"].(float64))
  2141. if mode <= 0 {
  2142. utils.ErrorLog("mode <= 0")
  2143. code = enums.ErrorCodeParamWrong
  2144. return
  2145. }
  2146. solution.ModeId = mode
  2147. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  2148. utils.ErrorLog("mode_name")
  2149. code = enums.ErrorCodeParamWrong
  2150. return
  2151. }
  2152. modeName, _ := dataBody["mode_name"].(string)
  2153. if len(modeName) == 0 {
  2154. utils.ErrorLog("len(mode_name) == 0")
  2155. code = enums.ErrorCodeParamWrong
  2156. return
  2157. }
  2158. solution.ModeName = modeName
  2159. solution.Name = modeName
  2160. }
  2161. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2162. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2163. solution.DialysisDuration = dialysisDuration
  2164. }
  2165. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  2166. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  2167. solution.TargetUltrafiltration = targetUltrafiltration
  2168. }
  2169. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  2170. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  2171. solution.DialysateFormulation = dialysateFormulation
  2172. }
  2173. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  2174. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  2175. solution.DialysisDurationHour = int64(dialysisDurationHour)
  2176. }
  2177. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  2178. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  2179. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  2180. }
  2181. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  2182. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  2183. solution.HemodialysisMachine = hemodialysisMachine
  2184. }
  2185. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  2186. dialyzer := int64(dataBody["dialyzer"].(float64))
  2187. solution.Dialyzer = dialyzer
  2188. }
  2189. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  2190. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  2191. solution.PerfusionApparatus = perfusionApparatus
  2192. }
  2193. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  2194. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  2195. solution.BloodFlowVolume = bloodFlowVolume
  2196. }
  2197. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  2198. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  2199. solution.Dewater = dewater
  2200. }
  2201. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  2202. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  2203. solution.DisplaceLiqui = displaceLiqui
  2204. }
  2205. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  2206. replacementWay := int64(dataBody["replacement_way"].(float64))
  2207. solution.ReplacementWay = replacementWay
  2208. }
  2209. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  2210. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  2211. solution.Anticoagulant = anticoagulant
  2212. }
  2213. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  2214. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  2215. solution.AnticoagulantShouji = anticoagulantShouji
  2216. }
  2217. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  2218. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  2219. solution.AnticoagulantWeichi = anticoagulantWeichi
  2220. }
  2221. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  2222. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  2223. solution.AnticoagulantZongliang = anticoagulantZongliang
  2224. }
  2225. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  2226. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  2227. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  2228. }
  2229. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  2230. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  2231. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  2232. }
  2233. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  2234. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  2235. solution.Kalium = kalium
  2236. }
  2237. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  2238. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  2239. solution.Sodium = sodium
  2240. }
  2241. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  2242. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  2243. solution.Calcium = calcium
  2244. }
  2245. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  2246. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  2247. solution.Bicarbonate = bicarbonate
  2248. }
  2249. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  2250. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  2251. solution.Glucose = glucose
  2252. }
  2253. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  2254. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  2255. // solution.DryWeight = dryWeight
  2256. // }
  2257. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  2258. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  2259. solution.DialysateFlow = dialysateFlow
  2260. }
  2261. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  2262. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  2263. solution.DialysateTemperature = dialysateTemperature
  2264. }
  2265. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  2266. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  2267. solution.Conductivity = conductivity
  2268. }
  2269. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  2270. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  2271. solution.ReplacementTotal = replacementTotal
  2272. }
  2273. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  2274. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  2275. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  2276. }
  2277. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  2278. body_fluid := int64(dataBody["body_fluid"].(float64))
  2279. solution.BodyFluid = body_fluid
  2280. }
  2281. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  2282. body_fluid_other := dataBody["body_fluid_other"].(string)
  2283. solution.BodyFluidOther = body_fluid_other
  2284. }
  2285. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  2286. special_medicine := int64(dataBody["special_medicine"].(float64))
  2287. solution.SpecialMedicine = special_medicine
  2288. }
  2289. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  2290. special_medicine_other := dataBody["special_medicine_other"].(string)
  2291. solution.SpecialMedicineOther = special_medicine_other
  2292. }
  2293. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  2294. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  2295. solution.DisplaceLiquiPart = displace_liqui_part
  2296. }
  2297. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  2298. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  2299. solution.DisplaceLiquiValue = displace_liqui_value
  2300. }
  2301. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  2302. blood_access := int64(dataBody["blood_access"].(float64))
  2303. solution.BloodAccess = blood_access
  2304. }
  2305. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  2306. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  2307. solution.Ultrafiltration = ultrafiltration
  2308. }
  2309. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  2310. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  2311. solution.TargetKtv = target_ktv
  2312. }
  2313. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2314. remark := dataBody["remark"].(string)
  2315. solution.Remark = remark
  2316. }
  2317. return
  2318. }
  2319. func childSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  2320. dataBody := make(map[string]interface{}, 0)
  2321. err := json.Unmarshal(data, &dataBody)
  2322. utils.InfoLog(string(data))
  2323. if err != nil {
  2324. utils.ErrorLog(err.Error())
  2325. code = enums.ErrorCodeParamWrong
  2326. return
  2327. }
  2328. if method == "create" {
  2329. if dataBody["parent_id"] == nil || reflect.TypeOf(dataBody["parent_id"]).String() != "float64" {
  2330. utils.ErrorLog("parent_id")
  2331. code = enums.ErrorCodeParamWrong
  2332. return
  2333. }
  2334. parentID := int64(dataBody["parent_id"].(float64))
  2335. if parentID <= 0 {
  2336. utils.ErrorLog("parentID <= 0")
  2337. code = enums.ErrorCodeParamWrong
  2338. return
  2339. }
  2340. solution.ParentId = parentID
  2341. if dataBody["sub_name"] == nil || reflect.TypeOf(dataBody["sub_name"]).String() != "string" {
  2342. utils.ErrorLog("sub_name")
  2343. code = enums.ErrorCodeParamWrong
  2344. return
  2345. }
  2346. subName, _ := dataBody["sub_name"].(string)
  2347. if len(subName) == 0 {
  2348. utils.ErrorLog("len(sub_name) == 0")
  2349. code = enums.ErrorCodeParamWrong
  2350. return
  2351. }
  2352. solution.SubName = subName
  2353. }
  2354. if dataBody["initiate_mode"] == nil || reflect.TypeOf(dataBody["initiate_mode"]).String() != "float64" {
  2355. utils.ErrorLog("initiate_mode")
  2356. code = enums.ErrorCodeParamWrong
  2357. return
  2358. }
  2359. initiateMode := int64(dataBody["initiate_mode"].(float64))
  2360. if initiateMode != 1 && initiateMode != 2 {
  2361. utils.ErrorLog("initiateMode != 1 && initiateMode != 2")
  2362. code = enums.ErrorCodeParamWrong
  2363. return
  2364. }
  2365. solution.InitiateMode = initiateMode
  2366. if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  2367. utils.ErrorLog("doctor")
  2368. code = enums.ErrorCodeParamWrong
  2369. return
  2370. }
  2371. doctor := int64(dataBody["doctor"].(float64))
  2372. if doctor <= 0 {
  2373. utils.ErrorLog("doctor <= 0")
  2374. code = enums.ErrorCodeParamWrong
  2375. return
  2376. }
  2377. solution.Doctor = doctor
  2378. return
  2379. }
  2380. func patientFormData(patient *models.Patients, data []byte, method string) (contagions []int64, diseases []int64, code int, formItems []*models.FormItem) {
  2381. patientBody := make(map[string]interface{}, 0)
  2382. err := json.Unmarshal(data, &patientBody)
  2383. if err != nil {
  2384. utils.ErrorLog(err.Error())
  2385. code = enums.ErrorCodeParamWrong
  2386. return
  2387. }
  2388. if patientBody["formItem"] != nil && reflect.TypeOf(patientBody["formItem"]).String() == "[]interface {}" {
  2389. formItem, _ := patientBody["formItem"].([]interface{})
  2390. if len(formItem) > 0 {
  2391. for _, item := range formItem {
  2392. items := item.(map[string]interface{})
  2393. project_name, _ := items["project_name"].(string)
  2394. fmt.Println(project_name)
  2395. range_type := int64(items["range_type"].(float64))
  2396. fmt.Println(range_type)
  2397. project_id := int64(items["project_id"].(float64))
  2398. fmt.Println(project_id)
  2399. item_id := int64(items["item_id"].(float64))
  2400. fmt.Println(item_id)
  2401. item, _ := items["item"].(string)
  2402. fmt.Println(items["item"].(string))
  2403. item_name, _ := items["item_name"].(string)
  2404. fmt.Println(item_name)
  2405. value, _ := items["value"].(string)
  2406. fmt.Println(items["value"].(string))
  2407. var form models.FormItem
  2408. form.ProjectName = project_name
  2409. form.RangeType = range_type
  2410. form.ProjectId = project_id
  2411. form.ItemId = item_id
  2412. form.Item = item
  2413. form.ItemName = item_name
  2414. form.Value = value
  2415. formItems = append(formItems, &form)
  2416. }
  2417. }
  2418. }
  2419. if patientBody["avatar"] == nil || reflect.TypeOf(patientBody["avatar"]).String() != "string" {
  2420. utils.ErrorLog("avatar")
  2421. code = enums.ErrorCodeParamWrong
  2422. return
  2423. }
  2424. avatar, _ := patientBody["avatar"].(string)
  2425. if len(avatar) == 0 {
  2426. utils.ErrorLog("len(avatar) == 0")
  2427. code = enums.ErrorCodeParamWrong
  2428. return
  2429. }
  2430. patient.Avatar = avatar
  2431. if patientBody["name"] == nil || reflect.TypeOf(patientBody["name"]).String() != "string" {
  2432. utils.ErrorLog("name")
  2433. code = enums.ErrorCodeParamWrong
  2434. return
  2435. }
  2436. name, _ := patientBody["name"].(string)
  2437. if len(name) == 0 {
  2438. utils.ErrorLog("len(name) == 0")
  2439. code = enums.ErrorCodeParamWrong
  2440. return
  2441. }
  2442. patient.Name = name
  2443. if patientBody["alias"] != nil && reflect.TypeOf(patientBody["alias"]).String() == "string" {
  2444. alias := patientBody["alias"].(string)
  2445. patient.Alias = alias
  2446. }
  2447. if patientBody["nation"] != nil && reflect.TypeOf(patientBody["nation"]).String() == "string" {
  2448. nation := patientBody["nation"].(string)
  2449. patient.Nation = nation
  2450. }
  2451. if patientBody["native_place"] != nil && reflect.TypeOf(patientBody["native_place"]).String() == "string" {
  2452. native_place := patientBody["native_place"].(string)
  2453. patient.NativePlace = native_place
  2454. }
  2455. if patientBody["idCardNo"] == nil || reflect.TypeOf(patientBody["idCardNo"]).String() != "string" {
  2456. utils.ErrorLog("idCardNo")
  2457. code = enums.ErrorCodeParamWrong
  2458. return
  2459. }
  2460. idCardNo, _ := patientBody["idCardNo"].(string)
  2461. if len(idCardNo) == 0 {
  2462. utils.ErrorLog("len(idCardNo) == 0")
  2463. code = enums.ErrorCodeParamWrong
  2464. return
  2465. }
  2466. patient.IdCardNo = idCardNo
  2467. patient.PatientType = 1
  2468. if patientBody["dialysisNo"] == nil || reflect.TypeOf(patientBody["dialysisNo"]).String() != "string" {
  2469. utils.ErrorLog("dialysisNo")
  2470. code = enums.ErrorCodeParamWrong
  2471. return
  2472. }
  2473. dialysisNo, _ := patientBody["dialysisNo"].(string)
  2474. if len(dialysisNo) == 0 {
  2475. utils.ErrorLog("len(dialysisNo) == 0")
  2476. code = enums.ErrorCodeParamWrong
  2477. return
  2478. }
  2479. patient.DialysisNo = dialysisNo
  2480. // }
  2481. if patientBody["lapseto"] == nil || reflect.TypeOf(patientBody["lapseto"]).String() != "float64" {
  2482. utils.ErrorLog("lapseto")
  2483. code = enums.ErrorCodeParamWrong
  2484. return
  2485. }
  2486. lapseto := int64(patientBody["lapseto"].(float64))
  2487. if lapseto <= 0 {
  2488. utils.ErrorLog("lapseto == 0")
  2489. code = enums.ErrorCodeParamWrong
  2490. return
  2491. }
  2492. patient.Lapseto = lapseto
  2493. if patientBody["gender"] == nil || reflect.TypeOf(patientBody["gender"]).String() != "float64" {
  2494. utils.ErrorLog("gender")
  2495. code = enums.ErrorCodeParamWrong
  2496. return
  2497. }
  2498. gender := int64(patientBody["gender"].(float64))
  2499. if gender <= 0 {
  2500. utils.ErrorLog("gender <= 0")
  2501. code = enums.ErrorCodeParamWrong
  2502. return
  2503. }
  2504. patient.Gender = gender
  2505. if patientBody["response_result"] != nil && reflect.TypeOf(patientBody["response_result"]).String() == "string" {
  2506. response_result := patientBody["response_result"].(string)
  2507. patient.ResponseResult = response_result
  2508. }
  2509. if patientBody["age"] == nil || reflect.TypeOf(patientBody["age"]).String() != "float64" {
  2510. utils.ErrorLog("age")
  2511. code = enums.ErrorCodeParamWrong
  2512. return
  2513. }
  2514. age := int64(patientBody["age"].(float64))
  2515. patient.Age = age
  2516. if patientBody["user_sys_before_count"] != nil || reflect.TypeOf(patientBody["user_sys_before_count"]).String() == "string" {
  2517. user_sys_before_count := patientBody["user_sys_before_count"].(string)
  2518. count, _ := strconv.ParseInt(user_sys_before_count, 10, 64)
  2519. patient.UserSysBeforeCount = count
  2520. }
  2521. timeLayout := "2006-01-02"
  2522. loc, _ := time.LoadLocation("Local")
  2523. if patientBody["birth"] == nil || reflect.TypeOf(patientBody["birth"]).String() != "string" {
  2524. utils.ErrorLog("birth")
  2525. code = enums.ErrorCodeParamWrong
  2526. return
  2527. }
  2528. birth, _ := patientBody["birth"].(string)
  2529. if len(birth) == 0 {
  2530. utils.ErrorLog("len(birth) == 0")
  2531. code = enums.ErrorCodeParamWrong
  2532. return
  2533. }
  2534. birthTime, err := time.ParseInLocation(timeLayout, birth, loc)
  2535. if err != nil {
  2536. utils.ErrorLog("birthTime")
  2537. code = enums.ErrorCodeParamWrong
  2538. return
  2539. }
  2540. patient.Birthday = birthTime.Unix()
  2541. if patientBody["height"] != nil && reflect.TypeOf(patientBody["height"]).String() == "string" {
  2542. height, _ := strconv.ParseInt(patientBody["height"].(string), 10, 64)
  2543. patient.Height = height
  2544. }
  2545. if patientBody["maritalStatus"] != nil && reflect.TypeOf(patientBody["maritalStatus"]).String() == "float64" {
  2546. maritalStatus := int64(patientBody["maritalStatus"].(float64))
  2547. patient.MaritalStatus = maritalStatus
  2548. }
  2549. if patientBody["children"] != nil && reflect.TypeOf(patientBody["children"]).String() == "string" {
  2550. children, _ := strconv.ParseInt(patientBody["children"].(string), 10, 64)
  2551. patient.Children = children
  2552. }
  2553. if patientBody["admissionNumber"] != nil && reflect.TypeOf(patientBody["admissionNumber"]).String() == "string" {
  2554. admissionNumber, _ := patientBody["admissionNumber"].(string)
  2555. patient.AdmissionNumber = admissionNumber
  2556. }
  2557. if patientBody["reimbursementWayID"] != nil && reflect.TypeOf(patientBody["reimbursementWayID"]).String() == "float64" {
  2558. reimbursementWayID := int64(patientBody["reimbursementWayID"].(float64))
  2559. patient.ReimbursementWayId = reimbursementWayID
  2560. }
  2561. if patientBody["healthCareNo"] != nil && reflect.TypeOf(patientBody["healthCareNo"]).String() == "string" {
  2562. healthCareNo := patientBody["healthCareNo"].(string)
  2563. patient.HealthCareNo = healthCareNo
  2564. }
  2565. if patientBody["phone"] == nil || reflect.TypeOf(patientBody["phone"]).String() != "string" {
  2566. utils.ErrorLog("phone")
  2567. code = enums.ErrorCodeParamWrong
  2568. return
  2569. }
  2570. phone := patientBody["phone"].(string)
  2571. if len(phone) == 0 {
  2572. utils.ErrorLog("len(phone) == 0")
  2573. code = enums.ErrorCodeParamWrong
  2574. return
  2575. }
  2576. if !utils.CheckMobile(phone) {
  2577. utils.ErrorLog("!phone")
  2578. code = enums.ErrorCodeMobileFormat
  2579. return
  2580. }
  2581. patient.Phone = phone
  2582. if patientBody["homeTelephone"] != nil && reflect.TypeOf(patientBody["homeTelephone"]).String() == "string" {
  2583. homeTelephone := patientBody["homeTelephone"].(string)
  2584. patient.HomeTelephone = homeTelephone
  2585. }
  2586. if patientBody["relative_phone"] != nil && reflect.TypeOf(patientBody["relative_phone"]).String() == "string" {
  2587. relativePhone := patientBody["relative_phone"].(string)
  2588. patient.RelativePhone = relativePhone
  2589. }
  2590. if patientBody["relative_relations"] != nil && reflect.TypeOf(patientBody["relative_relations"]).String() == "string" {
  2591. relativeRelations := patientBody["relative_relations"].(string)
  2592. patient.RelativeRelations = relativeRelations
  2593. }
  2594. if patientBody["homeAddress"] != nil && reflect.TypeOf(patientBody["homeAddress"]).String() == "string" {
  2595. homeAddress := patientBody["homeAddress"].(string)
  2596. patient.HomeAddress = homeAddress
  2597. }
  2598. if patientBody["work"] != nil && reflect.TypeOf(patientBody["work"]).String() == "string" {
  2599. work := patientBody["work"].(string)
  2600. patient.WorkUnit = work
  2601. }
  2602. if patientBody["unit_address"] != nil && reflect.TypeOf(patientBody["unit_address"]).String() == "string" {
  2603. unitAddress := patientBody["unit_address"].(string)
  2604. patient.UnitAddress = unitAddress
  2605. }
  2606. if patientBody["profession"] != nil && reflect.TypeOf(patientBody["profession"]).String() == "float64" {
  2607. profession := int64(patientBody["profession"].(float64))
  2608. patient.Profession = profession
  2609. }
  2610. if patientBody["education"] != nil && reflect.TypeOf(patientBody["education"]).String() == "float64" {
  2611. education := int64(patientBody["education"].(float64))
  2612. patient.EducationLevel = education
  2613. }
  2614. if patientBody["source"] == nil || reflect.TypeOf(patientBody["source"]).String() != "float64" {
  2615. utils.ErrorLog("source")
  2616. code = enums.ErrorCodeParamWrong
  2617. return
  2618. }
  2619. source := int64(patientBody["source"].(float64))
  2620. if source <= 0 {
  2621. utils.ErrorLog("source <= 0")
  2622. code = enums.ErrorCodeParamWrong
  2623. return
  2624. }
  2625. patient.Source = source
  2626. if patientBody["is_hospital_first_dialysis"] != nil && reflect.TypeOf(patientBody["is_hospital_first_dialysis"]).String() == "float64" {
  2627. isHospitalFirstDialysis := int64(patientBody["is_hospital_first_dialysis"].(float64))
  2628. patient.IsHospitalFirstDialysis = isHospitalFirstDialysis
  2629. }
  2630. if patientBody["firstDialysisDate"] != nil && reflect.TypeOf(patientBody["firstDialysisDate"]).String() == "string" {
  2631. firstDialysisDate := patientBody["firstDialysisDate"].(string)
  2632. firstDialysisDateTime, err := time.ParseInLocation(timeLayout, firstDialysisDate, loc)
  2633. if err == nil {
  2634. patient.FirstDialysisDate = firstDialysisDateTime.Unix()
  2635. }
  2636. }
  2637. if patientBody["first_dialysis_hospital"] != nil && reflect.TypeOf(patientBody["first_dialysis_hospital"]).String() == "string" {
  2638. firstDialysisHospital := patientBody["first_dialysis_hospital"].(string)
  2639. patient.FirstDialysisHospital = firstDialysisHospital
  2640. }
  2641. if patientBody["predialysis_condition"] != nil && reflect.TypeOf(patientBody["predialysis_condition"]).String() == "[]interface {}" {
  2642. thePredialysisCondition, _ := patientBody["predialysis_condition"].([]interface{})
  2643. if len(thePredialysisCondition) > 0 {
  2644. conditions := make([]string, 0)
  2645. for _, item := range thePredialysisCondition {
  2646. if reflect.TypeOf(item).String() != "string" {
  2647. continue
  2648. }
  2649. condition := item.(string)
  2650. if len(condition) > 0 {
  2651. conditions = append(conditions, condition)
  2652. }
  2653. }
  2654. patient.PredialysisCondition = strings.Join(conditions, ",")
  2655. }
  2656. }
  2657. if patientBody["pre_hospital_dialysis_frequency"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_frequency"]).String() == "string" {
  2658. preHospitalDialysisFrequency := patientBody["pre_hospital_dialysis_frequency"].(string)
  2659. patient.PreHospitalDialysisFrequency = preHospitalDialysisFrequency
  2660. }
  2661. if patientBody["pre_hospital_dialysis_times"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_times"]).String() == "string" {
  2662. preHospitalDialysisTimes, _ := strconv.ParseInt(patientBody["pre_hospital_dialysis_times"].(string), 10, 64)
  2663. patient.PreHospitalDialysisTimes = preHospitalDialysisTimes
  2664. }
  2665. if patientBody["hospital_first_dialysis_date"] != nil && reflect.TypeOf(patientBody["hospital_first_dialysis_date"]).String() == "string" {
  2666. hospitalFirstDialysisDate := patientBody["hospital_first_dialysis_date"].(string)
  2667. hospitalFirstDialysisDateTime, err := time.ParseInLocation(timeLayout, hospitalFirstDialysisDate, loc)
  2668. if err == nil {
  2669. patient.HospitalFirstDialysisDate = hospitalFirstDialysisDateTime.Unix()
  2670. }
  2671. }
  2672. if patientBody["partition"] != nil && reflect.TypeOf(patientBody["partition"]).String() == "float64" {
  2673. partition := int64(patientBody["partition"].(float64))
  2674. patient.PartitionId = partition
  2675. }
  2676. if patientBody["bed"] != nil && reflect.TypeOf(patientBody["bed"]).String() == "string" {
  2677. bed, _ := strconv.ParseInt(patientBody["bed"].(string), 10, 64)
  2678. patient.BedId = bed
  2679. }
  2680. if patientBody["healthCareDueDate"] != nil && reflect.TypeOf(patientBody["healthCareDueDate"]).String() == "string" {
  2681. healthCareDueDate := patientBody["healthCareDueDate"].(string)
  2682. healthCareDueDateTime, err := time.ParseInLocation(timeLayout, healthCareDueDate, loc)
  2683. if err == nil {
  2684. patient.HealthCareDueDate = healthCareDueDateTime.Unix()
  2685. }
  2686. }
  2687. if patientBody["blood"] != nil && reflect.TypeOf(patientBody["blood"]).String() == "float64" {
  2688. blood := int64(patientBody["blood"].(float64))
  2689. patient.BloodType = blood
  2690. }
  2691. if patientBody["rh"] != nil && reflect.TypeOf(patientBody["rh"]).String() == "float64" {
  2692. rh := int64(patientBody["rh"].(float64))
  2693. patient.Rh = rh
  2694. }
  2695. if patientBody["healthCareDueAlertDate"] != nil && reflect.TypeOf(patientBody["healthCareDueAlertDate"]).String() == "string" {
  2696. healthCareDueAlertDate := patientBody["healthCareDueAlertDate"].(string)
  2697. healthCareDueAlertDateTime, err := time.ParseInLocation(timeLayout, healthCareDueAlertDate, loc)
  2698. if err == nil {
  2699. patient.HealthCareDueAlertDate = healthCareDueAlertDateTime.Unix()
  2700. }
  2701. }
  2702. if patientBody["receivingDate"] != nil && reflect.TypeOf(patientBody["receivingDate"]).String() == "string" {
  2703. receivingDate := patientBody["receivingDate"].(string)
  2704. receivingDateTime, err := time.ParseInLocation(timeLayout, receivingDate, loc)
  2705. if err == nil {
  2706. patient.ReceivingDate = receivingDateTime.Unix()
  2707. }
  2708. }
  2709. if patientBody["induction"] != nil && reflect.TypeOf(patientBody["induction"]).String() == "float64" {
  2710. induction := int64(patientBody["induction"].(float64))
  2711. patient.InductionPeriod = induction
  2712. }
  2713. if patientBody["initial"] != nil && reflect.TypeOf(patientBody["initial"]).String() == "string" {
  2714. initial, _ := strconv.ParseInt(patientBody["initial"].(string), 10, 64)
  2715. patient.InitialDialysis = initial
  2716. }
  2717. if patientBody["dialysisTotal"] != nil && reflect.TypeOf(patientBody["dialysisTotal"]).String() == "string" {
  2718. dialysisTotal, _ := strconv.ParseInt(patientBody["dialysisTotal"].(string), 10, 64)
  2719. patient.TotalDialysis = dialysisTotal
  2720. }
  2721. if patientBody["contagions"] != nil && reflect.TypeOf(patientBody["contagions"]).String() == "[]interface {}" {
  2722. thisContagions, _ := patientBody["contagions"].([]interface{})
  2723. if len(thisContagions) > 0 {
  2724. for _, item := range thisContagions {
  2725. if reflect.TypeOf(item).String() != "float64" {
  2726. continue
  2727. }
  2728. contagion := int64(item.(float64))
  2729. if contagion > 0 {
  2730. contagions = append(contagions, contagion)
  2731. }
  2732. }
  2733. }
  2734. }
  2735. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  2736. doctor := int64(patientBody["doctor"].(float64))
  2737. patient.AttendingDoctorId = doctor
  2738. }
  2739. if patientBody["nurse"] != nil && reflect.TypeOf(patientBody["nurse"]).String() == "float64" {
  2740. nurse := int64(patientBody["nurse"].(float64))
  2741. patient.HeadNurseId = nurse
  2742. }
  2743. if patientBody["assessment"] != nil && reflect.TypeOf(patientBody["assessment"]).String() == "string" {
  2744. assessment := patientBody["assessment"].(string)
  2745. patient.Evaluate = assessment
  2746. }
  2747. if patientBody["diseases"] != nil && reflect.TypeOf(patientBody["diseases"]).String() == "[]interface {}" {
  2748. thisDiseases, _ := patientBody["diseases"].([]interface{})
  2749. if len(thisDiseases) > 0 {
  2750. for _, item := range thisDiseases {
  2751. if reflect.TypeOf(item).String() != "float64" {
  2752. continue
  2753. }
  2754. disease := int64(item.(float64))
  2755. if disease > 0 {
  2756. diseases = append(diseases, disease)
  2757. }
  2758. }
  2759. }
  2760. }
  2761. if patientBody["diagnose"] != nil && reflect.TypeOf(patientBody["diagnose"]).String() == "string" {
  2762. diagnose := patientBody["diagnose"].(string)
  2763. patient.Diagnose = diagnose
  2764. }
  2765. if patientBody["remark"] != nil && reflect.TypeOf(patientBody["remark"]).String() == "string" {
  2766. remark := patientBody["remark"].(string)
  2767. patient.Remark = remark
  2768. }
  2769. if patientBody["patient_complains"] != nil && reflect.TypeOf(patientBody["patient_complains"]).String() == "string" {
  2770. patient_complains := patientBody["patient_complains"].(string)
  2771. patient.PatientComplains = patient_complains
  2772. }
  2773. if patientBody["present_history"] != nil && reflect.TypeOf(patientBody["present_history"]).String() == "string" {
  2774. present_history := patientBody["present_history"].(string)
  2775. patient.PresentHistory = present_history
  2776. }
  2777. if patientBody["past_history"] != nil && reflect.TypeOf(patientBody["past_history"]).String() == "string" {
  2778. past_history := patientBody["past_history"].(string)
  2779. patient.PastHistory = past_history
  2780. }
  2781. if patientBody["temperature"] != nil && reflect.TypeOf(patientBody["temperature"]).String() == "string" {
  2782. temperature, _ := strconv.ParseFloat(patientBody["temperature"].(string), 64)
  2783. patient.Temperature = temperature
  2784. }
  2785. if patientBody["pulse"] != nil && reflect.TypeOf(patientBody["pulse"]).String() == "string" {
  2786. pulse, _ := strconv.ParseInt(patientBody["pulse"].(string), 10, 64)
  2787. patient.Pulse = pulse
  2788. }
  2789. if patientBody["respiratory"] != nil && reflect.TypeOf(patientBody["respiratory"]).String() == "string" {
  2790. respiratory, _ := strconv.ParseInt(patientBody["respiratory"].(string), 10, 64)
  2791. patient.Respiratory = respiratory
  2792. }
  2793. if patientBody["sbp"] != nil && reflect.TypeOf(patientBody["sbp"]).String() == "string" {
  2794. sbp, _ := strconv.ParseInt(patientBody["sbp"].(string), 10, 64)
  2795. patient.SBP = sbp
  2796. }
  2797. if patientBody["dbp"] != nil && reflect.TypeOf(patientBody["dbp"]).String() == "string" {
  2798. dbp, _ := strconv.ParseInt(patientBody["dbp"].(string), 10, 64)
  2799. patient.DBP = dbp
  2800. }
  2801. if patientBody["dialysis_age"] != nil && reflect.TypeOf(patientBody["dialysis_age"]).String() == "string" {
  2802. dialysis_age, _ := strconv.ParseInt(patientBody["dialysis_age"].(string), 10, 64)
  2803. patient.DialysisAge = dialysis_age
  2804. }
  2805. fmt.Println(patient.DialysisAge)
  2806. if patientBody["first_treatment_date"] != nil && reflect.TypeOf(patientBody["first_treatment_date"]).String() == "string" {
  2807. first_treatment_date := patientBody["first_treatment_date"].(string)
  2808. first_treatment_time, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  2809. if err == nil {
  2810. patient.FirstTreatmentDate = first_treatment_time.Unix()
  2811. }
  2812. }
  2813. if patientBody["expense_kind"] != nil && reflect.TypeOf(patientBody["expense_kind"]).String() == "float64" {
  2814. expense_kind := int64(patientBody["expense_kind"].(float64))
  2815. patient.ExpenseKind = expense_kind
  2816. }
  2817. fmt.Println(patient.ExpenseKind)
  2818. if patientBody["tell_phone"] != nil && reflect.TypeOf(patientBody["tell_phone"]).String() == "string" {
  2819. tell_phone := patientBody["tell_phone"].(string)
  2820. patient.TellPhone = tell_phone
  2821. }
  2822. if patientBody["contact_name"] != nil && reflect.TypeOf(patientBody["contact_name"]).String() == "string" {
  2823. contact_name := patientBody["contact_name"].(string)
  2824. patient.ContactName = contact_name
  2825. }
  2826. return
  2827. }
  2828. func (c *PatientApiController) GetPatientsByKeyWord() {
  2829. keyWord := c.GetString("keyword")
  2830. adminUserInfo := c.GetAdminUserInfo()
  2831. patient, err := service.GetPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  2832. if err != nil {
  2833. utils.ErrorLog(err.Error())
  2834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2835. return
  2836. }
  2837. c.ServeSuccessJSON(map[string]interface{}{
  2838. "patient": patient,
  2839. })
  2840. }
  2841. func (c *PatientApiController) QueryPatientById() {
  2842. id, _ := c.GetInt64("id")
  2843. fmt.Println(id)
  2844. patientInfo := service.QueryPatientById(id)
  2845. c.ServeSuccessJSON(map[string]interface{}{
  2846. "patient": patientInfo,
  2847. })
  2848. return
  2849. }
  2850. func (c *PatientApiController) GetRemindPatientList() {
  2851. page, _ := c.GetInt64("page", 1)
  2852. limit, _ := c.GetInt64("limit", 10)
  2853. adminUserInfo := c.GetAdminUserInfo()
  2854. total, patients, err := service.GetAllWaitRemindPatient(adminUserInfo.CurrentOrgId, page, limit)
  2855. if err != nil {
  2856. utils.ErrorLog(err.Error())
  2857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2858. return
  2859. }
  2860. c.ServeSuccessJSON(map[string]interface{}{
  2861. "total": total,
  2862. "patients": patients,
  2863. })
  2864. }
  2865. func (c *PatientApiController) PostIsOpenRemind() {
  2866. patient_id, _ := c.GetInt64("id", 1)
  2867. is_open_remind, _ := c.GetInt64("is_open_remind", 1)
  2868. adminUserInfo := c.GetAdminUserInfo()
  2869. err := service.UpdatePatientRemindStatus(patient_id, is_open_remind, adminUserInfo.CurrentOrgId)
  2870. if err == nil {
  2871. c.ServeSuccessJSON(map[string]interface{}{
  2872. "msg": "成功",
  2873. "is_open_remind": is_open_remind,
  2874. })
  2875. } else if err != nil {
  2876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2877. }
  2878. }
  2879. func (c *PatientApiController) GetPatientScheduleOne() {
  2880. id, _ := c.GetInt64("id")
  2881. //查询该病人是否当天是排班
  2882. nowDateTime := time.Now()
  2883. nowDate := nowDateTime.Format("2006-01-02")
  2884. nowDate += " 00:00:00"
  2885. timeLayout := "2006-01-02"
  2886. loc, _ := time.LoadLocation("Local")
  2887. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  2888. nowdate := theTime.Unix()
  2889. fmt.Println("nowdate", nowdate)
  2890. adminUser := c.GetAdminUserInfo()
  2891. orgId := adminUser.CurrentOrgId
  2892. fmt.Println("orgid", orgId)
  2893. scheduls, err := service.GetPatientScheduleOne(id, nowdate, orgId)
  2894. if err != nil {
  2895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2896. return
  2897. }
  2898. c.ServeSuccessJSON(map[string]interface{}{
  2899. "scheduls": scheduls,
  2900. })
  2901. }
  2902. func (c *PatientApiController) ExportPatients() {
  2903. dataBody := make(map[string]interface{}, 0)
  2904. all_patient, _, _ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId)
  2905. //all_patient, _,_ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId )
  2906. org, _ := service.GetOrgById(c.GetAdminUserInfo().CurrentOrgId)
  2907. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2908. if err != nil {
  2909. utils.ErrorLog(err.Error())
  2910. return
  2911. }
  2912. utils.ErrorLog("%v", dataBody)
  2913. export_time := time.Now().Unix()
  2914. var patients []*models.Patients
  2915. var total_patients []interface{}
  2916. if dataBody["patients"] != nil || reflect.TypeOf(dataBody["patients"]).String() == "[]interface {}" {
  2917. tempPatients := dataBody["patients"].([]interface{})
  2918. total_patients = tempPatients
  2919. for index, patientMap := range tempPatients {
  2920. patientNameM := patientMap.(map[string]interface{})
  2921. var patient models.Patients
  2922. if patientNameM["name"] == nil || reflect.TypeOf(patientNameM["name"]).String() != "string" {
  2923. utils.ErrorLog("name")
  2924. return
  2925. }
  2926. name, _ := patientNameM["name"].(string)
  2927. if len(name) == 0 { //名字为空则生成一条导入错误日志
  2928. err_log := models.ExportErrLog{
  2929. LogType: 1,
  2930. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2931. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的姓名不能为空",
  2932. Status: 1,
  2933. CreateTime: time.Now().Unix(),
  2934. UpdateTime: time.Now().Unix(),
  2935. ExportTime: export_time,
  2936. }
  2937. service.CreateExportErrLog(&err_log)
  2938. continue
  2939. }
  2940. patient.Name = name
  2941. if patientNameM["gender"] != nil || reflect.TypeOf(patientNameM["gender"]).String() == "string" {
  2942. gender, _ := strconv.ParseInt(patientNameM["gender"].(string), 10, 64)
  2943. if gender == 0 { //性别不符合要求则生成一条导入错误日志
  2944. err_log := models.ExportErrLog{
  2945. LogType: 1,
  2946. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2947. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的性别不符合要求",
  2948. Status: 1,
  2949. CreateTime: time.Now().Unix(),
  2950. UpdateTime: time.Now().Unix(),
  2951. ExportTime: export_time,
  2952. }
  2953. service.CreateExportErrLog(&err_log)
  2954. continue
  2955. } else {
  2956. patient.Gender = gender
  2957. }
  2958. }
  2959. if patientNameM["phone"] != nil || reflect.TypeOf(patientNameM["phone"]).String() == "string" {
  2960. phone, _ := patientNameM["phone"].(string)
  2961. if VerifyMobileFormat(phone) == false { //手机号码不符合要求则生成一条导入错误日志
  2962. if len(phone) == 0 {
  2963. err_log := models.ExportErrLog{
  2964. LogType: 1,
  2965. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2966. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码不能为空",
  2967. Status: 1,
  2968. CreateTime: time.Now().Unix(),
  2969. UpdateTime: time.Now().Unix(),
  2970. ExportTime: export_time,
  2971. }
  2972. service.CreateExportErrLog(&err_log)
  2973. continue
  2974. } else {
  2975. err_log := models.ExportErrLog{
  2976. LogType: 1,
  2977. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2978. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码格式不符合要求",
  2979. Status: 1,
  2980. CreateTime: time.Now().Unix(),
  2981. UpdateTime: time.Now().Unix(),
  2982. ExportTime: export_time,
  2983. }
  2984. service.CreateExportErrLog(&err_log)
  2985. continue
  2986. }
  2987. } else {
  2988. //var tempPatient *models.Patients
  2989. //for _, item := range all_patient {
  2990. // if item.Phone == phone {
  2991. // tempPatient = item
  2992. // }
  2993. //}
  2994. //需要判断该号码是否已经在系统内存在了,存在了则生成一条导入错误日志
  2995. count := service.FindPatientPhoneIsExist(phone, c.GetAdminUserInfo().CurrentOrgId)
  2996. if count > 1 {
  2997. err_log := models.ExportErrLog{
  2998. LogType: 1,
  2999. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3000. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码在系统中已经存在",
  3001. Status: 1,
  3002. CreateTime: time.Now().Unix(),
  3003. UpdateTime: time.Now().Unix(),
  3004. ExportTime: export_time,
  3005. }
  3006. service.CreateExportErrLog(&err_log)
  3007. continue
  3008. }
  3009. patient.Phone = phone
  3010. }
  3011. }
  3012. if patientNameM["id_card_no"] != nil || reflect.TypeOf(patientNameM["id_card_no"]).String() == "string" {
  3013. id_card_no, _ := patientNameM["id_card_no"].(string)
  3014. if IsIdCard(id_card_no) == false { //身份证号码不符合要求则生成一条导入错误日志
  3015. if len(id_card_no) == 0 {
  3016. err_log := models.ExportErrLog{
  3017. LogType: 1,
  3018. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3019. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码不能为空",
  3020. Status: 1,
  3021. CreateTime: time.Now().Unix(),
  3022. UpdateTime: time.Now().Unix(),
  3023. ExportTime: export_time,
  3024. }
  3025. service.CreateExportErrLog(&err_log)
  3026. continue
  3027. } else {
  3028. err_log := models.ExportErrLog{
  3029. LogType: 1,
  3030. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3031. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码格式不符合要求",
  3032. Status: 1,
  3033. CreateTime: time.Now().Unix(),
  3034. UpdateTime: time.Now().Unix(),
  3035. ExportTime: export_time,
  3036. }
  3037. service.CreateExportErrLog(&err_log)
  3038. continue
  3039. }
  3040. } else {
  3041. //var tempPatient *models.Patients
  3042. //for _, item := range all_patient {
  3043. // if item.IdCardNo == id_card_no {
  3044. // tempPatient = item
  3045. // }
  3046. //}
  3047. count := service.FindPatientIdCardNoIsExist(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  3048. if count > 1 {
  3049. //if tempPatient != nil && tempPatient.ID > 0 {
  3050. err_log := models.ExportErrLog{
  3051. LogType: 1,
  3052. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3053. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码在系统中已经存在",
  3054. Status: 1,
  3055. CreateTime: time.Now().Unix(),
  3056. UpdateTime: time.Now().Unix(),
  3057. ExportTime: export_time,
  3058. }
  3059. service.CreateExportErrLog(&err_log)
  3060. continue
  3061. }
  3062. //}
  3063. patient.IdCardNo = id_card_no
  3064. //patient.Birthday = GetBirthDay(id_card_no).Unix()
  3065. if GetBirthDay(id_card_no) == nil {
  3066. patient.Birthday = 0
  3067. } else {
  3068. patient.Birthday = GetBirthDay(id_card_no).Unix()
  3069. }
  3070. }
  3071. }
  3072. fmt.Println("111112222")
  3073. if patientNameM["first_treatment_date"] != nil || reflect.TypeOf(patientNameM["first_treatment_date"]).String() == "string" {
  3074. first_treatment_date, _ := patientNameM["first_treatment_date"].(string)
  3075. timeLayout := "2006/01/02"
  3076. loc, _ := time.LoadLocation("Local")
  3077. first_dialysis_date, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  3078. if err != nil { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  3079. if len(first_treatment_date) == 0 {
  3080. err_log := models.ExportErrLog{
  3081. LogType: 1,
  3082. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3083. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  3084. Status: 1,
  3085. CreateTime: time.Now().Unix(),
  3086. UpdateTime: time.Now().Unix(),
  3087. ExportTime: export_time,
  3088. }
  3089. service.CreateExportErrLog(&err_log)
  3090. continue
  3091. } else {
  3092. err_log := models.ExportErrLog{
  3093. LogType: 1,
  3094. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3095. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  3096. Status: 1,
  3097. CreateTime: time.Now().Unix(),
  3098. UpdateTime: time.Now().Unix(),
  3099. ExportTime: export_time,
  3100. }
  3101. service.CreateExportErrLog(&err_log)
  3102. continue
  3103. }
  3104. } else {
  3105. if len(first_treatment_date) == 0 {
  3106. err_log := models.ExportErrLog{
  3107. LogType: 1,
  3108. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3109. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  3110. Status: 1,
  3111. CreateTime: time.Now().Unix(),
  3112. UpdateTime: time.Now().Unix(),
  3113. ExportTime: export_time,
  3114. }
  3115. service.CreateExportErrLog(&err_log)
  3116. continue
  3117. } else {
  3118. if first_dialysis_date.Unix() == 0 { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  3119. err_log := models.ExportErrLog{
  3120. LogType: 1,
  3121. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3122. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  3123. Status: 1,
  3124. CreateTime: time.Now().Unix(),
  3125. UpdateTime: time.Now().Unix(),
  3126. ExportTime: export_time,
  3127. }
  3128. service.CreateExportErrLog(&err_log)
  3129. continue
  3130. } else {
  3131. patient.FirstDialysisDate = first_dialysis_date.Unix()
  3132. }
  3133. }
  3134. }
  3135. }
  3136. if patientNameM["source"] != nil || reflect.TypeOf(patientNameM["source"]).String() == "string" {
  3137. source, _ := strconv.ParseInt(patientNameM["source"].(string), 10, 64)
  3138. if source == 0 { //患者来源不符合要求则生成一条导入错误日志
  3139. err_log := models.ExportErrLog{
  3140. LogType: 1,
  3141. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3142. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不符合要求",
  3143. Status: 1,
  3144. CreateTime: time.Now().Unix(),
  3145. UpdateTime: time.Now().Unix(),
  3146. ExportTime: export_time,
  3147. }
  3148. service.CreateExportErrLog(&err_log)
  3149. continue
  3150. } else if source == 3 {
  3151. err_log := models.ExportErrLog{
  3152. LogType: 1,
  3153. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3154. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不能为空",
  3155. Status: 1,
  3156. CreateTime: time.Now().Unix(),
  3157. UpdateTime: time.Now().Unix(),
  3158. ExportTime: export_time,
  3159. }
  3160. service.CreateExportErrLog(&err_log)
  3161. continue
  3162. } else {
  3163. patient.Source = source
  3164. }
  3165. }
  3166. if patientNameM["lapseto"] != nil || reflect.TypeOf(patientNameM["lapseto"]).String() == "string" {
  3167. lapseto, _ := strconv.ParseInt(patientNameM["lapseto"].(string), 10, 64)
  3168. if lapseto == 0 { //治疗状态不符合要求则生成一条导入错误日志
  3169. err_log := models.ExportErrLog{
  3170. LogType: 1,
  3171. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3172. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不符合要求",
  3173. Status: 1,
  3174. CreateTime: time.Now().Unix(),
  3175. UpdateTime: time.Now().Unix(),
  3176. ExportTime: export_time,
  3177. }
  3178. service.CreateExportErrLog(&err_log)
  3179. continue
  3180. } else if lapseto == 3 {
  3181. err_log := models.ExportErrLog{
  3182. LogType: 1,
  3183. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3184. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不能为空",
  3185. Status: 1,
  3186. CreateTime: time.Now().Unix(),
  3187. UpdateTime: time.Now().Unix(),
  3188. ExportTime: export_time,
  3189. }
  3190. service.CreateExportErrLog(&err_log)
  3191. continue
  3192. } else {
  3193. patient.Lapseto = lapseto
  3194. }
  3195. }
  3196. if patientNameM["is_infectious"] != nil || reflect.TypeOf(patientNameM["is_infectious"]).String() == "string" {
  3197. is_infectious, _ := strconv.ParseInt(patientNameM["is_infectious"].(string), 10, 64)
  3198. if is_infectious == 0 { //传染病不符合要求则生成一条导入错误日志
  3199. err_log := models.ExportErrLog{
  3200. LogType: 1,
  3201. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3202. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不符合要求",
  3203. Status: 1,
  3204. CreateTime: time.Now().Unix(),
  3205. UpdateTime: time.Now().Unix(),
  3206. ExportTime: export_time,
  3207. }
  3208. service.CreateExportErrLog(&err_log)
  3209. continue
  3210. } else if is_infectious == 3 {
  3211. err_log := models.ExportErrLog{
  3212. LogType: 1,
  3213. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3214. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不能为空",
  3215. Status: 1,
  3216. CreateTime: time.Now().Unix(),
  3217. UpdateTime: time.Now().Unix(),
  3218. ExportTime: export_time,
  3219. }
  3220. service.CreateExportErrLog(&err_log)
  3221. continue
  3222. } else {
  3223. patient.IsInfectious = is_infectious
  3224. }
  3225. }
  3226. if patientNameM["contagions"] != nil && reflect.TypeOf(patientNameM["contagions"]).String() == "[]interface {}" {
  3227. var contagions []int64
  3228. thisContagions, _ := patientNameM["contagions"].([]interface{})
  3229. if len(thisContagions) > 0 {
  3230. for _, item := range thisContagions {
  3231. if reflect.TypeOf(item).String() != "float64" {
  3232. continue
  3233. }
  3234. contagion := int64(item.(float64))
  3235. if contagion > 0 {
  3236. contagions = append(contagions, contagion)
  3237. }
  3238. }
  3239. }
  3240. patient.ContagionIds = contagions
  3241. }
  3242. if patientNameM["diagnose"] != nil || reflect.TypeOf(patientNameM["diagnose"]).String() == "string" {
  3243. diagnose, _ := patientNameM["diagnose"].(string)
  3244. patient.Diagnose = diagnose
  3245. }
  3246. if patientNameM["dialysis_no"] != nil || reflect.TypeOf(patientNameM["dialysis_no"]).String() == "string" {
  3247. dialysis_no, _ := patientNameM["dialysis_no"].(string)
  3248. var tempPatient *models.Patients
  3249. for _, item := range all_patient {
  3250. if item.DialysisNo == dialysis_no {
  3251. tempPatient = item
  3252. }
  3253. }
  3254. if tempPatient != nil && tempPatient.ID > 0 {
  3255. patient.DialysisNo = GenerateDialysisNoTwo(patients)
  3256. } else {
  3257. patient.DialysisNo = dialysis_no
  3258. }
  3259. }
  3260. if patientNameM["height"] != nil || reflect.TypeOf(patientNameM["height"]).String() == "string" {
  3261. height, _ := patientNameM["height"].(string)
  3262. heights, _ := strconv.ParseFloat(height, 64)
  3263. patient.Height = int64(heights)
  3264. }
  3265. if patientNameM["home_address"] != nil || reflect.TypeOf(patientNameM["home_address"]).String() == "string" {
  3266. home_address, _ := patientNameM["home_address"].(string)
  3267. patient.HomeAddress = home_address
  3268. }
  3269. if patientNameM["dry_weight"] != nil || reflect.TypeOf(patientNameM["dry_weight"]).String() == "string" {
  3270. dry_weight, _ := patientNameM["dry_weight"].(string)
  3271. dry_weights, _ := strconv.ParseFloat(dry_weight, 64)
  3272. patient.DryWeight = dry_weights
  3273. }
  3274. patient.CreatedTime = time.Now().Unix()
  3275. patient.UpdatedTime = time.Now().Unix()
  3276. patient.Status = 1
  3277. patient.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
  3278. patient.IsExcelExport = 1
  3279. patient.PatientType = 1
  3280. patients = append(patients, &patient)
  3281. }
  3282. }
  3283. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  3284. if len(patients) > 0 {
  3285. for _, item := range patients {
  3286. service.CreateExportPatient(item, item.ContagionIds, org.Creator)
  3287. }
  3288. log := models.ExportLog{
  3289. LogType: 1,
  3290. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3291. TotalNum: int64(len(total_patients)),
  3292. FailNum: int64(len(errLogs)),
  3293. SuccessNum: int64(len(patients)),
  3294. CreateTime: time.Now().Unix(),
  3295. UpdateTime: time.Now().Unix(),
  3296. ExportTime: export_time,
  3297. Status: 1,
  3298. }
  3299. service.CreateExportLog(&log)
  3300. c.ServeSuccessJSON(map[string]interface{}{
  3301. "msg": "导入成功",
  3302. "total_num": len(total_patients),
  3303. "success_num": len(patients),
  3304. "fail_num": int64(len(errLogs)),
  3305. })
  3306. } else {
  3307. log := models.ExportLog{
  3308. LogType: 1,
  3309. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3310. TotalNum: int64(len(total_patients)),
  3311. FailNum: int64(len(errLogs)),
  3312. SuccessNum: int64(len(patients)),
  3313. CreateTime: time.Now().Unix(),
  3314. UpdateTime: time.Now().Unix(),
  3315. ExportTime: export_time,
  3316. Status: 1,
  3317. }
  3318. service.CreateExportLog(&log)
  3319. c.ServeSuccessJSON(map[string]interface{}{
  3320. "msg": "导入成功",
  3321. "total_num": len(total_patients),
  3322. "success_num": len(patients),
  3323. "fail_num": int64(len(errLogs)),
  3324. })
  3325. }
  3326. }
  3327. func GetBirthDay(IDCardNo string) *time.Time {
  3328. dayStr := IDCardNo[6:14]
  3329. birthDay, err := time.Parse("20060102", dayStr)
  3330. if err != nil {
  3331. fmt.Println(err)
  3332. return nil
  3333. }
  3334. return &birthDay
  3335. }
  3336. func VerifyMobileFormat(mobileNum string) bool {
  3337. regular := "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\\d{8}$"
  3338. reg := regexp.MustCompile(regular)
  3339. return reg.MatchString(mobileNum)
  3340. }
  3341. func IsIdCard(id string) (res bool) {
  3342. id = strings.ToUpper(id)
  3343. if len(id) != 15 && len(id) != 18 {
  3344. fmt.Println("1111111")
  3345. return false
  3346. }
  3347. r := regexp.MustCompile("(\\d{15})|(\\d{17}([0-9]|X))")
  3348. if !r.MatchString(id) {
  3349. fmt.Println("222222")
  3350. return false
  3351. }
  3352. if len(id) == 15 {
  3353. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[8:10])+"/"+string([]byte(id)[10:12])+"/"+"19"+string([]byte(id)[6:8]))
  3354. if tm2.Unix() == 0 {
  3355. fmt.Println("44444443333")
  3356. return false
  3357. }
  3358. return true
  3359. } else {
  3360. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[10:12])+"/"+string([]byte(id)[12:14])+"/"+string([]byte(id)[6:10]))
  3361. fmt.Println(string([]byte(id)[10:12]) + "/" + string([]byte(id)[12:14]) + "/" + string([]byte(id)[6:10]))
  3362. fmt.Println(tm2.Unix())
  3363. if tm2.Unix() == 0 {
  3364. fmt.Println("44445555555")
  3365. return false
  3366. }
  3367. //检验18位身份证的校验码是否正确。
  3368. //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
  3369. arr_int := []int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
  3370. arr_ch := []string{"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}
  3371. sign := 0
  3372. for k, v := range arr_int {
  3373. int_temp, _ := strconv.Atoi(string([]byte(id)[k : k+1]))
  3374. sign += int_temp * v
  3375. }
  3376. n := sign % 11
  3377. val_num := arr_ch[n]
  3378. if val_num != string([]byte(id)[17:18]) {
  3379. fmt.Println("5556666666")
  3380. return false
  3381. }
  3382. return true
  3383. }
  3384. }
  3385. func (c *PatientApiController) SaveEditAdvices() {
  3386. adminInfo := c.GetAdminUserInfo()
  3387. orgid := adminInfo.CurrentOrgId
  3388. startTime := c.GetString("start_time")
  3389. theTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", startTime)
  3390. groupno, _ := c.GetInt64("groupno")
  3391. fmt.Println("组", groupno)
  3392. date, _ := c.GetInt64("date")
  3393. fmt.Println("date", date)
  3394. patient_id, _ := c.GetInt64("patient_id")
  3395. fmt.Println("paitent_id", patient_id)
  3396. advice := models.XtDoctorAdvice{
  3397. StartTime: theTime.Unix(),
  3398. }
  3399. err := service.UpdateDoctorEditAdvice(advice, orgid, groupno, date, patient_id)
  3400. if err != nil {
  3401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3402. return
  3403. }
  3404. c.ServeSuccessJSON(map[string]interface{}{
  3405. "advice": advice,
  3406. })
  3407. }
  3408. func (c *PatientApiController) GetMaxDialysisNo() {
  3409. dialysisNo := service.ChechLastDialysisNo(c.GetAdminUserInfo().CurrentOrgId)
  3410. c.ServeSuccessJSON(map[string]interface{}{
  3411. "dialysis_no": dialysisNo,
  3412. })
  3413. }
  3414. func GenerateDialysisNoTwo(patients []*models.Patients) string {
  3415. dialysisNo2 := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
  3416. var tempPatient *models.Patients
  3417. for _, item := range patients {
  3418. if item.DialysisNo == dialysisNo2 {
  3419. tempPatient = item
  3420. }
  3421. }
  3422. if tempPatient == nil || tempPatient.ID == 0 {
  3423. return dialysisNo2
  3424. }
  3425. return GenerateDialysisNoTwo(patients)
  3426. }