patient_api_controller.go 106KB

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