patient_api_controller.go 131KB

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