1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831 |
- package controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "encoding/json"
- "fmt"
- "reflect"
- "strconv"
- "time"
-
- "github.com/astaxie/beego"
- )
-
- type DataApiController struct {
- BaseAuthAPIController
- }
-
- func DataApiRegistRouters() {
- beego.Router("/api/getconfiglist", &DataApiController{}, "get,post:GetConfigList")
- beego.Router("/api/createconfig", &DataApiController{}, "Post:CreateConfig")
- beego.Router("/api/createchildconfig", &DataApiController{}, "Post:CreateChildConfig")
- beego.Router("/api/updatechildconfig", &DataApiController{}, "Post:UpdateChildConfig")
- beego.Router("/api/deletechildconfig", &DataApiController{}, "Post:DeleteChildConfig")
- beego.Router("/api/updatetemplate", &DataApiController{}, "Post:UpdateTemplate")
-
- beego.Router("/api/getadviceconfigs", &DataApiController{}, "Get:GetAdviceConfigs")
- beego.Router("/api/getalladviceconfig", &DataApiController{}, "Get:GetAllAdviceConfigs")
-
- beego.Router("/api/drugdic/create", &DataApiController{}, "Post:CreateDrugDic")
- beego.Router("/api/drugdic/update", &DataApiController{}, "Put:UpdateDrugDic")
- beego.Router("/api/drugdic/delete", &DataApiController{}, "Delete:DeleteDrugDic")
- beego.Router("/api/drugway/create", &DataApiController{}, "Post:CreateDrugWay")
- beego.Router("/api/drugway/update", &DataApiController{}, "Put:UpdateDrugWay")
- beego.Router("/api/drugway/delete", &DataApiController{}, "Delete:DeleteDrugWay")
- beego.Router("/api/executionfrequency/create", &DataApiController{}, "Post:CreateExecutionFrequency")
- beego.Router("/api/executionfrequency/update", &DataApiController{}, "Put:UpdateExecutionFrequency")
- beego.Router("/api/executionfrequency/delete", &DataApiController{}, "Delete:DeleteExecutionFrequency")
-
- beego.Router("/api/advicetemplate/create", &DataApiController{}, "Post:CreateAdviceTemplate")
- beego.Router("/api/subadvice/create", &DataApiController{}, "Post:CreateSubAdviceTemplate")
- beego.Router("/api/advicetemplate/update", &DataApiController{}, "Put:UpdateAdviceTemplate")
- beego.Router("/api/advicetemplate/delete", &DataApiController{}, "Delete:DeleteAdviceTemplate")
- beego.Router("/api/advicetemplate/add", &DataApiController{}, "Post:CreateSingleAdviceTemplate")
- beego.Router("/api/adviceparenttemplate/delete", &DataApiController{}, "Delete:DeleteParentAdviceTemplate")
- beego.Router("/api/template/modify", &DataApiController{}, "Post:ModifyTemplateName")
-
- beego.Router("/api/filed/show", &DataApiController{}, "Post:ModifyFiledIsShow")
- beego.Router("/article/hanleupdatetwo", &DataApiController{}, "Get:GetHandleData")
- beego.Router("/article/updatedatatwo", &DataApiController{}, "Post:UpdateDataTwo")
-
- beego.Router("/api/hisadvicetemplate/create", &DataApiController{}, "Post:CreateHisAdviceTemplate")
- beego.Router("/api/hisadvicetemplate/update", &DataApiController{}, "Put:UpdateHisAdviceTemplate")
- beego.Router("/api/hisadvicetemplate/delete", &DataApiController{}, "Delete:DeleteHisAdviceTemplate")
- beego.Router("/api/hisadvicetemplate/add", &DataApiController{}, "Post:CreateSingleHisAdviceTemplate")
- beego.Router("/api/hisadviceparenttemplate/delete", &DataApiController{}, "Delete:DeleteHisParentAdviceTemplate")
- beego.Router("/api/histemplate/modify", &DataApiController{}, "Post:ModifyHisTemplateName")
- beego.Router("/api/getallhisadvicetemplate", &DataApiController{}, "Get:GetAllHisAdviceTemplate")
-
- }
-
- //GetPatientsList 取配置信息列表
- func (c *DataApiController) GetConfigList() {
- adminUserInfo := c.GetAdminUserInfo()
- configList, _ := service.GetConfigList(adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "configlist": configList,
- })
- return
-
- }
-
- //CreateConfig 创建配置信息
- func (c *DataApiController) CreateConfig() {
- adminUserInfo := c.GetAdminUserInfo()
-
- var dataconfig models.Dataconfig
- var resultConfig models.ConfigViewModel
- code := configFormData(&dataconfig, c.Ctx.Input.RequestBody)
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
- // 验证关键字段的值是否重复
-
- thisConfig, _ := service.FindConfigByTitle(dataconfig.Module, dataconfig.FieldName, adminUserInfo.CurrentOrgId)
- fmt.Println("99999", thisConfig)
- if thisConfig.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
- return
- }
-
- fieldValue := service.GetChildValue(dataconfig.Module, dataconfig.ParentId, adminUserInfo.CurrentOrgId)
- dataconfig.Value = fieldValue + 1
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- dataconfig.OrgId = adminUserInfo.CurrentOrgId
- dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
- dataconfig.Status = 1
- dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
- dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
- dataconfig.Remark = string(dataBody["remark"].(string))
- if dataBody["order"] != nil {
- dataconfig.Order = int64(dataBody["order"].(float64))
- } else {
- dataconfig.Order = 0
- }
-
- err = service.CreateConfig(&dataconfig)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
- return
- } else {
- resultConfig.ID = dataconfig.ID
- resultConfig.Module = dataconfig.Module
- resultConfig.Name = dataconfig.Name
- resultConfig.OrgId = dataconfig.OrgId
- resultConfig.ParentId = dataconfig.ParentId
- resultConfig.FieldName = dataconfig.FieldName
- resultConfig.CreateUserId = dataconfig.CreateUserId
- resultConfig.Title = dataconfig.Title
- resultConfig.Content = dataconfig.Content
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "dataconfig": resultConfig,
- "msg": "ok",
- })
- return
- }
-
- func (c *DataApiController) UpdateTemplate() {
- adminUserInfo := c.GetAdminUserInfo()
- var dataconfig models.Dataconfig
- code := configFormData(&dataconfig, c.Ctx.Input.RequestBody)
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- dataconfig.OrgId = adminUserInfo.CurrentOrgId
- dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
- dataconfig.Status = 1
- dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
- dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
- dataconfig.Remark = string(dataBody["remark"].(string))
- if dataBody["order"] != nil {
- dataconfig.Order = int64(dataBody["order"].(float64))
- } else {
- dataconfig.Order = 0
- }
-
- // 验证关键字段的值是否重复
- // cur_id := int64(dataBody["id"].(float64))
- // thisConfig,_:=service.FindConfigByTitleForUpdate(dataconfig.Module, dataconfig.Title,dataconfig.OrgId,cur_id)
- // if thisConfig.ID >0 {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
- // return
- // }
-
- configOrgId := int64(dataBody["org_id"].(float64))
- if configOrgId == 0 {
- dataconfig.DeleteIdSystem = int64(dataBody["id"].(float64))
- err := service.CreateConfig(&dataconfig)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
- return
- }
- } else {
- dataconfig.ID = int64(dataBody["id"].(float64))
- err = service.UpdateTemplate(&dataconfig)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
- return
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "dataconfig": dataconfig,
- "msg": "ok",
- })
- return
- }
-
- func (c *DataApiController) UpdateChildConfig() {
- adminUserInfo := c.GetAdminUserInfo()
- var dataconfig models.Dataconfig
- code := configChildFormData(&dataconfig, c.Ctx.Input.RequestBody)
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- dataconfig.OrgId = adminUserInfo.CurrentOrgId
- dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
- dataconfig.Status = 1
- dataconfig.Value = int(int64(dataBody["value"].(float64)))
- dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
- dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
- dataconfig.Remark = string(dataBody["remark"].(string))
- dataconfig.Order = int64(dataBody["orders"].(float64))
- dataconfig.FieldType = int64(dataBody["field_type"].(float64))
-
- //if dataBody["orders"] != nil {
- // dataconfig.Order = int64(dataBody["orders"].(float64))
- // fmt.Println("dataconfig",dataconfig.Order)
- //} else {
- // dataconfig.Order = 0
- //}
- configOrgId := int64(dataBody["org_id"].(float64))
- // 验证关键字段的值是否重复
- // configId := int64(dataBody["id"].(float64))
- // thisConfig,_:=service.FindConfigByNameForUpdate(dataconfig.Module, dataconfig.Name,dataconfig.ParentId,dataconfig.OrgId,configId)
- // if thisConfig.ID >0 {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
- // return
- // }
-
- if configOrgId == 0 {
- dataconfig.DeleteIdSystem = int64(dataBody["id"].(float64))
- err := service.CreateConfig(&dataconfig)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
- return
- }
- } else {
- dataconfig.ID = int64(dataBody["id"].(float64))
- err = service.UpdateChildConfig(&dataconfig)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
- return
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "dataconfig": dataconfig,
- "msg": "ok",
- })
- return
- }
-
- func (c *DataApiController) DeleteChildConfig() {
- adminUserInfo := c.GetAdminUserInfo()
- var dataconfig models.Dataconfig
- code := configChildFormData(&dataconfig, c.Ctx.Input.RequestBody)
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- dataconfig.OrgId = adminUserInfo.CurrentOrgId
- dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
- dataconfig.Status = 0
- dataconfig.Value = int(int64(dataBody["value"].(float64)))
- dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
- dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
- dataconfig.Remark = string(dataBody["remark"].(string))
- if dataBody["order"] != nil {
- dataconfig.Order = int64(dataBody["order"].(float64))
- } else {
- dataconfig.Order = 0
- }
- configOrgId := int64(dataBody["org_id"].(float64))
-
- if configOrgId == 0 {
- dataconfig.DeleteIdSystem = int64(dataBody["id"].(float64))
- err := service.CreateConfig(&dataconfig)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
- return
- }
- } else {
- dataconfig.ID = int64(dataBody["id"].(float64))
- err := service.DeleteChildConfig(&dataconfig)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
- return
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "dataconfig": dataconfig,
- "msg": "ok",
- })
- return
- }
-
- //CreateChildConfig 创建子配置信息
- func (c *DataApiController) CreateChildConfig() {
- adminUserInfo := c.GetAdminUserInfo()
-
- var dataconfig models.Dataconfig
- code := configChildFormData(&dataconfig, c.Ctx.Input.RequestBody)
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- dataconfig.OrgId = adminUserInfo.CurrentOrgId
- dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
- dataconfig.Status = 1
- dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
- dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
- dataconfig.Remark = string(dataBody["remark"].(string))
- if dataBody["order"] != nil {
- dataconfig.Order = int64(dataBody["order"].(float64))
- } else {
- dataconfig.Order = 0
- }
-
- if dataBody["field_type"] != nil {
- dataconfig.FieldType = int64(dataBody["field_type"].(float64))
- } else {
- dataconfig.FieldType = 0
- }
-
- // 验证关键字段的值是否重复
- // thisConfig,_:=service.FindConfigByName(dataconfig.Module, dataconfig.Name,dataconfig.ParentId,dataconfig.OrgId)
- // if thisConfig.ID >0 {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
- // return
- // }
-
- fieldValue := service.GetChildValue(dataconfig.Module, dataconfig.ParentId, dataconfig.OrgId)
- dataconfig.Value = fieldValue + 1
-
- err = service.CreateConfig(&dataconfig)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "dataconfig": dataconfig,
- "msg": "ok",
- })
- return
- }
-
- func configFormData(dataconfig *models.Dataconfig, data []byte) (code int) {
- configBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(data, &configBody)
- utils.InfoLog(string(data))
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
- if configBody["module"] == nil || reflect.TypeOf(configBody["module"]).String() != "string" {
- utils.ErrorLog("module")
- code = enums.ErrorCodeParamWrong
- return
- }
- module, _ := configBody["module"].(string)
- if len(module) == 0 {
- utils.ErrorLog("len(module) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- dataconfig.Module = module
-
- if module == "education" || module == "summary" || module == "course_disease" || module == "rescue_record" || module == "nursing_record" || module == "special_record" || module == "special_treatment" || module == "template_summary" || module == "template_plan" || module == "admitting_diagnosis" || module == "discharge_diagnosis" || module == "diagnosis_admission" || module == "treatment" || module == "illness_discharge" || module == "discharge_advice" {
- if configBody["title"] == nil || reflect.TypeOf(configBody["title"]).String() != "string" {
- utils.ErrorLog("title")
- code = enums.ErrorCodeParamWrong
- return
- }
- title, _ := configBody["title"].(string)
- if len(title) == 0 {
- utils.ErrorLog("len(title) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- dataconfig.Title = title
-
- if configBody["content"] == nil || reflect.TypeOf(configBody["content"]).String() != "string" {
- utils.ErrorLog("content")
- code = enums.ErrorCodeParamWrong
- return
- }
- content, _ := configBody["content"].(string)
- if len(content) == 0 {
- utils.ErrorLog("len(content) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- dataconfig.Content = content
- } else {
- if configBody["name"] == nil || reflect.TypeOf(configBody["name"]).String() != "string" {
- utils.ErrorLog("name")
- code = enums.ErrorCodeParamWrong
- return
- }
- name, _ := configBody["name"].(string)
- if len(name) == 0 {
- utils.ErrorLog("len(name) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- dataconfig.Name = name
-
- if configBody["field_name"] == nil || reflect.TypeOf(configBody["field_name"]).String() != "string" {
- utils.ErrorLog("field_name")
- code = enums.ErrorCodeParamWrong
- return
- }
- field_name, _ := configBody["field_name"].(string)
- if len(field_name) == 0 {
- utils.ErrorLog("len(field_name) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- dataconfig.FieldName = field_name
- }
- return
- }
-
- func configChildFormData(dataconfig *models.Dataconfig, data []byte) (code int) {
- configBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(data, &configBody)
- utils.InfoLog(string(data))
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
-
- if configBody["module"] == nil || reflect.TypeOf(configBody["module"]).String() != "string" {
- utils.ErrorLog("module")
- code = enums.ErrorCodeParamWrong
- return
- }
- module, _ := configBody["module"].(string)
- if len(module) == 0 {
- utils.ErrorLog("len(module) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- dataconfig.Module = module
-
- if module == "education" || module == "summary" {
- if configBody["title"] == nil || reflect.TypeOf(configBody["title"]).String() != "string" {
- utils.ErrorLog("title")
- code = enums.ErrorCodeParamWrong
- return
- }
- title, _ := configBody["title"].(string)
- if len(title) == 0 {
- utils.ErrorLog("len(title) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- dataconfig.Title = title
-
- if configBody["content"] == nil || reflect.TypeOf(configBody["content"]).String() != "string" {
- utils.ErrorLog("content")
- code = enums.ErrorCodeParamWrong
- return
- }
- content, _ := configBody["content"].(string)
- if len(content) == 0 {
- utils.ErrorLog("len(content) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- dataconfig.Content = content
- } else {
- if configBody["parent_id"] == nil || reflect.TypeOf(configBody["parent_id"]).String() != "float64" {
- utils.ErrorLog("module")
- code = enums.ErrorCodeParamWrong
- return
- }
- parent_id := int64(configBody["parent_id"].(float64))
- //if parent_id <= 0 {
- // utils.ErrorLog("parent_id <= 0")
- // code = enums.ErrorCodeParamWrong
- // return
- //}
- dataconfig.ParentId = parent_id
-
- if configBody["name"] == nil || reflect.TypeOf(configBody["name"]).String() != "string" {
- utils.ErrorLog("name")
- code = enums.ErrorCodeParamWrong
- return
- }
- name, _ := configBody["name"].(string)
- //if len(name) == 0 {
- // utils.ErrorLog("len(name) == 0")
- // code = enums.ErrorCodeParamWrong
- // return
- //}
- dataconfig.Name = name
- }
- return
- }
-
- func (c *DataApiController) GetAdviceConfigs() {
- advice_type, _ := c.GetInt64("type", 0)
- adminUserInfo := c.GetAdminUserInfo()
- var drugs []models.DrugDic
- drugways, _, _ := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
- efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
- adviceTemplates, _ := service.FindAllAdviceTemplate(adminUserInfo.CurrentOrgId, advice_type)
- c.ServeSuccessJSON(map[string]interface{}{
- "drugs": drugs,
- "drugways": drugways,
- "efs": efs,
- "advice_templates": adviceTemplates,
- })
- }
-
- func (c *DataApiController) CreateDrugDic() {
-
- adminUserInfo := c.GetAdminUserInfo()
-
- var drugdic models.DrugDic
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &drugdic)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if drugdic.Name == "" {
- utils.ErrorLog("医嘱名称不能为空")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeNow := time.Now().Unix()
- drugdic.Code = ""
- drugdic.Status = 1
- drugdic.CreatedTime = timeNow
- drugdic.UpdatedTime = timeNow
- drugdic.OrgId = adminUserInfo.CurrentOrgId
- drugdic.Creator = adminUserInfo.AdminUser.Id
-
- err = service.CreateDrugDic(&drugdic)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
- return
- }
-
- drugways_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_drugways"
-
- redis := service.RedisClient()
- defer redis.Close()
- redis.Set(drugways_keys, "", time.Second*60*60*18)
- c.ServeSuccessJSON(map[string]interface{}{
- "drugdic": drugdic,
- })
- return
- }
-
- func (c *DataApiController) UpdateDrugDic() {
-
- adminUserInfo := c.GetAdminUserInfo()
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- drugdic, _ := service.FindDrugDic(adminUserInfo.CurrentOrgId, id)
- if drugdic == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
- return
- }
-
- var drugdicdata models.DrugDic
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &drugdicdata)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if drugdicdata.Name == "" {
- utils.ErrorLog("医嘱名称不能为空")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeNow := time.Now().Unix()
- drugdic.UpdatedTime = timeNow
- drugdic.Name = drugdicdata.Name
- drugdic.Spec = drugdicdata.Spec
- drugdic.SpecUnit = drugdicdata.SpecUnit
- drugdic.Form = drugdicdata.Form
- drugdic.FormUnit = drugdicdata.FormUnit
-
- err = service.UpdateDrugDic(drugdic)
-
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- return
- }
-
- drugways_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_drugways"
-
- redis := service.RedisClient()
- defer redis.Close()
- redis.Set(drugways_keys, "", time.Second*60*60*18)
- c.ServeSuccessJSON(map[string]interface{}{
- "drugdic": drugdic,
- })
- return
- }
-
- func (c *DataApiController) DeleteDrugDic() {
- adminUserInfo := c.GetAdminUserInfo()
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drugdic, _ := service.FindDrugDic(adminUserInfo.CurrentOrgId, id)
- if drugdic == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
- return
- }
- timeNow := time.Now().Unix()
- drugdic.UpdatedTime = timeNow
- drugdic.Status = 2
-
- err := service.UpdateDrugDic(drugdic)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
- return
- }
- drugways_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_drugways"
-
- redis := service.RedisClient()
- defer redis.Close()
- redis.Set(drugways_keys, "", time.Second*60*60*18)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- func (c *DataApiController) CreateDrugWay() {
-
- adminUserInfo := c.GetAdminUserInfo()
-
- var drugway models.DrugwayDic
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &drugway)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if drugway.Name == "" {
- utils.ErrorLog("给药途径不能为空")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeNow := time.Now().Unix()
- drugway.Code = ""
- drugway.Status = 1
- drugway.CreatedTime = timeNow
- drugway.UpdatedTime = timeNow
- drugway.OrgId = adminUserInfo.CurrentOrgId
- drugway.Creator = adminUserInfo.AdminUser.Id
-
- err = service.CreateDrugWay(&drugway)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
- return
- }
- drugways_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_drugways"
-
- redis := service.RedisClient()
- defer redis.Close()
- redis.Set(drugways_keys, "", time.Second*60*60*18)
- c.ServeSuccessJSON(map[string]interface{}{
- "drugway": drugway,
- })
- return
- }
-
- func (c *DataApiController) UpdateDrugWay() {
-
- adminUserInfo := c.GetAdminUserInfo()
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- drugway, _ := service.FindDrugWay(adminUserInfo.CurrentOrgId, id)
- if drugway == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
- return
- }
-
- var drugwaydata models.DrugwayDic
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &drugwaydata)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if drugwaydata.Name == "" {
- utils.ErrorLog("给药途径不能为空")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeNow := time.Now().Unix()
- drugway.UpdatedTime = timeNow
- drugway.Name = drugwaydata.Name
-
- err = service.UpdateDrugWay(drugway)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- return
- }
- drugways_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_drugways"
-
- redis := service.RedisClient()
- defer redis.Close()
- redis.Set(drugways_keys, "", time.Second*60*60*18)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "drugway": drugway,
- })
- return
- }
-
- func (c *DataApiController) DeleteDrugWay() {
- adminUserInfo := c.GetAdminUserInfo()
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- drugway, _ := service.FindDrugWay(adminUserInfo.CurrentOrgId, id)
- if drugway == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
- return
- }
-
- timeNow := time.Now().Unix()
- drugway.UpdatedTime = timeNow
- drugway.Status = 2
-
- err := service.UpdateDrugWay(drugway)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
- return
- }
- drugways_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_drugways"
-
- redis := service.RedisClient()
- defer redis.Close()
- redis.Set(drugways_keys, "", time.Second*60*60*18)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- func (c *DataApiController) CreateExecutionFrequency() {
-
- adminUserInfo := c.GetAdminUserInfo()
-
- var ef models.ExecutionFrequencyDic
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &ef)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if ef.Name == "" {
- utils.ErrorLog("执行频率不能为空")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeNow := time.Now().Unix()
- ef.Code = ""
- ef.Status = 1
- ef.CreatedTime = timeNow
- ef.UpdatedTime = timeNow
- ef.OrgId = adminUserInfo.CurrentOrgId
- ef.Creator = adminUserInfo.AdminUser.Id
-
- err = service.CreateExecutionFrequency(&ef)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
- return
- }
-
- efs_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_efs"
- redis := service.RedisClient()
- defer redis.Close()
- redis.Set(efs_keys, "", time.Second*60*60*18)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "ef": ef,
- })
- return
- }
-
- func (c *DataApiController) UpdateExecutionFrequency() {
-
- adminUserInfo := c.GetAdminUserInfo()
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- ef, _ := service.FindExecutionFrequency(adminUserInfo.CurrentOrgId, id)
- if ef == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
- return
- }
-
- var efdata models.ExecutionFrequencyDic
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &efdata)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if efdata.Name == "" {
- utils.ErrorLog("执行频率不能为空")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeNow := time.Now().Unix()
- ef.UpdatedTime = timeNow
- ef.Name = efdata.Name
-
- err = service.UpdateExecutionFrequency(ef)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- return
- }
- efs_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_efs"
- redis := service.RedisClient()
- defer redis.Close()
- redis.Set(efs_keys, "", time.Second*60*60*18)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "ef": ef,
- })
- return
- }
-
- func (c *DataApiController) DeleteExecutionFrequency() {
- adminUserInfo := c.GetAdminUserInfo()
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- ef, _ := service.FindExecutionFrequency(adminUserInfo.CurrentOrgId, id)
- if ef == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
- return
- }
-
- timeNow := time.Now().Unix()
- ef.UpdatedTime = timeNow
- ef.Status = 2
-
- err := service.UpdateExecutionFrequency(ef)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
- return
- }
- efs_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_efs"
- redis := service.RedisClient()
- defer redis.Close()
- redis.Set(efs_keys, "", time.Second*60*60*18)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- func (c *DataApiController) CreateAdviceTemplate() {
- templateName := c.GetString("template_name")
- advice_type, _ := c.GetInt64("advice_type")
- sort, _ := c.GetInt64("sort")
-
- if templateName == "" {
- utils.ErrorLog("模版名称不能为空")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
- return
- }
-
- if advice_type < 0 {
- utils.ErrorLog("医嘱模版类型不能为空")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceTypeWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
- if appRole.UserType == 3 {
- headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- if getPermissionErr != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if headNursePermission == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
- return
- }
- }
-
- template := &models.DoctorAdviceParentTemplate{
- Name: templateName,
- OrgId: adminUserInfo.CurrentOrgId,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- AdviceType: advice_type,
- Sort: sort,
- }
-
- createErr := service.CreateTemplate(template)
- if createErr != nil {
- utils.ErrorLog("%v", createErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- var subTemplate []*models.DoctorAdviceTemplate
- if dataBody["data"] != nil && reflect.TypeOf(dataBody["data"]).String() == "[]interface {}" {
- subTemp, _ := dataBody["data"].([]interface{})
- if len(subTemp) > 0 {
- for _, item := range subTemp {
- items := item.(map[string]interface{})
- if items["advice_name"] == nil || reflect.TypeOf(items["advice_name"]).String() != "string" {
- utils.ErrorLog("advice_name")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advice_name, _ := items["advice_name"].(string)
- advice_desc, _ := items["advice_desc"].(string)
- single_dose_unit, _ := items["single_dose_unit"].(string)
- prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
- delivery_way, _ := items["delivery_way"].(string)
- execution_frequency, _ := items["execution_frequency"].(string)
- drug_spec, _ := items["drug_spec"].(string)
- drug_spec_unit, _ := items["drug_spec_unit"].(string)
- single_dose := items["single_dose"].(float64)
- prescribing_number := items["prescribing_number"].(float64)
-
- day_count, _ := strconv.ParseInt(items["day_count"].(string), 10, 64)
- weekdays := items["weekdays"].(string)
- frequency_type := int64(items["frequency_type"].(float64))
-
- drug_id := int64(items["drug_id"].(float64))
-
- way := int64(items["way"].(float64))
-
- subTemps := &models.DoctorAdviceTemplate{
- AdviceName: advice_name,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- OrgId: adminUserInfo.CurrentOrgId,
- AdviceDesc: advice_desc,
- AdviceType: advice_type,
- SingleDoseUnit: single_dose_unit,
- PrescribingNumber: prescribing_number,
- PrescribingNumberUnit: prescribing_number_unit,
- DeliveryWay: delivery_way,
- ExecutionFrequency: execution_frequency,
- TemplateId: template.ID,
- DrugSpec: drug_spec,
- DrugSpecUnit: drug_spec_unit,
- SingleDose: single_dose,
- AdviceDoctor: adminUserInfo.AdminUser.Id,
- DayCount: day_count,
- WeekDays: weekdays,
- FrequencyType: frequency_type,
- Way: way,
- DrugId: drug_id,
- DrugNameId: 0,
- }
- subTemplate = append(subTemplate, subTemps)
-
- }
- }
- }
- //errs := service.CreateBatchRecord(subTemplate)
- errs := service.CreateSubTemplate(subTemplate)
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
- return
- }
- templates, _ := service.FindDoctorAdviceTemplateById(template.ID, adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "template": templates,
- })
- return
- }
-
- func (c *DataApiController) UpdateAdviceTemplate() {
-
- adminUserInfo := c.GetAdminUserInfo()
- id, _ := c.GetInt64("id", 0)
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- template, _ := service.FindAdviceTemplate(adminUserInfo.CurrentOrgId, id)
- if template == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
- return
- }
-
- //TODO 根据路由来做权限
- //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
- //if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- var templatedata models.DoctorAdviceTemplate
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &templatedata)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if templatedata.AdviceName == "" {
- utils.ErrorLog("不能为空")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeNow := time.Now().Unix()
- template.UpdatedTime = timeNow
- template.AdviceName = templatedata.AdviceName
- template.AdviceDesc = templatedata.AdviceDesc
- template.SingleDose = templatedata.SingleDose
- template.SingleDoseUnit = templatedata.SingleDoseUnit
- template.PrescribingNumber = templatedata.PrescribingNumber
- template.PrescribingNumberUnit = templatedata.PrescribingNumberUnit
- template.DrugSpec = templatedata.DrugSpec
- template.DrugSpecUnit = templatedata.DrugSpecUnit
- template.DeliveryWay = templatedata.DeliveryWay
- template.ExecutionFrequency = templatedata.ExecutionFrequency
-
- template.FrequencyType = templatedata.FrequencyType
- template.DayCount = templatedata.DayCount
- template.WeekDays = templatedata.WeekDays
- template.DrugId = template.DrugId
- template.Way = template.Way
-
- err = service.UpdateAdviceTemplate(template)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "template": template,
- })
- return
- }
-
- func (c *DataApiController) DeleteAdviceTemplate() {
- adminUserInfo := c.GetAdminUserInfo()
- parent_id, _ := c.GetInt64("parent_id", 0)
- id, _ := c.GetInt64("id", 0)
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- template, _ := service.FindAdviceTemplate(adminUserInfo.CurrentOrgId, id)
- if template == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
- return
- }
-
- //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
- //if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- timeNow := time.Now().Unix()
- template.ID = id
- template.UpdatedTime = timeNow
- template.ParentId = parent_id
- template.Status = 2
-
- if parent_id > 0 { //删除子医嘱
- err := service.UpdateAdviceTemplate(template)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
- return
- }
- } else { //删除该医嘱下的所有子医嘱
- err := service.UpdateAdviceAndSubAdviceTemplate(template)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
- return
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- func (c *DataApiController) CreateSingleAdviceTemplate() {
- drug_spec := c.GetString("drug_spec")
- drug_spec_unit := c.GetString("drug_spec_unit")
- advice_name := c.GetString("advice_name")
- advice_desc := c.GetString("advice_desc")
- single_dose, _ := c.GetFloat("single_dose", 0)
- single_dose_unit := c.GetString("single_dose_unit")
- prescribing_number, _ := c.GetFloat("prescribing_number", 0)
- prescribing_number_unit := c.GetString("prescribing_number_unit")
- delivery_way := c.GetString("delivery_way")
- execution_frequency := c.GetString("execution_frequency")
- template_id, _ := c.GetInt64("template_id", -1)
-
- advice_type, _ := c.GetInt64("advice_type", -1)
- frequency_type, _ := c.GetInt64("frequency_type", -1)
- week_days := c.GetString("week_days")
- day_count, _ := c.GetInt64("day_count", -1)
- drug_id, _ := c.GetInt64("drug_id")
- way, _ := c.GetInt64("way")
- adminUserInfo := c.GetAdminUserInfo()
-
- template := models.DoctorAdviceTemplate{
- OrgId: adminUserInfo.CurrentOrgId,
- AdviceDoctor: adminUserInfo.AdminUser.Id,
- AdviceType: advice_type,
- FrequencyType: frequency_type,
- WeekDays: week_days,
- DayCount: day_count,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- DrugSpec: drug_spec,
- DrugSpecUnit: drug_spec_unit,
- AdviceName: advice_name,
- AdviceDesc: advice_desc,
- SingleDose: single_dose,
- SingleDoseUnit: service.TypeConversion02(single_dose_unit),
- PrescribingNumber: prescribing_number,
- PrescribingNumberUnit: prescribing_number_unit,
- DeliveryWay: delivery_way,
- ExecutionFrequency: execution_frequency,
- TemplateId: template_id,
- Way: way,
- DrugId: drug_id,
- }
-
- if template.AdviceName == "" {
- utils.ErrorLog("医嘱名字不能为空")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
- return
- }
-
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
- if appRole.UserType == 3 {
- headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- if getPermissionErr != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if headNursePermission == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
- return
- }
- }
-
- err := service.CreateAdviceTemplate(&template)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "template": template,
- })
- return
-
- }
-
- func (c *DataApiController) DeleteParentAdviceTemplate() {
- template_id, _ := c.GetInt64("template_id", 0)
- adminUserInfo := c.GetAdminUserInfo()
-
- _, err := service.FindParentTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- err1 := service.DeleteParentDoctorAdviceByTemplateId(template_id, adminUserInfo.CurrentOrgId)
- if err1 != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
-
- }
-
- func (c *DataApiController) CreateSubAdviceTemplate() {
- drug_spec := c.GetString("drug_spec")
- drug_spec_unit := c.GetString("drug_spec_unit")
- advice_name := c.GetString("advice_name")
- advice_desc := c.GetString("advice_desc")
- single_dose, _ := c.GetFloat("single_dose", 0)
- single_dose_unit := c.GetString("single_dose_unit")
- prescribing_number, _ := c.GetFloat("prescribing_number", 0)
- prescribing_number_unit := c.GetString("prescribing_number_unit")
- delivery_way := c.GetString("delivery_way")
- execution_frequency := c.GetString("execution_frequency")
- template_id, _ := c.GetInt64("template_id", 0)
- parent_id, _ := c.GetInt64("parent_id", 0)
- drug_id, _ := c.GetInt64("drug_id")
- way, _ := c.GetInt64("way")
- adminUserInfo := c.GetAdminUserInfo()
-
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
- if appRole.UserType == 3 {
- headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- if getPermissionErr != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if headNursePermission == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
- return
- }
- }
-
- template := models.DoctorAdviceTemplate{
- OrgId: adminUserInfo.CurrentOrgId,
- AdviceDoctor: adminUserInfo.AdminUser.Id,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- DrugSpec: drug_spec,
- DrugSpecUnit: drug_spec_unit,
- AdviceName: advice_name,
- AdviceDesc: advice_desc,
- SingleDose: single_dose,
- SingleDoseUnit: single_dose_unit,
- PrescribingNumber: prescribing_number,
- PrescribingNumberUnit: prescribing_number_unit,
- DeliveryWay: delivery_way,
- ExecutionFrequency: execution_frequency,
- TemplateId: template_id,
- ParentId: parent_id,
- DrugId: drug_id,
- Way: way,
- }
-
- if template.AdviceName == "" {
- utils.ErrorLog("医嘱名字不能为空")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
- return
- }
- err := service.CreateAdviceTemplate(&template)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "template": template,
- })
- return
-
- }
-
- func (this *DataApiController) ModifyTemplateName() {
- template_name := this.GetString("template_name")
- template_id, _ := this.GetInt64("template_id", 0)
- sort, _ := this.GetInt64("sort")
- if len(template_name) <= 0 {
- utils.ErrorLog("模版名字不能为空")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
- return
- }
-
- if template_id == 0 {
- utils.ErrorLog("模版不存在")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamTemplateNOEXISTWrong)
- return
- }
-
- adminUserInfo := this.GetAdminUserInfo()
-
- template, _ := service.FindParentTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
- var err error
- if template.Name == template_name {
- err = service.ModifyTemplateNameOne(template_id, template_name, sort)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- return
- }
- } else {
- //total := service.FindTemplateRecordByName(adminUserInfo.CurrentOrgId, template_name);
- //if total > 0 {
- // utils.ErrorLog("模版名称已经存在")
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNameWrong)
- // return
- //}
- err = service.ModifyTemplateNameOne(template_id, template_name, sort)
-
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- return
- }
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "template_name": template_name,
- "template_id": template_id,
- })
-
- }
-
- func (this *DataApiController) ModifyFiledIsShow() {
- id, _ := this.GetInt64("id", 0)
- is_show, _ := this.GetInt("is_show", 0)
- adminUserInfo := this.GetAdminUserInfo()
- err := service.ShowFiledConfig(adminUserInfo.CurrentOrgId, is_show, id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- return
- } else {
-
- this.ServeSuccessJSON(map[string]interface{}{
- "id": id,
- "is_show": is_show,
- })
- }
- }
-
- func (c *DataApiController) GetAllAdviceConfigs() {
-
- adminUserInfo := c.GetAdminUserInfo()
- var drugs []models.DrugDic
- drugways, _, _ := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
- efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
- adviceTemplates, _ := service.FindOtherAllAdviceTemplate(adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "drugs": drugs,
- "drugways": drugways,
- "efs": efs,
- "advice_templates": adviceTemplates,
- })
- }
-
- func (c *DataApiController) GetHandleData() {
- id, _ := c.GetInt64("id")
- config, err := service.GetHandleData(id)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "config": config,
- })
- }
-
- func (c *DataApiController) UpdateDataTwo() {
- id, _ := c.GetInt64("id")
- //fmt.Print("id",id)
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- //fmt.Print("err",err)
- //fmt.Print("id",id)
- name := dataBody["name"].(string)
- // fmt.Print("name",name)
- order := int64(dataBody["order"].(float64))
- // fmt.Print("order",order)
- remake := dataBody["remark"].(string)
- // fmt.Print("remake",remake)
- configModel := models.ConfigViewModel{
- Name: name,
- Order: order,
- Remark: remake,
- }
- err = service.UpdateDataTwo(id, configModel)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "configModel": configModel,
- })
- }
-
- func (c *DataApiController) CreateHisAdviceTemplate() {
- templateName := c.GetString("template_name")
- advice_type, _ := c.GetInt64("advice_type")
-
- if templateName == "" {
- utils.ErrorLog("模版名称不能为空")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
- return
- }
- if advice_type < 0 {
- utils.ErrorLog("医嘱模版类型不能为空")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceTypeWrong)
- return
- }
- adminUserInfo := c.GetAdminUserInfo()
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
- if appRole.UserType == 3 {
- headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- if getPermissionErr != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if headNursePermission == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
- return
- }
- }
- template := &models.HisDoctorAdviceParentTemplate{
- Name: templateName,
- OrgId: adminUserInfo.CurrentOrgId,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- AdviceType: advice_type,
- }
- createErr := service.CreateHisDoctorAdviceTemplate(template)
- if createErr != nil {
- utils.ErrorLog("%v", createErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- var subTemplate []*models.HisDoctorAdviceTemplate
- if dataBody["data"] != nil && reflect.TypeOf(dataBody["data"]).String() == "[]interface {}" {
- subTemp, _ := dataBody["data"].([]interface{})
- if len(subTemp) > 0 {
- for _, item := range subTemp {
- items := item.(map[string]interface{})
- if items["advice_name"] == nil || reflect.TypeOf(items["advice_name"]).String() != "string" {
- utils.ErrorLog("advice_name")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advice_name, _ := items["advice_name"].(string)
- advice_desc, _ := items["advice_desc"].(string)
- single_dose_unit, _ := items["single_dose_unit"].(string)
- prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
- delivery_way, _ := items["delivery_way"].(string)
- execution_frequency, _ := items["execution_frequency"].(string)
- drug_spec, _ := items["drug_spec"].(string)
- drug_spec_unit, _ := items["drug_spec_unit"].(string)
- single_dose := items["single_dose"].(float64)
- prescribing_number := items["prescribing_number"].(float64)
- drug_id := int64(items["drug_id"].(float64))
-
- subTemps := &models.HisDoctorAdviceTemplate{
- AdviceName: advice_name,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- OrgId: adminUserInfo.CurrentOrgId,
- AdviceDesc: advice_desc,
- AdviceType: advice_type,
- SingleDoseUnit: single_dose_unit,
- PrescribingNumber: prescribing_number,
- PrescribingNumberUnit: prescribing_number_unit,
- DeliveryWay: delivery_way,
- ExecutionFrequency: execution_frequency,
- TemplateId: template.ID,
- DrugSpec: drug_spec,
- DrugSpecUnit: drug_spec_unit,
- SingleDose: single_dose,
- AdviceDoctor: adminUserInfo.AdminUser.Id,
- DrugId: drug_id,
- }
- subTemplate = append(subTemplate, subTemps)
-
- }
- }
- }
- //errs := service.CreateBatchRecord(subTemplate)
- errs := service.CreateHisSubDoctorAdviceTemplate(subTemplate)
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
- return
- }
- templates, _ := service.FindHisDoctorAdviceTemplateById(template.ID, adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "template": templates,
- })
- return
- }
- func (c *DataApiController) UpdateHisAdviceTemplate() {
-
- adminUserInfo := c.GetAdminUserInfo()
- id, _ := c.GetInt64("id", 0)
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- template, _ := service.FindHisAdviceTemplate(adminUserInfo.CurrentOrgId, id)
- if template == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
- return
- }
-
- var templatedata models.HisDoctorAdviceTemplate
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &templatedata)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if templatedata.AdviceName == "" {
- utils.ErrorLog("不能为空")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeNow := time.Now().Unix()
- template.UpdatedTime = timeNow
- template.AdviceName = templatedata.AdviceName
- template.AdviceDesc = templatedata.AdviceDesc
- template.SingleDose = templatedata.SingleDose
- template.SingleDoseUnit = templatedata.SingleDoseUnit
- template.PrescribingNumber = templatedata.PrescribingNumber
- template.PrescribingNumberUnit = templatedata.PrescribingNumberUnit
- template.DrugSpec = templatedata.DrugSpec
- template.DrugSpecUnit = templatedata.DrugSpecUnit
- template.DeliveryWay = templatedata.DeliveryWay
- template.ExecutionFrequency = templatedata.ExecutionFrequency
- template.DrugId = template.DrugId
-
- err = service.UpdateHisAdviceTemplate(template)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "template": template,
- })
- return
-
- }
- func (c *DataApiController) DeleteHisAdviceTemplate() {
- adminUserInfo := c.GetAdminUserInfo()
- parent_id, _ := c.GetInt64("parent_id", 0)
- id, _ := c.GetInt64("id", 0)
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- template, _ := service.FindHisAdviceTemplate(adminUserInfo.CurrentOrgId, id)
- if template == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
- return
- }
-
- //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
- //if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- timeNow := time.Now().Unix()
- template.ID = id
- template.UpdatedTime = timeNow
- template.ParentId = parent_id
- template.Status = 2
-
- if parent_id > 0 { //删除子医嘱
- err := service.UpdateHisAdviceTemplate(template)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
- return
- }
- } else { //删除该医嘱下的所有子医嘱
- err := service.UpdateHisAdviceAndSubAdviceTemplate(template)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
- return
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
- func (c *DataApiController) CreateSingleHisAdviceTemplate() {
- drug_spec := c.GetString("drug_spec")
- drug_spec_unit := c.GetString("drug_spec_unit")
- advice_name := c.GetString("advice_name")
- advice_desc := c.GetString("advice_desc")
- single_dose, _ := c.GetFloat("single_dose", 0)
- single_dose_unit := c.GetString("single_dose_unit")
- prescribing_number, _ := c.GetFloat("prescribing_number", 0)
- prescribing_number_unit := c.GetString("prescribing_number_unit")
- delivery_way := c.GetString("delivery_way")
- execution_frequency := c.GetString("execution_frequency")
- template_id, _ := c.GetInt64("template_id", -1)
- drug_id, _ := c.GetInt64("drug_id")
- adminUserInfo := c.GetAdminUserInfo()
-
- template := models.HisDoctorAdviceTemplate{
- OrgId: adminUserInfo.CurrentOrgId,
- AdviceDoctor: adminUserInfo.AdminUser.Id,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- DrugSpec: drug_spec,
- DrugSpecUnit: drug_spec_unit,
- AdviceName: advice_name,
- AdviceDesc: advice_desc,
- SingleDose: single_dose,
- SingleDoseUnit: single_dose_unit,
- PrescribingNumber: prescribing_number,
- PrescribingNumberUnit: prescribing_number_unit,
- DeliveryWay: delivery_way,
- ExecutionFrequency: execution_frequency,
- TemplateId: template_id,
- DrugId: drug_id,
- }
-
- if template.AdviceName == "" {
- utils.ErrorLog("医嘱名字不能为空")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
- return
- }
-
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
- if appRole.UserType == 3 {
- headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- if getPermissionErr != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if headNursePermission == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
- return
- }
- }
- err := service.CreateHisAdviceTemplate(&template)
- if err != nil {
- utils.ErrorLog("%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "template": template,
- })
- return
- }
- func (c *DataApiController) DeleteHisParentAdviceTemplate() {
- template_id, _ := c.GetInt64("template_id", 0)
- adminUserInfo := c.GetAdminUserInfo()
- _, err := service.FindParentHisTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- err1 := service.DeleteHisParentDoctorAdviceByTemplateId(template_id, adminUserInfo.CurrentOrgId)
- if err1 != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "删除成功",
- })
- }
- func (this *DataApiController) ModifyHisTemplateName() {
- template_name := this.GetString("template_name")
- template_id, _ := this.GetInt64("template_id", 0)
-
- if len(template_name) <= 0 {
- utils.ErrorLog("模版名字不能为空")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
- return
- }
-
- if template_id == 0 {
- utils.ErrorLog("模版不存在")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamTemplateNOEXISTWrong)
- return
- }
- adminUserInfo := this.GetAdminUserInfo()
- template, _ := service.FindParentHisTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
- var err error
- if template.Name == template_name {
- err = service.ModifyTemplateName(template_id, template_name)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- return
- }
- } else {
- err = service.ModifyHisTemplateName(template_id, template_name)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- return
- }
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "template_name": template_name,
- "template_id": template_id,
- })
-
- }
- func (this *DataApiController) GetAllHisAdviceTemplate() {
- adminUserInfo := this.GetAdminUserInfo()
- drugs, _ := service.GetAllDrugLibs(adminUserInfo.CurrentOrgId)
- drugways, _, _ := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
- efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
- adviceTemplates, _ := service.FindHisAllAdviceTemplate(adminUserInfo.CurrentOrgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "drugways": drugways,
- "efs": efs,
- "advice_templates": adviceTemplates,
- "drugs": drugs,
- })
-
- }
|