patient_api_controller.go 148KB

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