---
title: "Summary Of Checks"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{SummaryOfChecks}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
options(rmarkdown.html_vignette.check_title = FALSE)
knitr::opts_chunk$set(
  warning = FALSE,
  message = FALSE,
  collapse = TRUE,
  comment = "#>"
)
```

## Run checks 
```{r setup}
library(DrugExposureDiagnostics)
library(dplyr)

# acetaminophen concept id is 1125315
acetaminophen <- 1125315
cdm <- getEunomiaCdm(ingredientId = acetaminophen)
acetaminophen_checks <- executeChecks(cdm = cdm, 
                                      ingredients = acetaminophen, 
                                      checks = c("missing", "exposureDuration", "type", "route", "sourceConcept", "daysSupply", "verbatimEndDate", 
                                                 "dose", "sig", "quantity", "histogram", "diagnosticsSummary"))
```

## Diagnostics summary
```{r}
acetaminophen_checks$diagnosticsSummary %>% 
  glimpse()
```

| Column  | Description |
:------------- | :------------- |
ingredient_concept_id | Concept ID of ingredient. |
ingredient  | Name of drug ingredient for which the checks have been performed. |
n_records | Number of records in the database for the ingredient or any of its descendants. Note, this count is generated before any sampling used for other checks. |
proportion_of_records_with_dose_form | Proportion of drug records with an associated dose form. |
proportion_of_records_by_route_type | Proportion of drug records by associated route type. |
proportion_of_records_by_drug_type | Proportion of drug records by drug types (drug types indicate whether the drug was a prescription record, a dispensation record, patient-reported, or so on).|
proportion_of_records_with_negative_drug_exposure_days | Proportion of drug records where drug exposure end date is before drug exposure start date. |
median_drug_exposure_days_q05_q95 | Median drug exposure days based on drug exposure end date minus drug exposure start date plus one day. |
proportion_of_records_missing_days_supply_or_dates | Proportion of drug records missing any of drug exposure start date, drug exposure end date, or days supply. |
median_quantity_q05_q95 | Median quantity recorded for quantity, along with 5th and 95th quantiles. |
proportion_of_records_missing_denominator_unit_concept_id | Proportion of drug records missing a denominator unit concept id |
median_amount_value_q05_q95 | The median amount value reported, along with 5th and 95th quantiles. |
result_obscured | TRUE if count has been suppressed due to being below the minimum cell count, otherwise FALSE. |

## Concept summary

```{r}
acetaminophen_checks$conceptSummary %>% 
  glimpse()
```

| Column  | Description |
:------------- | :------------- |
drug_concept_id  | ID of the drug concept. |
drug  | Name of the drug concept. |
ingredient_concept_id | Concept ID of ingredient. |
ingredient  | Name of drug ingredient for which the checks have been performed. |
n_records | Number of records for drug concept. |
domain_id  | From the CONCEPT table. A foreign key to the domain table the drug concept belongs to. |
vocabulary_id | From the CONCEPT table. A foreign key to the vocabulary table indicating from which source the drug concept has been adapted. |
concept_class_id  | From the CONCEPT table. The concept class of the drug concept (e.g.‘Ingredient’ or ‘Clinical Drug’). |
standard_concept  | From the CONCEPT table. A flag indicating whether the drug concept is standard ('S'), a classification ('C'), or a non-standard Source (NULL). |
concept_code  | From the CONCEPT table. The concept code represents the identifier of the Concept in the source vocabulary.  |
valid_start_date  | From the CONCEPT table. The date when the drug concept was first recorded |
valid_end_date  | From the CONCEPT table. The date when the drug concept became invalid because it was deleted or superseded (updated) by a new concept. |
invalid_reason  | From the CONCEPT table. Reason the Concept was invalidated. Possible values are D (deleted), U (replaced with an update) or NULL when valid_end_date has the default value. |
amount_value  | From DRUG_STRENGTH table. The numeric value or the amount of active ingredient contained within the drug product. |
amount_unit_concept_id  | From DRUG_STRENGTH table. The Concept representing the Unit of measure for the amount of active ingredient contained within the drug product. |
numerator_value  | From DRUG_STRENGTH table. The concentration of the active ingredient contained within the drug product. | 
numerator_unit_concept_id | From DRUG_STRENGTH table. The Concept representing the Unit of measure for the concentration of active ingredient.|
numerator_unit  | From the CONCEPT table. The concept name associated with the numerator_unit_concept_id. |
denominator_value | From DRUG_STRENGTH table. The amount of total liquid (or other divisible product, such as ointment, gel, spray, etc.).  |
denominator_unit_concept_id  | From DRUG_STRENGTH table. The Concept representing the denominator unit for the concentration of active ingredient. |
denominator_unit  |  From the CONCEPT table. The concept name associated with the denominator_unit_concept_id |
box_size | The number of units of Clinical Branded Drug or Quantified Clinical or Branded Drug contained in a box as dispensed to the patient. |
amount_unit  | From DRUG_STRENGTH table. |
dose_form  | From CONCEPT_RELATIONSHIP table. The RxNorm dose form associated with the drug concept. |
result_obscured | TRUE if count has been suppressed due to being below the minimum cell count, otherwise FALSE. |

## Missing values

```{r}
acetaminophen_checks$missingValuesByConcept %>% 
  glimpse()
```

| Column  | Description |
:------------- | :------------- |
drug_concept_id  | ID of the drug concept. |
drug  | Name of the drug concept. |
ingredient_concept_id | Concept ID of ingredient. |
ingredient  | Name of drug ingredient for which the checks have been performed. |
variable | Field in the drug exposure table. |
n_records | Number of records for drug concept.  |
n_records_not_missing_value | Number of records for drug concept not missing variable. |
n_records_missing_value  | Number of records for drug concept missing variable. |
proportion_records_missing_value | Proportion of records missing variable. |
result_obscured | TRUE if count has been suppressed due to being below the minimum cell count, otherwise FALSE. |


## Drug exposure duration

```{r}
acetaminophen_checks$drugExposureDurationByConcept %>% 
  glimpse()
```

| Column  | Description |
:------------- | :------------- |
drug_concept_id  | ID of the drug concept. |
drug  | Name of the drug concept. |
ingredient_concept_id | Concept ID of ingredient. |
ingredient  | Name of drug ingredient for which the checks have been performed. |
n_records | Number of records for drug concept. |
n_non_negative_days  | Number of drug records with a duration of one day or more. |
n_negative_days  | Number of drug records with a negative duration (ie drug exposure start date after drug exposure end date). |
proportion_negative_days  | Proportion of drug records with a negative duration |
minimum_drug_exposure_days  | Minimum drug exposure duration |
q05_drug_exposure_days  | 5th quantile of drug exposure duration |
q10_drug_exposure_days  | 10th quantile of drug exposure duration |
q25_drug_exposure_days   | 25th quantile of drug exposure duration |   
median_drug_exposure_days  | Median drug exposure duration |
q75_drug_exposure_days  | 75th quantile of drug exposure duration |
q90_drug_exposure_days  | 90th quantile of drug exposure duration |
q95_drug_exposure_days  | 95th quantile of drug exposure duration |
maximum_drug_exposure_days  | Maximum drug exposure duration |
result_obscured | TRUE if count has been suppressed due to being below the minimum cell count, otherwise FALSE. |

## Drug days supply

```{r}
acetaminophen_checks$drugDaysSupplyByConcept %>% 
  glimpse()
```

| Column  | Description |
:------------- | :------------- |
drug_concept_id  | ID of the drug concept. |
drug  | Name of the drug concept. |
ingredient  | Name of drug ingredient for which the checks have been performed. |
ingredient_concept_id | Concept ID of ingredient. |
n_records | Number of records for drug concept.  |
n_different_days_supply_and_drug_dates   | Number of records where days supply differs to drug exposure end minus start plus one day. |
n_days_supply_match_drug_dates | Number of records where days supply matches drug exposure end minus start plus one day. |          
n_missing_days_supply_or_drug_dates  | Number of records missing any of drug exposure start date, drug exposure end date, or days supply. |
proportion_different_days_supply_and_drug_dates  | Proportion of drug records where days supply differs to drug exposure end minus start plus one day. |
proportion_days_supply_match_drug_dates  | Proportion of drug records where days supply matches to drug exposure end minus start plus one day. |        
proportion_missing_days_supply_or_dates | Proportion of drug records missing any of drug exposure start date, drug exposure end date, or days supply. |
result_obscured | TRUE if count has been suppressed due to being below the minimum cell count, otherwise FALSE. | 


## Drug types

```{r}
acetaminophen_checks$drugTypesByConcept %>% 
  glimpse()
```

| Column  | Description |
:------------- | :------------- |
drug_concept_id  | ID of the drug concept. |
drug  | Name of the drug concept. |
ingredient  | Name of drug ingredient for which the checks have been performed. |
ingredient_concept_id | Concept ID of ingredient. |
n_records | Number of records for drug concept.  |
drug_type_concept_id  | Concept ID of drug type |  
drug_type  | Concept name for drug type |     
result_obscured | TRUE if count has been suppressed due to being below the minimum cell count, otherwise FALSE. |

## Drug routes

```{r}
acetaminophen_checks$drugRoutesByConcept %>% 
  glimpse()
```

| Column  | Description |
:------------- | :------------- |
drug_concept_id  | ID of the drug concept. |
drug  | Name of the drug concept. |
ingredient  | Name of drug ingredient for which the checks have been performed. |
ingredient_concept_id | Concept ID of ingredient. |
n_records | Number of records for drug concept.  |
route_concept_id | Concept ID of route. |  
route_type  | Concept name for route. |     
result_obscured | TRUE if count has been suppressed due to being below the minimum cell count, otherwise FALSE. |

## Drug source concepts

```{r}
acetaminophen_checks$drugSourceConceptsByConcept %>% 
  glimpse()
```

| Column  | Description |
:------------- | :------------- |
drug_concept_id  | ID of the drug concept. |
drug  | Name of the drug concept. |
ingredient_concept_id | Concept ID of ingredient. |
ingredient  | Name of drug ingredient for which the checks have been performed. |
n_records | Number of records for drug concept.  |
drug_source_concept_id  | Concept ID of source concept |  
drug_source_type         | Concept name for source concept |     
result_obscured | TRUE if count has been suppressed due to being below the minimum cell count, otherwise FALSE. |

## Drug verbatim end date

```{r}
acetaminophen_checks$drugVerbatimEndDateByConcept %>% 
  glimpse()
```

| Column  | Description |
:------------- | :------------- |
drug_concept_id  | ID of the drug concept. |
drug  | Name of the drug concept. |
ingredient  | Name of drug ingredient for which the checks have been performed. |
ingredient_concept_id | Concept ID of ingredient. |
n_records | Number of records for drug concept.  |
minimum_verbatim_end_date  | Minimum verbatim end date. |  
maximum_verbatim_end_date  | Maximum verbatim end date. |   
n_missing_verbatim_end_date  | Number of records missing verbatim end date. |  
n_not_missing_verbatim_end_date  | Number of records not missing verbatim end date. |     
n_verbatim_end_date_equal_to_drug_exposure_end_date  | Number of records where verbatim end date is the same as drug exposure end date. |     
n_verbatim_end_date_and_drug_exposure_end_date_differ  | Number of records where verbatim end date and drug exposure end date differ. |   
result_obscured | TRUE if count has been suppressed due to being below the minimum cell count, otherwise FALSE. |

## Drug dose

```{r}
acetaminophen_checks$drugDoseByConcept %>% 
  glimpse()
```

| Column  | Description |
:------------- | :------------- |
drug_concept_id  | ID of the drug concept. |
drug | Name of the drug concept. |
ingredient_concept_id | Concept ID of ingredient. |
ingredient  | Name of drug ingredient for which the checks have been performed. |
n_records | Number of records for drug concept. |
missing_days_supply_or_dates  | Number of records missing days supply or dates |                            
proportion_of_records_missing_days_supply_or_dates  | Proportion of records missing either days supply, start drug exposure date, or end drug exposure date  | 
missing_or_null_quantity  | Number of records with missing or null quantity | 
proportion_missing_or_null_quantity  | Proportion of records with missing or null quantity |                       
missing_denominator_unit_concept_id  | Number of records missing denominator unit concept id | 
proportion_of_records_missing_denominator_unit_concept_id  | Proportion of records missing denominator unit concept id | 
missing_or_null_amount_value  | Number of records missing or null amount value |                              
proportion_of_records_missing_or_null_amount_value  | Proportion of records missing or null amount value | 
q05_quantity  | 5th quantile for quantity.  | 
q10_quantity  | 10th quantile for quantity.  | 
q15_quantity  | 15th quantile for quantity.  |                                          
q20_quantity  | 20th quantile for quantity.  | 
q25_quantity  | 25th quantile for quantity.  | 
median_quantity  | median for quantity.  |                                       
q75_quantity  | 75th quantile for quantity.  | 
q80_quantity  | 80th quantile for quantity.  | 
q85_quantity  | 85th quantile for quantity.  |                                          
q90_quantity  | 90th quantile for quantity.  | 
q95_quantity  | 95th quantile for quantity.  |                                            
q05_amount_value  | 5th quantile for amount value.  | 
q10_amount_value  | 10th quantile for amount value.  | 
q15_amount_value  | 15th quantile for amount value.  |                                          
q20_amount_value  | 20th quantile for amount value.  | 
q25_amount_value  | 25th quantile for amount value.  | 
median_amount_value  | median for amount value.  |                                       
q75_amount_value  | 75th quantile for amount value.  | 
q80_amount_value  | 80th quantile for amount value.  | 
q85_amount_value  | 85th quantile for amount value.  |                                          
q90_amount_value  | 90th quantile for amount value.  | 
q95_amount_value  | 95th quantile for amount value.  | 
result_obscured | TRUE if count has been suppressed due to being below the minimum cell count, otherwise FALSE. |



## Drug sig

```{r}
acetaminophen_checks$drugSigByConcept %>% 
  glimpse()
```
| Column  | Description |
:------------- | :------------- |
drug_concept_id  | ID of the drug concept. |
drug  | Name of the drug concept. |
ingredient  | Name of drug ingredient for which the checks have been performed. |
ingredient_concept_id | Concept ID of ingredient. |
n_records | Number of records for drug concept.  |
sig | SIG recorded for records |  
result_obscured | TRUE if count has been suppressed due to being below the minimum cell count, otherwise FALSE. |

## Drug quantity

```{r}
acetaminophen_checks$drugQuantityByConcept %>% 
  glimpse()
```
| Column  | Description |
:------------- | :------------- |
drug_concept_id  | ID of the drug concept. |
drug  | Name of the drug concept. |
ingredient  | Name of drug ingredient for which the checks have been performed. |
ingredient_concept_id | Concept ID of ingredient. |
minimum_drug_exposure_quantity | Minimum drug exposure quantity. |
q05_drug_exposure_quantity | 5th quantile for drug exposure quantity. |         
q10_drug_exposure_quantity | 10th quantile for drug exposure quantity. |         
q25_drug_exposure_quantity | 25th quantile for drug exposure quantity. |        
median_drug_exposure_quantity | Median drug exposure quantity. |      
q75_drug_exposure_quantity | 75th quantile for drug exposure quantity. |         
q90_drug_exposure_quantity | 90th quantile for drug exposure quantity. |     
q95_drug_exposure_quantity | 95th quantile for drug exposure quantity. |         
maximum_drug_exposure_quantity | Maximum drug exposure quantity. |  
result_obscured | TRUE if count has been suppressed due to being below the minimum cell count, otherwise FALSE. |
