-
Notifications
You must be signed in to change notification settings - Fork 143
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
EA-186 - Loosen providermanagement to an aware_of dependency #230
Changes from 15 commits
cf7c477
94482cf
00bfd8d
417d1a6
db67858
03d6b78
4addd76
7786eeb
5ab37a0
79fc27d
cf56de4
c18eabd
24de377
7ef844b
abae11b
f301b25
8f08c87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package org.openmrs.module.emrapi.account; | ||
|
||
import org.openmrs.module.providermanagement.Provider; | ||
import org.openmrs.Provider; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a backwards-incompatible change to the ProviderIdentifierGenerator interface, though it now supports a broader, not narrower object, so should not pose any problems. |
||
|
||
/** | ||
* Implementers can provide implementations of this interface if they wish | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.openmrs.module.emrapi.account.provider; | ||
|
||
import org.openmrs.OpenmrsMetadata; | ||
import org.openmrs.Person; | ||
import org.openmrs.Provider; | ||
import org.openmrs.annotation.OpenmrsProfile; | ||
import org.openmrs.api.ProviderService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Provides an abstraction over Provider services | ||
*/ | ||
@OpenmrsProfile(modules = {"!providermanagement"}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Provides an implementation of provider-related methods that are used when providermanagement is not installed. This would be where we'd implement logic to support setting roles on the core |
||
public class CoreProviderService implements ProviderServiceFacade { | ||
|
||
private final ProviderService providerService; | ||
|
||
@Autowired | ||
public CoreProviderService(ProviderService providerService) { | ||
this.providerService = providerService; | ||
} | ||
|
||
@Override | ||
public Provider newProvider() { | ||
return new Provider(); | ||
} | ||
|
||
@Override | ||
public Collection<Provider> getProvidersByPerson(Person person) { | ||
return providerService.getProvidersByPerson(person, false); | ||
} | ||
|
||
@Override | ||
public Provider saveProvider(Provider provider) { | ||
return providerService.saveProvider(provider); | ||
} | ||
|
||
@Override | ||
public Object getProviderRole(Provider provider) { | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this also throw the same exception as setProviderRole? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The way I was seeing it, provider role is always null if the providermanagement module is not running. So why throw an exception? The setter is a different situation - the user is trying to set something and the module is unable to accommodate. |
||
} | ||
|
||
@Override | ||
public void setProviderRole(Provider provider, Object providerRole) { | ||
throw new IllegalStateException("Unable to set the provider role, the provider management module is not installed"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package org.openmrs.module.emrapi.account.provider; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Provides an implementation of provider-related methods that are used when providermanagement is installed. This allows us to keep any references to providermanagement hidden behind this conditionally loaded bean. The |
||
|
||
import org.openmrs.Person; | ||
import org.openmrs.Provider; | ||
import org.openmrs.annotation.OpenmrsProfile; | ||
import org.openmrs.api.ProviderService; | ||
import org.openmrs.module.providermanagement.ProviderRole; | ||
import org.openmrs.module.providermanagement.api.ProviderManagementService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Provides an abstraction over Provider services | ||
*/ | ||
@OpenmrsProfile(modules = {"providermanagement:*"}) | ||
public class ProviderManagementProviderService implements ProviderServiceFacade { | ||
|
||
private final ProviderService providerService; | ||
|
||
private final ProviderManagementService providerManagementService; | ||
|
||
@Autowired | ||
public ProviderManagementProviderService(ProviderService providerService, ProviderManagementService providerManagementService) { | ||
this.providerService = providerService; | ||
this.providerManagementService = providerManagementService; | ||
} | ||
|
||
@Override | ||
public Provider newProvider() { | ||
return new org.openmrs.module.providermanagement.Provider(); | ||
} | ||
|
||
@Override | ||
public Collection<org.openmrs.module.providermanagement.Provider> getProvidersByPerson(Person person) { | ||
return providerManagementService.getProvidersByPerson(person, false); | ||
} | ||
|
||
@Override | ||
public Provider saveProvider(Provider provider) { | ||
return providerService.saveProvider(provider); | ||
} | ||
|
||
@Override | ||
public Object getProviderRole(Provider provider) { | ||
if (provider instanceof org.openmrs.module.providermanagement.Provider) { | ||
return ((org.openmrs.module.providermanagement.Provider)provider).getProviderRole(); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public void setProviderRole(Provider provider, Object providerRole) { | ||
if (provider instanceof org.openmrs.module.providermanagement.Provider) { | ||
org.openmrs.module.providermanagement.Provider p = (org.openmrs.module.providermanagement.Provider) provider; | ||
if (providerRole == null) { | ||
p.setProviderRole(null); | ||
} | ||
else { | ||
ProviderRole role = null; | ||
if (providerRole instanceof ProviderRole) { | ||
role = (ProviderRole) providerRole; | ||
} | ||
else if (providerRole instanceof String) { | ||
role = getProviderRole((String) providerRole); | ||
} | ||
else if (providerRole instanceof Integer) { | ||
role = providerManagementService.getProviderRole((Integer) providerRole); | ||
} | ||
else if (providerRole instanceof String[]) { | ||
String[] roles = (String[]) providerRole; | ||
if (roles.length > 1) { | ||
throw new IllegalArgumentException("Only one provider role may be provided"); | ||
} | ||
role = getProviderRole(roles[0]); | ||
} | ||
if (role == null) { | ||
throw new IllegalArgumentException("Unable to set provider role from " + providerRole); | ||
} | ||
((org.openmrs.module.providermanagement.Provider) provider).setProviderRole(role); | ||
} | ||
} | ||
} | ||
|
||
private ProviderRole getProviderRole(String ref) { | ||
ProviderRole role = providerManagementService.getProviderRoleByUuid(ref); | ||
if (role == null) { | ||
try { | ||
Integer roleId = Integer.parseInt(ref); | ||
role = providerManagementService.getProviderRole(roleId); | ||
} | ||
catch (Exception ignored) { | ||
} | ||
} | ||
return role; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.openmrs.module.emrapi.account.provider; | ||
|
||
import org.openmrs.OpenmrsMetadata; | ||
import org.openmrs.Person; | ||
import org.openmrs.Provider; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Provides an abstraction over Provider services | ||
*/ | ||
public interface ProviderServiceFacade { | ||
|
||
Provider newProvider(); | ||
|
||
Collection<? extends Provider> getProvidersByPerson(Person person); | ||
|
||
Provider saveProvider(Provider provider); | ||
|
||
Object getProviderRole(Provider provider); | ||
|
||
void setProviderRole(Provider provider, Object providerRole); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,9 +51,7 @@ | |
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static java.util.Collections.EMPTY_LIST; | ||
import static java.util.Collections.reverseOrder; | ||
import static java.util.Collections.sort; | ||
import static java.util.Collections.*; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strange, I feel like my version of IntelliJ started doing wildcard imports again as well after I turned it off years ago. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
import static org.apache.commons.collections.CollectionUtils.find; | ||
import static org.apache.commons.collections.CollectionUtils.select; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a necessary backwards-incompatibility on the get/set providerRole methods by broadening to Object as ProviderRole is not available when the providermanagement module is not installed.