Skip to content

Commit

Permalink
[GR-1526] added requisition created date (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
djcooke authored Jun 20, 2024
1 parent ab0a054 commit a9f3824
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ca.on.oicr.pinery.api;

import java.time.Instant;
import java.time.LocalDate;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -50,4 +52,8 @@ public interface Requisition {
void setPauses(List<RequisitionPause> pauses);

void addPause(RequisitionPause pause);

public Instant getCreated();

public void setCreated(Instant created);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import ca.on.oicr.pinery.api.Requisition;
import ca.on.oicr.pinery.api.RequisitionPause;
import ca.on.oicr.pinery.api.SignOff;

import java.time.Instant;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand All @@ -20,6 +22,7 @@ public class DefaultRequisition implements Requisition {
private boolean stopped = false;
private String stopReason;
private List<RequisitionPause> pauses;
private Instant created;

@Override
public Integer getId() {
Expand Down Expand Up @@ -151,9 +154,19 @@ public void addPause(RequisitionPause pause) {
pauses.add(pause);
}

@Override
public Instant getCreated() {
return created;
}

@Override
public void setCreated(Instant created) {
this.created = created;
}

@Override
public int hashCode() {
return Objects.hash(assayIds, id, name, sampleIds, signOffs, stopped, stopReason);
return Objects.hash(assayIds, id, name, sampleIds, signOffs, stopped, stopReason, created);
}

@Override
Expand All @@ -171,6 +184,7 @@ public boolean equals(Object obj) {
&& Objects.equals(sampleIds, other.sampleIds)
&& Objects.equals(signOffs, other.signOffs)
&& Objects.equals(stopped, other.stopped)
&& Objects.equals(stopReason, other.stopReason);
&& Objects.equals(stopReason, other.stopReason)
&& Objects.equals(created, other.created);
}
}
17 changes: 13 additions & 4 deletions pinery-ws-dto/src/main/java/ca/on/oicr/ws/dto/Dtos.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -653,6 +654,7 @@ public static RequisitionDto asDto(Requisition from) {
}
to.setStopped(from.isStopped());
to.setStopReason(from.getStopReason());
to.setCreatedDate(format(from.getCreated()));
return to;
}

Expand All @@ -667,18 +669,25 @@ private static String format(Date date) {
if (date == null) {
return null;
}
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), ZoneId.systemDefault())
.truncatedTo(ChronoUnit.SECONDS)
.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
return format(Instant.ofEpochMilli(date.getTime()));
}

private static final String format(LocalDate date) {
private static String format(LocalDate date) {
if (date == null) {
return null;
}
return date.format(dateFormatter);
}

private static String format(Instant date) {
if (date == null) {
return null;
}
return ZonedDateTime.ofInstant(date, ZoneId.systemDefault())
.truncatedTo(ChronoUnit.SECONDS)
.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
}

protected static String format(BigDecimal decimal) {
if (decimal == null) {
return null;
Expand Down
15 changes: 13 additions & 2 deletions pinery-ws-dto/src/main/java/ca/on/oicr/ws/dto/RequisitionDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class RequisitionDto {
private boolean stopped = false;
private String stopReason;
private List<RequisitionPauseDto> pauses;
private String createdDate;

public Integer getId() {
return id;
Expand Down Expand Up @@ -99,9 +100,18 @@ public void setPauses(List<RequisitionPauseDto> pauses) {
this.pauses = pauses;
}

@JsonProperty("created_date")
public String getCreatedDate() {
return createdDate;
}

public void setCreatedDate(String createdDate) {
this.createdDate = createdDate;
}

@Override
public int hashCode() {
return Objects.hash(assayIds, id, name, sampleIds, signOffs, stopped, stopReason, pauses);
return Objects.hash(assayIds, id, name, sampleIds, signOffs, stopped, stopReason, pauses, createdDate);
}

@Override
Expand All @@ -120,6 +130,7 @@ public boolean equals(Object obj) {
&& Objects.equals(signOffs, other.signOffs)
&& Objects.equals(stopped, other.stopped)
&& Objects.equals(stopReason, other.stopReason)
&& Objects.equals(pauses, other.pauses);
&& Objects.equals(pauses, other.pauses)
&& Objects.equals(createdDate, other.createdDate);
}
}

0 comments on commit a9f3824

Please sign in to comment.