patient_api_controller.go 126KB

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