From 7027e16968ab2c52d4d28cbe33a28755d0e1c8b8 Mon Sep 17 00:00:00 2001 From: Vincenzo Ingenito Date: Mon, 7 Oct 2024 10:33:58 +0200 Subject: [PATCH 1/2] fix: Issue 1037 --- .../enums/ConfidentialityCodeEnum.java | 33 +++++++++++++++++++ .../gtw/dispatcher/service/impl/FhirSRV.java | 9 +++-- 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/enums/ConfidentialityCodeEnum.java diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/enums/ConfidentialityCodeEnum.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/enums/ConfidentialityCodeEnum.java new file mode 100644 index 00000000..050ac10f --- /dev/null +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/enums/ConfidentialityCodeEnum.java @@ -0,0 +1,33 @@ +package it.finanze.sanita.fse2.ms.gtw.dispatcher.enums; + + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * Accepted document types defined by the affinity domain: {@link http://www.hl7italia.it/hl7italia_D7/node/2359}. + * + */ +@Getter +@AllArgsConstructor +public enum ConfidentialityCodeEnum { + + NORMAL("N","Normal"), + VERY_RESTRICTED("V","Very Restricted"); + + private final String code; + + private final String display; + + + + public static String getDisplayByCode(String code) { + for (ConfidentialityCodeEnum el : ConfidentialityCodeEnum.values()) { + if (el.getCode().equals(code)) { + return el.getDisplay(); + } + } + return ""; + } + +} \ No newline at end of file diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/impl/FhirSRV.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/impl/FhirSRV.java index 4dd444f6..fb1de5d4 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/impl/FhirSRV.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/impl/FhirSRV.java @@ -39,6 +39,7 @@ import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.client.TransformResDTO; import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.AdministrativeReqEnum; import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.AttivitaClinicaEnum; +import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.ConfidentialityCodeEnum; import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.LowLevelDocEnum; import it.finanze.sanita.fse2.ms.gtw.dispatcher.exceptions.BusinessException; import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.IConfigSRV; @@ -177,8 +178,12 @@ private DocumentEntryDTO createDocumentEntry(final org.jsoup.nodes.Document docC final Element confidentialityElement = docCDA.select("ClinicalDocument > confidentialityCode").first(); if (confidentialityElement != null) { - de.setConfidentialityCode(confidentialityElement.attr("code")); - de.setConfidentialityCodeDisplayName(confidentialityElement.attr("displayName")); + String code = confidentialityElement.attr("code"); + if(!StringUtility.isNullOrEmpty(code)) { + de.setConfidentialityCode(confidentialityElement.attr("code")); + String display = ConfidentialityCodeEnum.getDisplayByCode(code); + de.setConfidentialityCodeDisplayName(display); + } } final Element typeCodeElement = docCDA.select("ClinicalDocument > code").first(); From 5dae1ba5f99cf55021216a04693905c9ad50cd7f Mon Sep 17 00:00:00 2001 From: Vincenzo Ingenito Date: Tue, 8 Oct 2024 22:45:45 +0200 Subject: [PATCH 2/2] fix: Issue 1035 --- .../controller/impl/PublicationCTL.java | 33 ++++++++++++++----- .../gtw/dispatcher/service/impl/FhirSRV.java | 14 +------- .../gtw/dispatcher/utility/DateUtility.java | 32 +++++++++++------- 3 files changed, 46 insertions(+), 33 deletions(-) diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/PublicationCTL.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/PublicationCTL.java index eedc948b..06d4ba1a 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/PublicationCTL.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/controller/impl/PublicationCTL.java @@ -21,6 +21,7 @@ import static it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.EventTypeEnum.INI_UPDATE; import static it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.EventTypeEnum.RIFERIMENTI_INI; import static it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.RestExecutionResultEnum.FHIR_MAPPING_ERROR; +import static it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.RestExecutionResultEnum.GENERIC_ERROR; import static it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.RestExecutionResultEnum.INI_EXCEPTION; import static it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.RestExecutionResultEnum.get; import static it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.CdaUtility.createMasterIdError; @@ -469,18 +470,32 @@ private ResourceDTO callFhirMappingEngine(String transformId, String engineId, final JWTPayloadDTO jwtPayloadToken, PublicationCreateReplaceMetadataDTO jsonObj, final byte[] bytePDF, final String cda, final String documentSha256) { String sha1 = StringUtility.encodeSHA1(bytePDF); - final ResourceDTO fhirResourcesDTO = documentReferenceSRV.createFhirResources(cda,jwtPayloadToken.getSubject_role(), jsonObj, bytePDF.length, documentSha256,transformId, engineId, - jwtPayloadToken.getSubject_organization_id(),jwtPayloadToken.getLocality(),sha1); + + ResourceDTO fhirResourcesDTO = null; + try { + fhirResourcesDTO = documentReferenceSRV.createFhirResources(cda,jwtPayloadToken.getSubject_role(), jsonObj, bytePDF.length, documentSha256,transformId, engineId, + jwtPayloadToken.getSubject_organization_id(),jwtPayloadToken.getLocality(),sha1); + + if(!StringUtility.isNullOrEmpty(fhirResourcesDTO.getErrorMessage())){ + final ErrorResponseDTO error = ErrorResponseDTO.builder() + .type(FHIR_MAPPING_ERROR.getType()) + .title(FHIR_MAPPING_ERROR.getTitle()) + .instance(ErrorInstanceEnum.FHIR_RESOURCE_ERROR.getInstance()) + .detail(fhirResourcesDTO.getErrorMessage()).build(); - if(!isNullOrEmpty(fhirResourcesDTO.getErrorMessage())) { - final ErrorResponseDTO error = ErrorResponseDTO.builder() - .type(FHIR_MAPPING_ERROR.getType()) - .title(FHIR_MAPPING_ERROR.getTitle()) - .instance(ErrorInstanceEnum.FHIR_RESOURCE_ERROR.getInstance()) - .detail(fhirResourcesDTO.getErrorMessage()).build(); + throw new ValidationException(error); + + } + } catch(Exception ex) { + final ErrorResponseDTO error = ErrorResponseDTO.builder() + .type(GENERIC_ERROR.getType()) + .title(GENERIC_ERROR.getTitle()) + .instance(ErrorInstanceEnum.INVALID_DATE_FORMAT.getInstance()) + .detail(ex.getCause().getMessage()).build(); throw new ValidationException(error); - } + + } return fhirResourcesDTO; } diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/impl/FhirSRV.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/impl/FhirSRV.java index fb1de5d4..cfff3960 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/impl/FhirSRV.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/service/impl/FhirSRV.java @@ -11,14 +11,12 @@ */ package it.finanze.sanita.fse2.ms.gtw.dispatcher.service.impl; -import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Base64; import java.util.Date; import java.util.List; -import java.util.TimeZone; import org.jsoup.Jsoup; import org.jsoup.nodes.Element; @@ -79,25 +77,15 @@ public ResourceDTO createFhirResources(final String cda, String authorRole,final AuthorSlotDTO authorSlot = buildAuthorSlotDTO(authorInstitution,authorRole,docCDA); - try { final SubmissionSetEntryDTO submissionSetEntryDTO = createSubmissionSetEntry(docCDA, requestBody.getTipoAttivitaClinica().getCode(), requestBody.getIdentificativoSottomissione(),authorSlot,organizationId); output.setSubmissionSetEntryJson(StringUtility.toJSON(submissionSetEntryDTO)); - } catch(final Exception ex) { - output.setErrorMessage(ex.getCause().getCause().getMessage()); - } - if(StringUtility.isNullOrEmpty(output.getErrorMessage())) { - try { final DocumentEntryDTO documentEntryDTO = createDocumentEntry(docCDA, requestBody, size, sha1, authorSlot); output.setDocumentEntryJson(StringUtility.toJSON(documentEntryDTO)); - } catch(final Exception ex) { - output.setErrorMessage(ex.getCause().getCause().getMessage()); - } - } - if(!configSrv.isRemoveEds() && StringUtility.isNullOrEmpty(output.getErrorMessage())) { + if(!configSrv.isRemoveEds()) { final TransformResDTO resDTO = client.callConvertCdaInBundle(req); if (!StringUtility.isNullOrEmpty(resDTO.getErrorMessage())) { output.setErrorMessage(resDTO.getErrorMessage()); diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/utility/DateUtility.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/utility/DateUtility.java index 36980a9f..b8c09000 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/utility/DateUtility.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/dispatcher/utility/DateUtility.java @@ -15,6 +15,10 @@ import java.text.ParseException; import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; @@ -58,17 +62,23 @@ public static boolean isValidDateFormat(String dateStr, String format) { return false; } } - + + public static String convertDateCda(String data) throws ParseException { - SimpleDateFormat sdf = new SimpleDateFormat(INI_DATE_PATTERN); - - if (data.length() == INI_DATE_PATTERN.length() + 5) { - sdf = new SimpleDateFormat(INI_DATE_PATTERN + "Z"); - data = data.substring(0, INI_DATE_PATTERN.length()) + data.substring(INI_DATE_PATTERN.length()).replace(":", ""); //Se nel fusoorario mi vengono passati i : li rimuovo - } - - sdf.setTimeZone(TimeZone.getTimeZone("GMT")); - return new SimpleDateFormat(INI_DATE_PATTERN).format(sdf.parse(data)); - } + SimpleDateFormat sdfInput; + if (data.contains("+") || data.contains("-")) { + sdfInput = new SimpleDateFormat("yyyyMMddHHmmssX"); + } else { + sdfInput = new SimpleDateFormat(INI_DATE_PATTERN); + } + sdfInput.setTimeZone(TimeZone.getTimeZone("UTC")); + + Date parsedDate = sdfInput.parse(data); + SimpleDateFormat sdfOutput = new SimpleDateFormat(INI_DATE_PATTERN); + sdfOutput.setTimeZone(TimeZone.getTimeZone("UTC")); + + return sdfOutput.format(parsedDate); + } + }