Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map OMOP data to inpatient_episodes table #28

Open
razekmh opened this issue Sep 26, 2024 · 3 comments
Open

Map OMOP data to inpatient_episodes table #28

razekmh opened this issue Sep 26, 2024 · 3 comments
Assignees
Labels
design Design, scoping and ToR work

Comments

@razekmh
Copy link

razekmh commented Sep 26, 2024

Extract data from the example OMOP data to fill the inpatient_episodes table from the validate article. This is a split from #17

Please feel free to assign yourself to the issue. Please the respective branch for development.

@razekmh razekmh added the design Design, scoping and ToR work label Sep 26, 2024
@AngharadGreen AngharadGreen self-assigned this Oct 2, 2024
@AngharadGreen
Copy link

AngharadGreen commented Oct 4, 2024

  • For this issue I have used the updated OMOK v0.3.0 to generate OMOP mockVisitOccurrence and mockProcedureOccurrence tables as these tables can be mapped to the RAMSES inpatient_episodes table.
  • For the RAMSES inpatient_episodes table the variables admission_method, last_episode_in_encounter, consultant_code and main_specialty_code are difficult to map to the OMOP CDM - I am looking into this in more detail to determine what OMOP tables would be appropriate to map to, as these variables must not contain missing data.

@AngharadGreen
Copy link

AngharadGreen commented Dec 13, 2024

Mapping synthetic data from OMOK to the Ramses inpatient_episodes table

I put together a summary presentation going over mapping OMOP CDM to the data frame accepted by Ramses Mapping OMOP to rameses.pptx

This summary diagram shows how the inpatient_episodes table could map to the data within OMOP:
image

Following this summary I will now try to reproduce the inpatient_episodes table from data generated from OMOK:

library(Ramses)
library(omock)
library(dplyr)
library(AMR)
library(DBI)

# Connect to ramses local database

ramses_db <- connect_local_database("ramses-db.duckdb")

# View and check structure of the ramses inpatient_episodes table
View(inpatient_episodes)
str(inpatient_episodes)

# generate mock OMOP data from OMOK v0.3.0

cdm <- mockCdmReference() |>
  mockPerson(nPerson = 10) |>
  mockObservationPeriod() |>
  mockConditionOccurrence() |>
  mockDrugExposure() |>
  mockMeasurement() |>
  mockDeath() |>
  mockProcedureOccurrence() |>
  mockObservation() |>
  mockVisitOccurrence() |>
  mockVocabularyTables()

#Extract the visit_occurrence table from mock omok database
omop_visit_occurrence <- cdm$visit_occurrence

#View and check structure of the omop_visit_occurrence table
View(omop_visit_occurrence)
str(omop_visit_occurrence)


#Extract the procedure_occurrence table from mock omok database
omop_procedure_occurrence <- cdm$procedure_occurrence

#View and check structure of the omop_procedure_occurence table
View(omop_procedure_occurrence)
str(omop_procedure_occurrence)

#Merge dataframes omop_visit_occurrence and omop_procedure_occurrence based on column visit_occurrence_id

Merged_df <- merge(omop_visit_occurrence, omop_procedure_occurrence, by="visit_occurrence_id")
View(Merged_df)

# If need to save this use write.csv(Merged_df,'Merged_df.csv', row.names = FALSE)

# Map OMOP fields to RAMSES fields

omop_to_ramses_inpatient_episodes <- Merged_df %>%
  transmute(
    #Mapping OMOP visit_occurrence_table person_id to RAMSES patient_id
    patient_id = person_id.x,
    #Mapping OMOP visit_occurrence_table visit_occurrence_id to RAMSES encounter_id
    encounter_id = visit_occurrence_id,
    #Mapping OMOP visit_occurrence_table visit_start_date to RAMSES admission_date
    admission_date = visit_start_date,
    #Mapping OMOP visit_occurrence_table visit_end_date to RAMSES discharge_date
    discharge_date = visit_end_date,
    #Mapping OMOP procedure_occurrence_table procedure_occurrence_id to RAMSES episode_number 
    episode_number = procedure_occurrence_id,
    #Mapping OMOP procedure_occurrence_table procedure_date to RAMSES episode_start
    episode_start = procedure_date,
    #Mapping OMOP procedure_occurrence_table procedure_end_date to RAMSES episode_end
    episode_end = procedure_end_date)

# The ramses columns admission_method, last_episode_in_encounter, consultant_code and main_specialty_code are not easily mapped to OMOP data from OMOCK so synthetic data will be added here for now: 

# Add in column admission_method to omop_to_ramses_inpatient_episodes
omop_to_ramses_inpatient_episodes$admission_method <- c("1", "2", "1", "1", "2", "1", "2", "1", "2", "1", "1", "1", "2", "2", "2", "2", "1", "1", "1", "1", "1", "2", "1", "1", "2", "1", "2", "1", "2", "1", "1", "1", "2", "2", "2", "2", "1", "1", "1", "1", "1", "2", "1", "1", "2", "1", "2", "1", "2", "1")

# Add in column last_episode_in_encounter to omop_to_ramses_inpatient_episodes
omop_to_ramses_inpatient_episodes$last_episode_in_encounter <- c("2", "2", "1", "2", "1", "2", "2", "2", "1", "1", "1", "1", "2", "2", "2", "2", "1", "2", "1", "2", "2", "2", "1", "2", "1", "2", "2", "2", "1", "1", "1", "1", "2", "2", "2", "2", "1", "2", "1", "2", "2", "2", "1", "2", "1", "2", "2", "2", "1", "1")

# Add in column consultant_code omop_to_ramses_inpatient_episodes
omop_to_ramses_inpatient_episodes$consultant_code <- c("C1000003", "C1000004", "C1000005", "C1000006", "C1000007", "C1000008", "C1000009", "C1000010", "C1000011", "C1000012", "C1000013", "C1000014", "C1000015", "C1000016", "C1000017", "C1000018", "C1000019", "C1000020", "C1000021", "C1000022", "C1000023", "C1000024", "C1000025", "C1000026", "C1000027", "C1000028", "C1000029", "C1000030", "C1000031", "C1000032", "C1000033", "C1000034", "C1000035", "C1000036", "C1000037", "C1000038", "C1000039", "C1000040", "C1000041", "C1000042", "C1000043", "C1000044", "C1000045", "C1000046", "C1000047", "C1000048", "C1000049", "C1000050", "C1000051", "C1000052")

# Add in column main_specialty_code to omop_to_ramses_inpatient_episodes
omop_to_ramses_inpatient_episodes$main_specialty_code <- c("100", "101", "107", "110", "120", "130", "140", "141", "142", "143", "145", "146", "147", "148", "149", "150", "160", "170", "171", "191", "180", "190", "192", "200", "300", "301", "302", "303", "304", "305", "310", "311", "312", "313", "314", "315", "317", "320", "321", "325", "326", "330", "340", "350", "352", "360", "361", "370", "371", "400")

#View and check structure of the omop_to_ramses_inpatient_episodes
View(omop_to_ramses_inpatient_episodes)
str(omop_to_ramses_inpatient_episodes)

#Extract the person table from mock omok database
omop_person <- cdm$person

#View and check structure of the omop_person table
View(omop_person)
str(omop_person)

omop_to_ramses_person <- omop_person %>%
  transmute(
    #Mapping OMOP visit_occurrence_table person_id to RAMSES patient_id
    patient_id = person_id)

#View and check structure of the omop_person table
View(omop_to_ramses_person)
str(omop_to_ramses_person)

#Validate omop_to_ramses_inpatient_episodes
validate_inpatient_episodes(patients = omop_to_ramses_person,
                            episodes = omop_to_ramses_inpatient_episodes)

[1] FALSE
Warning messages:
1: Some `episodes` fall outside hospitalisation dates. 
2: Total bed days calculated from `episodes` does notmatch admission duration.
 Bed days may be incorrect. 
3: Some hospital encounters have gaps between `episodes`.
Bed days may be underestimated. 
4: Hospital `episodes` must not overlap.

@AngharadGreen
Copy link

AngharadGreen commented Dec 13, 2024

I will now use the new OMOP extract to map to the Ramses inpatient_episodes table

  • The in_patient_episodes table represents a set of simulated records of finished consultant episodes for 202 patients, detailing all dates and times of admission, discharge, episode start and end, clinician, and clinical specialty.
  • Ramses is designed around the notion of hospital encounters identified by variable encounter_id, which correspond to the window from the time a patient is admitted to the time a patient is discharged.
  • In addition, Ramses use subdivisions of hospital encounters called episodes of care, which designate a continuous period of inpatient care under the responsibility of a department, specialty, or clinical team.
  • All hospital encounters consist of at least one episode of care.
  • Episodes of care are used to calculate bed-days as well as rates of infection, prescribing and other stewardship metrics for individual specialties and teams of clinicians.
  • Hospital encounters and episodes of care are recorded in a single table in which every row corresponds to one episode of care.
  • Dates of admissions and episode start/end must be valid:
  1. there must be no overlap between admissions or between episodes
  2. there must be no gap between episodes in an admission.
Ramses OMOP
patient_id person_id
encounter_id visit_occurrence_id (visit_occurrence)
admission_method
admission_date visit_start_date (visit occurrence)
discharge_date visit_end_date (visit_occurrence)
episode_number procedure_occurrence_id (procedure_occurrence)
last_episode_in_encounter
episode_start procedure_date
episode_end
consultant_code
main_specialty_code

Ramses also relies on validate_inpatient_episodes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Design, scoping and ToR work
Projects
None yet
Development

No branches or pull requests

2 participants