From 636b2c6f0ab6dd19c84fabb98ccbc977e917dbc1 Mon Sep 17 00:00:00 2001 From: Vincenzo Ingenito Date: Thu, 26 Sep 2024 16:52:43 +0200 Subject: [PATCH] fix: Creation time --- .../gtw/dispatcher/service/impl/FhirSRV.java | 33 +++++++++---------- .../gtw/dispatcher/utility/DateUtility.java | 23 +++++++++++-- 2 files changed, 36 insertions(+), 20 deletions(-) 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 fd7ac39..4dd444f 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,13 +11,14 @@ */ 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; @@ -56,10 +57,10 @@ public class FhirSRV implements IFhirSRV { private static final String EXTENSION_ATTRIBUTE = "extension"; private static final String REFERENCE_ID_LIST_SUFFIX = "&ISO^urn:ihe:iti:xds:2013:order"; - + @Autowired private FhirMappingClient client; - + @Autowired private IConfigSRV configSrv; @@ -74,7 +75,7 @@ public ResourceDTO createFhirResources(final String cda, String authorRole,final final DocumentReferenceDTO documentReferenceDTO = buildDocumentReferenceDTO(encodedCDA, requestBody, size, hash); FhirResourceDTO req = buildFhirResourceDTO(documentReferenceDTO, cda, transformId, engineId); - + AuthorSlotDTO authorSlot = buildAuthorSlotDTO(authorInstitution,authorRole,docCDA); try { @@ -149,7 +150,7 @@ private SubmissionSetEntryDTO createSubmissionSetEntry(final org.jsoup.nodes.Doc sse.setAuthorInstitution(authorSlotDTO.getAuthorInstitution()); sse.setAuthorRole(authorSlotDTO.getAuthorRole()); sse.setPatientId(buildPatient(docCDA)); - + String sourceId = StringUtility.sanitizeSourceId(organizationId); sse.setSourceId(SOURCE_ID_PREFIX+sourceId); sse.setUniqueID(identificativoSottomissione); @@ -164,8 +165,6 @@ private SubmissionSetEntryDTO createSubmissionSetEntry(final org.jsoup.nodes.Doc } return sse; } - - private DocumentEntryDTO createDocumentEntry(final org.jsoup.nodes.Document docCDA, final PublicationCreateReplaceMetadataDTO requestBody, final Integer size, final String sha1, @@ -202,8 +201,8 @@ private DocumentEntryDTO createDocumentEntry(final org.jsoup.nodes.Document docC de.setUniqueId(requestBody.getIdentificativoDoc()); de.setMimeType("application/pdf+text/x-cda-r2+xml"); - String effectiveTime = docCDA.select("ClinicalDocument > effectiveTime").val(); - de.setCreationTime(effectiveTime); + String effectiveTime = docCDA.select("ClinicalDocument > effectiveTime").val(); + de.setCreationTime(DateUtility.convertDateCda(effectiveTime)); de.setHash(sha1); de.setSize(size); if(requestBody.getAdministrativeRequest() != null) { @@ -244,20 +243,20 @@ private DocumentEntryDTO createDocumentEntry(final org.jsoup.nodes.Document docC if (requestBody.getDataFinePrestazione() != null && DateUtility.isValidDateFormat(requestBody.getDataFinePrestazione(), "yyyyMMddHHmmss")) { de.setServiceStopTime(requestBody.getDataFinePrestazione()); } - + List referenceIdList = buildReferenceIdList(docCDA, "ClinicalDocument > inFulfillmentOf > order > id"); if(!referenceIdList.isEmpty()) { de.setReferenceIdList(referenceIdList); } - - + + } catch(final Exception ex) { log.error("Error while create document entry : " , ex); throw new BusinessException("Error while create document entry : " , ex); } return de; } - + private List buildReferenceIdList(final org.jsoup.nodes.Document docCDA, final String path) { List out = new ArrayList<>(); Elements elements = docCDA.select(path); @@ -270,7 +269,7 @@ private List buildReferenceIdList(final org.jsoup.nodes.Document docCDA, } } } - + return out; } @@ -284,8 +283,8 @@ private String buildPatient(final org.jsoup.nodes.Document docCDA) { } return out; } - - + + private static AuthorSlotDTO buildAuthorSlotDTO(final String authorInstitution,final String authorRole,final org.jsoup.nodes.Document docCDA) { AuthorSlotDTO author = new AuthorSlotDTO(); author.setAuthorRole(authorRole); @@ -301,5 +300,5 @@ private static AuthorSlotDTO buildAuthorSlotDTO(final String authorInstitution,f } - + } 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 094fe2c..36980a9 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 @@ -11,18 +11,24 @@ */ package it.finanze.sanita.fse2.ms.gtw.dispatcher.utility; +import static it.finanze.sanita.fse2.ms.gtw.dispatcher.config.Constants.Misc.INI_DATE_PATTERN; + +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; +import java.util.TimeZone; import java.util.concurrent.TimeUnit; import it.finanze.sanita.fse2.ms.gtw.dispatcher.exceptions.BusinessException; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; + @Slf4j +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class DateUtility { - - private DateUtility() {} - + public static long getDifferenceDays(Date d1, Date d2) { long diff = d2.getTime() - d1.getTime(); return TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS); @@ -53,5 +59,16 @@ public static boolean isValidDateFormat(String dateStr, String format) { } } + 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)); + } }