test_that("check working example with defaults", {
DBI::dbDisconnect(attr(db, "dbcon"), shutdown = TRUE)
test_that("check working example with drug_strength", {
db <- mockDrugExposure(drug_strength = drug_strength)
test_that("check working example with drug drug_exposure", {
db <- mockDrugExposure(drug_exposure = drug_exposure)
test_that("check working example with drug_exposure options", {
db <- mockDrugExposure(drug_exposure_size = 1, patient_size = 1)
db <- mockDrugExposure(drug_exposure_size = 2, patient_size = 1)
test_that("check working example with drug_strength options", {
db <- mockDrugExposure(amount_val = 1,den_val = 1,unit = "mg",num_val = 1)

"check working example with drug_strength"
"check working example with drug drug_exposure"
"check working example with drug_exposure options"
"check working example with drug_strength options"

check working example with drug_strength

check working example with drug drug_exposure

check working example with drug_exposure options

check working example with drug_strength options

testData <- mockDrugExposure(drug_exposure = drug_exposure)
summarisedData <- summariseQuantity(testData, byConcept = F)

test_that("check if it can detect missing", {
#correct one should be c(na,na,366,na,365)
result <- checkDaysSupply(testData, byConcept = TRUE)
totalLength <- dim(testData$drug_exposure %>% dplyr::collect())[1]
result[result$drug_concept_id == 1, ]$proportion_missing_days_supply_or_drug_dates) == 1)
result[result$drug_concept_id == 2, ]$proportion_missing_days_supply_or_drug_dates) == 1)
result[result$drug_concept_id == 3, ]$proportion_missing_days_supply_or_drug_dates) == 1)
test_that("check if summarise days_supply works", {

result <- checkDrugDose(testData, "ingredient_drug_records","drug_strength" , byConcept = FALSE)
result <- checkDrugDose(testData, "ingredient_drug_records","drug_strength" , byConcept = TRUE)

cdm <- mockDrugExposure(drug_exposure = drugExposure)
resultDaysSupply <- createHistogram(cdm, "drug_exposure", type = "days_supply")
resultQuantity <- createHistogram(cdm, "drug_exposure", type = "quantity")
resultDuration <- createHistogram(cdm, "drug_exposure", type = "duration")
test_that("test save load fucntionality for histograms", {
cdm$drug_exposure <- cdm$drug_exposure %>% dplyr::mutate(days_supply = NA)