diff --git a/src/main/java/net/ihe/gazelle/adapter/connector/BundleToPatientRegistryConverter.java b/src/main/java/net/ihe/gazelle/adapter/connector/BundleToPatientRegistryConverter.java index 02cadb5b9b4f42a2c358b1cba09e3630d60e2269..f5624681542156cf8846690817ee5531f67638f1 100644 --- a/src/main/java/net/ihe/gazelle/adapter/connector/BundleToPatientRegistryConverter.java +++ b/src/main/java/net/ihe/gazelle/adapter/connector/BundleToPatientRegistryConverter.java @@ -18,8 +18,6 @@ public class BundleToPatientRegistryConverter { /** * private constructor to override the public implicit one. - * TODO je n'ai pas de TU sur cette classe, du coup je verifie tous les champs mais il y a peut-�tre des modifs � faire ar exemple pour les - * champs minimum attendus */ private BundleToPatientRegistryConverter() { } @@ -163,7 +161,6 @@ public class BundleToPatientRegistryConverter { return net.ihe.gazelle.app.patientregistryapi.business.AddressUse.BILLING; case HOME: return net.ihe.gazelle.app.patientregistryapi.business.AddressUse.HOME; - case NULL: case OLD: return net.ihe.gazelle.app.patientregistryapi.business.AddressUse.BAD; case TEMP: diff --git a/src/main/java/net/ihe/gazelle/application/PatientRegistryFeedClient.java b/src/main/java/net/ihe/gazelle/application/PatientRegistryFeedClient.java index 8490e98b857d028be8306b1cda631d9404d21dd8..8e5118916152cbfaf41a18233ec71914244df3a6 100644 --- a/src/main/java/net/ihe/gazelle/application/PatientRegistryFeedClient.java +++ b/src/main/java/net/ihe/gazelle/application/PatientRegistryFeedClient.java @@ -160,23 +160,17 @@ public class PatientRegistryFeedClient { patient.setUuid(uuid); client.updatePatient(patient); } catch (PatientFeedException e) { - switch (e.getCause().getMessage()) { - case "One patientIdentifier is malformed": - throw new UnprocessableEntityException("", e); - case "One PatientIdentifier is duplicated in DB": - throw new ResourceNotFoundException(""); - case "System not found": - throw new ResourceNotFoundException("System Domain could not be found when updating Patient"); - case "Unexpected Exception persisting Patient !": - throw new InternalErrorException("", e); - case "Null crossReference parameter for update": - throw new InternalErrorException("", e); - case "Persistence Error": - throw new InternalErrorException("", e); - case "Exception performing the read operation for requested criteria !": - throw new InternalErrorException("", 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("", e); + throw new InternalErrorException("An unhandled error occured"); } } return UpdateBundle.prepareBundleAfterUpdateOperation(uuid,serverUrl); diff --git a/src/main/java/net/ihe/gazelle/business/provider/CHBundleProvider.java b/src/main/java/net/ihe/gazelle/business/provider/CHBundleProvider.java index 8e032cab06fdaeb45e0cf4f0369464d6b0e67eab..43a1aa822bb9f28093895c0d3b33d4dd7be53293 100644 --- a/src/main/java/net/ihe/gazelle/business/provider/CHBundleProvider.java +++ b/src/main/java/net/ihe/gazelle/business/provider/CHBundleProvider.java @@ -1,11 +1,9 @@ package net.ihe.gazelle.business.provider; -import ca.uhn.fhir.rest.annotation.Create; -import ca.uhn.fhir.rest.annotation.Delete; -import ca.uhn.fhir.rest.annotation.IdParam; -import ca.uhn.fhir.rest.annotation.ResourceParam; +import ca.uhn.fhir.rest.annotation.*; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.server.IResourceProvider; +import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import net.ihe.gazelle.application.PatientRegistryFeedClient; import net.ihe.gazelle.lib.annotations.Package; @@ -76,6 +74,10 @@ public class CHBundleProvider implements IResourceProvider { @Delete public MethodOutcome delete(@IdParam IdType theId, @ResourceParam Bundle iti93Bundle) { + if (theId == null || theId.isEmpty()) { + throw new InvalidRequestException("Invalid ID Parameter, either null or empty."); + } + if (iti93Bundle == null || iti93Bundle.getEntry().isEmpty()) { throw new InvalidRequestException("Invalid bundle provided, either null or empty."); } @@ -87,6 +89,32 @@ public class CHBundleProvider implements IResourceProvider { } } + @Update + public MethodOutcome updatePatient(@IdParam IdType theId, @ResourceParam Bundle iti93Bundle) { + + if (theId == null || theId.isEmpty()) { + throw new InvalidRequestException("Invalid ID Parameter, either null or empty."); + } + + if (iti93Bundle == null || iti93Bundle.getEntry().isEmpty()) { + throw new InvalidRequestException("Invalid bundle provided, either null or empty."); + } + + try { + Patient updatedPatient = iti93BundleToPatient(iti93Bundle); + return chPatientResourceProvider.update(theId, updatedPatient); + } catch (InvalidRequestException e) { + if (e.getMessage().equals("Cannot find resource Type Patient in Bundle")) { + throw e; + } else { + throw new InvalidRequestException("Patient Resource Provider could not take request.", e); + } + } catch (InternalErrorException e) { + throw new InternalErrorException("Patient Resource Provider could not take request.", e); + } + + } + private Patient iti93BundleToPatient(Bundle pixmFeed) { List<Bundle.BundleEntryComponent> listOfEntries = pixmFeed.getEntry(); if (listOfEntries.size() != 2) { diff --git a/src/main/java/net/ihe/gazelle/business/provider/ChPatientResourceProvider.java b/src/main/java/net/ihe/gazelle/business/provider/ChPatientResourceProvider.java index 600a74ce2c87b2e16a16924d8666a700ea794cd7..8f3e889627680dea237f8b7c87ee3635325d9462 100644 --- a/src/main/java/net/ihe/gazelle/business/provider/ChPatientResourceProvider.java +++ b/src/main/java/net/ihe/gazelle/business/provider/ChPatientResourceProvider.java @@ -193,7 +193,7 @@ public class ChPatientResourceProvider implements IResourceProvider { @Delete public MethodOutcome delete(@IdParam IdType theId) { - if (theId == null) { + if (theId == null || theId.isEmpty()) { throw new InvalidRequestException(NO_ID_PROVIDED); } patientLogger.warn(theId.getId()); @@ -204,10 +204,7 @@ public class ChPatientResourceProvider implements IResourceProvider { patientLogger.warn("On en est au provider de patient"); String uuid = theId.getValue(); - if (uuid.isBlank()) { - patientLogger.error(NO_ID_PROVIDED); - throw new InvalidRequestException(NO_ID_PROVIDED); - } + try { patientLogger.error("On essaye de delete"); MethodOutcome methodOutcome = new MethodOutcome(); diff --git a/src/test/java/net/ihe/gazelle/adapter/connector/BundleToPatientRegistryConverterTest.java b/src/test/java/net/ihe/gazelle/adapter/connector/BundleToPatientRegistryConverterTest.java new file mode 100644 index 0000000000000000000000000000000000000000..c0500d518e1b197d3e54a346b09cf47bd31f2d4d --- /dev/null +++ b/src/test/java/net/ihe/gazelle/adapter/connector/BundleToPatientRegistryConverterTest.java @@ -0,0 +1,202 @@ +package net.ihe.gazelle.adapter.connector; + +import io.qameta.allure.*; +import net.ihe.gazelle.app.patientregistryapi.business.*; +import net.ihe.gazelle.app.patientregistryapi.business.Person; +import org.hl7.fhir.r4.model.*; +import org.hl7.fhir.r4.model.Address; +import org.hl7.fhir.r4.model.Patient; +import org.junit.jupiter.api.Test; + +import java.time.LocalDate; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + +@Feature("BundleConverter") +public class BundleToPatientRegistryConverterTest { + + @Test + @Description("Test on unitary conversion") + @Severity(SeverityLevel.CRITICAL) + @Story("Name conversion") + void TestPatientNameConverion(){ + Patient pat = new Patient(); + HumanName name = new HumanName(); + name.addGiven("Patrick"); + name.setUse(HumanName.NameUse.TEMP); + name.setFamily("Timsit"); + name.addPrefix("Jr"); + name.addSuffix("Sr"); + pat.addName(name); + + try { + net.ihe.gazelle.app.patientregistryapi.business.Patient response = BundleToPatientRegistryConverter.hl7PatientToPatientRegistry(pat); + PersonName responseName = response.getNames().get(0); + assertEquals("Patrick", responseName.getGivens().get(0)); + assertEquals("TEMP", responseName.getUse()); + assertEquals("Timsit", responseName.getFamily()); + assertEquals("Jr", responseName.getPrefix()); + assertEquals("Sr", responseName.getSuffix()); + } catch (ConversionException e) { + fail("could not convert Patient with just a name"); + } + + } + + @Test + @Description("Test on unitary conversion") + @Severity(SeverityLevel.CRITICAL) + @Story("Gender conversion") + void TestPatientGenderConverion(){ + + Patient pat1 = new Patient(); + pat1.setGender(Enumerations.AdministrativeGender.FEMALE); + + Patient pat2 = new Patient(); + pat2.setGender(Enumerations.AdministrativeGender.MALE); + + Patient pat3 = new Patient(); + pat3.setGender(Enumerations.AdministrativeGender.OTHER); + + Patient pat4 = new Patient(); + pat4.setGender(Enumerations.AdministrativeGender.UNKNOWN); + + try { + net.ihe.gazelle.app.patientregistryapi.business.Patient response = BundleToPatientRegistryConverter.hl7PatientToPatientRegistry(pat1); + assertEquals(GenderCode.FEMALE, response.getGender()); + + response = BundleToPatientRegistryConverter.hl7PatientToPatientRegistry(pat2); + assertEquals(GenderCode.MALE, response.getGender()); + + response = BundleToPatientRegistryConverter.hl7PatientToPatientRegistry(pat3); + assertEquals(GenderCode.OTHER, response.getGender()); + + response = BundleToPatientRegistryConverter.hl7PatientToPatientRegistry(pat4); + assertEquals(GenderCode.UNDEFINED, response.getGender()); + + } catch (ConversionException e) { + fail("could not convert Patient with just a gender"); + } + + } + + @Test + @Description("Test on unitary conversion") + @Severity(SeverityLevel.CRITICAL) + @Story("Contact conversion") + void TestPatientContactConverion(){ + + Patient pat = new Patient(); + Patient.ContactComponent comp = new Patient.ContactComponent(); + comp.setGender(Enumerations.AdministrativeGender.OTHER); + Address address = new Address(); + address.addLine("Henlo"); + comp.setAddress(address); + comp.setName(new HumanName().addGiven("toto")); + pat.addContact(comp); + + try { + net.ihe.gazelle.app.patientregistryapi.business.Patient response = BundleToPatientRegistryConverter.hl7PatientToPatientRegistry(pat); + Person contact = response.getContacts().get(0); + assertEquals(GenderCode.OTHER, contact.getGender()); + assertEquals("Henlo", contact.getAddresses().get(0).getLines().get(0)); + assertEquals("toto", contact.getNames().get(0).getGivens().get(0)); + + } catch (ConversionException e) { + fail("could not convert Patient with just a contact"); + } + + } + + @Test + @Description("Test on unitary conversion") + @Severity(SeverityLevel.CRITICAL) + @Story("Address conversion") + void TestPatientAddressConverion(){ + + Patient pat = new Patient(); + Address address = new Address(); + address.setCity("Chicoutimi"); + address.setCountry("Canada"); + address.setPostalCode("G7B 0G5"); + address.setState("Québec"); + address.setUse(Address.AddressUse.TEMP); + address.addLine("4 boulevard de l'Université"); + pat.addAddress(address); + + Patient pat1 = new Patient(); + Address address1 = new Address(); + address1.setUse(Address.AddressUse.BILLING); + pat1.addAddress(address1); + Patient pat2 = new Patient(); + Address address2 = new Address(); + address2.setUse(Address.AddressUse.HOME); + pat2.addAddress(address2); + Patient pat3 = new Patient(); + Address address3 = new Address(); + address3.setUse(Address.AddressUse.OLD); + pat3.addAddress(address3); + Patient pat4 = new Patient(); + Address address4 = new Address(); + address4.setUse(Address.AddressUse.WORK); + pat4.addAddress(address4); + + try { + net.ihe.gazelle.app.patientregistryapi.business.Patient response = BundleToPatientRegistryConverter.hl7PatientToPatientRegistry(pat); + net.ihe.gazelle.app.patientregistryapi.business.Address responseAddress = response.getAddresses().get(0); + assertEquals("Chicoutimi", responseAddress.getCity()); + assertEquals("Canada", responseAddress.getCountryIso3()); + assertEquals("G7B 0G5", responseAddress.getPostalCode()); + assertEquals("Québec", responseAddress.getState()); + assertEquals(AddressUse.TEMPORARY, responseAddress.getUse()); + assertEquals("4 boulevard de l'Université", responseAddress.getLines().get(0)); + + response = BundleToPatientRegistryConverter.hl7PatientToPatientRegistry(pat1); + responseAddress = response.getAddresses().get(0); + assertEquals(AddressUse.BILLING, responseAddress.getUse()); + + response = BundleToPatientRegistryConverter.hl7PatientToPatientRegistry(pat2); + responseAddress = response.getAddresses().get(0); + assertEquals(AddressUse.HOME, responseAddress.getUse()); + + response = BundleToPatientRegistryConverter.hl7PatientToPatientRegistry(pat3); + responseAddress = response.getAddresses().get(0); + assertEquals(AddressUse.BAD, responseAddress.getUse()); + + response = BundleToPatientRegistryConverter.hl7PatientToPatientRegistry(pat4); + responseAddress = response.getAddresses().get(0); + assertEquals(AddressUse.WORK, responseAddress.getUse()); + + } catch (ConversionException e) { + fail("could not convert Patient with just an address"); + } + + } + + @Test + @Description("Test on unitary conversion") + @Severity(SeverityLevel.CRITICAL) + @Story("Single parameters conversion") + void TestPatientParametersConverion(){ + + LocalDate dateValue = LocalDate.now(); + + Patient pat = new Patient(); + pat.setActive(true); + pat.setBirthDate(java.sql.Date.valueOf(dateValue)); + pat.setId("Hello"); + + try { + net.ihe.gazelle.app.patientregistryapi.business.Patient response = BundleToPatientRegistryConverter.hl7PatientToPatientRegistry(pat); + assertEquals(java.sql.Date.valueOf(dateValue), response.getDateOfBirth()); + assertEquals("Hello", response.getUuid()); + assertEquals(true, response.isActive()); + + } catch (ConversionException e) { + fail("could not convert Patient with simple parameters"); + } + + } + +} diff --git a/src/test/java/net/ihe/gazelle/adapter/connector/BusinessToFhirConverterTest.java b/src/test/java/net/ihe/gazelle/adapter/connector/BusinessToFhirConverterTest.java new file mode 100644 index 0000000000000000000000000000000000000000..6a24c13c1c027be3e8559aa6d6670bb80a3dbe6b --- /dev/null +++ b/src/test/java/net/ihe/gazelle/adapter/connector/BusinessToFhirConverterTest.java @@ -0,0 +1,240 @@ +package net.ihe.gazelle.adapter.connector; + +import io.qameta.allure.Description; +import io.qameta.allure.Severity; +import io.qameta.allure.SeverityLevel; +import io.qameta.allure.Story; +import io.qameta.allure.Feature; +import net.ihe.gazelle.app.patientregistryapi.business.*; +import org.hl7.fhir.r4.model.Enumerations; +import org.hl7.fhir.r4.model.Patient; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + +@Feature("Fhir to Business Converter") +public class BusinessToFhirConverterTest { + + @Test + @Description("Test on unitary conversion") + @Severity(SeverityLevel.CRITICAL) + @Story("Gender conversion") + void TestPatientGenderConversion(){ + + net.ihe.gazelle.app.patientregistryapi.business.Patient pat1 = new net.ihe.gazelle.app.patientregistryapi.business.Patient(); + pat1.setGender(GenderCode.FEMALE); + + net.ihe.gazelle.app.patientregistryapi.business.Patient pat2 = new net.ihe.gazelle.app.patientregistryapi.business.Patient(); + pat2.setGender(GenderCode.MALE); + + net.ihe.gazelle.app.patientregistryapi.business.Patient pat3 = new net.ihe.gazelle.app.patientregistryapi.business.Patient(); + pat3.setGender(GenderCode.OTHER); + + net.ihe.gazelle.app.patientregistryapi.business.Patient pat4 = new net.ihe.gazelle.app.patientregistryapi.business.Patient(); + pat4.setGender(GenderCode.UNDEFINED); + + try { + Patient response = BusinessToFhirConverter.patientToFhirPatient(pat1); + assertEquals(Enumerations.AdministrativeGender.FEMALE, response.getGender()); + + response = BusinessToFhirConverter.patientToFhirPatient(pat2); + assertEquals(Enumerations.AdministrativeGender.MALE, response.getGender()); + + response = BusinessToFhirConverter.patientToFhirPatient(pat3); + assertEquals(Enumerations.AdministrativeGender.OTHER, response.getGender()); + + response = BusinessToFhirConverter.patientToFhirPatient(pat4); + assertEquals(Enumerations.AdministrativeGender.UNKNOWN, response.getGender()); + + } catch (ConversionException e) { + fail("could not convert Patient with just a gender"); + } + + } + + @Test + @Description("Test on unitary conversion") + @Severity(SeverityLevel.CRITICAL) + @Story("Address conversion") + void TestPatientAddressConversion(){ + + net.ihe.gazelle.app.patientregistryapi.business.Patient pat = new net.ihe.gazelle.app.patientregistryapi.business.Patient(); + Address address = new Address(); + address.setCity("Chicoutimi"); + address.setCountryIso3("Canada"); + address.setPostalCode("G7B 0H3"); + address.setUse(AddressUse.WORK); + address.setState("Québec"); + address.addLine("4 boulevard de l'université"); + pat.addAddress(address); + + net.ihe.gazelle.app.patientregistryapi.business.Patient pat1 = new net.ihe.gazelle.app.patientregistryapi.business.Patient(); + Address address1 = new Address(); + address1.setUse(AddressUse.PRIMARY_HOME); + pat1.addAddress(address1); + + net.ihe.gazelle.app.patientregistryapi.business.Patient pat2 = new net.ihe.gazelle.app.patientregistryapi.business.Patient(); + Address address2 = new Address(); + address2.setUse(AddressUse.TEMPORARY); + pat2.addAddress(address2); + + net.ihe.gazelle.app.patientregistryapi.business.Patient pat3 = new net.ihe.gazelle.app.patientregistryapi.business.Patient(); + Address address3 = new Address(); + address3.setUse(AddressUse.BAD); + pat3.addAddress(address3); + + net.ihe.gazelle.app.patientregistryapi.business.Patient pat4 = new net.ihe.gazelle.app.patientregistryapi.business.Patient(); + Address address4 = new Address(); + address4.setUse(AddressUse.BILLING); + pat4.addAddress(address4); + + try { + Patient response = BusinessToFhirConverter.patientToFhirPatient(pat); + org.hl7.fhir.r4.model.Address responseAddress = response.getAddress().get(0); + assertEquals("Chicoutimi", responseAddress.getCity()); + assertEquals("Canada", responseAddress.getCountry()); + assertEquals("G7B 0H3", responseAddress.getPostalCode()); + assertEquals("Québec", responseAddress.getState()); + assertEquals("4 boulevard de l'université", responseAddress.getLine().get(0).getValue()); + assertEquals(org.hl7.fhir.r4.model.Address.AddressUse.WORK, responseAddress.getUse()); + + response = BusinessToFhirConverter.patientToFhirPatient(pat1); + responseAddress = response.getAddress().get(0); + assertEquals(org.hl7.fhir.r4.model.Address.AddressUse.HOME, responseAddress.getUse()); + + response = BusinessToFhirConverter.patientToFhirPatient(pat2); + responseAddress = response.getAddress().get(0); + assertEquals(org.hl7.fhir.r4.model.Address.AddressUse.TEMP, responseAddress.getUse()); + + response = BusinessToFhirConverter.patientToFhirPatient(pat3); + responseAddress = response.getAddress().get(0); + assertEquals(org.hl7.fhir.r4.model.Address.AddressUse.OLD, responseAddress.getUse()); + + response = BusinessToFhirConverter.patientToFhirPatient(pat4); + responseAddress = response.getAddress().get(0); + assertEquals(org.hl7.fhir.r4.model.Address.AddressUse.BILLING, responseAddress.getUse()); + + } catch (ConversionException e) { + fail("could not convert Patient with just an address"); + } + + } + + @Test + @Description("Test on unitary conversion") + @Severity(SeverityLevel.CRITICAL) + @Story("Gender conversion") + void TestPatientTelecomConversion(){ + + net.ihe.gazelle.app.patientregistryapi.business.Patient pat = new net.ihe.gazelle.app.patientregistryapi.business.Patient(); + ContactPoint cp = new ContactPoint(); + cp.setType(ContactPointType.BEEPER); + cp.setValue("Hello"); + cp.setUse(ContactPointUse.WORK); + pat.addContactPoint(cp); + + net.ihe.gazelle.app.patientregistryapi.business.Patient pat1 = new net.ihe.gazelle.app.patientregistryapi.business.Patient(); + ContactPoint cp1 = new ContactPoint(); + cp1.setType(ContactPointType.PHONE); + cp1.setValue("Hello"); + cp1.setUse(ContactPointUse.MOBILE); + pat1.addContactPoint(cp1); + + net.ihe.gazelle.app.patientregistryapi.business.Patient pat2 = new net.ihe.gazelle.app.patientregistryapi.business.Patient(); + ContactPoint cp2 = new ContactPoint(); + cp2.setType(ContactPointType.FAX); + cp2.setValue("Hello"); + cp2.setUse(ContactPointUse.TEMPORARY); + pat2.addContactPoint(cp2); + + net.ihe.gazelle.app.patientregistryapi.business.Patient pat3 = new net.ihe.gazelle.app.patientregistryapi.business.Patient(); + ContactPoint cp3 = new ContactPoint(); + cp3.setType(ContactPointType.URL); + cp3.setValue("Hello"); + cp3.setUse(ContactPointUse.HOME); + pat3.addContactPoint(cp3); + + net.ihe.gazelle.app.patientregistryapi.business.Patient pat4 = new net.ihe.gazelle.app.patientregistryapi.business.Patient(); + ContactPoint cp4 = new ContactPoint(); + cp4.setType(ContactPointType.EMAIL); + cp4.setValue("Hello"); + cp4.setUse(ContactPointUse.PRIMARY_HOME); + pat4.addContactPoint(cp4); + + net.ihe.gazelle.app.patientregistryapi.business.Patient pat5 = new net.ihe.gazelle.app.patientregistryapi.business.Patient(); + ContactPoint cp5 = new ContactPoint(); + cp5.setType(ContactPointType.SMS); + cp5.setValue("Hello"); + cp5.setUse(ContactPointUse.PRIMARY_HOME); + pat5.addContactPoint(cp5); + + net.ihe.gazelle.app.patientregistryapi.business.Patient pat6 = new net.ihe.gazelle.app.patientregistryapi.business.Patient(); + ContactPoint cp6 = new ContactPoint(); + cp6.setType(ContactPointType.OTHER); + cp6.setValue("Hello"); + cp6.setUse(ContactPointUse.PRIMARY_HOME); + pat6.addContactPoint(cp6); + + /*case HOME: + case PRIMARY_HOME: + return org.hl7.fhir.r4.model.ContactPoint.ContactPointUse.HOME; + case MOBILE: + return org.hl7.fhir.r4.model.ContactPoint.ContactPointUse.MOBILE; + case WORK: + return org.hl7.fhir.r4.model.ContactPoint.ContactPointUse.WORK; + case TEMPORARY: + return org.hl7.fhir.r4.model.ContactPoint.ContactPointUse.TEMP; + + case BEEPER: + return org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem.PAGER; + case PHONE: + return org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem.PHONE; + case FAX: + return org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem.FAX; + case URL: + return org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem.URL; + case EMAIL: + return org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem.EMAIL; + case SMS: + return org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem.SMS; + case OTHER: + return org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem.OTHER;*/ + + try { + Patient response = BusinessToFhirConverter.patientToFhirPatient(pat); + assertEquals("Hello", response.getTelecom().get(0).getValue()); + assertEquals(org.hl7.fhir.r4.model.ContactPoint.ContactPointUse.WORK, response.getTelecom().get(0).getUse()); + assertEquals(org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem.PAGER, response.getTelecom().get(0).getSystem()); + + response = BusinessToFhirConverter.patientToFhirPatient(pat1); + assertEquals(org.hl7.fhir.r4.model.ContactPoint.ContactPointUse.MOBILE, response.getTelecom().get(0).getUse()); + assertEquals(org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem.PHONE, response.getTelecom().get(0).getSystem()); + + response = BusinessToFhirConverter.patientToFhirPatient(pat2); + assertEquals(org.hl7.fhir.r4.model.ContactPoint.ContactPointUse.TEMP, response.getTelecom().get(0).getUse()); + assertEquals(org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem.FAX, response.getTelecom().get(0).getSystem()); + + response = BusinessToFhirConverter.patientToFhirPatient(pat3); + assertEquals(org.hl7.fhir.r4.model.ContactPoint.ContactPointUse.HOME, response.getTelecom().get(0).getUse()); + assertEquals(org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem.URL, response.getTelecom().get(0).getSystem()); + + response = BusinessToFhirConverter.patientToFhirPatient(pat4); + assertEquals(org.hl7.fhir.r4.model.ContactPoint.ContactPointUse.HOME, response.getTelecom().get(0).getUse()); + assertEquals(org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem.EMAIL, response.getTelecom().get(0).getSystem()); + + response = BusinessToFhirConverter.patientToFhirPatient(pat5); + assertEquals(org.hl7.fhir.r4.model.ContactPoint.ContactPointUse.HOME, response.getTelecom().get(0).getUse()); + assertEquals(org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem.SMS, response.getTelecom().get(0).getSystem()); + + response = BusinessToFhirConverter.patientToFhirPatient(pat6); + assertEquals(org.hl7.fhir.r4.model.ContactPoint.ContactPointUse.HOME, response.getTelecom().get(0).getUse()); + assertEquals(org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem.OTHER, response.getTelecom().get(0).getSystem()); + + } catch (ConversionException e) { + fail("could not convert Patient with just a Telecom"); + } + + } + +} diff --git a/src/test/java/net/ihe/gazelle/application/PatientFeedClientTest.java b/src/test/java/net/ihe/gazelle/application/PatientFeedClientTest.java index eb67ee8f95ec2f302f052eef7d8ca73ee5e2ebf5..7c1e010ad3809aa8b0e6fde3a7fc4fe853104d58 100644 --- a/src/test/java/net/ihe/gazelle/application/PatientFeedClientTest.java +++ b/src/test/java/net/ihe/gazelle/application/PatientFeedClientTest.java @@ -83,7 +83,7 @@ public class PatientFeedClientTest { Patient patient = new Patient(); assertThrows(PatientFeedException.class, - () -> patientRegistryFeedClient.createPatient(patient)); + () -> patientRegistryFeedClient.updatePatient(patient,"")); } @Test @@ -99,7 +99,7 @@ public class PatientFeedClientTest { Patient patient = new Patient(); assertThrows(PatientFeedException.class, - () -> patientRegistryFeedClient.createPatient(patient)); + () -> patientRegistryFeedClient.delete("")); } @Test @@ -115,7 +115,7 @@ public class PatientFeedClientTest { Patient patient = new Patient(); assertThrows(PatientFeedException.class, - () -> patientRegistryFeedClient.createPatient(patient)); + () -> patientRegistryFeedClient.mergePatient("","")); } @Test diff --git a/src/test/java/net/ihe/gazelle/business/provider/CHBundleProviderTest.java b/src/test/java/net/ihe/gazelle/business/provider/CHBundleProviderTest.java index bed7db1e83454177144c2e05e35a130f17dd5d8a..df596f71923d9d659555fcdf3ebf26d4731a3454 100644 --- a/src/test/java/net/ihe/gazelle/business/provider/CHBundleProviderTest.java +++ b/src/test/java/net/ihe/gazelle/business/provider/CHBundleProviderTest.java @@ -23,6 +23,8 @@ class CHBundleProviderTest { private static final CHBundleProvider bundle_feed_provider = new CHBundleProvider(new CHPatientProviderMock(feedClientMock)); public static final String GOOD_UUID = "123e4567-e89b-12d3-a456-426614174000"; + public static final String Throw_two_id = "LOLILO"; + public static final String Throw_ID = "MDR"; CHBundleProviderMock cbpm = new CHBundleProviderMock(); @@ -76,6 +78,7 @@ class CHBundleProviderTest { IdType id = new IdType(GOOD_UUID); assertThrows(InvalidRequestException.class, ()-> bundle_feed_provider.delete(id, cbpm.returnBundleFromResource(fileName)),"Bundle is null or Empty"); } + @Test @Description("Test on the delete operation, deleting a Patient but there is no Patient in the bundle") @Severity(SeverityLevel.CRITICAL) @@ -86,5 +89,66 @@ class CHBundleProviderTest { assertThrows(InvalidRequestException.class, ()-> bundle_feed_provider.delete(id, cbpm.returnBundleFromResource(fileName)),"Bundle Could not be converted to HL7 Patient"); } + @Test + @Description("Test on the update operation, clean update without issue") + @Severity(SeverityLevel.CRITICAL) + @Story("update operation") + void testUpdatePatient() { + String fileName = "post_request.json"; + IdType id = new IdType(GOOD_UUID); + MethodOutcome mo = bundle_feed_provider.updatePatient(id, cbpm.returnBundleFromResource(fileName)); + assertEquals(cbpm.ID_TO_RETURN,mo.getId().getValue()); + } + + @Test + @Description("Test on the update operation, updating a Patient but with a null bundle") + @Severity(SeverityLevel.CRITICAL) + @Story("update operation") + void testUpdatePatientNullBundle() { + String fileName = "null.json"; + IdType id = new IdType(GOOD_UUID); + assertThrows(InvalidRequestException.class, ()-> bundle_feed_provider.updatePatient(id, cbpm.returnBundleFromResource(fileName)),"Bundle is null or Empty"); + } + + @Test + @Description("Test on the update operation, updating a Patient but there is no Patient in the bundle") + @Severity(SeverityLevel.CRITICAL) + @Story("update operation") + void testUpdatePatientBlank() { + String fileName = "post_request_NO_PATIENT.json"; + IdType id = new IdType(GOOD_UUID); + assertThrows(InvalidRequestException.class, ()-> bundle_feed_provider.updatePatient(id, cbpm.returnBundleFromResource(fileName)),"bizu"); + } + + @Test + @Description("Test on the update operation, updating a Patient but there is no Patient in the bundle") + @Severity(SeverityLevel.CRITICAL) + @Story("update operation") + void testUpdateEmptyId() { + String fileName = "post_request_NO_PATIENT.json"; + IdType id = new IdType(""); + assertThrows(InvalidRequestException.class, ()-> bundle_feed_provider.updatePatient(id, cbpm.returnBundleFromResource(fileName)),"Invalid ID Parameter, either null or empty."); + } + + @Test + @Description("Test on the update operation, updating a Patient but there is no Patient in the bundle") + @Severity(SeverityLevel.CRITICAL) + @Story("update operation") + void testUpdateInvalidRequest() { + String fileName = "post_request_NO_PATIENT.json"; + IdType id = new IdType(Throw_ID); + assertThrows(InvalidRequestException.class, ()-> bundle_feed_provider.updatePatient(id, cbpm.returnBundleFromResource(fileName)),"Invalid ID Parameter, either null or empty."); + } + + @Test + @Description("Test on the update operation, updating a Patient but there is no Patient in the bundle") + @Severity(SeverityLevel.CRITICAL) + @Story("update operation") + void testUpdateInternalError() { + String fileName = "post_request_NO_PATIENT.json"; + IdType id = new IdType(Throw_two_id); + assertThrows(InvalidRequestException.class, ()-> bundle_feed_provider.updatePatient(id, cbpm.returnBundleFromResource(fileName)),"Invalid ID Parameter, either null or empty."); + } + } \ No newline at end of file diff --git a/src/test/java/net/ihe/gazelle/business/provider/CHPatientProviderMock.java b/src/test/java/net/ihe/gazelle/business/provider/CHPatientProviderMock.java index d74f48a22b5d90f279041b762a7c42c444f1264b..78fd7a39ac196f206f228e2be1f778bcd07fadf0 100644 --- a/src/test/java/net/ihe/gazelle/business/provider/CHPatientProviderMock.java +++ b/src/test/java/net/ihe/gazelle/business/provider/CHPatientProviderMock.java @@ -1,7 +1,10 @@ package net.ihe.gazelle.business.provider; +import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.ResourceParam; import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; +import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import net.ihe.gazelle.adapter.connector.ConversionException; import net.ihe.gazelle.app.patientregistryapi.application.PatientFeedException; import net.ihe.gazelle.application.PatientRegistryFeedClient; @@ -53,13 +56,27 @@ public class CHPatientProviderMock extends ChPatientResourceProvider{ if (id.equals(CHBundleProviderTest.GOOD_UUID)){ return mo.setId(iIdType.setValue("OK")); } - //Case NULL - if (id==null){ - return null; + + return null; + } + + @Override + public MethodOutcome update(@IdParam IdType theId, @ResourceParam Patient hl7Patient) { + MethodOutcome mo = new MethodOutcome(); + IdType iIdType = new IdType(); + + //Case OK + + if (theId.equals(CHBundleProviderTest.GOOD_UUID)){ + return mo.setId(iIdType.setValue("OK")); } - /*if (id.getValue().isBLank()) { - return null; - }*/ + else if (theId.equals(CHBundleProviderTest.Throw_ID)) { + throw new InvalidRequestException(""); + } + else if (theId.equals(CHBundleProviderTest.Throw_two_id)) { + throw new InternalErrorException(""); + } + return null; } } diff --git a/src/test/java/net/ihe/gazelle/business/provider/ChPatientResourceProviderTest.java b/src/test/java/net/ihe/gazelle/business/provider/ChPatientResourceProviderTest.java index 0bbd361f7956f6d39ff036d4d5f281dbc20112f6..8d2d23f4bbbd52e01e2d9babdef6032ba4e0d61a 100644 --- a/src/test/java/net/ihe/gazelle/business/provider/ChPatientResourceProviderTest.java +++ b/src/test/java/net/ihe/gazelle/business/provider/ChPatientResourceProviderTest.java @@ -1,18 +1,6 @@ package net.ihe.gazelle.business.provider; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import org.hl7.fhir.r4.model.Bundle; -import org.hl7.fhir.r4.model.IdType; -import org.hl7.fhir.r4.model.Identifier; -import org.hl7.fhir.r4.model.Parameters; -import org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent; -import org.junit.Assert; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - +import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.param.StringAndListParam; import ca.uhn.fhir.rest.param.StringOrListParam; import ca.uhn.fhir.rest.param.StringParam; @@ -21,14 +9,16 @@ import ca.uhn.fhir.rest.server.exceptions.ForbiddenOperationException; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; -import io.qameta.allure.Description; -import io.qameta.allure.Feature; -import io.qameta.allure.Severity; -import io.qameta.allure.SeverityLevel; -import io.qameta.allure.Story; +import io.qameta.allure.*; import net.ihe.gazelle.application.PatientRegistryFeedClient; import net.ihe.gazelle.application.PatientRegistrySearchClient; import net.ihe.gazelle.application.PatientRegistryXRefSearchClient; +import org.hl7.fhir.r4.model.*; +import org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; @Feature("ChaPatientProvider") class ChPatientResourceProviderTest { @@ -273,11 +263,13 @@ class ChPatientResourceProviderTest { @Story("ReadMethod") void testReadNoIdGiven() { IdType id = new IdType(); - id.setValue("2"); + id.setValue(""); try { read_provider.read(id); } catch (InvalidRequestException e) { assertEquals(ChPatientResourceProvider.NO_ID_PROVIDED, e.getMessage()); + } catch (Exception e) { + fail(); } } @@ -291,17 +283,123 @@ class ChPatientResourceProviderTest { assertEquals("[Arthur]", read_provider.read(id).getName().get(0).getGiven().toString()); } - //TODO not implemented UTs on provider yet. - //@Test + @Test @Description("Test on Update method, returns ok") @Severity(SeverityLevel.CRITICAL) @Story("UpdateMethod") void testUpdateFine() { IdType id = new IdType(); - Bundle iti93Bundle = new Bundle(); - iti93Bundle.addEntry().getRequest(); + Patient iti93Bundle = new Patient(); + iti93Bundle.setId("Plop"); id.setValue("3"); - //assertEquals("[Arthur]", feed_provider.update(id, iti93Bundle)); + Bundle returnedValue = (Bundle) feed_provider.update(id, iti93Bundle).getResource(); + assertEquals("Plop", returnedValue.getEntry().get(0).getResource().getId()); + } + + @Test + @Description("Test on Update method, returns ok") + @Severity(SeverityLevel.CRITICAL) + @Story("UpdateMethod") + void testUpdateUuidBlank() { + IdType id = new IdType(); + Patient iti93Bundle = new Patient(); + iti93Bundle.setId("Plop"); + id.setValue(""); + assertThrows(InvalidRequestException.class, () -> feed_provider.update(id, iti93Bundle)); + } + + @Test + @Description("Test on Update method, returns ok") + @Severity(SeverityLevel.CRITICAL) + @Story("UpdateMethod") + void testUpdatePatientBlank() { + IdType id = new IdType(); + Patient iti93Bundle = new Patient(); + id.setValue("3"); + assertThrows(InvalidRequestException.class, () -> feed_provider.update(id, iti93Bundle)); + } + + @Test + @Description("Test on Update method, returns ok") + @Severity(SeverityLevel.CRITICAL) + @Story("UpdateMethod") + void testUpdatePatientFeedThrown() { + IdType id = new IdType(); + Patient iti93Bundle = new Patient(); + iti93Bundle.setId("Plop"); + id.setValue("42"); + assertThrows(InternalErrorException.class, () -> feed_provider.update(id, iti93Bundle)); + } + + @Test + @Description("Test on Create method, returns ok") + @Severity(SeverityLevel.CRITICAL) + @Story("CreateMethod") + void testCreateFine() { + Patient iti93Bundle = new Patient(); + iti93Bundle.setId("PatientPixMFeed"); + Bundle returnedValue = (Bundle) feed_provider.create(iti93Bundle).getResource(); + assertEquals("1", returnedValue.getId()); + } + + @Test + @Description("Test on Create method, returns ok") + @Severity(SeverityLevel.CRITICAL) + @Story("CreateMethod") + void testCreatePatientBlank() { + assertThrows(InvalidRequestException.class, () -> feed_provider.create(null)); + } + + @Test + @Description("Test on Create method, returns nothing") + @Severity(SeverityLevel.CRITICAL) + @Story("CreateMethod") + void testCreatePatientNPE() { + Patient iti93Bundle = new Patient(); + iti93Bundle.setId("Plop"); + assertThrows(NullPointerException.class, () -> feed_provider.create(iti93Bundle)); + } + + @Test + @Description("Test on Create method, returns nothing") + @Severity(SeverityLevel.CRITICAL) + @Story("CreateMethod") + void testCreatePatientFeedThrown() { + Patient iti93Bundle = new Patient(); + iti93Bundle.setId("throw_me_something"); + assertThrows(InternalErrorException.class, () -> feed_provider.create(iti93Bundle)); + } + + @Test + @Description("Test on Delete method, returns ok") + @Severity(SeverityLevel.CRITICAL) + @Story("DeleteMethod") + void testDeleteFine() { + IdType theId = new IdType(); + theId.setValue("PatientPixMFeed"); + Bundle returnedValue = (Bundle) feed_provider.delete(theId).getResource(); + assertEquals("PatientPixMFeed", returnedValue.getId()); + } + + @Test + @Description("Test on Delete method, returns ok") + @Severity(SeverityLevel.CRITICAL) + @Story("DeleteMethod") + void testDeleteUuidEmpty() { + IdType theId = new IdType(); + theId.setValue(""); + assertThrows(InvalidRequestException.class, () -> feed_provider.delete(theId)); + } + + + @Test + @Description("Test on Delete method, returns ok") + @Severity(SeverityLevel.CRITICAL) + @Story("DeleteMethod") + void testDeletePatientFeedThrown() { + IdType theId = new IdType(); + theId.setValue("42"); + assertThrows(InternalErrorException.class, () -> feed_provider.delete(theId)); } } \ No newline at end of file diff --git a/src/test/java/net/ihe/gazelle/business/provider/IhePatientResourceProviderTest.java b/src/test/java/net/ihe/gazelle/business/provider/IhePatientResourceProviderTest.java index 1314f05dec9a60a9b2cef02d1f827955d460fe00..79ea390cf0c6926e57548a2bf953f65285e66ee5 100644 --- a/src/test/java/net/ihe/gazelle/business/provider/IhePatientResourceProviderTest.java +++ b/src/test/java/net/ihe/gazelle/business/provider/IhePatientResourceProviderTest.java @@ -5,12 +5,14 @@ import ca.uhn.fhir.rest.param.StringOrListParam; import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.server.exceptions.ForbiddenOperationException; +import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import io.qameta.allure.Description; import io.qameta.allure.Severity; import io.qameta.allure.SeverityLevel; import io.qameta.allure.Story; +import net.ihe.gazelle.app.patientregistryapi.application.SearchCrossReferenceException; import net.ihe.gazelle.application.PatientRegistryXRefSearchClient; import org.hl7.fhir.r4.model.Identifier; import org.hl7.fhir.r4.model.Parameters; @@ -184,4 +186,42 @@ class IhePatientResourceProviderTest { } + @Test + @Description("Test on ihe_pix operation, when the target system is blank") + @Severity(SeverityLevel.CRITICAL) + @Story("ihe_pix operation") + void testSourceIdentifierBlank() { + TokenParam sourceId = new TokenParam("http::/1", "69420"); + StringAndListParam targetDomains = new StringAndListParam(); + StringOrListParam stringParam = new StringOrListParam(); + stringParam.add(new StringParam("")); + targetDomains.addAnd(stringParam); + + try { + provider.findPatientsByIdentifier(null, targetDomains); + } catch (ResourceNotFoundException e) { + assertEquals(IhePatientResourceProvider.SOURCE_IDENTIFIER_PATIENT_IDENTIFIER_NOT_FOUND, e.getMessage()); + } + + } + + @Test + @Description("Test on ihe_pix operation, when the target system is blank") + @Severity(SeverityLevel.CRITICAL) + @Story("ihe_pix operation") + void testCrossRefException() { + TokenParam sourceId = new TokenParam("urn:oid:3", "69420"); + StringAndListParam targetDomains = new StringAndListParam(); + StringOrListParam stringParam = new StringOrListParam(); + stringParam.add(new StringParam("urn:oid:3")); + targetDomains.addAnd(stringParam); + + try { + provider.findPatientsByIdentifier(sourceId, targetDomains); + } catch (InternalErrorException e) { + assertEquals("net.ihe.gazelle.business.provider.PatientResourceProviderException: One of the target domain does not exist", e.getMessage()); + } + + } + } \ No newline at end of file diff --git a/src/test/java/net/ihe/gazelle/business/provider/PatientRegistryFeedClientMock.java b/src/test/java/net/ihe/gazelle/business/provider/PatientRegistryFeedClientMock.java index 64e50644842520c60ae83be95127d5d426b101cf..669f20dc15cc95c96e7c9f1a026398e8e13ca475 100644 --- a/src/test/java/net/ihe/gazelle/business/provider/PatientRegistryFeedClientMock.java +++ b/src/test/java/net/ihe/gazelle/business/provider/PatientRegistryFeedClientMock.java @@ -1,5 +1,7 @@ package net.ihe.gazelle.business.provider; +import net.ihe.gazelle.adapter.connector.BusinessToFhirConverter; +import net.ihe.gazelle.adapter.connector.ConversionException; import net.ihe.gazelle.app.patientregistryapi.application.PatientFeedException; import net.ihe.gazelle.app.patientregistryapi.business.Patient; import net.ihe.gazelle.app.patientregistryfeedclient.adapter.PatientFeedClient; @@ -35,8 +37,41 @@ public class PatientRegistryFeedClientMock extends PatientRegistryFeedClient { switch (uuid){ case "PatientPixMFeed": return bundle; + case "throw_me_something": + throw new PatientFeedException(); default: return null; } } + + @Override + public Bundle updatePatient(net.ihe.gazelle.app.patientregistryapi.business.Patient patientToUpdate, String uuid) throws PatientFeedException { + if (uuid.equals("42")) { + throw new PatientFeedException(); + } + Bundle response = new Bundle(); + Bundle.BundleEntryComponent component = new Bundle.BundleEntryComponent(); + try { + component.setResource(BusinessToFhirConverter.patientToFhirPatient(patientToUpdate)); + } + catch (ConversionException e) { + throw new PatientFeedException(e); + } + response.addEntry(component); + return response; + } + + @Override + public Bundle delete(String uuid) throws PatientFeedException{ + + if (uuid.equals("42")) { + throw new PatientFeedException(); + } + + Bundle response = new Bundle(); + response.setId(uuid); + + return response; + } + }