Skip to content

Commit

Permalink
PIXI-156: Add injection date to the hotel scan record form. Sometimes…
Browse files Browse the repository at this point in the history
… animals are injected on a different day than the scan is performed. (#19)
  • Loading branch information
andylassiter authored Dec 10, 2024
1 parent 32a0dfa commit e5cfbf4
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- [PIXI-156]: Add injection date to the hotel scan record form. Sometimes animals are injected on a different day than
the scan is performed.

## [1.3.1] - 20204-11-19

### Added
Expand Down Expand Up @@ -133,4 +136,5 @@ plugins directory and restart XNAT.
[PIXI-152]: https://radiologics.atlassian.net/browse/PIXI-152
[PIXI-153]: https://radiologics.atlassian.net/browse/PIXI-153
[PIXI-154]: https://radiologics.atlassian.net/browse/PIXI-154
[PIXI-155]: https://radiologics.atlassian.net/browse/PIXI-155
[PIXI-155]: https://radiologics.atlassian.net/browse/PIXI-155
[PIXI-156]: https://radiologics.atlassian.net/browse/PIXI-156
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Positive;
import java.time.LocalDate;
import java.time.LocalTime;

@Data
Expand All @@ -22,6 +23,7 @@ public class HotelSubjectDTO {
@ApiModelProperty(required = true, example = "Top Left", position = 2) @NotBlank private HotelPositionDTO position;
@ApiModelProperty private String orientation;
@ApiModelProperty @Positive private Double weight;
@ApiModelProperty @JsonFormat(pattern = "yyyyMMdd") private LocalDate injectionDate;
@ApiModelProperty @JsonFormat(pattern= "HHmmss") private LocalTime injectionTime; // Time is in DICOM Format
@ApiModelProperty @Positive private Double activity;
@ApiModelProperty private String notes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.sql.Date;
import java.sql.Time;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -135,6 +137,10 @@ protected HotelSubjectDTO toDTO(final PixiHotelsubjectI hotelSubject, final Pixi
.map(Objects::toString)
.map(Double::parseDouble)
.orElse(null);
LocalDate injectionDate = Optional.ofNullable(hotelSubject.getInjectionDate())
.map(Date.class::cast)
.map(Date::toLocalDate)
.orElse(null);
LocalTime injectionTime = Optional.ofNullable(hotelSubject.getInjectionTime())
.map(Time.class::cast)
.map(Time::toLocalTime)
Expand All @@ -156,6 +162,7 @@ protected HotelSubjectDTO toDTO(final PixiHotelsubjectI hotelSubject, final Pixi
.orientation(orientation)
.weight(weight)
.activity(activity)
.injectionDate(injectionDate)
.injectionTime(injectionTime)
.notes(notes)
.splitSessionLabel(splitSessionLabel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ console.log('pixi-editScanRecord.js');
spawn('div.description', 'Specify the route of administration used for the anesthesia')
])
]);

const injectionDateEl = spawn('div.panel-element.stacked', [
spawn('label.element-label|for=\'pixi:hotelScanRecord/hotel_subjects/subject[' + i + ']/injection_date\'', 'Injection Date'),
spawn('div.element-wrapper', [
spawn('input|type=\'date\'', {
id: 'pixi:hotelScanRecord/hotel_subjects/subject[' + i + ']/injection_date',
name: 'pixi:hotelScanRecord/hotel_subjects/subject[' + i + ']/injection_date',
}),
spawn('br'),
spawn('a.small_text', {
href: '#!',
onclick: (e) => XNAT.plugin.pixi.useSessionDateForInjectionDate(e, i)
}, 'Use Session Date')
])
]);

const splitSessionLabelEl = XNAT.ui.panel.input({
className: 'stacked',
Expand Down Expand Up @@ -214,6 +229,7 @@ console.log('pixi-editScanRecord.js');
name: 'pixi:hotelScanRecord/hotel_subjects/subject[' + i + ']/weight',
label: 'Weight (g)'
}),
injectionDateEl,
XNAT.ui.panel.input({
className: 'stacked',
type: 'time',
Expand Down Expand Up @@ -578,4 +594,37 @@ console.log('pixi-editScanRecord.js');
}
};

XNAT.plugin.pixi.useSessionDateForInjectionDate = function(e, i) {
console.log('Using session date for injection date for hotel position', i);
e.preventDefault();

const sessionSource = document.querySelector('input[name="session_existence"]:checked')?.value;
let sessionDate = '';

if (sessionSource === 'existing') {
console.log('Get session date from existing image session');
sessionDate = document.querySelector('input[name="pixi:hotelScanRecord/date"]')?.value;
} else if (sessionSource === 'new') {
console.log('New image session, not in XNAT, using user input session date');
const datepickerValue = document.querySelector('#datepicker1')?.value;
if (datepickerValue) {
const [month, day, year] = datepickerValue.split('/');
sessionDate = `${year}-${month}-${day}`;
}
} else {
console.log('Existing hotel scan record, using session date from the record');
sessionDate = document.querySelector('span.selected-session-date')?.textContent;
}

if (sessionDate) {
console.log(`Setting injection date for hotel position ${i} to ${sessionDate}`);
document.querySelector('input[name="pixi:hotelScanRecord/hotel_subjects/subject[' + i + ']/injection_date"]').value = sessionDate;


} else {
console.error('Session date not found.');
xmodal.message("Error", "Session date not found.");
}
}

}));
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@
<p><strong>Image Session:</strong> <a href="$content.getURI("/data/projects/${project}/experiments/${sessionId}?format=html")" class="selected-session-label">$item.getStringProperty("session_label")</a> <i class="spacer pad5"></i> <a href="#!" onclick="changeHotelSession()"><button class="btn btn-sm">Edit</button> </a></p>
<p><strong>Session Date:</strong> <span class="selected-session-date">$!item.getProperty("pixi:hotelScanRecord/date")</span></p>
#xdatHiddenBox("pixi:hotelScanRecord/session_label" $item "")
#xdatHiddenBox("pixi:hotelScanRecord/date" $item "")
</div>
</div>
</div>
Expand Down Expand Up @@ -477,6 +478,20 @@

</div>

<div class="panel-element stacked">
<label class="element-label" for="pixi:hotelScanRecord/hotel_subjects/subject[$i]/injection_date">
Injection Date
</label>
<div class="element-wrapper">
<input type="date"
id="pixi:hotelScanRecord/hotel_subjects/subject[$i]/injection_date"
name="pixi:hotelScanRecord/hotel_subjects/subject[$i]/injection_date"
value="$item.getProperty("pixi:hotelScanRecord/hotel_subjects/subject[$i]/injection_date")">
<br>
<a class="small_text" href="#!" onclick="XNAT.plugin.pixi.useSessionDateForInjectionDate(event, $i)">Use Session Date</a>
</div>
</div>

<div class="panel-element stacked">
<label class="element-label" for="pixi:hotelScanRecord/hotel_subjects/subject[$i]/injection_time">
Injection Time
Expand Down Expand Up @@ -985,7 +1000,7 @@
const position = hotelUnit.querySelector('[name*="position"]').value;

// Select the main inputs for a subject
const inputs = Array.from(hotelUnit.querySelectorAll('select[name*="orientation"], input[name*="weight"], input[name*="injection_time"], input[name*="activity"]'));
const inputs = Array.from(hotelUnit.querySelectorAll('select[name*="orientation"], input[name*="weight"], input[name*="injection_date"], input[name*="injection_time"], input[name*="activity"]'));

// If an input is non-empty, but the subject selector is empty, warn the user
if (isBlank(subjectSelector.value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@
<th>Weight (g)</th>
<td>$!subject.getProperty("weight")</td>
</tr>
<tr>
<th>Injection Date</th>
<td>$!subject.getProperty("injection_date")</td>
</tr>
<tr>
<th>Injection Time</th>
<td>$!subject.getProperty("injection_time")</td>
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/schemas/pixi/pixi.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,11 @@
<xs:documentation>Subject weight (g)</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="injection_date" type="xs:date" minOccurs="0">
<xs:annotation>
<xs:documentation>Radiopharmaceutical Injection Date</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="injection_time" type="xs:time" minOccurs="0">
<xs:annotation>
<xs:documentation>Radiopharmaceutical Injection Time</xs:documentation>
Expand Down

0 comments on commit e5cfbf4

Please sign in to comment.