-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EA-186 - Loosen providermanagement to an aware_of dependency (#230)
This introduces two breaking changes to the API: * Changes to some public methods in AccountDomainWrapper. Most notably, a change to getProviderRole and setProviderRole to operate on an Object rather than a ProviderRole explicitly. * Change to the ProviderIdentifierGenerator#generateIdentifier method to accept an org.openmrs.Provider rather than an org.openmrs.module.providermanagement.Provider.
- Loading branch information
Showing
35 changed files
with
345 additions
and
114 deletions.
There are no files selected for viewing
This file contains 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 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 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
2 changes: 1 addition & 1 deletion
2
api/src/main/java/org/openmrs/module/emrapi/account/ProviderIdentifierGenerator.java
This file contains 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
48 changes: 48 additions & 0 deletions
48
api/src/main/java/org/openmrs/module/emrapi/account/provider/CoreProviderService.java
This file contains 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,48 @@ | ||
package org.openmrs.module.emrapi.account.provider; | ||
|
||
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"}) | ||
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; | ||
} | ||
|
||
@Override | ||
public void setProviderRole(Provider provider, Object providerRole) { | ||
throw new IllegalStateException("Unable to set the provider role, the provider management module is not installed"); | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
...in/java/org/openmrs/module/emrapi/account/provider/ProviderManagementProviderService.java
This file contains 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,97 @@ | ||
package org.openmrs.module.emrapi.account.provider; | ||
|
||
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; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
api/src/main/java/org/openmrs/module/emrapi/account/provider/ProviderServiceFacade.java
This file contains 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,22 @@ | ||
package org.openmrs.module.emrapi.account.provider; | ||
|
||
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); | ||
} |
This file contains 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 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.