Skip to content

Commit dbc1019

Browse files
authored
social factors (#536)
* remove Lookup smoking status mapping * add source primary Id * simplify name and move order so mapper and mapping work * change common functions and fix date filtering * update mock and fix tests, TODO is legacy * add source primaryId for alcohol plugin * Use the correct Id for history * fix data spec * update logic to identify correct rows to keep and eliminate edge case * inner join removes unmapped data tidy up other logic * inner join to remove redunant mapping and tidy up code * fix select * fix case for GH to work * add suggested name changes to add clarity
1 parent f2231e1 commit dbc1019

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

test/uclh/test_observation_mapping.R

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,46 @@ source(here("test/uclh/mapping_expectations.R"))
66
source(here("test/uclh/utils.R"))
77

88
test_that("smoking table is valid", {
9-
mapping <- omop_plugins$observation$smoking_Patient$mapping(mock_project$conns$caboodle)
10-
expect_concept_matches_spec(mapping, value_as_concept_id, omop_spec$observation)
11-
# TODO Smoking has a local SNOMED code in the mock data, this should be fixed
12-
# expect_valid_omop_mapping(mapping,SmokingStatus,value_as_concept_id)
9+
mapping <- omop_plugins$observation$smoking$mapping(mock_project$conns$caboodle, trim = FALSE)
10+
expect_valid_omop_mapping(mapping, SmokingStatus, value_as_concept_id)
11+
12+
# smoking value_as_concept_id are non-standard
13+
mapping |>
14+
pull(standard_concept) |>
15+
expect_all_na()
16+
})
17+
18+
test_that("social factors keep correct rows", {
19+
source(here::here("mapping/UCLH/epic_common/social_factors_common.R"), local = TRUE)
20+
# Given that there are two VisitIds in SocialFactorsFactX
21+
# WHEN both Ids are populated
22+
# THEN check row relates to the same patient
23+
24+
valid_mapping_pdk <- 91L
25+
invalid_row_Id <- 165L
26+
27+
social_factors <- fetch_social_factors_for_cohort(mock_project$conns, mock_project$cohort)
28+
29+
social_factors |>
30+
pull(PatientPersistentId) |>
31+
expect_setequal(valid_mapping_pdk)
32+
33+
invalid_factors <- tbl(mock_project$conns$caboodle, "SocialFactorsFactX") |>
34+
filter(SocialFactorsId == invalid_row_Id)
35+
36+
# expect the invalid row to not exist after running common function
37+
social_factors |>
38+
inner_join(collect(invalid_factors), join_by(SocialFactorsId)) |>
39+
expect_no_rows()
40+
41+
# expect the invalid row to link to two patients in the raw table
42+
invalid_factors |>
43+
select(VisitId, HistoryVisitId) |>
44+
pivot_longer(everything()) |>
45+
left_join(tbl(mock_project$conns$caboodle, "Encounter"), join_by(value == VisitId)) |>
46+
distinct(PatientPersistentId) |>
47+
collect() |>
48+
expect_row_count(2L)
1349
})
1450

1551
test_that("observation Observation mapping has correct types", {

0 commit comments

Comments
 (0)