patient_api_controller.go 130KB

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