123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816 |
- package service
-
- import (
- "IC/models"
- "IC/utils"
- _ "IC/utils"
- "encoding/json"
- _ "encoding/json"
- "encoding/xml"
- _ "fmt"
- "github.com/astaxie/beego/httplib"
- _ "github.com/jinzhu/gorm"
- "net/url"
- "strconv"
- "strings"
- "time"
- )
-
- // 广州康允血液透析中心 检验检查对接
-
- type XmlKeyGzky struct {
- XMLName xml.Name `xml:"string"`
- StringName string `xml:"name,attr"`
- InnerText string `xml:",innerxml"`
- }
-
- // 获取艾迪康的key
- func GetAdKeyGzky(logid string, password string) (key string) {
- Domain := "http://183.63.151.26:8081/AdWebService_new/ADReportWebService.asmx/Login?"
- apiurl := "logid=" + logid + "&password=" + password
- apiurl = url.PathEscape(apiurl)
- apiurl = Domain + apiurl
- XmlKeyGzky := XmlKeyGzky{}
- httplib.Get(apiurl).ToXML(&XmlKeyGzky)
- return XmlKeyGzky.InnerText
- }
-
- type ADStringGzky struct {
- XMLName xml.Name `xml:"string" json:"string"`
- NewDataSetGzky rpnewDataSetGzky `xml:"NewDataSet" json:"NewDataSet"`
- }
-
- type rpnewDataSetGzky struct {
- ListTableGzky []rplisttableGzky `xml:"listtable" json:"listtable"`
- }
-
- type rplisttableGzky struct {
- Id string `xml:"Id" json:"Id"`
- ReportType string `xml:"ReportType" json:"ReportType"`
- AdiconBarcode string `xml:"AdiconBarcode" json:"AdiconBarcode"`
- PatientName string `xml:"PatientName" json:"PatientName"`
- Bgrq string `xml:"Bgrq" json:"Bgrq"`
- Instrument string `xml:"Instrument" json:"Instrument"`
- LisDate string `xml:"LisDate" json:"LisDate"`
- Sampleid string `xml:"Sampleid" json:"Sampleid"`
- CustomerBarcode string `xml:"CustomerBarcode" json:"CustomerBarcode"`
- Repno string `xml:"Repno" json:"Repno"`
- // PdfFileName string `xml:"PdfFileName" json:"PdfFileName"`
- // DownFlag string `xml:"DownFlag" json:"DownFlag"`
- // DownDate string `xml:"DownDate" json:"DownDate"`
- Sjrq string `xml:"Sjrq" json:"Sjrq"`
- // Sjys string `xml:"Sjys" json:"Sjys"`
- // Brnl string `xml:"Brnl" json:"Brnl"`
- // Brxb string `xml:"Brxb" json:"Brxb"`
- Bbzl string `xml:"bbzl" json:"bbzl"`
- // Bzlbid string `xml:"Bzlbid" json:"Bzlbid"`
- // PDFFileType string `xml:"PDFFileType" json:"PDFFileType"`
- // PageType string `xml:"PageType" json:"PageType"`
- PatientNo string `xml:"PatientNo" json:"PatientNo"`
- // SfzId string `xml:"SfzId" json:"SfzId"`
- // CertificatesType string `xml:"CertificatesType" json:"CertificatesType"`
- // Nationality string `xml:"Nationality" json:"Nationality"`
- // SerialNumber string `xml:"SerialNumber" json:"SerialNumber"`
- // Str1 string `xml:"Str1" json:"Str1"`
- // Str2 string `xml:"Str2" json:"Str2"`
- // Str3 string `xml:"Str3" json:"Str3"`
- // Str4 string `xml:"Str4" json:"Str4"`
- // Str5 string `xml:"Str5" json:"Str5"`
- // TWBG string `xml:"TWBG" json:"TWBG"`
- }
-
- // 获取机构一段时间内检验检查列表
- func GetAdGetReportListGzky(Key string, BeginDateTime string, EndDateTime string, TypeDateTime string, AgainFlag string) (key ADStringGzky) {
- Domain := "http://183.63.151.26:8081/AdWebService_new/ADReportWebService.asmx/GetReportList"
- //apiurl := "Key=" + Key + "&BeginDateTime=" + BeginDateTime + "&EndDateTime=" + EndDateTime + "&TypeDateTime=" + TypeDateTime + "&AgainFlag=" + AgainFlag
- //apiurl = url.PathEscape(apiurl)
- //apiurl = Domain + apiurl
- //utils.InfoLog("url0: %v", apiurl)
- var xmlKey ADStringGzky
- req := httplib.Post(Domain)
- req.Param("Key", Key)
- req.Param("BeginDateTime", BeginDateTime)
- req.Param("EndDateTime", EndDateTime)
- req.Param("TypeDateTime", TypeDateTime)
- req.Param("AgainFlag", AgainFlag)
- xmlString, _ := req.String()
- xmlString = strings.Replace(xmlString, "<", "<", -1)
- xmlString = strings.Replace(xmlString, ">", ">", -1)
- xml.Unmarshal([]byte(xmlString), &xmlKey)
- return xmlKey
- }
-
- type AdkCheckGzky struct {
- Cgbg AdkSResultGzky `json:"常规报告"`
- }
-
- type AdkSResultGzky struct {
- Item []AdkItemGzky `json:"item"`
- }
-
- type AdkItemGzky struct {
- Adiconbarcode string `json:"AdiconBarcode"`
- Patientname string `json:"PatientName"`
- Sex string `json:"Sex"`
- Age string `json:"Age"`
- Reportdate string `json:"ReportDate"`
- Itemcode string `json:"ItemCode"`
- ItemnameCn string `json:"ItemName_CN"`
- ItemnameEn string `json:"ItemName_EN"`
- Result string `json:"Result"`
- Resulthint string `json:"ResultHint"`
- Resultreference string `json:"ResultReference"`
- Resultunit string `json:"ResultUnit"`
- Zhmc string `json:"zhmc"`
- }
-
- func GetAdkInfoGzky(key string, id string) (str AdkCheckGzky, checkStr string) {
- Domain := "http://183.63.151.26:8081/AdWebService_new/ADReportWebService.asmx/GetJSONReportItemListByAdiconBarocde?"
- //apiurl := "key=" + key + "&AdiconBarocde=" + id
- //apiurl = url.PathEscape(apiurl)
- //apiurl = Domain + apiurl
- //utils.InfoLog("url1: %v", apiurl)
- xmlKey := XmlKeyGzky{}
- rep := httplib.Post(Domain)
- rep.Param("Key", key)
- rep.Param("AdiconBarcode", id)
- rep.ToXML(&xmlKey)
- utils.InfoLog("InnerText: %v", xmlKey.InnerText)
- var checkJSON AdkCheckGzky
- json.Unmarshal([]byte(xmlKey.InnerText), &checkJSON)
-
- return checkJSON, xmlKey.InnerText
- }
-
- // 广州康允透析中心Lis同步
- func SyncLisGzky(flag int64) (err error) {
- // 第一步:获取艾迪康下发的Key
- org_id := int64(10567)
- login := "RH0395"
- password := "abc123456"
- key := GetAdKeyGzky(login, password)
- utils.InfoLog("key:%v", key)
- // 第二步:获取上一次同步的时间点
- syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime - 60*60*24*3
- } else {
- sync_time = 1730390400
- }
-
- if flag > 0 {
- sync_time = 1730390400
- }
-
- nowTimes := time.Now().Unix()
- // syncTimes := time.Unix(sync_time,0).Format("2006-01-02")
- if sync_time < nowTimes {
- for i := sync_time; i < nowTimes; i = i + 86400 {
- tempsyncTimes := time.Unix(i, 0).Format("2006-01-02")
- adString := GetAdGetReportListGzky(key, tempsyncTimes, tempsyncTimes, "2", "1")
- listtable := adString.NewDataSetGzky.ListTableGzky
- if len(listtable) >= 1 {
- // 第三步:根据检查列表获取的ID来获取检验检查详情
- for _, list := range listtable {
- listId := list.AdiconBarcode
- checkInfo, _ := GetAdkInfoGzky(key, listId)
- //utils.InfoLog("checkStr: %v", checkStr)
- for _, info := range checkInfo.Cgbg.Item {
- // 根据姓名 去查询对应的patient_id
- patient, _ := GetPatientID(org_id, info.Patientname)
- utils.InfoLog("patient: %v", patient)
- if patient.ID > 0 {
- GzkyReportInfoHandle(info, org_id, patient.ID)
- }
- }
- }
- var syncInfo models.MiddleSyncInfo
- syncInfo.OrgId = org_id
-
- syncInfo.SyncTime = i
- syncInfo.SyncResultType = 1
- syncInfo.SyncRsultRemark = "同步成功"
- syncInfo.SyncTotalNum = 0
- syncInfo.SyncSuccessNum = 0
- syncInfo.SyncInfo = ""
- syncInfo.CreateTime = time.Now().Unix()
- syncInfo.UpdateTime = time.Now().Unix()
-
- cwderr := CreateSyncInfo(&syncInfo)
- if cwderr != nil {
- utils.ErrorLog("创建同步信息失败:%v", cwderr)
- return
- }
- }
- }
-
- }
- SyncToGzky()
- TreatSgnForGzky(10567)
- return
- }
-
- func SyncToGzky() {
-
- utils.TraceLog("检验检查同步任务开始执行")
- org_id := int64(10567)
-
- // 第一步:跟进org_id 去中间库查出需要同步的数据
- //inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
- inspections, _ := GetSyncInspectionByOrgId(org_id)
-
- // 第二步:将数据同步到业务库
- //if len(inspection_references) > 0 {
- // for _, inspection_reference := range inspection_references {
- // SyncInspectionReference(&inspection_reference)
- // }
- //}
-
- if len(inspections) > 0 {
- for _, inspection := range inspections {
- if inspection.SysProjectId > 0 && inspection.SysItemId > 0 {
- SyncGzkyInspection(&inspection)
- }
- }
- }
- utils.SuccessLog("检验检查同步任务完成")
- }
-
- // 从机构将数据同步到中间库
- func SyncGzkyInspection(data *models.MiddleInspection) error {
- tx := writeDb.Begin()
- var inspection models.Inspection
- var total int
- err = readDb.Model(&models.Inspection{}).Where("org_id = ? and project_id = ? and item_id = ? and patient_id =? and inspect_date=? and status = 1", data.OrgId, data.ProjectId, data.ItemId, data.PatientId, data.RecordDate).Find(&inspection).Count(&total).Error
- if total <= 0 {
- inspection.OrgId = data.OrgId
- inspection.PatientId = data.PatientId
- inspection.ProjectName = data.ProjectName
- // inspection.Project = data.ProjectName
- inspection.ProjectId = data.SysProjectId
- inspection.ItemName = data.ItemName
- inspection.ItemId = data.SysItemId
- inspection.InspectType = int64(data.InspectType)
- inspection.InspectValue = data.InspectValue
- inspection.InspectTips = data.InspectTips
- inspection.InspectDate = data.RecordDate
- inspection.Status = 1
- inspection.CreatedTime = time.Now().Unix()
- inspection.UpdatedTime = time.Now().Unix()
-
- err := tx.Model(&models.Inspection{}).Create(&inspection).Error
- if err != nil {
- tx.Rollback()
- }
-
- data.IsSync = 1
- data.SyncId = inspection.ID
- data.UpdatedTime = time.Now().Unix()
- ierr := writeMiddleDb.Save(&data).Error
- if ierr != nil {
- tx.Rollback()
- }
- }
- tx.Commit()
- return err
- }
-
- // 同步到正式库后,确认透前肾功能和透后肾功能
- // 计算KT/V 和 URR
- func TreatSgnForGzky(org_id int64) error {
- tx := writeDb.Begin()
- var inspection []models.Inspection
- err = readDb.Model(&models.Inspection{}).Where("org_id = ? and project_id = 15 and sgn_treat = 0 and status = 1", org_id).Find(&inspection).Error
- if len(inspection) > 0 {
- for _, insp := range inspection {
- var inspectionInfo models.Inspection
- err = readDb.Model(&models.Inspection{}).Where("org_id = ? and patient_id = ? and project_id = 15 and item_id = ? and inspect_date = ? and sgn_treat = 0 and status = 1", org_id, insp.PatientId, insp.ItemId, insp.InspectDate).First(&inspectionInfo).Error
- if inspectionInfo.ID > 0 {
- // 查询前面两天是否有数据,有的话,当前数据有透后数据
- startData := inspectionInfo.InspectDate - 60*60*48
- var inspectionBefore models.Inspection
- err = readDb.Model(&models.Inspection{}).Where("org_id = ? and patient_id = ? and project_id = 15 and item_id = ? and inspect_date >= ? and inspect_date < ? and sgn_treat = 0 and status = 1", org_id, insp.PatientId, insp.ItemId, startData, insp.InspectDate).First(&inspectionBefore).Error
- if inspectionBefore.ID > 0 {
- inspectionBefore.SgnTreat = 1
- inspectionBefore.UpdatedTime = time.Now().Unix()
- err = writeDb.Save(&inspectionBefore).Error
- if err != nil {
- tx.Rollback()
- }
- insp.ProjectId = 8060
- switch insp.ItemId {
- case 37: //尿素
- insp.ItemId = 8061
- break
- case 38: //尿酸
- insp.ItemId = 10834
- break
- case 42: //β2-微球蛋白
- insp.ItemId = 10835
- break
- case 115: //肌酐
- insp.ItemId = 8060
- break
- }
- insp.UpdatedTime = time.Now().Unix()
- insp.SgnTreat = 1
- err = writeDb.Save(&insp).Error
- if err != nil {
- tx.Rollback()
- }
- } else {
- // 前面两天没有查到数据,则可能当前数据是透前数据,后面两天查询到的数据是透后数据
- endData := inspectionInfo.InspectDate + 60*60*48
- var inspectionEnd models.Inspection
- err = readDb.Model(&models.Inspection{}).Where("org_id = ? and patient_id = ? and project_id = 15 and item_id = ? and inspect_date > ? and inspect_date <= ? and sgn_treat = 0 and status = 1", org_id, insp.PatientId, insp.ItemId, insp.InspectDate, endData).First(&inspectionEnd).Error
- if inspectionEnd.ID > 0 {
- insp.SgnTreat = 1
- insp.UpdatedTime = time.Now().Unix()
- err = writeDb.Save(&insp).Error
- if err != nil {
- tx.Rollback()
- }
- inspectionEnd.ProjectId = 8060
- switch inspectionEnd.ItemId {
- case 37: //尿素
- inspectionEnd.ItemId = 8061
- break
- case 38: //尿酸
- inspectionEnd.ItemId = 10834
- break
- case 42: //β2-微球蛋白
- inspectionEnd.ItemId = 10835
- break
- case 115: //肌酐
- inspectionEnd.ItemId = 8060
- break
- }
- inspectionEnd.UpdatedTime = time.Now().Unix()
- inspectionEnd.SgnTreat = 1
- err = writeDb.Save(&inspectionEnd).Error
- if err != nil {
- tx.Rollback()
- }
- } else {
- // 如果前面两天和后面两天都没有数据,则直接改变状体
- insp.SgnTreat = 1
- insp.UpdatedTime = time.Now().Unix()
- err = writeDb.Save(&insp).Error
- if err != nil {
- tx.Rollback()
- }
- }
- }
- } else {
- continue
- }
- }
- }
- tx.Commit()
- return err
- }
-
- // 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
- func GetGzkyItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, err error) {
- var inspection_reference models.MiddleInspectionReference
- err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ? and item_name = ?", org_id, project_name, item_name).First(&inspection_reference).Error
- if inspection_reference.ID > 0 {
- return inspection_reference.ItemId, err
- } else {
- err := readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id = ? and project_id = ? ", org_id, project_id).Select("max(item_id) as item_id").First(&inspection_reference).Error
- utils.InfoLog("inspection_reference: %v", inspection_reference)
- if inspection_reference.ItemId > 0 {
- return inspection_reference.ItemId + 1, err
- } else {
- return project_id*100 + 1, err
- }
- }
- }
-
- // 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
- func GetGzkyProjectID(org_id int64, project_name string) (project_id int64, err error) {
- var inspection_reference models.MiddleInspectionReference
- err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ?", org_id, project_name).First(&inspection_reference).Error
- if inspection_reference.ID > 0 {
- return inspection_reference.ProjectId, err
- } else {
- err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
- if inspection_reference.ProjectId > 0 {
- return inspection_reference.ProjectId + 1, err
- } else {
- return 1056701, err
- }
- }
- }
-
- func GzkyReportInfoHandle(CheckInfo AdkItemGzky, org_id int64, patientId int64) {
- tx := writeMiddleDb.Begin()
- var total int
- var RangeMin string
- var RangeMax string
-
- timstr := strings.Split(CheckInfo.Reportdate, ".")
- recordDateStr := timstr[0]
-
- if len(recordDateStr) == 0 {
- recordDateStr = time.Now().Format("2006-01-02 15:04")
- }
-
- record_date_str, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
- record_date := record_date_str.Unix()
- inspect_date := time.Unix(record_date, 0).Format("2006-01-02 15:04")
-
- // // 判断检查类型
- ItemType := 1
- Range := strings.Split(CheckInfo.Resultreference, "-")
- if len(Range) > 1 {
- RangeMin = Range[0]
- RangeMax = Range[1]
- ItemType = 1
- } else {
- ItemType = 2
- }
-
- var inspection models.MiddleInspection
- var inspection_reference models.MiddleInspectionReference
- err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and project = ? and item_code = ? and status = 1", org_id, CheckInfo.Zhmc, CheckInfo.Itemcode).Find(&inspection_reference).Count(&total).Error
- if inspection_reference.ID > 0 {
- ItemType = inspection_reference.RangeType
- }
- if total <= 0 {
- // 如果配置表里没有相关配置,则创建project_id,item_id和相关配置信息
- project_id, _ := GetChydProjectID(org_id, CheckInfo.Zhmc)
- item_id, _ := GetChydItemID(org_id, CheckInfo.Zhmc, CheckInfo.ItemnameCn, project_id)
-
- inspection_reference.OrgId = org_id
- inspection_reference.ProjectName = CheckInfo.Zhmc
- inspection_reference.Project = CheckInfo.Zhmc
- inspection_reference.ProjectId = project_id
- inspection_reference.ItemName = CheckInfo.ItemnameCn
- inspection_reference.ItemNameAddition = CheckInfo.ItemnameEn
- inspection_reference.ItemId = item_id
- inspection_reference.ItemCode = CheckInfo.Itemcode
- inspection_reference.RangeType = ItemType
- inspection_reference.RangeMin = RangeMin
- inspection_reference.RangeMax = RangeMax
- // inspection_reference.RangeValue = RangeValue
- //inspection_reference.RangeOptions = RangeOptions
- inspection_reference.Unit = CheckInfo.Resultunit
- inspection_reference.Status = 1
- inspection_reference.CreatedTime = time.Now().Unix()
- inspection_reference.UpdatedTime = time.Now().Unix()
- inspection_reference.InspectDate = inspect_date
- inspection_reference.UTime = inspect_date
- inspection_reference.Adiconbarcode = CheckInfo.Adiconbarcode
- err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
- if err != nil {
- tx.Rollback()
- }
- }
-
- var itotal int
- err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ? and project_id = ? and item_id = ? and record_date = ? and patient_id = ? and status = 1", org_id, inspection_reference.ProjectId, inspection_reference.ItemId, record_date, patientId).Find(&inspection).Count(&itotal).Error
- if itotal <= 0 {
- inspection.PatientId = patientId
- inspection.OrgId = org_id
- inspection.ProjectId = inspection_reference.ProjectId
- inspection.ItemName = inspection_reference.ItemName
- inspection.ProjectName = inspection_reference.ProjectName
- inspection.InspectType = ItemType
- inspection.ItemId = inspection_reference.ItemId
- inspection.InspectValue = CheckInfo.Result
- inspection.InspectDate = inspect_date
- inspection.RecordDate = record_date
- //inspection.InspectTips = result.AntiCode
- inspection.Status = 1
- inspection.CreatedTime = time.Now().Unix()
- inspection.UpdatedTime = time.Now().Unix()
- inspection.SysProjectId = inspection_reference.XtProjectId
- inspection.SysItemId = inspection_reference.XtItemId
- inspection.UTime = inspect_date
- inspection.HisUserId = strconv.FormatInt(patientId, 10)
- inspection.Adiconbarcode = CheckInfo.Adiconbarcode
- if inspection_reference.ItemId == 103180107 || inspection_reference.ItemId == 103180301 {
- if strings.Index(CheckInfo.Result, "阳性") != -1 {
- inspection.InspectValue = "阳性"
- } else {
- inspection.InspectValue = "阴性"
- }
- }
-
- err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
- if err != nil {
- tx.Rollback()
- }
- }
- tx.Commit()
- }
-
- //
- //type gzkylis struct {
- // Finputdate string `gorm:"column:F_InputDate" json:"F_InputDate"`
- // Fname string `gorm:"column:F_Name" json:"F_Name"`
- // Fsex string `gorm:"column:F_Sex" json:"F_Sex"`
- // Fage string `gorm:"column:F_Age" json:"F_Age"`
- // Fhospnaturalitem string `gorm:"column:F_HospNaturalItem" json:"F_HospNaturalItem"`
- // Fhospnaturalitemname string `gorm:"column:F_HospNaturalItemName" json:"F_HospNaturalItemName"`
- // Fhospitem string `gorm:"column:F_HospItem" json:"F_HospItem"`
- // Fhospitemname string `gorm:"column:F_HospItemName" json:"F_HospItemName"`
- // Fresult string `gorm:"column:F_Result" json:"F_Result"`
- // Funit string `gorm:"column:F_Unit" json:"F_Unit"`
- // Fhint string `gorm:"column:F_Hint" json:"F_Hint"`
- // Freference string `gorm:"column:F_Reference" json:"F_Reference"`
- // Frecordtime string `gorm:"column:F_RecordTime" json:"F_RecordTime"`
- //}
- //
- //func (gzkylis) TableName() string {
- // return "V_KM_LIS_Result"
- //}
- //
- //func GetGzkyLis(rdb *gorm.DB, synctime string) (record []*gzkylis, err error) {
- // err = rdb.Model(&gzkylis{}).Where("F_RecordTime >= ? ", synctime).Find(&record).Error
- // return
- //}
- //
- //// 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
- //func GetGzkyProjectID(org_id int64, project_name string) (project_id int64, err error) {
- // var inspection_reference models.MiddleInspectionReference
- // err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ? ", org_id, project_name).First(&inspection_reference).Error
- // if inspection_reference.ID > 0 {
- // return inspection_reference.ProjectId, err
- // } else {
- // err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
- // if inspection_reference.ProjectId > 0 {
- // return inspection_reference.ProjectId + 1, err
- // } else {
- // return 1056701, err
- // }
- // }
- //}
- //
- //// 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
- //func GetGzkyItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, err error) {
- // var inspection_reference models.MiddleInspectionReference
- // err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ? and item_name = ?", org_id, project_name, item_name).First(&inspection_reference).Error
- // if inspection_reference.ID > 0 {
- // return inspection_reference.ItemId, err
- // } else {
- // err := readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id = ? and project_id = ? ", org_id, project_id).Select("max(item_id) as item_id").First(&inspection_reference).Error
- // if inspection_reference.ItemId > 0 {
- // return inspection_reference.ItemId + 1, err
- // } else {
- // return project_id*100 + 1, err
- // }
- // }
- //}
- //
- //// 汕头三优血液透析中心
- //func SyncGzkyLis() (err error) {
- // org_id := int64(10567)
- //
- // org := &models.DataUploadConfig{
- // OrgId: org_id,
- // DbHost: "127.0.0.1",
- // DbPort: "1433",
- // DbPass: "1Q2W3e4r!@#$",
- // DbUser: "kyy",
- // DbName: "kmdb",
- // }
- //
- // orgDb, err := CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
- // if err != nil {
- // utils.ErrorLog("创建数据库连接失败:%v", err)
- // return
- // }
- //
- // // var sync_time int64
- // // sync_time = 1627747200
- //
- // // scpaLis, _ := GetScpaLis(orgDb, sync_time,"512926196302182682")
- // // utils.InfoLog("IdCardNo:%v",scpaLis)
- //
- // // 第一步:获取上一次同步的时间点
- // syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
- // var sync_time int64
- // if syncLastInfo.ID > 0 {
- // sync_time = syncLastInfo.SyncTime
- // } else {
- // sync_time = 1685548800
- // }
- //
- // SyncTime := time.Unix(sync_time, 0)
- // syncTimeStr := SyncTime.Format("2006-01-02 15:04:05")
- //
- // fmt.Println(SyncTime)
- // // 第二步:获取时间内所有检验结果
- // gzkyLis, _ := GetGzkyLis(orgDb, syncTimeStr)
- //
- // if len(gzkyLis) > 0 {
- // for _, LisInfo := range gzkyLis {
- // utils.InfoLog("LisInfo:%v", LisInfo)
- // utils.InfoLog("患者姓名:%v", LisInfo.Fname)
- // brxm := LisInfo.Fname
- // // 根据姓名获取患者ID
- // patient, _ := GetUserInfoByName(org_id, brxm)
- // if patient.ID > 0 {
- // project_id, _ := GetGzkyProjectID(org_id, LisInfo.Fhospnaturalitemname)
- // item_id, _ := GetGzkyItemID(org_id, LisInfo.Fhospnaturalitemname, LisInfo.Fhospitemname, project_id)
- // tx := writeMiddleDb.Begin()
- // var inspection models.MiddleInspection
- // var inspection_reference models.MiddleInspectionReference
- //
- // tempTime := strings.Split(LisInfo.Frecordtime, "T")
- // utils.InfoLog("tempTime1:%v", tempTime[0])
- // utils.InfoLog("tempTime2:%v", tempTime[1])
- // tempTime1 := strings.Split(tempTime[1], "Z")
- // tempRecord := tempTime[0] + " " + tempTime1[0]
- //
- // utils.InfoLog("tempTime3:%v", tempRecord)
- //
- // recordTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", tempRecord)
- // utils.InfoLog("tempTime4:%v", recordTime)
- // inspect_date := recordTime.Format("2006-01-02 15:04")
- // recordTimeStr, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", inspect_date)
- // recordTimeInt := recordTimeStr.Unix()
- // utils.InfoLog("tempTime5:%v", recordTimeInt)
- // utils.InfoLog("tempTime6:%v", recordTimeStr)
- //
- // var total int
- // var RangeOptions string
- // var RangeMin string
- // var RangeMax string
- // var ItemType int
- // typeFlag := strings.Contains(LisInfo.Freference, "阴性")
- // if typeFlag {
- // ItemType = 2
- // RangeMin = LisInfo.Freference
- // RangeOptions = LisInfo.Fhint
- // } else {
- // Range := strings.Split(LisInfo.Freference, "-")
- // if len(Range) > 1 {
- // RangeMin = Range[0]
- // RangeMax = Range[1]
- // ItemType = 1
- // } else {
- // ItemType = 2
- // RangeMin = LisInfo.Freference
- // }
- // RangeOptions = LisInfo.Fhint
- // }
- //
- // err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and project_id = ? and item_id = ? and status = 1", org_id, project_id, item_id).Find(&inspection_reference).Count(&total).Error
- // if total <= 0 {
- // inspection_reference.OrgId = org_id
- // inspection_reference.ProjectName = LisInfo.Fhospnaturalitemname
- // inspection_reference.Project = LisInfo.Fhospnaturalitem
- // inspection_reference.ProjectId = project_id
- // inspection_reference.ItemName = LisInfo.Fhospitemname
- // inspection_reference.ItemNameAddition = LisInfo.Fhospitem
- // inspection_reference.ItemId = item_id
- // inspection_reference.RangeType = ItemType
- // inspection_reference.RangeMin = RangeMin
- // inspection_reference.RangeMax = RangeMax
- // inspection_reference.RangeValue = LisInfo.Freference
- // inspection_reference.RangeOptions = RangeOptions
- // inspection_reference.Unit = LisInfo.Funit
- // inspection_reference.Status = 1
- // inspection_reference.CreatedTime = time.Now().Unix()
- // inspection_reference.UpdatedTime = time.Now().Unix()
- // inspection_reference.InspectDate = tempRecord
- // inspection_reference.UTime = tempRecord
- // err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
- // if err != nil {
- // tx.Rollback()
- // }
- // }
- // var itotal int
- // err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ? and project_id = ? and item_id = ? and record_date = ? and patient_id = ? and status = 1", org_id, project_id, item_id, recordTimeStr, patient.ID).Find(&inspection).Count(&itotal).Error
- // if itotal <= 0 {
- // // inspection.InspectValue = strings.Replace(LisInfo.Testresult, ">", ">", -1)
- // // inspection.InspectValue = strings.Replace(LiLisInfo.Testresult, "<", "<", -1)
- // inspection.PatientId = patient.ID
- // inspection.OrgId = org_id
- // inspection.ProjectId = project_id
- // inspection.ItemName = inspection_reference.ItemName
- // inspection.ProjectName = inspection_reference.ProjectName
- // inspection.InspectType = ItemType
- // inspection.ItemId = item_id
- // inspection.InspectValue = LisInfo.Fresult
- // inspection.InspectDate = inspect_date
- // inspection.RecordDate = recordTimeInt
- // inspection.InspectTips = LisInfo.Fhint
- // inspection.Status = 1
- // inspection.CreatedTime = time.Now().Unix()
- // inspection.UpdatedTime = time.Now().Unix()
- // // inspection.UTime = record_date.Format(timeLayout)
- // // inspection.HisUserId = strconv.FormatInt(patient_id, 10)
- // inspection.SysProjectId = inspection_reference.XtProjectId
- // inspection.SysItemId = inspection_reference.XtItemId
- // err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
- // if err != nil {
- // tx.Rollback()
- // }
- // }
- // tx.Commit()
- // } else {
- // continue
- // }
- // }
- // }
- // var syncInfo models.MiddleSyncInfo
- // syncInfo.OrgId = org_id
- // syncInfo.SyncTime = time.Now().Unix()
- // syncInfo.SyncResultType = 1
- // syncInfo.SyncRsultRemark = "同步成功"
- // syncInfo.SyncTotalNum = 0
- // syncInfo.SyncSuccessNum = 0
- // syncInfo.SyncInfo = ""
- // syncInfo.CreateTime = time.Now().Unix()
- // syncInfo.UpdateTime = time.Now().Unix()
- //
- // cwderr := CreateSyncInfo(&syncInfo)
- // if cwderr != nil {
- // utils.ErrorLog("创建同步信息失败:%v", cwderr)
- // return
- // }
- // SyncToGzkytx()
- // return
- //}
- //
- //// func deleteMid(tx *gorm.DB) (err error) {
- //// err = tx.Exec("UPDATE sgj_xt.xt_drug_cancel_stock as t," +
- //// "(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
- //// "(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_cancel_stock WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
- //// "WHERE t1.user_org_id = t2.orgid)tmp " +
- //// "SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
- //// "WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
- //// return
- //// }
- //
- //func SyncToGzkytx() {
- //
- // utils.TraceLog("检验检查同步任务开始执行")
- // org_id := int64(10567)
- //
- // // 第一步:跟进org_id 去中间库查出需要同步的数据
- // //inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
- // inspections, _ := GetSyncInspectionByOrgId(org_id)
- //
- // // 第二步:将数据同步到业务库
- // //if len(inspection_references) > 0 {
- // // for _, inspection_reference := range inspection_references {
- // // SyncInspectionReference(&inspection_reference)
- // // }
- // //}
- //
- // if len(inspections) > 0 {
- // for _, inspection := range inspections {
- // if inspection.SysProjectId > 0 && inspection.SysItemId > 0 {
- // SyncGzkyInspection(&inspection)
- // }
- // }
- // }
- // utils.SuccessLog("检验检查同步任务完成")
- //}
- //
- //// 从机构将数据同步到中间库
- //func SyncGzkyInspection(data *models.MiddleInspection) error {
- // tx := writeDb.Begin()
- // var inspection models.Inspection
- // var total int
- // err = readDb.Model(&models.Inspection{}).Where("org_id = ? and project_id = ? and item_id = ? and patient_id =? and inspect_date=? and status = 1", data.OrgId, data.ProjectId, data.ItemId, data.PatientId, data.RecordDate).Find(&inspection).Count(&total).Error
- // if total <= 0 {
- //
- // inspection.OrgId = data.OrgId
- // inspection.PatientId = data.PatientId
- // inspection.ProjectName = data.ProjectName
- // // inspection.Project = data.ProjectName
- // inspection.ProjectId = data.SysProjectId
- // inspection.ItemName = data.ItemName
- // inspection.ItemId = data.SysItemId
- // inspection.InspectType = int64(data.InspectType)
- // inspection.InspectValue = data.InspectValue
- // inspection.InspectTips = data.InspectTips
- // inspection.InspectDate = data.RecordDate
- // inspection.Status = 1
- // inspection.CreatedTime = time.Now().Unix()
- // inspection.UpdatedTime = time.Now().Unix()
- //
- // err := tx.Model(&models.Inspection{}).Create(&inspection).Error
- // if err != nil {
- // tx.Rollback()
- // }
- //
- // data.IsSync = 1
- // data.SyncId = inspection.ID
- // data.UpdatedTime = time.Now().Unix()
- // ierr := writeMiddleDb.Save(&data).Error
- // if ierr != nil {
- // tx.Rollback()
- // }
- // }
- // tx.Commit()
- // return err
- //}
|