12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913 |
- package city
-
- //
- import (
- "Data_Upload_Api/models/sz"
- "Data_Upload_Api/service"
- "Data_Upload_Api/utils"
- "fmt"
- _"github.com/astaxie/beego"
- "github.com/jinzhu/gorm"
- "github.com/robfig/cron"
- "math"
- "strconv"
- "strings"
- "time"
- )
-
- var createUploadDataCronJob *cron.Cron
-
- func init() {
- utils.InfoLog("开启定时任务")
- createUploadDataCronJob = cron.New()
- spec := "0 0 0 * * ?" // 每天凌晨0点检测数据上报情况
- // spec1 := "0 10 0 * * ?" // 每天凌晨0点检测数据上报情况
- // spec2 := "0 20 0 * * ?" // 每天凌晨0点检测数据上报情况
- createUploadDataCronJob.AddFunc(spec, func() {
- SyncToLg2h() //深圳市数据上报
- })
-
- // createUploadDataCronJob.AddFunc(spec1, func() {
- // SyncToHqyy() //深圳市数据上报
- // })
-
- // createUploadDataCronJob.AddFunc(spec2, func() {
- // SyncToSmzy() //深圳市数据上报
- // })
- }
-
- //
- func BeginAutoJob() {
- createUploadDataCronJob.Start()
- }
-
- func SyncToLg2h() {
- // 第一步:到上报配置表中找到深圳需要上报的机构
- // sz_province, _ := beego.AppConfig.Int64("sz_province")
- // sz_city, _ := beego.AppConfig.Int64("sz_city")
- // configs, _ := service.FindAllDataUploadConfigOrgInfo(sz_province, sz_city, 3)
-
- org := &sz.DataUploadConfig{
- OrgId: 9598,
- ProvinceId: 19,
- CityId: 291,
- DepartmentName: "深圳市龙岗区第二人民医院",
- HospitalId: "455835506",
- InstType: 1,
- DbHost: "183.62.158.36",
- DbPort: "61433",
- DbPass: "LG2H+9897",
- DbUser: "sa",
- DbName: "xtzk",
- }
-
- // for _, org := range configs {
- // 第二步:跟进配置,创建数据库连接
- if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
- orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
- if err != nil {
- utils.ErrorLog("创建数据库连接失败:%v", err)
- return
- }
- // 第三步:开始同步数据
- // 同步医院信息 t_hd_hospital
- SyncHospital(orgDb, org.OrgId, org.HospitalId, org.InstType, org.DepartmentName)
- // 同步水处理器 t_hd_wm
- SyncWMS(orgDb, org.OrgId, org.HospitalId)
- // // 同步员工 t_hd_staff
- SyncStaff(orgDb, org.OrgId, org.HospitalId)
- // // 同步病人 t_hd_patient
- SyncPatient(orgDb, org.OrgId, org.HospitalId)
- // // 同步排班 t_hd_shift
- SyncShift(orgDb, org.OrgId, org.HospitalId)
- // 同步处方 t_hd_ps
- SyncPs(orgDb, org.OrgId, org.HospitalId)
- // 同步处方药品 t_hd_ps
- SyncPsMedicine(orgDb, org.OrgId, org.HospitalId)
- // // 同步转院信息 t_hd_patient_out
- SyncPatientOut(orgDb, org.OrgId, org.HospitalId)
- // 同步处方信息 t_hd_doctors_advice
- SyncDoctorAdvice(orgDb, org.OrgId, org.HospitalId)
- // 同步透中信息 t_hd_middle
- SyncMiddle(orgDb, org.OrgId, org.HospitalId)
- // // 同步设备 t_hd_other_machine
- SyncOtherMachine(orgDb, org.OrgId, org.HospitalId)
- // // 同步维修 t_hd_maintain
- SyncMachineRepair(orgDb, org.OrgId, org.HospitalId)
- // // 同步设备 t_hd_dm
- SyncDM(orgDb, org.OrgId, org.HospitalId)
- // // 同步患者透析记录 t_hd_dialysis
- SyncDialysis(orgDb, org.OrgId, org.HospitalId)
- // 同步透析床位分区 t_hd_division
- SyncDivision(orgDb, org.OrgId, org.HospitalId)
- // 患者通路信息表(T_HD_ACCESS)
- SyncAccess(orgDb, org.OrgId, org.HospitalId)
- // 透析床位表(T_HD_SICKBED)
- SyncSickbed(orgDb, org.OrgId, org.HospitalId)
- // 患者诊断信息表(T_HD_DIAGNOSIS)
- SyncDiagnosis(orgDb, org.OrgId, org.HospitalId)
- // 患者传染病检查记录表(T_HD_INFECTION
- SyncInfection(orgDb, org.OrgId, org.HospitalId)
- // 透析并发症记录表(T_HD_COMPLICATION)
- SyncComplication(orgDb, org.OrgId, org.HospitalId)
- // 血透患者检测结果表(T_HD_LIS_REPORT)
- SyncLisReport(orgDb, org.OrgId, org.HospitalId)
- // 血透患者检验结果指标表(T_HD_LIS_INDICATORS)
- SyncLisIndicators(orgDb, org.OrgId, org.HospitalId)
-
- // 第四步:关闭数据库连接
- service.CloseDB(orgDb)
- }
- // }
- return
- }
-
- func SyncToHqyy() {
- // 第一步:到上报配置表中找到深圳需要上报的机构
- // sz_province, _ := beego.AppConfig.Int64("sz_province")
- // sz_city, _ := beego.AppConfig.Int64("sz_city")
- // configs, _ := service.FindAllDataUploadConfigOrgInfo(sz_province, sz_city, 3)
-
- org := &sz.DataUploadConfig{
- OrgId: 9442,
- ProvinceId: 19,
- CityId: 291,
- DepartmentName: "暨南大学附属深圳华侨医院",
- HospitalId: "73307826X",
- InstType: 1,
- DbHost: "183.11.232.26",
- DbPort: "3306",
- DbPass: "1Q2W3e4r!@#$",
- DbUser: "sa",
- DbName: "xtzk",
- }
-
- // for _, org := range configs {
- // 第二步:跟进配置,创建数据库连接
- if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
- orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
- if err != nil {
- utils.ErrorLog("创建数据库连接失败:%v", err)
- return
- }
- // 第三步:开始同步数据
- // 同步医院信息 t_hd_hospital
- SyncHospital(orgDb, org.OrgId, org.HospitalId, org.InstType, org.DepartmentName)
- // 同步水处理器 t_hd_wm
- SyncWMS(orgDb, org.OrgId, org.HospitalId)
- // // 同步员工 t_hd_staff
- SyncStaff(orgDb, org.OrgId, org.HospitalId)
- // // 同步病人 t_hd_patient
- SyncPatient(orgDb, org.OrgId, org.HospitalId)
- // // 同步排班 t_hd_shift
- SyncShift(orgDb, org.OrgId, org.HospitalId)
- // 同步处方 t_hd_ps
- SyncPs(orgDb, org.OrgId, org.HospitalId)
- // 同步处方药品 t_hd_ps
- SyncPsMedicine(orgDb, org.OrgId, org.HospitalId)
- // // 同步转院信息 t_hd_patient_out
- SyncPatientOut(orgDb, org.OrgId, org.HospitalId)
- // 同步处方信息 t_hd_doctors_advice
- SyncDoctorAdvice(orgDb, org.OrgId, org.HospitalId)
- // 同步透中信息 t_hd_middle
- SyncMiddle(orgDb, org.OrgId, org.HospitalId)
- // // 同步设备 t_hd_other_machine
- SyncOtherMachine(orgDb, org.OrgId, org.HospitalId)
- // // 同步维修 t_hd_maintain
- SyncMachineRepair(orgDb, org.OrgId, org.HospitalId)
- // // 同步设备 t_hd_dm
- SyncDM(orgDb, org.OrgId, org.HospitalId)
- // // 同步患者透析记录 t_hd_dialysis
- SyncDialysis(orgDb, org.OrgId, org.HospitalId)
- // 同步透析床位分区 t_hd_division
- SyncDivision(orgDb, org.OrgId, org.HospitalId)
- // 患者通路信息表(T_HD_ACCESS)
- SyncAccess(orgDb, org.OrgId, org.HospitalId)
- // 透析床位表(T_HD_SICKBED)
- SyncSickbed(orgDb, org.OrgId, org.HospitalId)
- // 患者诊断信息表(T_HD_DIAGNOSIS)
- SyncDiagnosis(orgDb, org.OrgId, org.HospitalId)
- // 患者传染病检查记录表(T_HD_INFECTION
- SyncInfection(orgDb, org.OrgId, org.HospitalId)
- // 透析并发症记录表(T_HD_COMPLICATION)
- SyncComplication(orgDb, org.OrgId, org.HospitalId)
- // 血透患者检测结果表(T_HD_LIS_REPORT)
- SyncLisReport(orgDb, org.OrgId, org.HospitalId)
- // 血透患者检验结果指标表(T_HD_LIS_INDICATORS)
- SyncLisIndicators(orgDb, org.OrgId, org.HospitalId)
-
- // 第四步:关闭数据库连接
- service.CloseDB(orgDb)
- }
- // }
- return
- }
-
- func SyncToSmzy() {
- // 第一步:到上报配置表中找到深圳需要上报的机构
- // sz_province, _ := beego.AppConfig.Int64("sz_province")
- // sz_city, _ := beego.AppConfig.Int64("sz_city")
- // configs, _ := service.FindAllDataUploadConfigOrgInfo(sz_province, sz_city, 3)
-
- org := &sz.DataUploadConfig{
- OrgId: 9504,
- ProvinceId: 19,
- CityId: 291,
- DepartmentName: "深圳生命之源血液透析中心",
- HospitalId: "MA5EU4PC0",
- InstType: 1,
- DbHost: "localhost",
- DbPort: "1433",
- DbPass: "1Q2W3e4r!@#$",
- DbUser: "sa",
- DbName: "xtzk",
- }
-
- // for _, org := range configs {
- // 第二步:跟进配置,创建数据库连接
- if len(org.DbHost) > 0 && len(org.DbUser) > 0 && len(org.DbPort) > 0 && len(org.DbPass) > 0 && len(org.DbName) > 0 {
- orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
- if err != nil {
- utils.ErrorLog("创建数据库连接失败:%v", err)
- return
- }
- // 第三步:开始同步数据
- // 同步医院信息 t_hd_hospital
- SyncHospital(orgDb, org.OrgId, org.HospitalId, org.InstType, org.DepartmentName)
- // 同步水处理器 t_hd_wm
- SyncWMS(orgDb, org.OrgId, org.HospitalId)
- // // 同步员工 t_hd_staff
- SyncStaff(orgDb, org.OrgId, org.HospitalId)
- // // 同步病人 t_hd_patient
- SyncPatient(orgDb, org.OrgId, org.HospitalId)
- // // 同步排班 t_hd_shift
- SyncShift(orgDb, org.OrgId, org.HospitalId)
- // 同步处方 t_hd_ps
- SyncPs(orgDb, org.OrgId, org.HospitalId)
- // 同步处方药品 t_hd_ps
- SyncPsMedicine(orgDb, org.OrgId, org.HospitalId)
- // // 同步转院信息 t_hd_patient_out
- SyncPatientOut(orgDb, org.OrgId, org.HospitalId)
- // 同步处方信息 t_hd_doctors_advice
- SyncDoctorAdvice(orgDb, org.OrgId, org.HospitalId)
- // 同步透中信息 t_hd_middle
- SyncMiddle(orgDb, org.OrgId, org.HospitalId)
- // // 同步设备 t_hd_other_machine
- SyncOtherMachine(orgDb, org.OrgId, org.HospitalId)
- // // 同步维修 t_hd_maintain
- SyncMachineRepair(orgDb, org.OrgId, org.HospitalId)
- // // 同步设备 t_hd_dm
- SyncDM(orgDb, org.OrgId, org.HospitalId)
- // // 同步患者透析记录 t_hd_dialysis
- SyncDialysis(orgDb, org.OrgId, org.HospitalId)
- // 同步透析床位分区 t_hd_division
- SyncDivision(orgDb, org.OrgId, org.HospitalId)
- // 患者通路信息表(T_HD_ACCESS)
- SyncAccess(orgDb, org.OrgId, org.HospitalId)
- // 透析床位表(T_HD_SICKBED)
- SyncSickbed(orgDb, org.OrgId, org.HospitalId)
- // 患者诊断信息表(T_HD_DIAGNOSIS)
- SyncDiagnosis(orgDb, org.OrgId, org.HospitalId)
- // 患者传染病检查记录表(T_HD_INFECTION
- SyncInfection(orgDb, org.OrgId, org.HospitalId)
- // 透析并发症记录表(T_HD_COMPLICATION)
- SyncComplication(orgDb, org.OrgId, org.HospitalId)
- // 血透患者检测结果表(T_HD_LIS_REPORT)
- SyncLisReport(orgDb, org.OrgId, org.HospitalId)
- // 血透患者检验结果指标表(T_HD_LIS_INDICATORS)
- SyncLisIndicators(orgDb, org.OrgId, org.HospitalId)
-
- // 第四步:关闭数据库连接
- service.CloseDB(orgDb)
- }
- // }
- return
- }
-
-
- // 同步医院信息
- func SyncHospital(rdb *gorm.DB, org_id int64, hospital_id string, inst_type int64, department_name string) {
- // 第一步:根据机构id获取上次同步时间
- syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 1)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- sync_time = 0
- }
-
- // 第二步:跟进上次同步时间找出这个时间段内增加的数据
- org, _ := service.FindOrgData(org_id, sync_time)
- if org.ID > 0 {
- hospital := &sz.TempHdHospital{
- HospitalId: hospital_id,
- InstType: strconv.FormatInt(inst_type, 10),
- DepartmentName: department_name,
- AuthorizedBeds: int64(len(org.DeviceNumber)),
- CreateTime: time.Now(),
- UpdateTime: time.Now(),
- Sjscsj: time.Now(),
- Xgbz: 0,
- }
- err := service.CreateOrgRecord(rdb, hospital)
- if err == nil {
- // 第三步:同步成功后,添加同步记录
- upload := &sz.DataUpload{
- SyncType: 1,
- OrgId: org_id,
- SyncTime: time.Now().Unix(),
- SyncResultType: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- }
- err := service.CreateUploadRecord(upload)
- if err != nil {
- utils.ErrorLog("%v", err)
- }
- }
- }
- }
-
- // 同步水处理器
- func SyncWMS(rdb *gorm.DB, org_id int64, hospital_id string) {
- // 第一步:根据机构id获取上次同步时间
- syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 22)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- sync_time = 0
- }
-
- //同步水处理机
- waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
- var wms []*sz.TempHdWm
- for _, item := range waterMachine {
- wm := &sz.TempHdWm{
- HospitalId: hospital_id,
- EquipmentId: strconv.FormatInt(item.ID, 10),
- EquipmentBrand: item.ManufactureFactory,
- EquipmentModel: strconv.FormatInt(item.UnitType, 10),
- EnableTime: time.Unix(item.StartDate, 0),
- DiscardedTime: time.Unix(item.RubbishDate, 0),
- EquipmentType: item.DeviceType,
- CreateTime: time.Now(),
- UpdateTime: time.Now(),
- Sjscsj: time.Now(),
- Xgbz: 0,
- }
-
- wms = append(wms, wm)
- }
-
- err := service.BatchCreateWMsRecord(wms, rdb)
- if err == nil {
- // 第三步:同步成功后,添加同步记录
- upload := &sz.DataUpload{
- SyncType: 22,
- OrgId: org_id,
- SyncTime: time.Now().Unix(),
- SyncResultType: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- }
- err := service.CreateUploadRecord(upload)
- if err != nil {
- utils.ErrorLog("%v", err)
- }
- } else {
- //错误处理
-
- }
-
- }
-
- // 同步员工
- func SyncStaff(rdb *gorm.DB, org_id int64, hospital_id string) {
- // 第一步:根据机构id获取上次同步时间
- syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 21)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- sync_time = 0
- }
-
- //同步员工信息
- roles, _ := service.FindOrgRolesData(org_id, sync_time, time.Now().Unix())
-
- //waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
- var staffs []*sz.TempHdStaff
- for _, role := range roles {
- var title int
- switch role.UserType {
- case 2:
- title = 1
- break
- case 3:
- title = 2
- break
- }
-
- staff := &sz.TempHdStaff{
- ID: role.AdminUserId,
- HospitalId: hospital_id,
- StaffId: strconv.FormatInt(role.ID, 10),
- StaffName: role.UserName,
- Position: int64(title),
- PermanentType: 1,
- CreateTime: time.Now(),
- UpdateTime: time.Now(),
- Sjscsj: time.Now(),
- Xgbz: 0,
- }
- staffs = append(staffs, staff)
-
- }
-
- err := service.BatchCreateStaffRecord(staffs, rdb)
- if err == nil {
- // 第三步:同步成功后,添加同步记录
- upload := &sz.DataUpload{
- SyncType: 21,
- OrgId: org_id,
- SyncTime: time.Now().Unix(),
- SyncResultType: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- }
- err := service.CreateUploadRecord(upload)
- if err != nil {
- utils.ErrorLog("%v", err)
- }
- } else {
- //错误处理
-
- }
- }
-
- // 同步病人
- func SyncPatient(rdb *gorm.DB, org_id int64, hospital_id string) {
- // 第一步:根据机构id获取上次同步时间
- syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 15)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- sync_time = 0
- }
-
- //同步员工信息
- patients, _ := service.FindOrgPatientData(org_id, sync_time, time.Now().Unix())
-
- //waterMachine, _ := service.FindOrgWaterMachineData(org_id, sync_time, time.Now().Unix())
- var hdPatients []*sz.TempHdPatient
- for _, patient := range patients {
-
- idcard_year, _ := strconv.Atoi(Substr(patient.IdCardNo, 6, 4)) // 年
- idcard_mo, _ := strconv.Atoi(Substr(patient.IdCardNo, 10, 2)) // 月
-
- idcard_day, _ := strconv.Atoi(Substr(patient.IdCardNo, 12, 2)) // 日
-
- date := strconv.Itoa(idcard_year)
- if idcard_mo < 10 {
- date = date + "-0" + strconv.Itoa(idcard_mo)
- } else {
- date = date + "-" + strconv.Itoa(idcard_mo)
- }
-
- if idcard_day < 10 {
- date = date + "-0" + strconv.Itoa(idcard_day)
- } else {
- date = date + "-" + strconv.Itoa(idcard_day)
- }
-
- local, _ := time.LoadLocation("Local")
- birthday, _ := time.ParseInLocation("2006-01-02", date, local)
- fmt.Println(birthday)
-
- var isCKD int
-
- value := strings.Index(patient.Diagnose, "慢性肾脏病")
- value2 := strings.Index(patient.Diagnose, "CKD")
- value3 := strings.Index(patient.Diagnose, "慢性肾衰竭")
-
- if value != -1 || value2 != -1 || value3 != -1 {
- isCKD = 1
- } else {
- isCKD = 0
- }
-
- p := &sz.TempHdPatient{
- HospitalId: hospital_id,
- PatientNk: patient.ID,
- CardNo: "000000000000000000",
- CardType: 1,
- IdNo: patient.IdCardNo,
- IdType: "01",
- PatientName: patient.Name,
- Gender: strconv.FormatInt(patient.Gender, 10),
- BornDate: birthday,
- DiagnosisSummary: patient.Diagnose,
- IsCrf: strconv.Itoa(isCKD),
- DialysisStartTime: time.Unix(patient.FirstDialysisDate,0),
- LocalStartTime: time.Unix(patient.HospitalFirstDialysisDate,0),
- OutpatientNo: patient.DialysisNo,
- HospitalizedNo: patient.AdmissionNumber,
- CreateTime: time.Now(),
- UpdateTime: time.Now(),
- Sjscsj: time.Now(),
- Xgbz: 0,
- }
-
- if patient.FirstDialysisDate != 0 {
- p.DialysisStartTime = time.Unix(patient.FirstDialysisDate, 0)
- }
- if patient.HospitalFirstDialysisDate != 0 {
- p.LocalStartTime = time.Unix(patient.HospitalFirstDialysisDate, 0)
- }
-
- hdPatients = append(hdPatients, p)
- }
-
- err := service.BatchCreatePatinet(hdPatients, rdb)
- if err == nil {
- // 第三步:同步成功后,添加同步记录
- upload := &sz.DataUpload{
- SyncType: 15,
- OrgId: org_id,
- SyncTime: time.Now().Unix(),
- SyncResultType: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- }
- err := service.CreateUploadRecord(upload)
- if err != nil {
- utils.ErrorLog("%v", err)
- }
- } else {
- //错误处理
-
- }
- }
-
- func Substr(str string, start, length int) string {
- rs := []rune(str)
- rl := len(rs)
- end := 0
- if start < 0 {
- start = rl - 1 + start
- }
- end = start + length
- if start > end {
- start, end = end, start
- }
- if start < 0 {
- start = 0
- }
- if start > rl {
- start = rl
- }
- if end < 0 {
- end = 0
- }
- if end > rl {
- end = rl
- }
- return string(rs[start:end])
-
- }
-
- // 同步排班
- func SyncShift(rdb *gorm.DB, org_id int64, hospital_id string) {
- // 第一步:根据机构id获取上次同步时间
- syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 19)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- sync_time = 0
- }
-
- var hdShift []*sz.TempHdShift
- schs, _ := service.FindOrgScheduleData(org_id, sync_time, time.Now().Unix())
-
- for _, sch := range schs {
- shift := &sz.TempHdShift{
- PsId: strconv.FormatInt(sch.ID, 10),
- HospitalId: hospital_id,
- PatientNk: strconv.FormatInt(sch.PatientId, 10),
- ScheduleDate: time.Unix(sch.ScheduleDate, 0),
- ShiftType: strconv.FormatInt(sch.ScheduleType, 10),
- SickbedNo: sch.DeviceNumber.ID,
- ScheduleStatus: "1",
- CreateTime: time.Now(),
- Sjscsj: time.Now(),
- Xgbz: 0,
- }
-
- hdShift = append(hdShift, shift)
- }
- err := service.BatchCreateSchedual(hdShift, rdb)
- if err == nil {
- // 第三步:同步成功后,添加同步记录
- upload := &sz.DataUpload{
- SyncType: 19,
- OrgId: org_id,
- SyncTime: time.Now().Unix(),
- SyncResultType: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- }
- err := service.CreateUploadRecord(upload)
- if err != nil {
- utils.ErrorLog("%v", err)
- }
- } else {
- //错误处理
-
- }
-
- }
-
- // 同步处方
- func SyncPs(rdb *gorm.DB, org_id int64, hospital_id string) {
- // 第一步:根据机构id获取上次同步时间
- syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 17)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- sync_time = 0
- }
-
- var hdPrescription []*sz.TempHdPs
- prescriptions, _ := service.FindOrgDialysisPrescriptionData(org_id, sync_time, time.Now().Unix())
- for _, item := range prescriptions {
-
- ps := &sz.TempHdPs{
- PrescribeId: strconv.FormatInt(item.ID, 10),
- HospitalId: hospital_id,
- PatientNk: strconv.FormatInt(item.PatientId, 10),
- Sjscsj: time.Now(),
- Xgbz: 0,
- PrescribeTime: time.Unix(item.RecordDate, 0),
- CreateTime: time.Unix(item.CreatedTime,0),
- }
-
- switch item.ModeId {
- case 1:
- ps.DialysisFrequency = 5
- ps.FrequencyUnit = 2
- ps.RrtTypeName = "HD"
- ps.RrtType = 1
-
- break
- case 2:
- ps.DialysisFrequency = 5
- ps.FrequencyUnit = 2
- ps.RrtTypeName = "HDF"
- ps.RrtType = 3
- break
- case 4:
- ps.DialysisFrequency = 5
- ps.FrequencyUnit = 2
- ps.RrtTypeName = "HP"
- ps.RrtType = 5
- break
- case 5:
- ps.DialysisFrequency = 5
- ps.FrequencyUnit = 2
- ps.RrtTypeName = "HF"
- ps.RrtType = 2
- break
- case 7:
- ps.DialysisFrequency = 5
- ps.FrequencyUnit = 2
- ps.RrtTypeName = "IUF"
- ps.RrtType = 6
- break
- default:
- ps.DialysisFrequency = 5
- ps.FrequencyUnit = 2
- ps.RrtTypeName = "HD"
- ps.RrtType = 1
- break
- }
-
- hdPrescription = append(hdPrescription, ps)
- }
- var err error
- for _, hdps := range hdPrescription{
- err = service.BatchCreatePsOther(hdps, rdb)
- }
-
- // err := service.BatchCreatePs(hdPrescription, rdb)
-
- if err == nil {
- // 第三步:同步成功后,添加同步记录
- upload := &sz.DataUpload{
- SyncType: 17,
- OrgId: org_id,
- SyncTime: time.Now().Unix(),
- SyncResultType: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- }
- err := service.CreateUploadRecord(upload)
- if err != nil {
- utils.ErrorLog("%v", err)
- }
- } else {
- //错误处理
-
- }
-
- }
-
- // 同步处方药物
- func SyncPsMedicine(rdb *gorm.DB, org_id int64, hospital_id string) {
- // 第一步:根据机构id获取上次同步时间
- syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 18)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- sync_time = 0
- }
-
- var tempPsmedicine []*sz.TempHdPsMedicine
- prescriptions, _ := service.FindOrgDoctorAdviceTemplateData(org_id, sync_time, time.Now().Unix())
-
- for _, item := range prescriptions {
-
- psm := &sz.TempHdPsMedicine{
- Sn : item.ID,
- HospitalId: hospital_id,
- MedicineTypeId: "2",
- MedicineId: strconv.FormatInt(item.ID,10),
- CreateTime: time.Now(),
- Sjscsj: time.Now(),
- Xgbz: 0,
- }
- tempPsmedicine = append(tempPsmedicine, psm)
- }
-
- err := service.BatchCreatePsm(tempPsmedicine, rdb)
-
- if err == nil {
- // 第三步:同步成功后,添加同步记录
- upload := &sz.DataUpload{
- SyncType: 18,
- OrgId: org_id,
- SyncTime: time.Now().Unix(),
- SyncResultType: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- }
- err := service.CreateUploadRecord(upload)
- if err != nil {
- utils.ErrorLog("%v", err)
- }
- } else {
- //错误处理
-
- }
- }
-
- // 同步转院信息
- func SyncPatientOut(rdb *gorm.DB, org_id int64, hospital_id string) {
- // 第一步:根据机构id获取上次同步时间
- syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 16)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- sync_time = 0
- }
-
- var hdPatientOuts []*sz.TempHdPatientOut
- patients, _ := service.FindOrgPatientOutData(org_id, sync_time, time.Now().Unix())
- //
- for _, patient := range patients {
-
- p := &sz.TempHdPatientOut{
- Sn: strconv.FormatInt(patient.PatientLapseto.ID,10),
- HospitalId: hospital_id,
- PatientNk: strconv.FormatInt(patient.ID, 10),
- SequelaeDate: time.Unix(patient.PatientLapseto.LapsetoTime,0),
- SequelaeType: "99",
- CreateTime: time.Unix(patient.PatientLapseto.CreatedTime,0),
- DeathReason: "99",
- ExtReason: "99",
- Sjscsj: time.Now(),
- Xgbz: 0,
- }
- hdPatientOuts = append(hdPatientOuts, p)
- }
-
- err := service.BatchCreatePatientOut(hdPatientOuts, rdb)
-
- if err == nil {
- // 第三步:同步成功后,添加同步记录
- upload := &sz.DataUpload{
- SyncType: 16,
- OrgId: org_id,
- SyncTime: time.Now().Unix(),
- SyncResultType: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- }
- err := service.CreateUploadRecord(upload)
- if err != nil {
- utils.ErrorLog("%v", err)
- }
- } else {
- //错误处理
-
- }
-
- }
-
- // 同步处方信息
- func SyncDoctorAdvice(rdb *gorm.DB, org_id int64, hospital_id string) {
- // 第一步:根据机构id获取上次同步时间
- syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 6)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- sync_time = 0
- }
-
- var hdDoctorAdvices []*sz.TempHdDoctorsAdvice
- dialysisPrescriptions, _ := service.FindOrgDialysisPrescriptionData(org_id, sync_time, time.Now().Unix())
-
- for _, dp := range dialysisPrescriptions {
- if dp.DialysisOrder.ID > 0 {
- advice := &sz.TempHdDoctorsAdvice{
- MedicalOrderId: strconv.FormatInt(dp.ID, 10),
- HospitalId: hospital_id,
- DialysisId: strconv.FormatInt(dp.DialysisOrder.ID, 10),
- OrderType: "1",
- PatientNk: strconv.FormatInt(dp.PatientId, 10),
- DialysisDuration: dp.DialysisDurationHour*60 + dp.DialysisDurationMinute,
- BloodVol: int64(math.Floor(dp.BloodFlowVolume + 0/5)),
- Anticoagulant: dp.Anticoagulant,
- CreateTime: time.Now(),
- Sjscsj: time.Now(),
- Xgbz: 0,
- DryWeight: dp.AssessmentBeforeDislysis.DryWeight,
- }
- switch dp.ModeId {
- case 1:
- advice.RrtTypeName = "HD"
- advice.RrtType = 1
- break
- case 2:
- advice.RrtTypeName = "HDF"
- advice.RrtType = 3
- break
- case 4:
- advice.RrtTypeName = "HP"
- advice.RrtType = 5
- break
- case 5:
- advice.RrtTypeName = "HF"
- advice.RrtType = 2
- break
- case 7:
- advice.RrtTypeName = "IUF"
- advice.RrtType = 6
- break
- default:
- advice.RrtTypeName = "HD"
- advice.RrtType = 1
- }
- if advice.RrtType == 0 {
- continue
- }
- hdDoctorAdvices = append(hdDoctorAdvices, advice)
- }
-
- }
-
- err := service.BatchCreateDoctorsAdvice(hdDoctorAdvices, rdb)
-
- if err == nil {
- // 第三步:同步成功后,添加同步记录
- upload := &sz.DataUpload{
- SyncType: 6,
- OrgId: org_id,
- SyncTime: time.Now().Unix(),
- SyncResultType: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- }
- err := service.CreateUploadRecord(upload)
- if err != nil {
- utils.ErrorLog("%v", err)
- }
- } else {
- //错误处理
-
- }
-
- }
-
- //
- func SyncMiddle(rdb *gorm.DB, org_id int64, hospital_id string) {
- // 第一步:根据机构id获取上次同步时间
- syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 36)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- sync_time = 0
- }
-
- var hdMiddle []*sz.TempHdMiddle
- monitors, _ := service.FindOrgMonitorRecordData(org_id, sync_time, time.Now().Unix())
-
- for _, item := range monitors {
-
- mid := &sz.TempHdMiddle{
- Sn : item.ID,
- HospitalId: hospital_id,
- DialysisId: strconv.FormatInt(item.DialysisOrder.ID, 10),
- MonitorTime: time.Unix(item.OperateTime, 0),
- Sbp: int64(math.Floor(item.SystolicBloodPressure + 0/5)),
- Dbp: int64(math.Floor(item.DiastolicBloodPressure + 0/5)),
- PatientNk: strconv.FormatInt(item.PatientId, 10),
- CreateTime: time.Now(),
- Sjscsj: time.Now(),
- Xgbz: 0,
- }
- if mid.Sbp > 999 {
- continue
- }
-
- if mid.Dbp > 999 {
- continue
- }
-
- hdMiddle = append(hdMiddle, mid)
- }
-
- err := service.BatchCreateMonitor(hdMiddle, rdb)
-
- if err == nil {
- // 第三步:同步成功后,添加同步记录
- upload := &sz.DataUpload{
- SyncType: 36,
- OrgId: org_id,
- SyncTime: time.Now().Unix(),
- SyncResultType: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- }
- err := service.CreateUploadRecord(upload)
- if err != nil {
- utils.ErrorLog("%v", err)
- }
- } else {
- //错误处理
-
- }
-
- }
-
- // 同步设备
- func SyncOtherMachine(rdb *gorm.DB, org_id int64, hospital_id string) {
- // 第一步:根据机构id获取上次同步时间
- syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 13)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- sync_time = 0
- }
-
- //同步设备
- waterMachine, _ := service.FindOrgOtherMachineData(org_id, sync_time, time.Now().Unix())
- var wms []*sz.TempHdOtherMachine
- for _, item := range waterMachine {
- wm := &sz.TempHdOtherMachine{
- HospitalId: hospital_id,
- EquipmentId: strconv.FormatInt(item.ID, 10),
- EquipmentBrand: item.ManufactureFactory,
- EquipmentModel: strconv.FormatInt(item.UnitType, 10),
- EnableTime: time.Unix(item.BuyDate, 0),
- Status: 1,
- EquipmentType: 11,
- CreateTime: time.Now(),
- UpdateTime: time.Now(),
- Sjscsj: time.Now(),
- Xgbz: strconv.FormatInt(0, 10),
- }
- switch item.MachineStatus {
- case 1:
- wm.Status = 1
- break
- case 4:
- wm.Status = 3
- break
- }
-
- wms = append(wms, wm)
- }
-
- err := service.BatchCreateOtherMachineRecord(wms, rdb)
- if err == nil {
- // 第三步:同步成功后,添加同步记录
- upload := &sz.DataUpload{
- SyncType: 13,
- OrgId: org_id,
- SyncTime: time.Now().Unix(),
- SyncResultType: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- }
- err := service.CreateUploadRecord(upload)
- if err != nil {
- utils.ErrorLog("%v", err)
- }
- } else {
- //错误处理
-
- }
-
- }
-
- // 同步维修
- func SyncMachineRepair(rdb *gorm.DB, org_id int64, hospital_id string) {
- // 第一步:根据机构id获取上次同步时间
- syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 11)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- sync_time = 0
- }
-
- //同步设备
- hdMaintain, _ := service.FindOrgMachineRepairData(org_id, sync_time, time.Now().Unix())
- var maintain []*sz.TempHdMaintain
- for _, item := range hdMaintain {
- mt := &sz.TempHdMaintain{
- HospitalId: hospital_id,
- EquipmentId: strconv.FormatInt(item.VMDeviceAddmacher.ID, 10),
- RepairTime: time.Unix(item.GuaranteeDate, 0),
- CreateTime: time.Now(),
- Sjscsj: time.Now(),
- Xgbz: 0,
- }
- switch item.VMDeviceAddmacher.DeviceType {
- case 1:
- mt.EquipmentType = "11"
- break
- case 2:
- mt.EquipmentType = "21"
- break
- case 3:
- mt.EquipmentType = "99"
- break
- }
-
- maintain = append(maintain, mt)
- }
-
- err := service.BatchCreateMainTain(maintain, rdb)
- if err == nil {
- // 第三步:同步成功后,添加同步记录
- upload := &sz.DataUpload{
- SyncType: 11,
- OrgId: org_id,
- SyncTime: time.Now().Unix(),
- SyncResultType: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- }
- err := service.CreateUploadRecord(upload)
- if err != nil {
- utils.ErrorLog("%v", err)
- }
- } else {
- //错误处理
-
- }
-
- }
-
- // 同步设备
- func SyncDM(rdb *gorm.DB, org_id int64, hospital_id string) {
- // 第一步:根据机构id获取上次同步时间
- syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 5)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- sync_time = 0
- }
-
- //同步设备
- dm, _ := service.FindOrgMachineData(org_id, sync_time, time.Now().Unix())
- var hdms []*sz.TempHdDm
- for _, item := range dm {
- hdm := &sz.TempHdDm{
- HospitalId: hospital_id,
- EquipmentId: strconv.FormatInt(item.ID, 10),
- SickbedNo: strconv.FormatInt(item.DeviceNumber.ID, 10),
- SickbedType: "0",
- EquipmentBrand: item.ManufactureFactory,
- EquipmentModel: strconv.FormatInt(item.UnitType, 10),
- EnableTime: time.Unix(item.BuyDate, 0),
- // EquipmentType: "11",
- Bbp: "0",
- CreateTime: time.Now(),
- UpdateTime: time.Now(),
- Sjscsj: time.Now(),
- Xgbz: strconv.FormatInt(0, 10),
- }
-
- switch item.MachineStatus {
- case 1:
- hdm.Status = "1"
- break
- case 4:
- hdm.Status = "3"
- break
- }
-
- switch item.DeviceType {
- case 1:
- hdm.EquipmentType = "11"
- break
- case 3:
- hdm.EquipmentType = "99"
- break
- }
-
- hdms = append(hdms, hdm)
- }
-
- err := service.BatchCreateHDMRecord(hdms, rdb)
- if err == nil {
- // 第三步:同步成功后,添加同步记录
- upload := &sz.DataUpload{
- SyncType: 5,
- OrgId: org_id,
- SyncTime: time.Now().Unix(),
- SyncResultType: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- }
- err := service.CreateUploadRecord(upload)
- if err != nil {
- utils.ErrorLog("%v", err)
- }
- } else {
- //错误处理
-
- }
- }
-
- // 同步患者透析记录
- func SyncDialysis(rdb *gorm.DB, org_id int64, hospital_id string) {
- // 第一步:根据机构id获取上次同步时间
- syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 2)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- sync_time = 0
- }
-
- var tempDialysis []*sz.TempHdDialysis
- dialysisData, _ := service.FindOrgDialysisData(org_id, sync_time, time.Now().Unix())
-
- for _, item := range dialysisData {
-
- psm := &sz.TempHdDialysis{
- DialysisId: strconv.FormatInt(item.ID, 10),
- HospitalId: hospital_id,
- PatientNk: strconv.FormatInt(item.PatientId, 10),
- PsId: strconv.FormatInt(item.Schedule.ID, 10),
- DialysisDate: time.Unix(item.DialysisDate, 0),
- SickbedNo: item.DeviceNumber.Number,
- DivisionId: strconv.FormatInt(item.Schedule.PartitionId, 10),
- EquipmentId: strconv.FormatInt(item.DeviceNumber.ID, 10),
- MixDialysis: "0",
- TotalTreatDuration: item.AssessmentAfterDislysis.ActualTreatmentHour*60 + item.AssessmentAfterDislysis.ActualTreatmentMinute,
- IsHospitalization: "0",
- IsEmergency: "0",
- IsPerioperativePeriod: "0",
- BeforeSbp: int64(item.AssessmentBeforeDislysis.SystolicBloodPressure),
- BeforeDbp: int64(item.AssessmentBeforeDislysis.DiastolicBloodPressure),
- AfterSbp: int64(item.AssessmentAfterDislysis.SystolicBloodPressure),
- AfterDbp: int64(item.AssessmentAfterDislysis.DiastolicBloodPressure),
- BeforeWeight: item.AssessmentBeforeDislysis.WeightBefore,
- AfterWeight: item.AssessmentAfterDislysis.WeightAfter,
- UpNurseId: strconv.FormatInt(item.StartNurse,10),
- DownNurseId: strconv.FormatInt(item.FinishNurse,10),
- CheckNurseId: strconv.FormatInt(item.FinishNurse,10),
- PunctureNurseId: strconv.FormatInt(item.PunctureNurse,10),
- StartTime: time.Unix(item.StartTime, 0),
- EndTime: time.Unix(item.EndTime, 0),
- CreateTime: time.Unix(item.CreatedTime, 0),
- Sjscsj: time.Now(),
- Xgbz: 0,
- }
- if item.AssessmentAfterDislysis.ActualUltrafiltration < 10 {
- psm.ActualufMl = int64(item.AssessmentAfterDislysis.ActualUltrafiltration * 1000)
- } else {
- psm.ActualufMl = int64(item.AssessmentAfterDislysis.ActualUltrafiltration)
- }
-
- if item.VMDialysisPrescription.TargetUltrafiltration < 10 {
- psm.Ufv = int64(item.VMDialysisPrescription.TargetUltrafiltration * 1000)
- } else {
- psm.Ufv = int64(item.VMDialysisPrescription.TargetUltrafiltration)
- }
-
- if item.AssessmentAfterDislysis.ActualDisplacement < 10 {
- psm.TotalReplace = int64(item.AssessmentAfterDislysis.ActualDisplacement * 1000)
- } else {
- psm.TotalReplace = int64(item.AssessmentAfterDislysis.ActualDisplacement)
- }
-
- tempDialysis = append(tempDialysis, psm)
- }
-
- err := service.BatchCreateDialysis(tempDialysis, rdb)
-
- if err == nil {
- // 第三步:同步成功后,添加同步记录
- upload := &sz.DataUpload{
- SyncType: 2,
- OrgId: org_id,
- SyncTime: time.Now().Unix(),
- SyncResultType: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- }
- err := service.CreateUploadRecord(upload)
- if err != nil {
- utils.ErrorLog("%v", err)
- }
- } else {
- //错误处理
-
- }
-
- }
-
-
- // 同步透析床位分区
- func SyncDivision(rdb *gorm.DB, org_id int64, hospital_id string) {
- // 第一步:根据机构id获取上次同步时间
- syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 55)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- sync_time = 0
- }
-
- //同步透析床位分区
- dm, _ := service.FindOrgDeviceZoneRecordData(org_id, sync_time, time.Now().Unix())
- var hdms []*sz.TempHdDivision
- for _, item := range dm {
- hdm := &sz.TempHdDivision{
- DivisionId: strconv.FormatInt(item.ID,10),
- HospitalId: hospital_id,
- DivisionName: item.Name,
- DivisionType: strconv.FormatInt(item.Type,10),
- CreateTime: time.Now(),
- UpdateTime: time.Now(),
- Sjscsj: time.Now(),
- Xgbz: strconv.FormatInt(0, 10),
- }
-
- hdms = append(hdms, hdm)
- }
-
- err := service.CreateHDDivision(hdms, rdb)
- if err == nil {
- // 第三步:同步成功后,添加同步记录
- upload := &sz.DataUpload{
- SyncType: 55,
- OrgId: org_id,
- SyncTime: time.Now().Unix(),
- SyncResultType: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- }
- err := service.CreateUploadRecord(upload)
- if err != nil {
- utils.ErrorLog("%v", err)
- }
- } else {
- //错误处理
-
- }
- }
-
- // 患者通路信息表
- func SyncAccess(rdb *gorm.DB, org_id int64, hospital_id string) {
- // 第一步:根据机构id获取上次同步时间
- syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 56)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- sync_time = 0
- }
-
- //同步员工信息
- patients, _ := service.FindOrgPatientData(org_id, sync_time, time.Now().Unix())
- var accessList []*sz.TempHdAccess
- for _, patient := range patients {
- before,_ := service.FindAssessmentBeforeDislysis(org_id,patient.ID)
- if before.ID > 0{
- access := &sz.TempHdAccess{
- AccessId : before.ID,
- HospitalId: hospital_id,
- PatientNk: strconv.FormatInt(before.PatientId, 10),
- AccessType: 1,
- AccessTypeName: "自体动静脉内瘘",
- AccessStatus: 1,
- SetupDate: time.Unix(patient.FirstDialysisDate, 0),
- FirstUseTime: time.Unix(patient.FirstDialysisDate, 0),
- CreateTime: time.Now(),
- UpdateTime: time.Now(),
- Sjscsj: time.Now(),
- Xgbz: 0,
- }
- accessList = append(accessList,access)
- }
- }
-
- if len(accessList) > 0 {
- err := service.CreateAccess(accessList, rdb)
- if err == nil {
- // 第三步:同步成功后,添加同步记录
- upload := &sz.DataUpload{
- SyncType: 56,
- OrgId: org_id,
- SyncTime: time.Now().Unix(),
- SyncResultType: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- }
- err := service.CreateUploadRecord(upload)
- if err != nil {
- utils.ErrorLog("%v", err)
- }
- } else {
- //错误处理
-
- }
- }
- }
-
- // 透析床位表
- func SyncSickbed(rdb *gorm.DB, org_id int64, hospital_id string) {
- // 第一步:根据机构id获取上次同步时间
- syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 57)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- sync_time = 0
- }
-
- //同步床位
- devices, _ := service.FindOrgDeviceNumber(org_id, sync_time, time.Now().Unix())
- var sickbedList []*sz.TempHdSickbed
- for _, device := range devices {
- sickbed := &sz.TempHdSickbed{
- SickbedNo : device.ID,
- HospitalId: hospital_id,
- DivisionId: strconv.FormatInt(device.ZoneId,10),
- SickbedCode: device.Number,
- SickbedType: "0",
- CreateTime: time.Now(),
- UpdateTime: time.Now(),
- Sjscsj: time.Now(),
- Xgbz: 0,
- }
- sickbedList = append(sickbedList,sickbed)
- }
-
- if len(sickbedList) > 0 {
- err := service.CreateSickbed(sickbedList, rdb)
- if err == nil {
- // 第三步:同步成功后,添加同步记录
- upload := &sz.DataUpload{
- SyncType: 57,
- OrgId: org_id,
- SyncTime: time.Now().Unix(),
- SyncResultType: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- }
- err := service.CreateUploadRecord(upload)
- if err != nil {
- utils.ErrorLog("%v", err)
- }
- } else {
- //错误处理
-
- }
- }
- }
-
- // 患者诊断信息表(T_HD_DIAGNOSIS)
- func SyncDiagnosis(rdb *gorm.DB, org_id int64, hospital_id string) {
- // 第一步:根据机构id获取上次同步时间
- syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 58)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- sync_time = 0
- }
-
- //同步患者
- patients, _ := service.FindOrgPatientData(org_id, sync_time, time.Now().Unix())
- var diagnosisList []*sz.TempHdDiagnosis
- for _, patient := range patients {
- diagnosis := &sz.TempHdDiagnosis{
- DiagnosisId : patient.ID,
- HospitalId: hospital_id,
- PatientNk: strconv.FormatInt(patient.ID, 10),
- DiagnosisTime: time.Unix(patient.CreatedTime, 0),
- DiagnosisType: "10",
- DiagnosisTypeItem: "1001",
- DiagnosisTypeDetail: "100113",
- CreateTime: time.Now(),
- UpdateTime: time.Now(),
- Sjscsj: time.Now(),
- Xgbz: 0,
- }
- diagnosisList = append(diagnosisList,diagnosis)
- }
-
- if len(diagnosisList) > 0 {
- err := service.CreateDiagnosis(diagnosisList, rdb)
- if err == nil {
- // 第三步:同步成功后,添加同步记录
- upload := &sz.DataUpload{
- SyncType: 58,
- OrgId: org_id,
- SyncTime: time.Now().Unix(),
- SyncResultType: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- }
- err := service.CreateUploadRecord(upload)
- if err != nil {
- utils.ErrorLog("%v", err)
- }
- } else {
- //错误处理
-
- }
- }
- }
-
- // 患者传染病检查记录表(T_HD_INFECTION
- func SyncInfection(rdb *gorm.DB, org_id int64, hospital_id string) {
- // 第一步:根据机构id获取上次同步时间
- syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 59)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- sync_time = 0
- }
-
- //同步患者
- patients, _ := service.FindOrgPatientDataOne(org_id)
- var infectionList []*sz.TempHdInfection
- for _, patient := range patients {
- // 查询有没有做传染病检查并返回检验检查时间
- inspections, _ := service.FindOrgInspectionGroupOne(org_id, sync_time, time.Now().Unix(),patient.ID)
- if len(inspections) > 0 {
- for _, insp := range inspections {
- inspection_arr ,_:= service.FindOrgInspectionGroupTwo(org_id,insp.InspectDate,patient.ID)
- if len(inspection_arr) > 0 {
- infection := &sz.TempHdInfection{
- Sn : strconv.FormatInt(patient.ID,10),
- HospitalId: hospital_id,
- PatientNk: strconv.FormatInt(patient.ID, 10),
- Hbv: 0,
- Hcv: 0,
- Rpr: 0,
- Hiv: 0,
- Hbsag: 9,
- Hbsab: 9,
- Hbeag: 9,
- Hbeab: 9,
- Hbcab: 9,
- CheckDate: time.Unix(patient.CreatedTime, 0),
- DoctorId: strconv.FormatInt(patient.RegistrarsId,10),
- CreateTime: time.Now(),
- Sjscsj: time.Now(),
- Xgbz: 0,
- }
-
-
- for _ , infectionDiseases := range inspection_arr{
- if infectionDiseases.ItemId == 60 {
- infection.Hcv = 0
- if infectionDiseases.InspectValue == "阳性" {
- infection.Hcv = 1
- }
- }
- if infectionDiseases.ItemId == 62 {
- infection.Hbsag = 0
- if infectionDiseases.InspectValue == "阳性" {
- infection.Hbsag = 1
- }
- }
-
- if infectionDiseases.ItemId == 63 {
- infection.Hbsab = 0
- if infectionDiseases.InspectValue == "阳性" {
- infection.Hbsab = 1
- }
- }
-
- if infectionDiseases.ItemId == 64 {
- infection.Hbeag = 0
- if infectionDiseases.InspectValue == "阳性" {
- infection.Hbeag = 1
- }
- }
-
- if infectionDiseases.ItemId == 65 {
- infection.Hbeab = 0
- if infectionDiseases.InspectValue == "阳性" {
- infection.Hbeab = 1
- }
- }
-
- if infectionDiseases.ItemId == 66 {
- infection.Hbcab = 0
- if infectionDiseases.InspectValue == "阳性" {
- infection.Hbcab = 1
- }
- }
-
- if infectionDiseases.ItemId == 111 {
- infection.Hiv = 0
- if infectionDiseases.InspectValue == "阳性" {
- infection.Hiv = 1
- }
- }
-
- if infectionDiseases.ItemId == 112 {
- infection.Rpr = 0
- if infectionDiseases.InspectValue == "阳性" {
- infection.Rpr = 1
- }
- }
-
- if infectionDiseases.ItemId == 178 {
- infection.Hbv = 0
- if infectionDiseases.InspectValue == "阳性" {
- infection.Hbv = 1
- }
- }
-
- if infectionDiseases.ItemId == 179 {
- infection.Hcv = 0
- if infectionDiseases.InspectValue == "阳性" {
- infection.Hcv = 1
- }
- }
-
- }
- infectionList = append(infectionList,infection)
- }
- }
- }
- }
-
- if len(infectionList) > 0 {
- err := service.CreateInfection(infectionList, rdb)
- if err == nil {
- // 第三步:同步成功后,添加同步记录
- upload := &sz.DataUpload{
- SyncType: 59,
- OrgId: org_id,
- SyncTime: time.Now().Unix(),
- SyncResultType: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- }
- err := service.CreateUploadRecord(upload)
- if err != nil {
- utils.ErrorLog("%v", err)
- }
- } else {
- //错误处理
-
- }
- }
- }
-
-
- // 透析并发症记录表(T_HD_COMPLICATION)
- func SyncComplication(rdb *gorm.DB, org_id int64, hospital_id string) {
- // 第一步:根据机构id获取上次同步时间
- syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 60)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- sync_time = 0
- }
-
- //同步监测记录
- var complicationList []*sz.TempHdComplication
- monitors, _ := service.FindOrgMonitorRecordByLike(org_id,"%肌肉痉挛%", sync_time, time.Now().Unix())
- for _, monitor := range monitors {
- complication := &sz.TempHdComplication{
- Sn : strconv.FormatInt(monitor.ID,10),
- HospitalId : hospital_id,
- PatientNk : strconv.FormatInt(monitor.PatientId, 10),
- DialysisId : monitor.DialysisOrderId,
- MonitorId : monitor.ID,
- NeopathyTime: 1,
- NeopathyType: "3",
- NeopathyDesc: monitor.Symptom,
- CreateTime: time.Unix(monitor.CreatedTime, 0),
- Sjscsj: time.Now(),
- Xgbz: 0,
- }
- complicationList = append(complicationList,complication)
- }
-
- monitorones, _ := service.FindOrgMonitorRecordByLike(org_id,"%胸痛%", sync_time, time.Now().Unix())
- for _, monitor := range monitorones {
- complicationone := &sz.TempHdComplication{
- Sn : strconv.FormatInt(monitor.ID,10),
- HospitalId : hospital_id,
- PatientNk : strconv.FormatInt(monitor.PatientId, 10),
- DialysisId : monitor.DialysisOrderId,
- MonitorId : monitor.ID,
- NeopathyTime: 1,
- NeopathyType: "6",
- NeopathyDesc: monitor.Symptom,
- CreateTime: time.Unix(monitor.CreatedTime, 0),
- Sjscsj: time.Now(),
- Xgbz: 0,
- }
- complicationList = append(complicationList,complicationone)
- }
-
- monitortwos, _ := service.FindOrgMonitorRecordByLike(org_id,"%恶心%", sync_time, time.Now().Unix())
- for _, monitor := range monitortwos {
- complicationtwo := &sz.TempHdComplication{
- Sn : strconv.FormatInt(monitor.ID,10),
- HospitalId : hospital_id,
- PatientNk : strconv.FormatInt(monitor.PatientId, 10),
- DialysisId : monitor.DialysisOrderId,
- MonitorId : monitor.ID,
- NeopathyTime: 1,
- NeopathyType: "7",
- NeopathyDesc: monitor.Symptom,
- CreateTime: time.Unix(monitor.CreatedTime, 0),
- Sjscsj: time.Now(),
- Xgbz: 0,
- }
- complicationList = append(complicationList,complicationtwo)
- }
-
- monitorfours, _ := service.FindOrgMonitorRecordByLike(org_id,"%头痛%", sync_time, time.Now().Unix())
- for _, monitor := range monitorfours {
- complicationfour := &sz.TempHdComplication{
- Sn : strconv.FormatInt(monitor.ID,10),
- HospitalId : hospital_id,
- PatientNk : strconv.FormatInt(monitor.PatientId, 10),
- DialysisId : monitor.DialysisOrderId,
- MonitorId : monitor.ID,
- NeopathyTime: 1,
- NeopathyType: "11",
- NeopathyDesc: monitor.Symptom,
- CreateTime: time.Unix(monitor.CreatedTime, 0),
- Sjscsj: time.Now(),
- Xgbz: 0,
- }
- complicationList = append(complicationList,complicationfour)
- }
-
- monitorthrees, _ := service.FindOrgMonitorRecordByLike(org_id,"%发热%", sync_time, time.Now().Unix())
- for _, monitor := range monitorthrees {
- complicationthree := &sz.TempHdComplication{
- Sn : strconv.FormatInt(monitor.ID,10),
- HospitalId : hospital_id,
- PatientNk : strconv.FormatInt(monitor.PatientId, 10),
- DialysisId : monitor.DialysisOrderId,
- MonitorId : monitor.ID,
- NeopathyTime: 1,
- NeopathyType: "15",
- NeopathyDesc: monitor.Symptom,
- CreateTime: time.Unix(monitor.CreatedTime, 0),
- Sjscsj: time.Now(),
- Xgbz: 0,
- }
- complicationList = append(complicationList,complicationthree)
- }
-
-
- if len(complicationList) > 0 {
- err := service.CreateComplication(complicationList, rdb)
- if err == nil {
- // 第三步:同步成功后,添加同步记录
- upload := &sz.DataUpload{
- SyncType: 60,
- OrgId: org_id,
- SyncTime: time.Now().Unix(),
- SyncResultType: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- }
- err := service.CreateUploadRecord(upload)
- if err != nil {
- utils.ErrorLog("%v", err)
- }
- } else {
- //错误处理
-
- }
- }
- }
-
- // 血透患者检测结果表(T_HD_LIS_REPORT)
- func SyncLisReport(rdb *gorm.DB, org_id int64, hospital_id string) {
- // 第一步:根据机构id获取上次同步时间
- syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 61)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- sync_time = 0
- }
-
- //同步监测记录
- inspections, _ := service.FindOrgInspection(org_id, sync_time, time.Now().Unix())
- var lisReportList []*sz.TempHdLisReport
- tempFlag := 1
- for _, inspection := range inspections {
- tempFlag = 1
- fmt.Println("1")
- for _,tempReport := range lisReportList {
- // fmt.Println("2")
- if tempReport.ReportDate == time.Unix(inspection.InspectDate,0) && tempReport.ApplicationType == strconv.FormatInt(inspection.ProjectId,10) && tempReport.PatientNk == strconv.FormatInt(inspection.PatientId,10) {
- tempFlag = 0
- break
- } else {
- continue
- }
- }
- fmt.Println("3")
- if tempFlag == 1 {
- lisReport := &sz.TempHdLisReport{
- LabSno : strconv.FormatInt(inspection.InspectType,10) + strconv.FormatInt(inspection.ProjectId,10),
- HospitalId : hospital_id,
- PatientNk : strconv.FormatInt(inspection.PatientId, 10),
- ReportDate : time.Unix(inspection.InspectDate, 0),
- CheckDate : "1",
- JzNo : inspection.Patients.AdmissionNumber,
- MzFlag : "1",
- ZyNo : "-",
- MzNo : inspection.Patients.AdmissionNumber,
- DepartmentCode : "10035",
- DepartmentName : "血透中心",
- CardNo : inspection.Patients.IdCardNo,
- CardType : "9",
- PatientName : inspection.Patients.Name,
- DepCode : "A03.05",
- DepName : "血透中心",
- InspectedType : "1",
- ReportCategry : inspection.ProjectName,
- ApplicationName : inspection.ProjectName,
- ApplicationType : strconv.FormatInt(inspection.ProjectId,10),
- CheckName : inspection.ProjectName,
- CheckItemName : inspection.ItemName,
- CheckItemCode : strconv.FormatInt(inspection.ItemId,10),
- RecordCcount : 0,
- CheckResult : inspection.InspectValue,
- DiagnoseName : "-",
- CreateTime : time.Unix(inspection.CreatedTime, 0),
- Sjscsj: time.Now(),
- Xgbz: 0,
- }
- lisReportList = append(lisReportList,lisReport)
- } else {
- continue
- }
- }
-
- if len(lisReportList) > 0 {
- err := service.CreateLisReport(lisReportList, rdb)
- if err == nil {
- // 第三步:同步成功后,添加同步记录
- upload := &sz.DataUpload{
- SyncType: 61,
- OrgId: org_id,
- SyncTime: time.Now().Unix(),
- SyncResultType: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- }
- err := service.CreateUploadRecord(upload)
- if err != nil {
- utils.ErrorLog("%v", err)
- }
- } else {
- //错误处理
-
- }
- }
- }
-
- // 血透患者检验结果指标表(T_HD_LIS_INDICATORS)
- func SyncLisIndicators(rdb *gorm.DB, org_id int64, hospital_id string) {
- // 第一步:根据机构id获取上次同步时间
- syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 62)
- var sync_time int64
- if syncLastInfo.ID > 0 {
- sync_time = syncLastInfo.SyncTime
- } else {
- sync_time = 0
- }
-
- //同步监测记录
- inspections , _ := service.FindOrgInspectionReference(org_id, sync_time, time.Now().Unix())
- var lisIndicatorsList []*sz.TempHdLisIndicators
-
- for _, inspection := range inspections {
- lisIndicators := &sz.TempHdLisIndicators{
- InspectedResultNo : strconv.FormatInt(inspection.ID,10),
- HospitalId : hospital_id,
- LabSno : strconv.FormatInt(inspection.InspectType,10) + strconv.FormatInt(inspection.ProjectId,10),
- ReportDate : time.Unix(inspection.InspectDate, 0),
- CheckDate : time.Unix(inspection.InspectDate, 0),
- InspectedIndicate : inspection.ProjectName,
- InspectedItemEnName : strconv.FormatInt(inspection.ItemId,10),
- InspectedItemCnName : inspection.ItemName,
- InspectedResultDesc : inspection.InspectValue,
- InspectedResultValue : inspection.InspectValue,
- InspectedResultUnit : inspection.XtInspectionReference.Unit,
- RefRange : "-",
- UnitType : inspection.XtInspectionReference.Unit,
- InspectedResult : 5,
- CreateTime : time.Unix(inspection.CreatedTime, 0),
- Sjscsj: time.Now(),
- Xgbz: 0,
- }
- if len(inspection.XtInspectionReference.Unit) == 0 {
- lisIndicators.InspectedResultUnit = "-"
- lisIndicators.UnitType = "-"
- }
-
- if inspection.XtInspectionReference.RangeType ==1 {
- lisIndicators.RefRange = inspection.XtInspectionReference.RangeMin + "-" + inspection.XtInspectionReference.RangeMax
- } else {
- if len(inspection.XtInspectionReference.RangeOptions) == 0 {
- lisIndicators.RefRange = "-"
- } else {
- lisIndicators.RefRange = inspection.XtInspectionReference.RangeOptions
- }
- }
- lisIndicatorsList = append(lisIndicatorsList,lisIndicators)
- }
-
- if len(lisIndicatorsList) > 0 {
- err := service.CreateLisIndicators(lisIndicatorsList, rdb)
- if err == nil {
- // 第三步:同步成功后,添加同步记录
- upload := &sz.DataUpload{
- SyncType: 62,
- OrgId: org_id,
- SyncTime: time.Now().Unix(),
- SyncResultType: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- }
- err := service.CreateUploadRecord(upload)
- if err != nil {
- utils.ErrorLog("%v", err)
- }
- } else {
- //错误处理
-
- }
- }
- }
|