-
Notifications
You must be signed in to change notification settings - Fork 813
feat(provider_finder): Add 'prefer_one' provider finding strategy #1567
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
Open
andrequina
wants to merge
6
commits into
synthetichealth:master
Choose a base branch
from
andrequina:add_prefer_one_provider_feature
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c318fb0
feat(provider_finder): Add 'prefer_one' provider finding strategy
andrequina 9c9f0b9
removed duplicate and unused imports
andrequina 4f2c2f5
Add provider caching and exception handling
andrequina e9334f5
Update getPreferredNPI method to return null if using preferred provi…
andrequina 9c34a90
Refactor: Set city and state options from provider location
andrequina 2613344
removed outdated comment about changing demographics
andrequina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...java/org/mitre/synthea/world/agents/behaviors/providerfinder/ProviderFinderPreferOne.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| package org.mitre.synthea.world.agents.behaviors.providerfinder; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.mitre.synthea.helpers.Config; | ||
| import org.mitre.synthea.world.agents.Person; | ||
| import org.mitre.synthea.world.agents.Provider; | ||
| import org.mitre.synthea.world.concepts.HealthRecord.EncounterType; | ||
|
|
||
| /** | ||
| * Finder that prioritizes a single provider based on NPI specified in configuration. | ||
| * If the preferred provider is not available or suitable, it falls back to the nearest provider. | ||
| */ | ||
| public class ProviderFinderPreferOne implements IProviderFinder { | ||
|
|
||
| private static final String PREFER_ONE_NPI = "generate.providers.prefer_one.npi"; | ||
| private static final String PREFER_ONE_IGNORE_SUITABLE = "generate.providers.prefer_one.ignore_suitable"; | ||
| // Fallback finder if the preferred one isn't suitable during encounter finding | ||
| private final IProviderFinder fallbackFinder = new ProviderFinderNearest(); | ||
| // Cache for the preferred provider to avoid repeated lookups | ||
| private static Provider cachedPreferredProvider = null; | ||
| // Track the NPI that was used to find the cached provider | ||
| private static String cachedNpi = null; | ||
|
|
||
| public static boolean isUsingPreferredProvider() { | ||
| return Config.get("generate.providers.selection_behavior", "nearest").equals(Provider.PREFER_ONE); | ||
| } | ||
|
|
||
| public static boolean isIgnoringSuitable() { | ||
| return Boolean.valueOf(Config.get(PREFER_ONE_IGNORE_SUITABLE, "false")); | ||
| } | ||
|
|
||
| public static String getPreferredNPI() { | ||
| return isUsingPreferredProvider() ? Config.get(PREFER_ONE_NPI, null) : null; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| @Override | ||
| public Provider find(List<Provider> providers, Person person, EncounterType service, long time) { | ||
|
|
||
| String preferredNpi = getPreferredNPI(); | ||
|
|
||
| if (preferredNpi != null && !preferredNpi.isEmpty()) { | ||
| // first check the list passed in (if the states line up with the detault state, e.g., MA, then it may be found in the list) | ||
| // if it's not found in the list then look across all providers. The state will be updated on the patient and generator. | ||
| Provider provider = findPreferredProvider(providers, preferredNpi, person, service, time); | ||
| if (provider == null) provider = findPreferredProvider(Provider.getProviderList(), preferredNpi, person, service, time); | ||
| if (provider != null) return provider; | ||
| } | ||
|
|
||
| // If preferred NPI not set, not found in the list, or not suitable, use the fallback finder. | ||
| return fallbackFinder.find(providers, person, service, time); | ||
| } | ||
|
|
||
| private Provider findPreferredProvider(List<Provider> providers, String preferredNpi, Person person, EncounterType service, long time) { | ||
andrequina marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (!isUsingPreferredProvider()) return null; | ||
|
|
||
| if (preferredNpi == null || preferredNpi.isEmpty()) { | ||
| throw new ExceptionInInitializerError("ERROR: generate.providers.selection_behavior=PreferOne but " + PREFER_ONE_NPI + " is not set. Using demographic location."); | ||
| } | ||
|
|
||
| // Check if we already have a cached provider with the correct NPI | ||
| if (cachedPreferredProvider != null && preferredNpi.equals(cachedNpi)) { | ||
| return cachedPreferredProvider; | ||
| } | ||
|
|
||
| for (Provider provider : providers) { | ||
|
|
||
| // Check if this provider matches the preferred NPI | ||
| if (preferredNpi.equals(provider.npi)) { | ||
|
|
||
| cachedPreferredProvider = provider; | ||
| cachedNpi = provider.npi; | ||
|
|
||
| // Check if the preferred provider offers the service and accepts the patient | ||
| if (provider.hasService(service) && provider.accepts(person, time)) { | ||
| return provider; | ||
| } else { | ||
| if (isIgnoringSuitable()) return provider; | ||
| // Preferred provider found but is not suitable (doesn't offer service or accept patient) | ||
| // Break the loop and proceed to fallback. | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| cachedPreferredProvider = null; | ||
| cachedNpi = null; | ||
| return null; | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.