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 6b150f2d023aad0c9d65f2852c01dc59378a00e6..be8f936c69c87aede6d30b12d30ff79f7a1f4f84 100644 --- a/src/main/java/net/ihe/gazelle/adapter/connector/BundleToPatientRegistryConverter.java +++ b/src/main/java/net/ihe/gazelle/adapter/connector/BundleToPatientRegistryConverter.java @@ -105,10 +105,16 @@ public class BundleToPatientRegistryConverter { if (id.hasSystem()) { entityIdentifier.setSystemIdentifier(id.getSystem()); } + else { + throw new InvalidRequestException("Cannot create Patient without any Identifier"); + } if (id.hasValue()) { entityIdentifier.setSystemName(id.getValue()); } + else { + throw new InvalidRequestException("Cannot create Patient without any Identifier"); + } convertedPatient.addIdentifier(entityIdentifier); } diff --git a/src/main/java/net/ihe/gazelle/application/PatientRegistryFeedClient.java b/src/main/java/net/ihe/gazelle/application/PatientRegistryFeedClient.java index 945171071e16a770b2e64e911687975a0047338f..88f0139a5fa5163a867ffae1943b8115bf08dad2 100644 --- a/src/main/java/net/ihe/gazelle/application/PatientRegistryFeedClient.java +++ b/src/main/java/net/ihe/gazelle/application/PatientRegistryFeedClient.java @@ -1,6 +1,21 @@ package net.ihe.gazelle.application; -import ca.uhn.fhir.rest.server.exceptions.*; +import java.net.InetAddress; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.UnknownHostException; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.xml.ws.WebServiceException; + +import org.hl7.fhir.r4.model.Bundle; + +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 ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; +import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import net.ihe.gazelle.adapter.connector.BusinessToFhirConverter; import net.ihe.gazelle.adapter.connector.DeletionBundle; import net.ihe.gazelle.adapter.connector.UpdateBundle; @@ -14,251 +29,265 @@ import net.ihe.gazelle.framework.preferencesmodelapi.application.NamespaceExcept import net.ihe.gazelle.framework.preferencesmodelapi.application.OperationalPreferencesService; import net.ihe.gazelle.framework.preferencesmodelapi.application.PreferenceException; import net.ihe.gazelle.lib.annotations.Package; -import org.hl7.fhir.r4.model.Bundle; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.xml.ws.WebServiceException; -import java.net.InetAddress; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.UnknownHostException; @Named("PatientRegistryFeedClient") public class PatientRegistryFeedClient { - public static final String BAD_UUID = "Created Patient has an uuid that is not valid."; - public static final String NO_UUID = "No UUID was retrieved from the created Patient"; - public static final String NO_PATIENT_PARAMETER = "No Patient were given to create"; - public static final String CLIENT_NOT_SET = "client not set"; - private String serverUrl; - private static final GazelleLogger logger = GazelleLoggerFactory.getInstance().getLogger(PatientRegistryFeedClient.class); - private OperationalPreferencesService operationalPreferencesService; - private PatientFeedClient client; + public static final String BAD_UUID = "Created Patient has an uuid that is not valid."; + public static final String NO_UUID = "No UUID was retrieved from the created Patient"; + public static final String NO_PATIENT_PARAMETER = "No Patient were given to create"; + public static final String CLIENT_NOT_SET = "client not set"; + private String serverUrl; + private static final GazelleLogger logger = GazelleLoggerFactory.getInstance().getLogger(PatientRegistryFeedClient.class); + private OperationalPreferencesService operationalPreferencesService; + private PatientFeedClient client; + + public PatientRegistryFeedClient() { + } - public PatientRegistryFeedClient() { - } + /** + * Default constructor, used for injection. + * + * @param operationalPreferencesService {@link OperationalPreferencesService} used to retrieve Patient Registry's URL. + */ + @Inject + public PatientRegistryFeedClient(OperationalPreferencesService operationalPreferencesService) { - /** - * Default constructor, used for injection. - * - * @param operationalPreferencesService {@link OperationalPreferencesService} used to retrieve Patient Registry's URL. - */ - @Inject - public PatientRegistryFeedClient(OperationalPreferencesService operationalPreferencesService) { + this.operationalPreferencesService = operationalPreferencesService; + } - this.operationalPreferencesService = operationalPreferencesService; - } + /** + * Package-private constructor used for test purposes. + * + * @param url {@link URL} to be used by this to instantiate the processing service to retrieve patients. + */ + @Package + PatientRegistryFeedClient(URL url) { + this.client = new PatientFeedClient(url); + } - /** - * Package-private constructor used for test purposes. - * - * @param url {@link URL} to be used by this to instantiate the processing service to retrieve patients. - */ - @Package - PatientRegistryFeedClient(URL url) { - this.client = new PatientFeedClient(url); - } + @Package + public void setClient(PatientFeedClient client) { + this.client = client; + } - @Package - public void setClient(PatientFeedClient client) { - this.client = client; - } + /** + * Initialize the Search Client using the Operational Preferences Service. + * + * @throws PatientFeedException if the service cannot be instantiated. + */ + private void initializeClient() throws PatientFeedException { + String patientRegistryUrl = null; + try { + patientRegistryUrl = this.operationalPreferencesService. + getStringValue(Preferences.PATIENT_REGISTRY_URL.getNamespace().getValue(), Preferences.PATIENT_REGISTRY_URL.getKey()); + this.client = new PatientFeedClient(new URL(patientRegistryUrl)); + } catch (NamespaceException | PreferenceException e) { + throw new PatientFeedException(String.format("Unable to retrieve [%s] Preference !", Preferences.PATIENT_REGISTRY_URL.getKey())); + } catch (MalformedURLException e) { + throw new PatientFeedException(String.format("Preference [%s] with value [%s] is not a valid URL !", + Preferences.PATIENT_REGISTRY_URL.getKey(), + patientRegistryUrl)); + } catch (WebServiceException e) { + logger.warn(e.getMessage()); + throw new PatientFeedException(String.format("Can't connect to patient registry ! at address [%s]", patientRegistryUrl)); + } + } - /** - * Initialize the Search Client using the Operational Preferences Service. - * - * @throws PatientFeedException if the service cannot be instantiated. - */ - private void initializeClient() throws PatientFeedException { - String patientRegistryUrl = null; - try { - patientRegistryUrl = this.operationalPreferencesService. - getStringValue(Preferences.PATIENT_REGISTRY_URL.getNamespace().getValue(), Preferences.PATIENT_REGISTRY_URL.getKey()); - this.client = new PatientFeedClient(new URL(patientRegistryUrl)); - } catch (NamespaceException | PreferenceException e) { - throw new PatientFeedException(String.format("Unable to retrieve [%s] Preference !", Preferences.PATIENT_REGISTRY_URL.getKey())); - } catch (MalformedURLException e) { - throw new PatientFeedException(String.format("Preference [%s] with value [%s] is not a valid URL !", - Preferences.PATIENT_REGISTRY_URL.getKey(), - patientRegistryUrl)); - } catch (WebServiceException e) { - logger.warn(e.getMessage()); - throw new PatientFeedException(String.format("Can't connect to patient registry ! at address [%s]", patientRegistryUrl)); - } - } + /** + * Method called to create a Patient in the Patient Registry Database + * + * @param patient : the patient to add in database, represented in patientRegistry model + * @return a string corresponding to the uuid of the newly created patient in the database. + */ + public Bundle createPatient(net.ihe.gazelle.app.patientregistryapi.business.Patient patient) throws PatientFeedException { + if (client == null) { + logger.info(CLIENT_NOT_SET); + initializeClient(); + } + if (patient == null) { + throw new InvalidRequestException(NO_PATIENT_PARAMETER); + } - /** - * Method called to create a Patient in the Patient Registry Database - * - * @param patient : the patient to add in database, represented in patientRegistry model - * @return a string corresponding to the uuid of the newly created patient in the database. - */ - public Bundle createPatient(net.ihe.gazelle.app.patientregistryapi.business.Patient patient) throws PatientFeedException { - if (client == null) { - logger.info(CLIENT_NOT_SET); - initializeClient(); - } - if (patient == null) { - throw new InvalidRequestException(NO_PATIENT_PARAMETER); - } + PersonName name = patient.getNames().get(0); + if (name.getFamily().isBlank() || name.getGivens().isEmpty()) { + throw new InvalidRequestException("Mandatory fields are missing"); + } + if (patient.getDateOfBirth() == null || patient.getGender() == null) { + throw new InvalidRequestException("Mandatory fields are missing"); + } - PersonName name = patient.getNames().get(0); - if (name.getFamily().isBlank() || name.getGivens().isEmpty()) { - throw new InvalidRequestException("Mandatory fields are missing"); - } - if (patient.getDateOfBirth() == null || patient.getGender() == null) { - throw new InvalidRequestException("Mandatory fields are missing"); - } + try { + String uuid = client.createPatient(patient); - try { - String uuid = client.createPatient(patient); + if (uuid == null || uuid.isBlank()) { + throw new InternalErrorException(NO_UUID); + } - if (uuid == null || uuid.isBlank()) { - throw new InternalErrorException(NO_UUID); - } + return BusinessToFhirConverter.uuidToBundle(uuid, serverUrl); - 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 "Unexpected Exception persisting Patient !": + throw new InternalErrorException("", e); + case "Null crossReference parameter for creation": + throw new InternalErrorException("", e); + case "Persistence Error": + throw new InternalErrorException("", e); + case "Exception performing the read operation for requested criteria !": + throw new InternalErrorException("", e); + default: + throw new InternalErrorException("", e); + } + } + } - } 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 "Unexpected Exception persisting Patient !": - throw new InternalErrorException("", e); - case "Null crossReference parameter for creation": - throw new InternalErrorException("", e); - case "Persistence Error": - throw new InternalErrorException("", e); - case "Exception performing the read operation for requested criteria !": - throw new InternalErrorException("", e); - default: - throw new InternalErrorException("", e); - } - } - } + /** + * Method called to update a Patient in the PAtient Registry Database. + * + * @param patient : the Patient object we want to insert in DB + * @param uuid : The uuid of the patient corresponding to it in DB + * @return a String corresponding to the uuid confirming the transaction has been successful. + */ + public Bundle updatePatient(net.ihe.gazelle.app.patientregistryapi.business.Patient patient, String uuid) throws PatientFeedException { + if (client == null) { + logger.info("client not set"); + initializeClient(); + } + if (patient == null || uuid == null || uuid.isBlank()) { + throw new InvalidRequestException("Invalid parameters"); + } - /** - * Method called to update a Patient in the PAtient Registry Database. - * - * @param patient : the Patient object we want to insert in DB - * @param uuid : The uuid of the patient corresponding to it in DB - * @return a String corresponding to the uuid confirming the transaction has been successful. - */ - public Bundle updatePatient(net.ihe.gazelle.app.patientregistryapi.business.Patient patient, String uuid) throws PatientFeedException { - if (client == null) { - logger.info("client not set"); - initializeClient(); - } - if (patient == null || uuid == null || uuid.isBlank()) { - throw new InvalidRequestException("Invalid parameters"); - } + try { + 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 id 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); + default: + throw new InternalErrorException("", e); + } + } + return UpdateBundle.prepareBundleAfterUpdateOperation(uuid,serverUrl); - try { - 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 id 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); - default: - throw new InternalErrorException("", e); - } - } - return UpdateBundle.prepareBundleAfterUpdateOperation(uuid,serverUrl); + } - } + /** + * Method called to merge two Patients in the Patient Registry Database. + * + * @param uuidOriginal : the Patient object we want to insert in DB + * @param uuidDuplicated : The uuid of the patient corresponding to it in DB + * @return a String corresponding to the uuid confirming the transaction has been successful. + */ + public Bundle mergePatient(String uuidOriginal, String uuidDuplicated) throws PatientFeedException { + if (client == null) { + logger.info("client not set"); + initializeClient(); + } + if (uuidOriginal == null || uuidOriginal.isBlank()) { + throw new InvalidRequestException("Invalid parameters"); + } + if (uuidDuplicated == null || uuidDuplicated.isBlank()) { + throw new InvalidRequestException("Invalid parameters"); + } - /** - * Method called to merge two Patients in the Patient Registry Database. - * - * @param uuidOriginal : the Patient object we want to insert in DB - * @param uuidDuplicated : The uuid of the patient corresponding to it in DB - * @return a String corresponding to the uuid confirming the transaction has been successful. - */ - public Bundle mergePatient(String uuidOriginal, String uuidDuplicated) throws PatientFeedException { - if (client == null) { - logger.info("client not set"); - initializeClient(); - } - if (uuidOriginal == null || uuidOriginal.isBlank()) { - throw new InvalidRequestException("Invalid parameters"); - } - if (uuidDuplicated == null || uuidDuplicated.isBlank()) { - throw new InvalidRequestException("Invalid parameters"); - } + try { + client.mergePatient(uuidOriginal, uuidDuplicated); + } catch (PatientFeedException e) { + logger.error("pouet pouet ciboulette"); + //TODO Map errors and delete the pouet pouet ciboulette comment + } - try { - client.mergePatient(uuidOriginal, uuidDuplicated); - } catch (PatientFeedException e) { - logger.error("pouet pouet ciboulette"); - //TODO Map errors and delete the pouet pouet ciboulette comment - } + return new Bundle(); - return new Bundle(); + } - } + /** + * Methode to delete a Patient with its uuid + * @param uuid of the patient to delete + * @return Result of the Deletion + * @throws PatientFeedException + */ + public Bundle delete(String uuid) throws PatientFeedException { + logger.error("plop"); + if (client == null) { + logger.info("client not set"); + initializeClient(); + } + if (uuid == null || uuid.isBlank()) { + throw new InvalidRequestException("Invalid parameter"); + } + try { + boolean deletionStatus = client.deletePatient(uuid); + 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 "); + default: + throw new InternalErrorException("Unknown Error append"); + } + /* + logger.error("Error during delete Method : ", exception); + if (exception.getCause().getMessage().equals("PatientFeedClient : Patient didn't exist")) { + throw new ResourceNotFoundException(String.format("Any patient for given uuid [%s]", uuid)); + } + throw new InternalErrorException(exception); + //FIXME MAPPING FROM PatReg*/ + } + } + /*throw new PatientFeedException("Exception while Mapping with GITB elements !", e); + throw new PatientFeedException ("Invalid Response from distant PatientFeedProcessingService !", e); + throw new PatientFeedException("Invalid operation used on distant PatientFeedProcessingService !", e); + throw new PatientFeedException("Invalid Request sent to distant PatientFeedProcessingService !", e); - /** - * Methode to delete a - * @param uuid of the patient to delete - * @return Result of the Deletion - * @throws PatientFeedException - */ - public Bundle delete(String uuid) throws PatientFeedException { - if (client == null) { - logger.info("client not set"); - initializeClient(); - } - if (uuid == null || uuid.isBlank()) { - throw new InvalidRequestException("Invalid parameter"); - } - try { - boolean deletionStatus = client.deletePatient(uuid); - if (!deletionStatus) { - throw new ResourceGoneException("Patient with UUID " + uuid); - } - return DeletionBundle.PrepareBundleAfterDeletionOperation(uuid, serverUrl); - } catch (PatientFeedException exception) { - logger.error("Error during delete Method : ", exception); - if (exception.getCause().getMessage().equals("PatientFeedClient : Patient didn't exist")) { - throw new ResourceNotFoundException(String.format("Any patient for given uuid [%s]", uuid)); - } - throw new InternalErrorException(exception); - //FIXME MAPPING FROM PatReg - } - } - /** - * The method is used to retrieve the url of the current server. - */ - private void getUrlOfServer() { - InetAddress ip; - try { - ip = InetAddress.getLocalHost(); - serverUrl = ip.getCanonicalHostName(); - logger.info(String.format("Your current Hostname : %s", serverUrl)); +throw new IllegalArgumentException("");*/ + /** + * The method is used to retrieve the url of the current server. + */ + private void getUrlOfServer() { + InetAddress ip; + try { + ip = InetAddress.getLocalHost(); + serverUrl = ip.getCanonicalHostName(); + logger.info(String.format("Your current Hostname : %s", serverUrl)); - } catch (UnknownHostException exception) { - logger.error("Unable to find serverUrl"); - serverUrl = "ReplaceByTheRightEndpoint"; - } - } + } catch (UnknownHostException exception) { + logger.error("Unable to find serverUrl"); + serverUrl = "ReplaceByTheRightEndpoint"; + } + } } 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 95178df3eafcef18fbc1ad15373a631793efc25d..16ca8e90cd4a240f253d22dcfb6afd76ecad0e43 100644 --- a/src/main/java/net/ihe/gazelle/business/provider/CHBundleProvider.java +++ b/src/main/java/net/ihe/gazelle/business/provider/CHBundleProvider.java @@ -1,6 +1,17 @@ package net.ihe.gazelle.business.provider; +import javax.inject.Inject; +import javax.inject.Named; + +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.r4.model.Bundle; +import org.hl7.fhir.r4.model.IdType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + 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.api.MethodOutcome; import ca.uhn.fhir.rest.server.IResourceProvider; @@ -8,53 +19,72 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import net.ihe.gazelle.adapter.connector.BundleToPatientRegistryConverter; import net.ihe.gazelle.adapter.connector.ConversionException; import net.ihe.gazelle.application.PatientRegistryFeedClient; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.r4.model.Bundle; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.inject.Inject; -import javax.inject.Named; @Named("chBundleProvider") public class CHBundleProvider implements IResourceProvider { - private static final Logger patientLogger = LoggerFactory.getLogger(CHBundleProvider.class); - @Inject - private ChPatientResourceProvider chPatientResourceProvider; - - @Inject - private PatientRegistryFeedClient patientRegistryFeedClient; - - @Override - public Class<? extends IBaseResource> getResourceType() { - return Bundle.class; - } - - /** - * Method called to create a Patient - * - * @param iti93Bundle - * @return - */ - @Create - public MethodOutcome create(@ResourceParam Bundle iti93Bundle) { - if (iti93Bundle == null || iti93Bundle.getEntry().isEmpty()) { - patientLogger.error("test"); - throw new InvalidRequestException("test"); - } - try { - net.ihe.gazelle.app.patientregistryapi.business.Patient patient = BundleToPatientRegistryConverter.iti93BundleToPatient(iti93Bundle); - MethodOutcome methodOutcome = new MethodOutcome(); -// chPatientResourceProvider.create(patient); -// methodOutcome.setResource(patientRegistryFeedClient.createPatient(patient)); - return methodOutcome; - - } catch (ConversionException e) { - throw new InvalidRequestException("Bundle Could not be converted to HL7 Patient"); - } -// } catch (PatientFeedException e) { -// throw new InternalErrorException("Patient Feed client is not set"); -// } - } + private static final Logger patientLogger = LoggerFactory.getLogger(CHBundleProvider.class); + @Inject + private ChPatientResourceProvider chPatientResourceProvider; + + @Inject + private PatientRegistryFeedClient patientRegistryFeedClient; + + @Override + public Class<? extends IBaseResource> getResourceType() { + return Bundle.class; + } + + /** + * Method called to create a Patient + * + * @param iti93Bundle + * @return + */ + @Create + public MethodOutcome create(@ResourceParam Bundle iti93Bundle) { + if (iti93Bundle == null || iti93Bundle.getEntry().isEmpty()) { + patientLogger.error("test"); + throw new InvalidRequestException("test"); + } + try { + net.ihe.gazelle.app.patientregistryapi.business.Patient patient = BundleToPatientRegistryConverter.iti93BundleToPatient(iti93Bundle); + MethodOutcome methodOutcome = new MethodOutcome(); + // chPatientResourceProvider.create(patient); + // methodOutcome.setResource(patientRegistryFeedClient.createPatient(patient)); + return methodOutcome; + + } catch (ConversionException e) { + throw new InvalidRequestException("Bundle Could not be converted to HL7 Patient"); + } + // } catch (PatientFeedException e) { + // throw new InternalErrorException("Patient Feed client is not set"); + // } + } + + /** + * Method to delete a Patient via a bundle + * + * @param iti93Bundle + * @return + */ + @Delete + public MethodOutcome delete(@IdParam IdType theId, @ResourceParam Bundle iti93Bundle) { + if (iti93Bundle == null || iti93Bundle.getEntry().isEmpty()) { + throw new InvalidRequestException("Invalid bundle provided, either null or empty."); + } + patientLogger.warn("Bundle received by resource Provider, will do"); + try { + net.ihe.gazelle.app.patientregistryapi.business.Patient patient = BundleToPatientRegistryConverter.iti93BundleToPatient(iti93Bundle); + MethodOutcome methodOutcome = new MethodOutcome(); + patientLogger.warn(patient.getIdentifiers().get(0).getSystemIdentifier()); + IdType patientId = new IdType(patient.getIdentifiers().get(0).getSystemIdentifier()); + patientLogger.warn("Was able to translate patient"); + patientLogger.warn(patientId.getValue()); + chPatientResourceProvider.delete(patientId); + return methodOutcome; + } catch (ConversionException e) { + throw new InvalidRequestException("Bundle Could not be converted to HL7 Patient"); + } + } } 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 9071ab329aa352e50f71c53b63e187ac09d05f93..69a849dd3ab4f6b7a82b4a209f49f011f564e751 100644 --- a/src/main/java/net/ihe/gazelle/business/provider/ChPatientResourceProvider.java +++ b/src/main/java/net/ihe/gazelle/business/provider/ChPatientResourceProvider.java @@ -1,6 +1,26 @@ package net.ihe.gazelle.business.provider; -import ca.uhn.fhir.rest.annotation.*; +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.r4.model.IdType; +import org.hl7.fhir.r4.model.Parameters; +import org.hl7.fhir.r4.model.Patient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +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.Operation; +import ca.uhn.fhir.rest.annotation.OperationParam; +import ca.uhn.fhir.rest.annotation.Read; +import ca.uhn.fhir.rest.annotation.ResourceParam; +import ca.uhn.fhir.rest.annotation.Update; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.param.StringAndListParam; import ca.uhn.fhir.rest.param.StringOrListParam; @@ -21,16 +41,6 @@ import net.ihe.gazelle.application.PatientRegistrySearchClient; import net.ihe.gazelle.application.PatientRegistryXRefSearchClient; import net.ihe.gazelle.lib.annotations.Package; import net.ihe.gazelle.lib.searchmodelapi.business.exception.SearchException; -import org.hl7.fhir.instance.model.api.IBaseBundle; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.r4.model.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.inject.Inject; -import javax.inject.Named; -import java.util.ArrayList; -import java.util.List; /** * This is a resource provider which stores Patient resources in memory using a HashMap. This is obviously not a production-ready solution for many @@ -174,13 +184,25 @@ public class ChPatientResourceProvider implements IResourceProvider { * @return FhirBundle that contains the deletion status */ @Delete - public MethodOutcome delete(@IdParam() IdType theId) { - String uuid = theId.getIdPart(); + public MethodOutcome delete(@IdParam IdType theId) { + + if (theId == null) { + throw new InvalidRequestException(NO_ID_PROVIDED); + } + patientLogger.warn(theId.getId()); + patientLogger.warn(theId.getIdPart()); + patientLogger.warn(theId.getValue()); + patientLogger.warn(theId.getValueAsString()); + + 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(); methodOutcome.setResource(patientRegistryFeedClient.delete(uuid)); return methodOutcome;