patient_api_controller.go 144KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024
  1. package mobile_api_controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/jinzhu/gorm"
  10. "math"
  11. "strings"
  12. // "fmt"
  13. "reflect"
  14. "strconv"
  15. "time"
  16. )
  17. type PatientApiController struct {
  18. MobileBaseAPIAuthController
  19. }
  20. func (c *PatientApiController) GetPatientInfoWithDiseases() {
  21. id, _ := c.GetInt64("patient", 0)
  22. if id <= 0 {
  23. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  24. return
  25. }
  26. adminUserInfo := c.GetMobileAdminUserInfo()
  27. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  28. if patient.ID == 0 {
  29. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  30. return
  31. }
  32. Registrars, err := service.GetAdminUser(adminUserInfo.Org.Id, adminUserInfo.App.Id, patient.RegistrarsId)
  33. if err != nil {
  34. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. return
  36. }
  37. if Registrars != nil {
  38. patient.Registrars = Registrars.Name
  39. }
  40. c.ServeSuccessJSON(map[string]interface{}{
  41. "patient": patient,
  42. })
  43. return
  44. }
  45. func (c *PatientApiController) CreateDialysisSolution() {
  46. id, _ := c.GetInt64("patient", 0)
  47. if id <= 0 {
  48. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  49. return
  50. }
  51. adminUserInfo := c.GetMobileAdminUserInfo()
  52. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  53. if patient.ID == 0 {
  54. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  55. return
  56. }
  57. //根据路由来做权限
  58. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  59. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  60. //if template.TemplateId == 2 || template.TemplateId == 6 {
  61. // if appRole.UserType == 3 {
  62. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  63. // if getPermissionErr != nil {
  64. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  65. // return
  66. // } else if headNursePermission == nil {
  67. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  68. // return
  69. // }
  70. // }
  71. //}
  72. var solution models.DialysisSolution
  73. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  74. if code > 0 {
  75. c.ServeFailJSONWithSGJErrorCode(code)
  76. return
  77. }
  78. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  79. solution.Doctor = adminUserInfo.AdminUser.Id
  80. solution.Status = 1
  81. solution.PatientId = id
  82. solution.CreatedTime = time.Now().Unix()
  83. solution.UserOrgId = adminUserInfo.Org.Id
  84. solution.UpdatedTime = time.Now().Unix()
  85. solution.SubName = ""
  86. solution.ParentId = 0
  87. err := service.CreatePatientDialysisSolution(&solution)
  88. if err != nil {
  89. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  90. return
  91. }
  92. c.ServeSuccessJSON(map[string]interface{}{
  93. "msg": "ok",
  94. "solution": solution,
  95. })
  96. return
  97. }
  98. func (c *PatientApiController) EditDialysisSolution() {
  99. id, _ := c.GetInt64("id", 0)
  100. if id <= 0 {
  101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  102. return
  103. }
  104. adminUserInfo := c.GetMobileAdminUserInfo()
  105. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.Org.Id, id)
  106. if solution.ID == 0 {
  107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  108. return
  109. }
  110. //if solution.Doctor != adminUserInfo.AdminUser.Id {
  111. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  112. // if getPermissionErr != nil {
  113. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  114. // return
  115. // } else if headNursePermission == nil {
  116. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  117. // return
  118. // }
  119. //}
  120. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "update")
  121. if code > 0 {
  122. c.ServeFailJSONWithSGJErrorCode(code)
  123. return
  124. }
  125. // solution.RegistrarsId = adminUserInfo.AdminUser.Id
  126. solution.Doctor = adminUserInfo.AdminUser.Id
  127. solution.Status = 1
  128. // solution.PatientId = id
  129. // solution.CreatedTime = time.Now().Unix()
  130. // solution.UserOrgId = adminUserInfo.Org.Id
  131. solution.UpdatedTime = time.Now().Unix()
  132. // solution.SubName = ""
  133. // solution.ParentId = 0
  134. err := service.UpdatePatientDialysisSolution(&solution)
  135. if err != nil {
  136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  137. return
  138. }
  139. c.ServeSuccessJSON(map[string]interface{}{
  140. "msg": "ok",
  141. "solution": solution,
  142. })
  143. return
  144. }
  145. func (c *PatientApiController) CreateDoctorAdvice() {
  146. patient, _ := c.GetInt64("id", 0)
  147. if patient <= 0 {
  148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  149. return
  150. }
  151. adminUserInfo := c.GetMobileAdminUserInfo()
  152. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  153. if patientInfo.ID == 0 {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  155. return
  156. }
  157. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  158. //if appRole.UserType == 3{
  159. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdvicePermissionDeniedModify)
  160. // return
  161. //}
  162. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  163. //
  164. //if appRole.UserType == 3 {
  165. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  166. // if getPermissionErr != nil {
  167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  168. // return
  169. // } else if headNursePermission == nil {
  170. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  171. // return
  172. // }
  173. //}
  174. var advice models.DoctorAdvice
  175. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  176. if code > 0 {
  177. c.ServeFailJSONWithSGJErrorCode(code)
  178. return
  179. }
  180. if advice.ParentId > 0 {
  181. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  182. if old.ID == 0 || old.PatientId != patient {
  183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  184. return
  185. }
  186. if old.StopState == 1 || old.ExecutionState == 1 {
  187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  188. return
  189. }
  190. if old.ParentId > 0 {
  191. advice.ParentId = old.ParentId
  192. }
  193. advice.StartTime = old.StartTime
  194. advice.AdviceDoctor = old.AdviceDoctor
  195. advice.DeliveryWay = old.DeliveryWay
  196. advice.ExecutionFrequency = old.ExecutionFrequency
  197. advice.GroupNo = old.GroupNo
  198. }
  199. advice.Status = 1
  200. advice.CreatedTime = time.Now().Unix()
  201. advice.UpdatedTime = time.Now().Unix()
  202. advice.StopState = 2
  203. advice.ExecutionState = 2
  204. advice.UserOrgId = adminUserInfo.Org.Id
  205. advice.PatientId = patient
  206. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  207. err := service.CreateDoctorAdvice(&advice)
  208. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  209. redis := service.RedisClient()
  210. defer redis.Close()
  211. redis.Set(key, "", time.Second)
  212. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  213. redis.Set(keyOne, "", time.Second)
  214. if err != nil {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  216. return
  217. }
  218. c.ServeSuccessJSON(map[string]interface{}{
  219. "msg": "ok",
  220. "advice": advice,
  221. })
  222. return
  223. }
  224. func (c *PatientApiController) EditDoctorAdvice() {
  225. id, _ := c.GetInt64("id", 0)
  226. patient_id, _ := c.GetInt64("patient_id")
  227. doc_advice_date, _ := c.GetInt64("advice_date")
  228. if id <= 0 {
  229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  230. return
  231. }
  232. redis := service.RedisClient()
  233. adminUserInfo := c.GetMobileAdminUserInfo()
  234. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  235. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  236. //
  237. //if appRole.UserType == 3 {
  238. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  239. // if getPermissionErr != nil {
  240. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  241. // return
  242. // } else if headNursePermission == nil {
  243. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  244. // return
  245. // }
  246. //}
  247. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  248. if advice.ID == 0 {
  249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  250. return
  251. }
  252. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  253. if code > 0 {
  254. c.ServeFailJSONWithSGJErrorCode(code)
  255. return
  256. }
  257. advice.Status = 1
  258. advice.UpdatedTime = time.Now().Unix()
  259. advice.UserOrgId = adminUserInfo.Org.Id
  260. advice.Modifier = adminUserInfo.AdminUser.Id
  261. //处理修改医嘱开始时间逻辑(不包括子医嘱)
  262. //1.一组医嘱内只有一条医嘱(不包括子医嘱)的情况下,只需要直接修改医嘱开始时间,不需要重新分配组号
  263. //2.一组医嘱内有多条医嘱(不包括子医嘱)的情况下,需要为修改的那条医嘱重新分配组号,并修改医嘱开始时间
  264. var err error
  265. var isChangeGroup bool
  266. if advice.ParentId == 0 {
  267. adviceSlice, _ := service.FindAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  268. sourceAdvice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice.ID)
  269. if len(adviceSlice) == 1 {
  270. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要修改子医嘱的开始时间,如果相同直接修改,不需要修改子医嘱的开始时间
  271. if advice.StartTime == sourceAdvice.StartTime {
  272. err = service.UpdateDoctorAdvice(&advice)
  273. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  274. defer redis.Close()
  275. redis.Set(key, "", time.Second)
  276. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":advice_list_all"
  277. redis.Set(keyOne, "", time.Second)
  278. isChangeGroup = false
  279. } else {
  280. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  281. isChangeGroup = false
  282. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  283. defer redis.Close()
  284. redis.Set(key, "", time.Second)
  285. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  286. redis.Set(keyOne, "", time.Second)
  287. }
  288. } else if len(adviceSlice) > 1 {
  289. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要重新分配组,如果相同直接修改,不需要分配组
  290. if advice.StartTime == sourceAdvice.StartTime {
  291. err = service.UpdateDoctorAdvice(&advice)
  292. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  293. defer redis.Close()
  294. redis.Set(key, "", time.Second)
  295. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  296. redis.Set(keyOne, "", time.Second)
  297. isChangeGroup = false
  298. } else {
  299. gruopNo := service.GetMaxAdviceGroupID(adminUserInfo.Org.Id)
  300. gruopNo = gruopNo + 1
  301. advice.GroupNo = gruopNo
  302. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  303. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  304. defer redis.Close()
  305. redis.Set(key, "", time.Second)
  306. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  307. redis.Set(keyOne, "", time.Second)
  308. isChangeGroup = true
  309. }
  310. }
  311. } else {
  312. isChangeGroup = false
  313. err = service.UpdateDoctorAdvice(&advice)
  314. redis := service.RedisClient()
  315. defer redis.Close()
  316. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  317. redis.Set(key, "", time.Second)
  318. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  319. redis.Set(keyOne, "", time.Second)
  320. }
  321. if err != nil {
  322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  323. return
  324. }
  325. if !isChangeGroup {
  326. c.ServeSuccessJSON(map[string]interface{}{
  327. "msg": "ok",
  328. "advice": advice,
  329. "isChange": isChangeGroup, //方便前端处理数据
  330. })
  331. } else {
  332. newGroupAdvice, err := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  333. if err != nil {
  334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  335. return
  336. }
  337. c.ServeSuccessJSON(map[string]interface{}{
  338. "msg": "ok",
  339. "advice": newGroupAdvice,
  340. "isChange": isChangeGroup, //方便前端处理数据
  341. })
  342. }
  343. return
  344. }
  345. func (c *PatientApiController) StopDoctorAdvice() {
  346. id, _ := c.GetInt64("id", 0)
  347. if id <= 0 {
  348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  349. return
  350. }
  351. adminUserInfo := c.GetMobileAdminUserInfo()
  352. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  353. if advice.ID == 0 {
  354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  355. return
  356. }
  357. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  358. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  359. // return
  360. //}
  361. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  362. //
  363. //if appRole.UserType == 3 {
  364. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  365. // if getPermissionErr != nil {
  366. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  367. // return
  368. // } else if headNursePermission == nil {
  369. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  370. // return
  371. // }
  372. //}
  373. if advice.StopState == 1 {
  374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  375. return
  376. }
  377. dataBody := make(map[string]interface{}, 0)
  378. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  379. if err != nil {
  380. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  381. return
  382. }
  383. timeLayout := "2006-01-02"
  384. loc, _ := time.LoadLocation("Local")
  385. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  386. utils.ErrorLog("stop_time")
  387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  388. return
  389. }
  390. stopTime, _ := dataBody["stop_time"].(string)
  391. if len(stopTime) == 0 {
  392. utils.ErrorLog("len(stop_time) == 0")
  393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  394. return
  395. }
  396. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  397. if err != nil {
  398. utils.ErrorLog(err.Error())
  399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  400. return
  401. }
  402. advice.StopTime = theTime.Unix()
  403. if dataBody["stop_reason"] == nil || reflect.TypeOf(dataBody["stop_reason"]).String() != "string" {
  404. utils.ErrorLog("stop_reason")
  405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  406. return
  407. }
  408. stopReason, _ := dataBody["stop_reason"].(string)
  409. if len(stopReason) == 0 {
  410. utils.ErrorLog("len(stop_reason) == 0")
  411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  412. return
  413. }
  414. advice.StopReason = stopReason
  415. advice.Status = 1
  416. advice.UpdatedTime = time.Now().Unix()
  417. advice.StopDoctor = adminUserInfo.AdminUser.Id
  418. advice.StopState = 1
  419. advice.StopTime = time.Now().Unix()
  420. advice.Modifier = adminUserInfo.AdminUser.Id
  421. err = service.StopDoctorAdvice(&advice)
  422. if err != nil {
  423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  424. return
  425. }
  426. c.ServeSuccessJSON(map[string]interface{}{
  427. "msg": "ok",
  428. "advice": advice,
  429. })
  430. return
  431. }
  432. func (c *PatientApiController) DeleteDoctorAdvice() {
  433. id, _ := c.GetInt64("id", 0)
  434. if id <= 0 {
  435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  436. return
  437. }
  438. adminUserInfo := c.GetMobileAdminUserInfo()
  439. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  440. if advice.ID == 0 {
  441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  442. return
  443. }
  444. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  445. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  446. // return
  447. //}
  448. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  449. //
  450. //if appRole.UserType == 3 {
  451. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  452. // if getPermissionErr != nil {
  453. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  454. // return
  455. // } else if headNursePermission == nil {
  456. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  457. // return
  458. // }
  459. //}
  460. advice.UpdatedTime = time.Now().Unix()
  461. advice.Status = 0
  462. advice.Modifier = adminUserInfo.AdminUser.Id
  463. err := service.DeleteDoctorAdvice(&advice)
  464. if err != nil {
  465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  466. return
  467. }
  468. c.ServeSuccessJSON(map[string]interface{}{
  469. "msg": "ok",
  470. })
  471. return
  472. }
  473. func (c *PatientApiController) ExecDoctorAdvice() {
  474. execution_time := c.GetString("execution_time")
  475. origin, _ := c.GetInt64("origin", 0)
  476. groupno, _ := c.GetInt64("groupno", -1)
  477. if origin != 2 {
  478. var ids []string
  479. if groupno == 0 {
  480. advice_ids := c.GetString("advice_id")
  481. ids = strings.Split(advice_ids, ",")
  482. }
  483. if groupno < 0 {
  484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  485. return
  486. }
  487. if len(execution_time) <= 0 {
  488. utils.ErrorLog("execution_time")
  489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  490. return
  491. }
  492. timeLayout2 := "2006-01-02 15:04:05"
  493. loc, _ := time.LoadLocation("Local")
  494. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  495. if errs != nil {
  496. utils.ErrorLog(errs.Error())
  497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  498. return
  499. }
  500. adminUserInfo := c.GetMobileAdminUserInfo()
  501. var advice models.DoctorAdvice
  502. if groupno > 0 {
  503. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  504. for _, item := range advices {
  505. if item.ExecutionState == 2 {
  506. advice = item
  507. }
  508. }
  509. } else {
  510. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  511. for _, item := range advices {
  512. if item.ExecutionState == 2 {
  513. advice = item
  514. }
  515. }
  516. }
  517. if advice.ExecutionState == 1 {
  518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  519. return
  520. }
  521. if advice.Checker >= 0 && advice.Checker == adminUserInfo.AdminUser.Id {
  522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  523. return
  524. }
  525. if advice.StartTime > theTime.Unix() {
  526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  527. return
  528. }
  529. execution_staff := adminUserInfo.AdminUser.Id
  530. advices := models.DoctorAdvice{
  531. ExecutionStaff: execution_staff,
  532. ExecutionTime: theTime.Unix(),
  533. UpdatedTime: time.Now().Unix(),
  534. }
  535. var err error
  536. if groupno > 0 {
  537. err = service.ExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  538. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  539. redis := service.RedisClient()
  540. //清空key 值
  541. redis.Set(key, "", time.Second)
  542. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  543. redis.Set(keyTwo, "", time.Second)
  544. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  545. redis.Set(keyThree, "", time.Second)
  546. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  547. theTime := toTime.Format("2006-01-02")
  548. fmt.Println("theTIME", theTime)
  549. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  550. fmt.Println("keyFour323223323232323232", keyFour)
  551. redis.Set(keyFour, "", time.Second)
  552. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  553. redis.Set(keyFive, "", time.Second)
  554. defer redis.Close()
  555. } else {
  556. err = service.BatchExceOldDoctorAdvice(&advices, ids)
  557. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  558. redis := service.RedisClient()
  559. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  560. redis.Set(keyTwo, "", time.Second)
  561. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  562. redis.Set(keyThree, "", time.Second)
  563. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  564. theTime := toTime.Format("2006-01-02")
  565. fmt.Println("theTIME", theTime)
  566. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  567. fmt.Println("keyFour323223323232323232", keyFour)
  568. redis.Set(keyFour, "", time.Second)
  569. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  570. redis.Set(keySix, "", time.Second)
  571. defer redis.Close()
  572. //清空key 值
  573. redis.Set(key, "", time.Second)
  574. }
  575. if err != nil {
  576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  577. return
  578. }
  579. advice.ExecutionStaff = execution_staff
  580. advice.ExecutionTime = theTime.Unix()
  581. advice.ExecutionState = 1
  582. advice.Modifier = adminUserInfo.AdminUser.Id
  583. //处理出库相关逻辑
  584. //1.判断是否启用药品管理和自备药出库功能
  585. //药品管理信息
  586. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  587. //自备药信息
  588. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
  589. if drugStockConfig.IsOpen == 1 {
  590. if groupno > 0 {
  591. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  592. isHasWay := false //用来判断是否包含来自药品库的医嘱
  593. for _, item := range advices {
  594. if item.Way == 1 {
  595. isHasWay = true
  596. }
  597. }
  598. if isHasWay {
  599. var total int64
  600. var prescribing_number_total int64
  601. for _, item := range advices {
  602. if item.Way == 1 {
  603. //查询该药品的剩余库存
  604. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
  605. //查询改药品信息
  606. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  607. //判断单位是否相等
  608. if medical.MaxUnit == item.PrescribingNumberUnit {
  609. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  610. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  611. //转化为最小单位
  612. total = list.Count * medical.MinNumber
  613. prescribing_number_total = count * medical.MinNumber
  614. }
  615. if medical.MinUnit == item.PrescribingNumberUnit {
  616. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  617. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  618. total = list.Count*medical.MinNumber + list.StockMinNumber
  619. prescribing_number_total = count
  620. }
  621. fmt.Println("开医嘱数量", prescribing_number_total)
  622. fmt.Println("剩余库存", total)
  623. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  624. c.ServeSuccessJSON(map[string]interface{}{
  625. "msg": "3",
  626. "advice": advice,
  627. "ids": ids,
  628. })
  629. return
  630. }
  631. if prescribing_number_total > total {
  632. c.ServeSuccessJSON(map[string]interface{}{
  633. "msg": "2",
  634. "advice": advice,
  635. "ids": ids,
  636. })
  637. return
  638. }
  639. if prescribing_number_total <= total {
  640. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  641. c.ServeSuccessJSON(map[string]interface{}{
  642. "msg": "1",
  643. "advice": advice,
  644. "ids": ids,
  645. })
  646. return
  647. }
  648. }
  649. }
  650. }
  651. } else {
  652. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  653. isHasWay := false //用来判断是否包含来自药品库的医嘱
  654. for _, item := range advices {
  655. if item.Way == 1 {
  656. isHasWay = true
  657. }
  658. }
  659. if isHasWay {
  660. var total int64
  661. var prescribing_number_total int64
  662. for _, item := range advices {
  663. if item.Way == 1 {
  664. //查询该药品的剩余库存
  665. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
  666. //查询改药品信息
  667. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  668. //判断单位是否相等
  669. if medical.MaxUnit == item.PrescribingNumberUnit {
  670. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  671. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  672. //转化为最小单位
  673. total = list.Count*medical.MinNumber + list.StockMinNumber
  674. fmt.Println("美国疫情2332323233232323232332323232233232323232", total)
  675. prescribing_number_total = count * medical.MinNumber
  676. }
  677. if medical.MinUnit == item.PrescribingNumberUnit {
  678. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  679. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  680. total = list.Count*medical.MinNumber + list.StockMinNumber
  681. prescribing_number_total = count
  682. }
  683. fmt.Println("开医嘱数量", prescribing_number_total)
  684. fmt.Println("剩余库存", total)
  685. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  686. c.ServeSuccessJSON(map[string]interface{}{
  687. "msg": "3",
  688. "advice": advice,
  689. "ids": ids,
  690. })
  691. return
  692. }
  693. if prescribing_number_total > total {
  694. c.ServeSuccessJSON(map[string]interface{}{
  695. "msg": "2",
  696. "advice": advice,
  697. "ids": ids,
  698. })
  699. return
  700. }
  701. if prescribing_number_total <= total {
  702. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  703. c.ServeSuccessJSON(map[string]interface{}{
  704. "msg": "1",
  705. "advice": advice,
  706. "ids": ids,
  707. })
  708. return
  709. }
  710. }
  711. }
  712. }
  713. }
  714. }
  715. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  716. if groupno > 0 {
  717. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  718. for _, item := range advices {
  719. if item.ExecutionState == 1 && item.Way == 2 {
  720. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  721. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  722. timeStr := time.Now().Format("2006-01-02")
  723. timeArr := strings.Split(timeStr, "-")
  724. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  725. total = total + 1
  726. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  727. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  728. number = number + total
  729. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  730. //插入自备药出库单
  731. outStock := models.XtSelfOutStock{
  732. DrugName: item.AdviceName,
  733. DrugNameId: item.DrugNameId,
  734. DrugSpec: item.AdviceDesc,
  735. OutstoreNumber: count,
  736. AdminUserId: adminUserInfo.AdminUser.Id,
  737. StorckTime: item.AdviceDate,
  738. UserOrgId: adminUserInfo.Org.Id,
  739. CreatedTime: time.Now().Unix(),
  740. Status: 1,
  741. PatientId: item.PatientId,
  742. ExitMode: 2,
  743. MedicId: item.DrugId,
  744. StockOutNumber: warehousing_out_order,
  745. }
  746. //查询 该患者是否已出库
  747. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  748. if errcode == gorm.ErrRecordNotFound {
  749. service.CreateOutStock(&outStock)
  750. } else if errcode == nil {
  751. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  752. fmt.Println("err", err)
  753. }
  754. }
  755. }
  756. } else {
  757. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  758. for _, item := range advices {
  759. if item.ExecutionState == 1 && item.Way == 2 {
  760. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  761. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  762. timeStr := time.Now().Format("2006-01-02")
  763. timeArr := strings.Split(timeStr, "-")
  764. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  765. total = total + 1
  766. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  767. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  768. number = number + total
  769. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  770. //插入自备药出库单
  771. outStock := models.XtSelfOutStock{
  772. DrugName: item.AdviceName,
  773. DrugNameId: item.DrugNameId,
  774. DrugSpec: item.AdviceDesc,
  775. OutstoreNumber: count,
  776. AdminUserId: adminUserInfo.AdminUser.Id,
  777. StorckTime: item.AdviceDate,
  778. UserOrgId: adminUserInfo.Org.Id,
  779. CreatedTime: time.Now().Unix(),
  780. Status: 1,
  781. PatientId: item.PatientId,
  782. ExitMode: 2,
  783. MedicId: item.DrugId,
  784. StockOutNumber: warehousing_out_order,
  785. }
  786. //查询 该患者是否已出库
  787. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  788. if errcode == gorm.ErrRecordNotFound {
  789. service.CreateOutStock(&outStock)
  790. } else if errcode == nil {
  791. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  792. fmt.Println("err", err)
  793. }
  794. }
  795. }
  796. }
  797. }
  798. c.ServeSuccessJSON(map[string]interface{}{
  799. "msg": "1",
  800. "advice": advice,
  801. "ids": ids,
  802. })
  803. return
  804. } else if origin == 2 {
  805. var ids []string
  806. advice_ids := c.GetString("advice_id")
  807. ids = strings.Split(advice_ids, ",")
  808. if len(execution_time) <= 0 {
  809. utils.ErrorLog("execution_time")
  810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  811. return
  812. }
  813. timeLayout2 := "2006-01-02 15:04:05"
  814. loc, _ := time.LoadLocation("Local")
  815. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  816. if errs != nil {
  817. utils.ErrorLog(errs.Error())
  818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  819. return
  820. }
  821. adminInfo := c.GetMobileAdminUserInfo()
  822. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  823. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  824. var err error
  825. for _, item := range advices {
  826. if item.ExecutionState == 1 {
  827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  828. return
  829. }
  830. if item.Checker >= 0 && item.Checker == adminInfo.AdminUser.Id {
  831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  832. return
  833. }
  834. if item.StartTime > theTime.Unix() {
  835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  836. return
  837. }
  838. item.ExecutionState = 1
  839. item.ExecutionStaff = adminInfo.AdminUser.Id
  840. item.ExecutionTime = theTime.Unix()
  841. err = service.SaveHisDoctorAdvice(item)
  842. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  843. redis := service.RedisClient()
  844. //清空key 值
  845. redis.Set(key, "", time.Second)
  846. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  847. redis.Set(keyTwo, "", time.Second)
  848. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  849. redis.Set(keyThree, "", time.Second)
  850. recordDate := theTime.Format("2006-01-02")
  851. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  852. redis.Set(keyFour, "", time.Second)
  853. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  854. redis.Set(keyFive, "", time.Second)
  855. defer redis.Close()
  856. }
  857. if err == nil {
  858. //药品管理信息
  859. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  860. if drugStockConfig.IsOpen == 1 {
  861. for _, item := range advices {
  862. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  863. var total int64
  864. var prescribing_number_total int64
  865. //查询该药品是否有库存
  866. list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId)
  867. //查询改药品信息
  868. medical, _ := service.GetBaseDrugMedical(advice.DrugId)
  869. //判断单位是否相等
  870. if medical.MaxUnit == advice.PrescribingNumberUnit {
  871. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  872. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  873. //转化为最小单位
  874. total = list.Count*medical.MinNumber + list.StockMinNumber
  875. prescribing_number_total = count * medical.MinNumber
  876. }
  877. fmt.Println("医嘱开的数量", total)
  878. if medical.MinUnit == advice.PrescribingNumberUnit {
  879. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  880. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  881. total = list.Count*medical.MinNumber + list.StockMinNumber
  882. prescribing_number_total = count
  883. }
  884. fmt.Println("数量一", prescribing_number_total)
  885. fmt.Println("数量二", total)
  886. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  887. c.ServeSuccessJSON(map[string]interface{}{
  888. "msg": "3",
  889. "advice": advice,
  890. "ids": ids,
  891. })
  892. return
  893. }
  894. if prescribing_number_total > total {
  895. c.ServeSuccessJSON(map[string]interface{}{
  896. "msg": "2",
  897. "advice": advice,
  898. "ids": ids,
  899. })
  900. return
  901. }
  902. if prescribing_number_total <= total {
  903. service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  904. c.ServeSuccessJSON(map[string]interface{}{
  905. "msg": "1",
  906. "advice": advice,
  907. "ids": ids,
  908. })
  909. return
  910. }
  911. }
  912. }
  913. for _, item := range advices {
  914. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  915. c.ServeSuccessJSON(map[string]interface{}{
  916. "msg": "1",
  917. "advice": advice,
  918. "ids": ids,
  919. })
  920. }
  921. } else {
  922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  923. }
  924. }
  925. }
  926. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  927. execution_time := c.GetString("execution_time")
  928. fmt.Println("execution_time", execution_time)
  929. groupno, _ := c.GetInt64("groupno", -1)
  930. var ids []string
  931. if groupno == 0 {
  932. advice_ids := c.GetString("advice_id")
  933. ids = strings.Split(advice_ids, ",")
  934. }
  935. if groupno < 0 {
  936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  937. return
  938. }
  939. if len(execution_time) <= 0 {
  940. utils.ErrorLog("execution_time")
  941. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  942. return
  943. }
  944. timeLayout2 := "2006-01-02 15:04:05"
  945. loc, _ := time.LoadLocation("Local")
  946. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  947. if errs != nil {
  948. utils.ErrorLog(errs.Error())
  949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  950. return
  951. }
  952. adminUserInfo := c.GetMobileAdminUserInfo()
  953. var advice models.DoctorAdvice
  954. if groupno > 0 {
  955. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  956. for _, item := range advices {
  957. if item.ExecutionState == 1 {
  958. advice = item
  959. }
  960. }
  961. } else {
  962. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  963. for _, item := range advices {
  964. if item.ExecutionState == 1 {
  965. advice = item
  966. }
  967. }
  968. }
  969. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  970. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  971. // if getPermissionErr != nil {
  972. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  973. // return
  974. // } else if headNursePermission == nil {
  975. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  976. // return
  977. // }
  978. //}
  979. if advice.StartTime > theTime.Unix() {
  980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  981. return
  982. }
  983. advices := models.DoctorAdvice{
  984. ExecutionTime: theTime.Unix(),
  985. UpdatedTime: time.Now().Unix(),
  986. }
  987. var err error
  988. if groupno > 0 {
  989. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  990. redis := service.RedisClient()
  991. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  992. fmt.Println("keyThh322323232323232323223", key)
  993. redis.Set(key, "", time.Second)
  994. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  995. redis.Set(keyOne, "", time.Second)
  996. defer redis.Close()
  997. } else {
  998. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  999. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1000. redis := service.RedisClient()
  1001. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1002. fmt.Println("keyTwohh322323232323232323223", key)
  1003. redis.Set(key, "", time.Second)
  1004. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1005. redis.Set(keyOne, "", time.Second)
  1006. defer redis.Close()
  1007. }
  1008. //判断是否开启his
  1009. errs, config := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  1010. //如果开启去修改执行时间
  1011. if config.IsOpen == 1 {
  1012. advicesinfo := models.HisDoctorAdviceInfo{
  1013. ExecutionTime: theTime.Unix(),
  1014. UpdatedTime: time.Now().Unix(),
  1015. }
  1016. fmt.Println("ids2323232232323", ids)
  1017. var advicehis models.HisDoctorAdviceInfo
  1018. service.ModifyExceDoctorAdviceById(&advicesinfo, ids)
  1019. his_advices, _ := service.FindHisDoctorAdviceByIdOne(adminUserInfo.Org.Id, ids)
  1020. for _, item := range his_advices {
  1021. if item.ExecutionState == 1 {
  1022. advicehis = item
  1023. }
  1024. }
  1025. redis := service.RedisClient()
  1026. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.PatientId, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_doctor_advice"
  1027. redis.Set(keyThree, "", time.Second)
  1028. recordDate := theTime.Format("2006-01-02")
  1029. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1030. redis.Set(keyFour, "", time.Second)
  1031. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_advices_list_all"
  1032. redis.Set(keyFive, "", time.Second)
  1033. defer redis.Close()
  1034. project := models.HisPrescriptionProject{
  1035. ExecutionTime: theTime.Unix(),
  1036. Mtime: time.Now().Unix(),
  1037. }
  1038. service.ModifyHisPrescriptionProject(&project, ids)
  1039. keyEnd := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.PatientId, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_doctor_advice"
  1040. redis.Set(keyEnd, "", time.Second)
  1041. keyFours := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1042. redis.Set(keyFours, "", time.Second)
  1043. keyFives := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_advices_list_all"
  1044. redis.Set(keyFives, "", time.Second)
  1045. defer redis.Close()
  1046. }
  1047. if err != nil {
  1048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1049. return
  1050. }
  1051. advice.ExecutionTime = theTime.Unix()
  1052. c.ServeSuccessJSON(map[string]interface{}{
  1053. "msg": "ok",
  1054. "advice": advice,
  1055. "ids": ids,
  1056. })
  1057. return
  1058. }
  1059. func (c *PatientApiController) CheckDoctorAdvice() {
  1060. origin, _ := c.GetInt64("origin", 0)
  1061. if origin != 2 {
  1062. groupno, _ := c.GetInt64("groupno", -1)
  1063. var ids []string
  1064. if groupno == 0 {
  1065. advice_ids := c.GetString("advice_id")
  1066. if advice_ids == "" {
  1067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1068. return
  1069. } else {
  1070. ids = strings.Split(advice_ids, ",")
  1071. if len(ids) <= 0 {
  1072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1073. return
  1074. }
  1075. }
  1076. }
  1077. if groupno < 0 {
  1078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1079. return
  1080. }
  1081. adminUserInfo := c.GetMobileAdminUserInfo()
  1082. var advice models.DoctorAdvice
  1083. if groupno > 0 {
  1084. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1085. for _, item := range advices {
  1086. if item.CheckState == 0 {
  1087. advice = item
  1088. }
  1089. }
  1090. if advice.CheckState == 1 {
  1091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1092. return
  1093. }
  1094. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1096. return
  1097. }
  1098. } else {
  1099. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1100. for _, item := range advices {
  1101. if item.CheckState == 0 {
  1102. advice = item
  1103. }
  1104. }
  1105. if advice.CheckState == 1 {
  1106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1107. return
  1108. }
  1109. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1111. return
  1112. }
  1113. }
  1114. checker := adminUserInfo.AdminUser.Id
  1115. theTime := time.Now()
  1116. advices := models.DoctorAdvice{
  1117. CheckTime: theTime.Unix(),
  1118. Checker: checker,
  1119. UpdatedTime: time.Now().Unix(),
  1120. }
  1121. var err error
  1122. if groupno > 0 {
  1123. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1124. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1125. redis := service.RedisClient()
  1126. //清空key 值
  1127. redis.Set(key, "", time.Second)
  1128. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1129. redis.Set(keyTwo, "", time.Second)
  1130. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1131. redis.Set(keyThree, "", time.Second)
  1132. recordDate := theTime.Format("2006-01-02")
  1133. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1134. redis.Set(keyFour, "", time.Second)
  1135. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1136. redis.Set(keyFive, "", time.Second)
  1137. defer redis.Close()
  1138. } else {
  1139. if len(ids[0]) <= 0 {
  1140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1141. return
  1142. } else {
  1143. //t := time.Now().Format("2006-01-02")/**/
  1144. //timeLayout2 := "2006-01-02"
  1145. //loc, _ := time.LoadLocation("Local")
  1146. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  1147. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  1148. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1149. redis := service.RedisClient()
  1150. //清空key 值
  1151. redis.Set(key, "", time.Second)
  1152. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1153. redis.Set(keyTwo, "", time.Second)
  1154. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1155. redis.Set(keyThree, "", time.Second)
  1156. recordDate := theTime.Format("2006-01-02")
  1157. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1158. redis.Set(keyFour, "", time.Second)
  1159. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1160. redis.Set(keyFive, "", time.Second)
  1161. defer redis.Close()
  1162. }
  1163. }
  1164. if err != nil {
  1165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1166. return
  1167. }
  1168. advice.Checker = checker
  1169. advice.CheckTime = theTime.Unix()
  1170. advice.CheckState = 1
  1171. c.ServeSuccessJSON(map[string]interface{}{
  1172. "msg": "ok",
  1173. "advice": advice,
  1174. })
  1175. } else if origin == 2 {
  1176. adminInfo := c.GetMobileAdminUserInfo()
  1177. var ids []string
  1178. advice_ids := c.GetString("advice_id")
  1179. ids = strings.Split(advice_ids, ",")
  1180. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  1181. var err error
  1182. for _, item := range advices {
  1183. if item.CheckState == 1 {
  1184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1185. return
  1186. }
  1187. if item.ExecutionStaff >= 0 && item.ExecutionStaff == adminInfo.AdminUser.Id {
  1188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1189. return
  1190. }
  1191. item.Checker = adminInfo.AdminUser.Id
  1192. item.CheckTime = time.Now().Unix()
  1193. item.CheckState = 1
  1194. err = service.SaveHisDoctorAdvice(item)
  1195. redis := service.RedisClient()
  1196. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1197. //清空key 值
  1198. redis.Set(key, "", time.Second)
  1199. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1200. redis.Set(keyTwo, "", time.Second)
  1201. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1202. redis.Set(keyThree, "", time.Second)
  1203. theTime := time.Now()
  1204. recordDate := theTime.Format("2006-01-02")
  1205. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  1206. redis.Set(keyFour, "", time.Second)
  1207. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1208. redis.Set(keyFive, "", time.Second)
  1209. defer redis.Close()
  1210. }
  1211. if err == nil {
  1212. c.ServeSuccessJSON(map[string]interface{}{
  1213. "msg": "ok",
  1214. "advice": advices,
  1215. })
  1216. } else {
  1217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1218. return
  1219. }
  1220. }
  1221. return
  1222. }
  1223. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  1224. id, _ := c.GetInt64("patient", 0)
  1225. assessmentDate := c.GetString("assessment_date", "")
  1226. if id <= 0 || len(assessmentDate) != 10 {
  1227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1228. return
  1229. }
  1230. timeLayout := "2006-01-02"
  1231. loc, _ := time.LoadLocation("Local")
  1232. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  1233. if err != nil {
  1234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1235. return
  1236. }
  1237. theAssessmentDateTime := theTime.Unix()
  1238. adminUserInfo := c.GetMobileAdminUserInfo()
  1239. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1240. if patient.ID == 0 {
  1241. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1242. return
  1243. }
  1244. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationSeven(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  1245. if getPEErr != nil {
  1246. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  1247. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1248. return
  1249. }
  1250. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1251. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1252. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1253. var evaluation models.PredialysisEvaluation
  1254. if theEvaluation != nil {
  1255. evaluation = *theEvaluation
  1256. }
  1257. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  1258. if code > 0 {
  1259. c.ServeFailJSONWithSGJErrorCode(code)
  1260. return
  1261. }
  1262. if theEvaluation == nil {
  1263. evaluation.CreatedTime = time.Now().Unix()
  1264. evaluation.Status = 1
  1265. evaluation.AssessmentDate = theAssessmentDateTime
  1266. evaluation.PatientId = id
  1267. evaluation.UserOrgId = adminUserInfo.Org.Id
  1268. if appRole.UserType == 2 || appRole.UserType == 1 {
  1269. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1270. evaluation.AssessmentTime = time.Now().Unix()
  1271. } else {
  1272. evaluation.Creater = adminUserInfo.AdminUser.Id
  1273. }
  1274. } else {
  1275. evaluation.UpdatedTime = time.Now().Unix()
  1276. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  1277. if appRole.UserType == 2 || appRole.UserType == 1 {
  1278. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1279. evaluation.AssessmentTime = time.Now().Unix()
  1280. } else {
  1281. evaluation.Modifier = adminUserInfo.AdminUser.Id
  1282. if evaluation.Creater == 0 {
  1283. evaluation.Creater = adminUserInfo.AdminUser.Id
  1284. }
  1285. }
  1286. }
  1287. //新增逻辑
  1288. var dewater_amount float64
  1289. dewater_amount = 0
  1290. if evaluation.DryWeight > 0 {
  1291. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  1292. if template.TemplateId == 17 || template.TemplateId == 22 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 34 || template.TemplateId == 32 {
  1293. dewater_amount = dewater_amount * 1000
  1294. }
  1295. if dewater_amount <= 0 {
  1296. dewater_amount = 0
  1297. }
  1298. } else {
  1299. dewater_amount = 0
  1300. }
  1301. // 计算透析处方的相关超滤量
  1302. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  1303. var lastDialysisPrescribe *models.DialysisPrescription
  1304. var dialysisSolution *models.DialysisSolution
  1305. var dialysisPrescribe *models.DialysisPrescription
  1306. var system_dialysisPrescribe *models.SystemPrescription
  1307. var mode_id int64
  1308. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  1309. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  1310. if schedual != nil {
  1311. // 获取透析模版
  1312. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  1313. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, schedual.ModeId)
  1314. mode_id = schedual.ModeId
  1315. } else {
  1316. // 获取透析模版
  1317. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  1318. if dialysisPrescribe == nil && dialysisSolution != nil {
  1319. mode_id = dialysisSolution.ModeId
  1320. }
  1321. if dialysisPrescribe == nil && dialysisSolution == nil {
  1322. mode_id = 0
  1323. }
  1324. }
  1325. // 插入透析处方
  1326. if dialysisPrescribe == nil && dialysisSolution != nil {
  1327. var newprescribe models.DialysisPrescription
  1328. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  1329. newprescribe.PatientId = dialysisSolution.PatientId
  1330. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  1331. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  1332. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  1333. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  1334. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  1335. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  1336. newprescribe.ModeId = dialysisSolution.ModeId
  1337. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  1338. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  1339. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  1340. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  1341. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  1342. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  1343. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  1344. newprescribe.Glucose = dialysisSolution.Glucose
  1345. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  1346. newprescribe.Kalium = dialysisSolution.Kalium
  1347. newprescribe.Sodium = dialysisSolution.Sodium
  1348. newprescribe.Calcium = dialysisSolution.Calcium
  1349. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  1350. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  1351. newprescribe.Conductivity = dialysisSolution.Conductivity
  1352. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  1353. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  1354. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  1355. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  1356. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  1357. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  1358. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  1359. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  1360. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  1361. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  1362. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  1363. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  1364. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  1365. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  1366. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  1367. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  1368. newprescribe.CreatedTime = time.Now().Unix()
  1369. newprescribe.UpdatedTime = time.Now().Unix()
  1370. newprescribe.RecordDate = theAssessmentDateTime
  1371. newprescribe.DewaterAmount = dewater_amount
  1372. newprescribe.TargetUltrafiltration = dewater_amount
  1373. newprescribe.Status = 1
  1374. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  1375. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  1376. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  1377. newprescribe.ID = dialysisPrescription.ID
  1378. if dialysisPrescription.ID == 0 {
  1379. fmt.Println("处方11111111111")
  1380. err := service.AddSigleRecord(&newprescribe)
  1381. //获取key,清空redis
  1382. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1383. redis := service.RedisClient()
  1384. //清空key 值
  1385. redis.Set(key, "", time.Second)
  1386. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1387. //清空key 值
  1388. redis.Set(keyOne, "", time.Second)
  1389. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1390. //清空key 值
  1391. redis.Set(keyTwo, "", time.Second)
  1392. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1393. redis.Set(keySix, "", time.Second)
  1394. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1395. redis.Set(keySeven, "", time.Second)
  1396. if err != nil {
  1397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1398. }
  1399. } else {
  1400. err := service.UpDateDialysisPrescription(&newprescribe)
  1401. //获取key,清空redis
  1402. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1403. redis := service.RedisClient()
  1404. //清空key 值
  1405. redis.Set(key, "", time.Second)
  1406. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1407. //清空key 值
  1408. redis.Set(keyOne, "", time.Second)
  1409. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1410. //清空key 值
  1411. redis.Set(keyTwo, "", time.Second)
  1412. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1413. redis.Set(keySix, "", time.Second)
  1414. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1415. redis.Set(keySeven, "", time.Second)
  1416. if err != nil {
  1417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1418. }
  1419. }
  1420. }
  1421. if dialysisPrescribe == nil && dialysisSolution == nil {
  1422. if lastDialysisPrescribe != nil {
  1423. var newprescribe models.DialysisPrescription
  1424. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  1425. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  1426. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  1427. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  1428. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  1429. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  1430. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  1431. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  1432. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  1433. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  1434. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  1435. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  1436. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  1437. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  1438. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  1439. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  1440. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  1441. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  1442. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  1443. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  1444. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  1445. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  1446. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  1447. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  1448. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  1449. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  1450. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  1451. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  1452. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  1453. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  1454. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  1455. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  1456. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  1457. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  1458. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  1459. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  1460. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  1461. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  1462. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  1463. newprescribe.CreatedTime = time.Now().Unix()
  1464. newprescribe.UpdatedTime = time.Now().Unix()
  1465. newprescribe.RecordDate = theAssessmentDateTime
  1466. newprescribe.DewaterAmount = dewater_amount
  1467. newprescribe.TargetUltrafiltration = dewater_amount
  1468. newprescribe.Status = 1
  1469. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  1470. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  1471. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  1472. newprescribe.ID = dialysisPrescription.ID
  1473. if dialysisPrescription.ID == 0 {
  1474. err := service.AddSigleRecord(&newprescribe)
  1475. //获取key,清空redis
  1476. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1477. redis := service.RedisClient()
  1478. //清空key 值
  1479. redis.Set(key, "", time.Second)
  1480. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1481. //清空key 值
  1482. redis.Set(keyOne, "", time.Second)
  1483. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1484. //清空key 值
  1485. redis.Set(keyTwo, "", time.Second)
  1486. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1487. redis.Set(keySix, "", time.Second)
  1488. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1489. redis.Set(keySeven, "", time.Second)
  1490. fmt.Println("处方2222222222")
  1491. if err != nil {
  1492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1493. }
  1494. } else {
  1495. err := service.UpDateDialysisPrescription(&newprescribe)
  1496. //获取key,清空redis
  1497. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1498. redis := service.RedisClient()
  1499. //清空key 值
  1500. redis.Set(key, "", time.Second)
  1501. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1502. //清空key 值
  1503. redis.Set(keyOne, "", time.Second)
  1504. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1505. //清空key 值
  1506. redis.Set(keyTwo, "", time.Second)
  1507. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1508. redis.Set(keySix, "", time.Second)
  1509. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1510. redis.Set(keySeven, "", time.Second)
  1511. if err != nil {
  1512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1513. }
  1514. }
  1515. if err != nil {
  1516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1517. }
  1518. } else if system_dialysisPrescribe != nil {
  1519. var newprescribe models.DialysisPrescription
  1520. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  1521. newprescribe.PatientId = id
  1522. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  1523. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  1524. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  1525. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  1526. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  1527. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  1528. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  1529. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  1530. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  1531. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  1532. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  1533. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  1534. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  1535. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  1536. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  1537. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  1538. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  1539. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  1540. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  1541. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  1542. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  1543. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  1544. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  1545. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  1546. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  1547. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  1548. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  1549. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  1550. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  1551. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  1552. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  1553. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  1554. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  1555. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  1556. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  1557. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  1558. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  1559. newprescribe.CreatedTime = time.Now().Unix()
  1560. newprescribe.UpdatedTime = time.Now().Unix()
  1561. newprescribe.RecordDate = theAssessmentDateTime
  1562. newprescribe.DewaterAmount = dewater_amount
  1563. newprescribe.TargetUltrafiltration = dewater_amount
  1564. newprescribe.Status = 1
  1565. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  1566. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  1567. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  1568. newprescribe.ID = dialysisPrescription.ID
  1569. if dialysisPrescription.ID == 0 {
  1570. err := service.AddSigleRecord(&newprescribe)
  1571. fmt.Println("处方2222222222")
  1572. //获取key,清空redis
  1573. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1574. redis := service.RedisClient()
  1575. //清空key 值
  1576. redis.Set(key, "", time.Second)
  1577. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1578. //清空key 值
  1579. redis.Set(keyOne, "", time.Second)
  1580. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1581. //清空key 值
  1582. redis.Set(keyTwo, "", time.Second)
  1583. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1584. redis.Set(keySix, "", time.Second)
  1585. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1586. redis.Set(keySeven, "", time.Second)
  1587. if err != nil {
  1588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1589. }
  1590. } else {
  1591. err := service.UpDateDialysisPrescription(&newprescribe)
  1592. //获取key,清空redis
  1593. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1594. redis := service.RedisClient()
  1595. //清空key 值
  1596. redis.Set(key, "", time.Second)
  1597. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1598. //清空key 值
  1599. redis.Set(keyOne, "", time.Second)
  1600. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1601. //清空key 值
  1602. redis.Set(keyTwo, "", time.Second)
  1603. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1604. redis.Set(keySix, "", time.Second)
  1605. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1606. redis.Set(keySeven, "", time.Second)
  1607. if err != nil {
  1608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1609. }
  1610. }
  1611. if err != nil {
  1612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1613. }
  1614. } else {
  1615. var newprescribe models.DialysisPrescription
  1616. newprescribe.UserOrgId = adminUserInfo.Org.Id
  1617. newprescribe.PatientId = id
  1618. newprescribe.ModeId = mode_id
  1619. newprescribe.CreatedTime = time.Now().Unix()
  1620. newprescribe.UpdatedTime = time.Now().Unix()
  1621. newprescribe.RecordDate = theAssessmentDateTime
  1622. newprescribe.DewaterAmount = dewater_amount
  1623. newprescribe.TargetUltrafiltration = dewater_amount
  1624. newprescribe.Status = 1
  1625. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  1626. newprescribe.ID = dialysisPrescription.ID
  1627. if dialysisPrescription.ID == 0 {
  1628. err := service.AddSigleRecord(&newprescribe)
  1629. fmt.Println("处方44444444444")
  1630. //获取key,清空redis
  1631. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1632. redis := service.RedisClient()
  1633. //清空key 值
  1634. redis.Set(key, "", time.Second)
  1635. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1636. //清空key 值
  1637. redis.Set(keyOne, "", time.Second)
  1638. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1639. //清空key 值
  1640. redis.Set(keyTwo, "", time.Second)
  1641. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1642. redis.Set(keySix, "", time.Second)
  1643. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1644. redis.Set(keySeven, "", time.Second)
  1645. if err != nil {
  1646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1647. }
  1648. } else {
  1649. err := service.UpDateDialysisPrescription(&newprescribe)
  1650. //获取key,清空redis
  1651. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1652. redis := service.RedisClient()
  1653. //清空key 值
  1654. redis.Set(key, "", time.Second)
  1655. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1656. //清空key 值
  1657. redis.Set(keyOne, "", time.Second)
  1658. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1659. //清空key 值
  1660. redis.Set(keyTwo, "", time.Second)
  1661. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1662. redis.Set(keySix, "", time.Second)
  1663. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1664. redis.Set(keySeven, "", time.Second)
  1665. if err != nil {
  1666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1667. }
  1668. }
  1669. if err != nil {
  1670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1671. }
  1672. }
  1673. }
  1674. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  1675. // if dialysisPrescribe != nil {
  1676. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  1677. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  1678. // dialysisPrescribe.DewaterAmount = dewater_amount
  1679. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  1680. // dialysisPrescribe.Status = 1
  1681. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  1682. // if updateErr != nil {
  1683. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1684. // }
  1685. // }
  1686. err = service.UpadatePredialysisEvaluation(&evaluation)
  1687. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  1688. redis := service.RedisClient()
  1689. defer redis.Close()
  1690. //清空key 值
  1691. redis.Set(key, "", time.Second)
  1692. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  1693. redis.Set(keyOne, "", time.Second)
  1694. keyTwo := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1695. redis.Set(keyTwo, "", time.Second)
  1696. if err != nil {
  1697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1698. return
  1699. }
  1700. c.ServeSuccessJSON(map[string]interface{}{
  1701. "msg": "ok",
  1702. "evaluation": evaluation,
  1703. })
  1704. return
  1705. }
  1706. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  1707. dataBody := make(map[string]interface{}, 0)
  1708. err := json.Unmarshal(data, &dataBody)
  1709. utils.InfoLog(string(data))
  1710. if err != nil {
  1711. utils.ErrorLog(err.Error())
  1712. code = enums.ErrorCodeParamWrong
  1713. return
  1714. }
  1715. // if method == "create" {
  1716. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  1717. utils.ErrorLog("mode")
  1718. code = enums.ErrorCodeParamWrong
  1719. return
  1720. }
  1721. mode := int64(dataBody["mode"].(float64))
  1722. if mode <= 0 {
  1723. utils.ErrorLog("mode <= 0")
  1724. code = enums.ErrorCodeParamWrong
  1725. return
  1726. }
  1727. solution.ModeId = mode
  1728. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  1729. utils.ErrorLog("mode_name")
  1730. code = enums.ErrorCodeParamWrong
  1731. return
  1732. }
  1733. modeName, _ := dataBody["mode_name"].(string)
  1734. if len(modeName) == 0 {
  1735. utils.ErrorLog("len(mode_name) == 0")
  1736. code = enums.ErrorCodeParamWrong
  1737. return
  1738. }
  1739. solution.ModeName = modeName
  1740. solution.Name = modeName
  1741. // }
  1742. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  1743. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  1744. solution.DialysisDuration = dialysisDuration
  1745. }
  1746. if dataBody["dialysis_duration"] != nil {
  1747. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  1748. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  1749. solution.DialysisDuration = dialysisDuration
  1750. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  1751. dialysisDuration := dataBody["dialysis_duration"].(float64)
  1752. solution.DialysisDuration = dialysisDuration
  1753. }
  1754. }
  1755. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  1756. dialyzer := int64(dataBody["dialyzer"].(float64))
  1757. solution.Dialyzer = dialyzer
  1758. }
  1759. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  1760. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  1761. solution.PerfusionApparatus = perfusionApparatus
  1762. }
  1763. if dataBody["blood_flow_volume"] != nil {
  1764. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  1765. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  1766. solution.BloodFlowVolume = bloodFlowVolume
  1767. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  1768. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  1769. solution.BloodFlowVolume = bloodFlowVolume
  1770. }
  1771. }
  1772. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  1773. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  1774. solution.HemodialysisMachine = hemodialysisMachine
  1775. }
  1776. if dataBody["dewater"] != nil {
  1777. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  1778. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  1779. solution.Dewater = dewater
  1780. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  1781. dewater := dataBody["dewater"].(float64)
  1782. solution.Dewater = dewater
  1783. }
  1784. }
  1785. if dataBody["replacement_total"] != nil {
  1786. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  1787. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  1788. solution.ReplacementTotal = replacementTotal
  1789. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  1790. replacementTotal := dataBody["replacement_total"].(float64)
  1791. solution.ReplacementTotal = replacementTotal
  1792. }
  1793. }
  1794. if dataBody["displace_liqui"] != nil {
  1795. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  1796. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  1797. solution.DisplaceLiqui = displaceLiqui
  1798. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  1799. displaceLiqui := dataBody["displace_liqui"].(float64)
  1800. solution.DisplaceLiqui = displaceLiqui
  1801. }
  1802. }
  1803. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  1804. replacementWay := int64(dataBody["replacement_way"].(float64))
  1805. solution.ReplacementWay = replacementWay
  1806. }
  1807. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  1808. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  1809. solution.Anticoagulant = anticoagulant
  1810. }
  1811. if dataBody["anticoagulant_shouji"] != nil {
  1812. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  1813. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  1814. solution.AnticoagulantShouji = anticoagulantShouji
  1815. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  1816. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  1817. solution.AnticoagulantShouji = anticoagulantShouji
  1818. }
  1819. }
  1820. if dataBody["anticoagulant_weichi"] != nil {
  1821. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  1822. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  1823. solution.AnticoagulantWeichi = anticoagulantWeichi
  1824. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  1825. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  1826. solution.AnticoagulantWeichi = anticoagulantWeichi
  1827. }
  1828. }
  1829. if dataBody["anticoagulant_zongliang"] != nil {
  1830. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  1831. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  1832. solution.AnticoagulantZongliang = anticoagulantZongliang
  1833. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  1834. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  1835. solution.AnticoagulantZongliang = anticoagulantZongliang
  1836. }
  1837. }
  1838. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  1839. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  1840. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  1841. }
  1842. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  1843. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  1844. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  1845. }
  1846. if dataBody["kalium"] != nil {
  1847. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  1848. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  1849. solution.Kalium = kalium
  1850. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  1851. kalium := dataBody["kalium"].(float64)
  1852. solution.Kalium = kalium
  1853. }
  1854. }
  1855. if dataBody["sodium"] != nil {
  1856. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  1857. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  1858. solution.Sodium = sodium
  1859. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  1860. sodium := dataBody["sodium"].(float64)
  1861. solution.Sodium = sodium
  1862. }
  1863. }
  1864. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  1865. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  1866. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  1867. solution.Calcium = calcium
  1868. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  1869. calcium := dataBody["calcium"].(float64)
  1870. solution.Calcium = calcium
  1871. }
  1872. }
  1873. if dataBody["bicarbonate"] != nil {
  1874. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  1875. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  1876. solution.Bicarbonate = bicarbonate
  1877. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  1878. bicarbonate := dataBody["bicarbonate"].(float64)
  1879. solution.Bicarbonate = bicarbonate
  1880. }
  1881. }
  1882. if dataBody["glucose"] != nil {
  1883. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  1884. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  1885. solution.Glucose = glucose
  1886. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  1887. glucose := dataBody["glucose"].(float64)
  1888. solution.Glucose = glucose
  1889. }
  1890. }
  1891. // if dataBody["dry_weight"] != nil {
  1892. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  1893. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  1894. // solution.DryWeight = dryWeight
  1895. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  1896. // dryWeight := dataBody["dry_weight"].(float64)
  1897. // solution.DryWeight = dryWeight
  1898. // }
  1899. // }
  1900. if dataBody["dialysate_flow"] != nil {
  1901. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  1902. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  1903. solution.DialysateFlow = dialysateFlow
  1904. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  1905. dialysateFlow := dataBody["dialysate_flow"].(float64)
  1906. solution.DialysateFlow = dialysateFlow
  1907. }
  1908. }
  1909. if dataBody["dialysate_temperature"] != nil {
  1910. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  1911. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  1912. solution.DialysateTemperature = dialysateTemperature
  1913. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  1914. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  1915. solution.DialysateTemperature = dialysateTemperature
  1916. }
  1917. }
  1918. if dataBody["conductivity"] != nil {
  1919. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  1920. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  1921. solution.Conductivity = conductivity
  1922. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  1923. conductivity := dataBody["conductivity"].(float64)
  1924. solution.Conductivity = conductivity
  1925. }
  1926. }
  1927. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1928. remark := dataBody["remark"].(string)
  1929. solution.Remark = remark
  1930. }
  1931. if dataBody["dialysis_duration_hour"] != nil {
  1932. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  1933. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  1934. solution.DialysisDurationHour = dialysisDurationHour
  1935. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  1936. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  1937. solution.DialysisDurationHour = int64(dialysisDurationHour)
  1938. }
  1939. }
  1940. if dataBody["dialysis_duration_minute"] != nil {
  1941. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  1942. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  1943. solution.DialysisDurationMinute = dialysisDurationMinute
  1944. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  1945. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  1946. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  1947. }
  1948. }
  1949. if dataBody["target_ultrafiltration"] != nil {
  1950. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  1951. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  1952. solution.TargetUltrafiltration = targetUltrafiltration
  1953. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  1954. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  1955. solution.TargetUltrafiltration = targetUltrafiltration
  1956. }
  1957. }
  1958. if dataBody["dialysate_formulation"] != nil {
  1959. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  1960. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  1961. solution.DialysateFormulation = dialysateFormulation
  1962. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  1963. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  1964. solution.DialysateFormulation = int64(dialysateFormulation)
  1965. }
  1966. }
  1967. return
  1968. }
  1969. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  1970. dataBody := make(map[string]interface{}, 0)
  1971. err := json.Unmarshal(data, &dataBody)
  1972. utils.InfoLog(string(data))
  1973. if err != nil {
  1974. utils.ErrorLog(err.Error())
  1975. code = enums.ErrorCodeParamWrong
  1976. return
  1977. }
  1978. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  1979. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  1980. evaluation.WeightBefore = weightVefore
  1981. }
  1982. // fmt.Println(dataBody["dry_weight"])
  1983. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  1984. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  1985. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  1986. fmt.Println(additionalWeight)
  1987. evaluation.DryWeight = additionalWeight
  1988. }
  1989. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  1990. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  1991. fmt.Println(additionalWeight)
  1992. evaluation.AdditionalWeight = additionalWeight
  1993. }
  1994. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  1995. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  1996. evaluation.Temperature = Temperature
  1997. }
  1998. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  1999. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  2000. evaluation.SystolicBloodPressure = systolicBloodPressure
  2001. }
  2002. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  2003. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  2004. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  2005. }
  2006. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  2007. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  2008. evaluation.PulseFrequency = pulseFrequency
  2009. }
  2010. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  2011. breathingRate, _ := strconv.ParseFloat(dataBody["breathing_rate"].(string), 64)
  2012. evaluation.BreathingRate = breathingRate
  2013. }
  2014. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  2015. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  2016. evaluation.LastPostDialysis = lastPostDialysis
  2017. }
  2018. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  2019. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  2020. evaluation.DialysisInterphase = dialysisInterphase
  2021. }
  2022. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  2023. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  2024. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  2025. }
  2026. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  2027. catheter, _ := dataBody["catheter"].(string)
  2028. evaluation.Catheter = catheter
  2029. }
  2030. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  2031. catheter_bend := int(dataBody["catheter_bend"].(float64))
  2032. evaluation.CatheterBend = catheter_bend
  2033. }
  2034. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  2035. Complication, _ := dataBody["complication"].(string)
  2036. evaluation.Complication = Complication
  2037. }
  2038. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2039. remark := dataBody["remark"].(string)
  2040. evaluation.Remark = remark
  2041. }
  2042. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  2043. machine_type := dataBody["machine_type"].(string)
  2044. evaluation.MachineType = machine_type
  2045. }
  2046. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  2047. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  2048. evaluation.BloodAccessPartId = blood_access_part_id
  2049. }
  2050. //if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  2051. // blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  2052. // evaluation.BloodAccessPartId = blood_access_part_id
  2053. //}
  2054. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  2055. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  2056. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  2057. }
  2058. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  2059. internal_fistula, _ := dataBody["internal_fistula"].(string)
  2060. evaluation.InternalFistula = internal_fistula
  2061. }
  2062. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  2063. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  2064. evaluation.InternalFistulaSkin = internal_fistula_skin
  2065. }
  2066. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "string" {
  2067. ishemorrhage, _ := dataBody["is_hemorrhage"].(string)
  2068. is_hemorrhage, _ := strconv.ParseInt(ishemorrhage, 10, 64)
  2069. evaluation.IsHemorrhage = is_hemorrhage
  2070. //if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  2071. // is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  2072. // fmt.Println("is_hemorrhage2222222222222222",is_hemorrhage)
  2073. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  2074. is_hemorrhage = 0
  2075. }
  2076. evaluation.IsHemorrhage = is_hemorrhage
  2077. if is_hemorrhage == 1 {
  2078. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  2079. hemorrhage, _ := dataBody["hemorrhage"].(string)
  2080. evaluation.Hemorrhage = hemorrhage
  2081. }
  2082. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  2083. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  2084. evaluation.HemorrhageOther = hemorrhage_other
  2085. }
  2086. }
  2087. } else {
  2088. evaluation.IsHemorrhage = 0
  2089. }
  2090. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  2091. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  2092. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  2093. }
  2094. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  2095. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  2096. evaluation.InternalFistulaOther = internal_fistula_other
  2097. }
  2098. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  2099. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  2100. evaluation.BloodAccessNoise = blood_access_noise
  2101. }
  2102. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "string" {
  2103. //puncture_way := int64(dataBody["puncture_way"].(float64))
  2104. puncture_way := dataBody["puncture_way"].(string)
  2105. evaluation.PunctureWay = puncture_way
  2106. }
  2107. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  2108. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  2109. evaluation.VenousCatheterization = venous_catheterization
  2110. }
  2111. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  2112. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  2113. evaluation.VenousCatheterizationPart = venous_catheterization_part
  2114. }
  2115. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  2116. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  2117. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  2118. }
  2119. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  2120. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  2121. evaluation.DuctusArantii = ductus_arantii
  2122. }
  2123. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  2124. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  2125. evaluation.EmergencyTreatment = emergency_treatment
  2126. }
  2127. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  2128. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  2129. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  2130. }
  2131. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  2132. dialysis_count, _ := dataBody["dialysis_count"].(string)
  2133. //count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  2134. evaluation.DialysisCount = dialysis_count
  2135. }
  2136. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  2137. is_infect, _ := dataBody["is_infect"].(string)
  2138. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  2139. evaluation.IsInfect = infect
  2140. }
  2141. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  2142. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  2143. evaluation.Exposed = exposed
  2144. }
  2145. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  2146. skin, _ := dataBody["skin"].(string)
  2147. //skins, _ := strconv.ParseInt(skin, 10, 64)
  2148. evaluation.Skin = skin
  2149. }
  2150. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  2151. skin_other, _ := dataBody["skin_other"].(string)
  2152. evaluation.SkinOther = skin_other
  2153. }
  2154. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  2155. infect_other, _ := dataBody["infect_other"].(string)
  2156. evaluation.InfectOther = infect_other
  2157. }
  2158. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  2159. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  2160. evaluation.DuctusArantiiOther = ductus_arantii_other
  2161. }
  2162. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  2163. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  2164. evaluation.PunctureNeedle = punctureNeedle
  2165. }
  2166. if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "string" {
  2167. humor_excessive_symptom, _ := dataBody["humor_excessive_symptom"].(string)
  2168. evaluation.HumorExcessiveSymptom = humor_excessive_symptom
  2169. }
  2170. if dataBody["pinholing"] != nil && reflect.TypeOf(dataBody["pinholing"]).String() == "string" {
  2171. pinholing := dataBody["pinholing"].(string)
  2172. evaluation.Phinholing = pinholing
  2173. }
  2174. if dataBody["catheter_suture"] != nil && reflect.TypeOf(dataBody["catheter_suture"]).String() == "string" {
  2175. catheter_suture := dataBody["catheter_suture"].(string)
  2176. evaluation.CatheterSuture = catheter_suture
  2177. }
  2178. if dataBody["catheter_suture_other"] != nil && reflect.TypeOf(dataBody["catheter_suture_other"]).String() == "string" {
  2179. catheter_suture_other := dataBody["catheter_suture_other"].(string)
  2180. evaluation.CatheterSutureOther = catheter_suture_other
  2181. }
  2182. if dataBody["urine_volume"] != nil && reflect.TypeOf(dataBody["urine_volume"]).String() == "string" {
  2183. urine_volume, _ := strconv.ParseFloat(dataBody["urine_volume"].(string), 64)
  2184. evaluation.UrineVolume = urine_volume
  2185. }
  2186. if dataBody["edema"] != nil && reflect.TypeOf(dataBody["edema"]).String() == "string" {
  2187. edema := dataBody["edema"].(string)
  2188. evaluation.Edema = edema
  2189. }
  2190. if dataBody["special_treatment"] != nil && reflect.TypeOf(dataBody["special_treatment"]).String() == "string" {
  2191. specialTreatment := dataBody["special_treatment"].(string)
  2192. evaluation.SpecialTreatment = specialTreatment
  2193. }
  2194. if dataBody["catheter_maintenance"] != nil && reflect.TypeOf(dataBody["catheter_maintenance"]).String() == "string" {
  2195. catheter_maintenance := dataBody["catheter_maintenance"].(string)
  2196. evaluation.CatheterMaintenance = catheter_maintenance
  2197. }
  2198. if dataBody["thromubus_type"] != nil && reflect.TypeOf(dataBody["thromubus_type"]).String() == "float64" {
  2199. thromubusType := int64(dataBody["thromubus_type"].(float64))
  2200. evaluation.ThromubusType = thromubusType
  2201. }
  2202. if dataBody["thrombus_av"] != nil && reflect.TypeOf(dataBody["thrombus_av"]).String() == "string" {
  2203. thrombus_av := dataBody["thrombus_av"].(string)
  2204. evaluation.ThrombusAv = thrombus_av
  2205. }
  2206. if dataBody["thromubus_a"] != nil && reflect.TypeOf(dataBody["thromubus_a"]).String() == "string" {
  2207. thromubus_a := dataBody["thromubus_a"].(string)
  2208. evaluation.ThromubusA = thromubus_a
  2209. }
  2210. if dataBody["thromubus_v"] != nil && reflect.TypeOf(dataBody["thromubus_v"]).String() == "string" {
  2211. thromubus_v := dataBody["thromubus_v"].(string)
  2212. evaluation.ThromubusV = thromubus_v
  2213. }
  2214. if dataBody["dehydration"] != nil && reflect.TypeOf(dataBody["dehydration"]).String() == "string" {
  2215. dehydration := dataBody["dehydration"].(string)
  2216. evaluation.Dehydration = dehydration
  2217. }
  2218. if dataBody["period"] != nil && reflect.TypeOf(dataBody["period"]).String() == "float64" {
  2219. period := int64(dataBody["period"].(float64))
  2220. evaluation.Period = period
  2221. }
  2222. if dataBody["estimated_food_intake"] != nil && reflect.TypeOf(dataBody["estimated_food_intake"]).String() == "string" {
  2223. estimated_food_intake := dataBody["estimated_food_intake"].(string)
  2224. evaluation.EstimatedFoodIntake = estimated_food_intake
  2225. }
  2226. if dataBody["blood_pressure_during_dialysis"] != nil && reflect.TypeOf(dataBody["blood_pressure_during_dialysis"]).String() == "string" {
  2227. blood_pressure_during_dialysis := dataBody["blood_pressure_during_dialysis"].(string)
  2228. evaluation.BloodPressureDuringDialysis = blood_pressure_during_dialysis
  2229. }
  2230. if dataBody["pre_dialysis_drugs"] != nil && reflect.TypeOf(dataBody["pre_dialysis_drugs"]).String() == "string" {
  2231. pre_dialysis_drugs := dataBody["pre_dialysis_drugs"].(string)
  2232. evaluation.PreDialysisDrugs = pre_dialysis_drugs
  2233. }
  2234. return
  2235. }
  2236. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  2237. dataBody := make(map[string]interface{}, 0)
  2238. err := json.Unmarshal(data, &dataBody)
  2239. if err != nil {
  2240. utils.ErrorLog(err.Error())
  2241. code = enums.ErrorCodeParamWrong
  2242. return
  2243. }
  2244. timeLayout := "2006-01-02"
  2245. loc, _ := time.LoadLocation("Local")
  2246. isChild := false
  2247. if action == "create" {
  2248. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2249. utils.ErrorLog("advice_type")
  2250. code = enums.ErrorCodeParamWrong
  2251. return
  2252. }
  2253. adviceType := int64(dataBody["advice_type"].(float64))
  2254. if adviceType != 1 && adviceType != 2 {
  2255. utils.ErrorLog("advice_type != 1&&2")
  2256. code = enums.ErrorCodeParamWrong
  2257. return
  2258. }
  2259. advice.AdviceType = adviceType
  2260. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2261. utils.ErrorLog("advice_date")
  2262. code = enums.ErrorCodeParamWrong
  2263. return
  2264. }
  2265. adviceDate, _ := dataBody["advice_date"].(string)
  2266. if len(adviceDate) == 0 {
  2267. utils.ErrorLog("len(adviceDate) == 0")
  2268. code = enums.ErrorCodeParamWrong
  2269. return
  2270. }
  2271. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2272. if err != nil {
  2273. utils.ErrorLog(err.Error())
  2274. code = enums.ErrorCodeParamWrong
  2275. return
  2276. }
  2277. advice.AdviceDate = theTime.Unix()
  2278. advice.RecordDate = theTime.Unix()
  2279. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  2280. parentId := int64(dataBody["parent_id"].(float64))
  2281. advice.ParentId = parentId
  2282. if parentId > 0 {
  2283. isChild = true
  2284. }
  2285. }
  2286. } else {
  2287. isChild = advice.ParentId > 0
  2288. }
  2289. if !isChild {
  2290. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2291. utils.ErrorLog("start_time")
  2292. code = enums.ErrorCodeParamWrong
  2293. return
  2294. }
  2295. startTime, _ := dataBody["start_time"].(string)
  2296. if len(startTime) == 0 {
  2297. utils.ErrorLog("len(start_time) == 0")
  2298. code = enums.ErrorCodeParamWrong
  2299. return
  2300. }
  2301. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  2302. if err != nil {
  2303. utils.ErrorLog(err.Error())
  2304. code = enums.ErrorCodeParamWrong
  2305. return
  2306. }
  2307. advice.StartTime = theTime.Unix()
  2308. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  2309. deliveryWay, _ := dataBody["delivery_way"].(string)
  2310. advice.DeliveryWay = deliveryWay
  2311. }
  2312. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  2313. executionFrequency, _ := dataBody["execution_frequency"].(string)
  2314. advice.ExecutionFrequency = executionFrequency
  2315. }
  2316. }
  2317. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  2318. deliveryWay, _ := dataBody["delivery_way"].(string)
  2319. advice.DeliveryWay = deliveryWay
  2320. }
  2321. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  2322. executionFrequency, _ := dataBody["execution_frequency"].(string)
  2323. advice.ExecutionFrequency = executionFrequency
  2324. }
  2325. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  2326. utils.ErrorLog("advice_name")
  2327. code = enums.ErrorCodeParamWrong
  2328. return
  2329. }
  2330. adviceName, _ := dataBody["advice_name"].(string)
  2331. if len(adviceName) == 0 {
  2332. utils.ErrorLog("len(advice_name) == 0")
  2333. code = enums.ErrorCodeParamWrong
  2334. return
  2335. }
  2336. advice.AdviceName = adviceName
  2337. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  2338. adviceDsc, _ := dataBody["advice_desc"].(string)
  2339. advice.AdviceDesc = adviceDsc
  2340. }
  2341. if dataBody["way"] == nil {
  2342. advice.Way = 0
  2343. } else {
  2344. if dataBody["way"] != nil || reflect.TypeOf(dataBody["way"]).String() == "float64" {
  2345. way := int64(dataBody["way"].(float64))
  2346. advice.Way = way
  2347. }
  2348. }
  2349. if dataBody["drug_id"] == nil {
  2350. advice.DrugId = 0
  2351. } else {
  2352. if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  2353. drug_id := int64(dataBody["drug_id"].(float64))
  2354. advice.DrugId = drug_id
  2355. }
  2356. }
  2357. if dataBody["drug_name_id"] == nil {
  2358. advice.DrugNameId = 0
  2359. } else {
  2360. if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  2361. drug_name_id := int64(dataBody["drug_name_id"].(float64))
  2362. advice.DrugNameId = drug_name_id
  2363. fmt.Println("0000000000", advice.DrugNameId)
  2364. }
  2365. }
  2366. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  2367. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  2368. advice.SingleDose = singleDose
  2369. }
  2370. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  2371. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  2372. advice.SingleDoseUnit = singleDoseUnit
  2373. }
  2374. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  2375. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  2376. advice.DrugSpec = drugSpec
  2377. }
  2378. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  2379. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  2380. advice.DrugSpecUnit = drugSpecUnit
  2381. }
  2382. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  2383. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  2384. advice.PrescribingNumber = prescribingNumber
  2385. }
  2386. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  2387. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  2388. advice.PrescribingNumberUnit = prescribingNumberUnit
  2389. }
  2390. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2391. remark, _ := dataBody["remark"].(string)
  2392. advice.Remark = remark
  2393. }
  2394. return
  2395. }
  2396. func (c *PatientApiController) GetPatientEducation() {
  2397. patientID, _ := c.GetInt64("patient_id", 0)
  2398. page, _ := c.GetInt64("page", 0)
  2399. limit, _ := c.GetInt64("limit", 0)
  2400. startTime := c.GetString("start_time", "")
  2401. endTime := c.GetString("end_time", "")
  2402. if page <= 0 {
  2403. page = 1
  2404. }
  2405. if limit <= 0 {
  2406. limit = 10
  2407. }
  2408. if patientID <= 0 {
  2409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2410. return
  2411. }
  2412. timeLayout := "2006-01-02"
  2413. loc, _ := time.LoadLocation("Local")
  2414. var theStartTIme int64
  2415. if len(startTime) > 0 {
  2416. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2417. if err != nil {
  2418. theStartTIme = 0
  2419. }
  2420. theStartTIme = theTime.Unix()
  2421. }
  2422. var theEndtTIme int64
  2423. if len(endTime) > 0 {
  2424. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2425. if err != nil {
  2426. theEndtTIme = 0
  2427. }
  2428. theEndtTIme = theTime.Unix()
  2429. }
  2430. adminUserInfo := c.GetMobileAdminUserInfo()
  2431. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  2432. c.ServeSuccessJSON(map[string]interface{}{
  2433. "total": total,
  2434. "edus": edus,
  2435. })
  2436. return
  2437. }
  2438. func (c *PatientApiController) GetPatientSchedulesList() {
  2439. patientID, _ := c.GetInt64("patient_id", 0)
  2440. page, _ := c.GetInt64("page", 0)
  2441. limit, _ := c.GetInt64("limit", 0)
  2442. if patientID <= 0 {
  2443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2444. return
  2445. }
  2446. adminUserInfo := c.GetMobileAdminUserInfo()
  2447. todayTime := time.Now().Format("2006-01-02")
  2448. timeLayout := "2006-01-02 15:04:05"
  2449. loc, _ := time.LoadLocation("Local")
  2450. var theStartTime int64
  2451. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  2452. theStartTime = theTime.Unix()
  2453. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  2454. if len(schedules) > 0 {
  2455. for index, item := range schedules {
  2456. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  2457. schedules[index].Week = int64(week)
  2458. }
  2459. }
  2460. c.ServeSuccessJSON(map[string]interface{}{
  2461. "schedules": schedules,
  2462. })
  2463. return
  2464. }
  2465. func (c *PatientApiController) GetRecords() {
  2466. patientID, _ := c.GetInt64("patient_id", 0)
  2467. page, _ := c.GetInt64("page", 0)
  2468. limit, _ := c.GetInt64("limit", 0)
  2469. startTime := c.GetString("start_time", "")
  2470. endTime := c.GetString("end_time", "")
  2471. mode_id, _ := c.GetInt64("mode_id", 0)
  2472. if page <= 0 {
  2473. page = 1
  2474. }
  2475. if limit <= 0 {
  2476. limit = 10
  2477. }
  2478. if patientID <= 0 {
  2479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2480. return
  2481. }
  2482. timeLayout := "2006-01-02"
  2483. loc, _ := time.LoadLocation("Local")
  2484. var theStartTIme int64
  2485. if len(startTime) > 0 {
  2486. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2487. if err != nil {
  2488. theStartTIme = 0
  2489. }
  2490. theStartTIme = theTime.Unix()
  2491. }
  2492. var theEndtTIme int64
  2493. if len(endTime) > 0 {
  2494. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2495. if err != nil {
  2496. theEndtTIme = 0
  2497. }
  2498. theEndtTIme = theTime.Unix()
  2499. }
  2500. adminUserInfo := c.GetMobileAdminUserInfo()
  2501. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  2502. c.ServeSuccessJSON(map[string]interface{}{
  2503. "total": total,
  2504. "records": records,
  2505. })
  2506. return
  2507. }
  2508. func (c *PatientApiController) GetPatientMonitor() {
  2509. partition, _ := c.GetInt64("partition")
  2510. monitorDate := c.GetString("date")
  2511. patient_id, _ := c.GetInt64("patient_id")
  2512. timeLayout := "2006-01-02"
  2513. loc, _ := time.LoadLocation("Local")
  2514. var theStartTime int64
  2515. if len(monitorDate) > 0 {
  2516. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  2517. if err != nil {
  2518. theStartTime = 0
  2519. }
  2520. theStartTime = theTime.Unix()
  2521. }
  2522. adminInfo := c.GetMobileAdminUserInfo()
  2523. orgID := adminInfo.Org.Id
  2524. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition, patient_id)
  2525. if err != nil {
  2526. c.ErrorLog("获取排班信息失败:%v", err)
  2527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2528. } else {
  2529. if len(monitor) > 0 {
  2530. //获取所有床位
  2531. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  2532. //获取所有分区
  2533. zoneList, _ := service.GetAllZoneByList(orgID)
  2534. //获取透析处方
  2535. prescriptions, _ := service.GetAllPrescriptionByList(orgID, theStartTime)
  2536. //获取透前评估
  2537. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  2538. //获取上机
  2539. dialysisOrders, _ := service.GetAllDialysisOrdersByListSix(orgID, theStartTime)
  2540. //获取透后
  2541. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListOne(orgID, theStartTime)
  2542. //获取透后监测
  2543. monitorlist, _ := service.GetAllMonitorList(orgID, theStartTime)
  2544. //获取所有的患者
  2545. patients, _ := service.GetAllPatientListByListOne(orgID)
  2546. //获取所有透析模式
  2547. treatments, _ := service.GetAllTreatModeByList(orgID)
  2548. for key, item := range monitor {
  2549. // 获取床位信息
  2550. for _, it := range numberList {
  2551. if item.BedId == it.ID {
  2552. monitor[key].DeviceNumber = it
  2553. break
  2554. }
  2555. }
  2556. //获取分区信息
  2557. for _, it := range zoneList {
  2558. if item.PartitionId == it.ID {
  2559. monitor[key].DeviceZone = it
  2560. }
  2561. }
  2562. for _, prescription := range prescriptions {
  2563. if item.PatientId == prescription.PatientId {
  2564. monitor[key].Prescription = prescription
  2565. break
  2566. }
  2567. }
  2568. // 透前评估
  2569. for _, assessmentBefore := range assessmentBefores {
  2570. if item.PatientId == assessmentBefore.PatientId {
  2571. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  2572. break
  2573. }
  2574. }
  2575. // 透析上下机
  2576. for _, dialysisOrder := range dialysisOrders {
  2577. if item.PatientId == dialysisOrder.PatientId {
  2578. monitor[key].DialysisOrder = dialysisOrder
  2579. break
  2580. }
  2581. }
  2582. // 治疗小节
  2583. for _, afterDislysis := range AssessmentAfterDislysis {
  2584. if item.PatientId == afterDislysis.PatientId {
  2585. monitor[key].AssessmentAfterDislysis = afterDislysis
  2586. break
  2587. }
  2588. }
  2589. for _, it := range monitorlist {
  2590. if item.PatientId == it.PatientId {
  2591. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  2592. }
  2593. }
  2594. for _, patient := range patients {
  2595. if item.PatientId == patient.ID {
  2596. monitor[key].MonitorPatients = patient
  2597. break
  2598. }
  2599. }
  2600. for _, treatment := range treatments {
  2601. if item.ModeId == treatment.ID {
  2602. monitor[key].TreatmentMode = treatment
  2603. break
  2604. }
  2605. }
  2606. }
  2607. }
  2608. }
  2609. //获取患者的透析次数
  2610. count, err := service.GetDialysisCount(orgID, partition)
  2611. patients, err := service.GetAllpatient(orgID)
  2612. if err == nil {
  2613. c.ServeSuccessJSON(map[string]interface{}{
  2614. "monitor": monitor,
  2615. "patientCount": count,
  2616. "patients": patients,
  2617. })
  2618. } else {
  2619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2620. }
  2621. }
  2622. // /m/api/monitor/patient [get] 搜索病人的测量记录
  2623. // @param keyword:string 病人姓名或透析号
  2624. // @param page:int
  2625. func (this *PatientApiController) SearchMonitorPatient() {
  2626. keyword := this.GetString("keyword")
  2627. page, _ := this.GetInt("page")
  2628. if page <= 0 {
  2629. page = 1
  2630. }
  2631. if len(keyword) == 0 {
  2632. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2633. return
  2634. }
  2635. adminUserInfo := this.GetMobileAdminUserInfo()
  2636. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  2637. if getMonitorErr != nil {
  2638. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2639. return
  2640. } else {
  2641. this.ServeSuccessJSON(map[string]interface{}{
  2642. "monitor": monitors,
  2643. })
  2644. }
  2645. }
  2646. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  2647. id, _ := c.GetInt64("id", 0)
  2648. page, _ := c.GetInt64("page", 0)
  2649. limit, _ := c.GetInt64("limit", 0)
  2650. if id <= 0 {
  2651. c.ServeSuccessJSON(map[string]interface{}{
  2652. "solutions": nil,
  2653. })
  2654. return
  2655. }
  2656. if page <= 0 {
  2657. page = 1
  2658. }
  2659. if limit <= 0 {
  2660. limit = 10
  2661. }
  2662. adminInfo := c.GetMobileAdminUserInfo()
  2663. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  2664. c.ServeSuccessJSON(map[string]interface{}{
  2665. "solutions": solutions,
  2666. "total": total,
  2667. })
  2668. return
  2669. }
  2670. //GetDoctorAdvices 医嘱列表
  2671. func (c *PatientApiController) GetDoctorAdvices() {
  2672. id, _ := c.GetInt64("id", 0)
  2673. adviceType, _ := c.GetInt64("advice_type", 0)
  2674. stopType, _ := c.GetInt64("stop_state", 0)
  2675. startTime := c.GetString("start_time", "")
  2676. endTime := c.GetString("end_time", "")
  2677. keywords := c.GetString("keywords", "")
  2678. need, _ := c.GetInt64("need_doctor", 0)
  2679. adminUserInfo := c.GetMobileAdminUserInfo()
  2680. timeLayout := "2006-01-02"
  2681. loc, _ := time.LoadLocation("Local")
  2682. var theStartTIme int64
  2683. if len(startTime) > 0 {
  2684. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2685. if err != nil {
  2686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2687. return
  2688. }
  2689. theStartTIme = theTime.Unix()
  2690. }
  2691. var theEndtTIme int64
  2692. if len(endTime) > 0 {
  2693. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2694. if err != nil {
  2695. utils.ErrorLog(err.Error())
  2696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2697. return
  2698. }
  2699. theEndtTIme = theTime.Unix()
  2700. }
  2701. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  2702. if need == 1 {
  2703. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  2704. c.ServeSuccessJSON(map[string]interface{}{
  2705. "advices": advices,
  2706. "total": total,
  2707. "users": users,
  2708. })
  2709. } else {
  2710. c.ServeSuccessJSON(map[string]interface{}{
  2711. "advices": advices,
  2712. "total": total,
  2713. "users": []string{},
  2714. })
  2715. }
  2716. return
  2717. }
  2718. func (c *PatientApiController) GetPrintDialysisOrder() {
  2719. xtno := c.GetString("xtno")
  2720. xtdate := c.GetString("xtdate")
  2721. timeLayout := "2006-01-02"
  2722. loc, _ := time.LoadLocation("Local")
  2723. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  2724. if err != nil {
  2725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2726. return
  2727. }
  2728. xttime := theTime.Unix()
  2729. //获取当前日期月份的第一天
  2730. firstmonth := service.GetFirstDateOfMonth(theTime)
  2731. firstMonthDate := firstmonth.Unix()
  2732. operatorIDs := make([]int64, 0)
  2733. adminUserInfo := c.GetMobileAdminUserInfo()
  2734. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  2735. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  2736. //透析单
  2737. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2738. if dialysisOrder != nil {
  2739. if dialysisOrder.FinishNurse > 0 {
  2740. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  2741. }
  2742. if dialysisOrder.StartNurse > 0 {
  2743. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  2744. }
  2745. }
  2746. last_order, _ := service.GetLastTimeOrder(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2747. //透前评估
  2748. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2749. //透后评估
  2750. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2751. if AssessmentAfterDislysis.Modifier > 0 {
  2752. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  2753. }
  2754. //透析处方
  2755. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2756. if dialysisPrescription.PrescriptionDoctor > 0 {
  2757. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  2758. }
  2759. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2760. patientInfo.TotalDialysis = dialysis_count
  2761. //临时医嘱
  2762. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2763. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2764. config, err := service.GetHisDoctorConfig(adminUserInfo.Org.Id)
  2765. project_config, _ := service.GetHisProjectConfig(adminUserInfo.Org.Id)
  2766. projects, _ := service.FindAllHisProjectById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2767. if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  2768. for _, item := range projects {
  2769. cnt, _ := strconv.ParseFloat(item.Count, 64)
  2770. var advice models.HisDoctorAdviceInfo
  2771. advice.ID = item.ID
  2772. advice.Checker = item.Checker
  2773. advice.CheckTime = item.CheckTime
  2774. advice.CheckState = item.CheckState
  2775. advice.ExecutionState = item.ExecutionState
  2776. advice.ExecutionStaff = item.ExecutionStaff
  2777. //advice.PrescribingNumber = float64(item.Count)
  2778. advice.PrescribingNumber = cnt
  2779. advice.PrescribingNumberUnit = item.Unit
  2780. advice.AdviceDoctor = item.Doctor
  2781. if item.Type == 3 {
  2782. advice.AdviceName = item.GoodInfo.GoodName
  2783. advice.PrescribingNumberUnit = item.GoodInfo.PackingUnit
  2784. } else if item.Type == 2 {
  2785. advice.AdviceName = item.HisProject.ProjectName
  2786. }
  2787. advice.StartTime = item.StartTime
  2788. hisAdvice = append(hisAdvice, &advice)
  2789. }
  2790. }
  2791. if len(DoctorAdvice) > 0 {
  2792. for _, item := range DoctorAdvice {
  2793. if item.AdviceDoctor > 0 {
  2794. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  2795. }
  2796. if item.ExecutionStaff > 0 {
  2797. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  2798. }
  2799. if item.Checker > 0 {
  2800. operatorIDs = append(operatorIDs, item.Checker)
  2801. }
  2802. }
  2803. }
  2804. //DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2805. //透析监测
  2806. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2807. //透析小结
  2808. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2809. //接诊评估
  2810. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2811. //相关操作对应的操作人
  2812. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  2813. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  2814. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2815. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2816. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.Org.Id)
  2817. if config.IsOpen == 1 {
  2818. c.ServeSuccessJSON(map[string]interface{}{
  2819. "users": adminUser,
  2820. "patientInfo": patientInfo,
  2821. "PredialysisEvaluation": PredialysisEvaluation,
  2822. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  2823. "dialysisPrescription": dialysisPrescription,
  2824. "advices": hisAdvice,
  2825. "monitors": Record,
  2826. "summary": TreatmentSummary,
  2827. "receiverTreatmentAccess": receiverTreatmentAccess,
  2828. "dialysisOrder": dialysisOrder,
  2829. "operators": operators,
  2830. "org_template_info": templateInfo,
  2831. "check": check,
  2832. "dialysiscount": dialysiscount,
  2833. "last_order": last_order,
  2834. "projects": projects,
  2835. "project_config": project_config,
  2836. })
  2837. }
  2838. if config.IsOpen == 0 || config.IsOpen == 2 {
  2839. c.ServeSuccessJSON(map[string]interface{}{
  2840. "users": adminUser,
  2841. "patientInfo": patientInfo,
  2842. "PredialysisEvaluation": PredialysisEvaluation,
  2843. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  2844. "dialysisPrescription": dialysisPrescription,
  2845. "advices": DoctorAdvice,
  2846. "monitors": Record,
  2847. "summary": TreatmentSummary,
  2848. "receiverTreatmentAccess": receiverTreatmentAccess,
  2849. "dialysisOrder": dialysisOrder,
  2850. "operators": operators,
  2851. "org_template_info": templateInfo,
  2852. "check": check,
  2853. "dialysiscount": dialysiscount,
  2854. "last_order": last_order,
  2855. "projects": projects,
  2856. "project_config": project_config,
  2857. })
  2858. }
  2859. }
  2860. func (c *PatientApiController) CreateGroupAdvice() {
  2861. is_child, _ := c.GetInt64("is_child", 0)
  2862. if is_child == 1 {
  2863. patient, _ := c.GetInt64("id", 0)
  2864. if patient <= 0 {
  2865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2866. return
  2867. }
  2868. adminUserInfo := c.GetMobileAdminUserInfo()
  2869. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  2870. if patientInfo.ID == 0 {
  2871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2872. return
  2873. }
  2874. group_no, _ := c.GetInt64("group_no")
  2875. if group_no <= 0 {
  2876. group_no = 0
  2877. }
  2878. dataBody := make(map[string]interface{}, 0)
  2879. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2880. if err != nil {
  2881. utils.ErrorLog(err.Error())
  2882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2883. return
  2884. }
  2885. timeLayout := "2006-01-02"
  2886. loc, _ := time.LoadLocation("Local")
  2887. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2888. utils.ErrorLog("advice_type")
  2889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2890. return
  2891. }
  2892. adviceType := int64(dataBody["advice_type"].(float64))
  2893. if adviceType != 1 && adviceType != 2 {
  2894. utils.ErrorLog("advice_type != 1&&2")
  2895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2896. return
  2897. }
  2898. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2899. utils.ErrorLog("start_time")
  2900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2901. return
  2902. }
  2903. startTime2, _ := dataBody["start_time"].(string)
  2904. time_arr := strings.Split(startTime2, " ")
  2905. if len(time_arr) > 0 {
  2906. startTime2 = time_arr[0]
  2907. }
  2908. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2909. utils.ErrorLog("advice_date")
  2910. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2911. return
  2912. }
  2913. adviceDate := startTime2
  2914. if len(adviceDate) == 0 {
  2915. utils.ErrorLog("len(adviceDate) == 0")
  2916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2917. return
  2918. }
  2919. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2920. if err != nil {
  2921. utils.ErrorLog(err.Error())
  2922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2923. return
  2924. }
  2925. AdviceDate := theTime.Unix()
  2926. RecordDate := theTime.Unix()
  2927. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2928. utils.ErrorLog("start_time")
  2929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2930. return
  2931. }
  2932. startTime, _ := dataBody["start_time"].(string)
  2933. if len(startTime) == 0 {
  2934. utils.ErrorLog("len(start_time) == 0")
  2935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2936. return
  2937. }
  2938. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  2939. if err != nil {
  2940. utils.ErrorLog(err.Error())
  2941. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2942. return
  2943. }
  2944. StartTime := theTime.Unix()
  2945. Remark := ""
  2946. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2947. remark, _ := dataBody["remark"].(string)
  2948. Remark = remark
  2949. }
  2950. var advices []*models.GroupAdvice
  2951. // utils.TraceLog("%+v", dataBody["adviceNames"])
  2952. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  2953. utils.ErrorLog("adviceNames")
  2954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2955. return
  2956. }
  2957. adviceNames := dataBody["adviceNames"].([]interface{})
  2958. for _, adviceNameMap := range adviceNames {
  2959. adviceNameM := adviceNameMap.(map[string]interface{})
  2960. var advice models.GroupAdvice
  2961. advice.Remark = Remark
  2962. advice.AdviceType = adviceType
  2963. advice.StartTime = StartTime
  2964. advice.AdviceDate = AdviceDate
  2965. advice.RecordDate = RecordDate
  2966. advice.Status = 1
  2967. advice.CreatedTime = time.Now().Unix()
  2968. advice.UpdatedTime = time.Now().Unix()
  2969. advice.StopState = 2
  2970. advice.ExecutionState = 2
  2971. advice.UserOrgId = adminUserInfo.Org.Id
  2972. advice.PatientId = patientInfo.ID
  2973. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2974. //入口
  2975. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  2976. if errcode > 0 {
  2977. c.ServeFailJSONWithSGJErrorCode(errcode)
  2978. return
  2979. }
  2980. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  2981. subdrugs := adviceNameM["subdrugs"].([]interface{})
  2982. if len(subdrugs) > 0 {
  2983. for _, subdrug := range subdrugs {
  2984. var s models.GroupAdvice
  2985. s.Remark = Remark
  2986. s.AdviceType = adviceType
  2987. s.StartTime = StartTime
  2988. s.AdviceDate = AdviceDate
  2989. s.RecordDate = RecordDate
  2990. s.Status = 1
  2991. s.CreatedTime = time.Now().Unix()
  2992. s.UpdatedTime = time.Now().Unix()
  2993. s.StopState = 2
  2994. s.ExecutionState = 2
  2995. s.UserOrgId = adminUserInfo.Org.Id
  2996. s.PatientId = patientInfo.ID
  2997. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  2998. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  2999. if errcode > 0 {
  3000. c.ServeFailJSONWithSGJErrorCode(errcode)
  3001. return
  3002. }
  3003. advice.Children = append(advice.Children, &s)
  3004. }
  3005. }
  3006. }
  3007. advices = append(advices, &advice)
  3008. }
  3009. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  3010. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  3011. redis := service.RedisClient()
  3012. //清空key 值
  3013. redis.Set(key, "", time.Second)
  3014. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  3015. redis.Set(keyOne, "", time.Second)
  3016. defer redis.Close()
  3017. if createErr != nil {
  3018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3019. return
  3020. }
  3021. c.ServeSuccessJSON(map[string]interface{}{
  3022. "msg": "ok",
  3023. "advices": newAdvices,
  3024. })
  3025. return
  3026. } else if is_child == 2 {
  3027. patient, _ := c.GetInt64("id", 0)
  3028. if patient <= 0 {
  3029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3030. return
  3031. }
  3032. adminUserInfo := c.GetMobileAdminUserInfo()
  3033. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  3034. if patientInfo.ID == 0 {
  3035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3036. return
  3037. }
  3038. var advice models.DoctorAdvice
  3039. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  3040. if code > 0 {
  3041. c.ServeFailJSONWithSGJErrorCode(code)
  3042. return
  3043. }
  3044. if advice.ParentId > 0 {
  3045. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  3046. if old.ID == 0 || old.PatientId != patient {
  3047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3048. return
  3049. }
  3050. if old.StopState == 1 || old.ExecutionState == 1 {
  3051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3052. return
  3053. }
  3054. if old.ParentId > 0 {
  3055. advice.ParentId = old.ParentId
  3056. }
  3057. advice.StartTime = old.StartTime
  3058. advice.AdviceDoctor = old.AdviceDoctor
  3059. advice.DeliveryWay = old.DeliveryWay
  3060. advice.ExecutionFrequency = old.ExecutionFrequency
  3061. advice.GroupNo = old.GroupNo
  3062. }
  3063. advice.Status = 1
  3064. advice.CreatedTime = time.Now().Unix()
  3065. advice.UpdatedTime = time.Now().Unix()
  3066. advice.StopState = 2
  3067. advice.ExecutionState = 2
  3068. advice.UserOrgId = adminUserInfo.Org.Id
  3069. advice.PatientId = patient
  3070. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3071. err := service.CreateDoctorAdvice(&advice)
  3072. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3073. redis := service.RedisClient()
  3074. //清空key 值
  3075. redis.Set(key, "", time.Second)
  3076. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3077. redis.Set(keyOne, "", time.Second)
  3078. fmt.Println("key`2232333332233223233232", key)
  3079. defer redis.Close()
  3080. if err != nil {
  3081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3082. return
  3083. }
  3084. c.ServeSuccessJSON(map[string]interface{}{
  3085. "msg": "ok",
  3086. "advice": advice,
  3087. })
  3088. return
  3089. }
  3090. }
  3091. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  3092. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  3093. utils.ErrorLog("advice_name")
  3094. return enums.ErrorCodeParamWrong
  3095. }
  3096. adviceName, _ := json["advice_name"].(string)
  3097. if len(adviceName) == 0 {
  3098. utils.ErrorLog("len(advice_name) == 0")
  3099. return enums.ErrorCodeParamWrong
  3100. }
  3101. advice.AdviceName = adviceName
  3102. adviceDesc, _ := json["advice_desc"].(string)
  3103. advice.AdviceDesc = adviceDesc
  3104. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3105. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3106. advice.DrugSpec = drugSpec
  3107. }
  3108. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3109. remark, _ := json["remark"].(string)
  3110. advice.Remark = remark
  3111. }
  3112. //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
  3113. // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
  3114. // advice.Way = src_type
  3115. //}
  3116. if json["way"] == nil {
  3117. advice.Way = 0
  3118. } else {
  3119. if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
  3120. way := int64(json["way"].(float64))
  3121. advice.Way = way
  3122. }
  3123. }
  3124. if json["drug_id"] == nil {
  3125. advice.DrugId = 0
  3126. } else {
  3127. if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
  3128. drug_id := int64(json["drug_id"].(float64))
  3129. advice.DrugId = drug_id
  3130. }
  3131. }
  3132. if json["drug_name_id"] == nil {
  3133. advice.DrugNameId = 0
  3134. } else {
  3135. if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
  3136. drug_name_id := int64(json["drug_name_id"].(float64))
  3137. advice.DrugNameId = drug_name_id
  3138. }
  3139. }
  3140. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  3141. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  3142. advice.DrugSpecUnit = drugSpecUnit
  3143. }
  3144. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3145. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3146. advice.SingleDose = singleDose
  3147. }
  3148. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3149. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3150. advice.SingleDoseUnit = singleDoseUnit
  3151. }
  3152. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3153. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3154. advice.PrescribingNumber = prescribingNumber
  3155. }
  3156. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3157. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3158. advice.PrescribingNumberUnit = prescribingNumberUnit
  3159. }
  3160. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3161. deliveryWay, _ := json["delivery_way"].(string)
  3162. advice.DeliveryWay = deliveryWay
  3163. }
  3164. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3165. executionFrequency, _ := json["execution_frequency"].(string)
  3166. advice.ExecutionFrequency = executionFrequency
  3167. }
  3168. return 0
  3169. }
  3170. func (c *PatientApiController) DelDoctorAdvice() {
  3171. groupno, _ := c.GetInt64("groupno", -1)
  3172. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  3173. patient_id, _ := c.GetInt64("patient_id")
  3174. doc_advice_date, _ := c.GetInt64("advice_date")
  3175. redis := service.RedisClient()
  3176. if is_sub == 1 { //是
  3177. advice_id, _ := c.GetInt64("advice_id")
  3178. adminUserInfo := c.GetMobileAdminUserInfo()
  3179. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  3180. if advice.ID == 0 {
  3181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3182. return
  3183. }
  3184. advice.Status = 0
  3185. advice.UpdatedTime = time.Now().Unix()
  3186. advice.Modifier = adminUserInfo.AdminUser.Id
  3187. err := service.DeleteDoctorAdvice(&advice)
  3188. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  3189. redis.Set(key, "", time.Second)
  3190. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  3191. redis.Set(keyTwo, "", time.Second)
  3192. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  3193. redis.Set(keyThree, "", time.Second)
  3194. redis.Close()
  3195. if err != nil {
  3196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3197. return
  3198. }
  3199. c.ServeSuccessJSON(map[string]interface{}{
  3200. "msg": "ok",
  3201. })
  3202. return
  3203. } else { //
  3204. var ids []string
  3205. if groupno == 0 {
  3206. advice_id := c.GetString("advice_id")
  3207. ids = strings.Split(advice_id, ",")
  3208. if len(ids) <= 0 {
  3209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3210. return
  3211. }
  3212. }
  3213. if groupno < 0 {
  3214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3215. return
  3216. }
  3217. adminUserInfo := c.GetMobileAdminUserInfo()
  3218. var advice models.DoctorAdvice
  3219. if groupno > 0 {
  3220. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  3221. if advice.ID == 0 {
  3222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3223. return
  3224. }
  3225. } else {
  3226. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  3227. for _, item := range advices {
  3228. if item.ID == 0 {
  3229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3230. return
  3231. }
  3232. }
  3233. }
  3234. advice.UpdatedTime = time.Now().Unix()
  3235. advice.Status = 0
  3236. advice.GroupNo = groupno
  3237. advice.Modifier = adminUserInfo.AdminUser.Id
  3238. var err error
  3239. if groupno > 0 {
  3240. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  3241. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  3242. fmt.Println("key2332323223323232323232323", key)
  3243. redis.Set(key, "", time.Second)
  3244. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  3245. redis.Set(keyTwo, "", time.Second)
  3246. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  3247. redis.Set(keyThree, "", time.Second)
  3248. } else {
  3249. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  3250. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  3251. redis.Set(key, "", time.Second)
  3252. fmt.Println("key2332323223323232323232323", key)
  3253. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  3254. fmt.Println("key2332323223323232323232323", keyTwo)
  3255. redis.Set(keyTwo, "", time.Second)
  3256. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  3257. redis.Set(keyThree, "", time.Second)
  3258. redis.Close()
  3259. }
  3260. if err != nil {
  3261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3262. return
  3263. }
  3264. c.ServeSuccessJSON(map[string]interface{}{
  3265. "msg": "ok",
  3266. })
  3267. return
  3268. }
  3269. }
  3270. // /m/api/advice/group/modify_starttime [post]
  3271. // @param group_no:int
  3272. // @param start_time:string yyyy-MM-dd hh:mm:ss
  3273. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  3274. group_no, _ := this.GetInt64("group_no")
  3275. start_time_str := this.GetString("start_time")
  3276. if group_no <= 0 || len(start_time_str) == 0 {
  3277. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3278. return
  3279. }
  3280. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  3281. if parseTimeErr != nil {
  3282. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  3283. return
  3284. }
  3285. adminUserInfo := this.GetMobileAdminUserInfo()
  3286. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  3287. if updateStartTimeErr != nil {
  3288. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  3289. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3290. return
  3291. }
  3292. this.ServeSuccessJSON(map[string]interface{}{
  3293. "start_time": startTime.Unix(),
  3294. })
  3295. }
  3296. func (this *PatientApiController) DelSubDoctorAdvice() {
  3297. advice_id, _ := this.GetInt64("advice_id")
  3298. adminUserInfo := this.GetMobileAdminUserInfo()
  3299. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  3300. if advice.ID == 0 {
  3301. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3302. return
  3303. }
  3304. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  3305. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  3306. // return
  3307. //}
  3308. advice.Status = 0
  3309. advice.UpdatedTime = time.Now().Unix()
  3310. advice.Modifier = adminUserInfo.AdminUser.Id
  3311. err := service.DeleteDoctorAdvice(&advice)
  3312. if err != nil {
  3313. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3314. return
  3315. }
  3316. this.ServeSuccessJSON(map[string]interface{}{
  3317. "msg": "ok",
  3318. })
  3319. return
  3320. }
  3321. func (this *PatientApiController) GetAdviceUnReadMessage() {
  3322. //adminUserInfo := this.GetMobileAdminUserInfo()
  3323. //service.FindUnReadDoctorAdviceMessage()
  3324. }
  3325. func (this *PatientApiController) GetPatientsByKeyWord() {
  3326. keyWord := this.GetString("keyword")
  3327. adminUserInfo := this.GetMobileAdminUserInfo()
  3328. today := utils.ZeroHourTimeOfDay(time.Now())
  3329. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  3330. if err != nil {
  3331. utils.ErrorLog(err.Error())
  3332. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3333. return
  3334. }
  3335. this.ServeSuccessJSON(map[string]interface{}{
  3336. "patient": patient,
  3337. })
  3338. }
  3339. func (this *PatientApiController) GetSearchPatient() {
  3340. keyWord := this.GetString("keyword")
  3341. adminUserInfo := this.GetMobileAdminUserInfo()
  3342. patient, err := service.GetPatientsByKey(adminUserInfo.Org.Id, keyWord)
  3343. if err != nil {
  3344. utils.ErrorLog(err.Error())
  3345. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3346. return
  3347. }
  3348. this.ServeSuccessJSON(map[string]interface{}{
  3349. "patient": patient,
  3350. })
  3351. }
  3352. func (c *PatientApiController) ExecProject() {
  3353. execution_time := c.GetString("execution_time")
  3354. project_id, _ := c.GetInt64("project_id")
  3355. team_id, _ := c.GetInt64("team_id")
  3356. is_check_team, _ := c.GetInt64("is_check_team")
  3357. if len(execution_time) <= 0 {
  3358. utils.ErrorLog("execution_time")
  3359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3360. return
  3361. }
  3362. timeLayout2 := "2006-01-02 15:04:05"
  3363. loc, _ := time.LoadLocation("Local")
  3364. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  3365. if errs != nil {
  3366. utils.ErrorLog(errs.Error())
  3367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3368. return
  3369. }
  3370. adminInfo := c.GetMobileAdminUserInfo()
  3371. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  3372. if project.ExecutionState == 1 {
  3373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  3374. return
  3375. }
  3376. if project.Checker >= 0 && project.Checker == adminInfo.AdminUser.Id {
  3377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  3378. return
  3379. }
  3380. project.ExecutionState = 1
  3381. project.ExecutionStaff = adminInfo.AdminUser.Id
  3382. project.ExecutionTime = theTime.Unix()
  3383. if team_id == 0 {
  3384. err := service.SaveHisProject(&project)
  3385. if err == nil {
  3386. c.ServeSuccessJSON(map[string]interface{}{
  3387. "project": project,
  3388. })
  3389. } else {
  3390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3391. return
  3392. }
  3393. } else {
  3394. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  3395. err := service.SaveHisProject(&project)
  3396. if err == nil {
  3397. c.ServeSuccessJSON(map[string]interface{}{
  3398. "project": project,
  3399. })
  3400. } else {
  3401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3402. return
  3403. }
  3404. } else {
  3405. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  3406. var ids []int64
  3407. for _, items := range ps {
  3408. ids = append(ids, items.ID)
  3409. }
  3410. err := service.UpdateTeamProjectExceStatus(ids, adminInfo.AdminUser.Id, theTime.Unix())
  3411. if err == nil {
  3412. c.ServeSuccessJSON(map[string]interface{}{
  3413. "project": project,
  3414. })
  3415. } else {
  3416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3417. return
  3418. }
  3419. }
  3420. }
  3421. }
  3422. func (c *PatientApiController) CheckProject() {
  3423. adminInfo := c.GetMobileAdminUserInfo()
  3424. project_id, _ := c.GetInt64("project_id")
  3425. team_id, _ := c.GetInt64("team_id")
  3426. is_check_team, _ := c.GetInt64("is_check_team")
  3427. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  3428. if project.CheckState == 1 {
  3429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  3430. return
  3431. }
  3432. if project.ExecutionStaff >= 0 && project.ExecutionStaff == adminInfo.AdminUser.Id {
  3433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  3434. return
  3435. }
  3436. project.Checker = adminInfo.AdminUser.Id
  3437. project.CheckTime = time.Now().Unix()
  3438. project.CheckState = 1
  3439. if team_id == 0 {
  3440. err := service.SaveHisProject(&project)
  3441. if err == nil {
  3442. c.ServeSuccessJSON(map[string]interface{}{
  3443. "msg": "ok",
  3444. "project": project,
  3445. })
  3446. } else {
  3447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3448. return
  3449. }
  3450. } else {
  3451. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  3452. err := service.SaveHisProject(&project)
  3453. if err == nil {
  3454. c.ServeSuccessJSON(map[string]interface{}{
  3455. "msg": "ok",
  3456. "project": project,
  3457. })
  3458. } else {
  3459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3460. return
  3461. }
  3462. } else {
  3463. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  3464. var ids []int64
  3465. for _, items := range ps {
  3466. ids = append(ids, items.ID)
  3467. }
  3468. err := service.UpdateTeamProjectCheckStatus(ids, project.PatientId, project.RecordDate, project.UserOrgId, adminInfo.AdminUser.Id, time.Now().Unix())
  3469. if err == nil {
  3470. c.ServeSuccessJSON(map[string]interface{}{
  3471. "project": project,
  3472. })
  3473. } else {
  3474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3475. return
  3476. }
  3477. }
  3478. }
  3479. }