Skip to content

APP-410 Convert NBSSR00009 Bar Graph of Selected Disease by Month#3092

Draft
krista-skylight wants to merge 37 commits intomainfrom
kc/convert-nbssr00009
Draft

APP-410 Convert NBSSR00009 Bar Graph of Selected Disease by Month#3092
krista-skylight wants to merge 37 commits intomainfrom
kc/convert-nbssr00009

Conversation

@krista-skylight
Copy link
Copy Markdown
Contributor

@krista-skylight krista-skylight commented Mar 19, 2026

Checklist for adding a library:

  • Copy this checklist into your (draft) PR description
  • Check the existing description for the library in apps/modernization-api/src/main/resources/db/report/execution/03_ODSE_Data_Report_Library_Init.sql
    • If the report execution service is not yet in use by any STLT (even beta), you should update this file
    • Update the description in the library-specific migration
  • Add a migration to apps/modernization-api/src/main/resources/db/report/execution/libraries named <your library name>.sql
    • Copy another migration and update the variables at the top of the file
  • Add the migration to apps/modernization-api/src/main/resources/db/report-execution-changelog.yml. It should be added to the latest changeSet since the last release - this could require a new changeSet if there isn't one since last release
  • Check the migration works by building/running the containerized dev setup
  • Add a python library file to apps/report-execution/src/libraries named in lowercase, but generally following the naming convention of SAS (needs to be human recognizable as the same library)
  • Follow the pattern established in existing libraries to create your library. The execute function is the required method and its signature will (someday) be checked for validity
    • Make sure pertinent text embedded in the reports is included in the description of the report
    • Note in the doc string any deviation from the SAS
  • Keep an eye out for things in the sas library that are/could be centralized to pre- or post-processing or a util would be helpful for (e.g. common formatting needs)
  • Add integration tests in a apps/report-execution/tests/libraries/<your_library_here>py file following the conventions established for other libraries
    • The subset_sql can be assumed to be well tested by the modernization-api, so focus on any logic and additional joins/queries/analysis that is added in the library
    • The database used in integration testing is our standard golden db + seed used in other testing - if additional data is needed to test the report, add it to the seeding process
  • Add e2e test coverage for the report
    • If this step is not set up, create a ticket to track this as follow on work needed for this report
  • Check that the report has parity with the NBS 6 version using (process TBD)
    • If this step is not set up, create a ticket to track this as follow on work needed for this report
  • Keep an eye out for opportunities to:
    • Consolidate reports by using parameters (parameter design tbd)
    • Improve the report spec or result expectations
  • Update the SAS to Python tracking spreadsheet with information about the newly converted library
  • Update/clarify these instructions in the epic based on your experience

Krista Chan and others added 6 commits March 10, 2026 20:21
Co-authored-by: Mary McGrath <m.c.mcgrath13@gmail.com>
Co-authored-by: Mary McGrath <m.c.mcgrath13@gmail.com>
This reverts commit 4a1f036.

get rid of .gitignore change
@krista-skylight krista-skylight self-assigned this Mar 19, 2026
@krista-skylight krista-skylight changed the title APP-229 Convert SAS Libraries to Python APP-229 Convert NBSSR00009 Bar Graph of Selected Disease by Month Mar 30, 2026
@krista-skylight krista-skylight marked this pull request as ready for review April 1, 2026 23:30
@krista-skylight krista-skylight requested a review from a team as a code owner April 1, 2026 23:30
@krista-skylight krista-skylight requested review from JordanGuinn and removed request for a team April 1, 2026 23:30
Comment on lines +44 to +47
" COALESCE(state_cd, 'N/A') as state_cd,\n"
" COALESCE(state, 'N/A') as state,\n"
" COALESCE(county, 'N/A') as county,\n"
" COALESCE(cnty_cd, 'N/A') as cnty_cd,\n"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(thought, b): I know the SAS does coalescing with 'N/A' - I'm unconvinced we need to do this in SQL or if this is entirely equivalent as the SAS seems to be mapping '' => 'N/A', which isn't the same as NULL (or is it in SAS??) - what are your thoughts here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

TO DO: get rid of coalesce, don't worry about null values

):
"""Standard Report 09: Monthly Cases by Disease and State.

'SR9: Bar Graph of Selected Disease by Month. Report demonstrates, using a
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(sugg, nb): maybe add an "originally, " here since this is no longer a bar graph?

# Format the time period string
time_period_str = f'{start_date} to {end_date}' if time_range else 'Last 12 Months'

header = 'SR9: Monthly Cases by Disease and State'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
header = 'SR9: Monthly Cases by Disease and State'
header = 'SR9: Monthly Cases by Disease, County and State'

maybe?

assert result.content_type == 'table'

data = result.content.data
assert len(data) > 0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(q, nb): given we know the data, can we make a stronger assertion here than > 0? 3 diseases, 3 states, 3 counties, 6 months -> 130ish rows?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the specific 6 month time range I used in this test gave me 52 rows so I put the assertion at >50 right now. will that always remain the same as long as phc_demographic.yaml has the same random seed? If so, can I assume we're always going to keep it the same?


# Verify data structure and basic sanity checks
for row in data:
# Find the row index for each column (don't assume order)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(q, nb): why not assume order since it is fixed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

At first I assumed order and then left that note and chose to not assume order and list out all the names instead just to maybe make the test a little less brittle. Though I quickly discovered there was a downside when I went back to change the column names.


# Month name should be 3 letters
month_name = row[col_index['month_name']]
assert len(month_name) in [3, 4] # Some months like 'Sept' might be 4 chars
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(q, b): does SAS also have this "sometimtes 4" short name?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ooh I'm not sure about SAS. I put this in because I'm accustomed to python strftime abbreviating september to Sept. I googled and seems like MSSQL doesn't do that though so I think I can safely remove this.

@krista-skylight krista-skylight changed the title APP-229 Convert NBSSR00009 Bar Graph of Selected Disease by Month APP-410 Convert NBSSR00009 Bar Graph of Selected Disease by Month Apr 2, 2026
Comment on lines +321 to +323
assert 'State(s):' in result.subheader
assert 'Disease(s):' in result.subheader
assert 'Time Period:' in result.subheader
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(thought, b): this format looks different than SAS (and the other reports) - should we create a util that takes in a list of states and a time period formats the subheader?

(sugg, b): I don't see diseases in the original subheader - remove?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

created a util called gen_subheader within src.utils and rewrote to match the original subheader but with the pipe separator like in your example


header = 'SR9: Monthly Cases by Disease and State'
subheader = (
f'State(s): {", ".join(state_list) if state_list else "All"} | '
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if there are no states, is "All" a reasonable default? for SR2, I omit state if there are no states

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I ended up getting rid of this since this report should always have state and should error without one. I would have thought the default would be 'All' if we ever change it to not require selecting a state but I guess we can cross that bridge when we get there?

@krista-skylight krista-skylight marked this pull request as draft April 2, 2026 15:13
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 3, 2026

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.

2 participants