Skip to content

Commit

Permalink
Merge pull request #83 from coronasafe/ocr
Browse files Browse the repository at this point in the history
Ocr
  • Loading branch information
mathew-alex authored Aug 25, 2023
2 parents 5c013d4 + df409bc commit f85634a
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
CREATE TYPE "AssetType" AS ENUM ('CAMERA', 'MONITOR');

-- AlterTable
ALTER TABLE "Asset" ADD COLUMN "bedId" INTEGER,
ADD COLUMN "password" TEXT,
ALTER TABLE "Asset" ADD COLUMN "password" TEXT,
ADD COLUMN "port" INTEGER DEFAULT 80,
ADD COLUMN "type" "AssetType" NOT NULL DEFAULT 'MONITOR',
ADD COLUMN "username" TEXT;
Expand All @@ -13,6 +12,7 @@ CREATE TABLE "Bed" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"externalId" TEXT NOT NULL,
"cameraId" INTEGER NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"deleted" BOOLEAN NOT NULL DEFAULT false,
Expand All @@ -38,7 +38,7 @@ CREATE UNIQUE INDEX "Bed_externalId_key" ON "Bed"("externalId");
CREATE UNIQUE INDEX "Preset_bedId_key" ON "Preset"("bedId");

-- AddForeignKey
ALTER TABLE "Asset" ADD CONSTRAINT "Asset_bedId_fkey" FOREIGN KEY ("bedId") REFERENCES "Bed"("id") ON DELETE SET NULL ON UPDATE CASCADE;
ALTER TABLE "Bed" ADD CONSTRAINT "Bed_cameraId_fkey" FOREIGN KEY ("cameraId") REFERENCES "Asset"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Preset" ADD CONSTRAINT "Preset_bedId_fkey" FOREIGN KEY ("bedId") REFERENCES "Bed"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
6 changes: 3 additions & 3 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ model Asset {
password String?
port Int? @default(80)
DailyRound DailyRound[]
Bed Bed? @relation(fields: [bedId], references: [id])
bedId Int?
Bed Bed[]
@@index([externalId, ipAddress])
}
Expand All @@ -40,7 +39,8 @@ model Bed {
name String
externalId String @unique
monitorPreset Preset?
assets Asset[]
camera Asset @relation(fields: [cameraId], references: [id])
cameraId Int
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
deleted Boolean @default(false)
Expand Down
42 changes: 33 additions & 9 deletions src/controller/BedController.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,50 @@ export class BedController {
},
include: {
monitorPreset: true,
camera: true,
},
orderBy: [{ updatedAt: "desc" }],
});

const cameras = await prisma.asset.findMany({
where: {
deleted: false,
type: "CAMERA",
},
orderBy: [{ updatedAt: "desc" }],
});

res.render("pages/beds/list", {
dayjs,
beds,
cameras,
errors: req.flash("error"),
});
} catch (err) {
res.render("pages/beds/list", {
dayjs,
beds: [],
cameras: [],
errors: [err.message],
});
}
};

static create = async (req, res) => {
const { name, externalId, preset_x, preset_y, preset_zoom } = req.body;
const { name, externalId, cameraId, preset_x, preset_y, preset_zoom } =
req.body;

console.log(preset_x, preset_y, preset_zoom);
try {
await prisma.bed.create({
data: {
name,
externalId,
cameraId: Number(cameraId) || undefined,
monitorPreset: {
create: {
x: Number(preset_x),
y: Number(preset_y),
zoom: Number(preset_zoom),
x: Number(preset_x) || undefined,
y: Number(preset_y) || undefined,
zoom: Number(preset_zoom) || undefined,
},
},
},
Expand All @@ -66,12 +78,22 @@ export class BedController {
},
include: {
monitorPreset: true,
camera: true,
},
});

const cameras = await prisma.asset.findMany({
where: {
deleted: false,
type: "CAMERA",
},
orderBy: [{ updatedAt: "desc" }],
});

res.render("pages/beds/edit", {
dayjs,
bed,
cameras,
errors: req.flash("error"),
});
} catch (err) {
Expand All @@ -82,7 +104,8 @@ export class BedController {

static edit = async (req, res) => {
const { id } = req.params;
const { name, externalId, preset_x, preset_y, preset_zoom } = req.body;
const { name, externalId, cameraId, preset_x, preset_y, preset_zoom } =
req.body;

try {
await prisma.bed.update({
Expand All @@ -92,11 +115,12 @@ export class BedController {
data: {
name,
externalId,
cameraId: Number(cameraId) || undefined,
monitorPreset: {
update: {
x: Number(preset_x),
y: Number(preset_y),
zoom: Number(preset_zoom),
x: Number(preset_x) || undefined,
y: Number(preset_y) || undefined,
zoom: Number(preset_zoom) || undefined,
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/controller/ObservationController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
getAsset,
getCameraByBedId,
getBedById,
getPatientId,
} from "../utils/dailyRoundUtils.js";

Expand Down Expand Up @@ -290,7 +290,7 @@ const updateObservationsToCare = async () => {
payload.rounds_type = "AUTOMATED";

try {
const camera = await getCameraByBedId(bed_id);
const { camera } = await getBedById(bed_id);

const cameraParams = {
hostname: camera.ipAddress,
Expand Down
11 changes: 5 additions & 6 deletions src/utils/dailyRoundUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ export const getPatientId = async (assetExternalId) => {
// };


export const getCameraByBedId = async (bedId) => {
return prisma.asset.findFirst({
export const getBedById = async (bedId) => {
return prisma.bed.findFirst({
where: {
bedId,
assetType: "CAMERA",
id: bedId,
deleted: false,
},
include: {
Bed: true,
camera: true,
},
})
});
};
9 changes: 0 additions & 9 deletions src/views/pages/assetForm.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,6 @@
<label for="ipAddress">Port</label>
<input class="px-2 py-1 border-2 border-black" type="number" placeholder="127.0.0.1" name="port" id="port" value="<%- asset.port %>" />
</div>
<div class="flex flex-col mt-2">
<label for="name">Bed</label>
<select class="p-2 border-2 border-black" name="type" id="type">
<option value="" disabled selected hidden>Select a Bed</option>
<% beds.forEach(function(bed){ %>
<option class="truncate" selected="<%= asset.bedId === bed.id %>" value="<%= bed.externalId %>"><%= bed.name + " -- " + bed.externalId.slice(0, 10) %></option>
<% }) %>
</select>
</div>
<div class="flex flex-col mt-2">
<input class="px-4 py-2 hover:bg-green-700 bg-green-500" type="submit" value="Save" />
</div>
Expand Down
7 changes: 1 addition & 6 deletions src/views/pages/assetList.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@
<input class="p-2 border-2 border-black" type="text" placeholder="remote-user" name="username" id="username" value="" />
<input class="p-2 border-2 border-black" type="password" placeholder="password" name="password" id="password" value="" />
<input class="p-2 border-2 border-black" type="number" placeholder="80" name="port" id="port" value="" />
<select class="p-2 border-2 border-black" name="bedId" id="bedId" placeholder="Bed">
<option value="" disabled selected hidden>Select a Bed</option>
<% beds.forEach(function(bed){ %>
<option class="truncate" value="<%= bed.externalId %>"><%= bed.name + " -- " + bed.externalId.slice(0, 10) %></option>
<% }) %>
</select>

<input class="px-4 py-2 hover:bg-green-700 bg-green-500" type="submit" value="Add " />
</div>
</form>
Expand Down
9 changes: 9 additions & 0 deletions src/views/pages/beds/edit.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
<label for="externalId">External ID</label>
<input class="px-2 py-1 border-2 border-black" type="text" placeholder="UUID" name="externalId" id="externalId" value="<%- bed.externalId %>" />
</div>
<div class="flex flex-col mt-2">
<label for="name">Camera</label>
<select class="p-2 border-2 border-black" name="cameraId" id="cameraId">
<option value="" disabled selected hidden>Select a Camera</option>
<% cameras.forEach(function(camera){ %>
<option class="truncate" selected="<%= camera.cameraId === camera.id %>" value="<%= camera.id %>"><%= camera.name %></option>
<% }) %>
</select>
</div>

<h2 class="my-3 py-3 text-2xl border-b">Update Monitor Preset<h2>
<div class="flex flex-col mt-2">
Expand Down
8 changes: 8 additions & 0 deletions src/views/pages/beds/list.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
<div class="flex flex-wrap items-center my-4 gap-4">
<input class="p-2 border-2 border-black" type="text" placeholder="Name" name="name" id="name" value="" />
<input class="p-2 border-2 border-black" type="text" placeholder="UUID" name="externalId" id="externalId" value="" />
<select class="p-2 border-2 border-black" name="cameraId" id="cameraId" placeholder="Camera">
<option value="" disabled selected>Select a Camera</option>
<% cameras.forEach(function(camera){ %>
<option class="truncate" value="<%= camera.id %>"><%= camera.name %></option>
<% }) %>
</select>

<div class="w-full flex flex-wrap items-center my-4 gap-4">
<h3>Add Monitor Preset</h3>
Expand All @@ -44,6 +50,7 @@
<th>ID</th>
<th>Name</th>
<th>External ID</th>
<th>Camera</th>
<th>Monitor Preset</th>
<th>Updated At</th>
<th>Actions</th>
Expand All @@ -53,6 +60,7 @@
<td class="w-fit"><%= bed.id %></td>
<td class="w-fit"><%= bed.name %></td>
<td class="w-fit"><%= bed.externalId %></td>
<td class="w-fit"><%= bed.camera?.name ?? "No Camera Linked" %></td>
<% if (bed.monitorPreset) { %>
<td class="w-fit"><%= bed.monitorPreset.x %>, <%= bed.monitorPreset.y %>, <%= bed.monitorPreset.zoom %></td>
<% } else { %>
Expand Down

0 comments on commit f85634a

Please sign in to comment.