Skip to content

Commit

Permalink
Merge pull request #48 from OHDSI/unit_tests_PREMIER
Browse files Browse the repository at this point in the history
fix unit test PREMIER
  • Loading branch information
bradanton authored Feb 15, 2024
2 parents 6e39119 + 1429c2e commit 49d7b5b
Show file tree
Hide file tree
Showing 31 changed files with 16,033 additions and 2 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -342,5 +342,4 @@ docs/IBM_CCAE_MDCR/Test Cases/extras/config.csv
# Pages files to test changes
_site
.Rproj.user


ETL-LambdaBuilder.Rproj
Binary file added docs/PREMIER/ARCHIVE/Premier_ETL_CDM_V5.doc
Binary file not shown.
Binary file added docs/PREMIER/ARCHIVE/Premier_ETL_CDM_V5_2.doc
Binary file not shown.
Binary file added docs/PREMIER/Premier_ETL_CDM_V5_3.doc
Binary file not shown.
2 changes: 2 additions & 0 deletions docs/PREMIER/Test Cases/.Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
^.*\.Rproj$
^\.Rproj\.user$
8 changes: 8 additions & 0 deletions docs/PREMIER/Test Cases/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.Rproj.user
.Rhistory
*.RData
.Ruserdata
*errorReport.txt
*.Rprofile
/inst/sql/sql_server/insert.sql
/inst/sql/sql_server/test.sql
14 changes: 14 additions & 0 deletions docs/PREMIER/Test Cases/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Package: PremierTests
Type: Package
Title: Configures Test Cases for Premier
Version: 0.1.0
Author: Chris Knoll
Maintainer: Chris Knoll <[email protected]>
Description: Executes test case inserts and validates results.
License: None
LazyData: TRUE
Depends:
SqlRender,
DatabaseConnector
Roxygen: list(wrap = TRUE)
RoxygenNote: 6.0.1
4 changes: 4 additions & 0 deletions docs/PREMIER/Test Cases/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Generated by roxygen2: do not edit by hand

export(generateInsertSql)
export(generateTestSql)
20 changes: 20 additions & 0 deletions docs/PREMIER/Test Cases/PremierTests.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes

BuildType: Package
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,namespace
67 changes: 67 additions & 0 deletions docs/PREMIER/Test Cases/R/ConditionOccurrenceTests.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
createConditionOccurrenceTests <- function () {


# PATICD_DIAG.ICD_CODE ICD9CM
patient <- createPatient();
visit <- createVisit();
declareTest(description="ICD9CM record from PATICD_DIAG to condition_occurrence table", id = patient$person_id);
add_pat(medrec_key = patient$medrec_key,
pat_key = visit$pat_key,
adm_date = "2005-01-01",
disc_date = "2005-01-01");
add_patbill(pat_key = visit$pat_key);
add_paticd_diag(pat_key = visit$pat_key,
icd_code = "112.89",
icd_version = 9);
expect_condition_occurrence(person_id = patient$person_id,
visit_occurrence_id = visit$visit_occurrence_id,
condition_concept_id = 433968,
condition_start_date = "2005-01-01",
condition_source_value = '112.89');

# PATICD_DIAG.ICD_CODE ICD10CM
patient <- createPatient();
visit <- createVisit();
declareTest(description="ICD10CM record from PATICD_DIAG to condition_occurrence table", id = patient$person_id);
add_pat(medrec_key = patient$medrec_key,
pat_key = visit$pat_key,
adm_date = "2004-03-01",
disc_date = "2004-03-01");
add_patbill(pat_key = visit$pat_key);
add_paticd_diag(pat_key = visit$pat_key,
icd_code = "M05.421",
icd_version = 10);
expect_condition_occurrence(person_id = patient$person_id,
visit_occurrence_id = visit$visit_occurrence_id,
condition_concept_id = 4116440,
condition_start_date = "2004-03-01",
condition_source_value = "M05.421");
expect_condition_occurrence(person_id = patient$person_id,
visit_occurrence_id = visit$visit_occurrence_id,
condition_concept_id = 4107913, #map to multiple concepts?
condition_start_date = "2004-03-01",
condition_source_value = "M05.421");

#PRI_SEC flag to condition_status_concept_id
pri_sec_vals <- data.frame(
icd_pri_sec = c('A', 'P', 'S'),
concept_id = c('32890', '32902', '32908'));

for (i in 1:nrow(pri_sec_vals))
{
pri_sec_val <- pri_sec_vals[i,]
patient <- createPatient();
visit <- createVisit();
declareTest(description=paste0("PATICD_DIAG.ICD_PRI_SEC = ", pri_sec_val$icd_pri_sec, " to CONDITION_STATUS_CONCEPT_ID = ", pri_sec_val$concept_id),
id = patient$person_id);
add_pat(medrec_key = patient$medrec_key,
pat_key = visit$pat_key);
add_paticd_diag(pat_key = visit$pat_key,
icd_pri_sec = as.character(pri_sec_val$icd_pri_sec));
expect_condition_occurrence(person_id = patient$person_id,
visit_occurrence_id = visit$visit_occurrence_id,
condition_status_concept_id = pri_sec_val$concept_id,
condition_status_source_value = pri_sec_val$icd_pri_sec);
}

}
121 changes: 121 additions & 0 deletions docs/PREMIER/Test Cases/R/CostTests.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
createCostTests <- function () {

patient <- createPatient()
visit <- createVisit()
declareTest(description="Cost record from drug_exposure", id = patient$person_id);
add_pat(medrec_key = patient$medrec_key,
pat_key = visit$pat_key);
add_patbill(pat_key = visit$pat_key,
std_chg_code = 250250038820000,
bill_charges = 500.50,
bill_cost = 300.75);
add_chgmstr(std_chg_code = 250250038820000,
sum_dept_desc = "PHARMACY",
std_dept_desc = "PHARMACY");
expect_drug_exposure(person_id = patient$person_id,
drug_concept_id = 19042590);
expect_cost(cost_domain_id = "Drug",
total_charge = 500.50,
total_cost = 300.75,
revenue_code_concept_id = 38003147,
revenue_code_source_value = "PHARMACY / PHARMACY");


patient <- createPatient()
visit <- createVisit()
declareTest(description="Cost record from procedure_occurrence", id = patient$person_id);
add_pat(medrec_key = patient$medrec_key,
pat_key = visit$pat_key);
add_patbill(pat_key = visit$pat_key,
std_chg_code = 33840,
bill_charges = 29374.99,
bill_cost = 13572.76);
add_chgmstr(std_chg_code = 33840,
sum_dept_desc = "OR",
std_dept_desc = "SURGERY");
expect_procedure_occurrence(person_id = patient$person_id,
procedure_concept_id = 2107402);
expect_cost(cost_domain_id = "Procedure",
total_charge = 29374.99,
total_cost = 13572.76,
revenue_code_concept_id = 38003208,
revenue_code_source_value = "OR / SURGERY");


patient <- createPatient()
visit <- createVisit()
declareTest(description="Cost record from device_exposure", id = patient$person_id);
add_pat(medrec_key = patient$medrec_key,
pat_key = visit$pat_key);
add_patbill(pat_key = visit$pat_key,
std_chg_code = 270275000120000,
bill_charges = 499.99,
bill_cost = 99.99);
add_chgmstr(std_chg_code = 270275000120000,
sum_dept_desc = "SUPPLY",
std_dept_desc = "CENTRAL SUPPLY");
expect_device_exposure(person_id = patient$person_id,
device_concept_id = 4236068);
expect_cost(cost_domain_id = "Device",
total_charge = 499.99,
total_cost = 99.99,
revenue_code_concept_id = 38003163,
revenue_code_source_value = "SUPPLY / CENTRAL SUPPLY");


patient <- createPatient()
visit <- createVisit()
declareTest(description="Cost record from observation", id = patient$person_id);
add_pat(medrec_key = patient$medrec_key,
pat_key = visit$pat_key);
add_patbill(pat_key = visit$pat_key,
std_chg_code = 110214000620000,
bill_charges = 2347.77,
bill_cost = 2000.00);
add_chgmstr(std_chg_code = 110214000620000,
sum_dept_desc = "OTHER",
std_dept_desc = "DIALYSIS");
expect_observation(person_id = patient$person_id,
observation_concept_id = 4227255);
expect_cost(cost_domain_id = "Observation",
total_charge = 2347.77,
total_cost = 2000.00,
revenue_code_concept_id = 38003458,
revenue_code_source_value = "OTHER / DIALYSIS");


patient <- createPatient()
visit <- createVisit()
declareTest(description="Cost record from measurement", id = patient$person_id);
add_pat(medrec_key = patient$medrec_key,
pat_key = visit$pat_key);
add_patbill(pat_key = visit$pat_key,
std_chg_code = 85013,
bill_charges = 79.99,
bill_cost = 19.50);
add_chgmstr(std_chg_code = 85013,
sum_dept_desc = "LAB",
std_dept_desc = "LABORATORY");
expect_measurement(person_id = patient$person_id,
measurement_concept_id = 4016241);
expect_cost(cost_domain_id = "Measurement",
total_charge = 79.99,
total_cost = 19.50,
revenue_code_concept_id = 38003172,
revenue_code_source_value = "LAB / LABORATORY");


patient <- createPatient();
visit <- createVisit();
declareTest(description="MS_DRG record (1 digit) to cost table", id = patient$person_id);
add_pat(medrec_key = patient$medrec_key,
pat_key = visit$pat_key,
adm_date = "2005-01-01",
disc_date = "2005-01-01",
ms_drg = 1);
add_patbill(pat_key = visit$pat_key);
expect_count_cost(drg_concept_id = 38000887, #drg=001
drg_source_value = "001",
rowCount = 1);

}
79 changes: 79 additions & 0 deletions docs/PREMIER/Test Cases/R/DeathTests.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
createDeathTests <- function ()
{

# note death.death_date = visit_occurrence.visit_end_date

patient <- createPatient();
visit <- createVisit();
declareTest(description = "Death from PAT.DISC_STATUS without PATICD.ICD_CODE death codes", id = patient$person_id);
add_pat(medrec_key = patient$medrec_key,
pat_key = visit$pat_key,
adm_date = "2010-10-01",
disc_date = "2010-10-04",
disc_status = 20);
add_patbill(pat_key = visit$pat_key)
expect_death(person_id = patient$person_id,
death_type_concept_id = 32812,
death_date = '2010-10-04');


patient <- createPatient();
visit <- createVisit();
declareTest(description = "Death from PAT.DISC_STATUS with PATICD.ICD_CODE death code, use DISC_STATUS", id = patient$person_id);
add_pat(medrec_key = patient$medrec_key,
pat_key = visit$pat_key,
adm_date = "2010-10-01",
disc_date = "2010-10-04",
disc_status = 20);
add_patbill(pat_key = visit$pat_key)
add_paticd_diag(pat_key = visit$pat_key,
icd_version = 10,
icd_code = "G93.82")
expect_death(person_id = patient$person_id,
death_type_concept_id = 32812,
death_date = '2010-10-04');


patient <- createPatient();
visit <- createVisit();
declareTest(description = "Death PATICD.ICD_CODE death code", id = patient$person_id);
add_pat(medrec_key = patient$medrec_key,
pat_key = visit$pat_key,
adm_date = "2010-10-01",
disc_date = "2010-10-04",
disc_status = 99);
add_patbill(pat_key = visit$pat_key);
add_paticd_diag(pat_key = visit$pat_key,
icd_version = 10,
icd_code = "G93.82");
expect_death(person_id = patient$person_id,
death_type_concept_id = 32875,
death_date = '2010-10-04');


patient <- createPatient();
visit1 <- createVisit();
visit2 <- createVisit();
declareTest(description = "No records populated >32 days after death", id = patient$person_id);
add_pat(medrec_key = patient$medrec_key,
pat_key = visit1$pat_key,
adm_date = "2010-10-01",
disc_date = "2010-10-04",
disc_status = 20);
add_patbill(pat_key = visit1$pat_key);
add_pat(medrec_key = patient$medrec_key,
pat_key = visit2$pat_key,
adm_date = "2011-01-01",
disc_date = "2011-01-01",
disc_status = 99);
add_patbill(pat_key = visit2$pat_key);
expect_death(person_id = patient$person_id,
death_type_concept_id = 32812,
death_date = '2010-10-04');
expect_no_visit_occurrence(person_id = patient$person_id,
visit_occurrence_id = visit2$visit_occurrence_id,
visit_start_date = '2011-01-01',
visit_end_date = '2011-01-01')

}

Loading

0 comments on commit 49d7b5b

Please sign in to comment.