patient_api_controller.go 113KB

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