patient_api_controller.go 126KB

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