Commit 48b06973 authored by Alexandre Pocinho's avatar Alexandre Pocinho
Browse files

Work on PATREG-199 improve webservices for GitB

parent 949efadc
Pipeline #272818 failed with stages
in 4 minutes and 58 seconds
......@@ -12,9 +12,19 @@ public class PatientProcessingWebserviceConstants {
public static final String PATIENT_SEARCH_OPERATION = "PatientSearch";
public static final String UUID_OUTPUT_NAME = "UUID";
public static final String PATIENT_INPUT_NAME = "Patient";
public static final String PATIENT_OUTPUT_NAME = "Patient";
public static final String PATIENT_SEARCH_CRITERIA_INPUT_NAME = "PatientSearchCriteria";
public static final String PATIENT_LIST_OUTPUT_NAME = "PatientList";
public static final String PATIENT_CREATE_OPERATION = "PatientCreate";
public static final String PATIENT_UPDATE_OPERATION = "PatientUpdate";
public static final String PATIENT_DELETE_OPERATION = "PatientDelete";
public static final String PATIENT_MERGE_OPERATION = "PatientMerge";
public static final String UUID_PATIENT_TO_DELETE_INPUT_NAME ="UUIDOfPatientToDelete" ;
public static final String UUID_OF_ORIGINAL_PATIENT_INPUT_NAME = "UUIDOfOriginalPatient";
public static final String UUID_OF_DUPLICATED_PATIENT_INPUT_NAME = "UUIDOfDuplicatedPatient";
public static final String DELETE_STATUS_DONE = "Done";
public static final String DELETE_STATUS_GONE = "Gone";
/**
* Private constructor to hide implicit one.
......
......@@ -38,5 +38,5 @@ public interface PatientFeedService {
* @return true if the patient has been delete or false if the patient does not exist any more
* @throws PatientFeedException if the service is not able to correctly delete the patient
*/
boolean deletePatient(String uuid)throws PatientFeedException;
boolean deletePatient(String uuid) throws PatientFeedException;
}
......@@ -41,14 +41,14 @@ public class PatientFeedProcessingService {
* @param processRequest : GITB request received.
* @return ProcessResponse corresponding to the received request
*/
public ProcessResponse processPatientFeed(ProcessRequest processRequest) {
public ProcessResponse processPatientCreate(ProcessRequest processRequest) {
String uuidOfFedPatient;
List<AnyContent> patientToFeed = processRequest.getInput();
if (patientToFeed.size() != 1) {
throw new IllegalArgumentException("ProcessRequest.input shall contain one and only one patient !");
} else if (!PatientProcessingWebserviceConstants.PATIENT_INPUT_NAME.equals(patientToFeed.get(0).getName())) {
throw new IllegalArgumentException(String.format("ProcessRequest.input shall have the name '%s' for a %s operation !",
PatientProcessingWebserviceConstants.PATIENT_INPUT_NAME, PatientProcessingWebserviceConstants.PATIENT_FEED_OPERATION));
PatientProcessingWebserviceConstants.PATIENT_INPUT_NAME, PatientProcessingWebserviceConstants.PATIENT_CREATE_OPERATION));
}
try {
uuidOfFedPatient = patientFeedService.createPatient(mapper.getObject(patientToFeed.get(0), Patient.class));
......@@ -73,7 +73,7 @@ public class PatientFeedProcessingService {
throw new IllegalArgumentException("ProcessRequest.input shall contain one and only one patient !");
} else if (!PatientProcessingWebserviceConstants.PATIENT_INPUT_NAME.equals(patientToFeed.get(0).getName())) {
throw new IllegalArgumentException(String.format("ProcessRequest.input shall have the name '%s' for a %s operation !",
PatientProcessingWebserviceConstants.PATIENT_INPUT_NAME, PatientProcessingWebserviceConstants.PATIENT_FEED_OPERATION));
PatientProcessingWebserviceConstants.PATIENT_INPUT_NAME, PatientProcessingWebserviceConstants.PATIENT_UPDATE_OPERATION));
}
try {
// Appel du service
......@@ -85,6 +85,45 @@ public class PatientFeedProcessingService {
return ProcessResponseWithReportCreator.createFailedProcessResponse(e, patientToFeed.get(0));
}
}
public ProcessResponse processPatientDelete(ProcessRequest processRequest) {
boolean deletedPatientUuid;
List<AnyContent> patientToFeed = processRequest.getInput();
if (patientToFeed.size() != 1) {
throw new IllegalArgumentException("ProcessRequest.input shall contain one and only one patient !");
} else if (!PatientProcessingWebserviceConstants.UUID_PATIENT_TO_DELETE_INPUT_NAME.equals(patientToFeed.get(0).getName())) {
throw new IllegalArgumentException(String.format("ProcessRequest.input shall have the name '%s' for a %s operation !",
PatientProcessingWebserviceConstants.UUID_PATIENT_TO_DELETE_INPUT_NAME, PatientProcessingWebserviceConstants.PATIENT_DELETE_OPERATION));
}
try {
// Appel du service
deletedPatientUuid = patientFeedService.deletePatient(mapper.getObject(patientToFeed.get(0), String.class));
return createPatientDeleteProcessResponse(deletedPatientUuid);
} catch (MappingException e) {
throw new IllegalArgumentException("Cannot decode Request inputs as Patients !");
} catch (PatientFeedException e) {
return ProcessResponseWithReportCreator.createFailedProcessResponse(e, patientToFeed.get(0));
}
}
public ProcessResponse processPatientMerge(ProcessRequest processRequest) {
Patient mergedPatient;
List<AnyContent> patientToFeed = processRequest.getInput();
if (patientToFeed.size() != 2) {
throw new IllegalArgumentException("ProcessRequest.input shall contain two and only two patient !");
} else if (!PatientProcessingWebserviceConstants.UUID_OF_ORIGINAL_PATIENT_INPUT_NAME.equals(patientToFeed.get(0).getName()) && !PatientProcessingWebserviceConstants.UUID_OF_DUPLICATED_PATIENT_INPUT_NAME.equals(patientToFeed.get(1).getName())) {
throw new IllegalArgumentException(String.format("ProcessRequest.input shall have the name '%s' and '%s' for a %s operation !",
PatientProcessingWebserviceConstants.UUID_OF_ORIGINAL_PATIENT_INPUT_NAME, PatientProcessingWebserviceConstants.UUID_OF_DUPLICATED_PATIENT_INPUT_NAME, PatientProcessingWebserviceConstants.PATIENT_MERGE_OPERATION));
}
try {
// Appel du service
mergedPatient = patientFeedService.mergePatient(mapper.getObject(patientToFeed.get(0), String.class),mapper.getObject(patientToFeed.get(1), String.class));
return createProcessResponseWithPatient(mergedPatient);
} catch (MappingException e) {
throw new IllegalArgumentException("Cannot decode Request inputs as Patients !");
} catch (PatientFeedException e) {
return ProcessResponseWithReportCreator.createFailedProcessResponse(e, patientToFeed.get(0));
}
}
/**
* Create a {@link ProcessResponse} to a {@link ProcessRequest} sent to this service after a successful processing.
......@@ -126,13 +165,13 @@ public class PatientFeedProcessingService {
if (patientToReturn == null) {
throw new IllegalArgumentException("Successful operation shall return an existing Patient as an output !");
}
AnyContent uuidAnyContent;
AnyContent patientAnyContent;
try {
patientAnyContent = new MapperObjectToAnyContent().getAnyContent(PatientProcessingWebserviceConstants.PATIENT_OUTPUT_NAME, patientToReturn);
} catch (MappingException e) {
throw new PatientFeedException("Cannot map Patient to AnyContent !");
}
processResponse.getOutput().add(uuidAnyContent);
processResponse.getOutput().add(patientAnyContent);
processResponse.setReport(ProcessResponseWithReportCreator.createReport(TestResultType.SUCCESS));
return processResponse;
}
......
......@@ -66,6 +66,10 @@ public class PatientProcessingService implements ProcessingService {
return patientFeedProcessingService.processPatientUpdate(processRequest);
}else if (PatientProcessingWebserviceConstants.PATIENT_SEARCH_OPERATION.equals(processRequest.getOperation())) {
return patientSearchProcessingService.processPatientSearch(processRequest);
}else if (PatientProcessingWebserviceConstants.PATIENT_DELETE_OPERATION.equals(processRequest.getOperation())) {
return patientFeedProcessingService.processPatientDelete(processRequest);
}else if (PatientProcessingWebserviceConstants.PATIENT_MERGE_OPERATION.equals(processRequest.getOperation())) {
return patientFeedProcessingService.processPatientMerge(processRequest);
} else {
throw new UnsupportedOperationException(String.format("ProcessRequest.operation shall be %s or %s!",
PatientProcessingWebserviceConstants.PATIENT_FEED_OPERATION,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment