patient_api_controller.go 124KB

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