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

Reworked get_organ_types #725

Merged
merged 3 commits into from
Aug 27, 2024

Conversation

DerekFurstPitt
Copy link
Contributor

reworked get_organ_types such that it is only called once during the initialization of schema_manager. Created a global variable inside schema triggers and a quick setter function inside app.py to set that value after initialization of schema manager but before the value is fetched in schema_triggers

…initialization of schema_manager. Created a global variable inside schema triggers and a quick setter function inside app.py to set that value after initialization of schema manager but before the value is fetched in schema_triggers
Copy link
Member

@yuanzhou yuanzhou left a comment

Choose a reason for hiding this comment

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

@DerekFurstPitt Your rework looks be an anti-pattern. As you can tell we don't use any top-level variables in schema_triggers.py, it contains only functions. And schema_manager.py uses global variables but it only exposes them via getter functions, schema_manager.get_organ_types() in this case.

Instead of working around circular import, there's a much simpler solution. Take a look at how auth_helper_instance = get_auth_helper_instance() is being used in schema_manager.py first. Then

  • Add this new _organ_types = None
  • In get_organ_types(), first check if _organ_types is available then just return it. Otherwise set its value to be the result of the first response. This is essentially a singleton pattern.
  • In schema_triggers.py and app.py, keep using the old schema_manager.get_organ_types() since now it just reuses the value.
  • In app.py, there's no need to use the second parameter for validate_organ_code(organ_code, organ_types_dict=None).

Keep in mind that we are using the schema_manager as the central piece, any values to be reused by app.py or schema_triggers.py just need a reference/pointer to the exposed function in schema_manager.

…ble in schema manager _organ_types. For get_organ_types, if _organ_types is none, it generates organ types and sets the value to _organ_types then returns _organ_types. If its not none, it returns existing organ_types value
@yuanzhou yuanzhou merged commit c0a9c1d into dev-integrate Aug 27, 2024
5 checks passed
@yuanzhou yuanzhou deleted the Derek-Furst/initialize-get-organ-types branch August 28, 2024 15:03
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