Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #7610 Toggle Emergency Contact No. From Phone Number #7644

Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions cypress/e2e/patient_spec/patient_registration.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,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 @@ -118,7 +118,7 @@ describe("Patient Creation with consultation", () => {
emergency_phone_number,
yearOfBirth,
patientOneBloodGroup,
patientOccupation
patientOccupation,
);
patientMedicalHistory.verifyPatientMedicalDetails(
patientOnePresentHealth,
Expand All @@ -130,7 +130,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 +155,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 @@ -207,7 +207,7 @@ describe("Patient Creation with consultation", () => {
emergency_phone_number,
yearOfBirth,
patientOneUpdatedBloodGroup,
patientOccupation
patientOccupation,
);
// Verify No medical history
patientMedicalHistory.verifyNoSymptosPresent("Diabetes");
Expand All @@ -220,21 +220,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
6 changes: 3 additions & 3 deletions cypress/pageobject/Patient/PatientCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class PatientPage {
}

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

typePatientEmergencyNumber(phoneNumber: string) {
Expand Down Expand Up @@ -145,7 +145,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 +166,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 @@ -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"]}
/>
<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 @@ -1314,6 +1346,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
Loading