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

4513 incontinence supplies #4794

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

jadekstewart3
Copy link
Contributor

Checklist:

X I have performed a self-review of my own code,
X I have commented my code, particularly in hard-to-understand areas,
X I have added tests that prove my fix is effective or that my feature works,
X New and existing unit tests pass locally with my changes ("bundle exec rake"),
X I acknowledge that I will not force push my branch once reviews have started.

-->

Resolves #4513

Description

Made all necessary changes to the incontinence annual survey including:

  • updating the total number of adult incontinence supplies to include supplies contained with in kits
  • add field for the number of adults assisted per month that includes adults that have been assisted with kits
  • updated adult incontinence supplies per month calculation

Note: when creating a kit using the current factory, it creates an extra item (with the correct base category that includes adult but was not previously included in the 'Adult incontinence supplies' list. I've added that item to the test because it is technically correct. Let me know if you would like to see a different course of action, and I will be happy to fix it :)

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

I have created a kit with items and distribution to the test file to ensure that the calculations are indeed including kits and kit items

Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

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

Hey @jadekstewart3 -- the adults served isn't coming up as described in the issue. Could you take a look, please?

.merge(Item.adult_incontinence)
.where.not(items: {kit_id: nil})
.sum('line_items.quantity / COALESCE(items.distribution_quantity, 50)') / 12
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

Per the issue, "
The number of adults assisted with kit items is the number of kits that contain adult incontinence supplies distributed divided by the "quantity per individual" on the kit item. if there is no quantity per individual provided, assume that quantity is 1."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Quick question, also I apologize for missing that bit! Is it a safe assumption that the distribution_quantity is equal to the "quantity per individual"?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes. Sorry for the terminology ambiguity -- they are the same.

@jadekstewart3 jadekstewart3 force-pushed the 4513_incontinence_supplies branch from e64abc5 to 607bec6 Compare November 27, 2024 20:11
@cielf cielf self-requested a review November 28, 2024 17:13
Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

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

Hey @jadekstewart3 - I distributed 100,000 of a kit that contained 50 - 100 of a few different AI products. The supplies distributed looks plausible, but the adults assisted per month and adult incontinence supplies per adult per month didn't budge from what they were before the distribution. That doesn't seem right.

Can you track that down?

Screenshot 2024-11-28 at 12 22 44 PM

@jadekstewart3
Copy link
Contributor Author

@cielf Okay, I think I have tracked down the issue! Let me know if you run into any snags and Ill address it asap, I know we are in crunch time for this report!

@jadekstewart3 jadekstewart3 requested a review from cielf December 11, 2024 22:03
@cielf
Copy link
Collaborator

cielf commented Dec 12, 2024

I think it's not working still -- I distributed 200000 kits that had a variety of AI items in the range of about 50-100 -- similar to last time.

I got this:

Screenshot 2024-12-12 at 2 32 36 PM

.merge(Item.adult_incontinence)
.where.not(items: {kit_id: nil})
.sum('line_items.quantity / COALESCE(items.distribution_quantity, 1)')
end
Copy link
Collaborator

@cielf cielf Dec 12, 2024

Choose a reason for hiding this comment

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

I suspect this is giving you kits that are identified as adult_incontinence, rather than kits that have adult incontinence items in them? Though you used the same pattern as for the disposables... Huh.

@cielf
Copy link
Collaborator

cielf commented Dec 12, 2024

Hey @jadekstewart3 There's definitely something wrong with the diapers as well. There was a change re the kits recently, so I'm wondering if that's what's going on. Stay tuned (though, for expectations, I can't work on this tomorrow)

@cielf
Copy link
Collaborator

cielf commented Dec 12, 2024

Hey @jadekstewart3 -- One thing I notice is that this is based off a version of main from April. There have been an awful lot of changes since then. Could you rebase please?

@cielf
Copy link
Collaborator

cielf commented Dec 16, 2024

I should be able to look at this again tomorrow

@cielf
Copy link
Collaborator

cielf commented Dec 18, 2024

@jadekstewart3 Taking a look now, it's still awry (I don't know what the adults assisted per month should be without calculating it, but I'm sure it's not 1)
Screenshot 2024-12-18 at 4 18 32 PM

First level of pokingat it -- the number assisted with loose looks plausible. (I added 6000 loose, and this number went up by 10. So that tradks.)

.joins(line_items: {item: :kit})
.merge(Item.adult_incontinence)
.where.not(items: {kit_id: nil})
.sum('line_items.quantity / COALESCE(items.distribution_quantity, 1)')
Copy link
Collaborator

@cielf cielf Dec 18, 2024

Choose a reason for hiding this comment

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

I think this is giving you the people served with items that are kits and adult incontinence both? (which would be the zero we are getting). The distinction between items that are kits and items that are in the kits is our bugbear here. We want the number of people served with kits that contain adult incontinence items.

I think we're going to need to do a SQL statement for this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

There is a problem in the initial count — with what you’re excluding. But when you have that done, I’m wondering if using the same sql query, but substituting
SELECT SUM(COALESCE(line_items.quantity / items.distribution_quantity, 1))
for
SELECT SUM(line_items.quantity * kit_line_items.quantity)
in that same SQL query would do the job. I am in no way 100% sure on this - but leave it to you to do a reasoning through. I think line items there is the number of kits in the distributions, and items is the item that represents the kit, yes?

AND LOWER(base_items.category) LIKE '%adult%'
AND NOT (LOWER(base_items.category) LIKE '%cloth%' OR LOWER(base_items.name) LIKE '%cloth%')
AND kit_line_items.itemizable_type = 'Kit';
SQL
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should not be excluding cloth (Adult Cloth Diapers count as AI) and should be excluding wipes. See Item.adult_incontinence.

@cielf cielf self-requested a review December 19, 2024 21:28
Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

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

Current state is that the number of supplies from kits needs adjusting to match the item scope adult_incontinence. I think we're going to have to go with a sql call to get the total people served with kits, and have left some thoughts to pursue on that. Good Luck!

@cielf
Copy link
Collaborator

cielf commented Dec 20, 2024

Hi @dorner. I still need to do more manual testing on this, but it's time to bring you in. Status: as of Friday late afternoon, Jade thinks this is working in real life, but is having trouble with some of the testing.

@cielf cielf requested a review from dorner December 20, 2024 21:01
Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

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

I haven't quite figured out quite what the right SQL statement for the number of adults helped is, but wanted to get some steps toward it out there before @dorner takes a look.

@@ -14,8 +14,9 @@ def initialize(year:, organization:)
def report
@report ||= { name: 'Adult Incontinence',
entries: {
'Adult incontinence supplies distributed' => number_with_delimiter(distributed_supplies),
'Adult incontinence supplies per adult per month' => monthly_supplies&.round || 0,
'Adult incontinence supplies distributed' => number_with_delimiter(distributed_loose_supplies + distributed_adult_incontinence_items_from_kits),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this not total_supplies_distributed?

.for_year(year)
.joins(line_items: :item)
.merge(Item.adult_incontinence)
.sum('line_items.quantity / COALESCE(items.distribution_quantity, 50)') / 12
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is giving you an integer for each item/distribution combo - I found that it was significantly undercounting with our seed data. Changing 50 to 50.0 gave me the value I expected in my case where I had added just enough to get to 600 AI items. But this was in a case where they were all blank distribution quantities -- I suspect you need to make sure items.distribution_quantity reads as double as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Aside - we may want to talk to the stakeholders about fractional people per month - because at small volumes, it's going to change the supplies per month depending on whether we do or not. We should, in any case, have how we handle it make sense to them.

AND NOT (LOWER(base_items.category) LIKE '%wipes%' OR LOWER(base_items.name) LIKE '%wipes%')
AND kit_line_items.itemizable_type = 'Kit';
SQL

Copy link
Collaborator

Choose a reason for hiding this comment

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

Alas, this is not right yet. Try a case where you have 600 loose AI supplies distributed. Then add a kit with 20 supplies in it (10 each of two kinds). Then distribute 12 of those kits. If not quantities per individual have been specified, the number of people served should then be 2 (1 from the loose and 1 from the kits). It came out as 21.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The number of people served by a kit has nothing to do with the number of the AI supplies in the kit -- as long as it has any AI items in it.

And it is the item that is the line_item that we are worried about the distribution quantity on, as well -- i.e. whether the kit itself has a distribution quantity that is non-0.

So .. If I'm reading this right --

SELECT SUM(line_items.quantity * kit_line_items.quantity /
COALESCE(NULLIF(kit_items.distribution_quantity, 0), 1)) AS adults_assisted

Would become
SELECT SUM(line_items.quantity /
COALESCE(NULLIF(items.distribution_quantity, 0), 1)) AS adults_assisted

Copy link
Collaborator

@cielf cielf Dec 21, 2024

Choose a reason for hiding this comment

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

That's still not right -- I think it's counting the adult for the kit once for each different AI supply in the kit. In the case I described, above, the number of adults became 3.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm wondering - especially since this is going to be a relatively little used thing, if an ok approach might be to:

1/ Determine all the items-representing-kits whose kits have ai items (for the organization) That shouldn't be so hard, should it?

Caveat for the below, I don't have the tables in front of me:

Conceptually, you'd need to get the distinct itemizable_ids from the line items that have item type kit, with an item that is adult incontinence. Those itemizable ids represent the items that are kits with adult incontinence.

If that's empty, return 0. This will be the bulk of the time -- unless/until we get a lot of organizations pairing, say briefs and wipes in kits. (NDBN is still ramping up their adult incontinence programs, per our contacts there)

then
2/ use the same pattern as for the loose ai item people -- just substitute the result for #1 in for Item.adult_incontinence.

@dorner - is this a reasonable approach? I think it might be more maintainable than the raw SQL, and this is not going to be frequently used (it's the annual report, after all)

Copy link
Collaborator

Choose a reason for hiding this comment

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

If this is run yearly, I definitely don't care much about performance. Multiple queries should be fine.

…incontinence_items_from_kits still noodling total_kits_with_adult_incontinence_items_distributed
…istributed kits being returned. Taking another look at report calculations to ensure accuracy
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.

Improve Annual Survey regarding incontinence supplies
3 participants