123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774 |
- package service
-
- import (
- "IC/models"
- _ "IC/models"
- "IC/utils"
- "bytes"
- "encoding/json"
- _ "encoding/json"
- _ "encoding/xml"
- "fmt"
- _ "github.com/jinzhu/gorm"
- "io/ioutil"
- "net/http"
- "strconv"
- "strings"
- "time"
- )
-
- func GetbjncProjectID(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 = ?", org_id, project_name).First(&inspection_reference).Error
- if inspection_reference.ID > 0 {
- return inspection_reference.ProjectId, err
- } else {
- err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project = ? ", 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 1060601, err
- }
- }
- }
- }
-
- // 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
- func GetbjncItemID(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 = ? 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
- }
- }
- }
-
- // 北京南诚中西医结合医院Lis同步
- func SyncBjncLis() (err error) {
- org_id := int64(10606)
-
- // 第一步:获取上一次同步的时间点
- syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime - 60*60*6
- } else {
- sync_time = 1714492800
- }
-
- loc, _ := time.LoadLocation("Local") //重要:获取时区
- sync_time_temp := time.Unix(sync_time, 0)
- startTimeStr := sync_time_temp.Format("2006-01-02 15:04:05")
- end_time := time.Now().Unix()
- end_time_temp := time.Unix(end_time, 0)
- endTimeStr := end_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("startTimeStr:%v", startTimeStr)
- // utils.InfoLog("VipStr:%v", VipStr)
- // 跟进身份证获取patientID
- patientList, _ := BjncGetPatientInfo(patient.IdCardNo, endTimeStr)
-
- var bjncPatient BjncPatientInfo
- if err := json.Unmarshal([]byte(patientList), &bjncPatient); err != nil {
- utils.ErrorLog("解析失败:%v", err)
- }
-
- utils.InfoLog("patientId:%v", bjncPatient.Result[0].Patientid)
-
- reportList, _ := BjncGetLisReport(bjncPatient.Result[0].Patientid, startTimeStr, endTimeStr)
- var lisReport BjncLisReport
- if err := json.Unmarshal([]byte(reportList), &lisReport); err != nil {
- utils.ErrorLog("解析失败:%v", err)
- }
- utils.InfoLog("reportList:%v", lisReport)
-
- if len(lisReport.Result) > 0 {
- for _, linfo := range lisReport.Result {
- infoReprot, _ := BjncGetReportInfo(linfo.Reportno, startTimeStr, endTimeStr)
- var reportInfo ReportDetail
- if err := json.Unmarshal([]byte(infoReprot), &reportInfo); err != nil {
- utils.ErrorLog("解析失败:%v", err)
- }
-
- for _, ivalue := range reportInfo.Result {
- theTime, _ := time.ParseInLocation("2006-01-02 15:04:05", ivalue.Testtime, loc) //使用模板在对应时区转化为time.time类型
- start_temp_Time := theTime.Format("2006-01-02 15:04")
- SxTime, _ := time.ParseInLocation("2006-01-02 15:04", start_temp_Time, loc)
- start_time := SxTime.Unix()
-
- project_id, _ := GetbjncProjectID(org_id, ivalue.Combinationname)
- item_id, _ := GetbjncItemID(org_id, ivalue.Combinationname, ivalue.Itemname, project_id)
- tx := writeMiddleDb.Begin()
- var inspection models.MiddleInspection
- var inspection_reference models.MiddleInspectionReference
-
- var total int
- var RangeOptions string
- var RangeMin string
- var RangeMax string
- var ItemType int
- Range := strings.Split(ivalue.Referscope, "-")
- if len(Range) > 1 {
- RangeMin = Range[0]
- RangeMax = Range[1]
- ItemType = 1
- } else {
- ItemType = 2
- RangeOptions = ivalue.Referscope
- }
-
- 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 = ivalue.Combinationname
- inspection_reference.Project = ivalue.Combinationname
- inspection_reference.ProjectId = project_id
- inspection_reference.ItemName = ivalue.Itemname
- // inspection_reference.ItemNameAddition = strconv.FormatInt(info.ItemId, 10)
- 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 = ivalue.Unit
- inspection_reference.Status = 1
- inspection_reference.CreatedTime = time.Now().Unix()
- inspection_reference.UpdatedTime = time.Now().Unix()
- inspection_reference.InspectDate = ivalue.Testtime
- inspection_reference.UTime = ivalue.Testtime
- 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, start_time, 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 = ivalue.Itemreportresult
- inspection.InspectDate = start_temp_Time
- inspection.RecordDate = start_time
- // inspection.InspectTips = report.Resultstate
- 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)
- 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 BjncPatientInfo struct {
- Msg string `json:"msg"`
- Code string `json:"code"`
- Result []struct {
- Patientid int64 `json:"patientId"`
- Visitid int64 `json:"visitId"`
- Outpatientno string `json:"outPatientNo"`
- Patientname string `json:"patientName"`
- Idcardno string `json:"idCardNo"`
- } `json:"result"`
- }
-
- func BjncGetPatientInfo(id_card_no string, endTime string) (string, string) {
- // 1.生成签名sign
- var sync_time int64
- sync_time = 1690819200 // 2023-08-01 00:00:00
- sync_time_temp := time.Unix(sync_time, 0)
- startTimeStr := sync_time_temp.Format("2006-01-02 15:04:05")
- signData := make(map[string]interface{})
- //signData["dateType"] = "07"
- signData["startTime"] = startTimeStr
- signData["idCardNo"] = id_card_no
- signData["endTime"] = endTime
- bytesData, _ := json.Marshal(signData)
- inputLog := string(bytesData)
- signStr := "body=" + inputLog + "&operUserCode=100&serv=getRegisterInfo&key=A3195B3D179B01F66C86703E0890A95F"
- signTemp := utils.String2md5(signStr)
- sign := strings.ToUpper(signTemp)
-
- // 2.请求参数
- inputData := make(map[string]interface{})
- inputData["body"] = signData
- inputData["serv"] = "getRegisterInfo"
- inputData["operUserCode"] = "100"
- inputData["sign"] = sign
-
- postData, err := json.Marshal(inputData)
- postStr := string(postData)
- utils.InfoLog("1111111111:%v", postStr)
- if err != nil {
- fmt.Println(err.Error())
- return err.Error(), ""
- }
-
- reader := bytes.NewReader(postData)
- url := "http://123.127.8.35:18090/esb/listener/openapi/StandardInterface"
-
- 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", "XTXT")
-
- 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)
- utils.InfoLog("22222222:%v", str)
- return str, inputLog
- }
-
- type BjncLisReport struct {
- Code string `json:"code"`
- Msg string `json:"msg"`
- Result []struct {
- Patientid string `json:"patientId"`
- Patientname string `json:"patientName"`
- Reportno int64 `json:"reportNo"`
- Visitid string `json:"visitId"`
- Applydeptname string `json:"applyDeptName"`
- Reportname string `json:"reportName"`
- } `json:"result"`
- }
-
- func BjncGetLisReport(id_card_no int64, startTime string, endTime string) (string, string) {
- // 1.生成签名sign
- signData := make(map[string]interface{})
- signData["patientId"] = strconv.FormatInt(id_card_no, 10)
- signData["dateType"] = "16"
- signData["startTime"] = startTime
- signData["endTime"] = endTime
- bytesData, _ := json.Marshal(signData)
- inputLog := string(bytesData)
- signStr := "body=" + inputLog + "&operUserCode=100&serv=getLisReport&key=A3195B3D179B01F66C86703E0890A95F"
- signTemp := utils.String2md5(signStr)
- sign := strings.ToUpper(signTemp)
-
- // 2.请求参数
- inputData := make(map[string]interface{})
- inputData["body"] = signData
- inputData["serv"] = "getLisReport"
- inputData["operUserCode"] = "100"
- inputData["sign"] = sign
-
- postData, err := json.Marshal(inputData)
- postStr := string(postData)
- utils.InfoLog("1111111111:%v", postStr)
- if err != nil {
- fmt.Println(err.Error())
- return err.Error(), ""
- }
-
- reader := bytes.NewReader(postData)
- url := "http://123.127.8.35:18090/esb/listener/openapi/StandardInterface"
-
- 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", "XTXT")
-
- 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)
- utils.InfoLog("22222222:%v", str)
- return str, inputLog
- }
-
- type ReportDetail struct {
- Msg string `json:"msg"`
- Code string `json:"code"`
- Result []struct {
- Detailid string `json:"detailId"`
- Reportno string `json:"reportNo"`
- Testtime string `json:"testTime"`
- Combinationcode string `json:"combinationCode"`
- Combinationname string `json:"combinationName"`
- Itemcode string `json:"itemCode"`
- Itemname string `json:"itemName"`
- Abbreviation string `json:"abbreviation"`
- Itemreportresult string `json:"itemReportResult"`
- Unit string `json:"unit"`
- Resultpoint string `json:"resultPoint"`
- Rownr string `json:"rownr"`
- Referlow string `json:"referLow"`
- Referhigh string `json:"referHigh"`
- Referscope string `json:"referScope"`
- Low string `json:"low"`
- High string `json:"high"`
- } `json:"result"`
- }
-
- func BjncGetReportInfo(report_no int64, startTime string, endTime string) (string, string) {
- // 1.生成签名sign
- signData := make(map[string]interface{})
- signData["reportNo"] = strconv.FormatInt(report_no, 10)
- signData["dateType"] = "16"
- signData["startTime"] = startTime
- signData["endTime"] = endTime
- bytesData, _ := json.Marshal(signData)
- inputLog := string(bytesData)
- signStr := "body=" + inputLog + "&operUserCode=100&serv=getLisReportDetail&key=A3195B3D179B01F66C86703E0890A95F"
- signTemp := utils.String2md5(signStr)
- sign := strings.ToUpper(signTemp)
-
- // 2.请求参数
- inputData := make(map[string]interface{})
- inputData["body"] = signData
- inputData["serv"] = "getLisReportDetail"
- inputData["operUserCode"] = "100"
- inputData["sign"] = sign
-
- postData, err := json.Marshal(inputData)
- postStr := string(postData)
- utils.InfoLog("1111111111:%v", postStr)
- if err != nil {
- fmt.Println(err.Error())
- return err.Error(), ""
- }
-
- reader := bytes.NewReader(postData)
- url := "http://123.127.8.35:18090/esb/listener/openapi/StandardInterface"
-
- 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", "XTXT")
-
- 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)
- utils.InfoLog("22222222:%v", str)
- return str, inputLog
- }
-
- func SyncBjncHis() (err error) {
- org_id := int64(10606)
- redisClient := RedisClient()
- defer redisClient.Close()
-
- // 第一步:获取上一次同步的时间点
- sync_time_tt, _ := redisClient.Get("bjncyyyy_sync_time").Result()
-
- sync_time, _ := strconv.ParseInt(sync_time_tt, 10, 64)
-
- if sync_time == 0 {
- sync_time = time.Now().Unix() - 60*60*10
- //sync_time = 1719763200
- }
-
- loc, _ := time.LoadLocation("Local") //重要:获取时区
- sync_time_temp := time.Unix(sync_time, 0)
- startTimeStr := sync_time_temp.Format("2006-01-02 15:04:05")
- end_time := time.Now().Unix()
- end_time_temp := time.Unix(end_time, 0)
- endTimeStr := end_time_temp.Format("2006-01-02 15:04:05")
-
- new_sync_time := time.Now().Unix() - 60*60
- redisClient.Set("bjncyyyy_sync_time", new_sync_time, time.Minute*60*24)
- // 第二步:获取所有患者的病历号
-
- 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, _ := BjncGetHis(patient.IdCardNo, startTimeStr, endTimeStr)
- var bjncHis BjncHis
- if err := json.Unmarshal([]byte(result), &bjncHis); err != nil {
- utils.ErrorLog("解析失败:%v", err)
- }
- fmt.Println(bjncHis)
- for _, cinfo := range bjncHis.Result {
- fmt.Println(cinfo.Patientid)
- // 查询该患者当天是否有排班信息
-
- STime, _ := time.ParseInLocation("2006-01-02 15:04:05", cinfo.Itemeffectivetimelow, loc) //使用模板在对应时区转化为time.time类型
- formattedTime := STime.Format("2006-01-02")
- StTime, _ := time.ParseInLocation("2006-01-02", formattedTime, loc)
- schedulesTime := StTime.Unix()
-
- theTime, _ := time.ParseInLocation("2006-01-02 15:04:05", cinfo.Itemeffectivetimelow, loc) //使用模板在对应时区转化为time.time类型
- start_temp_Time := theTime.Format("2006-01-02 15:04")
- SxTime, _ := time.ParseInLocation("2006-01-02 15:04", start_temp_Time, loc)
- start_time := SxTime.Unix()
- utils.InfoLog("start_time:%v", start_time)
-
- schedulesInfo, _ := GetSchedulesByPatientID(org_id, schedulesTime, patient.ID)
- if schedulesInfo.ID > 0 {
- start_time = theTime.Unix()
- } else {
- continue
- }
-
- // 根据同步来的 advice_id 来查询库里是否已经存在
- advice_info, _ := GetAdviceBySyncAdviceIdForScyyyy(org_id, cinfo.Medicaladviceid, schedulesTime, patient.ID)
- utils.InfoLog("Orderstatuscode:%v", cinfo.Orderstatuscode)
- utils.InfoLog("AdviceName:%v", cinfo.Diagproname)
- if advice_info.ID > 0 {
- if cinfo.Orderstatuscode == 4 || cinfo.Orderstatuscode == 5 {
- advice_info.Status = 0
- SaveDoctorAdviceHandle(&advice_info)
- } else {
- continue
- }
- } else {
- if cinfo.Orderstatuscode == 1 || cinfo.Orderstatuscode == 8 {
- // 根据姓名获取医生ID
- var doctor_id int64
- temp_doctor_id, _ := redisClient.Get("bjncyyyy_doctor_id_" + cinfo.Orderdoctorcode).Result()
- if len(temp_doctor_id) == 0 {
- doctor, _ := GetAdminUserId(org_id, cinfo.Orderdoctorname)
- doctor_id = doctor.AdminUserId
- if doctor_id > 0 {
- redisClient.Set("bjncyyyy_doctor_id_"+cinfo.Orderdoctorcode, doctor_id, time.Minute*60*2)
- } else {
- continue
- }
- } else {
- doctor_id, _ = strconv.ParseInt(temp_doctor_id, 10, 64)
- }
- //
- // // 根据排班班次,固定医嘱时间
-
- advice := models.XtDoctorAdvice{
- UserOrgId: org_id,
- PatientId: patient.ID,
- AdviceType: 2,
- AdviceDate: schedulesTime,
- StartTime: start_time,
- AdviceName: cinfo.Diagproname,
- RecordDate: schedulesTime,
- SingleDose: cinfo.Dosequantity,
- SingleDoseUnit: cinfo.Dosequantityunit,
- PrescribingNumber: cinfo.Amount,
- PrescribingNumberUnit: cinfo.Unit,
- DeliveryWay: cinfo.Routename,
- ExecutionFrequency: cinfo.Executefrequencyname,
- AdviceDoctor: doctor_id,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- SyncAdviceId: cinfo.Medicaladviceid,
- ExecutionState: 2,
- Status: 1,
- IsSync: 1,
- }
- utils.InfoLog("advice:%v", advice)
-
- if len(cinfo.Diagproname) > 0 {
- handleerr := CreateDoctorAdviceHandle(&advice)
- if handleerr != nil {
- utils.ErrorLog("添加医嘱信息失败:%v", handleerr)
- continue
- }
- } else {
- continue
- }
- } 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 BjncHis struct {
- Msg string `json:"msg"`
- Code string `json:"code"`
- Result []struct {
- Patientid string `json:"patientId"`
- Visitid string `json:"visitId"`
- Outpatientno string `json:"outPatientNo"`
- Patientname string `json:"patientName"`
- Idcardno string `json:"idCardNo"`
- Orderstatuscode int64 `json:"orderStatusCode"`
- Ordercreatetime string `json:"orderCreateTime"`
- Orderdoctorcode string `json:"orderDoctorCode"`
- Orderdoctorname string `json:"orderDoctorName"`
- Medicaladviceid int64 `json:"medicalAdviceId"`
- Medicalordername string `json:"medicalOrderName"`
- Itemname string `json:"itemName"`
- Itemeffectivetimelow string `json:"itemEffectiveTimeLow"`
- Executefrequencyname string `json:"executeFrequencyName"`
- Routename string `json:"routeName"`
- Dosequantity float64 `json:"doseQuantity"`
- Dosequantityunit string `json:"doseQuantityUnit"`
- Totaldosequantity float64 `json:"totalDoseQuantity"`
- Totaldosequantityunit string `json:"totalDoseQuantityUnit"`
- Diagproname string `json:"diagProName"`
- Amount float64 `json:"amount"`
- Unit string `json:"unit"`
- } `json:"result"`
- }
-
- func BjncGetHis(id_card_no string, startTime string, endTime string) (string, string) {
- // 1.生成签名sign
- signData := make(map[string]interface{})
- signData["dateType"] = "07"
- signData["medicalOrderType"] = "1,2,3,A,B,D,E,L,N,O"
- signData["idCardNo"] = id_card_no
- signData["startTime"] = startTime
- signData["endTime"] = endTime
- bytesData, _ := json.Marshal(signData)
- inputLog := string(bytesData)
- signStr := "body=" + inputLog + "&operUserCode=100&serv=getMedicalAdvice&key=A3195B3D179B01F66C86703E0890A95F"
- signTemp := utils.String2md5(signStr)
- sign := strings.ToUpper(signTemp)
-
- // 2.请求参数
- inputData := make(map[string]interface{})
- inputData["body"] = signData
- inputData["serv"] = "getMedicalAdvice"
- inputData["operUserCode"] = "100"
- inputData["sign"] = sign
-
- postData, err := json.Marshal(inputData)
- postStr := string(postData)
- utils.InfoLog("1111111111:%v", postStr)
- if err != nil {
- fmt.Println(err.Error())
- return err.Error(), ""
- }
-
- reader := bytes.NewReader(postData)
- url := "http://123.127.8.35:18090/esb/listener/openapi/StandardInterface"
-
- 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", "XTXT")
-
- 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)
- utils.InfoLog("22222222:%v", str)
- return str, inputLog
- }
-
- //
- //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("检验检查同步任务完成")
- //}
|