Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer Annotating Types Over Asserting #3042

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const evaluateEcrMetadata = (
fhirBundle: Bundle,
mappings: PathMappings,
): EcrMetadata => {
const rrDetails = evaluate(fhirBundle, mappings.rrDetails) as Observation[];
const rrDetails: Observation[] = evaluate(fhirBundle, mappings.rrDetails);

let reportableConditionsList: ReportableConditions = {};

Expand Down Expand Up @@ -97,11 +97,11 @@ export const evaluateEcrMetadata = (
}

const custodianRef = evaluate(fhirBundle, mappings.eicrCustodianRef)[0] ?? "";
const custodian = evaluateReference(
const custodian: Organization = evaluateReference(
fhirBundle,
mappings,
custodianRef,
) as Organization;
);

const eicrReleaseVersion = (fhirBundle: any, mappings: any) => {
const releaseVersion = evaluate(fhirBundle, mappings.eicrReleaseVersion)[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,8 @@ export const evaluateEmergencyContact = (
fhirBundle: Bundle,
mappings: PathMappings,
) => {
const contacts = (evaluate(fhirBundle, mappings.patientEmergencyContact) ??
[]) as PatientContact[];
const contacts: PatientContact[] =
evaluate(fhirBundle, mappings.patientEmergencyContact) ?? [];

if (contacts.length === 0) return undefined;

Expand Down Expand Up @@ -655,19 +655,19 @@ export const evaluateValue = (entry: Element, path: string | Path): string => {
) {
value = originalValue.toString();
} else if (originalValuePath === "Quantity") {
const data = originalValue as Quantity;
const data: Quantity = originalValue;
let unit = data.unit;
const firstLetterRegex = /^[a-z]/i;
if (unit?.match(firstLetterRegex)) {
unit = " " + unit;
}
value = `${data.value ?? ""}${unit ?? ""}`;
} else if (originalValuePath === "CodeableConcept") {
const data = originalValue as CodeableConcept;
const data: CodeableConcept = originalValue;
value =
data.coding?.[0].display || data.text || data.coding?.[0].code || "";
} else if (originalValuePath === "Coding") {
const data = originalValue as Coding;
const data: Coding = originalValue;
value = data?.display || data?.code || "";
} else if (typeof originalValue === "object") {
console.log(`Not implemented for ${originalValue.__path__}`);
Expand Down
5 changes: 2 additions & 3 deletions containers/ecr-viewer/src/app/services/formatService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,8 @@ export function formatTablesToJSON(htmlString: string): TableJson[] {
}

// <table><caption>{name}</caption></table>
const tableWithCaptionArray = doc.querySelectorAll(
"table:has(caption)",
) as NodeListOf<HTMLTableElement>;
const tableWithCaptionArray: NodeListOf<HTMLTableElement> =
doc.querySelectorAll("table:has(caption)");
if (tableWithCaptionArray.length > 0) {
tableWithCaptionArray.forEach((table) => {
const resultName = getElementText(table.caption as Element);
Expand Down
2 changes: 1 addition & 1 deletion containers/ecr-viewer/src/app/services/labsService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ export const evaluateDiagnosticReportData = (
columnName: "Test Method",
infoPath: "observationDeviceReference",
applyToValue: (ref) => {
const device = evaluateReference(fhirBundle, mappings, ref) as Device;
const device: Device = evaluateReference(fhirBundle, mappings, ref);
return safeParse(device.deviceName?.[0]?.name ?? "");
},
className: "minw-10 width-20",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ const PatientBanner = ({ bundle, mappings }: PatientBannerProps) => {
</span>
<span className="patient-banner-dob">
{bundle && mappings
? formatDate((evaluate(bundle, mappings.patientDOB) as any[])[0]) ||
""
? formatDate(
(evaluate(bundle, mappings.patientDOB) as string[])[0],
) || ""
: ""}
</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ export const returnCareTeamTable = (
(entry.period as any).text = formatStartEndDate(start, end);
}

const practitioner = evaluateReference(
const practitioner: Practitioner = evaluateReference(
bundle,
mappings,
entry?.member?.reference || "",
) as Practitioner;
);
const practitionerNameObj = practitioner.name?.find(
(nameObject) => nameObject.family,
);
Expand Down Expand Up @@ -144,11 +144,11 @@ export const returnImmunizations = (
immunizationsArray.forEach((entry) => {
entry.occurrenceDateTime = formatDateTime(entry.occurrenceDateTime ?? "");

const manufacturer = evaluateReference(
const manufacturer: Organization = evaluateReference(
fhirBundle,
mappings,
entry.manufacturer?.reference || "",
) as Organization;
);
if (manufacturer) {
(entry.manufacturer as any).name = manufacturer.name || "";
}
Expand Down
Loading