patient_api_controller.go 131KB

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