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