-
Notifications
You must be signed in to change notification settings - Fork 862
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 1 commit
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
152 changes: 152 additions & 0 deletions
152
...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,152 @@ | ||
| package org.mitre.synthea.world.agents.behaviors.providerfinder; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.List; | ||
|
|
||
| import org.mitre.synthea.helpers.Config; | ||
| import org.mitre.synthea.world.agents.Person; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| import org.mitre.synthea.helpers.Config; | ||
|
jawalonoski marked this conversation as resolved.
|
||
| import org.mitre.synthea.world.agents.Person; | ||
|
jawalonoski marked this conversation as resolved.
|
||
| 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. | ||
| * Also provides a static method to override initial person demographics based on this preference. | ||
| * 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(); | ||
|
|
||
| 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 Config.get(PREFER_ONE_NPI, null); | ||
|
andrequina marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| public static Provider getPreferredProvider() { | ||
|
|
||
| if (!isUsingPreferredProvider()) return null; | ||
|
|
||
|
|
||
| String preferredNpi = getPreferredNPI(); | ||
| if (preferredNpi == null || preferredNpi.isEmpty()) { | ||
| System.err.println("WARNING: generate.providers.selection_behavior=PreferOne but " + PREFER_ONE_NPI + " is not set. Using demographic location."); | ||
| return null; // NPI not configured, do nothing. | ||
| } | ||
|
|
||
| Provider preferredProvider = null; | ||
| // Find the preferred provider by NPI from the loaded list | ||
| // Note: This assumes the provider is within the initially loaded set. | ||
| for (Provider p : Provider.getProviderList()) { | ||
| if (preferredNpi.equals(p.npi)) { | ||
| preferredProvider = p; | ||
| break; | ||
| } | ||
| } | ||
|
andrequina marked this conversation as resolved.
Outdated
|
||
| return preferredProvider; | ||
| } | ||
|
|
||
| /** | ||
| * Checks configuration for the PreferOne provider setting. If enabled and the | ||
| * preferred provider is found, overrides the City, State, and Coordinate | ||
| * entries in the provided demographics map with the provider's location. | ||
| * Logs warnings if the provider or its location data is not found. | ||
| * | ||
| * @param demoAttributes The map of demographic attributes to potentially modify. | ||
| */ | ||
| public static void overrideDemographicsIfPreferredProvider(Map<String, Object> demoAttributes) { | ||
|
|
||
| Provider preferredProvider = getPreferredProvider(); | ||
|
|
||
| if (preferredProvider != null) { | ||
| // Override demographics with preferred provider's location data | ||
| boolean cityOverridden = false; | ||
| boolean stateOverridden = false; | ||
| boolean coordsOverridden = false; | ||
|
|
||
| if (preferredProvider.city != null && !preferredProvider.city.isEmpty()) { | ||
| demoAttributes.put(Person.CITY, preferredProvider.city); | ||
| cityOverridden = true; | ||
| } | ||
| if (preferredProvider.state != null && !preferredProvider.state.isEmpty()) { | ||
| demoAttributes.put(Person.STATE, preferredProvider.state); | ||
| stateOverridden = true; | ||
| } | ||
| // IMPORTANT: Update coordinates as well for provider finding logic | ||
| java.awt.geom.Point2D.Double providerCoords = preferredProvider.getLonLat(); | ||
| if (providerCoords != null) { | ||
| // Create a new Point2D object to avoid modifying the provider's instance | ||
| demoAttributes.put(Person.COORDINATE, | ||
| new java.awt.geom.Point2D.Double(providerCoords.getX(), providerCoords.getY())); | ||
| coordsOverridden = true; | ||
| } | ||
|
|
||
| if (!cityOverridden || !stateOverridden || !coordsOverridden) { | ||
| System.err.println("WARNING: Preferred provider NPI '" + preferredProvider.npi | ||
| + "' found, but missing location data (City: " + preferredProvider.city | ||
| + ", State: " + preferredProvider.state + ", Coords: " + providerCoords | ||
| + "). Not all location attributes were overridden."); | ||
| } | ||
| // TODO: Consider updating Person.COUNTY if available? Provider doesn't store it. | ||
|
|
||
| } else { | ||
| // Log a warning if the provider wasn't found | ||
| System.err.println("WARNING: Preferred provider NPI '" + getPreferredNPI() + "' configured but provider not found in loaded list. Using demographic location."); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public Provider find(List<Provider> providers, Person person, EncounterType service, long time) { | ||
|
|
||
| String preferredNpi = Config.get(PREFER_ONE_NPI, null); | ||
|
|
||
| System.out.println("PreferredNpi: " + preferredNpi); | ||
|
andrequina marked this conversation as resolved.
Outdated
|
||
|
|
||
| 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); | ||
|
andrequina marked this conversation as resolved.
|
||
| } | ||
|
|
||
| private Provider findPreferredProvider(List<Provider> providers, String preferredNpi, Person person, EncounterType service, long time) { | ||
|
andrequina marked this conversation as resolved.
|
||
| for (Provider provider : providers) { // Iterate the passed-in list | ||
| // Check if this provider matches the preferred NPI | ||
| if (preferredNpi.equals(provider.npi)) { | ||
| System.out.println("FOUND PROVIDER: " + provider.npi + " -- " + preferredNpi); | ||
|
|
||
| // 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; | ||
| } | ||
| } | ||
| } | ||
| 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.