patient_api_controller.go 123KB

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