Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align datapack sitetool code #44

Closed
wants to merge 21 commits into from
Closed

Conversation

jacksonsj
Copy link
Contributor

@jason-p-pickering & @sam-bao - Could you both review this code and send feedback?

The purpose of these changes was to better align code used to process Data Packs and Site Tools, which had been largely duplicative and clunky.

Because of the many downstream implications of some of these changes, I'd like to ask for both of you to review to identify ways these changes may impact your code.

Major changes include:

  • Tagging country UIDs based on the processed data itself, rather than based on tool home page. This allows for all variations of country pairings to occur in the Site Tool or Data Pack. But, this may have downstream implications on validation apps.
  • Functionalizing code processes and forking to allow usage in both Data Pack and Site Tool processing with variation based on need.
  • Removing some warnings that had been issued before in integrity checks that have confused users and are not actually informative (e.g., column or tab order issues).
  • Functionalizing process used to test and open a file.
  • Grouping all tool processing, whether Data Pack or Site Tool, under unPackTool.
  • Standardizing naming of indicator_code (instead of indicatorCode)

#' disaggs used in a specific sheet.
defunctDisaggs <- function(d) {

defunct <- d$data$extract %>%
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would make sense if possible to have this as a configuration file? We know there are likely going to be defunct disaggs next year, so a more flexible combination of indicator code and disagg might work?

dplyr::filter(value < 0) %>%
dplyr::pull(indicatorCode) %>%
dplyr::pull(indicator_code) %>%
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to indicator code will require very minor change to datapack commons code (https://github.com/pepfar-datim/data-pack-commons/search?q=indicatorCode&unscoped_q=indicatorCode) I added an issue to that repo (pepfar-datim/data-pack-commons#22)

names(readxl::read_excel(
d$keychain$submission_path,
sheet = "Home",
range = "B25"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anyway we could get this out as a hardcode and into a schema/configuration?

@sam-bao
Copy link
Contributor

sam-bao commented Apr 30, 2019

I unpacked a Lesotho data pack and completed a diff against the original unpacked data pack
for data$distributedMER and the only difference found was the name change from indicatorCode to indicator_code.

I also checked datim$PSNUxIM and datim$SUBNAT_IMPATT and found no differences.

@sam-bao
Copy link
Contributor

sam-bao commented Apr 30, 2019

@jacksonsj I agree with Jason's comments about pulling out some of the hard coded bits that are tightly coupled to COP19 and placing in a config file.

Additionally we have already discussed the need to improve our naming across the board. Lines like this are a pretty good example of our inconsistency.

dplyr::select(site_uid,mech_code,indicator_code,Type,Age,Sex,KeyPop,value)

This should probably be
dplyr::select(site_uid, mechanism_code, indicator_code, support_type , age, sex, key_population, value)

That said I think we can do a general renaming once the main refactoring is done.

The changes in this pull request have a very limited impact on the code I wrote and am maintaining.

# Check OU name and UID match up
interactive_print("Checking the OU name and UID on HOME tab...")
d <- checkSiteToolOUinfo(d)
countries <-
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a function for metadata calls in datapack commons (https://github.com/pepfar-datim/data-pack-commons/blob/f1bedc5bc1a7c25e2a1993920d0c934813e68242/R/dhis2api.R#L278)

I wanted to make a small change to this function to move base_url to the end with a default of getOption("baseurl")

This would make the equivalent call something like:

datapackcommons::getMetadata(end_point = "organisationUnits", 
                                                         filters = c("organisationUnitGroups.name:eq:Country",
                                                                           paste0("children.id:in:[",site_uids,"]")),
                                                         fields = "id,name")

We should coordinate how we want to make common api calls like this. I bet Jason has his own version somewhere as well.

d$info$warningMsg <- NULL
d$info$has_error <- FALSE
site_uids <- d$data$targets %>%
dplyr::pull(site_uid) %>%
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance this will result in too many sites to make the api call - there is some maximum length to the api call.

readxl::read_excel(
path = d$keychain$submission_path,
sheet = "Home",
range = "B23") %>%
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jacksonsj I think currently ou uid is in B25, has this changed?

@sam-bao
Copy link
Contributor

sam-bao commented May 10, 2019

@jacksonsj for these most recent changes. I was able to unpack Lesotho data pack without issue, and confirmed the distributedMer output, SNUxIM output, and datim$PSNUxIM matched the original unpacking I did for Lesotho.

@sam-bao
Copy link
Contributor

sam-bao commented Aug 9, 2019

@jacksonsj is this still a valid pull request/branch? As this makes a lot of changes I don't think we can merge it into master at this moment - I think it represent post cop 19 refactoring. Should we close the pull request without merging?

@sam-bao
Copy link
Contributor

sam-bao commented Sep 23, 2019

@jacksonsj Can we close this pull request and delete the branch?

@jacksonsj jacksonsj closed this Sep 23, 2019
@jacksonsj jacksonsj deleted the align-datapack-sitetool-code branch September 23, 2019 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants