patient_api_controller.go 110KB

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