Skip to content

Commit

Permalink
fix: return timespan of all partial radiations
Browse files Browse the repository at this point in the history
fixes #79
  • Loading branch information
pcvolkmer committed Aug 19, 2024
1 parent 22165f3 commit 7e61a96
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.miracum.streams.ume.obdstofhir.mapper;

import java.util.*;
import lombok.val;
import org.hl7.fhir.r4.model.*;
import org.miracum.streams.ume.obdstofhir.FhirProperties;
import org.miracum.streams.ume.obdstofhir.lookup.*;
Expand Down Expand Up @@ -500,31 +501,32 @@ public Procedure createRadiotherapyProcedure(
return stProcedure;
}

/**
* This will return the whole timespan of completed partial radiations as part of a therapy. If no
* usable start or end dates have been found, this method will return a tuple containing `null`
* values.
*
* @param partialRadiations The partial radiations
* @return A tuple with start date and end date of all given partial radiations
*/
public Tupel<Date, Date> getTimeSpanFromPartialRadiations(List<Bestrahlung> partialRadiations) {
// min Beginndatum
List<Date> minDates = new ArrayList<>();
// maxBeginndatum
List<Date> maxDates = new ArrayList<>();

for (var radio : partialRadiations) {
if (radio.getST_Beginn_Datum() != null) {
minDates.add(convertObdsDateToDateTimeType(radio.getST_Beginn_Datum()).getValue());
}
if (radio.getST_Ende_Datum() != null) {
maxDates.add(convertObdsDateToDateTimeType(radio.getST_Ende_Datum()).getValue());
}
}

Date minDate = null;
Date maxDate = null;

if (!minDates.isEmpty()) {
minDate = Collections.min(minDates);
}
if (!maxDates.isEmpty()) {
maxDate = Collections.min(maxDates);
}

return new Tupel<>(minDate, maxDate);
val minDates =
partialRadiations.stream()
.map(radio -> convertObdsDateToDateTimeType(radio.getST_Beginn_Datum()))
.filter(Objects::nonNull)
.map(PrimitiveType::getValue)
.toList();

val maxDates =
partialRadiations.stream()
.map(radio -> convertObdsDateToDateTimeType(radio.getST_Ende_Datum()))
.filter(Objects::nonNull)
.map(PrimitiveType::getValue)
.toList();

return Tupel.<Date, Date>builder()
.first(minDates.isEmpty() ? null : Collections.min(minDates))
.second(maxDates.isEmpty() ? null : Collections.max(maxDates))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.miracum.streams.ume.obdstofhir.mapper;

import static org.assertj.core.api.Assertions.assertThat;

import java.time.Instant;
import java.util.Date;
import java.util.List;
import lombok.val;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.miracum.streams.ume.obdstofhir.FhirProperties;
import org.miracum.streams.ume.obdstofhir.model.ADT_GEKID.Menge_Patient.Patient.Menge_Meldung.Meldung.Menge_ST.ST.Menge_Bestrahlung.Bestrahlung;
import org.miracum.streams.ume.obdstofhir.model.Tupel;

public class ObdsProcedureMapperTest {

private ObdsProcedureMapper mapper;

@BeforeEach
void setup() {
this.mapper = new ObdsProcedureMapper(new FhirProperties());
}

@Test
void shouldGetWholeTimeSpanFromPartialRadiations() {
val partialRadiations =
List.of(
getTestPartialRadiationForTimespand("01.01.2024", "31.01.2024"),
getTestPartialRadiationForTimespand("01.03.2024", "30.04.2024"),
getTestPartialRadiationForTimespand("10.05.2024", "31.05.2024"));

val actual = this.mapper.getTimeSpanFromPartialRadiations(partialRadiations);

assertThat(actual)
.isEqualTo(
Tupel.builder()
.first(Date.from(Instant.parse("2024-01-01T00:00:00Z")))
.second(Date.from(Instant.parse("2024-05-31T00:00:00Z")))
.build());
}

private static Bestrahlung getTestPartialRadiationForTimespand(String start, String end) {
Bestrahlung bestrahlung = new Bestrahlung();
bestrahlung.setST_Beginn_Datum(start);
bestrahlung.setST_Ende_Datum(end);
return bestrahlung;
}
}

0 comments on commit 7e61a96

Please sign in to comment.