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

Helper functions to create ActivityInfo form and field schemas #32

Closed
Ryo-N7 opened this issue Nov 25, 2022 · 9 comments
Closed

Helper functions to create ActivityInfo form and field schemas #32

Ryo-N7 opened this issue Nov 25, 2022 · 9 comments

Comments

@Ryo-N7
Copy link
Collaborator

Ryo-N7 commented Nov 25, 2022

This was brought up in the most recent ActivityInfo with R webinar, some helper function for users to set up the structure of the ActivityInfo form schema when using the addForm() function, kind of like the permissions() helper function we have for updateUserRole()? This same helper function can be applied to updateFormSchema().

Can also extend this for setting up the structure of Database schema as well and then updating the database schema/tree? Somewhat related, I also remember seeing a createDatabase() function in an older webinar from 2018, but its not in the current R package anymore.

@Ryo-N7 Ryo-N7 changed the title Helper function to create ActivityInfo schema structure Helper function to create ActivityInfo schema structure (form and database) Dec 6, 2022
@Ryo-N7 Ryo-N7 changed the title Helper function to create ActivityInfo schema structure (form and database) Helper function to create ActivityInfo schema structure (forms and databases) Dec 6, 2022
@Ryo-N7 Ryo-N7 changed the title Helper function to create ActivityInfo schema structure (forms and databases) Helper functions to create ActivityInfo schema structure (forms and databases) Dec 6, 2022
@Ryo-N7
Copy link
Collaborator Author

Ryo-N7 commented Dec 9, 2022

createDatabase() should be something like this:

activityinfo:::postResource("databases", body = list(id = cuid(), label = "my new db!", templateId = "blank"), task = sprintf("Creating test database '%s' post request", label))

@Ryo-N7
Copy link
Collaborator Author

Ryo-N7 commented Dec 12, 2022

for uploading a NEW form (that doesn't exist in ActivityInfo yet), be able to grab a data.frame (imported into R as CSV or Excel, etc.) and then run it through a function to create a ActivityInfo schema structure from which we can use to upload into ActivityInfo: either via the activityinfo::addForm() or the add Form >> paste field list on the UI


EDIT: the above separated out into a separate issue, #44 as it ties into separate improvements to importTable() as well rather than just the form schema stuff

@Ryo-N7
Copy link
Collaborator Author

Ryo-N7 commented Dec 12, 2022

some kind of function to inspect all possible field types available in ActivityInfo (quantity, FREE_TEXT, Date, etc.)

@Ryo-N7
Copy link
Collaborator Author

Ryo-N7 commented Dec 16, 2022

getFormSchema() has a method that allows you to transform it into a data.frame but getDatabaseSchema() currently does not.

it'll be nice to get the database schema into a data.frame format as well so that updates to the database schema can also be handled via data.frames , similar to #33

@Ryo-N7
Copy link
Collaborator Author

Ryo-N7 commented Dec 16, 2022

of course it's more difficult to do this for the DB schema since it has several very distinct elements (tables, roles, users as their own list-of-lists) so maybe helper functions to extract these specific bits of a db schema would be helpful:

afda_schema <- getDatabaseSchema("c5h9mudkz3sqce52")

## Tables come from the "resources" list
## turn below code into a function

## Get table labels
tab_label <- afda_schema %>% 
  purrr::pluck("resources") %>% 
  purrr::map(pluck("label")) %>% unlist()

## Get table IDs
tab_id <- afda_schema %>% 
  purrr::pluck("resources") %>% 
  purrr::map(pluck("id")) %>% 
  unlist()

## put 'em together to create a nice look-up
data.frame(
  Table = tab_label,
  table_id = tab_id
)

## separate function to extract all users and user info

## separate function to extract all roles and role info....

@nickdickinson
Copy link
Collaborator

Great example! Thanks!

@Ryo-N7
Copy link
Collaborator Author

Ryo-N7 commented Jan 27, 2023

Checklist

  • createDatabase() function

Helper functions to extract elements of the database schema and turn into a nicie data.frame similar to form schema method:

  • database meta-info as a data.frame (Id, version, label, billing account, language, etc.)
  • table labels, table IDs,
  • user list, user info,
  • roles, role info,
  • permissions/grants
  • locks
  • security categories

Form schema helpers: be able to build a form schema from the ground-up

  • field types (also can just be included as a list in the documentation)
  • build out all the necessary fields (id, code, label, relevance/validationCondition, calculated field formulas, etc.)
  • set up single/multiple select fields
  • set up reference fields

Ideal workflow:

  1. createDatabase() for a blank database
  2. then have all of these form schema helper functions set with different options to create different standardized form schemas in the proper list object format
  3. upload all that into new db with addForm()
  4. if applicable, use importTable() to add data immediately

@nickdickinson
Copy link
Collaborator

At the moment, the following branch https://github.com/bedatadriven/activityinfo-R/tree/version-4.32 can be tested. I will add more form fields and the other help functions now but the main work has been done.

Added are:

createDatabase(); 
deleteDatabase(); 
formFieldSchema(); 
asFormFieldSchema(); 
validateFormFieldSchema(); 
formSchema();
asFormSchema(); 
validateFormSchema()
deleteForm(); 
addForm()

Text, Barcode, and Serial Code Form field functions (constructor and validation):

barcodeFieldSchema()
textFieldSchema()
serialNumberFieldSchema()
validateBarcodeFieldSchema()
validateTextFieldSchema()
validateSerialNumberFieldSchema()

Added s3 generics for some chaining when creating and modifying forms and their fields.
Updated and improved tests and documentation

Here is an example from an actual test:

dbTest <- createDatabase("Another test database on the fly!")

fmSchm <- formSchema(databaseId = dbTest$databaseId, label = paste0("R form with multiple fields test ", cuid()))

fmSchm <- fmSchm |> 
  addFormField(barcodeFieldSchema(label = "A barcode field")) |>
  addFormField(textFieldSchema(label = "A text field")) |>
  addFormField(serialNumberFieldSchema(label = "A serial number field"))
  
dbMetadata <- addForm(databaseId = databaseId, schema = fmSchm)
fmSchm2 <- getFormSchema(formId = fmSchm$id)

deleteForm(databaseId = databaseId, formId = fmSchm2$id)

result <- deleteDatabase(databaseId = dbTest$databaseId)

@akbertram
Copy link
Member

akbertram commented Jan 31, 2023 via email

@akbertram akbertram changed the title Helper functions to create ActivityInfo schema structure (forms and databases) Helper functions to create ActivityInfo form and field schemas Feb 1, 2023
@akbertram akbertram added this to the Release 4.32 milestone Feb 1, 2023
@nickdickinson nickdickinson removed their assignment Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

3 participants