patient_api_controller.go 109KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320
  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. adviceDate, _ := dataBody["advice_date"].(string)
  925. if len(adviceDate) == 0 {
  926. utils.ErrorLog("len(adviceDate) == 0")
  927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  928. return
  929. }
  930. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  931. if err != nil {
  932. utils.ErrorLog(err.Error())
  933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  934. return
  935. }
  936. AdviceDate := theTime.Unix()
  937. RecordDate := theTime.Unix()
  938. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  939. utils.ErrorLog("start_time")
  940. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  941. return
  942. }
  943. startTime, _ := dataBody["start_time"].(string)
  944. if len(startTime) == 0 {
  945. utils.ErrorLog("len(start_time) == 0")
  946. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  947. return
  948. }
  949. theTime, err = time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  950. if err != nil {
  951. utils.ErrorLog(err.Error())
  952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  953. return
  954. }
  955. StartTime := theTime.Unix()
  956. Remark := ""
  957. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  958. remark, _ := dataBody["remark"].(string)
  959. Remark = remark
  960. }
  961. var advices []*models.GroupAdvice
  962. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  963. utils.ErrorLog("adviceNames")
  964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  965. return
  966. }
  967. adviceNames := dataBody["adviceNames"].([]interface{})
  968. for _, adviceNameMap := range adviceNames {
  969. adviceNameM := adviceNameMap.(map[string]interface{})
  970. var advice models.GroupAdvice
  971. advice.Remark = Remark
  972. advice.AdviceType = adviceType
  973. advice.StartTime = StartTime
  974. advice.AdviceDate = AdviceDate
  975. advice.RecordDate = RecordDate
  976. advice.Status = 1
  977. advice.CreatedTime = time.Now().Unix()
  978. advice.UpdatedTime = time.Now().Unix()
  979. advice.StopState = 2
  980. advice.ExecutionState = 2
  981. advice.UserOrgId = adminUserInfo.CurrentOrgId
  982. advice.PatientId = patientInfo.ID
  983. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  984. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  985. utils.ErrorLog("advice_name")
  986. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  987. return
  988. }
  989. adviceName, _ := adviceNameM["advice_name"].(string)
  990. if len(adviceName) == 0 {
  991. utils.ErrorLog("len(advice_name) == 0")
  992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  993. return
  994. }
  995. advice.AdviceName = adviceName
  996. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  997. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  998. advice.DrugSpec = drugSpec
  999. }
  1000. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  1001. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  1002. advice.AdviceDesc = adviceDesc
  1003. }
  1004. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  1005. template_id, _ := adviceNameM["template_id"].(string)
  1006. advice.TemplateId = template_id
  1007. }
  1008. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  1009. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  1010. advice.DrugSpecUnit = drugSpecUnit
  1011. }
  1012. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  1013. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  1014. advice.SingleDose = singleDose
  1015. }
  1016. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  1017. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  1018. advice.SingleDoseUnit = singleDoseUnit
  1019. }
  1020. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  1021. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  1022. advice.PrescribingNumber = prescribingNumber
  1023. }
  1024. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  1025. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  1026. advice.PrescribingNumberUnit = prescribingNumberUnit
  1027. }
  1028. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  1029. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  1030. advice.DeliveryWay = deliveryWay
  1031. }
  1032. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  1033. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  1034. advice.ExecutionFrequency = executionFrequency
  1035. }
  1036. if adviceType == 1 {
  1037. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  1038. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  1039. advice.FrequencyType = frequency_type
  1040. }
  1041. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "string" {
  1042. day_count, _ := strconv.ParseInt(adviceNameM["day_count"].(string), 10, 64)
  1043. advice.DayCount = day_count
  1044. }
  1045. if adviceNameM["week_days"] != nil && reflect.TypeOf(adviceNameM["week_days"]).String() == "string" {
  1046. week_day, _ := adviceNameM["week_days"].(string)
  1047. advice.WeekDay = week_day
  1048. }
  1049. }
  1050. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "string" {
  1051. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  1052. advice.ExecutionFrequency = executionFrequency
  1053. }
  1054. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "[]interface {}" {
  1055. children := adviceNameM["children"].([]interface{})
  1056. if len(children) > 0 {
  1057. for _, childrenMap := range children {
  1058. childMap := childrenMap.(map[string]interface{})
  1059. var child models.GroupAdvice
  1060. child.Remark = Remark
  1061. child.AdviceType = adviceType
  1062. child.StartTime = StartTime
  1063. child.AdviceDate = AdviceDate
  1064. child.RecordDate = RecordDate
  1065. child.Status = 1
  1066. child.CreatedTime = time.Now().Unix()
  1067. child.UpdatedTime = time.Now().Unix()
  1068. child.StopState = 2
  1069. child.ExecutionState = 2
  1070. child.UserOrgId = adminUserInfo.CurrentOrgId
  1071. child.PatientId = patientInfo.ID
  1072. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  1073. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  1074. utils.ErrorLog("child advice_name")
  1075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1076. return
  1077. }
  1078. childAdviceName, _ := childMap["advice_name"].(string)
  1079. if len(childAdviceName) == 0 {
  1080. utils.ErrorLog("len(child advice_name) == 0")
  1081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1082. return
  1083. }
  1084. child.AdviceName = childAdviceName
  1085. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  1086. childAdviceDesc, _ := childMap["advice_desc"].(string)
  1087. child.AdviceDesc = childAdviceDesc
  1088. }
  1089. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  1090. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  1091. child.DrugSpec = childDrugSpec
  1092. }
  1093. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  1094. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  1095. child.DrugSpecUnit = childDrugSpecUnit
  1096. }
  1097. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  1098. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  1099. child.SingleDose = childSingleDose
  1100. }
  1101. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  1102. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  1103. child.SingleDoseUnit = childSingleDoseUnit
  1104. }
  1105. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  1106. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  1107. child.PrescribingNumber = childPrescribingNumber
  1108. }
  1109. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  1110. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  1111. child.PrescribingNumberUnit = childPrescribingNumberUnit
  1112. }
  1113. child.DeliveryWay = advice.DeliveryWay
  1114. child.ExecutionFrequency = advice.ExecutionFrequency
  1115. advice.Children = append(advice.Children, &child)
  1116. }
  1117. }
  1118. }
  1119. advices = append(advices, &advice)
  1120. }
  1121. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  1122. if err != nil {
  1123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1124. return
  1125. }
  1126. c.ServeSuccessJSON(map[string]interface{}{
  1127. "msg": "ok",
  1128. "advices": list,
  1129. })
  1130. return
  1131. }
  1132. func (c *PatientApiController) CreateDoctorAdvice() {
  1133. patient, _ := c.GetInt64("id", 0)
  1134. if patient <= 0 {
  1135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1136. return
  1137. }
  1138. adminUserInfo := c.GetAdminUserInfo()
  1139. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1140. if patientInfo.ID == 0 {
  1141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1142. return
  1143. }
  1144. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1145. if appRole.UserType == 3 {
  1146. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1147. if getPermissionErr != nil {
  1148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1149. return
  1150. } else if headNursePermission == nil {
  1151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1152. return
  1153. }
  1154. }
  1155. var advice models.DoctorAdvice
  1156. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  1157. if code > 0 {
  1158. c.ServeFailJSONWithSGJErrorCode(code)
  1159. return
  1160. }
  1161. if advice.ParentId > 0 {
  1162. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  1163. if old.ID == 0 || old.PatientId != patient {
  1164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  1165. return
  1166. }
  1167. if old.StopState == 1 || old.ExecutionState == 1 {
  1168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1169. return
  1170. }
  1171. if old.ParentId > 0 {
  1172. advice.ParentId = old.ParentId
  1173. }
  1174. advice.StartTime = old.StartTime
  1175. advice.AdviceDoctor = old.AdviceDoctor
  1176. advice.DeliveryWay = old.DeliveryWay
  1177. advice.ExecutionFrequency = old.ExecutionFrequency
  1178. advice.GroupNo = old.GroupNo
  1179. }
  1180. advice.Status = 1
  1181. advice.CreatedTime = time.Now().Unix()
  1182. advice.UpdatedTime = time.Now().Unix()
  1183. advice.StopState = 2
  1184. advice.ExecutionState = 2
  1185. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1186. advice.PatientId = patient
  1187. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1188. err := service.CreateDoctorAdvice(&advice)
  1189. if err != nil {
  1190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1191. return
  1192. }
  1193. c.ServeSuccessJSON(map[string]interface{}{
  1194. "msg": "ok",
  1195. "advice": advice,
  1196. })
  1197. return
  1198. }
  1199. func (c *PatientApiController) ExecGroupAdvice() {
  1200. groupNo, _ := c.GetInt64("groupno", 0)
  1201. executionTime := c.GetString("execution_time")
  1202. if groupNo <= 0 {
  1203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1204. return
  1205. }
  1206. if len(executionTime) <= 0 {
  1207. utils.ErrorLog("execution_time")
  1208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1209. return
  1210. }
  1211. adminUserInfo := c.GetAdminUserInfo()
  1212. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  1213. if advice.ID == 0 {
  1214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1215. return
  1216. }
  1217. if advice.ExecutionState == 1 {
  1218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1219. return
  1220. }
  1221. executionStaff := adminUserInfo.AdminUser.Id
  1222. // checker := adminUserInfo.AdminUser.Id
  1223. timeLayout := "2006-01-02 15:04:05"
  1224. loc, _ := time.LoadLocation("Local")
  1225. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1226. if err != nil {
  1227. utils.ErrorLog(err.Error())
  1228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1229. return
  1230. }
  1231. if advice.StartTime > theTime.Unix() {
  1232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1233. return
  1234. }
  1235. exceAdvice := models.DoctorAdvice{
  1236. ExecutionStaff: executionStaff,
  1237. ExecutionTime: theTime.Unix(),
  1238. // Checker: checker,
  1239. UpdatedTime: time.Now().Unix(),
  1240. }
  1241. err = service.ExceDoctorAdviceByGroupNo(&exceAdvice, groupNo, adminUserInfo.CurrentOrgId)
  1242. if err != nil {
  1243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1244. return
  1245. }
  1246. advice.ExecutionStaff = executionStaff
  1247. advice.ExecutionTime = theTime.Unix()
  1248. // advice.Checker = checker
  1249. c.ServeSuccessJSON(map[string]interface{}{
  1250. "msg": "ok",
  1251. "advice": advice,
  1252. })
  1253. return
  1254. }
  1255. func (c *PatientApiController) ExecDoctorAdvice() {
  1256. patient, _ := c.GetInt64("patient", 0)
  1257. id, _ := c.GetInt64("id", 0)
  1258. executionTime := c.GetString("execution_time")
  1259. if id <= 0 || patient <= 0 {
  1260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1261. return
  1262. }
  1263. if len(executionTime) <= 0 {
  1264. utils.ErrorLog("execution_time")
  1265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1266. return
  1267. }
  1268. adminUserInfo := c.GetAdminUserInfo()
  1269. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1270. if advice.ID == 0 || advice.PatientId != patient {
  1271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1272. return
  1273. }
  1274. if advice.ExecutionState == 1 {
  1275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1276. return
  1277. }
  1278. executionStaff := adminUserInfo.AdminUser.Id
  1279. // checker := adminUserInfo.AdminUser.Id
  1280. timeLayout := "2006-01-02 15:04:05"
  1281. loc, _ := time.LoadLocation("Local")
  1282. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1283. if err != nil {
  1284. utils.ErrorLog(err.Error())
  1285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1286. return
  1287. }
  1288. if advice.StartTime > theTime.Unix() {
  1289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1290. return
  1291. }
  1292. exceAdvice := models.DoctorAdvice{
  1293. ExecutionStaff: executionStaff,
  1294. ExecutionTime: theTime.Unix(),
  1295. // Checker: checker,
  1296. UpdatedTime: time.Now().Unix(),
  1297. }
  1298. if advice.ParentId > 0 {
  1299. err = service.ExceDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1300. } else {
  1301. err = service.ExceDoctorAdviceById(&exceAdvice, id, patient)
  1302. }
  1303. if err != nil {
  1304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1305. return
  1306. }
  1307. advice.ExecutionStaff = executionStaff
  1308. advice.ExecutionTime = theTime.Unix()
  1309. // advice.Checker = checker
  1310. c.ServeSuccessJSON(map[string]interface{}{
  1311. "msg": "ok",
  1312. "advice": advice,
  1313. })
  1314. return
  1315. }
  1316. func (c *PatientApiController) CheckGroupAdvice() {
  1317. groupno, _ := c.GetInt64("groupno", 0)
  1318. if groupno <= 0 {
  1319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1320. return
  1321. }
  1322. adminUserInfo := c.GetAdminUserInfo()
  1323. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupno)
  1324. if advice.ID == 0 {
  1325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1326. return
  1327. }
  1328. if advice.CheckState == 1 {
  1329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1330. return
  1331. }
  1332. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1334. return
  1335. }
  1336. checker := adminUserInfo.AdminUser.Id
  1337. theTime := time.Now()
  1338. exceAdvice := models.DoctorAdvice{
  1339. Checker: checker,
  1340. CheckTime: theTime.Unix(),
  1341. UpdatedTime: time.Now().Unix(),
  1342. }
  1343. var err error
  1344. err = service.CheckDoctorAdviceByGroupNo(&exceAdvice, groupno, adminUserInfo.CurrentOrgId)
  1345. if err != nil {
  1346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1347. return
  1348. }
  1349. // advice.ExecutionStaff = executionStaff
  1350. // advice.ExecutionTime = theTime.Unix()
  1351. advice.Checker = checker
  1352. advice.CheckTime = theTime.Unix()
  1353. c.ServeSuccessJSON(map[string]interface{}{
  1354. "msg": "ok",
  1355. "advice": advice,
  1356. })
  1357. return
  1358. }
  1359. func (c *PatientApiController) CheckDoctorAdvice() {
  1360. patient, _ := c.GetInt64("patient", 0)
  1361. id, _ := c.GetInt64("id", 0)
  1362. // executionTime := c.GetString("execution_time")
  1363. if id <= 0 || patient <= 0 {
  1364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1365. return
  1366. }
  1367. adminUserInfo := c.GetAdminUserInfo()
  1368. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1369. if advice.ID == 0 || advice.PatientId != patient {
  1370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1371. return
  1372. }
  1373. if advice.CheckState == 1 {
  1374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1375. return
  1376. }
  1377. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1378. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1379. return
  1380. }
  1381. // executionStaff := adminUserInfo.AdminUser.Id
  1382. checker := adminUserInfo.AdminUser.Id
  1383. // timeLayout := "2006-01-02 15:04:05"
  1384. // loc, _ := time.LoadLocation("Local")
  1385. // theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1386. // if err != nil {
  1387. // utils.ErrorLog(err.Error())
  1388. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1389. // return
  1390. // }
  1391. theTime := time.Now()
  1392. if advice.ExecutionTime > theTime.Unix() {
  1393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1394. return
  1395. }
  1396. exceAdvice := models.DoctorAdvice{
  1397. Checker: checker,
  1398. CheckTime: theTime.Unix(),
  1399. UpdatedTime: time.Now().Unix(),
  1400. }
  1401. var err error
  1402. if advice.ParentId > 0 {
  1403. err = service.CheckDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1404. } else {
  1405. err = service.CheckDoctorAdviceById(&exceAdvice, id, patient)
  1406. }
  1407. if err != nil {
  1408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1409. return
  1410. }
  1411. // advice.ExecutionStaff = executionStaff
  1412. // advice.ExecutionTime = theTime.Unix()
  1413. advice.Checker = checker
  1414. advice.CheckTime = theTime.Unix()
  1415. c.ServeSuccessJSON(map[string]interface{}{
  1416. "msg": "ok",
  1417. "advice": advice,
  1418. })
  1419. return
  1420. }
  1421. func (c *PatientApiController) UpdateDoctorAdvice() {
  1422. patient, _ := c.GetInt64("patient", 0)
  1423. id, _ := c.GetInt64("id", 0)
  1424. if id <= 0 || patient <= 0 {
  1425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1426. return
  1427. }
  1428. adminUserInfo := c.GetAdminUserInfo()
  1429. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1430. if advice.ID == 0 || advice.PatientId != patient {
  1431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1432. return
  1433. }
  1434. //if advice.AdviceType == 1 {
  1435. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeLongTimeAdviceNotCanntEdit)
  1436. // return
  1437. //}
  1438. if advice.StopState == 1 || advice.ExecutionState == 1 {
  1439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1440. return
  1441. }
  1442. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1443. //if appRole.UserType == 3 {
  1444. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1445. // if getPermissionErr != nil {
  1446. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1447. // return
  1448. // } else if headNursePermission == nil {
  1449. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1450. // return
  1451. // }
  1452. //}
  1453. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  1454. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCanotEditOtherAdvice)
  1455. // return
  1456. //}
  1457. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  1458. if code > 0 {
  1459. c.ServeFailJSONWithSGJErrorCode(code)
  1460. return
  1461. }
  1462. advice.UpdatedTime = time.Now().Unix()
  1463. advice.Modifier = adminUserInfo.AdminUser.Id
  1464. err := service.UpdateDoctorAdvice(&advice)
  1465. if err != nil {
  1466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1467. return
  1468. }
  1469. c.ServeSuccessJSON(map[string]interface{}{
  1470. "msg": "ok",
  1471. "advice": advice,
  1472. })
  1473. return
  1474. }
  1475. func (c *PatientApiController) StopGroupAdvice() {
  1476. groupNo, _ := c.GetInt64("groupno", 0)
  1477. if groupNo <= 0 {
  1478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1479. return
  1480. }
  1481. adminUserInfo := c.GetAdminUserInfo()
  1482. advice, _ := service.FindDoctorAdviceByGoroupNo(adminUserInfo.CurrentOrgId, groupNo)
  1483. if advice.ID == 0 {
  1484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1485. return
  1486. }
  1487. if advice.StopState == 1 || advice.ExecutionState == 1 {
  1488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1489. return
  1490. }
  1491. dataBody := make(map[string]interface{}, 0)
  1492. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1493. if err != nil {
  1494. utils.ErrorLog(err.Error())
  1495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1496. return
  1497. }
  1498. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  1499. utils.ErrorLog("stop_time")
  1500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1501. return
  1502. }
  1503. stopTime, _ := dataBody["stop_time"].(string)
  1504. if len(stopTime) == 0 {
  1505. utils.ErrorLog("len(stop_time) == 0")
  1506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1507. return
  1508. }
  1509. timeLayout := "2006-01-02"
  1510. loc, _ := time.LoadLocation("Local")
  1511. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  1512. if err != nil {
  1513. utils.ErrorLog(err.Error())
  1514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1515. return
  1516. }
  1517. advice.StopTime = theTime.Unix()
  1518. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  1519. stopReason, _ := dataBody["stop_reason"].(string)
  1520. advice.StopReason = stopReason
  1521. }
  1522. advice.UpdatedTime = time.Now().Unix()
  1523. advice.StopDoctor = adminUserInfo.AdminUser.Id
  1524. advice.StopState = 1
  1525. err = service.StopGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, &advice)
  1526. if err != nil {
  1527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  1528. return
  1529. }
  1530. c.ServeSuccessJSON(map[string]interface{}{
  1531. "msg": "ok",
  1532. })
  1533. return
  1534. }
  1535. func (c *PatientApiController) StopDoctorAdvice() {
  1536. id, _ := c.GetInt64("id", 0)
  1537. if id <= 0 {
  1538. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1539. return
  1540. }
  1541. adminUserInfo := c.GetAdminUserInfo()
  1542. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1543. //
  1544. //if appRole.UserType == 3 {
  1545. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1546. // if getPermissionErr != nil {
  1547. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1548. // return
  1549. // } else if headNursePermission == nil {
  1550. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1551. // return
  1552. // }
  1553. //}
  1554. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1555. if advice.ID == 0 {
  1556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1557. return
  1558. }
  1559. if advice.StopState == 1 || advice.ExecutionState == 1 {
  1560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1561. return
  1562. }
  1563. dataBody := make(map[string]interface{}, 0)
  1564. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1565. if err != nil {
  1566. utils.ErrorLog(err.Error())
  1567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1568. return
  1569. }
  1570. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  1571. utils.ErrorLog("stop_time")
  1572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1573. return
  1574. }
  1575. stopTime, _ := dataBody["stop_time"].(string)
  1576. if len(stopTime) == 0 {
  1577. utils.ErrorLog("len(stop_time) == 0")
  1578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1579. return
  1580. }
  1581. timeLayout := "2006-01-02"
  1582. loc, _ := time.LoadLocation("Local")
  1583. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  1584. if err != nil {
  1585. utils.ErrorLog(err.Error())
  1586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1587. return
  1588. }
  1589. advice.StopTime = theTime.Unix()
  1590. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  1591. stopReason, _ := dataBody["stop_reason"].(string)
  1592. advice.StopReason = stopReason
  1593. }
  1594. advice.UpdatedTime = time.Now().Unix()
  1595. advice.StopDoctor = adminUserInfo.AdminUser.Id
  1596. advice.StopState = 1
  1597. err = service.StopDoctorAdvice(&advice)
  1598. if err != nil {
  1599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  1600. return
  1601. }
  1602. c.ServeSuccessJSON(map[string]interface{}{
  1603. "msg": "ok",
  1604. "advice": advice,
  1605. })
  1606. return
  1607. }
  1608. func (c *PatientApiController) DeleteDoctorAdvice() {
  1609. id, _ := c.GetInt64("id", 0)
  1610. if id <= 0 {
  1611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1612. return
  1613. }
  1614. adminUserInfo := c.GetAdminUserInfo()
  1615. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1616. if advice.ID == 0 {
  1617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1618. return
  1619. }
  1620. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  1621. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1622. // return
  1623. //}
  1624. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1625. //
  1626. //if appRole.UserType == 3 {
  1627. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1628. // if getPermissionErr != nil {
  1629. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1630. // return
  1631. // } else if headNursePermission == nil {
  1632. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1633. // return
  1634. // }
  1635. //}
  1636. advice.UpdatedTime = time.Now().Unix()
  1637. advice.Status = 0
  1638. advice.Modifier = adminUserInfo.AdminUser.Id
  1639. err := service.DeleteDoctorAdvice(&advice)
  1640. if err != nil {
  1641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  1642. return
  1643. }
  1644. c.ServeSuccessJSON(map[string]interface{}{
  1645. "msg": "ok",
  1646. })
  1647. return
  1648. }
  1649. func (c *PatientApiController) DeleteGroupAdvice() {
  1650. groupNo, _ := c.GetInt64("groupno", 0)
  1651. if groupNo <= 0 {
  1652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1653. return
  1654. }
  1655. adminUserInfo := c.GetAdminUserInfo()
  1656. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  1657. if advice.ID == 0 {
  1658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1659. return
  1660. }
  1661. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1662. //if appRole.UserType == 3 {
  1663. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1664. // if getPermissionErr != nil {
  1665. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1666. // return
  1667. // } else if headNursePermission == nil {
  1668. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1669. // return
  1670. // }
  1671. //}
  1672. err := service.DeleteGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, adminUserInfo.AdminUser.Id)
  1673. if err != nil {
  1674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  1675. return
  1676. }
  1677. c.ServeSuccessJSON(map[string]interface{}{
  1678. "msg": "ok",
  1679. })
  1680. return
  1681. }
  1682. //GetDoctorAdvices 医嘱列表
  1683. func (c *PatientApiController) GetDoctorAdvices() {
  1684. id, _ := c.GetInt64("id", 0)
  1685. adviceType, _ := c.GetInt64("advice_type", 0)
  1686. stopType, _ := c.GetInt64("stop_state", 0)
  1687. startTime := c.GetString("start_time", "")
  1688. endTime := c.GetString("end_time", "")
  1689. keywords := c.GetString("keywords", "")
  1690. adminUserInfo := c.GetAdminUserInfo()
  1691. operatorIDs := make([]int64, 0)
  1692. timeLayout := "2006-01-02"
  1693. loc, _ := time.LoadLocation("Local")
  1694. var theStartTIme int64
  1695. if len(startTime) > 0 {
  1696. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  1697. if err != nil {
  1698. utils.ErrorLog(err.Error())
  1699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1700. return
  1701. }
  1702. theStartTIme = theTime.Unix()
  1703. }
  1704. var theEndtTIme int64
  1705. if len(endTime) > 0 {
  1706. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  1707. if err != nil {
  1708. utils.ErrorLog(err.Error())
  1709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1710. return
  1711. }
  1712. theEndtTIme = theTime.Unix()
  1713. }
  1714. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  1715. if len(advices) > 0 {
  1716. for _, item := range advices {
  1717. if item.AdviceDoctor > 0 {
  1718. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  1719. }
  1720. if item.ExecutionStaff > 0 {
  1721. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  1722. }
  1723. if item.Checker > 0 {
  1724. operatorIDs = append(operatorIDs, item.Checker)
  1725. }
  1726. if item.StopDoctor > 0 {
  1727. operatorIDs = append(operatorIDs, item.StopDoctor)
  1728. }
  1729. }
  1730. }
  1731. //相关操作对应的操作人
  1732. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  1733. c.ServeSuccessJSON(map[string]interface{}{
  1734. "advices": advices,
  1735. "operators": operators,
  1736. "total": total,
  1737. })
  1738. return
  1739. }
  1740. func (c *PatientApiController) GetPatientSchedules() {
  1741. id, _ := c.GetInt64("id", 0)
  1742. if id <= 0 {
  1743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1744. return
  1745. }
  1746. adminUserInfo := c.GetAdminUserInfo()
  1747. todayTime := time.Now().Format("2006-01-02")
  1748. timeLayout := "2006-01-02 15:04:05"
  1749. loc, _ := time.LoadLocation("Local")
  1750. var theStartTime int64
  1751. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  1752. theStartTime = theTime.Unix()
  1753. schedules, _ := service.GetPatientScheduleFormToday(adminUserInfo.CurrentOrgId, id, theStartTime)
  1754. if len(schedules) > 0 {
  1755. for index, item := range schedules {
  1756. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  1757. schedules[index].Week = int64(week)
  1758. }
  1759. }
  1760. c.ServeSuccessJSON(map[string]interface{}{
  1761. "schedules": schedules,
  1762. })
  1763. return
  1764. }
  1765. func (c *PatientApiController) GetPatientDialysisRecords() {
  1766. patientID, _ := c.GetInt64("patient_id", 0)
  1767. page, _ := c.GetInt64("page", 0)
  1768. limit, _ := c.GetInt64("limit", 0)
  1769. startTime := c.GetString("start_time", "")
  1770. endTime := c.GetString("end_time", "")
  1771. mode_id, _ := c.GetInt64("mode_id", 0)
  1772. if page <= 0 {
  1773. page = 1
  1774. }
  1775. if limit <= 0 {
  1776. limit = 10
  1777. }
  1778. if patientID <= 0 {
  1779. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1780. return
  1781. }
  1782. timeLayout := "2006-01-02"
  1783. loc, _ := time.LoadLocation("Local")
  1784. var theStartTIme int64
  1785. if len(startTime) > 0 {
  1786. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  1787. if err != nil {
  1788. theStartTIme = 0
  1789. }
  1790. theStartTIme = theTime.Unix()
  1791. }
  1792. var theEndtTIme int64
  1793. if len(endTime) > 0 {
  1794. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  1795. if err != nil {
  1796. theEndtTIme = 0
  1797. }
  1798. theEndtTIme = theTime.Unix()
  1799. }
  1800. adminInfo := c.GetAdminUserInfo()
  1801. records, total, _ := service.GetPatientDialysisRecord(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  1802. c.ServeSuccessJSON(map[string]interface{}{
  1803. "total": total,
  1804. "records": records,
  1805. })
  1806. return
  1807. }
  1808. func (c *PatientApiController) ProEducation() {
  1809. patientID, _ := c.GetInt64("patient_id", 0)
  1810. page, _ := c.GetInt64("page", 0)
  1811. limit, _ := c.GetInt64("limit", 0)
  1812. startTime := c.GetString("start_time", "")
  1813. endTime := c.GetString("end_time", "")
  1814. if page <= 0 {
  1815. page = 1
  1816. }
  1817. if limit <= 0 {
  1818. limit = 10
  1819. }
  1820. if patientID <= 0 {
  1821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1822. return
  1823. }
  1824. timeLayout := "2006-01-02"
  1825. loc, _ := time.LoadLocation("Local")
  1826. var theStartTIme int64
  1827. if len(startTime) > 0 {
  1828. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  1829. if err != nil {
  1830. theStartTIme = 0
  1831. }
  1832. theStartTIme = theTime.Unix()
  1833. }
  1834. var theEndtTIme int64
  1835. if len(endTime) > 0 {
  1836. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  1837. if err != nil {
  1838. theEndtTIme = 0
  1839. }
  1840. theEndtTIme = theTime.Unix()
  1841. }
  1842. adminInfo := c.GetAdminUserInfo()
  1843. edus, total, _ := service.GetPatientTreatmentSummaryList(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme)
  1844. c.ServeSuccessJSON(map[string]interface{}{
  1845. "total": total,
  1846. "edus": edus,
  1847. })
  1848. return
  1849. }
  1850. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  1851. dataBody := make(map[string]interface{}, 0)
  1852. err := json.Unmarshal(data, &dataBody)
  1853. if err != nil {
  1854. utils.ErrorLog(err.Error())
  1855. code = enums.ErrorCodeParamWrong
  1856. return
  1857. }
  1858. timeLayout := "2006-01-02"
  1859. loc, _ := time.LoadLocation("Local")
  1860. isChild := false
  1861. if action == "create" {
  1862. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  1863. utils.ErrorLog("advice_type")
  1864. code = enums.ErrorCodeParamWrong
  1865. return
  1866. }
  1867. adviceType := int64(dataBody["advice_type"].(float64))
  1868. if adviceType != 1 && adviceType != 2 && adviceType != 3 {
  1869. utils.ErrorLog("advice_type != 1&&2")
  1870. code = enums.ErrorCodeParamWrong
  1871. return
  1872. }
  1873. advice.AdviceType = adviceType
  1874. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1875. utils.ErrorLog("advice_date")
  1876. code = enums.ErrorCodeParamWrong
  1877. return
  1878. }
  1879. adviceDate, _ := dataBody["advice_date"].(string)
  1880. if len(adviceDate) == 0 {
  1881. utils.ErrorLog("len(adviceDate) == 0")
  1882. code = enums.ErrorCodeParamWrong
  1883. return
  1884. }
  1885. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  1886. if err != nil {
  1887. utils.ErrorLog(err.Error())
  1888. code = enums.ErrorCodeParamWrong
  1889. return
  1890. }
  1891. advice.AdviceDate = theTime.Unix()
  1892. advice.RecordDate = theTime.Unix()
  1893. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  1894. parentId := int64(dataBody["parent_id"].(float64))
  1895. advice.ParentId = parentId
  1896. if parentId > 0 {
  1897. isChild = true
  1898. }
  1899. }
  1900. }
  1901. if !isChild {
  1902. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1903. utils.ErrorLog("start_time")
  1904. code = enums.ErrorCodeParamWrong
  1905. return
  1906. }
  1907. startTime, _ := dataBody["start_time"].(string)
  1908. if len(startTime) == 0 {
  1909. utils.ErrorLog("len(start_time) == 0")
  1910. code = enums.ErrorCodeParamWrong
  1911. return
  1912. }
  1913. theTime, err := time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  1914. if err != nil {
  1915. utils.ErrorLog(err.Error())
  1916. code = enums.ErrorCodeParamWrong
  1917. return
  1918. }
  1919. advice.StartTime = theTime.Unix()
  1920. // if dataBody["advice_doctor"] == nil || reflect.TypeOf(dataBody["advice_doctor"]).String() != "float64" {
  1921. // utils.ErrorLog("advice_doctor")
  1922. // code = enums.ErrorCodeParamWrong
  1923. // return
  1924. // }
  1925. // adviceDoctor := int64(dataBody["advice_doctor"].(float64))
  1926. // if adviceDoctor <= 0 {
  1927. // utils.ErrorLog("advice_doctor <=0")
  1928. // code = enums.ErrorCodeParamWrong
  1929. // return
  1930. // }
  1931. // advice.AdviceDoctor = adviceDoctor
  1932. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  1933. deliveryWay, _ := dataBody["delivery_way"].(string)
  1934. advice.DeliveryWay = deliveryWay
  1935. }
  1936. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  1937. executionFrequency, _ := dataBody["execution_frequency"].(string)
  1938. advice.ExecutionFrequency = executionFrequency
  1939. }
  1940. if advice.AdviceType == 1 && advice.ParentId == 0 {
  1941. if dataBody["frequency_type"] != nil || reflect.TypeOf(dataBody["frequency_type"]).String() == "float64" {
  1942. frequency_type := int64(dataBody["frequency_type"].(float64))
  1943. advice.FrequencyType = frequency_type
  1944. }
  1945. if dataBody["day_count"] != nil || reflect.TypeOf(dataBody["day_count"]).String() == "string" {
  1946. day_count, _ := strconv.ParseInt(dataBody["day_count"].(string), 10, 64)
  1947. advice.DayCount = day_count
  1948. }
  1949. if dataBody["week_days"] != nil && reflect.TypeOf(dataBody["week_days"]).String() == "string" {
  1950. week_day, _ := dataBody["week_days"].(string)
  1951. advice.WeekDay = week_day
  1952. }
  1953. }
  1954. }
  1955. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  1956. utils.ErrorLog("advice_name")
  1957. code = enums.ErrorCodeParamWrong
  1958. return
  1959. }
  1960. adviceName, _ := dataBody["advice_name"].(string)
  1961. if len(adviceName) == 0 {
  1962. utils.ErrorLog("len(advice_name) == 0")
  1963. code = enums.ErrorCodeParamWrong
  1964. return
  1965. }
  1966. advice.AdviceName = adviceName
  1967. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  1968. adviceDsc, _ := dataBody["advice_desc"].(string)
  1969. advice.AdviceDesc = adviceDsc
  1970. }
  1971. if dataBody["dialysis_order_id"] != nil && reflect.TypeOf(dataBody["dialysis_order_id"]).String() == "float64" {
  1972. dialysisOrderId, _ := dataBody["dialysis_order_id"].(float64)
  1973. advice.DialysisOrderId = int64(dialysisOrderId)
  1974. }
  1975. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  1976. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  1977. advice.SingleDose = singleDose
  1978. }
  1979. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  1980. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  1981. advice.SingleDoseUnit = singleDoseUnit
  1982. }
  1983. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  1984. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  1985. advice.DrugSpec = drugSpec
  1986. }
  1987. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  1988. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  1989. advice.DrugSpecUnit = drugSpecUnit
  1990. }
  1991. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  1992. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  1993. advice.PrescribingNumber = prescribingNumber
  1994. }
  1995. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  1996. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  1997. advice.PrescribingNumberUnit = prescribingNumberUnit
  1998. }
  1999. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2000. remark, _ := dataBody["remark"].(string)
  2001. advice.Remark = remark
  2002. }
  2003. return
  2004. }
  2005. func solutionFormData(solution *models.DialysisSolution, data []byte) (code int) {
  2006. dataBody := make(map[string]interface{}, 0)
  2007. err := json.Unmarshal(data, &dataBody)
  2008. utils.InfoLog(string(data))
  2009. if err != nil {
  2010. utils.ErrorLog(err.Error())
  2011. code = enums.ErrorCodeParamWrong
  2012. return
  2013. }
  2014. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2015. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2016. solution.DialysisDuration = dialysisDuration
  2017. }
  2018. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  2019. replacementWay := int64(dataBody["replacement_way"].(float64))
  2020. solution.ReplacementWay = replacementWay
  2021. }
  2022. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  2023. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  2024. solution.BloodFlowVolume = bloodFlowVolume
  2025. }
  2026. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  2027. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  2028. solution.HemodialysisMachine = hemodialysisMachine
  2029. }
  2030. if dataBody["blood_filter"] != nil && reflect.TypeOf(dataBody["blood_filter"]).String() == "float64" {
  2031. bloodFilter := int64(dataBody["blood_filter"].(float64))
  2032. solution.BloodFilter = bloodFilter
  2033. }
  2034. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  2035. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  2036. solution.PerfusionApparatus = perfusionApparatus
  2037. }
  2038. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  2039. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  2040. solution.DialysateFlow = dialysateFlow
  2041. }
  2042. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  2043. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  2044. solution.Kalium = kalium
  2045. }
  2046. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  2047. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  2048. solution.Sodium = sodium
  2049. }
  2050. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  2051. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  2052. solution.Calcium = calcium
  2053. }
  2054. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  2055. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  2056. solution.Bicarbonate = bicarbonate
  2057. }
  2058. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  2059. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  2060. solution.Anticoagulant = anticoagulant
  2061. }
  2062. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  2063. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  2064. solution.AnticoagulantShouji = anticoagulantShouji
  2065. }
  2066. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  2067. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  2068. solution.AnticoagulantWeichi = anticoagulantWeichi
  2069. }
  2070. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  2071. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  2072. solution.AnticoagulantZongliang = anticoagulantZongliang
  2073. }
  2074. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  2075. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  2076. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  2077. }
  2078. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  2079. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  2080. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  2081. }
  2082. return
  2083. }
  2084. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  2085. dataBody := make(map[string]interface{}, 0)
  2086. err := json.Unmarshal(data, &dataBody)
  2087. utils.InfoLog(string(data))
  2088. if err != nil {
  2089. utils.ErrorLog(err.Error())
  2090. code = enums.ErrorCodeParamWrong
  2091. return
  2092. }
  2093. if method == "create" {
  2094. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  2095. utils.ErrorLog("mode")
  2096. code = enums.ErrorCodeParamWrong
  2097. return
  2098. }
  2099. mode := int64(dataBody["mode"].(float64))
  2100. if mode <= 0 {
  2101. utils.ErrorLog("mode <= 0")
  2102. code = enums.ErrorCodeParamWrong
  2103. return
  2104. }
  2105. solution.ModeId = mode
  2106. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  2107. utils.ErrorLog("mode_name")
  2108. code = enums.ErrorCodeParamWrong
  2109. return
  2110. }
  2111. modeName, _ := dataBody["mode_name"].(string)
  2112. if len(modeName) == 0 {
  2113. utils.ErrorLog("len(mode_name) == 0")
  2114. code = enums.ErrorCodeParamWrong
  2115. return
  2116. }
  2117. solution.ModeName = modeName
  2118. solution.Name = modeName
  2119. }
  2120. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2121. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2122. solution.DialysisDuration = dialysisDuration
  2123. }
  2124. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  2125. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  2126. solution.TargetUltrafiltration = targetUltrafiltration
  2127. }
  2128. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  2129. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  2130. solution.DialysateFormulation = dialysateFormulation
  2131. }
  2132. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  2133. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  2134. solution.DialysisDurationHour = int64(dialysisDurationHour)
  2135. }
  2136. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  2137. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  2138. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  2139. }
  2140. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  2141. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  2142. solution.HemodialysisMachine = hemodialysisMachine
  2143. }
  2144. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  2145. dialyzer := int64(dataBody["dialyzer"].(float64))
  2146. solution.Dialyzer = dialyzer
  2147. }
  2148. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  2149. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  2150. solution.PerfusionApparatus = perfusionApparatus
  2151. }
  2152. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  2153. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  2154. solution.BloodFlowVolume = bloodFlowVolume
  2155. }
  2156. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  2157. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  2158. solution.Dewater = dewater
  2159. }
  2160. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  2161. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  2162. solution.DisplaceLiqui = displaceLiqui
  2163. }
  2164. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  2165. replacementWay := int64(dataBody["replacement_way"].(float64))
  2166. solution.ReplacementWay = replacementWay
  2167. }
  2168. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  2169. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  2170. solution.Anticoagulant = anticoagulant
  2171. }
  2172. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  2173. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  2174. solution.AnticoagulantShouji = anticoagulantShouji
  2175. }
  2176. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  2177. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  2178. solution.AnticoagulantWeichi = anticoagulantWeichi
  2179. }
  2180. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  2181. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  2182. solution.AnticoagulantZongliang = anticoagulantZongliang
  2183. }
  2184. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  2185. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  2186. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  2187. }
  2188. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  2189. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  2190. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  2191. }
  2192. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  2193. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  2194. solution.Kalium = kalium
  2195. }
  2196. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  2197. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  2198. solution.Sodium = sodium
  2199. }
  2200. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  2201. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  2202. solution.Calcium = calcium
  2203. }
  2204. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  2205. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  2206. solution.Bicarbonate = bicarbonate
  2207. }
  2208. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  2209. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  2210. solution.Glucose = glucose
  2211. }
  2212. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  2213. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  2214. // solution.DryWeight = dryWeight
  2215. // }
  2216. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  2217. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  2218. solution.DialysateFlow = dialysateFlow
  2219. }
  2220. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  2221. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  2222. solution.DialysateTemperature = dialysateTemperature
  2223. }
  2224. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  2225. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  2226. solution.Conductivity = conductivity
  2227. }
  2228. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  2229. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  2230. solution.ReplacementTotal = replacementTotal
  2231. }
  2232. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  2233. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  2234. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  2235. }
  2236. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  2237. body_fluid := int64(dataBody["body_fluid"].(float64))
  2238. solution.BodyFluid = body_fluid
  2239. }
  2240. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  2241. body_fluid_other := dataBody["body_fluid_other"].(string)
  2242. solution.BodyFluidOther = body_fluid_other
  2243. }
  2244. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  2245. special_medicine := int64(dataBody["special_medicine"].(float64))
  2246. solution.SpecialMedicine = special_medicine
  2247. }
  2248. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  2249. special_medicine_other := dataBody["special_medicine_other"].(string)
  2250. solution.SpecialMedicineOther = special_medicine_other
  2251. }
  2252. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  2253. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  2254. solution.DisplaceLiquiPart = displace_liqui_part
  2255. }
  2256. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  2257. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  2258. solution.DisplaceLiquiValue = displace_liqui_value
  2259. }
  2260. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  2261. blood_access := int64(dataBody["blood_access"].(float64))
  2262. solution.BloodAccess = blood_access
  2263. }
  2264. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  2265. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  2266. solution.Ultrafiltration = ultrafiltration
  2267. }
  2268. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  2269. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  2270. solution.TargetKtv = target_ktv
  2271. }
  2272. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2273. remark := dataBody["remark"].(string)
  2274. solution.Remark = remark
  2275. }
  2276. return
  2277. }
  2278. func childSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  2279. dataBody := make(map[string]interface{}, 0)
  2280. err := json.Unmarshal(data, &dataBody)
  2281. utils.InfoLog(string(data))
  2282. if err != nil {
  2283. utils.ErrorLog(err.Error())
  2284. code = enums.ErrorCodeParamWrong
  2285. return
  2286. }
  2287. if method == "create" {
  2288. if dataBody["parent_id"] == nil || reflect.TypeOf(dataBody["parent_id"]).String() != "float64" {
  2289. utils.ErrorLog("parent_id")
  2290. code = enums.ErrorCodeParamWrong
  2291. return
  2292. }
  2293. parentID := int64(dataBody["parent_id"].(float64))
  2294. if parentID <= 0 {
  2295. utils.ErrorLog("parentID <= 0")
  2296. code = enums.ErrorCodeParamWrong
  2297. return
  2298. }
  2299. solution.ParentId = parentID
  2300. if dataBody["sub_name"] == nil || reflect.TypeOf(dataBody["sub_name"]).String() != "string" {
  2301. utils.ErrorLog("sub_name")
  2302. code = enums.ErrorCodeParamWrong
  2303. return
  2304. }
  2305. subName, _ := dataBody["sub_name"].(string)
  2306. if len(subName) == 0 {
  2307. utils.ErrorLog("len(sub_name) == 0")
  2308. code = enums.ErrorCodeParamWrong
  2309. return
  2310. }
  2311. solution.SubName = subName
  2312. }
  2313. if dataBody["initiate_mode"] == nil || reflect.TypeOf(dataBody["initiate_mode"]).String() != "float64" {
  2314. utils.ErrorLog("initiate_mode")
  2315. code = enums.ErrorCodeParamWrong
  2316. return
  2317. }
  2318. initiateMode := int64(dataBody["initiate_mode"].(float64))
  2319. if initiateMode != 1 && initiateMode != 2 {
  2320. utils.ErrorLog("initiateMode != 1 && initiateMode != 2")
  2321. code = enums.ErrorCodeParamWrong
  2322. return
  2323. }
  2324. solution.InitiateMode = initiateMode
  2325. if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  2326. utils.ErrorLog("doctor")
  2327. code = enums.ErrorCodeParamWrong
  2328. return
  2329. }
  2330. doctor := int64(dataBody["doctor"].(float64))
  2331. if doctor <= 0 {
  2332. utils.ErrorLog("doctor <= 0")
  2333. code = enums.ErrorCodeParamWrong
  2334. return
  2335. }
  2336. solution.Doctor = doctor
  2337. return
  2338. }
  2339. func patientFormData(patient *models.Patients, data []byte, method string) (contagions []int64, diseases []int64, code int, formItems []*models.FormItem) {
  2340. patientBody := make(map[string]interface{}, 0)
  2341. err := json.Unmarshal(data, &patientBody)
  2342. if err != nil {
  2343. utils.ErrorLog(err.Error())
  2344. code = enums.ErrorCodeParamWrong
  2345. return
  2346. }
  2347. if patientBody["formItem"] != nil && reflect.TypeOf(patientBody["formItem"]).String() == "[]interface {}" {
  2348. formItem, _ := patientBody["formItem"].([]interface{})
  2349. if len(formItem) > 0 {
  2350. for _, item := range formItem {
  2351. items := item.(map[string]interface{})
  2352. project_name, _ := items["project_name"].(string)
  2353. fmt.Println(project_name)
  2354. range_type := int64(items["range_type"].(float64))
  2355. fmt.Println(range_type)
  2356. project_id := int64(items["project_id"].(float64))
  2357. fmt.Println(project_id)
  2358. item_id := int64(items["item_id"].(float64))
  2359. fmt.Println(item_id)
  2360. item, _ := items["item"].(string)
  2361. fmt.Println(items["item"].(string))
  2362. item_name, _ := items["item_name"].(string)
  2363. fmt.Println(item_name)
  2364. value, _ := items["value"].(string)
  2365. fmt.Println(items["value"].(string))
  2366. var form models.FormItem
  2367. form.ProjectName = project_name
  2368. form.RangeType = range_type
  2369. form.ProjectId = project_id
  2370. form.ItemId = item_id
  2371. form.Item = item
  2372. form.ItemName = item_name
  2373. form.Value = value
  2374. formItems = append(formItems, &form)
  2375. }
  2376. }
  2377. }
  2378. if patientBody["avatar"] == nil || reflect.TypeOf(patientBody["avatar"]).String() != "string" {
  2379. utils.ErrorLog("avatar")
  2380. code = enums.ErrorCodeParamWrong
  2381. return
  2382. }
  2383. avatar, _ := patientBody["avatar"].(string)
  2384. if len(avatar) == 0 {
  2385. utils.ErrorLog("len(avatar) == 0")
  2386. code = enums.ErrorCodeParamWrong
  2387. return
  2388. }
  2389. patient.Avatar = avatar
  2390. if patientBody["name"] == nil || reflect.TypeOf(patientBody["name"]).String() != "string" {
  2391. utils.ErrorLog("name")
  2392. code = enums.ErrorCodeParamWrong
  2393. return
  2394. }
  2395. name, _ := patientBody["name"].(string)
  2396. if len(name) == 0 {
  2397. utils.ErrorLog("len(name) == 0")
  2398. code = enums.ErrorCodeParamWrong
  2399. return
  2400. }
  2401. patient.Name = name
  2402. if patientBody["alias"] != nil && reflect.TypeOf(patientBody["alias"]).String() == "string" {
  2403. alias := patientBody["alias"].(string)
  2404. patient.Alias = alias
  2405. }
  2406. if patientBody["nation"] != nil && reflect.TypeOf(patientBody["nation"]).String() == "string" {
  2407. nation := patientBody["nation"].(string)
  2408. patient.Nation = nation
  2409. }
  2410. if patientBody["native_place"] != nil && reflect.TypeOf(patientBody["native_place"]).String() == "string" {
  2411. native_place := patientBody["native_place"].(string)
  2412. patient.NativePlace = native_place
  2413. }
  2414. if patientBody["idCardNo"] == nil || reflect.TypeOf(patientBody["idCardNo"]).String() != "string" {
  2415. utils.ErrorLog("idCardNo")
  2416. code = enums.ErrorCodeParamWrong
  2417. return
  2418. }
  2419. idCardNo, _ := patientBody["idCardNo"].(string)
  2420. if len(idCardNo) == 0 {
  2421. utils.ErrorLog("len(idCardNo) == 0")
  2422. code = enums.ErrorCodeParamWrong
  2423. return
  2424. }
  2425. patient.IdCardNo = idCardNo
  2426. patient.PatientType = 1
  2427. if patientBody["dialysisNo"] == nil || reflect.TypeOf(patientBody["dialysisNo"]).String() != "string" {
  2428. utils.ErrorLog("dialysisNo")
  2429. code = enums.ErrorCodeParamWrong
  2430. return
  2431. }
  2432. dialysisNo, _ := patientBody["dialysisNo"].(string)
  2433. if len(dialysisNo) == 0 {
  2434. utils.ErrorLog("len(dialysisNo) == 0")
  2435. code = enums.ErrorCodeParamWrong
  2436. return
  2437. }
  2438. patient.DialysisNo = dialysisNo
  2439. // }
  2440. if patientBody["lapseto"] == nil || reflect.TypeOf(patientBody["lapseto"]).String() != "float64" {
  2441. utils.ErrorLog("lapseto")
  2442. code = enums.ErrorCodeParamWrong
  2443. return
  2444. }
  2445. lapseto := int64(patientBody["lapseto"].(float64))
  2446. if lapseto <= 0 {
  2447. utils.ErrorLog("lapseto == 0")
  2448. code = enums.ErrorCodeParamWrong
  2449. return
  2450. }
  2451. patient.Lapseto = lapseto
  2452. if patientBody["gender"] == nil || reflect.TypeOf(patientBody["gender"]).String() != "float64" {
  2453. utils.ErrorLog("gender")
  2454. code = enums.ErrorCodeParamWrong
  2455. return
  2456. }
  2457. gender := int64(patientBody["gender"].(float64))
  2458. if gender <= 0 {
  2459. utils.ErrorLog("gender <= 0")
  2460. code = enums.ErrorCodeParamWrong
  2461. return
  2462. }
  2463. patient.Gender = gender
  2464. if patientBody["response_result"] != nil && reflect.TypeOf(patientBody["response_result"]).String() == "string" {
  2465. response_result := patientBody["response_result"].(string)
  2466. patient.ResponseResult = response_result
  2467. }
  2468. if patientBody["age"] == nil || reflect.TypeOf(patientBody["age"]).String() != "float64" {
  2469. utils.ErrorLog("age")
  2470. code = enums.ErrorCodeParamWrong
  2471. return
  2472. }
  2473. age := int64(patientBody["age"].(float64))
  2474. patient.Age = age
  2475. timeLayout := "2006-01-02"
  2476. loc, _ := time.LoadLocation("Local")
  2477. if patientBody["birth"] == nil || reflect.TypeOf(patientBody["birth"]).String() != "string" {
  2478. utils.ErrorLog("birth")
  2479. code = enums.ErrorCodeParamWrong
  2480. return
  2481. }
  2482. birth, _ := patientBody["birth"].(string)
  2483. if len(birth) == 0 {
  2484. utils.ErrorLog("len(birth) == 0")
  2485. code = enums.ErrorCodeParamWrong
  2486. return
  2487. }
  2488. birthTime, err := time.ParseInLocation(timeLayout, birth, loc)
  2489. if err != nil {
  2490. utils.ErrorLog("birthTime")
  2491. code = enums.ErrorCodeParamWrong
  2492. return
  2493. }
  2494. patient.Birthday = birthTime.Unix()
  2495. if patientBody["height"] != nil && reflect.TypeOf(patientBody["height"]).String() == "string" {
  2496. height, _ := strconv.ParseInt(patientBody["height"].(string), 10, 64)
  2497. patient.Height = height
  2498. }
  2499. if patientBody["maritalStatus"] != nil && reflect.TypeOf(patientBody["maritalStatus"]).String() == "float64" {
  2500. maritalStatus := int64(patientBody["maritalStatus"].(float64))
  2501. patient.MaritalStatus = maritalStatus
  2502. }
  2503. if patientBody["children"] != nil && reflect.TypeOf(patientBody["children"]).String() == "string" {
  2504. children, _ := strconv.ParseInt(patientBody["children"].(string), 10, 64)
  2505. patient.Children = children
  2506. }
  2507. if patientBody["admissionNumber"] != nil && reflect.TypeOf(patientBody["admissionNumber"]).String() == "string" {
  2508. admissionNumber, _ := patientBody["admissionNumber"].(string)
  2509. patient.AdmissionNumber = admissionNumber
  2510. }
  2511. if patientBody["reimbursementWayID"] != nil && reflect.TypeOf(patientBody["reimbursementWayID"]).String() == "float64" {
  2512. reimbursementWayID := int64(patientBody["reimbursementWayID"].(float64))
  2513. patient.ReimbursementWayId = reimbursementWayID
  2514. }
  2515. if patientBody["healthCareNo"] != nil && reflect.TypeOf(patientBody["healthCareNo"]).String() == "string" {
  2516. healthCareNo := patientBody["healthCareNo"].(string)
  2517. patient.HealthCareNo = healthCareNo
  2518. }
  2519. if patientBody["phone"] == nil || reflect.TypeOf(patientBody["phone"]).String() != "string" {
  2520. utils.ErrorLog("phone")
  2521. code = enums.ErrorCodeParamWrong
  2522. return
  2523. }
  2524. phone := patientBody["phone"].(string)
  2525. if len(phone) == 0 {
  2526. utils.ErrorLog("len(phone) == 0")
  2527. code = enums.ErrorCodeParamWrong
  2528. return
  2529. }
  2530. if !utils.CheckMobile(phone) {
  2531. utils.ErrorLog("!phone")
  2532. code = enums.ErrorCodeMobileFormat
  2533. return
  2534. }
  2535. patient.Phone = phone
  2536. if patientBody["homeTelephone"] != nil && reflect.TypeOf(patientBody["homeTelephone"]).String() == "string" {
  2537. homeTelephone := patientBody["homeTelephone"].(string)
  2538. patient.HomeTelephone = homeTelephone
  2539. }
  2540. if patientBody["relative_phone"] != nil && reflect.TypeOf(patientBody["relative_phone"]).String() == "string" {
  2541. relativePhone := patientBody["relative_phone"].(string)
  2542. patient.RelativePhone = relativePhone
  2543. }
  2544. if patientBody["relative_relations"] != nil && reflect.TypeOf(patientBody["relative_relations"]).String() == "string" {
  2545. relativeRelations := patientBody["relative_relations"].(string)
  2546. patient.RelativeRelations = relativeRelations
  2547. }
  2548. if patientBody["homeAddress"] != nil && reflect.TypeOf(patientBody["homeAddress"]).String() == "string" {
  2549. homeAddress := patientBody["homeAddress"].(string)
  2550. patient.HomeAddress = homeAddress
  2551. }
  2552. if patientBody["work"] != nil && reflect.TypeOf(patientBody["work"]).String() == "string" {
  2553. work := patientBody["work"].(string)
  2554. patient.WorkUnit = work
  2555. }
  2556. if patientBody["unit_address"] != nil && reflect.TypeOf(patientBody["unit_address"]).String() == "string" {
  2557. unitAddress := patientBody["unit_address"].(string)
  2558. patient.UnitAddress = unitAddress
  2559. }
  2560. if patientBody["profession"] != nil && reflect.TypeOf(patientBody["profession"]).String() == "float64" {
  2561. profession := int64(patientBody["profession"].(float64))
  2562. patient.Profession = profession
  2563. }
  2564. if patientBody["education"] != nil && reflect.TypeOf(patientBody["education"]).String() == "float64" {
  2565. education := int64(patientBody["education"].(float64))
  2566. patient.EducationLevel = education
  2567. }
  2568. if patientBody["source"] == nil || reflect.TypeOf(patientBody["source"]).String() != "float64" {
  2569. utils.ErrorLog("source")
  2570. code = enums.ErrorCodeParamWrong
  2571. return
  2572. }
  2573. source := int64(patientBody["source"].(float64))
  2574. if source <= 0 {
  2575. utils.ErrorLog("source <= 0")
  2576. code = enums.ErrorCodeParamWrong
  2577. return
  2578. }
  2579. patient.Source = source
  2580. if patientBody["is_hospital_first_dialysis"] != nil && reflect.TypeOf(patientBody["is_hospital_first_dialysis"]).String() == "float64" {
  2581. isHospitalFirstDialysis := int64(patientBody["is_hospital_first_dialysis"].(float64))
  2582. patient.IsHospitalFirstDialysis = isHospitalFirstDialysis
  2583. }
  2584. if patientBody["firstDialysisDate"] != nil && reflect.TypeOf(patientBody["firstDialysisDate"]).String() == "string" {
  2585. firstDialysisDate := patientBody["firstDialysisDate"].(string)
  2586. firstDialysisDateTime, err := time.ParseInLocation(timeLayout, firstDialysisDate, loc)
  2587. if err == nil {
  2588. patient.FirstDialysisDate = firstDialysisDateTime.Unix()
  2589. }
  2590. }
  2591. if patientBody["first_dialysis_hospital"] != nil && reflect.TypeOf(patientBody["first_dialysis_hospital"]).String() == "string" {
  2592. firstDialysisHospital := patientBody["first_dialysis_hospital"].(string)
  2593. patient.FirstDialysisHospital = firstDialysisHospital
  2594. }
  2595. if patientBody["predialysis_condition"] != nil && reflect.TypeOf(patientBody["predialysis_condition"]).String() == "[]interface {}" {
  2596. thePredialysisCondition, _ := patientBody["predialysis_condition"].([]interface{})
  2597. if len(thePredialysisCondition) > 0 {
  2598. conditions := make([]string, 0)
  2599. for _, item := range thePredialysisCondition {
  2600. if reflect.TypeOf(item).String() != "string" {
  2601. continue
  2602. }
  2603. condition := item.(string)
  2604. if len(condition) > 0 {
  2605. conditions = append(conditions, condition)
  2606. }
  2607. }
  2608. patient.PredialysisCondition = strings.Join(conditions, ",")
  2609. }
  2610. }
  2611. if patientBody["pre_hospital_dialysis_frequency"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_frequency"]).String() == "string" {
  2612. preHospitalDialysisFrequency := patientBody["pre_hospital_dialysis_frequency"].(string)
  2613. patient.PreHospitalDialysisFrequency = preHospitalDialysisFrequency
  2614. }
  2615. if patientBody["pre_hospital_dialysis_times"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_times"]).String() == "string" {
  2616. preHospitalDialysisTimes, _ := strconv.ParseInt(patientBody["pre_hospital_dialysis_times"].(string), 10, 64)
  2617. patient.PreHospitalDialysisTimes = preHospitalDialysisTimes
  2618. }
  2619. if patientBody["hospital_first_dialysis_date"] != nil && reflect.TypeOf(patientBody["hospital_first_dialysis_date"]).String() == "string" {
  2620. hospitalFirstDialysisDate := patientBody["hospital_first_dialysis_date"].(string)
  2621. hospitalFirstDialysisDateTime, err := time.ParseInLocation(timeLayout, hospitalFirstDialysisDate, loc)
  2622. if err == nil {
  2623. patient.HospitalFirstDialysisDate = hospitalFirstDialysisDateTime.Unix()
  2624. }
  2625. }
  2626. if patientBody["partition"] != nil && reflect.TypeOf(patientBody["partition"]).String() == "float64" {
  2627. partition := int64(patientBody["partition"].(float64))
  2628. patient.PartitionId = partition
  2629. }
  2630. if patientBody["bed"] != nil && reflect.TypeOf(patientBody["bed"]).String() == "string" {
  2631. bed, _ := strconv.ParseInt(patientBody["bed"].(string), 10, 64)
  2632. patient.BedId = bed
  2633. }
  2634. if patientBody["healthCareDueDate"] != nil && reflect.TypeOf(patientBody["healthCareDueDate"]).String() == "string" {
  2635. healthCareDueDate := patientBody["healthCareDueDate"].(string)
  2636. healthCareDueDateTime, err := time.ParseInLocation(timeLayout, healthCareDueDate, loc)
  2637. if err == nil {
  2638. patient.HealthCareDueDate = healthCareDueDateTime.Unix()
  2639. }
  2640. }
  2641. if patientBody["blood"] != nil && reflect.TypeOf(patientBody["blood"]).String() == "float64" {
  2642. blood := int64(patientBody["blood"].(float64))
  2643. patient.BloodType = blood
  2644. }
  2645. if patientBody["rh"] != nil && reflect.TypeOf(patientBody["rh"]).String() == "float64" {
  2646. rh := int64(patientBody["rh"].(float64))
  2647. patient.Rh = rh
  2648. }
  2649. if patientBody["healthCareDueAlertDate"] != nil && reflect.TypeOf(patientBody["healthCareDueAlertDate"]).String() == "string" {
  2650. healthCareDueAlertDate := patientBody["healthCareDueAlertDate"].(string)
  2651. healthCareDueAlertDateTime, err := time.ParseInLocation(timeLayout, healthCareDueAlertDate, loc)
  2652. if err == nil {
  2653. patient.HealthCareDueAlertDate = healthCareDueAlertDateTime.Unix()
  2654. }
  2655. }
  2656. if patientBody["receivingDate"] != nil && reflect.TypeOf(patientBody["receivingDate"]).String() == "string" {
  2657. receivingDate := patientBody["receivingDate"].(string)
  2658. receivingDateTime, err := time.ParseInLocation(timeLayout, receivingDate, loc)
  2659. if err == nil {
  2660. patient.ReceivingDate = receivingDateTime.Unix()
  2661. }
  2662. }
  2663. if patientBody["induction"] != nil && reflect.TypeOf(patientBody["induction"]).String() == "float64" {
  2664. induction := int64(patientBody["induction"].(float64))
  2665. patient.InductionPeriod = induction
  2666. }
  2667. if patientBody["initial"] != nil && reflect.TypeOf(patientBody["initial"]).String() == "string" {
  2668. initial, _ := strconv.ParseInt(patientBody["initial"].(string), 10, 64)
  2669. patient.InitialDialysis = initial
  2670. }
  2671. if patientBody["dialysisTotal"] != nil && reflect.TypeOf(patientBody["dialysisTotal"]).String() == "string" {
  2672. dialysisTotal, _ := strconv.ParseInt(patientBody["dialysisTotal"].(string), 10, 64)
  2673. patient.TotalDialysis = dialysisTotal
  2674. }
  2675. if patientBody["contagions"] != nil && reflect.TypeOf(patientBody["contagions"]).String() == "[]interface {}" {
  2676. thisContagions, _ := patientBody["contagions"].([]interface{})
  2677. if len(thisContagions) > 0 {
  2678. for _, item := range thisContagions {
  2679. if reflect.TypeOf(item).String() != "float64" {
  2680. continue
  2681. }
  2682. contagion := int64(item.(float64))
  2683. if contagion > 0 {
  2684. contagions = append(contagions, contagion)
  2685. }
  2686. }
  2687. }
  2688. }
  2689. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  2690. doctor := int64(patientBody["doctor"].(float64))
  2691. patient.AttendingDoctorId = doctor
  2692. }
  2693. if patientBody["nurse"] != nil && reflect.TypeOf(patientBody["nurse"]).String() == "float64" {
  2694. nurse := int64(patientBody["nurse"].(float64))
  2695. patient.HeadNurseId = nurse
  2696. }
  2697. if patientBody["assessment"] != nil && reflect.TypeOf(patientBody["assessment"]).String() == "string" {
  2698. assessment := patientBody["assessment"].(string)
  2699. patient.Evaluate = assessment
  2700. }
  2701. if patientBody["diseases"] != nil && reflect.TypeOf(patientBody["diseases"]).String() == "[]interface {}" {
  2702. thisDiseases, _ := patientBody["diseases"].([]interface{})
  2703. if len(thisDiseases) > 0 {
  2704. for _, item := range thisDiseases {
  2705. if reflect.TypeOf(item).String() != "float64" {
  2706. continue
  2707. }
  2708. disease := int64(item.(float64))
  2709. if disease > 0 {
  2710. diseases = append(diseases, disease)
  2711. }
  2712. }
  2713. }
  2714. }
  2715. if patientBody["diagnose"] != nil && reflect.TypeOf(patientBody["diagnose"]).String() == "string" {
  2716. diagnose := patientBody["diagnose"].(string)
  2717. patient.Diagnose = diagnose
  2718. }
  2719. if patientBody["remark"] != nil && reflect.TypeOf(patientBody["remark"]).String() == "string" {
  2720. remark := patientBody["remark"].(string)
  2721. patient.Remark = remark
  2722. }
  2723. if patientBody["patient_complains"] != nil && reflect.TypeOf(patientBody["patient_complains"]).String() == "string" {
  2724. patient_complains := patientBody["patient_complains"].(string)
  2725. patient.PatientComplains = patient_complains
  2726. }
  2727. if patientBody["present_history"] != nil && reflect.TypeOf(patientBody["present_history"]).String() == "string" {
  2728. present_history := patientBody["present_history"].(string)
  2729. patient.PresentHistory = present_history
  2730. }
  2731. if patientBody["past_history"] != nil && reflect.TypeOf(patientBody["past_history"]).String() == "string" {
  2732. past_history := patientBody["past_history"].(string)
  2733. patient.PastHistory = past_history
  2734. }
  2735. if patientBody["temperature"] != nil && reflect.TypeOf(patientBody["temperature"]).String() == "string" {
  2736. temperature, _ := strconv.ParseFloat(patientBody["temperature"].(string), 64)
  2737. patient.Temperature = temperature
  2738. }
  2739. if patientBody["pulse"] != nil && reflect.TypeOf(patientBody["pulse"]).String() == "string" {
  2740. pulse, _ := strconv.ParseInt(patientBody["pulse"].(string), 10, 64)
  2741. patient.Pulse = pulse
  2742. }
  2743. if patientBody["respiratory"] != nil && reflect.TypeOf(patientBody["respiratory"]).String() == "string" {
  2744. respiratory, _ := strconv.ParseInt(patientBody["respiratory"].(string), 10, 64)
  2745. patient.Respiratory = respiratory
  2746. }
  2747. if patientBody["sbp"] != nil && reflect.TypeOf(patientBody["sbp"]).String() == "string" {
  2748. sbp, _ := strconv.ParseInt(patientBody["sbp"].(string), 10, 64)
  2749. patient.SBP = sbp
  2750. }
  2751. if patientBody["dbp"] != nil && reflect.TypeOf(patientBody["dbp"]).String() == "string" {
  2752. dbp, _ := strconv.ParseInt(patientBody["dbp"].(string), 10, 64)
  2753. patient.DBP = dbp
  2754. }
  2755. if patientBody["dialysis_age"] != nil && reflect.TypeOf(patientBody["dialysis_age"]).String() == "string" {
  2756. dialysis_age, _ := strconv.ParseInt(patientBody["dialysis_age"].(string), 10, 64)
  2757. patient.DialysisAge = dialysis_age
  2758. }
  2759. fmt.Println(patient.DialysisAge)
  2760. if patientBody["first_treatment_date"] != nil && reflect.TypeOf(patientBody["first_treatment_date"]).String() == "string" {
  2761. first_treatment_date := patientBody["first_treatment_date"].(string)
  2762. first_treatment_time, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  2763. if err == nil {
  2764. patient.FirstTreatmentDate = first_treatment_time.Unix()
  2765. }
  2766. }
  2767. if patientBody["expense_kind"] != nil && reflect.TypeOf(patientBody["expense_kind"]).String() == "float64" {
  2768. expense_kind := int64(patientBody["expense_kind"].(float64))
  2769. patient.ExpenseKind = expense_kind
  2770. }
  2771. fmt.Println(patient.ExpenseKind)
  2772. if patientBody["tell_phone"] != nil && reflect.TypeOf(patientBody["tell_phone"]).String() == "string" {
  2773. tell_phone := patientBody["tell_phone"].(string)
  2774. patient.TellPhone = tell_phone
  2775. }
  2776. if patientBody["contact_name"] != nil && reflect.TypeOf(patientBody["contact_name"]).String() == "string" {
  2777. contact_name := patientBody["contact_name"].(string)
  2778. patient.ContactName = contact_name
  2779. }
  2780. return
  2781. }
  2782. func (c *PatientApiController) GetPatientsByKeyWord() {
  2783. keyWord := c.GetString("keyword")
  2784. adminUserInfo := c.GetAdminUserInfo()
  2785. patient, err := service.GetPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  2786. if err != nil {
  2787. utils.ErrorLog(err.Error())
  2788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2789. return
  2790. }
  2791. c.ServeSuccessJSON(map[string]interface{}{
  2792. "patient": patient,
  2793. })
  2794. }
  2795. func (c *PatientApiController) QueryPatientById() {
  2796. id, _ := c.GetInt64("id")
  2797. fmt.Println(id)
  2798. patientInfo := service.QueryPatientById(id)
  2799. c.ServeSuccessJSON(map[string]interface{}{
  2800. "patient": patientInfo,
  2801. })
  2802. return
  2803. }
  2804. func (c *PatientApiController) GetRemindPatientList() {
  2805. page, _ := c.GetInt64("page", 1)
  2806. limit, _ := c.GetInt64("limit", 10)
  2807. adminUserInfo := c.GetAdminUserInfo()
  2808. total, patients, err := service.GetAllWaitRemindPatient(adminUserInfo.CurrentOrgId, page, limit)
  2809. if err != nil {
  2810. utils.ErrorLog(err.Error())
  2811. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2812. return
  2813. }
  2814. c.ServeSuccessJSON(map[string]interface{}{
  2815. "total": total,
  2816. "patients": patients,
  2817. })
  2818. }
  2819. func (c *PatientApiController) PostIsOpenRemind() {
  2820. patient_id, _ := c.GetInt64("id", 1)
  2821. is_open_remind, _ := c.GetInt64("is_open_remind", 1)
  2822. adminUserInfo := c.GetAdminUserInfo()
  2823. err := service.UpdatePatientRemindStatus(patient_id, is_open_remind, adminUserInfo.CurrentOrgId)
  2824. if err == nil {
  2825. c.ServeSuccessJSON(map[string]interface{}{
  2826. "msg": "成功",
  2827. "is_open_remind": is_open_remind,
  2828. })
  2829. } else if err != nil {
  2830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2831. }
  2832. }