12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784 |
- 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 := "Abc123456@"
- 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)
- }
- }
-
- SyncToGzczjhtx()
- }
-
- 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
- }
-
- // 根据姓名获取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 string) (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["开嘱时间"] = advice_time
-
- 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 {
- fmt.Println(item)
- // if len(item.Patients.AdmissionNumber) > 0 {
- if len(patient_zy_ids) == 0 {
- //patient_zy_ids = item.Patients.IdCardNo + "-" + strconv.FormatInt(item.Patients.ID, 10) + "-" + item.Patients.AdmissionNumber
- } else {
- //patient_zy_ids = patient_zy_ids + "," + item.Patients.IdCardNo + "-" + strconv.FormatInt(item.Patients.ID, 10) + "-" + item.Patients.AdmissionNumber
- }
- // }
- }
- // 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("", ",")
- for _, idStr := range idArray {
- temp_id := strings.Split(idStr, "-")
- id := temp_id[0]
- patient_id := temp_id[1]
- admission_number := temp_id[2]
- 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和检验检查名称获取该检查的project_id,如没有,则创建一个
- func GetSzbljhProjectID(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 1013800, 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, org_id)
- 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: org_id,
- 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(org_id, strconv.FormatInt(yz.AdviceId,10))
- 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("记录日志"))
- }
- }
-
- }
-
- func GetSzblItemID(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
- }
- }
- }
|