patient_api_controller.go 150KB

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