Skip to content

Commit 0ceeb6b

Browse files
committed
fixes #526 with an exception for NA status of measureConditionEraCompleteness
1 parent 55ef475 commit 0ceeb6b

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

R/calculateNotApplicableStatus.R

+26-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
#' Determines if check should be notApplicable
17+
#' Determines if check should be notApplicable and the notApplicableReason
1818
#'
1919
#' @param checkResults A dataframe containing the results of the data quality checks
2020
#'
@@ -93,15 +93,39 @@
9393
fieldIsEmpty = dplyr::coalesce(.data$fieldIsEmpty, !is.na(.data$cdmFieldName)),
9494
)
9595

96+
checkResults$notApplicable <- NA
97+
checkResults$notApplicableReason <- NA
98+
99+
conditionOccurrenceIsEmpty <- emptyTables %>% dplyr::filter(.data$cdmTableName == "CONDITION_OCCURRENCE") %>% dplyr::pull(tableIsEmpty)
100+
# drugExposureIsEmpty <- emptyTables %>% filter(.data$cdmTableName == "DRUG_EXPOSURE") %>% pull(tableIsEmpty)
96101
for (i in seq_len(nrow(checkResults))) {
97-
checkResults$notApplicable[i] <- .applyNotApplicable(checkResults[i, ])
102+
if (checkResults[i, "checkName"] == "measureConditionEraCompleteness") {
103+
# Special rule for measureConditionEraCompleteness, which should be notApplicable if CONDITION_OCCURRENCE is empty
104+
if (conditionOccurrenceIsEmpty) {
105+
checkResults$notApplicable[i] <- 1
106+
checkResults$notApplicableReason[i] <- "Table CONDITION_OCCURRENCE is empty."
107+
} else {
108+
checkResults$notApplicable[i] <- 0
109+
}
110+
# } else if (checkResult[i, "checkName"] == "measureDrugEraCompleteness") {
111+
# # Special rule for measureDrugEraCompleteness, which should be notApplicable if DRUG_EXPOSURE is empty
112+
# if (drugExposureIsEmpty) {
113+
# checkResults$notApplicable[i] <- 1
114+
# checkResults$notApplicableReason[i] <- "Table DRUG_EXPOSURE is empty."
115+
# } else {
116+
# checkResults$notApplicable[i] <- 0
117+
# }
118+
} else {
119+
checkResults$notApplicable[i] <- .applyNotApplicable(checkResults[i, ])
120+
}
98121
}
99122

100123
checkResults <- checkResults %>%
101124
dplyr::mutate(
102125
notApplicableReason = ifelse(
103126
.data$notApplicable == 1,
104127
dplyr::case_when(
128+
!is.na(.data$notApplicableReason) ~ .data$notApplicableReason,
105129
.data$tableIsMissing ~ sprintf("Table %s does not exist.", .data$cdmTableName),
106130
.data$fieldIsMissing ~ sprintf("Field %s.%s does not exist.", .data$cdmTableName, .data$cdmFieldName),
107131
.data$tableIsEmpty ~ sprintf("Table %s is empty.", .data$cdmTableName),

0 commit comments

Comments
 (0)