patient_api_controller.go 101KB

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