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