1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768 |
- package service
-
- import (
- "IC/models"
- "IC/utils"
- _ "IC/utils"
- "bytes"
- "encoding/json"
- _ "encoding/json"
- "encoding/xml"
- "fmt"
- _ "fmt"
- "github.com/astaxie/beego/httplib"
- _ "github.com/jinzhu/gorm"
- "io/ioutil"
- "net/http"
- "net/url"
- "os"
- "strconv"
- "strings"
- "time"
- )
-
- type RequestResult struct {
- Msg string `json:"msg"`
- Result []struct {
- AdviceId int64 `json:"医嘱ID"`
- OtherId int64 `json:"相关ID"`
- Source int `json:"病人来源"`
- PatientId int64 `json:"病人ID"`
- JzId int64 `json:"就诊ID"`
- BabyId int `json:"婴儿ID"`
- PatientDepartmentId int `json:"病人科室ID"`
- OrderId int `json:"次序"`
- AdviceStatus int `json:"医嘱状态"`
- AdviceType int `json:"医嘱类型"`
- DiagnosisType string `json:"诊疗类型"`
- DiagnosisItemId int `json:"诊疗项目ID"`
- CheckMethd string `json:"检查方法"`
- ChargeItemId int `json:"收费项目ID"`
- Day int `json:"天数"`
- JiLiang float64 `json:"剂量"`
- YongLiang string `json:"用量"`
- DanLiang float64 `json:"单量"`
- Shuliang float64 `json:"数量"`
- Advice string `json:"医嘱"`
- GeiYaoTuJing string `json:"给药途径"`
- ShuoMing string `json:"说明"`
- ZhiXingKeShiId int `json:"执行科室ID"`
- ZhiXingKeShi string `json:"执行科室"`
- PN string `json:"P(+)或N(-)表示阳性或阴性"`
- ZhiXingPinCi string `json:"执行频次"`
- PinLvCiShu int `json:"频率次数"`
- PinLvJianGe int `json:"频率间隔"`
- JianGeDanWei string `json:"间隔单位"`
- ZhiXingShiJianFangAn string `json:"执行时间方案"`
- JiJiaTeXing int `json:"计价特性"`
- ZhiXingXingZhi int `json:"执行性质"`
- ZhiXingBiaoZhi int `json:"执行标记"`
- KeFouFenLing int `json:"可否分零"`
- JinJiBiaoZhi int `json:"紧急标志"`
- KaiShiZhiXingShiJian int64 `json:"开始执行时间"`
- ZhiXingZhongZhiShiJian int64 `json:"执行终止时间"`
- ShangCiZhiXingShiJian int64 `json:"上次执行时间"`
- KaiZhuKeShiId int `json:"开嘱科室ID"`
- DoctorCode string `json:"医师编码"`
- Doctor string `json:"开嘱医师"`
- AdviceTime int64 `json:"开嘱时间"`
- StopTime int64 `json:"停嘱时间"`
- ApplyId int `json:"申请ID"`
- UploadLable int `json:"上传标志"`
- CheckResult int `json:"审查结果"`
- NoPrint int `json:"忽略打印"`
- Summary string `json:"摘要"`
- AdviceOrderId int64 `json:"医嘱单id"`
- GeiYaoKeShi int `json:"给药科室"`
- GeiYaoXingZhi int `json:"给药性质"`
- GroupNo int `json:"组号"`
- Speed string `json:"滴速"`
- ShouRiCiShu float64 `json:"首日次数"`
- MoRiCiShu float64 `json:"末日次数"`
- AdviceDoctorId int `json:"开嘱医师ID"`
- AdviceNurseId int `json:"开嘱护士ID"`
- OperaId int `json:"操作员ID"`
- Opera string `json:"操作员"`
- CheckTime int64 `json:"审核时间"`
- ReplyAdviceTime int64 `json:"重整医嘱时间"`
- } `json:"result"`
- Code string `json:"code"`
- }
-
- type XmlKey struct {
- XMLName xml.Name `xml:"string"`
- StringName string `xml:"name,attr"`
- InnerText string `xml:",innerxml"`
- }
-
- // 获取艾迪康的key
- func GetAdKey(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
- xmlKey := XmlKey{}
- httplib.Get(apiurl).ToXML(&xmlKey)
- return xmlKey.InnerText
- }
-
- type ADString struct {
- XMLName xml.Name `xml:"string" json:"string"`
- NewDataSet rpnewDataSet `xml:"NewDataSet" json:"NewDataSet"`
- }
-
- type rpnewDataSet struct {
- ListTable []rplisttable `xml:"listtable" json:"listtable"`
- }
-
- type rplisttable struct {
- Id string `xml:"Id" json:"Id"`
- 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"`
- // ReportType string `xml:"ReportType" json:"ReportType"`
- // AdiconBarcode string `xml:"AdiconBarcode" json:"AdiconBarcode"`
- // 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 GetAdGetReportList(Key string, BeginDateTime string, EndDateTime string, TypeDateTime string, AgainFlag string) (key ADString) {
- 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 ADString
- xmlString, _ := httplib.Get(apiurl).String()
- xmlString = strings.Replace(xmlString, "<", "<", -1)
- xmlString = strings.Replace(xmlString, ">", ">", -1)
- xml.Unmarshal([]byte(xmlString), &xmlKey)
- return xmlKey
- }
-
- type adkCheck struct {
- ApplyId string `json:"applyid"`
- ReportNo string `json:"reportno"`
- PatName string `json:"patname"`
- Sex string `json:"sex"`
- Age string `json:"age"`
- DptName string `json:"dptname"`
- Testtype string `json:"testtype"`
- Testcode string `json:"testcode"`
- ExecuteTime string `json:"receivetime"`
- Checktime string `json:"checktime"`
- Checkcode string `json:"checkcode"`
- Result []adkResult `json:"result"`
- }
-
- func GetAdkInfo(key string, id string) (str []adkCheck, checkStr string) {
- Domain := "http://183.63.151.26:8081/AdWebService_new/ADReportWebService.asmx/GetJSONReportItemListById?"
- apiurl := "key=" + key + "&Id=" + id
- apiurl = url.PathEscape(apiurl)
- apiurl = Domain + apiurl
- utils.InfoLog("url1: %v", apiurl)
- xmlKey := XmlKey{}
- httplib.Get(apiurl).ToXML(&xmlKey)
- utils.InfoLog("url2: %v", xmlKey.InnerText)
- var checkJSON []adkCheck
- json.Unmarshal([]byte(xmlKey.InnerText), &checkJSON)
-
- return checkJSON, xmlKey.InnerText
- }
-
- // 沅胜透析中心Lis同步
- func SyncLisYstx() (err error) {
- // 第一步:获取艾迪康下发的Key
- org_id := int64(9919)
- login := "R26028"
- password := "abc123"
- key := GetAdKey(login, password)
- // 第二步:获取上一次同步的时间点
- syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime + 86400
- } else {
- sync_time = 1577808000
- }
- 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")
- utils.InfoLog("tempsyncTimes:%v", tempsyncTimes)
- adString := GetAdGetReportList(key, tempsyncTimes, tempsyncTimes, "2", "2")
- listtable := adString.NewDataSet.ListTable
- utils.InfoLog("listtable: %v", listtable)
- if len(listtable) > 3 {
- // 第三步:根据检查列表获取的ID来获取检验检查详情
- for _, list := range listtable {
- listId := list.Id
- utils.InfoLog("listId: %v", listId)
- checkInfo, checkStr := GetAdkInfo(key, listId)
- utils.InfoLog("checkInfo: %v", checkInfo)
- utils.InfoLog("checkStr: %v", checkStr)
- for _, info := range checkInfo {
- // 根据姓名 去查询对应的patient_id
- patient, _ := GetPatientID(org_id, info.PatName)
- utils.InfoLog("patient: %v", patient)
- if patient.ID > 0 {
- middleReportHandle := models.MiddleReportHandle{
- OrgId: org_id,
- HisUserId: strconv.FormatInt(patient.ID, 10),
- ApplyNo: info.ApplyId,
- ReportId: info.ReportNo,
- Name: info.PatName,
- Sex: info.Sex,
- Age: info.Age,
- Dept: info.DptName,
- PatientId: strconv.FormatInt(patient.ID, 10),
- RequestTime: info.ExecuteTime,
- ExecuteTime: info.ExecuteTime,
- ReceiveTime: info.ExecuteTime,
- CheckTime: info.ExecuteTime,
- ReportInfo: checkStr,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- }
- handleerr := CreateReportHandle(&middleReportHandle)
- if handleerr != nil {
- utils.ErrorLog("创建检验检查操作数据失败:%v", handleerr)
- return
- }
-
- YsReportInfoHandle(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
- }
- }
-
- }
-
- }
-
- return
- }
-
- // 根据姓名获取patient_id
- func GetPatientID(org_id int64, patient_name string) (patient models.Patients, err error) {
- err = readDb.Model(&models.Patients{}).Where("user_org_id = ? and status = 1 and name = ? ", org_id, patient_name).First(&patient).Error
- return
- }
-
- func GetProjectInfo(item_id int64, org_id int64) (project_info models.MiddleInspectionReference, err error) {
- err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and item_id = ?", org_id, item_id).First(&project_info).Error
- return
- }
-
- // 修改配置信息
- func UpdateInspectionReference(InspectionReference *models.MiddleInspectionReference) error {
- err := readMiddleDb.Model(&models.MiddleInspectionReference{}).Updates(&InspectionReference).Error
- return err
- }
-
- // 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
- func GetYsProjectID(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
- utils.InfoLog("inspection_reference: %v", inspection_reference)
- if inspection_reference.ProjectId > 0 {
- return inspection_reference.ProjectId + 1, err
- } else {
- return 38001, err
- }
- }
- }
-
- // 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
- func GetGzjhProjectID(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 116001, err
- }
- }
- }
-
- func YsReportInfoHandle(CheckInfo adkCheck, org_id int64, patientId int64) {
- // 1.先把所有的检查项弄出来
- for _, info := range CheckInfo.Result {
- // 根据project_id和item_id 判断该项是否存在
- curitemcode, _ := strconv.ParseInt(info.Itemcode, 10, 64)
- reference, _ := GetProjectInfo(curitemcode, org_id)
- utils.InfoLog("reference: %v", info)
- if reference.ID > 0 {
- if reference.ProjectId > 0 {
- LgthYsSync(info, reference.ProjectId, curitemcode, org_id, patientId, CheckInfo.ExecuteTime)
- } else {
- project_id := int64(0)
- if len(info.Groupitemcode) > 0 {
- // 对没有project信息的项目进行修改
- project_id, _ = GetYsProjectID(org_id, info.Groupitemcode)
- reference.ProjectId = project_id
- reference.ProjectName = info.Groupitemcode
- reference.Project = info.Groupitemcode
- // 修改配置信息
- UpdateInspectionReference(&reference)
- }
- LgthYsSync(info, project_id, curitemcode, org_id, patientId, CheckInfo.ExecuteTime)
- }
- } else {
- project_id := int64(0)
- if len(info.Groupitemcode) > 0 {
- project_id, _ = GetYsProjectID(org_id, info.Groupitemcode)
- }
- LgthYsSync(info, project_id, curitemcode, org_id, patientId, CheckInfo.ExecuteTime)
- }
- }
-
- SyncToYstx()
- }
-
- type adkResult struct {
- Testno string `json:"testno"`
- Reportno string `json:"reportno"`
- Itemord string `json:"itemord"`
- Itemcode string `json:"itemcode"`
- Itemname string `json:"itemname"`
- ItemEname string `json:"itemename"`
- Result string `json:"result"`
- Units string `json:"units"`
- Testdate string `json:"testdate"`
- Eqpname string `json:"eqpname"`
- Groupitemcode string `json:"groupitemcode"`
- Groupitemname string `json:"groupitemname"`
- Limit string `json:"limit"`
- Resultstate string `json:"resultstate"`
- Criticalflag string `json:"criticalflag"`
- Itemename string `json:"itemename"`
- }
-
- // 从机构将数据同步到中间库
- func LgthYsSync(report adkResult, project_id int64, item_id int64, org_id int64, patient_id int64, receivetime string) (*models.MiddleInspectionReference, error) {
- tx := writeMiddleDb.Begin()
- var inspection models.MiddleInspection
- var inspection_reference models.MiddleInspectionReference
- recordDateStr := receivetime
-
- if len(receivetime) == 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")
- // date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
- // record_date,_ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
- var total int
- var RangeOptions string
- var RangeMin string
- var RangeMax string
-
- // // 判断检查类型
- ItemType := 1
- Range := strings.Split(report.Limit, "-")
- if len(Range) > 1 {
- RangeMin = Range[0]
- RangeMax = Range[1]
- ItemType = 1
- } else {
- ItemType = 2
- RangeOptions = report.Limit
- }
-
- 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 = inspection_reference.RangeType
- }
- if total <= 0 {
- inspection_reference.OrgId = org_id
- inspection_reference.ProjectName = report.Groupitemcode
- inspection_reference.Project = report.Groupitemcode
- inspection_reference.ProjectId = project_id
- inspection_reference.ItemName = report.Itemname
- inspection_reference.ItemNameAddition = report.ItemEname
- 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 = report.Units
- 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 {
- report.Result = strings.Replace(report.Result, ">", ">", -1)
- report.Result = strings.Replace(report.Result, "<", "<", -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 = report.Result
- inspection.InspectDate = inspect_date
- inspection.RecordDate = record_date
- inspection.InspectTips = report.Resultstate
- 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()
- }
- }
-
- // //处理检验检查操作表里同步条数和状态
- // cur_num := Head.ReportInfoItemHandleNum + 1
- // Head.ReportInfoItemHandleNum = cur_num
- // handleType := 2
- // if cur_num == Head.ReportInfoItemNum {
- // handleType = 1
- // }
- // middleReportHandle := models.MiddleReportHandle{
- // ID: Head.ID,
- // ReportInfoItemHandleNum: cur_num,
- // HandleType: int64(handleType),
- // UpdatedTime: time.Now().Unix(),
- // }
- // err = UpdateReportHandleListyOrgID(&middleReportHandle)
- // if err != nil {
- // tx.Rollback()
- // }
- // }
-
- tx.Commit()
- return nil, err
- }
-
- func SyncToYstx() {
- utils.TraceLog("检验检查同步任务开始执行")
- org_id := int64(9919)
-
- // 第一步:跟进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("检验检查同步任务完成")
- }
-
- // 根据姓名获取patient_id
- func GetPatientGzjhList(org_id int64, schedulesTime int64) (schedules []*models.DialysisSchedule, err error) {
- err = readDb.Model(&models.DialysisSchedule{}).Where("user_org_id = ? and status = 1 and schedule_date = ?", org_id, schedulesTime).Preload("Patients", "status = 1").Find(&schedules).Error
- return
- }
-
- // 根据姓名获取admin_user_id
- func GetAdminUserId(org_id int64, doctor_name string) (doctor models.UserAdminRole, err error) {
- err = writeUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? and status = 1 and user_name = ?", org_id, doctor_name).First(&doctor).Error
- return
- }
-
- func GetPatientGzjhByOrgId(org_id int64) (patientList []*models.Patients, err error) {
- err = readDb.Model(&models.Patients{}).Where("user_org_id = ? and status = 1", org_id).Find(&patientList).Error
- return
- }
-
- type gzjhResult struct {
- ErrorCode int64 `json:"error_code"`
- Result []gzjhyz `json:"data"`
- }
-
- type gzjhyz struct {
- HisUserId string `json:"his_user_id"`
- AdviceId int64 `json:"advice_id"`
- UserName string `json:"user_name"`
- DoctorId string `json:"doctor_id"`
- AdviceType string `json:"advice_type"`
- StartTime string `json:"start_time"`
- AdviceName string `json:"advice_name"`
- AdviceDesc string `json:"advice_desc"`
- SingleDose string `json:"single_dose"`
- SingleDoseUnit string `json:"single_dose_unit"`
- PrescribingNumber string `json:"prescribing_number"`
- PrescribingNumberUnit string `json:"prescribing_number_unit"`
- DeliveryWay string `json:"delivery_way"`
- ExecutionFrequency string `json:"execution_frequency"`
- State string `json:"state"`
- CTime string `json:"c_time"`
- UTime string `json:"u_time"`
- }
-
- func GetGzjhYz(sync_time int64, his_user_id string) (str gzjhResult, checkStr string) {
- apiurl := "http://219.135.166.106:8067/WebService.asmx/queryyzxx"
- rep := httplib.Get(apiurl)
- rep.Param("sync_time", strconv.FormatInt(sync_time, 10))
- rep.Param("access_token", "0")
- rep.Param("his_user_id", his_user_id)
- utils.InfoLog(strconv.FormatInt(sync_time, 10))
- utils.InfoLog(his_user_id)
- // str, _ := rep.String()
- xmlKey := XmlKey{}
- rep.ToXML(&xmlKey)
-
- var checkJSON gzjhResult
- json.Unmarshal([]byte(xmlKey.InnerText), &checkJSON)
- return checkJSON, xmlKey.InnerText
- }
-
- func CreateDoctorAdviceHandle(advice *models.XtDoctorAdvice) error {
- err := writeDb.Create(&advice).Error
- return err
- }
-
- func GetAdviceBySyncAdviceId(orgId int64, sync_advice_id int64) (advice models.XtDoctorAdvice, err error) {
- err = readDb.Model(&models.XtDoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND sync_advice_id = ?", orgId, sync_advice_id).First(&advice).Error
- return
- }
-
- func GetAdviceBySyncAdviceIdTwo(orgId int64, sync_advice_id int64) (advice models.XtDoctorAdvice, err error) {
- err = readDb.Model(&models.XtDoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND sync_id = ?", orgId, sync_advice_id).First(&advice).Error
- return
- }
-
- func HttpGetTfData(id_card_no string, advice_time string) (string, string) {
-
- inputData := make(map[string]interface{})
-
- inputData["病人来源"] = "1"
- inputData["身份证号"] = id_card_no
- inputData["开嘱时间"] = "2022-07-26 17:41:22"
-
- 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)
- var url string
- gdyb_url := "http://hip.zptfyy.com/esb/listener/getVaf"
- url = gdyb_url
-
- //url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/1101"
- 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(), ""
- }
- fmt.Println(string(respBytes))
- str := string(respBytes)
- return str, inputLog
-
- }
-
- //func GettfYz(sync_time int64, id_card_no string, advice_time string) (str gzjhResult, checkStr string) {
- //
- // api := "http://10.129.128.51:8803/esb/listener/getVaf" + "?病人来源=" + "1" + "&身份证号=" + "350623196810011858" + "&开嘱时间=" + "2022-03-30 01:47:51"
- // resp, requestErr := http.Get(api)
- // fmt.Println(requestErr)
- // defer resp.Body.Close()
- // body, ioErr := ioutil.ReadAll(resp.Body)
- // fmt.Println(ioErr)
- // fmt.Println(body)
- //
- // //apiurl := "http://10.129.128.51:8803/esb/listener/getVaf"
- // //rep := httplib.Get(apiurl)
- // //rep.Param("病人来源", strconv.FormatInt(1, 10))
- // //rep.Param("身份证号", id_card_no)
- // //rep.Param("开嘱时间", advice_time)
- // //
- // //xmlKey := XmlKey{}
- // //rep.ToXML(&xmlKey)
- // //
- // //var checkJSON gzjhResult
- // //json.Unmarshal([]byte(xmlKey.InnerText), &checkJSON)
- // return nil, ""
- //}
-
- // 广州暨华透析中心医嘱同步
- func SyncGzjhyz() (err error) {
- // 第一步:获取上次同步时间
- org_id := int64(10015)
-
- redisClient := RedisClient()
- defer redisClient.Close()
- sync_time_tt, _ := redisClient.Get("gdjh_sync_time").Result()
-
- sync_time, _ := strconv.ParseInt(sync_time_tt, 10, 64)
- if sync_time == 0 {
- sync_time = time.Now().Unix()
- }
- new_sync_time := time.Now().Unix()
- utils.InfoLog("new_sync_time:%v", new_sync_time)
- // 切换为当前时间
- redisClient.Set("gdjh_sync_time", new_sync_time, time.Minute*60*24)
- // 第二步: 获取当天排班患者的住院号
- schedulesDateStr := time.Now().Format("2006-01-02")
- schedulesDate, _ := utils.ParseTimeStringToTime("2006-01-02", schedulesDateStr)
- schedulesTime := schedulesDate.Unix()
- var patient_zy_ids []string
- // patient_zy_ids, _ := redisClient.Get(redisClient.Context(),"gdjh_patient_zy_ids").Result()
- // if len(patient_zy_ids) == 0 {
- schedules, _ := GetPatientGzjhList(org_id, schedulesTime)
- if len(schedules) > 0 {
- for _, item := range schedules {
- // if len(item.Patients.AdmissionNumber) > 0 {
- patient_zy_ids = append(patient_zy_ids, item.Patients.IdCardNo)
-
- //
- }
- // redisClient.Set(redisClient.Context(),"gdjh_patient_zy_ids", patient_zy_ids, time.Minute*5)
- }
- // }
- utils.InfoLog("2gdjh_patient_zy_ids:%v", patient_zy_ids)
-
- // 第三步: 根据获取的同步时间,同步人员,去获取医嘱信息
- //idArray := strings.Split(patient_zy_ids, ",")
- //for _, idStr := range patient_zy_ids {
- // temp_id := strings.Split(idStr, "-")
- // gzjhyz, yzstr := GetGzjhYz(sync_time, id)
- // if len(gzjhyz.Result) == 0 && len(admission_number) > 0 {
- // utils.InfoLog("admission_number:%v", admission_number)
- // gzjhyz, yzstr = GetGzjhYz(sync_time, admission_number)
- // }
- // utils.InfoLog("sync_time:%v", sync_time)
- // utils.InfoLog("yzstr:%v", yzstr)
- // if len(gzjhyz.Result) > 0 {
- // timeLayout := "2006010215:04:05" //转化所需模板
- // loc, _ := time.LoadLocation("Local") //重要:获取时区
- // for _, yz := range gzjhyz.Result {
- // // 根据姓名获取医生ID
- // var doctor_id int64
- // temp_doctor_id, _ := redisClient.Get("gdjh_doctor_id_" + yz.DoctorId).Result()
- // if len(temp_doctor_id) == 0 {
- // doctor, _ := GetAdminUserId(org_id, yz.DoctorId)
- // doctor_id = doctor.AdminUserId
- // if doctor_id > 0 {
- // redisClient.Set("gdjh_doctor_id_"+yz.DoctorId, doctor_id, time.Minute*60*2)
- // } else {
- // continue
- // }
- // } else {
- // doctor_id, _ = strconv.ParseInt(temp_doctor_id, 10, 64)
- // }
- // theTime, _ := time.ParseInLocation(timeLayout, yz.StartTime, loc) //使用模板在对应时区转化为time.time类型
- // start_time := theTime.Unix()
- // temp_patient_id, _ := strconv.ParseInt(patient_id, 10, 64)
- // SingleDose, _ := strconv.ParseFloat(yz.SingleDose, 64)
- // PrescribingNumber, _ := strconv.ParseFloat(yz.PrescribingNumber, 64)
- // advice := models.XtDoctorAdvice{
- // UserOrgId: org_id,
- // PatientId: temp_patient_id,
- // AdviceType: 2,
- // AdviceDate: schedulesTime,
- // StartTime: start_time,
- // AdviceName: yz.AdviceName,
- // AdviceDesc: yz.AdviceDesc,
- // RecordDate: schedulesTime,
- // SingleDose: SingleDose,
- // SingleDoseUnit: yz.SingleDoseUnit,
- // PrescribingNumber: PrescribingNumber,
- // PrescribingNumberUnit: yz.PrescribingNumberUnit,
- // DeliveryWay: yz.DeliveryWay,
- // ExecutionFrequency: yz.ExecutionFrequency,
- // AdviceDoctor: doctor_id,
- // CreatedTime: time.Now().Unix(),
- // UpdatedTime: time.Now().Unix(),
- // SyncAdviceId: yz.AdviceId,
- // ExecutionState: 2,
- // Status: 1,
- // IsSync: 1,
- // }
- // utils.InfoLog("advice:%v", advice)
- // // 根据同步来的 advice_id 来查询库里是否已经存在
- // advice_info, _ := GetAdviceBySyncAdviceId(org_id, yz.AdviceId)
- // utils.InfoLog("advice_info:%v", advice_info)
- // if advice_info.ID > 0 {
- // key := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(temp_patient_id, 10) + ":" + strconv.FormatInt(schedulesTime, 10) + ":doctor_advices"
- // //清空key 值
- // redisClient.Set(key, "", time.Second)
- // keyOne := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedulesTime, 10) + ":advice_list_all"
- // redisClient.Set(keyOne, "", time.Second)
- // continue
- // } else {
- // if len(yz.AdviceName) > 0 {
- // handleerr := CreateDoctorAdviceHandle(&advice)
- // if handleerr != nil {
- // utils.ErrorLog("添加医嘱信息失败:%v", handleerr)
- // continue
- // }
- // } else {
- // continue
- // }
- // }
- // }
- // }
- //}
- return
- }
-
- type gzjhLisResult struct {
- ErrorCode int64 `json:"error_code"`
- Result []gzjhlis `json:"data"`
- }
-
- type gzjhlis struct {
- HisUserId string `json:"his_user_id"`
- PatientName string `json:"patient_name"`
- ProjectId string `json:"project_id"`
- ProjectName string `json:"project_name"`
- InspectDate string `json:"inspect_date"`
- ItemId string `json:"item_id"`
- ItemName string `json:"item_name"`
- ItemType string `json:"item_type"`
- ItemValue string `json:"item_value"`
- RangeMin string `json:"range_min"`
- RangeMax string `json:"range_max"`
- RangeValue string `json:"range_value"`
- RangeOptions string `json:"range_options"`
- Unit string `json:"unit"`
- State string `json:"state"`
- CTime string `json:"c_time"`
- UTime string `json:"u_time"`
- }
-
- func GetGzjhLis(sync_time string, his_user_id string) (str gzjhLisResult, checkStr string) {
- apiurl := "http://219.135.166.106:8067/WebService.asmx/queryjyjcxx"
- rep := httplib.Post(apiurl)
- rep.Param("sync_time", sync_time)
- rep.Param("access_token", "")
- rep.Param("his_user_id", his_user_id)
- // str, _ := rep.String()
- xmlKey := XmlKey{}
- rep.ToXML(&xmlKey)
-
- var checkJSON gzjhLisResult
- json.Unmarshal([]byte(xmlKey.InnerText), &checkJSON)
- return checkJSON, xmlKey.InnerText
- }
-
- // 广州暨华透析中心Lis同步
- func SyncGzjhLis() (err error) {
- org_id := int64(10016)
-
- // 第一步:获取上一次同步的时间点
- syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime + 86400
- } else {
- sync_time = 1577808000
- }
- // 第二步:获取所有患者的病历号
-
- patientList, _ := GetPatientGzjhByOrgId(org_id)
- if len(patientList) > 0 {
- for _, patient := range patientList {
- if len(patient.AdmissionNumber) > 0 {
- // 上次同步时间转换为接口需要的格式
- patient_id := patient.ID
- sync_time_temp := time.Unix(sync_time, 0)
- syncTimeStr := sync_time_temp.Format("2006010215:04:05")
- gzjhLis, lisStr := GetGzjhLis(syncTimeStr, patient.IdCardNo)
- utils.InfoLog("yzstr:%v", lisStr)
-
- if len(gzjhLis.Result) > 0 {
- // timeLayout := "2006010215:04:05" // 转化所需模板
- // loc, _ := time.LoadLocation("Local") // 重要:获取时区
- for _, info := range gzjhLis.Result {
- // 根据project_id和item_id 判断该项是否存在
- project_id := int64(0)
- if len(info.ProjectId) > 0 {
- project_id, _ = GetGzjhProjectID(org_id, info.ProjectName)
- } else {
- continue
- }
-
- item_id, _ := GetItemID(org_id, info.ProjectName, info.ItemName, project_id)
-
- tx := writeMiddleDb.Begin()
- var inspection models.MiddleInspection
- var inspection_reference models.MiddleInspectionReference
- recordDateStr := info.InspectDate
-
- if len(info.InspectDate) == 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")
- // date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
- // record_date,_ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
- var total int
- var RangeOptions string
- var RangeMin string
- var RangeMax string
-
- // // 判断检查类型
- ItemType, _ := strconv.Atoi(info.ItemType)
- Range := strings.Split(info.RangeValue, "~")
- if len(Range) > 1 {
- RangeMin = Range[0]
- RangeMax = Range[1]
- ItemType = 1
- } else {
- ItemType = 2
- RangeOptions = info.RangeOptions
- }
-
- 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 = inspection_reference.RangeType
- }
- if total <= 0 {
- inspection_reference.OrgId = org_id
- inspection_reference.ProjectName = info.ProjectName
- inspection_reference.Project = info.ProjectName
- inspection_reference.ProjectId = project_id
- inspection_reference.ItemName = info.ItemName
- inspection_reference.ItemNameAddition = info.ItemId
- 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 = info.Unit
- 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 {
- info.ItemValue = strings.Replace(info.ItemValue, ">", ">", -1)
- info.ItemValue = strings.Replace(info.ItemValue, "<", "<", -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 = info.ItemValue
- inspection.InspectDate = inspect_date
- inspection.RecordDate = record_date
- // inspection.InspectTips = report.Resultstate
- 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
- }
- } 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
- }
- SyncToGzjhtx()
- return
- }
-
- func SyncToGzjhtx() {
- utils.TraceLog("检验检查同步任务开始执行")
- org_id := int64(10016)
-
- // 第一步:跟进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("检验检查同步任务完成")
- }
-
- type hbdyyz struct {
- HisUserId string `json:"his_user_id"`
- UserName string `json:"user_name"`
- DoctorId int64 `json:"doctor_id"`
- DoctorName string `json:"Doctor_name"`
- AdviceId int64 `json:"advice_id"`
- MedListCodg string `json:"med_list_codg"`
- StartTime int64 `json:"start_time"`
- AdviceName string `json:"advice_name"`
- AdviceDesc string `json:"advice_desc"`
- SingleDose string `json:"single_dose"`
- SingleDoseUnit string `json:"single_dose_unit"`
- PrescribingNumber string `json:"prescribing_number"`
- PrescribingNumberUnit string `json:"prescribing_number_unit"`
- DeliveryWay string `json:"delivery_way"`
- ExecutionFrequency string `json:"execution_frequency"`
- State int64 `json:"state"`
- CTime int64 `json:"create_time"`
- UTime int64 `json:"update_time"`
- }
-
- type hbdyHisResult struct {
- ErrorCode int64 `json:"error_code"`
- Result []hbdyyz `json:"data"`
- }
-
- func GetHbdyYz(sync_time string, his_user_id string) (str hbdyHisResult, checkStr string) {
- apiurl := "http://218.200.78.144:30800/esb-scheduler/api/XT_GET_ADVICE"
- rep := httplib.Post(apiurl)
- rep.Param("sync_time", sync_time)
- rep.Param("his_user_id", his_user_id)
- strs, err := rep.String()
- if err != nil {
- utils.InfoLog("err:%v", err)
- }
- utils.InfoLog("str:%v", strs)
-
- var checkJSON hbdyHisResult
- json.Unmarshal([]byte(strs), &checkJSON)
- utils.InfoLog("checkJSON:%v", checkJSON)
- return checkJSON, strs
- }
-
- // 湖北监利大垸透析中心医嘱同步
- func SyncHbJldyyz() (err error) {
- // 第一步:获取上次同步时间
- org_id := int64(10101)
-
- redisClient := RedisClient()
- defer redisClient.Close()
- sync_time, _ := redisClient.Get("gdjh_sync_time1").Result()
- if len(sync_time) == 0 {
- sync_time = strconv.FormatInt(time.Now().Unix(), 10)
- utils.InfoLog("sync_time:%v", sync_time)
- // formatTimeStr := "2021-08-31 00:00"
- // checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", sync_time)
- // sync_time = strconv.FormatInt(checkDateUnix.Unix(),10)
- }
- new_sync_time := time.Now().Unix()
- utils.InfoLog("new_sync_time:%v", new_sync_time)
- // 切换为当前时间
- redisClient.Set("gdjh_sync_time", new_sync_time, time.Minute*60*24)
- // 第二步: 获取当天排班患者的住院号
- schedulesDateStr := time.Now().Format("2006-01-02")
- schedulesDate, _ := utils.ParseTimeStringToTime("2006-01-02", schedulesDateStr)
- schedulesTime := schedulesDate.Unix()
- patient_zy_ids, _ := redisClient.Get("gdjh_patient_zy_ids").Result()
- if len(patient_zy_ids) == 0 {
- schedules, _ := GetPatientGzjhList(org_id, schedulesTime)
- if len(schedules) > 0 {
- for _, item := range schedules {
- if len(patient_zy_ids) == 0 {
- patient_zy_ids = item.Patients.IdCardNo + "-" + strconv.FormatInt(item.Patients.ID, 10)
- } else {
- patient_zy_ids = patient_zy_ids + "," + item.Patients.IdCardNo + "-" + strconv.FormatInt(item.Patients.ID, 10)
- }
- }
- redisClient.Set("gdjh_patient_zy_ids", patient_zy_ids, time.Minute*60*2)
- }
- }
- utils.InfoLog("2gdjh_patient_zy_ids:%v", patient_zy_ids)
-
- // 第三步: 根据获取的同步时间,同步人员,去获取医嘱信息
- idArray := strings.Split(patient_zy_ids, ",")
- for _, idStr := range idArray {
- temp_id := strings.Split(idStr, "-")
- id := temp_id[0]
- patient_id := temp_id[1]
- hbdyyz, _ := GetHbdyYz(sync_time, id)
- if len(hbdyyz.Result) > 0 {
- for _, yz := range hbdyyz.Result {
- utils.InfoLog("yz:%v", yz)
- // 根据姓名获取医生ID
- var doctor_id int64
- temp_doctor_id, _ := redisClient.Get("gdjh_doctor_id_" + strconv.FormatInt(yz.DoctorId, 10)).Result()
- if len(temp_doctor_id) == 0 {
- doctor, _ := GetAdminUserId(org_id, yz.DoctorName)
- doctor_id = doctor.AdminUserId
- if doctor_id > 0 {
- redisClient.Set("gdjh_doctor_id_"+strconv.FormatInt(yz.DoctorId, 10), doctor_id, time.Minute*60*2)
- } else {
- continue
- }
- } else {
- doctor_id, _ = strconv.ParseInt(temp_doctor_id, 10, 64)
- }
- temp_patient_id, _ := strconv.ParseInt(patient_id, 10, 64)
- SingleDose, _ := strconv.ParseFloat(yz.SingleDose, 64)
- PrescribingNumber, _ := strconv.ParseFloat(yz.PrescribingNumber, 64)
- utils.InfoLog("PrescribingNumber:%v", PrescribingNumber)
- advice := models.XtDoctorAdvice{
- UserOrgId: org_id,
- PatientId: temp_patient_id,
- AdviceType: 2,
- AdviceDate: schedulesTime,
- StartTime: yz.StartTime,
- AdviceName: yz.AdviceName,
- AdviceDesc: yz.AdviceDesc,
- RecordDate: schedulesTime,
- SingleDose: SingleDose,
- SingleDoseUnit: yz.SingleDoseUnit,
- PrescribingNumber: PrescribingNumber,
- PrescribingNumberUnit: yz.PrescribingNumberUnit,
- DeliveryWay: yz.DeliveryWay,
- ExecutionFrequency: yz.ExecutionFrequency,
- AdviceDoctor: doctor_id,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- SyncAdviceId: yz.AdviceId,
- ExecutionState: 2,
- Status: 1,
- IsSync: 1,
- }
- utils.InfoLog("advice:%v", advice)
- // 根据同步来的 advice_id 来查询库里是否已经存在
- advice_info, _ := GetAdviceBySyncAdviceId(org_id, yz.AdviceId)
- utils.InfoLog("advice_info:%v", advice_info)
- if advice_info.ID > 0 {
- continue
- } else {
- if yz.State == 1 {
- handleerr := CreateDoctorAdviceHandle(&advice)
- if handleerr != nil {
- utils.ErrorLog("添加医嘱信息失败:%v", handleerr)
- continue
- }
- } else {
- continue
- }
- }
- }
- }
- }
- return
- }
-
- type hbdylis struct {
- HisUserId string `json:"his_user_id"`
- PatientName string `json:"patient_name"`
- ProjectId int64 `json:"project_id"`
- ProjectName string `json:"project_name"`
- InspectDate int64 `json:"inspect_date"`
- ItemId int64 `json:"item_id"`
- ItemName string `json:"item_name"`
- ItemType int64 `json:"item_type"`
- ItemValue string `json:"item_value"`
- RangeMin string `json:"range_min"`
- RangeMax string `json:"range_max"`
- RangeValue string `json:"range_value"`
- RangeOptions string `json:"range_options"`
- Unit string `json:"unit"`
- State int64 `json:"state"`
- CTime int64 `json:"c_time"`
- UTime int64 `json:"u_time"`
- }
-
- type hbdyLisResult struct {
- ErrorCode int64 `json:"error_code"`
- Result []hbdylis `json:"data"`
- }
-
- func GethbdyLis(sync_time string, his_user_id string) (str hbdyLisResult, checkStr string) {
- apiurl := "http://218.200.78.144:30800/esb-scheduler/api/XT_GET_INSPECTION"
- rep := httplib.Post(apiurl)
- rep.Param("sync_time", sync_time)
- rep.Param("his_user_id", his_user_id)
- strs, err := rep.String()
- if err != nil {
- utils.InfoLog("err:%v", err)
- }
- utils.InfoLog("str:%v", strs)
-
- var checkJSON hbdyLisResult
- json.Unmarshal([]byte(strs), &checkJSON)
- // utils.InfoLog("checkJSON:%v", checkJSON)
- return checkJSON, strs
- }
-
- // 湖北监利大院透析中心Lis同步
- func SyncHbdyLis() (err error) {
- org_id := int64(10101)
-
- // 第一步:获取上一次同步的时间点
- syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- sync_time = 1627747200
- }
- // 第二步:获取所有患者的病历号
-
- 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
- // sync_time_temp := time.Unix(sync_time,0)
- // syncTimeStr := sync_time_temp.Format("2006010215:04:05")
- utils.InfoLog("IdCardNo:%v", patient.IdCardNo)
- // 获取会员号
-
- // utils.InfoLog("VipStr:%v", VipStr)
-
- gzjhLis, _ := GethbdyLis(strconv.FormatInt(sync_time, 10), patient.IdCardNo)
- // if len(gzjhLis.Result) == 0 {
- // gzjhLis,_ = GethbdyLis(strconv.FormatInt(sync_time,10),VipStr)
- // }
- // utils.InfoLog("yzstr:%v", gzjhLis)
-
- if len(gzjhLis.Result) > 0 {
- // timeLayout := "2006010215:04:05" // 转化所需模板
- // loc, _ := time.LoadLocation("Local") // 重要:获取时区
- for _, info := range gzjhLis.Result {
- utils.InfoLog("Result:%v", info)
- // 根据project_id和item_id 判断该项是否存在
- project_id := int64(0)
- if info.ProjectId > 0 {
- project_id, _ = GetGzjhProjectID(org_id, info.ProjectName)
- } else {
- continue
- }
-
- item_id, _ := GetItemID(org_id, info.ProjectName, info.ItemName, project_id)
-
- tx := writeMiddleDb.Begin()
- var inspection models.MiddleInspection
- var inspection_reference models.MiddleInspectionReference
-
- record_date := info.InspectDate
-
- if info.InspectDate == 0 {
- record_date = time.Now().Unix()
- }
-
- // 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")
- // date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
- // record_date,_ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
- var total int
- var RangeOptions string
- var RangeMin string
- var RangeMax string
-
- // // 判断检查类型
- ItemType := info.ItemType
- Range := strings.Split(info.RangeValue, "-")
- if len(Range) > 1 {
- RangeMin = Range[0]
- RangeMax = Range[1]
- ItemType = 1
- } else {
- ItemType = 2
- RangeOptions = info.RangeOptions
- }
-
- 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
- inspection_reference.ProjectName = info.ProjectName
- inspection_reference.Project = info.ProjectName
- inspection_reference.ProjectId = project_id
- inspection_reference.ItemName = info.ItemName
- inspection_reference.ItemNameAddition = strconv.FormatInt(info.ItemId, 10)
- inspection_reference.ItemId = item_id
- inspection_reference.RangeType, _ = strconv.Atoi(strconv.FormatInt(ItemType, 10))
- inspection_reference.RangeMin = RangeMin
- inspection_reference.RangeMax = RangeMax
- // inspection_reference.RangeValue = RangeValue
- inspection_reference.RangeOptions = RangeOptions
- inspection_reference.Unit = info.Unit
- 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 {
- info.ItemValue = strings.Replace(info.ItemValue, ">", ">", -1)
- info.ItemValue = strings.Replace(info.ItemValue, "<", "<", -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, _ = strconv.Atoi(strconv.FormatInt(ItemType, 10))
- inspection.ItemId = item_id
- inspection.InspectValue = info.ItemValue
- inspection.InspectDate = inspect_date
- inspection.RecordDate = record_date
- // inspection.InspectTips = report.Resultstate
- 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()
- }
- }
-
- VipStr := ""
- VipArr := strings.Split(patient.DialysisNo, "(")
- if len(VipArr) > 1 {
- VipArrTwo := strings.Split(VipArr[1], ")")
- VipStr = VipArrTwo[0]
-
- gzjhLisbyVip, _ := GethbdyLis(strconv.FormatInt(sync_time, 10), VipStr)
- if len(gzjhLisbyVip.Result) > 0 {
- // timeLayout := "2006010215:04:05" // 转化所需模板
- // loc, _ := time.LoadLocation("Local") // 重要:获取时区
- for _, info := range gzjhLisbyVip.Result {
- // utils.InfoLog("Result:%v", info)
- // 根据project_id和item_id 判断该项是否存在
- project_id := int64(0)
- if info.ProjectId > 0 {
- project_id, _ = GetGzjhProjectID(org_id, info.ProjectName)
- } else {
- continue
- }
-
- item_id, _ := GetItemID(org_id, info.ProjectName, info.ItemName, project_id)
-
- tx := writeMiddleDb.Begin()
- var inspection models.MiddleInspection
- var inspection_reference models.MiddleInspectionReference
-
- record_date := info.InspectDate
-
- if info.InspectDate == 0 {
- record_date = time.Now().Unix()
- }
-
- // 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")
- // date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
- // record_date,_ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
- var total int
- var RangeOptions string
- var RangeMin string
- var RangeMax string
-
- // // 判断检查类型
- ItemType := info.ItemType
- Range := strings.Split(info.RangeValue, "-")
- if len(Range) > 1 {
- RangeMin = Range[0]
- RangeMax = Range[1]
- ItemType = 1
- } else {
- ItemType = 2
- RangeOptions = info.RangeOptions
- }
-
- 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
- inspection_reference.ProjectName = info.ProjectName
- inspection_reference.Project = info.ProjectName
- inspection_reference.ProjectId = project_id
- inspection_reference.ItemName = info.ItemName
- inspection_reference.ItemNameAddition = strconv.FormatInt(info.ItemId, 10)
- inspection_reference.ItemId = item_id
- inspection_reference.RangeType, _ = strconv.Atoi(strconv.FormatInt(ItemType, 10))
- inspection_reference.RangeMin = RangeMin
- inspection_reference.RangeMax = RangeMax
- // inspection_reference.RangeValue = RangeValue
- inspection_reference.RangeOptions = RangeOptions
- inspection_reference.Unit = info.Unit
- 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 {
- info.ItemValue = strings.Replace(info.ItemValue, ">", ">", -1)
- info.ItemValue = strings.Replace(info.ItemValue, "<", "<", -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, _ = strconv.Atoi(strconv.FormatInt(ItemType, 10))
- inspection.ItemId = item_id
- inspection.InspectValue = info.ItemValue
- inspection.InspectDate = inspect_date
- inspection.RecordDate = record_date
- // inspection.InspectTips = report.Resultstate
- 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
- }
- SyncToHbdytx()
- return
- }
-
- func SyncToHbdytx() {
- utils.TraceLog("检验检查同步任务开始执行")
- org_id := int64(10101)
-
- // 第一步:跟进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("检验检查同步任务完成")
- }
-
- // 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
- func GetBljhProjectID(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 5210138, err
- }
- }
- }
-
- // 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
- func GetBlItemID(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*10 + 1, err
- }
- }
- }
-
- // 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
- func GetShjhProjectID(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 5210215, err
- }
- }
- }
-
- // 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
- func GetShItemID(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*10 + 1, err
- }
- }
- }
-
- func Synctfyz() (err error) {
-
- // 第一步:获取上次同步时间
- org_id := int64(10330)
-
- redisClient := RedisClient()
- defer redisClient.Close()
- sync_time_tt, _ := redisClient.Get("tf_sync_time").Result()
-
- sync_time, _ := strconv.ParseInt(sync_time_tt, 10, 64)
- if sync_time == 0 {
- sync_time = time.Now().Unix()
- }
- new_sync_time := time.Now().Unix()
- utils.InfoLog("new_sync_time:%v", new_sync_time)
- // 切换为当前时间
- redisClient.Set("tf_sync_time", new_sync_time, time.Minute*60*24)
- // 第二步: 获取当天排班患者的住院号
- schedulesDateStr := time.Now().Format("2006-01-02")
- schedulesDate, _ := utils.ParseTimeStringToTime("2006-01-02", schedulesDateStr)
- schedulesTime := schedulesDate.Unix()
- var patient_zy_ids string
- // patient_zy_ids, _ := redisClient.Get(redisClient.Context(),"gdjh_patient_zy_ids").Result()
- // if len(patient_zy_ids) == 0 {
- schedules, _ := GetPatientGzjhList(org_id, schedulesTime)
- if len(schedules) > 0 {
- for _, item := range schedules {
- // if len(item.Patients.AdmissionNumber) > 0 {
- if len(patient_zy_ids) == 0 {
- patient_zy_ids = item.Patients.IdCardNo
- } else {
- patient_zy_ids = patient_zy_ids + "," + item.Patients.IdCardNo
- }
- // }
- }
- // redisClient.Set(redisClient.Context(),"gdjh_patient_zy_ids", patient_zy_ids, time.Minute*5)
- }
- // }
- utils.InfoLog("2gdjh_patient_zy_ids:%v", patient_zy_ids)
-
- // 第三步: 根据获取的同步时间,同步人员,去获取医嘱信息
- idArray := strings.Split(patient_zy_ids, ",")
- for _, idStr := range idArray {
- //temp_id := strings.Split(idStr, "-")
- id := idStr
- printInfo, _ := GetPatientsInfoByIDCardNo(id, 10330)
- timeNow := time.Unix(sync_time, 0) //2017-08-30 16:19:19 +0800 CST
-
- timeString := timeNow.Format("2006-01-02 15:04:05") //2015-06-15 08:52:32
-
- result, requestLog := HttpGetTfData(id, timeString)
- saveLog(result, requestLog, "tf", "tf", "tf")
- //fmt.Println(result)
- //fmt.Println(requestLog)
- var res RequestResult
- if err := json.Unmarshal([]byte(result), &res); err != nil {
- utils.ErrorLog("解析失败:%v", err)
- }
- fmt.Println(res)
- //saveLog(result, requestLog, "tf", "tf", "tf")
-
- //
- //if len(gzjhyz.Result) == 0 && len(admission_number) > 0 {
- // utils.InfoLog("admission_number:%v", admission_number)
- // gzjhyz, yzstr = GetGzjhYz(sync_time, admission_number)
- //}
- //utils.InfoLog("sync_time:%v", sync_time)
- //utils.InfoLog("yzstr:%v", yzstr)
- if len(res.Result) > 0 {
- //timeLayout := "2006010215:04:05" //转化所需模板
- //loc, _ := time.LoadLocation("Local") //重要:获取时区
- for _, yz := range res.Result {
- // 根据姓名获取医生ID
- var doctor_id int64
- //doctor_id, _ = strconv.ParseInt(yz.AdviceDoctorId, 10, 64)
-
- temp_doctor_id, _ := redisClient.Get("tf_doctor_id_" + yz.Doctor).Result()
- if len(temp_doctor_id) == 0 {
- doctor, _ := GetAdminUserId(org_id, yz.Doctor)
- doctor_id = doctor.AdminUserId
- if doctor_id > 0 {
- redisClient.Set("tf_doctor_id_"+yz.Doctor, doctor_id, time.Minute*60*2)
- } else {
- continue
- }
- } else {
- doctor_id, _ = strconv.ParseInt(temp_doctor_id, 10, 64)
- }
- //theTime, _ := time.ParseInLocation(timeLayout, , loc) //使用模板在对应时区转化为time.time类型
- start_time := yz.AdviceTime / 1000
- fmt.Println(start_time)
- temp_patient_id := printInfo.ID
- SingleDose := yz.DanLiang
- PrescribingNumber := yz.Shuliang
- advice := models.XtDoctorAdvice{
- UserOrgId: 3877,
- PatientId: temp_patient_id,
- AdviceType: 2,
- AdviceDate: schedulesTime,
- StartTime: start_time,
- AdviceName: yz.Advice,
- //AdviceDesc: yz.AdviceDesc,
- RecordDate: schedulesTime,
- SingleDose: SingleDose,
- PrescribingNumber: PrescribingNumber,
- DeliveryWay: yz.GeiYaoTuJing,
- ExecutionFrequency: yz.ZhiXingPinCi,
- AdviceDoctor: doctor_id,
- CreatedTime: time.Now().Unix(),
- UpdatedTime: time.Now().Unix(),
- SyncAdviceId: 0,
- ExecutionState: 2,
- Status: 1,
- IsSync: 1,
- SyncId: strconv.FormatInt(yz.AdviceId, 10),
- }
- utils.InfoLog("advice:%v", advice)
- // 根据同步来的 advice_id 来查询库里是否已经存在
- advice_info, _ := GetAdviceBySyncAdviceIdTwo(3877, yz.AdviceId)
- utils.InfoLog("advice_info:%v", advice_info)
- if advice_info.ID > 0 {
- key := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(temp_patient_id, 10) + ":" + strconv.FormatInt(schedulesTime, 10) + ":doctor_advices"
- //清空key 值
- redisClient.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(schedulesTime, 10) + ":advice_list_all"
- redisClient.Set(keyOne, "", time.Second)
- continue
- } else {
- if len(yz.Advice) > 0 {
- handleerr := CreateDoctorAdviceHandle(&advice)
- if handleerr != nil {
- utils.ErrorLog("添加医嘱信息失败:%v", handleerr)
- continue
- }
- } else {
- continue
- }
- }
- }
- }
- }
- return
- }
-
- //
-
- func saveLog(result string, request string, infno string, desc string, org_name string) {
-
- //org_id, _ := beego.AppConfig.Int64("org_id")
- //miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
- dir := org_name + "日志"
- utils.Mkdir(dir)
- month := time.Unix(1557042972, 0).Format("1")
- year := time.Now().Format("2006")
- month = time.Now().Format("01")
- day := time.Now().Format("02")
- hour := time.Now().Format("15")
- min := time.Now().Format("04")
- sec := time.Now().Format("05")
-
- result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
-
- file := org_name + "_" + year + month + day + "_log"
- file_name := file + ".txt"
- file_path := org_name + "日志" + "/" + file_name
- exist, _ := utils.PathExists(file_path)
- if exist { //存在
- fmt.Println("存在")
- f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
- if err != nil {
- fmt.Println("read fail")
- }
- content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
- n, _ := f.Seek(0, 2)
- _, err = f.WriteAt([]byte(content), n)
-
- } else { //不存在
- fmt.Println("文件不存在,创建文件")
- f, err := os.Create(org_name + "日志" + "/" + file_name)
- defer f.Close()
- if err != nil {
- } else {
- _, err = f.Write([]byte("记录日志"))
- }
- }
-
- }
|