Skip to content

Commit

Permalink
Fixed #7610 Toggle Emergency Contact No. From Phone Number (#7644)
Browse files Browse the repository at this point in the history
* Fixed #7610 Toggle  Emergency Contact No. From Phone Number

* lint checks

* Update PatientRegister.tsx

* Update PatientRegister.tsx

* changeRequest done

* change request done

* cyp_update

* cyp_update done

* done

* done

* cyp_done

* add test to check phone number is emergency number

---------

Co-authored-by: Rithvik Nishad <mail@rithviknishad.dev>
Co-authored-by: Mohammed Nihal <57055998+nihal467@users.noreply.github.com>
Co-authored-by: khavinshankar <khavinshankar@gmail.com>
  • Loading branch information
4 people committed May 7, 2024
1 parent c49929c commit 3e2ebab
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 27 deletions.
42 changes: 19 additions & 23 deletions cypress/e2e/patient_spec/patient_registration.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { afterEach, before, beforeEach, cy, describe, it } from "local-cypress";
import LoginPage from "../../pageobject/Login/LoginPage";
import { PatientPage } from "../../pageobject/Patient/PatientCreation";
import FacilityPage from "../../pageobject/Facility/FacilityCreation";
import {
generatePhoneNumber,
generateEmergencyPhoneNumber,
} from "../../pageobject/utils/constants";
import { generatePhoneNumber } from "../../pageobject/utils/constants";
import PatientTransfer from "../../pageobject/Patient/PatientTransfer";
import PatientExternal from "../../pageobject/Patient/PatientExternal";
import PatientInsurance from "../../pageobject/Patient/PatientInsurance";
Expand All @@ -27,7 +24,6 @@ describe("Patient Creation with consultation", () => {
const patientInsurance = new PatientInsurance();
const patientMedicalHistory = new PatientMedicalHistory();
const phone_number = generatePhoneNumber();
const emergency_phone_number = generateEmergencyPhoneNumber();
const age = calculateAge();
const patientFacility = "Dummy Facility 40";
const patientDateOfBirth = "01012001";
Expand Down Expand Up @@ -79,7 +75,7 @@ describe("Patient Creation with consultation", () => {
patientPage.patientformvisibility();
// Patient Details page
patientPage.typePatientPhoneNumber(phone_number);
patientPage.typePatientEmergencyNumber(emergency_phone_number);
patientPage.checkPhoneNumberIsEmergencyNumber();
patientPage.typePatientAge(age.toString());
patientPage.typePatientName(patientOneName);
patientPage.selectPatientGender(patientOneGender);
Expand All @@ -93,7 +89,7 @@ describe("Patient Creation with consultation", () => {
// Patient Medical History
patientMedicalHistory.typePatientPresentHealth(patientOnePresentHealth);
patientMedicalHistory.typePatientOngoingMedication(
patientOneOngoingMedication
patientOneOngoingMedication,
);
patientMedicalHistory.typeMedicalHistory(2, "Diabetes");
patientMedicalHistory.typeMedicalHistory(3, "Heart Disease");
Expand All @@ -115,10 +111,10 @@ describe("Patient Creation with consultation", () => {
age,
patientOneName,
phone_number,
emergency_phone_number,
phone_number,
yearOfBirth,
patientOneBloodGroup,
patientOccupation
patientOccupation,
);
patientMedicalHistory.verifyPatientMedicalDetails(
patientOnePresentHealth,
Expand All @@ -130,7 +126,7 @@ describe("Patient Creation with consultation", () => {
"Kidney Diseases",
"Lung Diseases/Asthma",
"Cancer",
"Other"
"Other",
);
// verify its presence in the patient detail page
cy.visit("/patients");
Expand All @@ -155,43 +151,43 @@ describe("Patient Creation with consultation", () => {
patientInsurance.typePatientInsuranceDetail(
patientOneFirstInsuranceId,
"subscriber_id",
patientOneFirstSubscriberId
patientOneFirstSubscriberId,
);
patientInsurance.typePatientInsuranceDetail(
patientOneFirstInsuranceId,
"policy_id",
patientOneFirstPolicyId
patientOneFirstPolicyId,
);
patientInsurance.typePatientInsuranceDetail(
patientOneFirstInsuranceId,
"insurer_id",
patientOneFirstInsurerId
patientOneFirstInsurerId,
);
patientInsurance.typePatientInsuranceDetail(
patientOneFirstInsuranceId,
"insurer_name",
patientOneFirstInsurerName
patientOneFirstInsurerName,
);
patientInsurance.clickAddInsruanceDetails();
patientInsurance.typePatientInsuranceDetail(
patientOneSecondInsuranceId,
"subscriber_id",
patientOneSecondSubscriberId
patientOneSecondSubscriberId,
);
patientInsurance.typePatientInsuranceDetail(
patientOneSecondInsuranceId,
"policy_id",
patientOneSecondPolicyId
patientOneSecondPolicyId,
);
patientInsurance.typePatientInsuranceDetail(
patientOneSecondInsuranceId,
"insurer_id",
patientOneSecondInsurerId
patientOneSecondInsurerId,
);
patientInsurance.typePatientInsuranceDetail(
patientOneSecondInsuranceId,
"insurer_name",
patientOneSecondInsurerName
patientOneSecondInsurerName,
);
patientPage.clickUpdatePatient();
cy.wait(3000);
Expand All @@ -204,10 +200,10 @@ describe("Patient Creation with consultation", () => {
age,
patientOneName,
phone_number,
emergency_phone_number,
phone_number,
yearOfBirth,
patientOneUpdatedBloodGroup,
patientOccupation
patientOccupation,
);
// Verify No medical history
patientMedicalHistory.verifyNoSymptosPresent("Diabetes");
Expand All @@ -220,21 +216,21 @@ describe("Patient Creation with consultation", () => {
patientOneFirstSubscriberId,
patientOneFirstPolicyId,
patientOneFirstInsurerId,
patientOneFirstInsurerName
patientOneFirstInsurerName,
);
patientInsurance.clickPatientInsuranceViewDetail();
cy.wait(3000);
patientInsurance.verifyPatientPolicyDetails(
patientOneFirstSubscriberId,
patientOneFirstPolicyId,
patientOneFirstInsurerId,
patientOneFirstInsurerName
patientOneFirstInsurerName,
);
patientInsurance.verifyPatientPolicyDetails(
patientOneSecondSubscriberId,
patientOneSecondPolicyId,
patientOneSecondInsurerId,
patientOneSecondInsurerName
patientOneSecondInsurerName,
);
});

Expand Down
12 changes: 8 additions & 4 deletions cypress/pageobject/Patient/PatientCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@ export class PatientPage {
}

typePatientPhoneNumber(phoneNumber: string) {
cy.get("#phone_number-div").click().type(phoneNumber);
cy.get("#phone_number").click().type(phoneNumber);
}

typePatientEmergencyNumber(phoneNumber: string) {
cy.get("#emergency_phone_number-div").click().type(phoneNumber);
cy.get("#emergency_phone_number").click().type(phoneNumber);
}

checkPhoneNumberIsEmergencyNumber() {
cy.get("#emergency_contact_checkbox > div > input").click();
}

typePatientDateOfBirth(dateOfBirth: string) {
Expand Down Expand Up @@ -145,7 +149,7 @@ export class PatientPage {
emergencyPhoneNumber,
yearOfBirth,
bloodGroup,
occupation
occupation,
) {
cy.url().should("include", "/facility/");
cy.get("[data-testid=patient-dashboard]").then(($dashboard) => {
Expand All @@ -166,7 +170,7 @@ export class PatientPage {
patientState,
patientDistrict,
patientLocalbody,
patientWard
patientWard,
) {
cy.get("[data-testid=patient-details]").then(($dashboard) => {
cy.url().should("include", "/facility/");
Expand Down
33 changes: 33 additions & 0 deletions src/Components/Patient/PatientRegister.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import useQuery from "../../Utils/request/useQuery.js";
import routes from "../../Redux/api.js";
import request from "../../Utils/request/request.js";
import SelectMenuV2 from "../Form/SelectMenuV2.js";
import Checkbox from "../Common/components/CheckBox.js";

const Loading = lazy(() => import("../Common/Loading"));
const PageTitle = lazy(() => import("../Common/PageTitle"));
Expand Down Expand Up @@ -222,6 +223,8 @@ export const PatientRegister = (props: PatientRegisterProps) => {
const [insuranceDetails, setInsuranceDetails] = useState<HCXPolicyModel[]>(
[],
);
const [isEmergencyNumberEnabled, setIsEmergencyNumberEnabled] =
useState(false);
const [insuranceDetailsError, setInsuranceDetailsError] =
useState<FieldError>();

Expand Down Expand Up @@ -467,6 +470,9 @@ export const PatientRegister = (props: PatientRegisterProps) => {
: null,
};
formData.sameAddress = data.address === data.permanent_address;
setIsEmergencyNumberEnabled(
data.phone_number === data.emergency_phone_number,
);
(data.medical_history ? data.medical_history : []).forEach(
(i: any) => {
const medicalHistory = MEDICAL_HISTORY_CHOICES.find(
Expand Down Expand Up @@ -1311,9 +1317,35 @@ export const PatientRegister = (props: PatientRegisterProps) => {
onChange={(event) => {
if (!id) duplicateCheck(event.value);
field("phone_number").onChange(event);
if (isEmergencyNumberEnabled) {
field("emergency_phone_number").onChange({
name: field("emergency_phone_number").name,
value: event.value,
});
}
}}
types={["mobile", "landline"]}
/>
<Checkbox
label="Is the phone number an emergency number?"
className="font-bold"
id="emergency_contact_checkbox"
checked={isEmergencyNumberEnabled}
onCheck={(checked) => {
setIsEmergencyNumberEnabled(checked);
checked
? field("emergency_phone_number").onChange({
name: field("emergency_phone_number")
.name,
value: field("phone_number").value,
})
: field("emergency_phone_number").onChange({
name: field("emergency_phone_number")
.name,
value: initForm.emergency_phone_number,
});
}}
/>
</div>
<div
data-testid="emergency-phone-number"
Expand All @@ -1324,6 +1356,7 @@ export const PatientRegister = (props: PatientRegisterProps) => {
label="Emergency contact number"
required
types={["mobile", "landline"]}
disabled={isEmergencyNumberEnabled}
/>
</div>
<div data-testid="name" id="name-div">
Expand Down

0 comments on commit 3e2ebab

Please sign in to comment.