Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 70ed415e authored by Alexandre Pocinho's avatar Alexandre Pocinho
Browse files

delete and update TU are fixed

parent 03499b33
No related branches found
No related tags found
3 merge requests!10Remove hardcoded mandatory targetSytem + upgrade HAPI FHIR version,!9Implements ITI-104 transaction + external validation,!8Implements ITI-104 features with external validation process
......@@ -11,8 +11,6 @@ import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import net.ihe.gazelle.adapter.connector.ConversionException;
import net.ihe.gazelle.adapter.connector.FhirToGazelleRegistryConverter;
import net.ihe.gazelle.app.patientregistryapi.application.PatientFeedException;
......@@ -128,7 +126,7 @@ public class IhePatientResourceProvider implements IResourceProvider {
// the '?' is surely not at the beginning of the string
EntityIdentifier identifier = createEntityIdentifierFromConditional(theConditional);
if(identifier == null){
throw new UnprocessableEntityException(NO_ID_PROVIDED);
throw new UnprocessableEntityException(NO_IDENTIFIER_PROVIDED);
}
try {
Patient patientUpdated;
......
......@@ -13,6 +13,7 @@ import net.ihe.gazelle.application.PatientRegistryXRefSearchClient;
import net.ihe.gazelle.business.provider.mock.*;
import net.ihe.gazelle.business.service.RequestValidatorService;
import org.hl7.fhir.r4.model.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
......@@ -30,7 +31,7 @@ class IhePatientResourceProviderTest {
public static final String UNPROCESSABLE_ENTITY_EXCEPTION_HAS_TO_BE_THROWN = "Unprocessable Entity Exception has to be thrown";
public static final String INVALID_REQUEST_EXCEPTION_HAS_TO_BE_THROWN = "InvalideRequestException has to be thrown";
public static final String NO_ID_PROVIDED = "No ID provided";
public static final String ERROR_IN_DELETION = "Error in deletion";
private static PatientRegistryXRefSearchClient xRefSearchClientMock;
private static PatientRegistrySearchClient searchClientMock;
private static RequestValidatorService rvs;
......@@ -143,66 +144,68 @@ class IhePatientResourceProviderTest {
fail(UNPROCESSABLE_ENTITY_EXCEPTION_HAS_TO_BE_THROWN);
}
}
/*
@Test
void testUpdatePatient() {
//Given
Patient patient = provider.createFhirResourceFromString(Patient.class, patientString);
String theConditional = "Patient?identifier=system%7C00001";
//When
MethodOutcome mo = provider.update(null, null, patient, iti104Request);
MethodOutcome mo = provider.update(null, theConditional, patient, iti104Request);
//Then
Patient patientReturned = (Patient) mo.getResource();
assertEquals("PatientIsUpdated", patientReturned.getId());
}
@Test
void testUpdatePatientWithPatientFeedException() {
//Given
Patient patient = provider.createFhirResourceFromString(Patient.class, patientString);
patient.setId("PatientFeedException");
//When
try {
//When
provider.update(null, null, patient, iti104Request);
} catch (UnprocessableEntityException e) {
//Then
assertEquals(IhePatientResourceProvider.PATIENT_FEED_CLIENT_IS_NOT_SET, e.getMessage());
} catch (Exception e) {
fail(UNPROCESSABLE_ENTITY_EXCEPTION_HAS_TO_BE_THROWN);
}
}
@Test
void testUpdatePatientWithPatientFeedException() {
//Given
Patient patient = provider.createFhirResourceFromString(Patient.class, patientString);
String theConditional = "Patient?identifier=system%7C00001";
@Test
void testUpdatePatientWithConversionException() {
//Given
Patient patient = provider.createFhirResourceFromString(Patient.class, patientString);
patient.setId("ConversionException");
try {
//When
provider.update( null, null, patient, iti104Request);
} catch (UnprocessableEntityException e) {
//Then
assertEquals(IhePatientResourceProvider.FHIR_PATIENT_COULD_NOT_BE_CONVERTED_TO_REGISTRY_PATIENT, e.getMessage());
} catch (Exception e) {
fail(UNPROCESSABLE_ENTITY_EXCEPTION_HAS_TO_BE_THROWN);
try {
//When
provider.update(null, theConditional, patient, iti104Request);
} catch (UnprocessableEntityException e) {
//Then
assertEquals(IhePatientResourceProvider.PATIENT_FEED_CLIENT_IS_NOT_SET, e.getMessage());
} catch (Exception e) {
fail(UNPROCESSABLE_ENTITY_EXCEPTION_HAS_TO_BE_THROWN);
}
}
}
@Test
void testUpdatePatientWithNullId() {
//Given
Patient patient = provider.createFhirResourceFromString(Patient.class, patientString);
try {
//When
provider.update( null, null, patient, iti104Request);
} catch (UnprocessableEntityException e) {
//Then
assertEquals(NO_IDENTIFIER_PROVIDED, e.getMessage());
} catch (Exception e) {
fail(UNPROCESSABLE_ENTITY_EXCEPTION_HAS_TO_BE_THROWN);
}
}
*/
@Test
void testUpdatePatientWithConversionException() {
//Given
Patient patient = provider.createFhirResourceFromString(Patient.class, patientString);
String theConditional = "Patient?identifier=system%7CConversionException";
try {
//When
provider.update(null, theConditional, patient, iti104Request);
} catch (UnprocessableEntityException e) {
//Then
assertEquals(IhePatientResourceProvider.FHIR_PATIENT_COULD_NOT_BE_CONVERTED_TO_REGISTRY_PATIENT, e.getMessage());
} catch (Exception e) {
fail(UNPROCESSABLE_ENTITY_EXCEPTION_HAS_TO_BE_THROWN);
}
}
@Test
void testUpdatePatientWithNullConditional() {
//Given
Patient patient = provider.createFhirResourceFromString(Patient.class, patientString);
try {
//When
provider.update(null, null, patient, iti104Request);
} catch (UnprocessableEntityException e) {
//Then
assertEquals(NO_IDENTIFIER_PROVIDED, e.getMessage());
} catch (Exception e) {
fail(UNPROCESSABLE_ENTITY_EXCEPTION_HAS_TO_BE_THROWN);
}
}
@Test
void testReadOk() {
//Given
......@@ -248,27 +251,30 @@ class IhePatientResourceProviderTest {
void testGetResource() {
assertEquals(Patient.class, provider.getResourceType());
}
/*
@Test
void testDelete() {
//Given
IdType id = new IdType(40);
String theConditional = "Patient?identifier=system%7C00001";
//When
MethodOutcome mo = provider.delete(id, iti104Request);
MethodOutcome mo = provider.delete(id, theConditional, iti104Request);
//Then
assertEquals(200, mo.getResponseStatusCode());
}
@Test
void testDeleteWithNullId() {
void testDeleteWithNoSystemValueForIdentifier() {
//Given
IdType id = new IdType();
String theConditional = "Patient?identifier=";
try {
//when
provider.delete(id, iti104Request);
Assertions.assertThrows(UnprocessableEntityException.class, () -> provider.delete(id, theConditional, iti104Request));
} catch (UnprocessableEntityException e) {
//Then
assertEquals(IhePatientResourceProvider.NO_ID_PROVIDED, e.getMessage());
assertEquals(ERROR_IN_DELETION, e.getMessage());
} catch (Exception e) {
fail(UNPROCESSABLE_ENTITY_EXCEPTION_HAS_TO_BE_THROWN);
}
......@@ -278,17 +284,47 @@ class IhePatientResourceProviderTest {
void testDeleteWithErrorDuringDeletion() {
//Given
IdType id = new IdType(42);
String theConditional = "Patient?identifier=system%7CFAILED";
try {
//When
provider.delete(id, theConditional, iti104Request);
} catch (UnprocessableEntityException e) {
//Then
assertTrue(e.getCause().getMessage().contains(PatientRegistryFeedClientMock.CANNOT_DELETE_PATIENT_WITH_IDENTIFIER));
} catch (Exception e) {
fail(UNPROCESSABLE_ENTITY_EXCEPTION_HAS_TO_BE_THROWN);
}
}
@Test
void testDeleteWithNullReturned() {
//Given
IdType id = new IdType(42);
String theConditional = "Patient?identifier=system%7CNULL";
//When
MethodOutcome mo = provider.delete(id, theConditional, iti104Request);
//Then
assertEquals(404, mo.getResponseStatusCode());
}
@Test
void testDeleteWithNullIdentifier() {
//Given
IdType id = new IdType(42);
String theConditional = "";
try {
//When
provider.delete(id, iti104Request);
provider.delete(id, theConditional, iti104Request);
} catch (UnprocessableEntityException e) {
//Then
assertEquals(IhePatientResourceProvider.ERROR_IN_DELETION, e.getMessage());
assertEquals(NO_IDENTIFIER_PROVIDED, e.getMessage());
} catch (Exception e) {
fail(UNPROCESSABLE_ENTITY_EXCEPTION_HAS_TO_BE_THROWN);
}
}
*/
@Test
void findPatientsByIdentifierUrn() {
......
package net.ihe.gazelle.business.provider.mock;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException;
import net.ihe.gazelle.adapter.connector.ConversionException;
import net.ihe.gazelle.adapter.connector.GazelleRegistryToFhirConverter;
import net.ihe.gazelle.app.patientregistryapi.application.PatientFeedException;
......@@ -15,6 +18,8 @@ public class PatientRegistryFeedClientMock extends PatientRegistryFeedClient {
public static final String URN_OK = "URN_OK";
private static final String CROSS_REFERENCE = "Cross Reference";
public static final String CANNOT_DELETE_PATIENT_WITH_IDENTIFIER = "Cannot delete patient with identifier ";
public PatientRegistryFeedClientMock() {
}
......@@ -39,24 +44,34 @@ public class PatientRegistryFeedClientMock extends PatientRegistryFeedClient {
@Override
public Patient updatePatient(net.ihe.gazelle.app.patientregistryapi.business.Patient patientToUpdate, EntityIdentifier identifier) throws PatientFeedException, ConversionException {
// return switch (uuid) {
// case "PatientFeedException" -> throw new PatientFeedException();
// case "ConversionException" -> throw new ConversionException();
// default -> {
// Patient patient = GazelleRegistryToFhirConverter.convertPatient(patientToUpdate);
// patient.setId("PatientIsUpdated");
// yield patient;
// }
// };
return null;
return switch (identifier.getValue()) {
case "PatientFeedException" -> throw new PatientFeedException();
case "ConversionException" -> throw new ConversionException();
default -> {
Patient patient = GazelleRegistryToFhirConverter.convertPatient(patientToUpdate);
patient.setId("PatientIsUpdated");
yield patient;
}
};
}
@Override
public boolean delete(String uuid) throws PatientFeedException {
if ("42".equals(uuid)) {
throw new PatientFeedException();
public EntityIdentifier delete(EntityIdentifier identifier){
if (identifier == null || identifier.getValue() == null) {
throw new InvalidRequestException("Invalid identifier");
}
return true;
if ("FAILED".equals(identifier.getValue())) {
throw new ResourceGoneException(CANNOT_DELETE_PATIENT_WITH_IDENTIFIER + identifier);
}
if ("NULL".equals(identifier.getValue())) {
identifier = null;
}
return identifier;
}
}
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