1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171 |
- package new_mobile_api_controllers
-
- import (
- "XT_New/controllers/mobile_api_controllers"
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "bytes"
- "encoding/json"
- "fmt"
- "github.com/astaxie/beego"
- "io/ioutil"
- "log"
- "net/http"
- "net/url"
- "os"
- "path"
- "regexp"
- "runtime"
- "strconv"
- "time"
- )
-
- type MobileRegistController struct {
- mobile_api_controllers.MobileBaseAPIController
- }
-
- // /mobile/regist [get]
-
- // /mobile/regist/submit [post]
- // @param mobile:string
- // @param password:string
- // @param code:string
- func (this *MobileRegistController) RegistSubmit() {
- mobile := this.GetString("mobile")
- pwd := this.GetString("password")
- code := this.GetString("code")
-
- // 判断手机号是否存在
- if utils.CellPhoneRegexp().MatchString(mobile) == false {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMobileFormat)
- return
- }
- if len(pwd) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePasswordEmpty)
- return
-
- }
- if len(code) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeVerificationCodeWrong)
- return
- }
- if service.IsMobileRegister(mobile) == true {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMobileRegistered)
- return
- }
-
- if code == "13535547901" {
- admin, err := service.RegisterSuperAdmin(mobile, pwd)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(err.Code)
- return
- } else {
- this.Ctx.SetCookie("mobile", mobile)
- this.SetSession("mobile_admin_user", admin)
- this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
- "result": true,
- "id": admin.Id,
- })
- this.ServeJSON()
- }
- } else {
-
- redisClient := service.RedisClient()
- defer redisClient.Close()
- cache_code, _ := redisClient.Get("code_msg_" + mobile).Result()
- if cache_code != code {
- //this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeVerificationCodeWrong)
- //this.ServeJSON()
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeVerificationCodeWrong)
-
- return
- }
- admin, err := service.RegisterSuperAdmin(mobile, pwd)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(err.Code)
- return
- } else {
- this.Ctx.SetCookie("mobile", mobile)
- this.SetSession("mobile_admin_user", admin)
- // 注册成功后验证码就要使其失效
- redisClient.Del("code_msg_" + mobile)
-
- this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
- "result": true,
- "id": admin.Id,
- })
- this.ServeJSON()
- }
-
- }
-
- }
-
- // /mobile/org/create/submit [post]
- // @param name:string
- // @param province:string 省名
- // @param city:string 市名
- // @param district:string 区县
- // @param address:string
- // @param category:int
- // @param contact_name:string
- // @param org_phone?:string
- // @param open_xt?:bool 是否开启血透系统
- // @param open_cdm?:bool 是否开启慢病系统
- // @param open_scrm?:bool 是否开启SCRM
- // @param open_mall?:bool 是否开启Mall
- func (this *MobileRegistController) CreateOrg() {
- adminUserObj := this.GetSession("mobile_admin_user")
- if adminUserObj == nil {
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeLoginTimeout)
- this.ServeJSON()
- return
- }
- adminUser := adminUserObj.(*models.AdminUser)
-
- //if didCreateOrg, checkCreateOrgErr := service.DidAdminUserCreateOrg(adminUser.Id); checkCreateOrgErr != nil {
- // this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // this.ServeJSON()
- // return
- //} else if didCreateOrg {
- // this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeRepeatCreateOrg)
- // this.ServeJSON()
- // return
- //}
-
- name := this.GetString("org_name")
- shortName := name
- provinceName := this.GetString("provinces_name")
- cityName := this.GetString("city_name")
- districtName := this.GetString("district_name")
- address := this.GetString("address")
- org_type := this.GetString("org_type")
- contactName := this.GetString("contact_name")
-
- //openXT, _ := this.GetBool("open_xt")
- //openCDM, _ := this.GetBool("open_cdm")
- //openSCRM, _ := this.GetBool("open_scrm")
- //openMall, _ := this.GetBool("open_mall")
-
- openXT := true
- openCDM := false
- openSCRM := false
- openMall := false
-
- if len(name) == 0 || len(shortName) == 0 || len(contactName) == 0 || len(address) == 0 || len(provinceName) <= 0 || len(cityName) <= 0 || len(districtName) <= 0 || len(org_type) <= 0 {
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- this.ServeJSON()
- return
- }
- orgPhone := this.GetString("telephone")
-
- if len(orgPhone) > 0 {
- if utils.PhoneRegexp().MatchString(orgPhone) == false {
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- this.ServeJSON()
- return
- }
- }
-
- provinceID := 0
- cityID := 0
- districtID := 0
-
- province, getProvinceErr := service.GetProvinceWithName(provinceName)
- if getProvinceErr != nil {
- utils.ErrorLog("查询省名失败:%v", getProvinceErr)
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- this.ServeJSON()
- return
- } else if province != nil {
- provinceID = int(province.ID)
- city, getCityErr := service.GetCityWithName(province.ID, cityName)
- if getCityErr != nil {
- utils.ErrorLog("查询城市名失败:%v", getCityErr)
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- this.ServeJSON()
- return
- } else if city != nil {
- cityID = int(city.ID)
- district, getDistrictErr := service.GetDistrictWithName(city.ID, districtName)
- if getDistrictErr != nil {
- utils.ErrorLog("查询区县名失败:%v", getDistrictErr)
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- this.ServeJSON()
- return
- } else if district != nil {
- districtID = int(district.ID)
- }
- }
- }
-
- orgType := service.GetOrgTypeByName(org_type)
-
- org := &models.Org{
- Creator: adminUser.Id,
- OrgName: name,
- OrgShortName: shortName,
- Province: int64(provinceID),
- City: int64(cityID),
- District: int64(districtID),
- Address: address,
- OrgType: orgType.ID,
- Telephone: orgPhone,
- ContactName: contactName,
- Claim: 1,
- Evaluate: 5,
- Status: 1,
- CreateTime: time.Now().Unix(),
- ModifyTime: time.Now().Unix(),
- }
-
- createErr := service.CreateOrg(org, adminUser.Mobile, openXT, openCDM, openSCRM, openMall) // 创建机构以及所有类型的 app,如果有新类型的平台,则需要在这个方法里面把创建这一新类型的 app 的代码加上
-
- if createErr != nil {
- utils.ErrorLog("mobile=%v的超级管理员创建机构失败:%v", adminUser.Mobile, createErr)
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
- this.ServeJSON()
- } else {
-
- //初始化病人和排班相关数据
- InitPatientAndSchedule(org)
- //初始化透析方案
- InitSystemPrescrption(org)
- //初始化医嘱模版
- //InitAdviceTemplate(org)
- //初始化角色和权限
- InitRoleAndPurviews(org)
- //初始化设备管理org
- InitEquitMentInformation(org)
- //初始化显示配置
-
- //创建完机构后进行登录验证操作
- ip := utils.GetIP(this.Ctx.Request)
- ssoDomain := beego.AppConfig.String("sso_domain")
- api := ssoDomain + "/m/login/pwd"
- values := make(url.Values)
- values.Set("mobile", adminUser.Mobile)
- values.Set("password", adminUser.Password)
- values.Set("app_type", "3")
- values.Set("ip", ip)
- resp, requestErr := http.PostForm(api, values)
-
- if requestErr != nil {
- utils.ErrorLog("请求SSO登录接口失败: %v", requestErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- defer resp.Body.Close()
- body, ioErr := ioutil.ReadAll(resp.Body)
- if ioErr != nil {
- utils.ErrorLog("SSO登录接口返回数据读取失败: %v", ioErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- var respJSON map[string]interface{}
- utils.InfoLog(string(body))
- if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
- utils.ErrorLog("SSO登录接口返回数据解析JSON失败: %v", err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- if respJSON["state"].(float64) != 1 {
- msg := respJSON["msg"].(string)
- utils.ErrorLog("SSO登录接口请求失败: %v", msg)
- if int(respJSON["code"].(float64)) == 609 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrPasswordWrong)
- return
- }
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else {
- utils.SuccessLog("SSO登录成功")
- // 下面这几段 Map=>JSON=>Struct 的流程可能会造成速度很慢
- userJSON := respJSON["data"].(map[string]interface{})["admin"].(map[string]interface{})
- userJSONBytes, _ := json.Marshal(userJSON)
- var adminUser models.AdminUser
- if err := json.Unmarshal(userJSONBytes, &adminUser); err != nil {
- utils.ErrorLog("解析管理员失败:%v", err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- var org models.Org
- if respJSON["data"].(map[string]interface{})["org"] != nil {
- orgJSON := respJSON["data"].(map[string]interface{})["org"].(map[string]interface{})
- orgJSONBytes, _ := json.Marshal(orgJSON)
- if err := json.Unmarshal(orgJSONBytes, &org); err != nil {
- utils.ErrorLog("解析机构失败:%v", err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- var app models.OrgApp
-
- if respJSON["data"].(map[string]interface{})["app"] != nil {
- appJSON := respJSON["data"].(map[string]interface{})["app"].(map[string]interface{})
- appJSONBytes, _ := json.Marshal(appJSON)
- if err := json.Unmarshal(appJSONBytes, &app); err != nil {
- utils.ErrorLog("解析应用失败:%v", err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- var appRole models.App_Role
-
- if respJSON["data"].(map[string]interface{})["app_role"] != nil {
- appRoleJSON := respJSON["data"].(map[string]interface{})["app_role"].(map[string]interface{})
- appRoleJSONBytes, _ := json.Marshal(appRoleJSON)
- if err := json.Unmarshal(appRoleJSONBytes, &appRole); err != nil {
- utils.ErrorLog("解析AppRole失败:%v", err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- var subscibe models.ServeSubscibe
- if respJSON["data"].(map[string]interface{})["subscibe"] != nil {
- subscibeJSON := respJSON["data"].(map[string]interface{})["subscibe"].(map[string]interface{})
- subscibeJSONBytes, _ := json.Marshal(subscibeJSON)
- if err := json.Unmarshal(subscibeJSONBytes, &subscibe); err != nil {
- utils.ErrorLog("解析Subscibe失败:%v", err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- }
-
- //service.GetOrgSubscibeState(&subscibe)
- templateInfo, _ := service.GetOrgInfoTemplate(org.Id)
-
- mobileAdminUserInfo := &mobile_api_controllers.MobileAdminUserInfo{
- AdminUser: &adminUser,
- Org: &org,
- App: &app,
- AppRole: &appRole,
- Subscibe: &subscibe,
- TemplateInfo: &templateInfo,
- }
- //设置seesion
- this.SetSession("mobile_admin_user_info", mobileAdminUserInfo)
-
- //设置cookie
- mobile := adminUser.Mobile + "-" + strconv.FormatInt(org.Id, 10) + "-" + strconv.FormatInt(appRole.Id, 10)
- token := utils.GenerateLoginToken(mobile)
- expiration, _ := beego.AppConfig.Int64("mobile_token_expiration_second")
- this.Ctx.SetCookie("token_cookie", token, expiration, "/")
-
- var configList interface{}
- var FiledList []*models.FiledConfig
-
- if org.Id > 0 {
- configList, _ = service.GetConfigList(org.Id)
- FiledList, _ = service.FindFiledByOrgId(org.Id)
- }
- if len(FiledList) == 0 {
- var err error
- if org.Id > 0 {
- err = service.BatchInsertFiledConfig(org.Id)
- if err == nil {
- FiledList, _ = service.FindFiledByOrgId(org.Id)
- } else {
- utils.ErrorLog("字段批量插入失败:%v", err)
- }
- } else {
- FiledList = make([]*models.FiledConfig, 0)
- }
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "admin": adminUser,
- "user": appRole,
- "org": org,
- "template_info": map[string]interface{}{
- "id": templateInfo.ID,
- "org_id": templateInfo.OrgId,
- "template_id": templateInfo.TemplateId,
- },
- "config_list": configList,
- "filed_list": FiledList,
- })
- }
-
- }
-
- }
-
- func InitAdviceTemplate(org *models.Org) {
-
- //初始化医嘱模版
- adviceInit := &models.AdviceInit{
- UserOrgId: org.Id,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- Status: 1,
- IsInit: 1,
- }
-
- adviceParentTemplate := LoadConfig("./advice_template.json").Parent_template
- for _, item := range adviceParentTemplate {
- parentTemplate := &models.DoctorAdviceParentTemplate{
- OrgId: org.Id,
- Name: item.Name,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- AdviceType: item.AdviceType,
- }
-
- createErr := service.CreateDoctorParentTemplate(parentTemplate)
- fmt.Println(parentTemplate.ID)
- if createErr == nil {
- for _, adviceTemplateItem := range item.DoctorAdviceTemplate {
- adviceTeplate := &models.DoctorAdviceTemplate{
- OrgId: org.Id,
- AdviceName: adviceTemplateItem.AdviceName,
- AdviceDesc: adviceTemplateItem.AdviceDesc,
- SingleDose: adviceTemplateItem.SingleDose,
- SingleDoseUnit: adviceTemplateItem.SingleDoseUnit,
- PrescribingNumber: adviceTemplateItem.PrescribingNumber,
- PrescribingNumberUnit: adviceTemplateItem.PrescribingNumberUnit,
- DeliveryWay: adviceTemplateItem.DeliveryWay,
- ExecutionFrequency: adviceTemplateItem.ExecutionFrequency,
- AdviceDoctor: adviceTemplateItem.AdviceDoctor,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- TemplateId: parentTemplate.ID,
- DrugSpec: adviceTemplateItem.DrugSpec,
- DrugSpecUnit: adviceTemplateItem.DrugSpecUnit,
- ParentId: adviceTemplateItem.ParentId,
- AdviceType: adviceTemplateItem.AdviceType,
- DayCount: adviceTemplateItem.DayCount,
- WeekDays: adviceTemplateItem.WeekDays,
- FrequencyType: adviceTemplateItem.FrequencyType,
- }
- createErr := service.CreateDoctorTemplate(adviceTeplate)
-
- if createErr == nil {
- for _, childItem := range adviceTemplateItem.SubDoctorAdviceTemplate {
- adviceTeplate := &models.DoctorAdviceTemplate{
- OrgId: org.Id,
- AdviceName: childItem.AdviceName,
- AdviceDesc: childItem.AdviceDesc,
- SingleDose: childItem.SingleDose,
- SingleDoseUnit: childItem.SingleDoseUnit,
- PrescribingNumber: childItem.PrescribingNumber,
- PrescribingNumberUnit: childItem.PrescribingNumberUnit,
- DeliveryWay: childItem.DeliveryWay,
- ExecutionFrequency: childItem.ExecutionFrequency,
- AdviceDoctor: childItem.AdviceDoctor,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- TemplateId: parentTemplate.ID,
- DrugSpec: childItem.DrugSpec,
- DrugSpecUnit: childItem.DrugSpecUnit,
- ParentId: adviceTeplate.ID,
- AdviceType: childItem.AdviceType,
- DayCount: childItem.DayCount,
- WeekDays: childItem.WeekDays,
- FrequencyType: childItem.FrequencyType,
- }
- service.CreateDoctorTemplate(adviceTeplate)
- }
- }
- }
- }
- }
- service.CreateAdviceInitConfig(adviceInit)
-
- }
-
- func InitSystemPrescrption(org *models.Org) {
- //初始化透析方案
- prescriptions := LoadPrescriptionConfig("./system_dialysis_prescription.json").Prescription
- for _, item := range prescriptions {
- item.UserOrgId = org.Id
- item.CreatedTime = time.Now().Unix()
- item.UpdatedTime = time.Now().Unix()
- service.CreateVMPrescription(item)
- }
-
- }
-
- func InitPatientAndSchedule(org *models.Org) {
- var ids []int64
- //数据初始化
-
- //创建两个虚拟病人
- patients := LoadPatientConfig("./patient.json").Patients
- for _, item := range patients {
- item.UserOrgId = org.Id
- item.CreatedTime = time.Now().Unix()
- item.UpdatedTime = time.Now().Unix()
- item.Status = 1
-
- service.CreateVMOrgPatient(item)
- ids = append(ids, item.ID)
- }
-
- //创建两个血透的虚拟病人到新表
- fmt.Print("patients", patients)
- for _, it := range patients {
- patientsNew := models.XtPatientsNew{
- UserOrgId: org.Id,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- Status: 1,
- BloodId: it.ID,
- BloodPatients: 1,
- Name: it.Name,
- Avatar: it.Avatar,
- PatientType: it.PatientType,
- Source: it.Source,
- Lapseto: it.Lapseto,
- Gender: it.Gender,
- Nation: it.Nation,
- NativePlace: it.NativePlace,
- MaritalStatus: it.MaritalStatus,
- IdCardNo: it.IdCardNo,
- Birthday: it.Birthday,
- ReimbursementWayId: it.ReimbursementWayId,
- HealthCareNo: it.HealthCareNo,
- Phone: it.Phone,
- HomeAddress: it.HomeAddress,
- WorkUnit: it.WorkUnit,
- UnitAddress: it.UnitAddress,
- Children: it.Children,
- IsHospitalFirstDialysis: it.IsHospitalFirstDialysis,
- FirstDialysisDate: it.FirstDialysisDate,
- BindingState: it.BindingState,
- PatientComplains: it.PatientComplains,
- PresentHistory: it.PresentHistory,
- PastHistory: it.PastHistory,
- Temperature: it.Temperature,
- Pulse: it.Pulse,
- Respiratory: it.Respiratory,
- Age: it.Age,
- IsOpenRemind: it.IsOpenRemind,
- TellPhone: it.TellPhone,
- FirstTreatmentDate: it.FirstTreatmentDate,
- ContactName: it.ContactName,
- }
- service.CreateVMOrgNewPatient(&patientsNew)
- }
- //创建1个分组
- vmGroup := &models.VMDeviceGroup{
- OrgId: org.Id,
- Name: "护理一组",
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- service.CreateVMGroup(vmGroup)
-
- //创建两个虚拟分区
- vmZone1 := &models.VMDeviceZone{
- OrgId: org.Id,
- Name: "A区",
- Type: 1,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
- service.CreateVMZone(vmZone1)
-
- vmZone2 := &models.VMDeviceZone{
- OrgId: org.Id,
- Name: "B区",
- Type: 2,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
- service.CreateVMZone(vmZone2)
-
- //创建2个虚拟床位
- vmDeviceNumber1 := &models.VMDeviceNumber{
- OrgId: org.Id,
- Number: "1号床",
- GroupId: vmGroup.ID,
- ZoneId: vmZone1.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
- service.CreateVMDeviceNumber(vmDeviceNumber1)
-
- vmDeviceNumber2 := &models.VMDeviceNumber{
- OrgId: org.Id,
- Number: "2号床",
- GroupId: vmGroup.ID,
- ZoneId: vmZone2.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
- service.CreateVMDeviceNumber(vmDeviceNumber2)
-
- var dates []int64
-
- mondayDate := GetDateOfWeek(1)
- tuesdayDate := GetDateOfWeek(2)
- wednesdayDate := GetDateOfWeek(3)
- thursdayDate := GetDateOfWeek(4)
- fridayDate := GetDateOfWeek(5)
- saturdayDate := GetDateOfWeek(6)
- sundayDate := GetDateOfWeek(7)
-
- dates = append(dates, mondayDate)
- dates = append(dates, tuesdayDate)
- dates = append(dates, wednesdayDate)
- dates = append(dates, thursdayDate)
- dates = append(dates, fridayDate)
- dates = append(dates, saturdayDate)
- dates = append(dates, sundayDate)
-
- //创建两个虚拟病人本周的排班
- //stime, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
- for week_type, date := range dates {
- for index, id := range ids {
- if index == 0 {
- sch := &models.VMSchedule{
- UserOrgId: org.Id,
- PartitionId: vmZone1.ID,
- BedId: vmDeviceNumber1.ID,
- PatientId: id,
- ScheduleDate: date,
- ScheduleType: 1,
- ScheduleWeek: int64(week_type + 1),
- ModeId: 1,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- }
- service.CreateVMSch(sch)
- }
-
- if index == 1 {
-
- sch := &models.VMSchedule{
- UserOrgId: org.Id,
- PartitionId: vmZone2.ID,
- BedId: vmDeviceNumber2.ID,
- PatientId: id,
- ScheduleDate: date,
- ScheduleType: 2,
- ScheduleWeek: int64(week_type + 1),
- ModeId: 1,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- }
- service.CreateVMSch(sch)
- }
- }
-
- }
-
- //创建单周模版
- //1.创建模版模式
- mode := &models.VMPatientScheduleTemplateMode{
- OrgId: org.Id,
- Mode: 1,
- ExecuteTimes: 0,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
- service.CreateVMSchMode(mode)
- //2.创建模版id
- templaeIdOne := &models.VMPatientScheduleTemplateId{
- OrgId: org.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
- service.CreateVMSchTemplateId(templaeIdOne)
- templaeIdTwo := &models.VMPatientScheduleTemplateId{
- OrgId: org.Id,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
- service.CreateVMSchTemplateId(templaeIdTwo)
- //3.创建单周排班模版
- items := LoadSchTemplateConfig("./schedule_template.json").Item
- for _, item := range items {
- if item.TimeType == 1 {
- item.OrgId = org.Id
- item.TemplateId = templaeIdOne.ID
- item.DeviceNumberId = vmDeviceNumber1.ID
- item.PatientId = ids[0]
- item.Status = 1
- item.Ctime = time.Now().Unix()
- item.Mtime = time.Now().Unix()
-
- } else if item.TimeType == 2 {
- item.OrgId = org.Id
- item.TemplateId = templaeIdOne.ID
- item.DeviceNumberId = vmDeviceNumber2.ID
- item.PatientId = ids[1]
- item.Status = 1
- item.Ctime = time.Now().Unix()
- item.Mtime = time.Now().Unix()
-
- }
-
- service.CreateVMSchTemplate(item)
- }
-
- }
-
- func InitRoleAndPurviews(org *models.Org) {
- roles := LoadRoleConfig("./role.json").Roles
- app, _ := service.GetOrgApp(org.Id, 3)
- for _, item := range roles {
- role := &models.Role{
- RoleName: item.RoleName,
- RoleIntro: item.RoleIntroduction,
- Creator: 0,
- OrgId: org.Id,
- AppId: app.Id,
- IsSuperAdmin: false,
- Status: 1,
- CreateTime: time.Now().Unix(),
- ModifyTime: time.Now().Unix(),
- Number: item.Number,
- IsSystem: item.IsSystem,
- }
- err := service.CreateOrgRole(role)
- if err == nil {
- purview := &models.RolePurview{
- RoleId: role.Id,
- OrgId: org.Id,
- AppId: role.AppId,
- PurviewIds: item.PurviewIds,
- Status: 1,
- CreateTime: time.Now().Unix(),
- ModifyTime: time.Now().Unix(),
- }
- func_purview := &models.SgjUserRoleFuncPurview{
- RoleId: role.Id,
- OrgId: org.Id,
- AppId: role.AppId,
- PurviewIds: item.FuncIds,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
-
- service.CreateRolePurview(purview)
- service.CreateFuncRolePurview(func_purview)
- }
- }
- }
-
- func (this *MobileRegistController) ModifyName() {
- name := this.GetString("name")
- adminUserObj := this.GetSession("mobile_admin_user")
- adminUser := adminUserObj.(*models.AdminUser)
- err := service.ModifyAdminUserName(name, adminUser.Id)
- if err != nil {
- utils.ErrorLog("修改管理员名字失败:%v", err)
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- this.ServeJSON()
- } else {
- this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{})
- this.ServeJSON()
- }
- }
-
- func (this *MobileRegistController) Login() {
- mobile := this.Ctx.GetCookie("mobile")
- adminUser, err := service.GetValidAdminUserByMobileReturnErr(mobile)
- if err != nil {
- utils.ErrorLog("获取管理信息失败:%v", err)
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- this.ServeJSON()
- } else {
-
- mobileAdminUserInfo := &mobile_api_controllers.MobileAdminUserInfo{
- AdminUser: adminUser,
- Org: nil,
- App: nil,
- AppRole: nil,
- Subscibe: nil,
- TemplateInfo: nil,
- }
-
- var org models.Org
- var user models.App_Role
- //设置seesion
- this.SetSession("mobile_admin_user_info", mobileAdminUserInfo)
- //设置cookie
- mobile = mobile + "-" + "0" + "-" + "0"
- token := utils.GenerateLoginToken(mobile)
- expiration, _ := beego.AppConfig.Int64("mobile_token_expiration_second")
- this.Ctx.SetCookie("token_cookie", token, expiration, "/")
- this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
- "admin": adminUser,
- "user": user,
- "org": org,
- "template_info": map[string]interface{}{
- "id": 0,
- "org_id": 0,
- "template_id": 0,
- },
- "config_list": nil,
- "filed_list": nil,
- })
- this.ServeJSON()
- }
-
- }
-
- type RoleConfig struct {
- Roles []*models.VMUserRoleAndPurview "json:roles"
- }
-
- type PatientConfig struct {
- Patients []*models.VMOrgPatients "json:patients"
- }
-
- type SchTemplateConfig struct {
- Item []*models.VMPatientScheduleTemplateItem "json:item"
- }
-
- type PrescriptionConfig struct {
- Prescription []*models.SystemPrescription "json:prescription"
- }
-
- func LoadRoleConfig(dataFile string) *RoleConfig {
- var config RoleConfig
- _, filename, _, _ := runtime.Caller(1)
- datapath := path.Join(path.Dir(filename), dataFile)
- config_file, err := os.Open(datapath)
- if err != nil {
- emit("Failed to open config file '%s': %s\n", datapath, err)
- return &config
- }
-
- fi, _ := config_file.Stat()
-
- buffer := make([]byte, fi.Size())
- _, err = config_file.Read(buffer)
-
- buffer, err = StripComments(buffer) //去掉注释
- if err != nil {
- emit("Failed to strip comments from json: %s\n", err)
- return &config
- }
-
- buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
- err = json.Unmarshal(buffer, &config) //解析json格式数据
- if err != nil {
- emit("Failed unmarshalling json: %s\n", err)
- return &config
- }
- return &config
- }
-
- func LoadPatientConfig(dataFile string) *PatientConfig {
- var config PatientConfig
- _, filename, _, _ := runtime.Caller(1)
- datapath := path.Join(path.Dir(filename), dataFile)
- config_file, err := os.Open(datapath)
- if err != nil {
- emit("Failed to open config file '%s': %s\n", datapath, err)
- return &config
- }
-
- fi, _ := config_file.Stat()
-
- buffer := make([]byte, fi.Size())
- _, err = config_file.Read(buffer)
-
- buffer, err = StripComments(buffer) //去掉注释
- if err != nil {
- emit("Failed to strip comments from json: %s\n", err)
- return &config
- }
-
- buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
- err = json.Unmarshal(buffer, &config) //解析json格式数据
- if err != nil {
- emit("Failed unmarshalling json: %s\n", err)
- return &config
- }
- return &config
- }
-
- func LoadSchTemplateConfig(dataFile string) *SchTemplateConfig {
- var config SchTemplateConfig
- _, filename, _, _ := runtime.Caller(1)
- datapath := path.Join(path.Dir(filename), dataFile)
- config_file, err := os.Open(datapath)
- if err != nil {
- emit("Failed to open config file '%s': %s\n", datapath, err)
- return &config
- }
-
- fi, _ := config_file.Stat()
-
- buffer := make([]byte, fi.Size())
- _, err = config_file.Read(buffer)
-
- buffer, err = StripComments(buffer) //去掉注释
- if err != nil {
- emit("Failed to strip comments from json: %s\n", err)
- return &config
- }
-
- buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
- err = json.Unmarshal(buffer, &config) //解析json格式数据
- if err != nil {
- emit("Failed unmarshalling json: %s\n", err)
- return &config
- }
- return &config
- }
-
- func LoadPrescriptionConfig(dataFile string) *PrescriptionConfig {
- var config PrescriptionConfig
- _, filename, _, _ := runtime.Caller(1)
- datapath := path.Join(path.Dir(filename), dataFile)
- config_file, err := os.Open(datapath)
- if err != nil {
- emit("Failed to open config file '%s': %s\n", datapath, err)
- return &config
- }
-
- fi, _ := config_file.Stat()
-
- buffer := make([]byte, fi.Size())
- _, err = config_file.Read(buffer)
-
- buffer, err = StripComments(buffer) //去掉注释
- if err != nil {
- emit("Failed to strip comments from json: %s\n", err)
- return &config
- }
-
- buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
- err = json.Unmarshal(buffer, &config) //解析json格式数据
- if err != nil {
- emit("Failed unmarshalling json: %s\n", err)
- return &config
- }
- return &config
- }
-
- func emit(msgfmt string, args ...interface{}) {
- log.Printf(msgfmt, args...)
- }
-
- func StripComments(data []byte) ([]byte, error) {
- data = bytes.Replace(data, []byte("\r"), []byte(""), 0) // Windows
- lines := bytes.Split(data, []byte("\n")) //split to muli lines
- filtered := make([][]byte, 0)
-
- for _, line := range lines {
- match, err := regexp.Match(`^\s*#`, line)
- if err != nil {
- return nil, err
- }
- if !match {
- filtered = append(filtered, line)
- }
- }
-
- return bytes.Join(filtered, []byte("\n")), nil
- }
-
- func GetDateOfWeek(week_type int) (weekMonday int64) {
- thisTime := time.Now()
- weekDay := int(thisTime.Weekday())
- if weekDay == 0 {
- weekDay = 7
- }
- weekEnd := 7 - weekDay
- weekStart := weekEnd - 6
- weekTitle := make([]string, 0)
- days := make([]string, 0)
- for index := weekStart; index <= weekEnd; index++ {
- theDay := thisTime.AddDate(0, 0, index)
- indexYear, indexMonthTime, indexDay := theDay.Date()
- indexMonth := int(indexMonthTime)
- indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
- weekTitle = append(weekTitle, indexWeek)
- days = append(days, theDay.Format("2006-01-02"))
- }
- var targetDayStr string
- switch week_type {
- case 1:
- targetDayStr = days[0]
- break
- case 2:
- targetDayStr = days[1]
-
- break
- case 3:
- targetDayStr = days[2]
-
- break
- case 4:
- targetDayStr = days[3]
-
- break
- case 5:
- targetDayStr = days[4]
-
- break
- case 6:
- targetDayStr = days[5]
-
- break
- case 7:
- targetDayStr = days[6]
-
- break
- }
- targetDay, _ := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
- return targetDay.Unix()
- }
-
- type Config struct {
- Parent_template []*models.VMDoctorAdviceParentTemplate "json:parent_template"
- }
-
- func LoadConfig(dataFile string) *Config {
- var config Config
- _, filename, _, _ := runtime.Caller(1)
- datapath := path.Join(path.Dir(filename), dataFile)
- config_file, err := os.Open(datapath)
- if err != nil {
- emit("Failed to open config file '%s': %s\n", datapath, err)
- return &config
- }
-
- fi, _ := config_file.Stat()
-
- buffer := make([]byte, fi.Size())
- _, err = config_file.Read(buffer)
-
- buffer, err = StripComments(buffer) //去掉注释
- if err != nil {
- emit("Failed to strip comments from json: %s\n", err)
- return &config
- }
-
- buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
- err = json.Unmarshal(buffer, &config) //解析json格式数据
- if err != nil {
- emit("Failed unmarshalling json: %s\n", err)
- return &config
- }
- return &config
- }
-
- func InitEquitMentInformation(org *models.Org) {
- //添加设备型号
- mode := models.VMDeviceMode{
- DeviceMode: "5008S",
- Status: 1,
- UserOrgId: org.Id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
- service.CreatedDeviceMode(&mode)
-
- deviceMode := models.VMDeviceMode{
- DeviceMode: "4008S",
- Status: 1,
- UserOrgId: org.Id,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- }
- service.CreatedDeviceMode(&deviceMode)
-
- firstDeviceMode, _ := service.GetFirstDeviceMode(org.Id)
- //获取机构下对应的第一数据
- number, _ := service.GetFirstBedNumber(org.Id)
- //添加设备
- deviceAddmacher := models.VmDeviceAddmacher{
- SerialNumber: "8VSAHE13",
- DeviceType: 1,
- BedId: number.ID,
- DeviceName: "费森尤斯",
- UnitType: firstDeviceMode.ID,
- MachineStatus: 1,
- Status: 1,
- UserOrgId: org.Id,
- Ctime: time.Now().Unix(),
- }
- service.CreateDeviceAddMacher(&deviceAddmacher)
- macher, _ := service.GetLastMacher(org.Id)
- fmt.Print(macher.ID)
- treatmentmode := models.VmDeviceTreatmentmode{
- MachineId: macher.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- UserOrgId: org.Id,
- TreateMode: 1,
- }
- service.CreatedTreateMode(&treatmentmode)
- treatmentmodeone := models.VmDeviceTreatmentmode{
- MachineId: macher.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- UserOrgId: org.Id,
- TreateMode: 2,
- }
- service.CreatedTreateMode(&treatmentmodeone)
- treatmentmodetwo := models.VmDeviceTreatmentmode{
- MachineId: macher.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- UserOrgId: org.Id,
- TreateMode: 3,
- }
- service.CreatedTreateMode(&treatmentmodetwo)
-
- treatmentmodethree := models.VmDeviceTreatmentmode{
- MachineId: macher.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- UserOrgId: org.Id,
- TreateMode: 4,
- }
- service.CreatedTreateMode(&treatmentmodethree)
- treatmentmodefour := models.VmDeviceTreatmentmode{
- MachineId: macher.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- UserOrgId: org.Id,
- TreateMode: 5,
- }
- service.CreatedTreateMode(&treatmentmodefour)
- treatmentmodefive := models.VmDeviceTreatmentmode{
- MachineId: macher.ID,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: time.Now().Unix(),
- UserOrgId: org.Id,
- TreateMode: 12,
- }
- service.CreatedTreateMode(&treatmentmodefive)
- }
|