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

Add file to CDE #4910

Merged
merged 40 commits into from
Dec 11, 2024
Merged

Add file to CDE #4910

merged 40 commits into from
Dec 11, 2024

Conversation

martha
Copy link
Contributor

@martha martha commented Nov 7, 2024

Merging this PR

  • Should go into release-145, because frontend could still be at release-143 when backend points at release-144, and this change which is needed for compatibility will go into release-144
  • use the squash-merge strategy for PRs targeting a release-X branch

Description

GH issue: https://github.com/open-path/Green-River/issues/6208

This PR

  • Adds a new column to CustomDataElement table, value_file_id, alongside the existing value_string, value_json, etc.
  • Adds the field to the model and graphql type
  • Enables saving a CustomDataElement whose value refers to a file record
    • Filters out such files from the Client Files page
  • Prevents "save and finish later" on assessments which save file records (See inline comment thread for reasoning)

To test:

  • Checkout Support file upload in assessments hmis-frontend#982. In the description of that PR I pasted the assessment json definition I've been using locally. (Also, that PR makes some minor updates to the Form Builder enabling the File question type to be configurable, so you could try that out too.)

Type of change

New feature

Checklist before requesting review

  • I have performed a self-review of my code
  • I have run the code that is being changed under ideal conditions, and it doesn't fail
  • If adding a new endpoint / exposing data in a new way, I have:
    • ensured the API can't leak data from other data sources
    • ensured this does not introduce N+1s
    • ensured permissions and visibility checks are performed in the right places - to confirm: files uploaded on an assessment should be visible to anyone who has permissions to view the assessment?
  • I have updated the documentation (or not applicable)
  • I have added spec tests (or not applicable)
  • I have provided testing instructions in this PR or the related issue (or not applicable)

@martha martha changed the title Add file to CDE (first pass) Add file to CDE Nov 21, 2024
@martha martha changed the base branch from release-141 to release-142 November 21, 2024 20:55
@martha martha requested a review from gigxz November 21, 2024 21:19
@martha martha changed the base branch from release-142 to release-143 December 3, 2024 00:04
drivers/hmis/app/models/hmis/file.rb Outdated Show resolved Hide resolved
else
submitted = Array.wrap(value)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, when any CDE value changes, we delete and replace all of them. See regression test farther down on this PR. I think this is a bug, but until now it wouldn't have had any impact except that such CDEs would have incorrect creation timestamps. The reason to fix it now is to prevent deletion and re-creation of File records.

Copy link
Contributor

@gigxz gigxz Dec 5, 2024

Choose a reason for hiding this comment

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

Ahh yep, thank you for addressing that!
How will it handle situations where there are repeated values that exist or are submitted? Like [{value_string: "foo"}, {value_string: "foo"}] (I'm thinking on an open-choice field, perhaps).
I don't think it's really necessary to preserve both values if they are identical, but it shouldn't explode or do something weird- maybe worth having a test case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a test case. It doesn't explode but it does do something weird - see comment below https://github.com/greenriver/hmis-warehouse/pull/4910/files#r1876005116

@martha martha marked this pull request as ready for review December 4, 2024 19:23
@martha martha requested a review from gigxz December 4, 2024 19:23
)
process_record(record: record, hud_values: hud_values, user: hmis_user, definition: definition)

# expect(record.custom_data_elements.size).to eq(4)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The commented-out line fails, since custom_data_elements.size is equal to 3. The last foo value doesn't get properly added because it's considered an existing value.

I think the most graceful way to deal with this is to just prevent submission of duplicate values. That way we don't have to keep track of value counters or anything like that. Maybe in normalize_custom_field_value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I implemented this, let me know what you think

@martha martha changed the base branch from release-143 to release-144 December 9, 2024 17:53
@gigxz gigxz changed the base branch from release-144 to release-145 December 10, 2024 21:58
@@ -229,7 +229,8 @@ def custom_case_notes(...)
end

def files(**args)
resolve_files(**args)
# Exclude files that have been uploaded by custom assessments
resolve_files(object.files.left_joins(:custom_data_element).merge(Hmis::Hud::CustomDataElement.where(id: nil)), **args)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is equivalent to .where.missing(:custom_data_element)! learned that one recently, I think it's neat

> Hmis::File.where.missing(:custom_data_element).count
  Hmis::File Count (3.0ms)  SELECT COUNT(*) FROM "files" LEFT OUTER JOIN "CustomDataElements" "custom_data_element" ON "custom_data_element"."DateDeleted" IS NULL AND "custom_data_element"."value_file_id" = "files"."id" WHERE "files"."type" = $1 AND "files"."deleted_at" IS NULL AND "custom_data_element"."id" IS NULL  [["type", "Hmis::File"]]

> Hmis::File.left_joins(:custom_data_element).merge(Hmis::Hud::CustomDataElement.where(id: nil)).count
  Hmis::File Count (3.3ms)  SELECT COUNT(*) FROM "files" LEFT OUTER JOIN "CustomDataElements" ON "CustomDataElements"."DateDeleted" IS NULL AND "CustomDataElements"."value_file_id" = "files"."id" WHERE "files"."type" = $1 AND "files"."deleted_at" IS NULL AND "CustomDataElements"."DateDeleted" IS NULL AND "CustomDataElements"."id" IS NULL   [["type", "Hmis::File"]]

Copy link
Contributor

@gigxz gigxz left a comment

Choose a reason for hiding this comment

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

nice work!!

@martha martha merged commit b7f169d into release-145 Dec 11, 2024
54 checks passed
@martha martha deleted the martha/6208-multi-upload branch December 11, 2024 12:10
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