-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathadverseEventsSection.ts
More file actions
115 lines (101 loc) · 3.5 KB
/
adverseEventsSection.ts
File metadata and controls
115 lines (101 loc) · 3.5 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import type { Locator, Page } from "@playwright/test";
/**
* Interactor for the Adverse Events (Pharmacovigilance) section on Drug pages.
*
* Displays adverse event data from the FDA Adverse Event Reporting System (FAERS),
* including event names with MedDRA links, reported event counts, and log likelihood
* ratios indicating the strength of the drug-adverse event association.
*
* @example
* ```typescript
* const adverseEvents = new PharmacovigilanceSection(page);
* await adverseEvents.waitForLoad();
*
* // Get number of adverse events
* const rowCount = await adverseEvents.getTableRows();
*
* // Get details of first adverse event
* const eventName = await adverseEvents.getAdverseEventName(0);
* const llr = await adverseEvents.getLogLikelihoodRatio(0);
* ```
*
* @category shared
* @remarks Section ID: `adverseevents`
*/
export class PharmacovigilanceSection {
constructor(private page: Page) {}
// Section container
getSection(): Locator {
return this.page.locator("[data-testid='section-adverseevents']");
}
async isSectionVisible(): Promise<boolean> {
return await this.getSection()
.isVisible()
.catch(() => false);
}
/**
* Wait for the section to finish loading (no skeleton loaders)
*/
async waitForLoad(): Promise<void> {
const section = this.getSection();
await section.waitFor({ state: "visible", timeout: 10000 });
// Wait for skeleton loaders to disappear
await this.page
.waitForFunction(
() => {
const sect = document.querySelector("[data-testid='section-adverseevents']");
if (!sect) return false;
const skeletons = sect.querySelectorAll(".MuiSkeleton-root");
return skeletons.length === 0;
},
{ timeout: 15000 }
)
.catch(() => {
// If no skeletons found, section already loaded
});
}
// Table
getTable(): Locator {
return this.getSection().locator("table");
}
async getTableRows(): Promise<number> {
const tbody = this.getTable().locator("tbody");
const rows = tbody.locator("tr");
return await rows.count();
}
async getTableRow(index: number): Promise<Locator> {
const tbody = this.getTable().locator("tbody");
return tbody.locator("tr").nth(index);
}
// Get adverse event name
async getAdverseEventName(rowIndex: number): Promise<string | null> {
const row = await this.getTableRow(rowIndex);
const cell = row.locator("td").nth(0);
return await cell.textContent();
}
// Get adverse event link (MedDRA)
async getAdverseEventLink(rowIndex: number): Promise<Locator> {
const row = await this.getTableRow(rowIndex);
return row.locator("a[href*='identifiers.org/meddra']");
}
async hasAdverseEventLink(rowIndex: number): Promise<boolean> {
const link = await this.getAdverseEventLink(rowIndex);
return await link.isVisible().catch(() => false);
}
async clickAdverseEventLink(rowIndex: number): Promise<void> {
const link = await this.getAdverseEventLink(rowIndex);
await link.click();
}
// Get count of reported events
async getReportedEventsCount(rowIndex: number): Promise<string | null> {
const row = await this.getTableRow(rowIndex);
const cell = row.locator("td").nth(1);
return await cell.textContent();
}
// Get log likelihood ratio
async getLogLikelihoodRatio(rowIndex: number): Promise<string | null> {
const row = await this.getTableRow(rowIndex);
const cell = row.locator("td").nth(2);
return await cell.textContent();
}
}