patient_api_controller.go 148KB

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