patient_api_controller.go 126KB

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