Skip to content

Commit

Permalink
comments implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
wuall826 committed May 2, 2024
1 parent aa1a673 commit d1aa415
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 153 deletions.
20 changes: 0 additions & 20 deletions src/main/java/ca/on/oicr/gsi/dimsum/controller/mvc/MvcUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ public class MvcUtils {

private static final String BEFORE_DATE_KEY = "BEFORE_DATE";
private static final String AFTER_DATE_KEY = "AFTER_DATE";
private static final String STARTED_BEFORE_KEY = "STARTED_BEFORE";
private static final String STARTED_AFTER_KEY = "STARTED_AFTER";
private static final String COMPLETED_BEFORE_KEY = "COMPLETED_BEFORE";
private static final String COMPLETED_AFTER_KEY = "COMPLETED_AFTER";

public static void validateDataQuery(DataQuery query) {
if (query.getPageNumber() < 1) {
Expand Down Expand Up @@ -129,22 +125,6 @@ public static LocalDate parseCaseDateFilterValue(DataQuery query, String key) {
return value == null ? null : LocalDate.parse(value);
}

public static LocalDate parseStartedBeforeDate(DataQuery query) {
return parseCaseDateFilterValue(query, STARTED_BEFORE_KEY);
}

public static LocalDate parseStartedAfterDate(DataQuery query) {
return parseCaseDateFilterValue(query, STARTED_AFTER_KEY);
}

public static LocalDate parseCompletedBeforeDate(DataQuery query) {
return parseCaseDateFilterValue(query, COMPLETED_BEFORE_KEY);
}

public static LocalDate parseCompletedAfterDate(DataQuery query) {
return parseCaseDateFilterValue(query, COMPLETED_AFTER_KEY);
}

public static LocalDate parseAfterDate(DataQuery query) {
return parseDateFilterValue(query, AFTER_DATE_KEY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@ private static CompletedGate getGate(String label) {
}

private static LocalDate getCompletionDate(Case x) {
if (x.isStopped()) {
return null;
}
List<CaseDeliverable> deliverables = x.getDeliverables();
if (deliverables.isEmpty()) {
return null;
Expand Down
21 changes: 14 additions & 7 deletions src/test/java/ca/on/oicr/gsi/dimsum/MockCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ private static Case makeCase25() {
addTest(kase, caseNumber, 1, "Test", "WG", true, true, true, true);
markAnalysisReview(kase.getDeliverables().get(0), true);
markReleaseApproval(kase.getDeliverables().get(0), true);
markRelease(kase.getDeliverables().get(0).getReleases().get(0), true);
markRelease(kase.getDeliverables().get(0).getReleases().get(0), true, null);
addDeliverable(kase, DeliverableType.CLINICAL_REPORT, "Clinical Report");
return kase;
}
Expand All @@ -331,7 +331,7 @@ private static Case makeCase26() {
addTest(kase, caseNumber, 1, "Test", "WG", true, true, true, true);
markAnalysisReview(kase.getDeliverables().get(0), true);
markReleaseApproval(kase.getDeliverables().get(0), true);
markRelease(kase.getDeliverables().get(0).getReleases().get(0), true);
markRelease(kase.getDeliverables().get(0).getReleases().get(0), true, null);
CaseDeliverable deliverable =
addDeliverable(kase, DeliverableType.CLINICAL_REPORT, "Clinical Report");
markAnalysisReview(deliverable, true);
Expand All @@ -345,7 +345,7 @@ private static Case makeCase27() {
addTest(kase, caseNumber, 1, "Test", "WG", true, true, true, true);
markAnalysisReview(kase.getDeliverables().get(0), true);
markReleaseApproval(kase.getDeliverables().get(0), true);
markRelease(kase.getDeliverables().get(0).getReleases().get(0), true);
markRelease(kase.getDeliverables().get(0).getReleases().get(0), true, null);
CaseDeliverable deliverable =
addDeliverable(kase, DeliverableType.CLINICAL_REPORT, "Clinical Report");
markAnalysisReview(deliverable, true);
Expand All @@ -360,7 +360,7 @@ private static Case makeCase28() {
addTest(kase, caseNumber, 1, "Test", "WG", true, true, true, true);
markAnalysisReview(kase.getDeliverables().get(0), true);
markReleaseApproval(kase.getDeliverables().get(0), true);
markRelease(kase.getDeliverables().get(0).getReleases().get(0), true);
markRelease(kase.getDeliverables().get(0).getReleases().get(0), true, null);
return kase;
}

Expand Down Expand Up @@ -398,7 +398,7 @@ private static Case makeCase31() {
addDeliverable(kase, DeliverableType.CLINICAL_REPORT, "Clinical Report");
markAnalysisReview(deliverable, true);
markReleaseApproval(deliverable, true);
markRelease(deliverable.getReleases().get(0), true);
markRelease(deliverable.getReleases().get(0), true, null);
return kase;
}

Expand Down Expand Up @@ -453,6 +453,9 @@ private static Case makeCase34() {
private static Case makeCase(String donorName, String assayName, String projectName,
String requisitionName, int caseNumber, LocalDate startDate,
LocalDate completionDate) {
if (startDate == null) {
startDate = LocalDate.now();
}
Case kase = mock(Case.class);
Donor donor = mock(Donor.class);
when(donor.getName()).thenReturn(donorName);
Expand Down Expand Up @@ -546,10 +549,14 @@ private static void markReleaseApproval(CaseDeliverable deliverable, Boolean qcP
when(deliverable.getReleaseApprovalQcDate()).thenReturn(LocalDate.now());
}

private static void markRelease(CaseRelease release, Boolean qcPassed) {
private static void markRelease(CaseRelease release, Boolean qcPassed, LocalDate qcDate) {
when(release.getQcPassed()).thenReturn(qcPassed);
when(release.getQcUser()).thenReturn("User");
when(release.getQcDate()).thenReturn(LocalDate.now());
if (qcDate != null) {
when(release.getQcDate()).thenReturn(qcDate);
} else {
when(release.getQcDate()).thenReturn(LocalDate.now());
}
}

private static ca.on.oicr.gsi.cardea.data.Test addTest(Case kase, int caseNumber, int testNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,8 @@ public void testStartedBeforeFilter() {
@org.junit.jupiter.api.Test
public void testStartedAfterFilter() {
CaseFilter filter = new CaseFilter(CaseFilterKey.STARTED_AFTER, "2023-12-31");
testFilterCases(filter, Arrays.asList(34));
testFilterCases(filter, Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34));
}

@org.junit.jupiter.api.Test
Expand Down
86 changes: 86 additions & 0 deletions ts/component/date-input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { replaceUrlParams, updateUrlParams } from "../util/urls";

export class DateInput {
direction: string;
onChangeCallback: (key: string, value: string) => void;
container: HTMLElement;
lastValue: string | null = null;

constructor(
direction: string,
onChangeCallback: (key: string, value: string) => void
) {
this.direction = this.formatLabel(direction);
this.onChangeCallback = onChangeCallback;
this.container = this.createDateFilterControl();
}

private createDateFilterControl(): HTMLElement {
const dateDiv = document.createElement("div");
dateDiv.className =
"font-inter font-medium text-12 text-black bg-grey-100 px-2 py-1 rounded-md hover:ring-2 ring-green-200 ring-offset-1";

const dateLabel = document.createElement("label");
dateLabel.htmlFor = `${this.direction.toLowerCase()}Date`;
dateLabel.textContent = `${this.direction}:`;

const dateSelect = this.makeDateSelect();
const dateInput = this.makeDateInput();

const updateUrlAndFilter = () => {
const selectedDirection = this.direction.toUpperCase();
const selectedType = dateSelect.value.toUpperCase();
const selectedDate = dateInput.value;
const key = `${selectedDirection}_${selectedType}`;

if (selectedDate !== this.lastValue) {
this.lastValue = selectedDate; // Update lastValue to the current

if (selectedDate) {
replaceUrlParams(key, selectedDate);
} else {
updateUrlParams(key, "", false);
}
this.onChangeCallback(key, selectedDate);
}
};

dateSelect.addEventListener("change", updateUrlAndFilter);
dateInput.addEventListener("input", updateUrlAndFilter);
dateInput.addEventListener("change", updateUrlAndFilter);

dateDiv.appendChild(dateLabel);
dateDiv.appendChild(dateSelect);
dateDiv.appendChild(dateInput);

return dateDiv;
}

private makeDateSelect(): HTMLSelectElement {
const dateSelect = document.createElement("select");
dateSelect.id = `${this.direction.toLowerCase()}Date`;
dateSelect.className =
"text-black bg-grey-100 px-2 py-1 rounded-md hover:ring-2 ring-green-200 ring-offset-1";

const dateTypes = ["before", "after"];
dateTypes.forEach((type) => {
const option = document.createElement("option");
option.value = type.toLowerCase();
option.textContent = type;
dateSelect.appendChild(option);
});

return dateSelect;
}

private makeDateInput(): HTMLInputElement {
const dateInput = document.createElement("input");
dateInput.type = "date";
dateInput.id = `${this.direction.toLowerCase()}DateInput`;
return dateInput;
}

private formatLabel(label: string): string {
return label.charAt(0).toUpperCase() + label.slice(1).toLowerCase();
}
}
Loading

0 comments on commit d1aa415

Please sign in to comment.