renamed
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
import { useState } from "react";
|
||||
import patientService from "../../services/patients";
|
||||
|
||||
const EntryForm = (): JSX.Element => {
|
||||
const [description, setDescription] = useState("");
|
||||
const [date, setDate] = useState("");
|
||||
const [specialist, setSpecialist] = useState("");
|
||||
const [healthCheckRating, setHealthCheckRating] = useState("");
|
||||
const [employerName, setEmployerName] = useState<string>("");
|
||||
|
||||
const addEntry = (e: React.SyntheticEvent) => {
|
||||
e.preventDefault();
|
||||
const newEntry = {
|
||||
description,
|
||||
date,
|
||||
specialist,
|
||||
healthCheckRating: Number(healthCheckRating),
|
||||
employerName,
|
||||
type: "HealthCheck" as const,
|
||||
};
|
||||
|
||||
patientService.createEntry(newEntry);
|
||||
|
||||
setDescription("");
|
||||
setDate("");
|
||||
setSpecialist("");
|
||||
setHealthCheckRating("");
|
||||
setEmployerName("");
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div>New HealthCheck entry</div>
|
||||
<form onSubmit={addEntry}>
|
||||
<label>
|
||||
Description
|
||||
<input
|
||||
type="text"
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Date
|
||||
<input
|
||||
type="text"
|
||||
value={date}
|
||||
onChange={(e) => setDate(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Specialist
|
||||
<input
|
||||
type="text"
|
||||
value={specialist}
|
||||
onChange={(e) => setSpecialist(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
HealthCheck rating
|
||||
<input
|
||||
type="text"
|
||||
value={healthCheckRating}
|
||||
onChange={(e) => setHealthCheckRating(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Employer name
|
||||
<input
|
||||
type="text"
|
||||
value={employerName}
|
||||
onChange={(e) => setEmployerName(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<button>Add</button>
|
||||
</form>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default EntryForm;
|
||||
@@ -0,0 +1,19 @@
|
||||
import { HealthCheck } from "../../types";
|
||||
|
||||
interface HealthCheckProps {
|
||||
entry: HealthCheck;
|
||||
}
|
||||
const HealthCheckEntry = ({ entry }: HealthCheckProps): JSX.Element => {
|
||||
return (
|
||||
<li>
|
||||
<div>date: {entry.date}</div>
|
||||
<div>description: {entry.description}</div>
|
||||
<div>specialist: {entry.specialist}</div>
|
||||
{"employerName" in entry ? (
|
||||
<div>employer name: {entry.employerName}</div>
|
||||
) : null}
|
||||
<div>health check rating: {entry.healthCheckRating}</div>
|
||||
</li>
|
||||
);
|
||||
};
|
||||
export default HealthCheckEntry;
|
||||
@@ -0,0 +1,31 @@
|
||||
import { Diagnosis, HospitalEntry } from "../../types";
|
||||
|
||||
interface HospitalEntryProps {
|
||||
entry: HospitalEntry;
|
||||
diagnoses: Diagnosis[];
|
||||
}
|
||||
const HospitalEntryElement = ({ entry, diagnoses }: HospitalEntryProps): JSX.Element => {
|
||||
return (
|
||||
<li>
|
||||
<div>date: {entry.date}</div>
|
||||
<div>description: {entry.description}</div>
|
||||
<div>specialist: {entry.specialist}</div>
|
||||
<div>
|
||||
discharge
|
||||
<div>date {entry.discharge.date}</div>
|
||||
<div>criteria {entry.discharge.criteria}</div>
|
||||
</div>
|
||||
{"diagnosisCodes" in entry ? (
|
||||
<ul>
|
||||
{entry.diagnosisCodes?.map((diagnosis, inx) => (
|
||||
<li key={inx}>
|
||||
{diagnosis}:
|
||||
{diagnoses.find((el) => el.code === diagnosis)?.name}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : null}
|
||||
</li>
|
||||
);
|
||||
};
|
||||
export default HospitalEntryElement;
|
||||
@@ -0,0 +1,36 @@
|
||||
import { Diagnosis, OccupationalHealthcareEntry } from "../../types";
|
||||
|
||||
interface OccupationalEntryProps {
|
||||
entry: OccupationalHealthcareEntry;
|
||||
diagnoses: Diagnosis[];
|
||||
}
|
||||
const OccupationalEntry = ({
|
||||
entry,
|
||||
diagnoses,
|
||||
}: OccupationalEntryProps): JSX.Element => {
|
||||
return (
|
||||
<li >
|
||||
<div>date: {entry.date}</div>
|
||||
<div>description: {entry.description}</div>
|
||||
<div>specialist: {entry.specialist}</div>
|
||||
<div>employerName: {entry.employerName}</div>
|
||||
{"sickLeave" in entry ? (
|
||||
<>
|
||||
<div>sick leave</div>
|
||||
<div>start date:{entry.sickLeave?.startDate}</div>
|
||||
<div>end date:{entry.sickLeave?.endDate}</div>
|
||||
</>
|
||||
) : null}
|
||||
{"diagnosisCodes" in entry ? (
|
||||
<ul>
|
||||
{entry.diagnosisCodes?.map((diagnosis, inx) => (
|
||||
<li key={inx}>
|
||||
{diagnosis}:{diagnoses.find((el) => el.code === diagnosis)?.name}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : null}
|
||||
</li>
|
||||
);
|
||||
};
|
||||
export default OccupationalEntry;
|
||||
@@ -0,0 +1,61 @@
|
||||
import { useParams } from "react-router-dom";
|
||||
import { Diagnosis, Patient } from "../../types";
|
||||
import HospitalEntry from "./HospitalEntry";
|
||||
import OccupationalEntry from "./OccupationalEntry";
|
||||
import HealthCheckEntry from "./HealthCheck";
|
||||
import EntryForm from "./EntryForm";
|
||||
|
||||
interface SinglePatientProps {
|
||||
patients: Patient[];
|
||||
diagnoses: Diagnosis[];
|
||||
}
|
||||
const SinglePatient = ({
|
||||
patients,
|
||||
diagnoses,
|
||||
}: SinglePatientProps): JSX.Element => {
|
||||
const { id } = useParams();
|
||||
const patient = patients.find((el) => el.id === id);
|
||||
if (!patient) return <></>;
|
||||
return (
|
||||
<>
|
||||
<h3>{patient.name}</h3>
|
||||
<div>gender: {patient.gender}</div>
|
||||
{patient.ssn ? <div>ssn: {patient.ssn}</div> : null}
|
||||
{patient.dateOfBirth ? (
|
||||
<div>date of birth: {patient.dateOfBirth}</div>
|
||||
) : null}
|
||||
<div>ocupation: {patient.occupation}</div>
|
||||
<EntryForm />
|
||||
<div>entries</div>
|
||||
<ul>
|
||||
{patient.entries.map((entry) => {
|
||||
switch (entry.type) {
|
||||
case "Hospital":
|
||||
return (
|
||||
<HospitalEntry
|
||||
entry={entry}
|
||||
diagnoses={diagnoses}
|
||||
key={entry.id}
|
||||
/>
|
||||
);
|
||||
case "OccupationalHealthcare":
|
||||
return (
|
||||
<OccupationalEntry
|
||||
entry={entry}
|
||||
diagnoses={diagnoses}
|
||||
key={entry.id}
|
||||
/>
|
||||
);
|
||||
case "HealthCheck":
|
||||
return <HealthCheckEntry entry={entry} key={entry.id} />;
|
||||
default:
|
||||
const _exhaustiveCheck: never = entry;
|
||||
return _exhaustiveCheck;
|
||||
}
|
||||
})}
|
||||
</ul>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default SinglePatient;
|
||||
Reference in New Issue
Block a user