Skip to content

Commit

Permalink
Merge pull request #41 from OHDSI/unit_tests_OPTUM_PANTHER
Browse files Browse the repository at this point in the history
fix unit test for optum_panther
  • Loading branch information
bradanton authored Feb 15, 2024
2 parents 49d7b5b + bc8d7a4 commit 075acdb
Show file tree
Hide file tree
Showing 20 changed files with 18,311 additions and 43,918 deletions.
149 changes: 102 additions & 47 deletions docs/OPTUM_PANTHER/Test Cases/R/ConditionOccurrenceTests.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,8 @@ createConditionOccurrenceTests <- function () {
# DIAGNOSIS
######################################


patient <- createPatient();
declareTest("Diagnosis without ''Diagnosis of'' status is not loaded", source_pid = patient$ptid, cdm_pid = patient$person_id)
add_patient(ptid=patient$ptid, birth_yr = 1950, gender = 'Male',
first_month_active = '200701', last_month_active = '201001')
add_diagnosis(ptid=patient$ptid, diagnosis_status = 'Family history of', diagnosis_cd = '7061',
diagnosis_cd_type = 'ICD9', diag_date = '2009-01-01')
expect_no_condition_occurrence(person_id = patient$person_id)


patient <- createPatient();
declareTest("Test diag_date to condition_start_date", source_pid = patient$ptid, cdm_pid = patient$person_id)
declareTest("Test diag_date to condition_start_date", id = patient$person_id)
add_patient(ptid=patient$ptid, birth_yr = 1950, gender = 'Male',
first_month_active = '200701', last_month_active = '201001')
add_diagnosis(ptid=patient$ptid, diagnosis_status = 'Diagnosis of', diagnosis_cd = '7061',
Expand All @@ -24,7 +14,7 @@ createConditionOccurrenceTests <- function () {


patient <- createPatient();
declareTest("Test diagnosis code type ICD9", source_pid = patient$ptid, cdm_pid = patient$person_id)
declareTest("Test diagnosis code type ICD9", id = patient$person_id)
enc <- createEncounter();
add_patient(ptid=patient$ptid, birth_yr = 1950, gender = 'Male',
first_month_active = '200701', last_month_active = '201001')
Expand All @@ -34,37 +24,100 @@ createConditionOccurrenceTests <- function () {


patient <- createPatient();
declareTest("Test diagnosis code type ICD10", source_pid = patient$ptid, cdm_pid = patient$person_id)
declareTest("Test diagnosis code type ICD10", id = patient$person_id)
enc <- createEncounter();
add_patient(ptid=patient$ptid, birth_yr = 1950, gender = 'Male',
first_month_active = '200701', last_month_active = '201001')
add_diagnosis(ptid=patient$ptid, diagnosis_status = 'Diagnosis of', diagnosis_cd = 'H44.611',
add_diagnosis(ptid=patient$ptid, diagnosis_status = 'Diagnosis of', diagnosis_cd = 'H44611',
diagnosis_cd_type = 'ICD10', diag_date = '2009-01-01')
expect_condition_occurrence(person_id = patient$person_id, condition_concept_id = 381850, condition_source_value = 'H44.611')
expect_condition_occurrence(person_id = patient$person_id, condition_concept_id = 381850, condition_source_value = 'H44611')


patient <- createPatient();
declareTest("Test primary diagnosis to condition_type_concept_id", source_pid = patient$ptid, cdm_pid = patient$person_id)
declareTest("Test primary admission diagnosis to condition_status_concept_id", id = patient$person_id)
enc <- createEncounter();
add_patient(ptid=patient$ptid, birth_yr = 1950, gender = 'Male',
first_month_active = '200701', last_month_active = '201001')
add_diagnosis(ptid=patient$ptid, diagnosis_status = 'Diagnosis of', diagnosis_cd = '7061',
diagnosis_cd_type = 'ICD9', diag_date = '2009-01-01', primary_diagnosis = '1')
expect_condition_occurrence(person_id = patient$person_id, condition_type_concept_id = 44786627)

diagnosis_cd_type = 'ICD9', diag_date = '2009-01-01', primary_diagnosis = '1', admitting_diagnosis = '1')
expect_condition_occurrence(person_id = patient$person_id, condition_status_concept_id = 32901)

patient <- createPatient();
declareTest("Test non-primary diagnosis to condition_type_concept_id", source_pid = patient$ptid, cdm_pid = patient$person_id)
declareTest("Test primary diagnosis to condition_status_concept_id", id = patient$person_id)
enc <- createEncounter();
add_patient(ptid=patient$ptid, birth_yr = 1950, gender = 'Male',
first_month_active = '200701', last_month_active = '201001')
add_diagnosis(ptid=patient$ptid, diagnosis_status = 'Diagnosis of', diagnosis_cd = '7061',
diagnosis_cd_type = 'ICD9', diag_date = '2009-01-01', primary_diagnosis = '1', admitting_diagnosis = '0', discharge_diagnosis = '0')
expect_condition_occurrence(person_id = patient$person_id, condition_status_concept_id = 32902)

patient <- createPatient();
declareTest("Test primary discharge diagnosis to condition_status_concept_id", id = patient$person_id)
enc <- createEncounter();
add_patient(ptid=patient$ptid, birth_yr = 1950, gender = 'Male',
first_month_active = '200701', last_month_active = '201001')
add_diagnosis(ptid=patient$ptid, diagnosis_status = 'Diagnosis of', diagnosis_cd = '7061',
diagnosis_cd_type = 'ICD9', diag_date = '2009-01-01', primary_diagnosis = '1', admitting_diagnosis = '0', discharge_diagnosis = '1')
expect_condition_occurrence(person_id = patient$person_id, condition_status_concept_id = 32903)


patient <- createPatient();
declareTest("Test preliminary or primary discharge diagnosis to condition_status_concept_id, should be preliminary diagnosis", id = patient$person_id)
enc <- createEncounter();
add_patient(ptid=patient$ptid, birth_yr = 1950, gender = 'Male',
first_month_active = '200701', last_month_active = '201001')
add_diagnosis(ptid=patient$ptid, diagnosis_cd = '7061',
diagnosis_cd_type = 'ICD9', diag_date = '2009-01-01', primary_diagnosis = '1', admitting_diagnosis = '0', discharge_diagnosis = '1', diagnosis_status = 'Possible diagnosis of')
expect_condition_occurrence(person_id = patient$person_id, condition_status_concept_id = 32899)

patient <- createPatient();
declareTest("Test preliminary or primary diagnosis to condition_status_concept_id, should be preliminary diagnosis", id = patient$person_id)
enc <- createEncounter();
add_patient(ptid=patient$ptid, birth_yr = 1950, gender = 'Male',
first_month_active = '200701', last_month_active = '201001')
add_diagnosis(ptid=patient$ptid, diagnosis_cd = '7061',
diagnosis_cd_type = 'ICD9', diag_date = '2009-01-01', primary_diagnosis = '1', admitting_diagnosis = '0', discharge_diagnosis = '0', diagnosis_status = 'Possible diagnosis of')
expect_condition_occurrence(person_id = patient$person_id, condition_status_concept_id = 32899)

patient <- createPatient();
declareTest("diagnosis_status = History of and primary diagnosis, record moved to Observation", id = patient$person_id)
enc <- createEncounter();
add_patient(ptid=patient$ptid, birth_yr = 1950, gender = 'Male',
first_month_active = '200701', last_month_active = '201001')
add_diagnosis(ptid=patient$ptid, diagnosis_cd = '7061',
diagnosis_cd_type = 'ICD9', diag_date = '2009-01-01', primary_diagnosis = '1', admitting_diagnosis = '0', discharge_diagnosis = '0', diagnosis_status = 'History of')
expect_no_condition_occurrence(person_id = patient$person_id)

patient <- createPatient();
declareTest("diagnosis_status = History of and primary discharge diagnosis, record moved to Observation", id = patient$person_id)
enc <- createEncounter();
add_patient(ptid=patient$ptid, birth_yr = 1950, gender = 'Male',
first_month_active = '200701', last_month_active = '201001')
add_diagnosis(ptid=patient$ptid, diagnosis_cd = '7061',
diagnosis_cd_type = 'ICD9', diag_date = '2009-01-01', primary_diagnosis = '1', admitting_diagnosis = '0', discharge_diagnosis = '1', diagnosis_status = 'History of')
expect_no_condition_occurrence(person_id = patient$person_id)

patient <- createPatient();
declareTest("Test admission diagnosis to condition_status_concept_id", id = patient$person_id)
enc <- createEncounter();
add_patient(ptid=patient$ptid, birth_yr = 1950, gender = 'Male',
first_month_active = '200701', last_month_active = '201001')
add_diagnosis(ptid=patient$ptid, diagnosis_status = 'Diagnosis of', diagnosis_cd = '7061',
diagnosis_cd_type = 'ICD9', diag_date = '2009-01-01', primary_diagnosis = '0')
expect_condition_occurrence(person_id = patient$person_id, condition_type_concept_id = 44786629)
diagnosis_cd_type = 'ICD9', diag_date = '2009-01-01', primary_diagnosis = '0', admitting_diagnosis = '1')
expect_condition_occurrence(person_id = patient$person_id, condition_status_concept_id = 32890)

patient <- createPatient();
declareTest("Test discharge diagnosis to condition_status_concept_id", id = patient$person_id)
enc <- createEncounter();
add_patient(ptid=patient$ptid, birth_yr = 1950, gender = 'Male',
first_month_active = '200701', last_month_active = '201001')
add_diagnosis(ptid=patient$ptid, diagnosis_status = 'Diagnosis of', diagnosis_cd = '7061',
diagnosis_cd_type = 'ICD9', diag_date = '2009-01-01', primary_diagnosis = '0', admitting_diagnosis = '0', discharge_diagnosis = '1')
expect_condition_occurrence(person_id = patient$person_id, condition_status_concept_id = 32896)


patient <- createPatient();
declareTest("Test diagnosis code with wrong diagnosis code type", source_pid = patient$ptid, cdm_pid = patient$person_id)
declareTest("Test diagnosis code with wrong diagnosis code type", id = patient$person_id)
enc <- createEncounter();
add_patient(ptid=patient$ptid, birth_yr = 1950, gender = 'Male',
first_month_active = '200701', last_month_active = '201001')
Expand All @@ -74,7 +127,7 @@ createConditionOccurrenceTests <- function () {


patient <- createPatient();
declareTest("Test blank diagnosis code", source_pid = patient$ptid, cdm_pid = patient$person_id)
declareTest("Test blank diagnosis code", id = patient$person_id)
enc <- createEncounter();
add_patient(ptid=patient$ptid, birth_yr = 1950, gender = 'Male',
first_month_active = '200701', last_month_active = '201001')
Expand All @@ -87,36 +140,38 @@ createConditionOccurrenceTests <- function () {
######################################

patient <- createPatient();
declareTest("Test HCPCS derived condition coming from procedure table", source_pid = patient$ptid, cdm_pid = patient$person_id)
declareTest("Test HCPCS derived condition coming from procedure table", id = patient$person_id)
add_patient(ptid=patient$ptid, birth_yr = 1950, gender = 'Male',
first_month_active = '200701', last_month_active = '201001')
add_procedure(ptid=patient$ptid, proc_code = 'G8007', proc_code_type = 'HCPCS', proc_date = '2009-01-01')
expect_condition_occurrence(person_id = patient$person_id, condition_concept_id = 312327)
add_procedure(ptid=patient$ptid, proc_code = 'G9312', proc_code_type = 'HCPCS', proc_date = '2009-01-01')
expect_condition_occurrence(person_id = patient$person_id, condition_concept_id = 4334801)

#no conditions in latest vocab originate from ICD9Proc, ICD10PCS, or CPT4

# Test provider for encounter
patient <- createPatient();
provider <- createProvider();
enc <- createEncounter();
declareTest("Patient has PROCEDURE record; validate the provider for the encid is mapped to provid", source_pid = patient$ptid, cdm_pid = patient$person_id)
add_patient(ptid=patient$ptid, birth_yr = 1950, gender = 'Male',
first_month_active = '200701', last_month_active = '201001')
add_provider(provid = provider$provid, specialty = "Internal Medicine", prim_spec_ind = "1")
add_encounter(encid = enc$encid, ptid = patient$ptid, interaction_type = 'Inpatient', interaction_date = '2009-01-01')
add_encounter_provider(enc=enc$encid, provid=provider$provid)
add_procedure(ptid=patient$ptid, proc_code = 'G8007', encid = enc$encid, proc_code_type = 'HCPCS', proc_date = '2009-01-01')
expect_condition_occurrence(person_id = patient$person_id, provider_id = provider$provid)
# TODO: provider_id auto generated, need to find way to get correct id
# patient <- createPatient();
# provider <- createProvider();
# enc <- createEncounter();
# declareTest("Patient has PROCEDURE record; validate the provider for the encid is mapped to provid", id = patient$person_id)
# add_patient(ptid=patient$ptid, birth_yr = 1950, gender = 'Male',
# first_month_active = '200701', last_month_active = '201001')
# add_provider(provid = provider$provid, specialty = "Internal Medicine", prim_spec_ind = "1")
# add_encounter(encid = enc$encid, ptid = patient$ptid, interaction_type = 'Inpatient', interaction_date = '2009-01-01')
# add_encounter_provider(enc=enc$encid, provid=provider$provid)
# add_procedure(ptid=patient$ptid, proc_code = 'G9312', encid = enc$encid, proc_code_type = 'HCPCS', proc_date = '2009-01-01')
# expect_condition_occurrence(person_id = patient$person_id, provider_id = provider$provid)


# Test visit_occurrence_id
patient <- createPatient();
enc <- createEncounter();
provider <- createProvider();
declareTest("Patient has PROCEDURE record; validate the visit_occurrence_id", source_pid = patient$ptid, cdm_pid = patient$person_id)
add_patient(ptid=patient$ptid, birth_yr = 1950, gender = 'Male',
first_month_active = '200701', last_month_active = '201001')
add_encounter(enc = enc$encid, ptid = patient$ptid, interaction_type = 'Inpatient', interaction_date = '2009-01-01', visitid = enc$encId)
add_procedure(ptid = patient$ptid, encid = enc$encid, proc_code = 'G8007', proc_code_type = 'HCPCS', proc_date = '2009-01-01')
expect_condition_occurrence(person_id = patient$person_id, visit_occurrence_id = enc$visit_occurrence_id)
# TODO: visit_occurrence_id auto generated, need to find way to get correct id
# patient <- createPatient();
# enc <- createEncounter();
# provider <- createProvider();
# declareTest("Patient has PROCEDURE record; validate the visit_occurrence_id", id = patient$person_id)
# add_patient(ptid=patient$ptid, birth_yr = 1950, gender = 'Male',
# first_month_active = '200701', last_month_active = '201001')
# add_encounter(enc = enc$encid, ptid = patient$ptid, interaction_type = 'Inpatient', interaction_date = '2009-01-01', visitid = enc$encId)
# add_procedure(ptid = patient$ptid, encid = enc$encid, proc_code = 'G9312', proc_code_type = 'HCPCS', proc_date = '2009-01-01')
# expect_condition_occurrence(person_id = patient$person_id, visit_occurrence_id = enc$visit_occurrence_id)
}
16 changes: 9 additions & 7 deletions docs/OPTUM_PANTHER/Test Cases/R/DeathTests.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ createDeathTests <- function () {

# Parameters to use in the function
patient <- createPatient();
enc <- createEncounter();
death_date_threshold <- 31
death_date <- "201404"
stay_dead_date <- as.character(as.Date("2014-04-30") + death_date_threshold - 1)
Expand All @@ -11,9 +12,10 @@ createDeathTests <- function () {
"observations", "patient_reported_medications", "prescriptions_written", "procedure", "visit")

# START - Tests
declareTest("Patient is indicated dead by date_of_death. Their death date is the last day of the month.", source_pid = patient$ptid, cdm_pid = patient$person_id)
add_patient(ptid=patient$ptid, date_of_death="201404")
expect_death(person_id = patient$person_id, death_date = "04/30/2014")
declareTest("Patient is indicated dead by date_of_death. Their death date is the last day of the month.", id = patient$person_id)
add_patient(ptid=patient$ptid, date_of_death="201404", deceased_indicator="1")
add_encounter(enc=enc$encid, ptid = patient$ptid, interaction_date = "2014-04-30")
expect_death(person_id = patient$person_id, death_date = "2014-04-30")
patient <- createPatient()

# Check each table that contains references to the patient (PTID) to see if they have information
Expand All @@ -32,8 +34,8 @@ createDeathDataForTables <- function(tables_to_check, death_date_desc, death_dat
patient <- createPatient();
enc = createEncounter();
visitId <- sequencer$nextSequence();
declareTest(paste("Patient has", tableName, "data occurring", death_date_desc), source_pid = patient$ptid, cdm_pid = patient$person_id)
add_patient(ptid=patient$ptid, date_of_death=death_date)
declareTest(paste("Patient has", tableName, "data occurring", death_date_desc), id = patient$person_id)
add_patient(ptid=patient$ptid, date_of_death=death_date,deceased_indicator="1")
add_encounter(enc=enc$encid, ptid = patient$ptid, interaction_date = end_date, visitid = visitId)

if (tableName == "care_area")
Expand All @@ -47,11 +49,11 @@ createDeathDataForTables <- function(tables_to_check, death_date_desc, death_dat
if (tableName =="insurance")
add_insurance(ptid=patient$ptid, encid=enc$encid, insurance_date=end_date)
if (tableName =="labs")
add_labs(ptid=patient$ptid, encid=enc$encid, order_date=end_date)
add_labs(ptid=patient$ptid, encid=enc$encid, result_date=end_date, order_date=end_date)
if (tableName =="medication_administrations")
add_medication_administrations(ptid=patient$ptid, encid=enc$encid, order_date=end_date)
if (tableName =="microbiology")
add_microbiology(ptid=patient$ptid, encid=enc$encid, order_date=end_date)
add_microbiology(ptid=patient$ptid, encid=enc$encid, collect_date=end_date, order_date=end_date)
if (tableName =="nlp_biomarkers")
add_nlp_biomarkers(ptid=patient$ptid, note_date=end_date)
if (tableName =="nlp_drug_rationale")
Expand Down
12 changes: 5 additions & 7 deletions docs/OPTUM_PANTHER/Test Cases/R/DeviceExposureTests.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ createDeviceExposureTests <- function () {
######################################

patient <- createPatient();
declareTest("Test HCPCS derived device coming from procedure table", source_pid = patient$ptid, cdm_pid = patient$person_id)
declareTest("Test HCPCS derived device coming from procedure table", id = patient$person_id)
add_patient(ptid=patient$ptid, birth_yr = 1950, gender = 'Male',
first_month_active = '200701', last_month_active = '201001')
add_procedure(ptid=patient$ptid, proc_code = 'A4217', proc_code_type = 'HCPCS', proc_date = '2009-01-01')
Expand All @@ -19,13 +19,11 @@ createDeviceExposureTests <- function () {
######################################

patient <- createPatient();
declareTest("Test device derived from diagnosis table", source_pid = patient$ptid, cdm_pid = patient$person_id)
declareTest("Test device derived from diagnosis table", id = patient$person_id)
add_patient(ptid=patient$ptid, birth_yr = 1950, gender = 'Male',
first_month_active = '200701', last_month_active = '201001')
add_diagnosis(ptid=patient$ptid, diagnosis_cd = 'Y73.0', diagnosis_cd_type = 'ICD10', diag_date = '2009-01-01',
add_diagnosis(ptid=patient$ptid, diagnosis_cd = '156009', diagnosis_cd_type = 'SNOMED', diag_date = '2009-01-01',
diagnosis_status = 'Diagnosis of')
# expect_device_exposure(person_id = patient$person_id, device_concept_id = 45767866,
# device_source_value = 'Y73.0', device_source_concept_id = 35224758)
expect_device_exposure(person_id = patient$person_id, device_concept_id = 45767866,
device_source_value = 'Y73.0')
expect_device_exposure(person_id = patient$person_id, device_concept_id = 4048868,
device_source_value = '156009')
}
Loading

0 comments on commit 075acdb

Please sign in to comment.