From cb1758fb557bf3de877e9cb7f6cda8a264ea74b4 Mon Sep 17 00:00:00 2001 From: Matt DiMeglio Date: Mon, 11 Aug 2025 15:34:16 -0400 Subject: [PATCH] Changes for new DB --- app/call.jsx | 6 +- app/incidents.jsx | 89 ++++++++++++------------- hooks/useCallFeed/useCallFeed.jsx | 30 +++++---- hooks/useDepartments/useDepartments.jsx | 24 ++++++- 4 files changed, 86 insertions(+), 63 deletions(-) diff --git a/app/call.jsx b/app/call.jsx index 1e92c87..ff695a4 100644 --- a/app/call.jsx +++ b/app/call.jsx @@ -1,8 +1,8 @@ -import React, { useState, useRef, useEffect } from 'react'; +import React, { useRef } from 'react'; import styled from 'styled-components'; import { useCallFeed } from '../hooks/useCallFeed'; import { Platform, Linking, View, ScrollView, Text, TouchableOpacity } from 'react-native'; -import { useLocalSearchParams, router } from 'expo-router'; +import { useLocalSearchParams } from 'expo-router'; import { StatusBar } from 'expo-status-bar'; import { SafeAreaView } from 'react-native-safe-area-context'; import { Ionicons } from '@expo/vector-icons'; @@ -11,7 +11,7 @@ import { Phone } from "healthicons-react-native/dist/filled"; import { PageHeader, PageFooter, -} from '../components/generalHelpers.jsx'; +} from '@/components/generalHelpers.jsx'; import ActionSheet from 'react-native-actions-sheet'; const DepartmentActionSheet = styled(ActionSheet)``; diff --git a/app/incidents.jsx b/app/incidents.jsx index b8eb1e5..579a2bb 100644 --- a/app/incidents.jsx +++ b/app/incidents.jsx @@ -28,13 +28,13 @@ export default function Incidents() { formatCallDateTime } = callFeed; - const sortedAndFilteredCalls = callDetails - .sort((a, b) => new Date(b.timestamp) - new Date(a.timestamp)) + const sortedAndFilteredCalls = callDetails.sort((a, b) => new Date(b.timestamp) - new Date(a.timestamp)) .filter((item, index, self) => { return index === self.findIndex(i => { - return `${i?.data?.Incident?.IncID}${i?.data?.Response?.ServiceName}` === `${item?.data?.Incident?.IncID}${item?.data?.Response?.ServiceName}` + return `${i?.incident?.incID}${i?.response?.serviceName}` === `${item?.incident?.incID}${item?.response?.serviceName}` }); - }); + })?.map(item => { return {...item, timestamp: item?.incident?.incDate} }) + || []; const { departmentTypeMap, @@ -93,31 +93,30 @@ export default function Incidents() { {sortedAndFilteredCalls?.length ? ( sortedAndFilteredCalls?.map((callItem, index) => { - const { data: call, timestamp } = callItem; - const { Incident, Address, Response } = call; + const { incident, address, response, timestamp } = callItem; const { - ServiceNumber, - IncDate, - IncNature, - IncNatureCode, - IncNatureCodeDesc, - Status, - } = Incident; + serviceNumber, + incDate, + incNature, + incNatureCode, + incNatureCodeDesc, + status, + } = incident; const { - StreetAddress, - AddressApartment, - Town, - State, - LocationName, - } = Address; + streetAddress, + addressApartment, + town, + state, + locationName, + } = address; const { - ServiceName - } = Response; - const SelectedIcon = callIconMap[IncNature] || AccidentAndEmergency; + serviceName + } = response; + const SelectedIcon = callIconMap[incNature] || AccidentAndEmergency; return ( { router.push({ pathname: '/call', @@ -134,9 +133,9 @@ export default function Incidents() { backgroundColor: '#fff', shadowOffset: { width: 0, height: 0 }, shadowColor: callColorSelector( - IncNatureCode, - IncNature, - Status + incNatureCodeDesc, + incNature, + status ), shadowOpacity: 1, shadowRadius: 5, @@ -151,10 +150,10 @@ export default function Incidents() { justifyContent: 'space-between' }} > - {formatCallDateTime(IncDate)} + {formatCallDateTime(incDate)} - {formatCallTimePast(IncDate)} - {Status === 'CLOSED' ? ( + {formatCallTimePast(incDate)} + {status === 'CLOSED' ? ( - {LocationName ? ( + {locationName ? ( - {`${LocationName}`} + {`${locationName}`} ) : ( @@ -199,9 +198,9 @@ export default function Incidents() { fontWeight: 600 }]} > - {`${StreetAddress}`} + {`${streetAddress?.split(',')[0]}`} - {AddressApartment ? ( + {addressApartment ? ( - {` - ${AddressApartment}`} + {` - ${addressApartment}`} ) : null} - {` ${Town}, ${State}`} + {` ${town}, ${state}`} )} @@ -230,7 +229,7 @@ export default function Incidents() { fontSize: 16 }} > - {`${IncNature}`} + {`${incNature}`} - {`${IncNatureCodeDesc}`} + {`${incNatureCodeDesc}`} @@ -261,7 +260,7 @@ export default function Incidents() { fontSize: 12, }} > - Service: {ServiceName} + Service: {serviceName} - {`Incident #: ${ServiceNumber}`} + {`Incident #: ${serviceNumber}`} diff --git a/hooks/useCallFeed/useCallFeed.jsx b/hooks/useCallFeed/useCallFeed.jsx index bd93a3e..1560344 100644 --- a/hooks/useCallFeed/useCallFeed.jsx +++ b/hooks/useCallFeed/useCallFeed.jsx @@ -86,16 +86,16 @@ const formatCallDateTime = (callValue) => { const getIncidents = async (departments, incidentStatus) => { let response; try { - response = await fetch(`${process.env.EXPO_PUBLIC_DATABASE_URL}/api/getRecentCalls`, { + response = await fetch(`${process.env.EXPO_PUBLIC_DATABASE_URL}/getRecentCalls/${5}`, { method: "GET", headers: { - "Content-Type": "application/json", apiKey: process.env.EXPO_PUBLIC_DATABASE_API_KEY }, - body: JSON.stringify({ - departments, - status: incidentStatus, - }), + // body: JSON.stringify({ + // callCount: 25, + // departments, + // status: incidentStatus, + // }), }); } catch (e) { console.error("Failed to fetch initial calls:", e); @@ -114,9 +114,12 @@ export const useCallFeed = () => { const [selectedStatus, setSelectedStatus] = useState({id: 'all', value: 'All Incidents'}); useEffect(() => { - const incidents = getIncidents(InitList?.map((dept) => { return dept?.id }), selectedStatus?.id); - setAllCalls(incidents); - setInit(false); + async function fetchData() { + const incidents = await getIncidents(InitList?.map((dept) => { return dept?.id }), selectedStatus?.id); + setAllCalls(incidents); + setInit(false); + } + fetchData(); }, []); useEffect(() => { @@ -129,14 +132,17 @@ export const useCallFeed = () => { }, [lastMessage]); useEffect(() => { - if (!init) { - const incidents = getIncidents(InitList?.map((dept) => { return dept?.id }), selectedStatus?.id); + async function fetchData() { + const incidents = await getIncidents(InitList?.map((dept) => { return dept?.id }), selectedStatus?.id); setAllCalls(incidents); } + if (!init) { + fetchData(); + } }, [selectedStatus]); const callColorSelector = (callAcuity, cardiacArrestCall, status) => { - if (status === "CLOSED") { + if (status?.toLowerCase() === "closed") { return "#0000CD"; } else if (CriticalCallList.includes(cardiacArrestCall)) { return "#8B0000"; diff --git a/hooks/useDepartments/useDepartments.jsx b/hooks/useDepartments/useDepartments.jsx index e7e0c40..877bff9 100644 --- a/hooks/useDepartments/useDepartments.jsx +++ b/hooks/useDepartments/useDepartments.jsx @@ -12,14 +12,32 @@ const accountDetails = { "CARDIAC ARREST|DEATH", ], "HighCallList": [ - "ALS" + "EMS ALS PRIORITY (ALS)", + "EMS Advanced Life Support life threatening response (ALS)", + "EMS ALS Intercept Required", + "EMS ALS Response – Cardiac Related", + "EMS ALS Response – Respiratory Distress", + "EMS ALS Response – Stroke Alert", + "EMS Basic Life Support with Paramedic Assist (BLS)", + "EMS ALS Tiered Response with Fire", + "EMS Response – Behavioral Emergency (ALS)", + "EMS Response – Obstetric Emergency (ALS)", + "EMS ALS Response – Overdose / Poisoning", + "EMS ALS Priority Interfacility Transfer", + "EMS Response – Unresponsive / Unconscious Patient (ALS)" ], "MediumCallList": [ "ALS-STANDARD", - "BLS-PRIORITY" + "BLS-PRIORITY", + "EMS BLS Priority Response", + "EMS BLS Response – Fall Injury" ], "LowCallList": [ - "BLS-STANDARD" + "EMS Standard Basic Life Support Response (BLS)", + "EMS BLS Non-Emergency Transport", + "EMS BLS Standby – Event Coverage", + "EMS Public Assist – Lift Only (BLS)", + "EMS BLS Scheduled Interfacility Transport" ] }, "InitList": [