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 20983cc54d497ef68d6b03128108c175b11fc0ac..9c42bfcbcaa7180025be25557371da69b84b8e36 100644 --- a/src/main/java/net/ihe/gazelle/business/provider/CHBundleProvider.java +++ b/src/main/java/net/ihe/gazelle/business/provider/CHBundleProvider.java @@ -24,14 +24,15 @@ public class CHBundleProvider implements IResourceProvider { private static final Logger patientLogger = LoggerFactory.getLogger(CHBundleProvider.class); - private CHBundleProvider(){} + private CHBundleProvider() { + } @Package - public CHBundleProvider(ChPatientResourceProvider chPatientResourceProvider){ - this.chPatientResourceProvider=chPatientResourceProvider; + public CHBundleProvider(ChPatientResourceProvider chPatientResourceProvider) { + this.chPatientResourceProvider = chPatientResourceProvider; } - @Inject + @Inject private ChPatientResourceProvider chPatientResourceProvider; @Inject @@ -60,16 +61,11 @@ public class CHBundleProvider implements IResourceProvider { if (iti93Bundle == null || iti93Bundle.getEntry().isEmpty()) { throw new InvalidRequestException("Bundle is null or Empty"); } - try { - Patient patientBundle = iti93BundleToPatient(iti93Bundle); - return chPatientResourceProvider.create(patientBundle); - } catch (ConversionException e) { - throw new InvalidRequestException("Bundle Could not be converted to HL7 Patient"); - } - + Patient patientBundle = iti93BundleToPatient(iti93Bundle); + return chPatientResourceProvider.create(patientBundle); } - private Patient iti93BundleToPatient(Bundle pixmFeed) throws ConversionException { + private Patient iti93BundleToPatient(Bundle pixmFeed) { List<Bundle.BundleEntryComponent> listOfEntries = pixmFeed.getEntry(); if (listOfEntries.size() != 2) { throw new InvalidRequestException("PixM Feed should have 2 entries."); @@ -84,6 +80,6 @@ public class CHBundleProvider implements IResourceProvider { } } } - throw new InvalidRequestException("Missing Patient in Bundle"); + throw new InvalidRequestException("Cannot find resource Type Patient in Bundle"); } } \ No newline at end of file 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 e08dd3da4de2fc2f14f7e675678102630f673857..d4967480bb20fbb6b14ee59ee71cbf36bf876e86 100644 --- a/src/test/java/net/ihe/gazelle/business/provider/CHBundleProviderTest.java +++ b/src/test/java/net/ihe/gazelle/business/provider/CHBundleProviderTest.java @@ -1,25 +1,18 @@ package net.ihe.gazelle.business.provider; 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; -import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; -import io.qameta.allure.Description; -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.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.io.InvalidClassException; import static org.junit.jupiter.api.Assertions.*; +@Feature("CHBundleProvider Test") class CHBundleProviderTest { @BeforeAll @@ -60,12 +53,12 @@ class CHBundleProviderTest { @Description("Test on the Create Method with a Bundle with No Patient inside") void testCreateNoPatientInBundle() { String fileName = "post_request_NO_PATIENT.json"; - assertThrows(InvalidRequestException.class, ()-> bundle_feed_provider.create(cbpm.returnBundleFromResource(fileName)),"Missing Patient in Bundle"); + assertThrows(InvalidRequestException.class, ()-> bundle_feed_provider.create(cbpm.returnBundleFromResource(fileName)),"Missing Pat in Bundle"); } @Test @Description("Test on the Create Method with a Bundle with 3 entries") - void testCreatePatientBundleWith3Entries() { + void testCreatePatientBundleWith1Entry() { String fileName = "post_request_1_entry.json"; assertThrows(InvalidRequestException.class, ()-> bundle_feed_provider.create(cbpm.returnBundleFromResource(fileName))); } 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 10f9b4bf7efe29ae9eb8acbbe08a734d00df4081..c5fb42b95b2cc42202bf2fe027fe392c58094192 100644 --- a/src/test/java/net/ihe/gazelle/business/provider/CHPatientProviderMock.java +++ b/src/test/java/net/ihe/gazelle/business/provider/CHPatientProviderMock.java @@ -2,6 +2,7 @@ package net.ihe.gazelle.business.provider; import ca.uhn.fhir.rest.annotation.ResourceParam; import ca.uhn.fhir.rest.api.MethodOutcome; +import net.ihe.gazelle.adapter.connector.ConversionException; import net.ihe.gazelle.app.patientregistryapi.application.PatientFeedException; import net.ihe.gazelle.application.PatientRegistryFeedClient; import net.ihe.gazelle.application.PatientRegistryXRefSearchClient; @@ -18,16 +19,20 @@ public class CHPatientProviderMock extends ChPatientResourceProvider{ } @Override - public MethodOutcome create(@ResourceParam Patient iti93Bundle) { + public MethodOutcome create(@ResourceParam Patient iti93Patient) { MethodOutcome mo = new MethodOutcome(); IIdType iIdType = new IdType(); //Case OK - if (iti93Bundle.getId().equals("Patient/PatientPIXmFeed")){ + if (iti93Patient.getId().equals("Patient/PatientPIXmFeed")){ return mo.setId(iIdType.setValue("OK")); } + //Case KO + if (iti93Patient.getId().equals("Bundle/PatientPIXmFeed")){ + return null; + } //Case NULL - if (iti93Bundle==null){ + if (iti93Patient==null){ return null; } return null;