patient_api_controller.go 131KB

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