patient_api_controller.go 110KB

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