patient_api_controller.go 124KB

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