Skip to content

Commit

Permalink
Merge branch 'develop' into feature/otel-config
Browse files Browse the repository at this point in the history
  • Loading branch information
simone-lungarella committed Apr 10, 2024
2 parents b03a842 + 294a0f5 commit b459b54
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
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.IFhirSRV;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.DateUtility;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.StringUtility;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.ValidationUtility;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -48,7 +49,7 @@
@Slf4j
public class FhirSRV implements IFhirSRV {

private static final String PATH_CUSTODIAN_ID = "ClinicalDocument > custodian > assignedCustodian > representedCustodianOrganization > id";
private static final String PATH_ID = "ClinicalDocument > id";
private static final String PATH_PATIENT_ID = "ClinicalDocument > recordTarget > patientRole> id";
private static final String EXTENSION_ATTRIBUTE = "extension";

Expand Down Expand Up @@ -140,12 +141,11 @@ private SubmissionSetEntryDTO createSubmissionSetEntry(final org.jsoup.nodes.Doc
sse.setAuthorRole(authorSlotDTO.getAuthorRole());
sse.setPatientId(buildPatient(docCDA));
String sourceIdRoot = "";
final Element custodianPath = docCDA.select(PATH_CUSTODIAN_ID).first();
if (custodianPath != null) {
sourceIdRoot = custodianPath.attr("root");
final Element idPath = docCDA.select(PATH_ID).first();
if (idPath != null) {
sourceIdRoot = idPath.attr("root");
sse.setSourceId(sourceIdRoot.substring(0, sourceIdRoot.length()-4));
}

sse.setSourceId(sourceIdRoot);
sse.setUniqueID(identificativoSottomissione);

sse.setSubmissionTime(new SimpleDateFormat(Constants.Misc.INI_DATE_PATTERN).format(new Date()));
Expand All @@ -158,7 +158,8 @@ 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 hash,
Expand Down Expand Up @@ -205,7 +206,7 @@ private DocumentEntryDTO createDocumentEntry(final org.jsoup.nodes.Document docC
administrativeRequestList.add(en.getCode() + "^" + en.getDescription());
}
de.setAdministrativeRequest(administrativeRequestList);

}

de.setAuthorRole(authorSlotDTO.getAuthorRole());
Expand All @@ -231,14 +232,13 @@ private DocumentEntryDTO createDocumentEntry(final org.jsoup.nodes.Document docC
de.setPracticeSettingCode(requestBody.getAssettoOrganizzativo().name());
de.setPracticeSettingCodeName(requestBody.getAssettoOrganizzativo().getDescription());

final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

if (requestBody.getDataInizioPrestazione() != null) {
de.setServiceStartTime(sdf.parse(requestBody.getDataInizioPrestazione()).toString());
if (requestBody.getDataInizioPrestazione() != null && DateUtility.isValidDateFormat(requestBody.getDataInizioPrestazione(), "yyyyMMddHHmmss")) {
de.setServiceStartTime(requestBody.getDataInizioPrestazione());
}

if (requestBody.getDataFinePrestazione() != null) {
de.setServiceStopTime(sdf.parse(requestBody.getDataFinePrestazione()).toString());
if (requestBody.getDataFinePrestazione() != null && DateUtility.isValidDateFormat(requestBody.getDataFinePrestazione(), "yyyyMMddHHmmss")) {
de.setServiceStopTime(requestBody.getDataFinePrestazione());
}
} catch(final Exception ex) {
log.error("Error while create document entry : " , ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
*/
package it.finanze.sanita.fse2.ms.gtw.dispatcher.utility;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import it.finanze.sanita.fse2.ms.gtw.dispatcher.exceptions.BusinessException;
import lombok.extern.slf4j.Slf4j;

@Slf4j
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);
long diff = d2.getTime() - d1.getTime();
return TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
}

public static Date addDay(final Date date, final Integer nDays) {
Calendar c = Calendar.getInstance();
try {
Expand All @@ -38,8 +38,20 @@ public static Date addDay(final Date date, final Integer nDays) {
throw new BusinessException("Error while perform addDay : " , ex);
}
return c.getTime();


}

public static boolean isValidDateFormat(String dateStr, String format) {
SimpleDateFormat sdf = new SimpleDateFormat(format);
sdf.setLenient(false);
try {
sdf.parse(dateStr);
return true;
} catch (Exception e) {
log.error("Error while perform isValidDate: " , e);
return false;
}
}


}

0 comments on commit b459b54

Please sign in to comment.