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

added validation for ocr data #125

Merged
merged 2 commits into from
Apr 19, 2024
Merged
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
30 changes: 22 additions & 8 deletions src/cron/automatedDailyRounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import axios, { AxiosError, AxiosResponse } from "axios";
import fs from "fs";
import path from "path";



import { staticObservations } from "@/controller/ObservationController";
import prisma from "@/lib/prisma";
import { AssetBed } from "@/types/asset";
import { CameraParams } from "@/types/camera";
import { CarePaginatedResponse } from "@/types/care";
import {
DailyRoundObservation,
Observation,
ObservationType,
} from "@/types/observation";
import { DailyRoundObservation, Observation, ObservationType } from "@/types/observation";
import { OCRV2Response } from "@/types/ocr";
import { CameraUtils } from "@/utils/CameraUtils";
import { isValid } from "@/utils/ObservationUtils";
Expand All @@ -21,6 +19,7 @@ import { getPatientId } from "@/utils/dailyRoundUtils";
import { downloadImage } from "@/utils/downloadImageWithDigestRouter";
import { parseVitalsFromImage } from "@/utils/ocr";


const UPDATE_INTERVAL = 60 * 60 * 1000;

export async function getMonitorPreset(bedId: string, assetId: string) {
Expand Down Expand Up @@ -92,7 +91,8 @@ export async function getVitalsFromImage(imageUrl: string) {
date.toString() !== "Invalid Date"
? date.toISOString()
: new Date().toISOString();
return {

const payload = {
taken_at: isoDate,
spo2: data.spO2?.oxygen_saturation_percentage ?? null,
ventilator_spo2: data.spO2?.oxygen_saturation_percentage ?? null,
Expand All @@ -107,6 +107,20 @@ export async function getVitalsFromImage(imageUrl: string) {
rounds_type: "AUTOMATED",
is_parsed_by_ocr: true,
} as DailyRoundObservation;

if (
payload.temperature &&
!(payload.temperature >= 95 && payload.temperature <= 106)
) {
payload.temperature = null;
payload.temperature_measured_at = null;
}

if (!payload.bp?.systolic || !payload.bp?.diastolic) {
payload.bp = {};
}

return payload;
}

export async function fileAutomatedDailyRound(
Expand Down Expand Up @@ -223,7 +237,7 @@ export async function getVitalsFromObservations(assetHostname: string) {
temperature: number;
temperature_mesured_at: string;
} | null) ?? { temperature: null, temperature_measured_at: null }),
bp: getValueFromData("blood-pressure", data) ?? { },
bp: getValueFromData("blood-pressure", data) ?? {},
rounds_type: "AUTOMATED",
is_parsed_by_ocr: false,
} as DailyRoundObservation;
Expand Down Expand Up @@ -327,4 +341,4 @@ export async function automatedDailyRounds() {
await fileAutomatedDailyRound(consultation_id, monitor.externalId, vitals);
console.log(`Daily round filed for the patient ${patient_id}`);
});
}
}
1 change: 1 addition & 0 deletions src/types/observation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export interface DailyRoundObservation {
bp?: {
systolic?: number | null;
diastolic?: number | null;
mean?: number | null;
};
taken_at?: string | Date | null;
rounds_type?: "AUTOMATED";
Expand Down
Loading