Skip to content

Commit

Permalink
Merge pull request #97 from phenotips/PN-490
Browse files Browse the repository at this point in the history
PN-490: Use matching notification widget on similar cases patient tab
  • Loading branch information
veronikaslc committed Aug 9, 2019
2 parents 44d1943 + 9a1cbf3 commit 25de652
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 1,387 deletions.
4 changes: 4 additions & 0 deletions core/client/pom.xml
Expand Up @@ -126,5 +126,9 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</dependency>
</dependencies>
</project>
Expand Up @@ -17,6 +17,7 @@
*/
package org.phenotips.remote.client;

import org.phenotips.matchingnotification.match.PatientMatch;
import org.phenotips.remote.api.OutgoingMatchRequest;
import org.phenotips.remote.common.internal.RemotePatientSimilarityView;

Expand All @@ -34,7 +35,8 @@
@Role
public interface RemoteMatchingService
{
OutgoingMatchRequest sendRequest(String patientId, String remoteServerId, int addTopNGenes);
OutgoingMatchRequest sendRequest(String patientId, String remoteServerId, int addTopNGenes,
List<PatientMatch> matchesList);

OutgoingMatchRequest getLastRequestSent(String patientId, String remoteServerId);

Expand Down
Expand Up @@ -24,6 +24,7 @@
import org.phenotips.data.similarity.PatientSimilarityViewFactory;
import org.phenotips.data.similarity.internal.DefaultAccessType;
import org.phenotips.matchingnotification.MatchingNotificationManager;
import org.phenotips.matchingnotification.match.PatientMatch;
import org.phenotips.remote.api.ApiConfiguration;
import org.phenotips.remote.api.ApiDataConverter;
import org.phenotips.remote.api.ApiViolationException;
Expand Down Expand Up @@ -122,7 +123,8 @@ public class DefaultRemoteMatchingService implements RemoteMatchingService
private MatchingNotificationManager notificationManager;

@Override
public OutgoingMatchRequest sendRequest(String patientId, String remoteServerId, int addTopNGenes)
public OutgoingMatchRequest sendRequest(String patientId, String remoteServerId, int addTopNGenes,
List<PatientMatch> matchesList)
{
DefaultOutgoingMatchRequest request =
new DefaultOutgoingMatchRequest(remoteServerId, ApiConfiguration.LATEST_API_VERSION_STRING, patientId);
Expand Down Expand Up @@ -209,7 +211,8 @@ public OutgoingMatchRequest sendRequest(String patientId, String remoteServerId,

if (ApiConfiguration.HTTP_OK.equals(httpStatus)) {
List<RemotePatientSimilarityView> parsedResults = this.getSimilarityResults(request);
this.notificationManager.saveOutgoingMatches(parsedResults, patientId, request.getRemoteServerId());
matchesList.addAll(this.notificationManager.saveOutgoingMatches(parsedResults, patientId,
request.getRemoteServerId()));
}

return request;
Expand Down
Expand Up @@ -22,12 +22,11 @@
import org.phenotips.matchingnotification.finder.MatchFinder;
import org.phenotips.matchingnotification.finder.internal.AbstractMatchFinder;
import org.phenotips.matchingnotification.match.PatientMatch;
import org.phenotips.matchingnotification.match.internal.CurrentPatientMatch;
import org.phenotips.remote.api.ApiConfiguration;
import org.phenotips.remote.api.OutgoingMatchRequest;
import org.phenotips.remote.client.RemoteMatchingService;
import org.phenotips.remote.common.ApplicationConfiguration;
import org.phenotips.remote.common.RemoteConfigurationManager;
import org.phenotips.remote.common.internal.RemotePatientSimilarityView;

import org.xwiki.component.annotation.Component;
import org.xwiki.model.reference.DocumentReferenceResolver;
Expand All @@ -41,6 +40,7 @@
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.core.Response;

import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -82,59 +82,65 @@ public int getPriority()
}

@Override
protected Set<String> getSupportedServerIdList()
public Set<String> getSupportedServerIdList()
{
return this.getRemotesList();
}

@Override
protected MatchRunStatus specificFindMatches(Patient patient, String remoteId, List<PatientMatch> matchesList)
protected Response specificFindMatches(Patient patient, String remoteId, List<PatientMatch> matchesList)
{
// Checking if a patient has a consent for remote matching
if (!this.consentManager.hasConsent(patient, REMOTE_MATCHING_CONSENT_ID)) {
this.logger.debug("Skipping patient {}. No consent for remote matching", patient.getId());
return MatchRunStatus.NOT_RUN;
}
try {
// Checking if a patient has a consent for remote matching
if (!this.consentManager.hasConsent(patient, REMOTE_MATCHING_CONSENT_ID)) {
this.logger.debug("Skipping patient {}. No consent for remote matching", patient.getId());
return Response.status(Response.Status.FORBIDDEN).build();
}

this.logger.debug("Finding remote matches for patient [{}] on server [{}]", patient.getId(), remoteId);
this.logger.debug("Finding remote matches for patient [{}] on server [{}]", patient.getId(), remoteId);

OutgoingMatchRequest request =
this.matchingService.sendRequest(patient.getId(), remoteId, ADD_TOP_N_GENES_PARAMETER);
OutgoingMatchRequest remoteResponse =
this.matchingService.sendRequest(patient.getId(), remoteId, ADD_TOP_N_GENES_PARAMETER, matchesList);

MatchRunStatus status = checkRequestValidity(request, patient.getId(), remoteId);
if (status != MatchRunStatus.OK) {
return status;
}

List<RemotePatientSimilarityView> parsedResults = this.matchingService.getSimilarityResults(request);
for (RemotePatientSimilarityView result : parsedResults) {
PatientMatch match = new CurrentPatientMatch(result, null, remoteId);
matchesList.add(match);
}
return MatchRunStatus.OK;
}
// If the response is null, the request was never initiated.
if (remoteResponse == null) {
this.logger.warn("Remote match request to [{}] was never initiated for patient [{}]",
remoteId, patient.getId());
return Response.status(Response.Status.NO_CONTENT).build();
}

private MatchRunStatus checkRequestValidity(OutgoingMatchRequest request, String patientId, String remoteId)
{
if (request != null && request.errorContactingRemoteServer()) {
this.logger.error("Unable to connect to remote server [{}] to send a request for patient [{}]",
remoteId, patientId);
return MatchRunStatus.ERROR;
if (!remoteResponse.wasSent()) {
if (remoteResponse.errorContactingRemoteServer()) {
this.logger.error("Unable to connect to remote server [{}]", remoteId);
return Response.status(Response.Status.SERVICE_UNAVAILABLE).build();
} else {
this.logger.error("Could not initialte an MME match request for patient [{}]", patient.getId());
return Response.status(Response.Status.CONFLICT).build();
}
}
// If no valid reply, retrieve the request status code and the JSON.
if (!remoteResponse.gotValidReply()) {
if (remoteResponse.getRequestStatusCode().equals(ApiConfiguration.HTTP_UNAUTHORIZED)) {
this.logger.error("Not authorized to contact selected MME server [{}]", remoteId);
return Response.status(Response.Status.UNAUTHORIZED).build();
}
if (remoteResponse.getRequestStatusCode().equals(ApiConfiguration.HTTP_UNSUPPORTED_API_VERSION)) {
this.logger.error("Unsupported MME version when contacting MME server [{}]", remoteId);
return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE).build();
}
this.logger.error("Remote MME server [{}] rejected match request with status code [{}]",
remoteId, remoteResponse.getRequestStatusCode());
this.logger.error(" ...and error details: [{}]", remoteResponse.getResponseJSON());
return Response.status(Response.Status.NOT_ACCEPTABLE).build();
}

if (request == null || !request.wasSent()) {
this.logger.error("Request for patientId [{}] was not sent to server [{}]", patientId, remoteId);
return MatchRunStatus.NOT_RUN;
}
return Response.status(Response.Status.OK).build();

if (!request.gotValidReply()) {
this.logger.error("Request for patientId {}, remoteId {} returned with status code: {}",
patientId, remoteId, request.getRequestStatusCode());
this.logger.error(" ...and error details: [{}]", request.getResponseJSON());
return MatchRunStatus.ERROR;
} catch (final Exception e) {
this.logger.error("Unexpected exception while generating remote matches: {}", e.getMessage());
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}

return MatchRunStatus.OK;
}

private Set<String> getRemotesList()
Expand Down
1 change: 0 additions & 1 deletion core/pom.xml
Expand Up @@ -35,7 +35,6 @@
<module>common</module>
<module>server</module>
<module>client</module>
<module>rest</module>
<module>metrics</module>
</modules>
</project>
147 changes: 0 additions & 147 deletions core/rest/pom.xml

This file was deleted.

0 comments on commit 25de652

Please sign in to comment.