123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- package controllers
-
- import (
- "IC/enums"
- "IC/models"
- "IC/service"
- "IC/utils"
- "encoding/json"
- "fmt"
- _ "github.com/astaxie/beego"
- _ "github.com/jinzhu/gorm"
- _ "strconv"
- "time"
- )
-
- // LisController operations for Lis
- type LisController struct {
- BaseAPIController
- }
-
- func (c *LisController) Schedule() {
- for i := 762429; i > 0; i-- {
- schedule,err := service.GetScheduless(int64(i))
- fmt.Println(schedule.ID)
- if err == nil {
- service.UpdateSchedule(schedule.ID,schedule.Status)
- }
-
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "resultList": "12345",
- })
- return
-
- }
-
- func (c *LisController) SyncAdvice() {
- // 获取备份库里所有的医嘱信息
- advices, _ := service.GetAllAdvice()
- for _, advice := range advices {
- // if index > 50 {
- // break
- // }
- tempAdvice := models.DoctorAdvice{
- ID: advice.ID,
- Checker: advice.Checker,
- CheckTime: advice.CheckTime,
- CheckState: advice.CheckState,
- }
- service.SyncAdvice(&tempAdvice)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "resultList": "12345",
- })
- return
-
- }
-
- func (c *LisController) FiledConfigSys() {
- orgs, _ := service.GetfiledConfigOrg()
- sysFiledConfig, _ := service.GetfiledConfigSys()
-
- if len(orgs) > 0 {
- for _, org := range orgs {
- for _, filed := range sysFiledConfig {
- filedConfig, _ := service.GetfiledConfigByOrgId(org.OrgId, filed.Module, filed.FiledName)
- if filedConfig.ID > 0 {
- continue
- } else {
- tempfiled := models.FiledConfig{
- OrgId: org.OrgId,
- Module: filed.Module,
- FiledName: filed.FiledName,
- FiledNameCn: filed.FiledNameCn,
- IsShow: 2,
- }
- service.CreatefiledConfig(&tempfiled)
- }
- }
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "resultList": "12345",
- })
- return
- }
-
- func (c *LisController) SyncToBase() {
- org_id, _ := c.GetInt64("org_id", 0)
- if org_id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- // 第一步:跟进org_id 去中间库查出需要同步的数据
- inspection_references, _ := service.GetSyncInspectionReferenceByOrgId(org_id)
- inspections, _ := service.GetSyncInspectionByOrgId(org_id)
-
- // 第二步:将数据同步到业务库
- if len(inspection_references) > 0 {
- for _, inspection_reference := range inspection_references {
- service.SyncInspectionReference(&inspection_reference)
- }
- }
-
- if len(inspections) > 0 {
- for _, inspection := range inspections {
- service.SyncInspection(&inspection)
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "resultList": "12345",
- })
- return
- }
-
- func (c *LisController) GetList() {
- org_id, _ := c.GetInt64("org_id", 0)
- if org_id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- // 第一步:根据机构id获取对应机构所有病人的his_user_id
- patients, patientError := service.GetHisUserIdByOrgID(org_id)
- if patientError != nil {
- utils.ErrorLog("获取用户His_user_id信息失败:%v", patientError)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- patientStr := make([]interface{}, 0)
- if len(patients) > 0 {
- // 第二步:根据病人的his_user_id来查询上次同步时间
- for _, patient := range patients {
- if len(patient.HisUserId) <= 0 {
- continue
- }
- // if patient.SelectType != 1 {
- // continue
- // }
-
- syncLastInfo, _ := service.GetSyncTimeByOrgID(org_id, patient.HisUserId)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- inspectionLastInfo, _ := service.GetInspectionLastInfoByOrgID(org_id, patient.HisUserId)
- if inspectionLastInfo.ID > 0 {
- sync_time = inspectionLastInfo.CreatedTime
- } else {
- sync_time = 1609430400
- }
- }
-
- syncTimes := time.Unix(sync_time, 0).Format("2006-01-02 15:04")
- utils.InfoLog("syncTimes:%v", syncTimes)
-
- // 第三步:跟进上次同步时间和指定的his_user_id,获取上次同步到现在指定人的检验检查记录
- resultList, _ := service.GetListByHisUserID(patient.HisUserId, syncTimes, patient.SelectType)
- var syncInfo models.MiddleSyncInfo
-
- if len(resultList) > 0 {
- // 如果有数据,则把同步过来的详情插入一条数据到同步详情表中
- syncInfo.OrgId = org_id
- syncInfo.HisUserId = patient.HisUserId
- syncInfo.SyncTime = time.Now().Unix()
- syncInfo.SyncResultType = 1
- syncInfo.SyncRsultRemark = "同步成功"
- syncInfo.SyncTotalNum = int64(len(resultList))
- syncInfo.SyncSuccessNum = 0
- SyncInfos, _ := json.Marshal(resultList)
- syncInfo.SyncInfo = string(SyncInfos)
- syncInfo.CreateTime = time.Now().Unix()
- syncInfo.UpdateTime = time.Now().Unix()
-
- err := service.CreateSyncInfo(&syncInfo)
- if err != nil {
- utils.ErrorLog("创建同步信息失败:%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- } else {
- // 如果没有数据,则插入一条数据到同步详情表中
- syncInfo.OrgId = org_id
- syncInfo.HisUserId = patient.HisUserId
- syncInfo.SyncTime = time.Now().Unix()
- syncInfo.SyncResultType = 1
- syncInfo.SyncRsultRemark = "该患者这个时间段没有任何检验检查数据"
- syncInfo.CreateTime = time.Now().Unix()
- syncInfo.UpdateTime = time.Now().Unix()
-
- err := service.CreateSyncInfo(&syncInfo)
- if err != nil {
- utils.ErrorLog("创建同步信息失败:%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- // utils.InfoLog("同步信息详情:%v",syncInfo)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- continue
- }
-
- // 第四部:将同步过来的数据插入到中间库对应的表
- syncSuccessNum := 0
- for _, result := range resultList {
- utils.ErrorLog("result:%v", result)
- if (result.HisUserId == patient.HisUserId) || (result.PatientName == patient.HisUserId) {
- patientId := patient.XtPatientId
- if patientId > 0 {
- inspection_reference, inspection, _ := service.Sync(result, org_id, patientId)
- if inspection_reference.ID > 0 || inspection.ID > 0 {
- syncSuccessNum++
- }
- }
- }
- }
- syncInfo.SyncSuccessNum = int64(syncSuccessNum)
- service.UpdateSyncInfo(&syncInfo)
-
- // patientStr = append(patientStr,patient.HisUserId)
- // utils.InfoLog("patientStr:%v",patientStr)
- }
- } else {
- var syncInfo models.MiddleSyncInfo
- // 如果没有数据,则插入一条数据到同步详情表中
- syncInfo.OrgId = org_id
- syncInfo.SyncTime = time.Now().Unix()
- syncInfo.SyncResultType = 0
- syncInfo.SyncRsultRemark = "该机构没有对应的his_user_id"
- syncInfo.CreateTime = time.Now().Unix()
- syncInfo.UpdateTime = time.Now().Unix()
-
- err := service.CreateSyncInfo(&syncInfo)
- if err != nil {
- utils.ErrorLog("创建同步信息失败:%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- utils.InfoLog("同步信息详情:%v", syncInfo)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- utils.InfoLog("patientStr:%v", patientStr)
-
- // // 第一步:根据机构id获取上次同步时间
- // syncLastInfo,_ := service.GetSyncTimeByOrgID(org_id)
- // var sync_time int64
- // if syncLastInfo.ID > 0 {
- // sync_time = syncLastInfo.SyncTime
- // } else {
- // sync_time = 0
- // }
-
- // syncTimes := time.Unix(sync_time,0).Format("2006-01-02 15:04")
- // utils.InfoLog("syncTimes:%v",syncTimes)
-
- // // 第二步:根据机构id获取对应机构所有病人的his_user_id
- // patients,patientError := service.GetHisUserIdByOrgID(org_id)
- // if patientError != nil {
- // utils.ErrorLog("获取用户His_user_id信息失败:%v", patientError)
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // }
-
- // patientStr:= make([]interface{},0)
- // if len(patients) > 0 {
- // for _ , patient := range patients {
- // patientStr = append(patientStr,patient.HisUserId)
- // utils.InfoLog("patientStr:%v",patientStr)
- // }
- // } else {
- // // 如果没有数据,则插入一条数据到同步详情表中
- // syncInfo.OrgId = org_id
- // syncInfo.SyncTime = time.Now().Unix()
- // syncInfo.SyncResultType = 0
- // syncInfo.SyncRsultRemark = "该机构没有对应的his_user_id"
- // syncInfo.CreateTime = time.Now().Unix()
- // syncInfo.UpdateTime = time.Now().Unix()
-
- // err := service.CreateSyncInfo(&syncInfo)
- // if err != nil {
- // utils.ErrorLog("创建同步信息失败:%v", err)
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // }
- // utils.InfoLog("同步信息详情:%v",syncInfo)
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // }
-
- // utils.InfoLog("patientStr:%v",patientStr)
-
- // // 第三步:跟进上次同步时间和指定的his_user_id,获取上次同步到现在指定人的检验检查记录
- // resultList, _ := service.GetList(patientStr,syncTimes)
-
- // if len(resultList) > 0 {
- // // 如果有数据,则把同步过来的详情插入一条数据到同步详情表中
- // syncInfo.OrgId = org_id
- // syncInfo.SyncTime = time.Now().Unix()
- // syncInfo.SyncResultType = 1
- // syncInfo.SyncRsultRemark = "同步成功"
- // syncInfo.SyncTotalNum = int64(len(resultList))
- // syncInfo.SyncSuccessNum = 0
- // SyncInfos,_ := json.Marshal(resultList)
- // syncInfo.SyncInfo = string(SyncInfos)
- // syncInfo.CreateTime = time.Now().Unix()
- // syncInfo.UpdateTime = time.Now().Unix()
-
- // err := service.CreateSyncInfo(&syncInfo)
- // if err != nil {
- // utils.ErrorLog("创建同步信息失败:%v", err)
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // }
- // } else {
- // // 如果没有数据,则插入一条数据到同步详情表中
- // syncInfo.OrgId = org_id
- // syncInfo.SyncTime = time.Now().Unix()
- // syncInfo.SyncResultType = 1
- // syncInfo.SyncRsultRemark = "该机构这个时间段没有任何检验检查数据"
- // syncInfo.CreateTime = time.Now().Unix()
- // syncInfo.UpdateTime = time.Now().Unix()
-
- // err := service.CreateSyncInfo(&syncInfo)
- // if err != nil {
- // utils.ErrorLog("创建同步信息失败:%v", err)
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // }
- // // utils.InfoLog("同步信息详情:%v",syncInfo)
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // }
-
- // // 第四部:将同步过来的数据插入到中间库对应的表
- // syncSuccessNum := 0
- // for _, result := range resultList {
- // patientId := int64(0)
- // for _ , patientInfo := range patients {
- // if result.HisUserId == patientInfo.HisUserId {
- // patientId = patientInfo.XtPatientId
- // break
- // }
- // }
- // if patientId > 0 {
- // inspection_reference,inspection,_ := service.Sync(result,org_id,patientId)
- // if (inspection_reference.ID > 0 || inspection.ID > 0 ) {
- // syncSuccessNum++
- // }
- // }
- // }
- // syncInfo.SyncSuccessNum = int64(syncSuccessNum)
- // service.UpdateSyncInfo(&syncInfo)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "resultList": patients,
- })
- return
-
- }
-
- func (c *LisController) SyncLgth() {
- service.SyncLisLgty()
- c.ServeSuccessJSON(map[string]interface{}{
- "resultList": "12345",
- })
- return
- }
-
- func (c *LisController) SyncYstx() {
- service.SyncLisYstx()
- c.ServeSuccessJSON(map[string]interface{}{
- "resultList": "12345",
- })
- return
- }
-
- func (c *LisController) SyncGzjhyz() {
- service.SyncGzjhyz()
- c.ServeSuccessJSON(map[string]interface{}{
- "resultList": "12345",
- })
- return
- }
-
- func (c *LisController) SyncGzjhLis() {
- service.SyncGzjhLis()
- c.ServeSuccessJSON(map[string]interface{}{
- "resultList": "12345",
- })
- return
- }
-
- func (c *LisController) SyncHbJldyyz() {
- service.SyncHbJldyyz()
- c.ServeSuccessJSON(map[string]interface{}{
- "resultList": "12345",
- })
- return
- }
-
- func (c *LisController) SyncHbJldyLis() {
- service.SyncHbdyLis()
- c.ServeSuccessJSON(map[string]interface{}{
- "resultList": "12345",
- })
- return
- }
-
- func (c *LisController) SyncBlLis() {
- service.GetDataInsertDB(10138)
- c.ServeSuccessJSON(map[string]interface{}{
- "resultList": "同步成功",
- })
- }
-
- func (c *LisController) SyncBlResultLis() {
-
- service.GetResultDataInsertDB(10138)
- c.ServeSuccessJSON(map[string]interface{}{
- "resultList": "同步成功",
- })
- }
|