diff --git a/src/main/java/org/nrg/xnatx/plugins/pixi/inveon/sessionBuilder/InveonSessionBuilder.java b/src/main/java/org/nrg/xnatx/plugins/pixi/inveon/sessionBuilder/InveonSessionBuilder.java index 62603ac..2eacf02 100644 --- a/src/main/java/org/nrg/xnatx/plugins/pixi/inveon/sessionBuilder/InveonSessionBuilder.java +++ b/src/main/java/org/nrg/xnatx/plugins/pixi/inveon/sessionBuilder/InveonSessionBuilder.java @@ -98,23 +98,25 @@ public XnatImagesessiondataBean call() throws Exception { sessionBean.setSubjectId(subject); sessionBean.setLabel(label); - // Set session date to earliest scan date - Optional sessionDate = sessionBean.getScans_scan().stream() - .map(XnatImagescandataI::getStartDate) - .map(d -> (Date) d) - .distinct() - .sorted() - .findFirst(); + String modality = hasPET ? "PET" : "CT"; - sessionDate.ifPresent(sessionBean::setDate); + Optional sessionDate = sessionBean.getScans_scan().stream() + .filter(s -> s.getModality().equalsIgnoreCase(modality)) + .map(XnatImagescandataI::getStartDate) + .map(d -> (Date) d) + .distinct() + .sorted() + .findFirst(); Optional sessionTime = sessionBean.getScans_scan().stream() - .map(XnatImagescandataI::getStarttime) - .map(d -> (Date) d) - .distinct() - .sorted() - .findFirst(); + .filter(s -> s.getModality().equalsIgnoreCase(modality)) + .map(XnatImagescandataI::getStarttime) + .map(d -> (Date) d) + .distinct() + .sorted() + .findFirst(); + sessionDate.ifPresent(sessionBean::setDate); sessionTime.ifPresent(sessionBean::setTime); return sessionBean;