feature: Simulator Scenarios + Clinical Validation: SOFA/GCS
This commit is contained in:
@@ -13,8 +13,23 @@ async function request(path, options = {}) {
|
||||
return envelope.data
|
||||
}
|
||||
|
||||
/** Returns null when the resource does not exist yet (HTTP 404 or empty optional payload). */
|
||||
async function requestOptional(path) {
|
||||
const res = await fetch(`${BASE_URL}${path}`, {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
const envelope = await res.json()
|
||||
if (res.status === 404) return null
|
||||
if (!res.ok || !envelope.success) {
|
||||
const msg = envelope.error?.message ?? `API ${res.status}: ${path}`
|
||||
throw new Error(msg)
|
||||
}
|
||||
return envelope.data ?? null
|
||||
}
|
||||
|
||||
export const api = {
|
||||
get: (path) => request(path),
|
||||
getOptional: (path) => requestOptional(path),
|
||||
post: (path, body) => request(path, {
|
||||
method: 'POST',
|
||||
body: body !== undefined ? JSON.stringify(body) : undefined,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { api } from './client'
|
||||
|
||||
export function fetchCurrentNews2(encounterId) {
|
||||
return api.get(`/api/v1/encounters/${encounterId}/news2/current`)
|
||||
return api.getOptional(`/api/v1/encounters/${encounterId}/news2/current`)
|
||||
}
|
||||
|
||||
export function fetchCurrentQsofa(encounterId) {
|
||||
@@ -9,15 +9,15 @@ export function fetchCurrentQsofa(encounterId) {
|
||||
}
|
||||
|
||||
export function fetchCurrentGcs(encounterId) {
|
||||
return api.get(`/api/v1/encounters/${encounterId}/gcs`)
|
||||
return api.getOptional(`/api/v1/encounters/${encounterId}/gcs`)
|
||||
}
|
||||
|
||||
export function fetchCurrentSofa(encounterId) {
|
||||
return api.get(`/api/v1/encounters/${encounterId}/sofa`)
|
||||
return api.getOptional(`/api/v1/encounters/${encounterId}/sofa`)
|
||||
}
|
||||
|
||||
export function fetchSepsisBundle(encounterId) {
|
||||
return api.get(`/api/v1/encounters/${encounterId}/sepsis-bundle/current`)
|
||||
return api.getOptional(`/api/v1/encounters/${encounterId}/sepsis-bundle/current`)
|
||||
}
|
||||
|
||||
export function fetchOrders(encounterId) {
|
||||
|
||||
@@ -68,10 +68,10 @@ export const useScoringStore = defineStore('scoring', () => {
|
||||
const id = encounterId.value
|
||||
try {
|
||||
const [g, s, n, q] = await Promise.all([
|
||||
clinicalApi.fetchCurrentGcs(id).catch(() => null),
|
||||
clinicalApi.fetchCurrentSofa(id).catch(() => null),
|
||||
clinicalApi.fetchCurrentNews2(id).catch(() => null),
|
||||
clinicalApi.fetchCurrentQsofa(id).catch(() => null),
|
||||
clinicalApi.fetchCurrentGcs(id),
|
||||
clinicalApi.fetchCurrentSofa(id),
|
||||
clinicalApi.fetchCurrentNews2(id),
|
||||
clinicalApi.fetchCurrentQsofa(id),
|
||||
])
|
||||
gcs.value = g
|
||||
sofa.value = s
|
||||
@@ -94,6 +94,7 @@ export const useScoringStore = defineStore('scoring', () => {
|
||||
}
|
||||
|
||||
function startPolling(id) {
|
||||
if (encounterId.value === id && timer) return
|
||||
stopPolling()
|
||||
encounterId.value = id
|
||||
refresh()
|
||||
|
||||
@@ -93,7 +93,7 @@ async function loadAll() {
|
||||
encountersApi.fetchObservations(id),
|
||||
clinicalApi.fetchNews2History(id).catch(() => []),
|
||||
clinicalApi.fetchMedications(id).catch(() => []),
|
||||
clinicalApi.fetchSepsisBundle(id).catch(() => null),
|
||||
clinicalApi.fetchSepsisBundle(id),
|
||||
clinicalApi.fetchOrders(id).catch(() => ({ items: [] })),
|
||||
])
|
||||
await alertStore.loadAlerts(id)
|
||||
|
||||
Reference in New Issue
Block a user