11package uk .nhs .adaptors .scr .mappings .from .hl7 ;
22
33import lombok .SneakyThrows ;
4-
5- import org .hibernate .validator .internal .util .logging .LoggerFactory ;
4+ import org .slf4j .LoggerFactory ;
65import org .hl7 .fhir .r4 .model .BaseDateTimeType ;
76import org .hl7 .fhir .r4 .model .DateTimeType ;
87import org .hl7 .fhir .r4 .model .InstantType ;
1514import java .time .LocalDate ;
1615import java .time .LocalDateTime ;
1716import java .time .format .DateTimeFormatter ;
18- import java .util .Date ;
1917import java .util .List ;
2018import java .util .TimeZone ;
2119
2624import static ca .uhn .fhir .model .api .TemporalPrecisionEnum .MILLI ;
2725import static java .lang .Integer .parseInt ;
2826
29- import java .lang .System .Logger ;
30- import java .lang .System .Logger .Level ;
31-
32-
3327public interface XmlToFhirMapper {
3428 // List of known date/time formats which may be present in HL7 based SCR.
3529 String DATE_TIME_SECONDS_PATTERN = "yyyyMMddHHmmss" ;
@@ -41,16 +35,9 @@ public interface XmlToFhirMapper {
4135 String SNOMED_SYSTEM = "http://snomed.info/sct" ;
4236 String TIMEZONE = "Europe/London" ;
4337
44- // private static Logger logger() {
45- // final class LogHolder {
46- // private static final Logger LOGGER = LoggerFactory.getLogger(XmlToFhirMapper.class);
47- // }
48- // return LogHolder.LOGGER;
49- // }
50-
5138 List <Resource > map (Node document );
5239
53- /**
40+ /**
5441 * Takes a date, and parses it into a BaseDateTimeObject.
5542 * Dates may be received in partial format, e.g. YYYY, YYYY-mm, which are invalid, but we still need to preserve
5643 * them as-is for clinical safety. Due to limitations on the third party FHIR parser code, we instead allocate a
@@ -75,8 +62,6 @@ static <T extends BaseDateTimeType> T parseDate(String date, Class<T> clazz) {
7562 int monthPrecision = 2 ;
7663 int yearPrecision = 1 ;
7764
78- Date defaultDate ;
79- defaultDate = new Date (0 );
8065
8166 if (isValidDate (date , DATE_TIME_SECONDS_PATTERN )) {
8267 LocalDateTime parsed = LocalDateTime .parse (date , DateTimeFormatter .ofPattern (DATE_TIME_SECONDS_PATTERN ));
@@ -123,10 +108,14 @@ static <T extends BaseDateTimeType> T parseDate(String date, Class<T> clazz) {
123108 baseDateTimeType .setYear (parseInt (date ) + 1 );
124109 baseDateTimeType .setMillis (yearPrecision );
125110 } else if (date .equals ("1" )) {
111+ date = "19700101" ;
112+ LocalDate parsed = LocalDate .parse (date , DateTimeFormatter .ofPattern (DATE_PATTERN ));
113+ baseDateTimeType .setPrecision (DAY );
126114 baseDateTimeType .setTimeZone (TimeZone .getTimeZone (TIMEZONE ));
127- baseDateTimeType .setValue (defaultDate );
128- // logger().log(Level.ERROR, "Invalid date value:1 updated");
129-
115+ setDatePart (baseDateTimeType , parsed .getDayOfMonth (), parsed .getMonthValue (), parsed .getYear ());
116+ baseDateTimeType .setMillis (dayPrecision );
117+ org .slf4j .Logger logger = LoggerFactory .getLogger (XmlToFhirMapper .class );
118+ logger .error ("Invalid date value:1 updated" );
130119 } else {
131120 throw new ScrBaseException ("Unsupported date format: " + date );
132121 }
@@ -162,5 +151,4 @@ static void setDatePart(BaseDateTimeType baseDateTimeType, int dayOfMonth, int m
162151 baseDateTimeType .setMonth (monthValue - 1 );
163152 baseDateTimeType .setYear (year );
164153 }
165-
166154}
0 commit comments