Skip to content

Commit

Permalink
Merge pull request #2290 from metriport/develop
Browse files Browse the repository at this point in the history
RELEASE - 1040 - Clinically Relevant MR
  • Loading branch information
Orta21 committed Jun 18, 2024
2 parents d38cf85 + 9a7748c commit 546a3ad
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions packages/core/src/external/aws/lambda-logic/bundle-to-html-adhd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const MEDICARE_CODE = "medicare";
const CPT_CODE = "cpt";

export const bundleToHtmlADHD = (fhirBundle: Bundle): string => {
const fhirTypes = extractFhirTypesFromBundle(fhirBundle);

const {
patient,
practitioners,
Expand All @@ -55,7 +57,24 @@ export const bundleToHtmlADHD = (fhirBundle: Bundle): string => {
tasks,
coverages,
organizations,
} = extractFhirTypesFromBundle(fhirBundle);
} = fhirTypes;

const isClinicallyRelevant = hasClinicalRelevantData(fhirTypes);

if (!isClinicallyRelevant) {
return `
<!DOCTYPE html>
<html>
<head>
<title>Medical Record Summary</title>
</head>
<body>
<h1>Medical Record Summary</h1>
<p>No clinically relevant data found in the bundle</p>
</body>
</html>
`;
}

if (!patient) {
throw new Error("No patient found in bundle");
Expand Down Expand Up @@ -287,7 +306,7 @@ function formatDateForDisplay(date?: string | undefined): string {
return date ? dayjs(date).format(ISO_DATE) : "";
}

function extractFhirTypesFromBundle(bundle: Bundle): {
type FhirTypes = {
diagnosticReports: DiagnosticReport[];
patient?: Patient | undefined;
practitioners: Practitioner[];
Expand All @@ -308,7 +327,9 @@ function extractFhirTypesFromBundle(bundle: Bundle): {
tasks: Task[];
coverages: Coverage[];
organizations: Organization[];
} {
};

function extractFhirTypesFromBundle(bundle: Bundle): FhirTypes {
let patient: Patient | undefined;
const practitioners: Practitioner[] = [];
const diagnosticReports: DiagnosticReport[] = [];
Expand Down Expand Up @@ -2334,3 +2355,19 @@ function getADHDVisits(conditions: Condition[]) {

return adhdVisits;
}

function hasClinicalRelevantData(fhirTypes: FhirTypes): boolean {
const hasValues: string[] = [];

Object.entries(fhirTypes).forEach(([key, value]) => {
const isNotRelatedPersons = key !== "relatedPersons";
const isNotCoverages = key !== "coverages";
const hasValue = value && Array.isArray(value) && value.length;

if (isNotRelatedPersons && isNotCoverages && hasValue) {
hasValues.push(key);
}
});

return hasValues.length > 0;
}

0 comments on commit 546a3ad

Please sign in to comment.