patient_api_controller.go 130KB

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