Skip to content

Commit

Permalink
Merge branch 'develop' into feature/audit-ini
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenzo-ingenito committed Oct 9, 2024
2 parents 5dbb747 + 5dae1ba commit a57341d
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 "";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,6 +37,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;
Expand Down Expand Up @@ -78,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());
Expand Down Expand Up @@ -177,8 +166,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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}


}

0 comments on commit a57341d

Please sign in to comment.