|
14 | 14 | # See the License for the specific language governing permissions and
|
15 | 15 | # limitations under the License.
|
16 | 16 |
|
17 |
| -#' Determines if check should be notApplicable |
| 17 | +#' Determines if check should be notApplicable and the notApplicableReason |
18 | 18 | #'
|
19 | 19 | #' @param checkResults A dataframe containing the results of the data quality checks
|
20 | 20 | #'
|
|
93 | 93 | fieldIsEmpty = dplyr::coalesce(.data$fieldIsEmpty, !is.na(.data$cdmFieldName)),
|
94 | 94 | )
|
95 | 95 |
|
| 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) |
96 | 101 | 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 | + } |
98 | 121 | }
|
99 | 122 |
|
100 | 123 | checkResults <- checkResults %>%
|
101 | 124 | dplyr::mutate(
|
102 | 125 | notApplicableReason = ifelse(
|
103 | 126 | .data$notApplicable == 1,
|
104 | 127 | dplyr::case_when(
|
| 128 | + !is.na(.data$notApplicableReason) ~ .data$notApplicableReason, |
105 | 129 | .data$tableIsMissing ~ sprintf("Table %s does not exist.", .data$cdmTableName),
|
106 | 130 | .data$fieldIsMissing ~ sprintf("Field %s.%s does not exist.", .data$cdmTableName, .data$cdmFieldName),
|
107 | 131 | .data$tableIsEmpty ~ sprintf("Table %s is empty.", .data$cdmTableName),
|
|
0 commit comments