Skip to content

Commit

Permalink
fix date of birth responsiveness and age not shown in death report (o…
Browse files Browse the repository at this point in the history
…hcnetwork#7539)

* fix date of birth responsiveness

* fixes death report age

* fix cypress test

---------

Co-authored-by: Mohammed Nihal <[email protected]>
  • Loading branch information
rithviknishad and nihal467 authored Apr 4, 2024
1 parent ba73426 commit a87a39b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cypress/pageobject/Patient/PatientCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class PatientPage {
}

typePatientDateOfBirth(dateOfBirth: string) {
cy.clickAndSelectOption("#patientAge", "D.O.B");
cy.clickAndSelectOption("#patientAge", "DOB");
cy.get("#date_of_birth").scrollIntoView();
cy.get("#date_of_birth").should("be.visible").click();
cy.get("#date-input").click().type(dateOfBirth);
Expand Down
3 changes: 2 additions & 1 deletion src/Components/DeathReport/DeathReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import TextFormField from "../Form/FormFields/TextFormField";
import TextAreaFormField from "../Form/FormFields/TextAreaFormField";
import DateFormField from "../Form/FormFields/DateFormField";
import PhoneNumberFormField from "../Form/FormFields/PhoneNumberFormField";
import { formatDateTime } from "../../Utils/utils";
import { formatDateTime, patientAgeInYears } from "../../Utils/utils";
import Page from "../Common/components/Page";
import Form from "../Form/Form";
import { useTranslation } from "react-i18next";
Expand Down Expand Up @@ -106,6 +106,7 @@ export default function PrintDeathReport(props: { id: string }) {
const patientComorbidities = getPatientComorbidities(res.data);
const data = {
...res.data,
age: patientAgeInYears(res.data!),
gender: patientGender,
address: patientAddress,
comorbidities: patientComorbidities,
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Form/SelectMenuV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const SelectMenuV2 = <T, V>(props: SelectMenuProps<T, V>) => {
{value.icon}
</div>
)}
<p className="ml-2.5 break-all text-sm font-medium">
<p className="ml-2.5 whitespace-nowrap break-all text-sm font-medium">
{value.selectedLabel}
</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Patient/PatientRegister.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,7 @@ export const PatientRegister = (props: PatientRegisterProps) => {
[
{
value: "date_of_birth",
text: "D.O.B.",
text: "DOB",
},
{ value: "age", text: "Age" },
] as const
Expand Down
14 changes: 14 additions & 0 deletions src/Utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,20 @@ const getRelativeDateSuffix = (abbreviated: boolean) => {
};
};

export const patientAgeInYears = (obj: PatientModel) => {
const start = dayjs(
obj.date_of_birth
? new Date(obj.date_of_birth)
: new Date(obj.year_of_birth!, 0, 1)
);

const end = dayjs(
obj.death_datetime ? new Date(obj.death_datetime) : new Date()
);

return end.diff(start, "years");
};

export const formatPatientAge = (obj: PatientModel, abbreviated = false) => {
const suffixes = getRelativeDateSuffix(abbreviated);

Expand Down

0 comments on commit a87a39b

Please sign in to comment.