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

RELEASE - 1040 - Clinically Relevant MR #2290

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Changes from 1 commit
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
Next Next commit
fix(api): has clinical data
Ref. #1040

Signed-off-by: Jorge Orta <[email protected]>
  • Loading branch information
Orta21 committed Jun 18, 2024
commit d9a063138e0ea1f63dbef428bcb2659de987287e
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;
}
Loading