From d1ff0265315e65f2429f802e3ace04c487480ab8 Mon Sep 17 00:00:00 2001 From: Josh Nygaard Date: Thu, 12 Dec 2024 10:02:56 -0500 Subject: [PATCH] Prefer annotating types over asserting --- .../ecr-viewer/src/app/services/ecrMetadataService.ts | 6 +++--- .../src/app/services/evaluateFhirDataService.ts | 10 +++++----- .../ecr-viewer/src/app/services/formatService.tsx | 5 ++--- containers/ecr-viewer/src/app/services/labsService.tsx | 2 +- .../src/app/view-data/components/PatientBanner.tsx | 5 +++-- .../ecr-viewer/src/app/view-data/components/common.tsx | 8 ++++---- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/containers/ecr-viewer/src/app/services/ecrMetadataService.ts b/containers/ecr-viewer/src/app/services/ecrMetadataService.ts index 96cc185a1a..f27b15691d 100644 --- a/containers/ecr-viewer/src/app/services/ecrMetadataService.ts +++ b/containers/ecr-viewer/src/app/services/ecrMetadataService.ts @@ -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 = {}; @@ -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]; diff --git a/containers/ecr-viewer/src/app/services/evaluateFhirDataService.ts b/containers/ecr-viewer/src/app/services/evaluateFhirDataService.ts index 876646b4e6..dedf6dba19 100644 --- a/containers/ecr-viewer/src/app/services/evaluateFhirDataService.ts +++ b/containers/ecr-viewer/src/app/services/evaluateFhirDataService.ts @@ -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; @@ -655,7 +655,7 @@ 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)) { @@ -663,11 +663,11 @@ export const evaluateValue = (entry: Element, path: string | Path): string => { } 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__}`); diff --git a/containers/ecr-viewer/src/app/services/formatService.tsx b/containers/ecr-viewer/src/app/services/formatService.tsx index d9d8235fbc..f359f36beb 100644 --- a/containers/ecr-viewer/src/app/services/formatService.tsx +++ b/containers/ecr-viewer/src/app/services/formatService.tsx @@ -384,9 +384,8 @@ export function formatTablesToJSON(htmlString: string): TableJson[] { } //
{name}
- const tableWithCaptionArray = doc.querySelectorAll( - "table:has(caption)", - ) as NodeListOf; + const tableWithCaptionArray: NodeListOf = + doc.querySelectorAll("table:has(caption)"); if (tableWithCaptionArray.length > 0) { tableWithCaptionArray.forEach((table) => { const resultName = getElementText(table.caption as Element); diff --git a/containers/ecr-viewer/src/app/services/labsService.tsx b/containers/ecr-viewer/src/app/services/labsService.tsx index b9e07dd284..8a2562f981 100644 --- a/containers/ecr-viewer/src/app/services/labsService.tsx +++ b/containers/ecr-viewer/src/app/services/labsService.tsx @@ -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", diff --git a/containers/ecr-viewer/src/app/view-data/components/PatientBanner.tsx b/containers/ecr-viewer/src/app/view-data/components/PatientBanner.tsx index e8abf455b4..ea7a923b9c 100644 --- a/containers/ecr-viewer/src/app/view-data/components/PatientBanner.tsx +++ b/containers/ecr-viewer/src/app/view-data/components/PatientBanner.tsx @@ -25,8 +25,9 @@ const PatientBanner = ({ bundle, mappings }: PatientBannerProps) => { {bundle && mappings - ? formatDate((evaluate(bundle, mappings.patientDOB) as any[])[0]) || - "" + ? formatDate( + (evaluate(bundle, mappings.patientDOB) as string[])[0], + ) || "" : ""} diff --git a/containers/ecr-viewer/src/app/view-data/components/common.tsx b/containers/ecr-viewer/src/app/view-data/components/common.tsx index 68b632b57f..1c3f43229d 100644 --- a/containers/ecr-viewer/src/app/view-data/components/common.tsx +++ b/containers/ecr-viewer/src/app/view-data/components/common.tsx @@ -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, ); @@ -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 || ""; }