Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 94c3203c authored by pm's avatar pm
Browse files

TUs after code review

parent bc2415ee
No related branches found
No related tags found
2 merge requests!5Release/2.0.0,!4Pixm
......@@ -111,30 +111,28 @@ public class PatientRegistryFeedClient {
if (patient.getDateOfBirth() == null || patient.getGender() == null) {
throw new InvalidRequestException("Mandatory fields are missing");
}
String uuid = "";
try {
patient.setUuid("PatientPIXmFeed");
String uuid = client.createPatient(patient);
uuid = client.createPatient(patient);
if (uuid == null || uuid.isBlank()) {
throw new InternalErrorException(NO_UUID);
}
return BusinessToFhirConverter.uuidToBundle(uuid, serverUrl);
} catch (PatientFeedException e) {
switch (e.getCause().getMessage()) {
case "One patientIdentifier is malformed":
throw new UnprocessableEntityException("", e);
case " one PatientIdentifier is duplicated id DB":
throw new ResourceNotFoundException("");
case "System not found":
throw new ResourceNotFoundException("System Domain could not be found when creating Patient");
case "Impossible to cross reference the patient (not saved)":
throw new InternalErrorException("Impossible to cross reference the patient, it will not be saved !", e);
case "Unexpected Exception persisting Patient !":
throw new InternalErrorException("", e);
throw new InternalErrorException("Unexpected Exception persisting Patient !", e);
default:
throw new InternalErrorException("", e);
treatClientBaseErrors(e);
}
}
return BusinessToFhirConverter.uuidToBundle(uuid, serverUrl);
}
/**
......@@ -157,18 +155,7 @@ public class PatientRegistryFeedClient {
patient.setUuid(uuid);
client.updatePatient(patient);
} catch (PatientFeedException e) {
switch (e.getMessage()) {
case "Invalid Request sent to distant PatientFeedProcessingService !":
throw new InvalidRequestException("Invalid Request sent to distant PatientFeedProcessingService !");
case "Invalid operation used on distant PatientFeedProcessingService !":
throw new ResourceNotFoundException("Invalid operation used on distant PatientFeedProcessingService !");
case "Invalid Response from distant PatientFeedProcessingService !":
throw new InternalErrorException("Invalid Response from distant PatientFeedProcessingService !");
case "Exception while Mapping with GITB elements !":
throw new InternalErrorException("Exception while Mapping with GITB elements !");
default:
throw new InternalErrorException("An unhandled error occured");
}
treatClientBaseErrors(e);
}
return UpdateBundle.prepareBundleAfterUpdateOperation(uuid,serverUrl);
......@@ -223,25 +210,17 @@ public class PatientRegistryFeedClient {
if (!deletionStatus) {
throw new ResourceGoneException("Patient with UUID " + uuid);
}
return DeletionBundle.prepareBundleAfterDeletionOperation(uuid, serverUrl);
} catch (PatientFeedException exception) {
switch (exception.getCause().getMessage()) {
//String.format(:"No result found for uuid : %s", uuid)
case "No result found for uuid :":
throw new ResourceNotFoundException("No result found for uuid :");
case "Unexpected Exception deleting Patient !":
throw new InternalErrorException("Unexpected Exception deleting Patient !");
case "Found multiple results for uuid :":
throw new ResourceNotFoundException("Found multiple results for uuid :");
case "Error : Patient uuid can not be null or empty":
throw new InvalidRequestException("Error : Patient uuid can not be null or empty");
case "Error : Patient can not be null ":
throw new InvalidRequestException("Error : Patient can not be null ");
case "The uuid cannot be null or empty":
throw new InternalErrorException("The uuid cannot be null or empty", exception);
case "Cannot proceed to delete":
throw new InternalErrorException("Cannot proceed to delete", exception);
default:
throw new InternalErrorException("Unknown Error append");
treatClientBaseErrors(exception);
}
//FIXME MAPPING FROM PatReg*/
}
return DeletionBundle.prepareBundleAfterDeletionOperation(uuid, serverUrl);
}
/**
......@@ -259,4 +238,25 @@ public class PatientRegistryFeedClient {
serverUrl = "ReplaceByTheRightEndpoint";
}
}
/**
* Private Method which goal is to process the first levels exceptions thrown by the Patient feed client.
*
* @param e the exception thrown
* @throws InternalErrorException throws back the exception with the right http code and the stack trace.
*/
private void treatClientBaseErrors (Exception e) throws InternalErrorException{
switch(e.getMessage()) {
case "Exception while Mapping with GITB elements !":
throw new InternalErrorException("Exception while Mapping with GITB elements !", e);
case "Invalid Response from distant PatientFeedProcessingService !":
throw new InternalErrorException("Invalid Response from distant PatientFeedProcessingService !", e);
case "Invalid operation used on distant PatientFeedProcessingService !":
throw new InternalErrorException("Invalid operation used on distant PatientFeedProcessingService !", e);
case "Invalid Request sent to distant PatientFeedProcessingService !":
throw new InternalErrorException("Invalid Request sent to distant PatientFeedProcessingService !", e);
default:
throw new InternalErrorException("An unhandled error was thrown.", e);
}
}
}
......@@ -49,12 +49,11 @@ public class CHBundleProvider implements IResourceProvider {
}
/**
* Method called to create a Patient
* Method called to create a Patient contained in an iti 93 bundle
*
* @param iti93Bundle
* @return
* @param iti93Bundle : the Bundle containing the patient to add to Patient Registry.
* @return a Method Outcome containing
*/
@Create
public MethodOutcome create(@ResourceParam Bundle iti93Bundle) {
if (iti93Bundle == null || iti93Bundle.getEntry().isEmpty()) {
......@@ -66,10 +65,12 @@ public class CHBundleProvider implements IResourceProvider {
}
/**
* Method to delete a Patient via a bundle
* Method to delete a Patient - represented by its uuid - and a bundle representing the Patientas well.
*
* @param iti93Bundle
* @return
* @param theId : the uuid of the patient to delete in database
* @param iti93Bundle : the bundle containing the patient to delete.
*
* @return a method outcome containing a response Bundle with the patient and the http response.
*/
@Delete
public MethodOutcome delete(@IdParam IdType theId, @ResourceParam Bundle iti93Bundle) {
......@@ -89,6 +90,13 @@ public class CHBundleProvider implements IResourceProvider {
}
}
/**
* Method called to update a Patient - represented by its uuid - with another Patient included in an iti 93 Bundle.
*
* @param theId : the id of the Patient to update in the database
* @param iti93Bundle : the new value of the patient to be saved.
* @return a Method Outcome containing the response bundle with a representation of the patient, and the http response
*/
@Update
public MethodOutcome updatePatient(@IdParam IdType theId, @ResourceParam Bundle iti93Bundle) {
......@@ -115,6 +123,11 @@ public class CHBundleProvider implements IResourceProvider {
}
/**
* Private method to get back the Patient contained in an iti 93 Bundle.
* @param pixmFeed : the bundle in which to recover the Patient.
* @return the patient contained in the bundle for further checks and use.
*/
private Patient iti93BundleToPatient(Bundle pixmFeed) {
List<Bundle.BundleEntryComponent> listOfEntries = pixmFeed.getEntry();
if (listOfEntries.size() != 2) {
......
......@@ -116,10 +116,10 @@ public class ChPatientResourceProvider implements IResourceProvider {
}
/**
* Method called to create a Patient
* Method called to create a Patient on Patient Registry
*
* @param iti93Patient
* @return
* @param iti93Patient : the Patient to create.
* @return a MethodOutcome containing a representation of the patient created.
*/
@Create
public MethodOutcome create(@ResourceParam Patient iti93Patient) {
......@@ -135,7 +135,7 @@ public class ChPatientResourceProvider implements IResourceProvider {
if (methodOutcome.getResource() != null) {
return methodOutcome;
} else {
throw new NullPointerException("MethodOutcome was not created");
throw new ResourceNotFoundException("MethodOutcome was not created");
}
} catch (ConversionException e) {
......@@ -245,6 +245,11 @@ public class ChPatientResourceProvider implements IResourceProvider {
return parametersResults;
}
/**
* Private method used to transform a Source Identifier into an Entity Identifier for Patient Registry database
* @param sourceIdentifier : the source Identifier to convert
* @return An Entity Identifier understood by Patient Registry.
*/
private EntityIdentifier createEntityIdentifierFromSourceIdentifier(TokenParam sourceIdentifier) {
if (sourceIdentifier == null) {
throw new InvalidRequestException(SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND);
......
......@@ -357,7 +357,7 @@ class ChPatientResourceProviderTest {
void testCreatePatientNPE() {
Patient iti93Bundle = new Patient();
iti93Bundle.setId("Plop");
assertThrows(NullPointerException.class, () -> feed_provider.create(iti93Bundle));
assertThrows(ResourceNotFoundException.class, () -> feed_provider.create(iti93Bundle));
}
@Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment