diff --git a/cypress/e2e/patient_spec/patient_registration.cy.ts b/cypress/e2e/patient_spec/patient_registration.cy.ts index 28b9234065..634b6d5c81 100644 --- a/cypress/e2e/patient_spec/patient_registration.cy.ts +++ b/cypress/e2e/patient_spec/patient_registration.cy.ts @@ -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"; @@ -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"; @@ -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); @@ -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"); @@ -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, @@ -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"); @@ -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); @@ -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"); @@ -220,7 +216,7 @@ describe("Patient Creation with consultation", () => { patientOneFirstSubscriberId, patientOneFirstPolicyId, patientOneFirstInsurerId, - patientOneFirstInsurerName + patientOneFirstInsurerName, ); patientInsurance.clickPatientInsuranceViewDetail(); cy.wait(3000); @@ -228,13 +224,13 @@ describe("Patient Creation with consultation", () => { patientOneFirstSubscriberId, patientOneFirstPolicyId, patientOneFirstInsurerId, - patientOneFirstInsurerName + patientOneFirstInsurerName, ); patientInsurance.verifyPatientPolicyDetails( patientOneSecondSubscriberId, patientOneSecondPolicyId, patientOneSecondInsurerId, - patientOneSecondInsurerName + patientOneSecondInsurerName, ); }); diff --git a/cypress/pageobject/Patient/PatientCreation.ts b/cypress/pageobject/Patient/PatientCreation.ts index 01bdfdb8cb..078302f1ee 100644 --- a/cypress/pageobject/Patient/PatientCreation.ts +++ b/cypress/pageobject/Patient/PatientCreation.ts @@ -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) { @@ -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) => { @@ -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/"); diff --git a/src/Components/Patient/PatientRegister.tsx b/src/Components/Patient/PatientRegister.tsx index dea0484a67..4917ae7225 100644 --- a/src/Components/Patient/PatientRegister.tsx +++ b/src/Components/Patient/PatientRegister.tsx @@ -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")); @@ -222,6 +223,8 @@ export const PatientRegister = (props: PatientRegisterProps) => { const [insuranceDetails, setInsuranceDetails] = useState( [], ); + const [isEmergencyNumberEnabled, setIsEmergencyNumberEnabled] = + useState(false); const [insuranceDetailsError, setInsuranceDetailsError] = useState(); @@ -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( @@ -1301,9 +1307,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"]} /> + { + 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, + }); + }} + />
{ label="Emergency contact number" required types={["mobile", "landline"]} + disabled={isEmergencyNumberEnabled} />