[58c332]: / RadETL / R / radiologyOccurrenceDateTime_OccurrenceTable.R

Download this file

46 lines (43 with data), 2.4 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#' 'radiologyOccurrenceDateTime'
#'
#' radiologyOccurrenceDateTime function indicates date and time of each occurrences are taken
#'
#'
#' @param DICOMList you can put it like this and then run the function : DICOMList<-DICOMHeaderList(DICOMFolderPath)
#' @import dplyr
#' @importFrom magrittr "%>%"
#'
#'
#' @return A dataframe indicating date and time of each occurrences are taken
#' @examples
#' DICOMList<-DICOMHeaderList(DICOMFolderPath)
#' radiologyOccurrenceDateTime(DICOMList)
#' @export
#radiologyOccurrenceDateTime
radiologyOccurrenceDateTime<-function(DICOMList){
radiologyOccurrenceDateTime<-lapply(DICOMList, function(x){
studyDate<-as.character(x[[1]] %>% filter(name %in% c('StudyDate')) %>% select(value))
studyTime<-as.character(x[[1]] %>% filter(name %in% c('StudyTime')) %>% select(value))
if(studyDate=="character(0)" | studyDate==""){
studyDate='NA'
}
if(studyTime=="character(0)" | studyTime==""){
studyTime='NA'
}
studyDateTime<-paste(studyDate, studyTime, sep = '')
studyDateTime<-gsub("NA", '', studyDateTime)
studyDateTime<-ifelse(is.na(as.POSIXct(studyDateTime, format = '%Y%m%d%H%M%S',origin = "1970-01-01",tz ="UTC"))==F, as.character(as.POSIXct(studyDateTime, format = '%Y%m%d%H%M%S',origin = "1970-01-01",tz ="UTC")), ifelse(is.na(as.POSIXct(studyDateTime, format = '%Y%m%d',origin = "1970-01-01",tz ="UTC"))==F, as.character(as.POSIXct(studyDate, format = '%Y%m%d',origin = "1970-01-01",tz ="UTC")), 'NA'))
return(studyDateTime)
})
radiologyOccurrenceDateTime<-do.call(rbind, radiologyOccurrenceDateTime)
radiologyOccurrenceDateTime<-as.data.frame(radiologyOccurrenceDateTime)
colnames(radiologyOccurrenceDateTime)<-'studyDateTime'
radiologyOccurrenceDateTime<-cbind(radiologyOccurrenceId(DICOMList), radiologyOccurrenceDateTime)
radiologyOccurrenceDateTime<-as.data.frame(radiologyOccurrenceDateTime %>% group_by(radiologyOccurrenceId) %>% distinct(studyDateTime))
radiologyOccurrenceDateTime<-split(radiologyOccurrenceDateTime, radiologyOccurrenceDateTime$radiologyOccurrenceId)
radiologyOccurrenceDateTime<-lapply(radiologyOccurrenceDateTime, function(x){
as.data.frame(x[c(1),])
})
radiologyOccurrenceDateTime<-data.frame(do.call(rbind, radiologyOccurrenceDateTime), row.names = NULL)
return(radiologyOccurrenceDateTime)
}