patient_api_controller.go 129KB

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