其想法如下。每个病人都有一个独特的病人身份,我们称之为hidenic_id。然而,这个病人可能会多次住院。另一方面,每个条目都有唯一的emtek_id。
病人110380于2001年4月14日入院11:08,后经医院转院,于2001年4月24日18:16出院。该病人于2001年11月5日23:24再次入院,因为他现在有不同的emtek_id。他于2001年5月25日16:26出院。因此,您需要通过检查日期来分配正确的emtek_ids。如果合并文件中的日期在接纳和释放时间内(或非常接近的时间,如24小时),我们可以分配该emtek_id。
如何使用hidenic_id为条目分配不同的emtek_IDs并承认时间?
发布于 2020-08-13 18:30:06
我有一些值得分享的想法。
首先,从emtek_id和date中创建hidenic_id。第二,使emtek_id具有解析的逻辑,例如,emtek_id@dataTime。第三,使数据库成为一个全局向量。根据内存限制,必须有一个比这更快的方法,但它可能会给您一些想法。
主要问题是处理NA值和不正确的hidenic_id,验证hidenic_id(s),如果没有前面的字符(这将是一个快速修复),则填充ID。最后,如何处理不正确但不是NA/null的输入?例如,假设您输入的是"ID“而不是"ID12345",您想要将它作为一个调用来分配一个新值或为一个正确的输入XOR NA值提供提示吗?我假设您只提供正确的ID输入或NA值,但这是我的琐碎假设。
这里有一些伪代码来开始这个想法。你选择如何存储数据(例如。然后使用data.table::fread()文件:
#this file's name is "make.hidenic_id.R"
library(data.table)
library(stringr)
set.seed(101)
#one might one a backup written, perhaps conditionally updating it every hour or so.
database.hidenic_id <<-data.table::fread("database.filename.hidenic_id.csv")
database.emtek_id <<-data.table::fread("database.filename.emtek_id.csv")
make.hidenic_Id = function(in.hidenic_id){
if(is.na(in.hidenic_id) | !(in.hidenic_id %in% database.hidenic_id)){
new.hidenic_id=NA
#conditionally make new hidenic_id
while( new.hidenic_id %in% database.hidenic_id){
new.hidenic_id = paste0("ID",str_pad(sample.int(99999, 1),5,pad=0))
}
#make new emtek_id
new.emtek_id <- paste0(new.hidenic_id, sep="@", str_sub(Sys.time(),1,16))
#update databases; e.g., c(database.emtek_id, new.emtek_id)
database.hidenic_id <<- c(database.hidenic_id, new.hidenic_id)
database.emtek_id <<- c(database.emtek_id, new.emtek_id)
}else{
new.emtek_id <- paste0(in.hidenic_id, sep="@", str_sub(Sys.time(),1,16))
# update database.emtek_id
database.emtek_id <<- c(database.emtek_id, new.emtek_id)
}
return(new.emtek_id)
}
temp = readline(prompt="Enter hidenic_id OR type \"NA\": ")
data.table::fwrite(database.emtek_id, "database.filename.emtek_id.csv")
data.table::fwrite(database.hidenic_id,"database.filename.hidenic_id.csv")
调用该文件
source("make.hidenic_id.R")
在管理糟糕的输入数据或优化搜索方面,我没有做很多“良好实践”的事情,但这是一个强有力的开端。其他一些好的做法是使用更长的整数或一个不同的前导字符串,但您从未说过我们可以使用输入值来生成ID。
你可以说这是受人口普查的启发,因为每一个地理ID变量都是一个庞大的字符串。
发布于 2013-06-21 17:00:36
我对你的问题很感兴趣,所以我创建了一些模拟数据,试图解决这个问题,但我自己遇到了一些困惑,然后发布了我的问题,我认为这是你的问题,但更笼统。您可以在这里看到响应:How can I tell if a time point exists between a set of before and after times
我的帖子产生了我相信的东西,这是你所开始的,被检查过的答案是我相信你在寻找的。完整的代码如下。您需要安装zoo
和IRanges
。而且,我是在2.15.3版中这样做的。IRanges
在3.0.0中没有正确安装。
## package installation
source("http://bioconductor.org/biocLite.R")
biocLite("IRanges")
install.packages("zoo")
## generate the emtek and hidenic file data
library(zoo)
date_string <- paste("2001", sample(12, 10, 3), sample(28,10), sep = "-")
time_string <- c("23:03:20", "22:29:56", "01:03:30", "18:21:03", "16:56:26",
"23:03:20", "22:29:56", "01:03:30", "18:21:03", "16:56:26")
entry_emtek <- strptime(paste(date_string, time_string), "%Y-%m-%d %H:%M:%S")
entry_emtek <- entry_emtek[order(entry_emtek)]
exit_emtek <- entry_emtek + 3600 * 24
emtek_file <- data.frame(emtek_id = 1:10, entry_emtek, exit_emtek)
hidenic_id <- 110380:110479
date_string <- paste("2001", sample(12, 100, replace = TRUE), sample(28,100, replace = T), sep = "-")
time_string <- rep(c("23:03:20", "22:29:56", "01:03:30", "18:21:03", "16:56:26",
"23:03:20", "22:29:56", "01:03:30", "18:21:03", "16:56:26"),10)
hidenic_time <- strptime(paste(date_string, time_string), "%Y-%m-%d %H:%M:%S")
hidenic_time <- hidenic_time[order(hidenic_time)]
hidenic_file <- data.frame(hidenic_id, hidenic_time)
## Find the intersection of emtek and hidenic times. This part was done by user: agstudy
library(IRanges)
## create a time intervals
subject <- IRanges(as.numeric(emtek_file$entry_emtek),
as.numeric(emtek_file$exit_emtek))
## create a time intervals (start=end here)
query <- IRanges(as.numeric(hidenic_file$hidenic_time),
as.numeric(hidenic_file$hidenic_time))
## find overlaps and extract rows (both time point and intervals)
emt.ids <- subjectHits(findOverlaps(query,subject))
hid.ids <- queryHits(findOverlaps(query,subject))
cbind(hidenic_file[hid.ids,],emtek_file[emt.ids,])
https://stackoverflow.com/questions/17222981
复制相似问题