Files
hpos-web/src/App.js

121 lines
3.9 KiB
JavaScript
Raw Normal View History

import './App.css';
2023-07-05 07:12:43 +05:30
import React, { useEffect, useState } from 'react';
import moment from 'moment';
2023-07-05 07:12:43 +05:30
2023-07-26 15:35:17 +05:30
import { collection, onSnapshot, query } from "firebase/firestore";
2023-07-07 04:51:55 +05:30
import Card from './components/Card';
import db from './firebase';
function App() {
2023-07-07 08:48:14 +05:30
const [totalScreened, setTotalScreened] = useState(0);
2023-07-05 07:12:43 +05:30
const [males, setMales] = useState(0);
2023-07-07 08:48:14 +05:30
const [females, setFemales] = useState(0);
const [normal, setNormal] = useState(0);
2023-07-26 15:35:17 +05:30
// const [positives, setPositives] = useState(0);
2023-07-07 08:48:14 +05:30
const [traits, setTraits] = useState(0);
const [diseases, setDiseases] = useState(0);
const [lastUpdate, setLastUpdate] = useState(moment());
2023-07-21 08:20:39 +05:30
const [devMode, setDevMode] = useState(false);
2023-07-05 07:12:43 +05:30
useEffect(() => {
2023-07-07 08:48:14 +05:30
const q = query(collection(db, "patientData"));
const unsub = onSnapshot(q, (querySnapshot) => {
const patients = [];
let maleCount = 0;
let femaleCount = 0;
querySnapshot.forEach((document) => {
const patient = document.data();
patients.push(patient);
2023-07-07 09:01:35 +05:30
const { gender } = patient;
2023-07-20 17:53:59 +05:30
if (gender?.toLowerCase() === 'male') {
2023-07-07 08:48:14 +05:30
maleCount++;
}
2023-07-20 17:53:59 +05:30
if (gender?.toLowerCase() === 'female') {
2023-07-07 08:48:14 +05:30
femaleCount++;
}
});
setTotalScreened(patients.length);
setMales(maleCount);
setFemales(femaleCount);
setLastUpdate(moment());
2023-07-07 08:48:14 +05:30
});
2023-07-26 15:35:17 +05:30
return () => unsub;
2023-07-07 08:48:14 +05:30
}, []);
useEffect(() => {
const q = query(collection(db, "testData"));
const unsub = onSnapshot(q, (querySnapshot) => {
const hposTests = [];
let normalCount = 0;
2023-07-07 08:48:14 +05:30
let traitCount = 0;
let diseaseCount = 0;
querySnapshot.forEach((document) => {
const hposTestData = document.data();
hposTests.push(hposTestData);
2023-07-07 09:01:35 +05:30
const { result } = hposTestData;
if (result === "NORMAL") {
normalCount++;
}
2023-07-07 09:01:35 +05:30
if (result === 'SICKLECELLTRAIT') {
2023-07-07 08:48:14 +05:30
traitCount++;
}
2023-07-07 09:01:35 +05:30
if (result === 'SICKLECELLDISEASE') {
2023-07-07 08:48:14 +05:30
diseaseCount++;
}
});
setNormal(normalCount);
2023-07-26 15:35:17 +05:30
// setPositives(traitCount + diseaseCount);
2023-07-07 08:48:14 +05:30
setTraits(traitCount);
setDiseases(diseaseCount);
setLastUpdate(moment());
2023-07-07 08:48:14 +05:30
});
2023-07-26 15:35:17 +05:30
return () => unsub;
}, []);
2023-07-05 07:12:43 +05:30
return (
<div>
2023-07-26 15:49:51 +05:30
<div className='dashboard-title'>
2023-07-26 15:35:17 +05:30
<img className="nscm-logo" src={require('./logo_nobg.png')} alt='img' />
2023-07-11 14:30:00 +05:30
<div className='title-text'>HPOS Sickel Cell Test Dashboard</div>
2023-07-26 15:35:17 +05:30
<img className="gov-logo-1" src={require('./gov_logo2.png')} alt='img' />
<img className="gov-logo" src={require('./gov_logo3.png')} alt='img' />
<img className="gov-logo-3" src={require('./gov_logo4.png')} alt='img' />
</div>
2023-07-11 14:30:00 +05:30
2023-07-07 04:51:55 +05:30
<div className='cards-container'>
<div className='cards-row'>
<Card title={"Registration"} counter={totalScreened} color={'black'} backgroundColor={'rgb(254, 240, 227)'} />
2023-07-07 08:48:14 +05:30
<Card title={"Male"} counter={males} backgroundColor={'rgb(234, 240, 230)'} />
<Card title={"Female"} counter={females} backgroundColor={'rgb(234, 246, 245)'} />
2023-07-07 04:51:55 +05:30
</div>
<div className='cards-row'>
<Card title={"Normal"} counter={normal} backgroundColor={'rgb(192,233, 199)'} />
2023-07-07 08:48:14 +05:30
<Card title={"Trait"} counter={traits} backgroundColor={'rgb(237, 190, 190)'} />
<Card title={"Disease"} counter={diseases} backgroundColor={'rgb(249, 195, 195)'} />
2023-07-07 04:51:55 +05:30
</div>
2023-07-20 19:29:37 +05:30
</div>
2023-07-20 19:29:37 +05:30
<div className='footer'>
2023-07-26 15:35:17 +05:30
<div className='last-update'>
Updated at: {moment(lastUpdate).format("DD-MM-YYYY hh:mm:ss a")}
</div>
2023-07-11 14:30:00 +05:30
2023-07-26 15:35:17 +05:30
<div className='developer' onClick={() => setDevMode(!devMode)}>
Developed by <img className="dev-logo" alt='img' src={require('./smi-logo-120x120.webp')} /> ShanMukha
</div>
2023-07-21 08:20:39 +05:30
2023-07-26 15:35:17 +05:30
{/* {devMode &&
2023-07-21 08:20:39 +05:30
<div>dev mode is on</div>} */}
2023-07-26 15:35:17 +05:30
</div>
</div>
);
}
export default App;