123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846 |
- package service
-
- import (
- "IC/models"
- "IC/utils"
- _ "IC/utils"
- _"bytes"
- _"encoding/json"
- _ "encoding/json"
- _"encoding/xml"
- _"fmt"
- _"net/http"
- _"io/ioutil"
- _ "github.com/jinzhu/gorm"
- "strconv"
- _"strings"
- "time"
- "github.com/jinzhu/gorm"
- )
-
- type AdminUserList struct {
- Id int64 `json:"id"`
- Name string `json:"name"`
- UserType int64 `json:"user_type"`
- Status int64 `json:"status"`
- }
-
- func GetAllAdminUsers(orgId, appid int64) (list []*AdminUserList, err error) {
-
- err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.org_id=? and uar.app_id =? and ua.status=1", orgId, appid).Select("ua.id, uar.user_name as name, uar.user_type,uar.status").Scan(&list).Error
- return
- }
-
- func GetPatientInformation(id int64, orgid int64) (models.Patients, error) {
- patients := models.Patients{}
- err := XTReadDB().Where("id = ? AND user_org_id = ?", id, orgid).Find(&patients).Error
- return patients, err
- }
-
- func GetAllPatientByOrgID(orgid int64, timenow int64) (order []*models.DialysisOrder, err error) {
- err = XTReadDB().Where("user_org_id = ? AND dialysis_date = ? AND stage = 2 AND status = ?", orgid, timenow, 1).Find(&order).Error
- return order, err
- }
-
- //透析处方
- func FindPatientPrescribeById(orgID int64, patientsId int64, recordDate int64) (patient models.DialysisPrescription, err error) {
- err = readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id=? and status=1 and record_date = ? ", patientsId, orgID, recordDate).First(&patient).Error
- return
- }
-
- //透前评估
- func FindPredialysisEvaluationById(orgID int64, patientsId int64, recordDate int64) (patient models.PredialysisEvaluation, err error) {
- err = readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id=? and status=1 and assessment_date = ?", patientsId, orgID, recordDate).First(&patient).Error
- return
- }
-
- //透后评估
- func FindAssessmentAfterDislysisById(orgID int64, patientsId int64, recordDate int64) (patient models.AssessmentAfterDislysis, err error) {
- err = readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id=? and status=1 and assessment_date =?", patientsId, orgID, recordDate).First(&patient).Error
- return
- }
-
- //透析监测
- func FindAllMonitorRecord(orgID int64, patientsId int64, recordDate int64) (record []*models.MonitoringRecord, err error) {
- err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id=? and status=1 and monitoring_date = ?", patientsId, orgID, recordDate).Order("operate_time ASC").Find(&record).Error
- return
- }
-
- //临时医嘱
- func FindDoctorAdviceOrderById(orgID int64,patientId int64, recordDate int64) (patient []*models.DoctorAdvice, err error) {
- err = readDb.Model(&models.DoctorAdvice{}).
- Where("user_org_id=? and status=1 and record_date = ? and advice_type = 2 and patient_id = ?", orgID, recordDate,patientId).
- Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, single_dose, single_dose_unit, prescribing_number, prescribing_number_unit, delivery_way, execution_frequency, advice_doctor, status, created_time,updated_time, advice_affirm, remark, stop_time, stop_reason, stop_doctor, stop_state, parent_id, execution_time, execution_staff, execution_state, checker, check_state, check_time, groupno, IF(parent_id > 0, parent_id, id) as advice_order").Order("start_time asc, groupno desc, advice_order desc, id asc").
- Find(&patient).Error
- return
- }
-
-
- func BatchCreateRecord(ps *models.EmrBloodDialyRecord, rdb *gorm.DB) (err error) {
- err = rdb.Create(&ps).Error
- return err
- }
-
- func BatchCreateDetail(ps *models.EmrBloodDialyDetail, rdb *gorm.DB) (err error) {
- err = rdb.Create(&ps).Error
- return err
- }
-
- func BatchCreateOrder(ps *models.EmrBloodDialyOrder, rdb *gorm.DB) (err error) {
- err = rdb.Create(&ps).Error
- return err
- }
-
- // 潍坊内分泌医院 同步健康数据上报
- func EmrBloodDiaylOrder() {
- org := &models.DataUploadConfig{
- DbHost: "127.0.0.1",
- DbPort: "1433",
- DbPass: "Aa123456",
- DbUser: "xtzk",
- DbName: "wfnfm",
- }
-
- if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
- orgDb, err := CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
- if err != nil {
- utils.ErrorLog("创建数据库连接失败:%v", err)
- return
- }
-
- // 第二步:获取上一次同步的时间点
- syncLastInfo, _ := GetSyncTimeByOrgIDForYs(1041401)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime + 86400
- } else {
- sync_time = 1664553600
- }
- adminUser, _ := GetAllAdminUsers(10414, 15102)
- nowTimes := time.Now().Unix()
- if sync_time < nowTimes {
- for i := sync_time; i < nowTimes; i = i + 86400 {
- tempsyncTimes := time.Unix(i, 0).Format("2006-01-02")
- timeLayout := "2006-01-02 15:04:05"
- timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, tempsyncTimes+" 00:00:00")
- timenow := timeStringToTime.Unix()
- orders,_ := GetAllPatientByOrgID(10414,timenow)
- if len(orders) > 0 {
- for _, order := range orders {
-
- //查询病人信息
- patients, _ := GetPatientInformation(order.PatientId, 10414)
-
- Records, _ := FindDoctorAdviceOrderById(10414,order.PatientId,timenow)
- if len(Records) > 0 {
- for _,record := range Records {
- emrDetail := &models.EmrBloodDialyOrder{
- ReqNo : patients.DialysisNo,
- OrderType : "1",
- OrderDate : time.Unix(record.StartTime, 0).Format("2006-01-02 15:04:05"),
- OrderName : record.AdviceName,
- Dosage : strconv.FormatFloat(record.PrescribingNumber, 'f', 1, 32)+record.PrescribingNumberUnit,
- Usage : record.DeliveryWay,
- ExecDate : time.Unix(record.ExecutionTime, 0).Format("2006-01-02 15:04:05"),
- Orglevel : "二级",
- Submitdate : time.Unix(record.CreatedTime, 0).Format("2006-01-02 15:04:05"),
- Recordstate : "0",
- Fectchdate : time.Unix(order.CreatedTime, 0).Format("2006-01-02 15:04:05"),
- OrganizationCode : "",
- OrganizationName : "",
- DistrictCode : "370724",
- DistrictName : "临朐县",
- Uploadmark : "0",
- }
- for _, admin := range adminUser {
- if record.AdviceDoctor == admin.Id {
- emrDetail.DoctorName = admin.Name
- }
- if record.ExecutionStaff == admin.Id{
- emrDetail.NurseName = admin.Name
- }
- }
-
- currentYear := time.Now().Year() //当前年
- emrDetail.Businessyear = int64(currentYear)
- BatchCreateOrder(emrDetail,orgDb)
- }
- }
- }
- var syncInfo models.MiddleSyncInfo
- syncInfo.OrgId = 1041401
-
- 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
- }
- }
- }
- }
-
-
-
-
- // 第四步:关闭数据库连接
- CloseDB(orgDb)
- }
- }
-
- // 潍坊内分泌医院 同步健康数据上报
- func EmrBloodDiaylDetail() {
- org := &models.DataUploadConfig{
- DbHost: "localhost",
- DbPort: "1433",
- DbPass: "Aa123456",
- DbUser: "xtzk",
- DbName: "wfnfm",
- }
-
- if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
- orgDb, err := CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
- if err != nil {
- utils.ErrorLog("创建数据库连接失败:%v", err)
- return
- }
- // 第二步:获取上一次同步的时间点
- syncLastInfo, _ := GetSyncTimeByOrgIDForYs(1041402)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime + 86400
- } else {
- sync_time = 1664553600
- }
-
- nowTimes := time.Now().Unix()
- if sync_time < nowTimes {
- for i := sync_time; i < nowTimes; i = i + 86400 {
- tempsyncTimes := time.Unix(i, 0).Format("2006-01-02")
- timeLayout := "2006-01-02 15:04:05"
- timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, tempsyncTimes+" 00:00:00")
- timenow := timeStringToTime.Unix()
-
- orders,_ := GetAllPatientByOrgID(10414,timenow)
- if len(orders) > 0 {
- for _, order := range orders {
-
- //查询病人信息
- patients, _ := GetPatientInformation(order.PatientId, 10414)
-
- Records, _ := FindAllMonitorRecord(10414, order.PatientId, timenow)
- if len(Records) > 0 {
- for _,record := range Records {
- emrDetail := &models.EmrBloodDialyDetail{
- ReqNo : patients.DialysisNo,
- Patientname : patients.Name,
- Idcard : patients.IdCardNo,
- Hospitalcode : "MA3R6UFL9",
- Hospitalname : "潍坊内分泌与代谢病医院",
- BdDate : time.Unix(record.MonitoringDate, 0).Format("2006-01-02") + " " + record.MonitoringTime ,
- BdBp : strconv.FormatFloat(record.SystolicBloodPressure, 'f', 1, 32) + "/" + strconv.FormatFloat(record.DiastolicBloodPressure, 'f', 1, 32),
- BdT : record.DialysateTemperature,
- BdRate : record.PulseFrequency,
- BdFlow : record.BloodFlowVolume,
- BdVbp : record.VenousPressure,
- BdTmp : record.TransmembranePressure,
- BdUfvLimit : record.UltrafiltrationVolume,
- Orglevel : "二级",
- Submitdate : time.Unix(record.CreatedTime, 0).Format("2006-01-02 15:04:05"),
- Recordstate : "0",
- Fectchdate : time.Unix(order.CreatedTime, 0).Format("2006-01-02 15:04:05"),
- OrganizationCode : "",
- OrganizationName : "",
- DistrictCode : "370724",
- DistrictName : "临朐县",
- Uploadmark : "0",
- }
- currentYear := time.Now().Year() //当前年
- emrDetail.Businessyear = int64(currentYear)
- BatchCreateDetail(emrDetail,orgDb)
- }
- }
- }
- var syncInfo models.MiddleSyncInfo
- syncInfo.OrgId = 1041402
-
- 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
- }
- }
- }
- }
- // 第四步:关闭数据库连接
- CloseDB(orgDb)
- }
- }
-
- // 潍坊内分泌医院 同步健康数据上报
- func EmrBloodDiaylRecord() {
- org := &models.DataUploadConfig{
- DbHost: "localhost",
- DbPort: "1433",
- DbPass: "Aa123456",
- DbUser: "xtzk",
- DbName: "wfnfm",
- }
-
- if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
- orgDb, err := CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
- if err != nil {
- utils.ErrorLog("创建数据库连接失败:%v", err)
- return
- }
- adminUser, _ := GetAllAdminUsers(10414, 15102)
-
- // 第二步:获取上一次同步的时间点
- syncLastInfo, _ := GetSyncTimeByOrgIDForYs(1041403)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime + 86400
- } else {
- sync_time = 1664553600
- }
-
- nowTimes := time.Now().Unix()
- if sync_time < nowTimes {
- for i := sync_time; i < nowTimes; i = i + 86400 {
- tempsyncTimes := time.Unix(i, 0).Format("2006-01-02")
- timeLayout := "2006-01-02 15:04:05"
-
- timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, tempsyncTimes+" 00:00:00")
- timenow := timeStringToTime.Unix()
-
- orders,_ := GetAllPatientByOrgID(10414,timenow)
- if len(orders) > 0 {
- for _, order := range orders {
-
- //查询病人信息
- patients, _ := GetPatientInformation(order.PatientId, 10414)
- //透析处方
- dialysisPrescription, _ := FindPatientPrescribeById(10414, order.PatientId, timenow)
- //透前评估
- PredialysisEvaluation, _ := FindPredialysisEvaluationById(10414, order.PatientId, timenow)
- //透后评估
- AssessmentAfterDislysis, _ := FindAssessmentAfterDislysisById(10414, order.PatientId, timenow)
-
- emrRecord := &models.EmrBloodDialyRecord{
- ReqNo : patients.DialysisNo,
- Patientname : patients.Name,
- Idcard : patients.IdCardNo,
- Hospitalcode : "MA3R6UFL9",
- Hospitalname : "潍坊内分泌与代谢病医院",
- AdmissionId : patients.IdCardNo,
- BdDate : time.Unix(order.DialysisDate, 0).Format("2006-01-02"),
- BdMatno : dialysisPrescription.DialyzerPerfusionApparatus,
- Temperature : PredialysisEvaluation.Temperature,
- PulseRate : PredialysisEvaluation.PulseFrequency,
- BreathingRate : PredialysisEvaluation.BreathingRate,
- PressureH : PredialysisEvaluation.SystolicBloodPressure,
- PressureL : PredialysisEvaluation.DiastolicBloodPressure,
- UfvLimit : dialysisPrescription.DewaterAmount*1000,
- FirstAnticoagulant : dialysisPrescription.AnticoagulantShouji,
- BdHours : AssessmentAfterDislysis.ActualTreatmentHour,
- BdType : dialysisPrescription.ModeId,
- BdT : 36.5,
- AnticoagulantTotal : dialysisPrescription.AnticoagulantZongliang,
- BdCruorContiton : "2",
- PatientWeight : PredialysisEvaluation.DryWeight,
- WeightBf : PredialysisEvaluation.WeightBefore,
- WeightAf : AssessmentAfterDislysis.WeightAfter,
- WeightBalan : PredialysisEvaluation.WeightBefore - PredialysisEvaluation.WeightBefore,
- Vascular : "2",
- Orglevel : "二级",
- Submitdate : time.Unix(order.CreatedTime, 0).Format("2006-01-02 15:04:05"),
- Recordstate : "0",
- Fectchdate : time.Unix(order.CreatedTime, 0).Format("2006-01-02 15:04:05"),
- OrganizationCode : "",
- OrganizationName : "",
- DistrictCode : "370724",
- DistrictName : "临朐县",
- Uploadmark : "0",
- }
-
- for _, admin := range adminUser {
- if dialysisPrescription.Creater == admin.Id {
- emrRecord.DoctorName = admin.Name
- }
- if order.StartNurse == admin.Id{
- emrRecord.OperName = admin.Name
- emrRecord.PrimaryName = admin.Name
- }
- }
-
- if(patients.Gender == 1){
- emrRecord.SexCode = "1"
- emrRecord.SexName = "男"
- }
- if(patients.Gender == 2){
- emrRecord.SexCode = "2"
- emrRecord.SexName = "女"
- }
-
- currentYear := time.Now().Year() //当前年
- birthYear := time.Unix(patients.Birthday, 0).Year()
- emrRecord.Businessyear = int64(currentYear)
- emrRecord.Age = int64(currentYear) - int64(birthYear)
- switch dialysisPrescription.Anticoagulant {
- case 1:
- emrRecord.Anticoagulant = "无肝素"
- break
- case 2:
- emrRecord.Anticoagulant = "普通肝素"
- break
- case 3:
- emrRecord.Anticoagulant = "低分子肝素"
- break
- case 4:
- emrRecord.Anticoagulant = "阿加曲班"
- break
- case 5:
- emrRecord.Anticoagulant = "枸橼酸钠"
- break
- case 6:
- emrRecord.Anticoagulant = "低分子肝素钙"
- break
- case 7:
- emrRecord.Anticoagulant = "低分子肝素钠"
- break
- }
-
- switch dialysisPrescription.ModeId {
- case 1:
- emrRecord.BdTypeName = "HD"
- break
- case 2:
- emrRecord.BdTypeName = "HDF"
- break
- case 3:
- emrRecord.BdTypeName = "HD+HP"
- break
- case 4:
- emrRecord.BdTypeName = "HP"
- break
- case 5:
- emrRecord.BdTypeName = "HF"
- break
- case 6:
- emrRecord.BdTypeName = "SCUF"
- break
- case 7:
- emrRecord.BdTypeName = "IUF"
- break
- case 8:
- emrRecord.BdTypeName = "HFHD"
- break
- case 9:
- emrRecord.BdTypeName = "HFHD+HP"
- break
- case 10:
- emrRecord.BdTypeName = "PHF"
- break
- case 11:
- emrRecord.BdTypeName = "HFR"
- break
- case 12:
- emrRecord.BdTypeName = "HDF+HP"
- break
- default:
- emrRecord.BdTypeName = "HD"
- break
- }
-
- if AssessmentAfterDislysis.Cruor == "透析器-0度" || len(AssessmentAfterDislysis.Cruor) <= 0{
- emrRecord.BdCruor = "2"
- emrRecord.BdCruorName = "无凝血"
- } else {
- emrRecord.BdCruor = "1"
- emrRecord.BdCruorName = "有凝血"
- }
-
- BatchCreateRecord(emrRecord,orgDb)
- }
-
- var syncInfo models.MiddleSyncInfo
- syncInfo.OrgId = 1041403
-
- 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
- }
- }
- }
- }
- // 第四步:关闭数据库连接
- CloseDB(orgDb)
- }
- }
-
- // 福建天福医院透析中心Lis同步
- // func SyncFjtfLis() (err error) {
- // org_id := int64(10330)
-
- // // 第一步:获取上一次同步的时间点
- // syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
- // var sync_time int64
- // if syncLastInfo.ID > 0 {
- // sync_time = syncLastInfo.SyncTime
- // } else {
- // sync_time = 1651334400 // 2022-05-01 00:00:00
- // }
-
- // sync_time_temp := time.Unix(sync_time,0)
- // syncTimeStr := sync_time_temp.Format("2006-01-02 15:04:05")
- // // 第二步:获取所有患者的病历号
-
- // patientList, _ := GetPatientGzjhByOrgId(org_id)
- // if len(patientList) > 0 {
- // for _, patient := range patientList {
- // if len(patient.IdCardNo) > 0 || len(patient.DialysisNo) > 0 {
- // patient_id := patient.ID
- // utils.InfoLog("IdCardNo:%v", patient.IdCardNo)
- // // utils.InfoLog("VipStr:%v", VipStr)
-
- // result, _ := FjtjGetLab(patient.IdCardNo,syncTimeStr)
- // var fjtfLab LabResult
- // if err := json.Unmarshal([]byte(result), &fjtfLab); err != nil {
- // utils.ErrorLog("解析失败:%v", err)
- // }
- // fmt.Println(fjtfLab)
-
- // if len(fjtfLab.Result) > 0 {
- // // 根据获取的头部lab01获取检查结果
-
- // for _, info := range fjtfLab.Result {
- // lacResult, _ := FjtjGetLac(info.Lab01)
- // var fjtfLac LacResult
- // if err := json.Unmarshal([]byte(lacResult), &fjtfLac); err != nil {
- // utils.ErrorLog("解析失败:%v", err)
- // }
- // fmt.Println(fjtfLac)
- // for _,cinfo := range fjtfLac.Result{
- // project_id := int64(0)
- // item_id := int64(0)
- // if len(cinfo.Bbx05a) > 0 {
- // project_id, _ = GetfjtfProjectID(org_id, cinfo.Bbx05a)
- // item_id, _ = GetFjtfItemID(org_id, cinfo.Bbx05a, cinfo.Bbx05, project_id)
- // } else {
- // project_id, _ = GetfjtfProjectID(org_id, cinfo.Bbx05)
- // item_id, _ = GetFjtfItemID(org_id, cinfo.Bbx05, cinfo.Bbx05, project_id)
- // }
-
-
- // tx := writeMiddleDb.Begin()
- // var inspection models.MiddleInspection
- // var inspection_reference models.MiddleInspectionReference
-
-
- // loc, _ := time.LoadLocation("Local")
- // theTime, _ := time.ParseInLocation("2006-01-02 15:04:05", cinfo.Lac25, loc)
- // record_date := theTime.Unix()
-
- // if record_date == 0 {
- // record_date = time.Now().Unix()
- // }
-
- // inspect_date := time.Unix(record_date, 0).Format("2006-01-02 15:04")
- // var total int
- // var RangeOptions string
- // var RangeMin string
- // var RangeMax string
-
- // // // 判断检查类型
- // ItemType := 1
- // Range := strings.Split(cinfo.Lac15, "-")
- // if len(Range) > 1 {
- // RangeMin = cinfo.Lac13
- // RangeMax = cinfo.Lac14
- // ItemType = 1
- // } else {
- // ItemType = 2
- // RangeOptions = cinfo.Lac15
- // }
-
- // 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 inspection_reference.ID > 0 {
- // // ItemType = int64(inspection_reference.RangeType)
- // // }
-
- // if total <= 0 {
- // inspection_reference.OrgId = org_id
- // if len(cinfo.Bbx05a) > 0 {
- // inspection_reference.ProjectName = cinfo.Bbx05a
- // inspection_reference.Project = cinfo.Bbx05a
- // } else {
- // inspection_reference.ProjectName = cinfo.Bbx05
- // inspection_reference.Project = cinfo.Bbx05
- // }
- // inspection_reference.ProjectId = project_id
- // inspection_reference.ItemName = cinfo.Bbx05
- // inspection_reference.ItemId = item_id
- // inspection_reference.RangeType = ItemType
- // inspection_reference.RangeMin = RangeMin
- // inspection_reference.RangeMax = RangeMax
- // // inspection_reference.RangeValue = RangeValue
- // inspection_reference.RangeOptions = RangeOptions
- // inspection_reference.Unit = cinfo.Bdg02
- // 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
- // 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, record_date, patient_id).Find(&inspection).Count(&itotal).Error
- // if itotal <= 0 {
- // 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 = cinfo.Lac10
- // inspection.InspectDate = inspect_date
- // inspection.RecordDate = record_date
- // inspection.InspectTips = cinfo.Lac11
- // inspection.Status = 1
- // inspection.CreatedTime = time.Now().Unix()
- // inspection.UpdatedTime = time.Now().Unix()
- // inspection.UTime = inspect_date
- // inspection.HisUserId = strconv.FormatInt(patient_id, 10)
- // 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
- // }
- // SyncToFjtftx()
- // return
- // }
-
- // type LabResult struct {
- // Msg string `json:"msg"`
- // Result []struct {
- // Lab01 int64 `json:"lab01"`
- // Lab58 string `json:"lab58"`
- // } `json:"result"`
- // Code string `json:"code"`
- // }
-
- // func FjtjGetLab(id_card_no string, synctime string) (string, string) {
- // inputData := make(map[string]interface{})
-
- // inputData["vaa15"] = id_card_no
- // inputData["begintime"] = synctime
-
- // var inputLog string
- // bytesData, err := json.Marshal(inputData)
- // inputLog = string(bytesData)
- // fmt.Println(string(bytesData))
- // if err != nil {
- // fmt.Println(err.Error())
- // return err.Error(), ""
- // }
- // reader := bytes.NewReader(bytesData)
- // url := "http://hip.zptfyy.com/esb/listener/getLab1"
-
- // request, err := http.NewRequest("POST", url, reader)
- // if err != nil {
- // fmt.Println(err.Error())
- // return err.Error(), ""
- // }
-
- // request.Header.Set("Content-Type", "application/json;charset=UTF-8")
- // request.Header.Set("code", "xt")
-
- // client := http.Client{}
- // resp, err := client.Do(request)
- // if err != nil {
- // fmt.Println(err.Error())
- // return err.Error(), ""
- // }
- // respBytes, err := ioutil.ReadAll(resp.Body)
- // if err != nil {
- // fmt.Println(err.Error())
- // return err.Error(), ""
- // }
- // str := string(respBytes)
- // return str, inputLog
- // }
-
- // type LacResult struct {
- // Msg string `json:"msg"`
- // Result []struct {
- // Lab01 int64 `json:"labo1"`
- // Bbx05 string `json:"BBX05"`
- // Bbx05a string `json:"BBX05A"`
- // Bfc03 string `json:"BFC03"`
- // Bdg02 string `json:"BDG02"`
- // Lac10 string `json:"LAC10"`
- // Lac11 string `json:"LAC11"`
- // Lac13 string `json:"LAC13"`
- // Lac14 string `json:"LAC14"`
- // Lac15 string `json:"LAC15"`
- // Lac25 string `json:"LAC25"`
- // } `json:"result"`
- // Code string `json:"code"`
- // }
-
- // func FjtjGetLac(lab01 int64) (string, string) {
- // inputData := make(map[string]interface{})
-
- // inputData["lab01"] = lab01
-
- // var inputLog string
- // bytesData, err := json.Marshal(inputData)
- // inputLog = string(bytesData)
- // fmt.Println(string(bytesData))
- // if err != nil {
- // fmt.Println(err.Error())
- // return err.Error(), ""
- // }
- // reader := bytes.NewReader(bytesData)
- // url := "http://hip.zptfyy.com/esb/listener/getLac1"
-
- // request, err := http.NewRequest("POST", url, reader)
- // if err != nil {
- // fmt.Println(err.Error())
- // return err.Error(), ""
- // }
-
- // request.Header.Set("Content-Type", "application/json;charset=UTF-8")
- // request.Header.Set("code", "xt")
-
- // client := http.Client{}
- // resp, err := client.Do(request)
- // if err != nil {
- // fmt.Println(err.Error())
- // return err.Error(), ""
- // }
- // respBytes, err := ioutil.ReadAll(resp.Body)
- // if err != nil {
- // fmt.Println(err.Error())
- // return err.Error(), ""
- // }
- // str := string(respBytes)
- // return str, inputLog
- // }
-
- // 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
- // func GetfjtfProjectID(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 330001, err
- // }
- // }
- // }
-
- // 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
- // func GetFjtfItemID(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
- // }
- // }
- // }
-
-
- // func SyncToFjtftx() {
- // utils.TraceLog("检验检查同步任务开始执行")
- // org_id := int64(10330)
-
- // // 第一步:跟进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 {
- // SyncInspection(&inspection)
- // }
- // }
- // utils.SuccessLog("检验检查同步任务完成")
- // }
|