Skip to content

Commit

Permalink
Fix: Qualification field for nurse user type (#8694)
Browse files Browse the repository at this point in the history
Co-authored-by: Mohammed Nihal <57055998+nihal467@users.noreply.github.com>
  • Loading branch information
AdityaJ2305 and nihal467 authored Oct 3, 2024
1 parent cd4cc9f commit e44e245
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 48 deletions.
4 changes: 2 additions & 2 deletions cypress/e2e/users_spec/UsersCreation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe("User Creation", () => {
userCreationPage.setInputDate("date_of_birth", "date-input", "25081999");
userCreationPage.selectDropdownOption("user_type", "Doctor");
userCreationPage.typeIntoElementById("c_password", "Test@123");
userCreationPage.typeIntoElementById("doctor_qualification", "MBBS");
userCreationPage.typeIntoElementById("qualification", "MBBS");
userCreationPage.typeIntoElementById("doctor_experience_commenced_on", "2");
userCreationPage.typeIntoElementById(
"doctor_medical_council_registration",
Expand All @@ -172,7 +172,7 @@ describe("User Creation", () => {
"home_facility",
"Dummy Shifting Center",
);
userCreationPage.verifyElementContainsText("doctor-qualification", "MBBS");
userCreationPage.verifyElementContainsText("qualification", "MBBS");
userCreationPage.verifyElementContainsText("doctor-experience", "2");
userCreationPage.verifyElementContainsText(
"medical-council-registration",
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/users_spec/UsersProfile.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("Manage User Profile", () => {
const email = "test@example.com";
const phone = "+918899887788";
const workinghours = "8";
const doctorQualification = "MBBS";
const qualification = "MBBS";
const doctorYoE = "10";
const medicalCouncilRegistration = "1234567890";

Expand Down Expand Up @@ -40,7 +40,7 @@ describe("Manage User Profile", () => {
userProfilePage.typePhone(phone);
userProfilePage.typeWhatsApp(phone);
userProfilePage.typeWorkingHours(workinghours);
userProfilePage.typeDoctorQualification(doctorQualification);
userProfilePage.typeQualification(qualification);
userProfilePage.typeDoctorYoE(doctorYoE);
userProfilePage.typeMedicalCouncilRegistration(medicalCouncilRegistration);

Expand Down
4 changes: 2 additions & 2 deletions cypress/pageobject/Users/UserProfilePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export default class UserProfilePage {
cy.get("#weekly_working_hours").click().clear().type(workinghours);
}

typeDoctorQualification = (doctorQualification: string) => {
cy.get("#doctor_qualification").click().clear().type(doctorQualification);
typeQualification = (qualification: string) => {
cy.get("#qualification").click().clear().type(qualification);
};

typeDoctorYoE = (doctorYoE: string) => {
Expand Down
40 changes: 32 additions & 8 deletions src/Components/Users/ManageUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ export default function ManageUsers() {
};

let userList: any[] = [];

userListData?.results &&
userListData.results.length &&
(userList = userListData.results.map((user: any, idx) => {
Expand Down Expand Up @@ -283,15 +282,17 @@ export default function ManageUsers() {
<>
<div className="col-span-1">
<UserDetails
id="doctor-qualification"
title="Qualification"
id="qualification"
title={t("qualification")}
>
{user.doctor_qualification ? (
{user.qualification ? (
<span className="font-semibold">
{user.doctor_qualification}
{user.qualification}
</span>
) : (
<span className="text-secondary-600">Unknown</span>
<span className="text-secondary-600">
{t("unknown")}
</span>
)}
</UserDetails>
</div>
Expand All @@ -307,7 +308,9 @@ export default function ManageUsers() {
years
</span>
) : (
<span className="text-secondary-600">Unknown</span>
<span className="text-secondary-600">
{t("unknown")}
</span>
)}
</UserDetails>
</div>
Expand All @@ -321,7 +324,9 @@ export default function ManageUsers() {
{user.doctor_medical_council_registration}
</span>
) : (
<span className="text-secondary-600">Unknown</span>
<span className="text-secondary-600">
{t("unknown")}
</span>
)}
</UserDetails>
</div>
Expand All @@ -335,11 +340,30 @@ export default function ManageUsers() {
</div>
</UserDetails>
)}

<div
className={`${
isExtremeSmallScreen ? "flex flex-wrap" : "grid grid-cols-2"
}`}
>
{user.user_type === "Nurse" && (
<div className="row-span-1">
<UserDetails
id="qualification"
title={t("qualification")}
>
{user.qualification ? (
<span className="font-semibold">
{user.qualification}
</span>
) : (
<span className="text-secondary-600">
{t("unknown")}
</span>
)}
</UserDetails>
</div>
)}
{user.created_by && (
<div className="col-span-1">
<UserDetails id="created_by" title="Created by">
Expand Down
38 changes: 24 additions & 14 deletions src/Components/Users/UserAdd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import CheckBoxFormField from "../Form/FormFields/CheckBoxFormField";
import { useTranslation } from "react-i18next";

const Loading = lazy(() => import("../Common/Loading"));

interface UserProps {
userId?: number;
}
Expand Down Expand Up @@ -72,7 +71,7 @@ type UserForm = {
state: number;
district: number;
local_body: number;
doctor_qualification: string | undefined;
qualification: string | undefined;
doctor_experience_commenced_on: string | undefined;
doctor_medical_council_registration: string | undefined;
};
Expand All @@ -95,7 +94,7 @@ const initForm: UserForm = {
state: 0,
district: 0,
local_body: 0,
doctor_qualification: undefined,
qualification: undefined,
doctor_experience_commenced_on: undefined,
doctor_medical_council_registration: undefined,
};
Expand Down Expand Up @@ -372,7 +371,16 @@ export const UserAdd = (props: UserProps) => {
invalidForm = true;
}
return;
case "doctor_qualification":
case "qualification":
if (
(state.form.user_type === "Doctor" ||
state.form.user_type === "Nurse") &&
!state.form[field]
) {
errors[field] = t("field_required");
invalidForm = true;
}
return;
case "doctor_medical_council_registration":
if (state.form.user_type === "Doctor" && !state.form[field]) {
errors[field] = t("field_required");
Expand Down Expand Up @@ -553,9 +561,9 @@ export const UserAdd = (props: UserProps) => {
: state.form.alt_phone_number,
) ?? "",
date_of_birth: dateQueryString(state.form.date_of_birth),
doctor_qualification:
state.form.user_type === "Doctor"
? state.form.doctor_qualification
qualification:
state.form.user_type === "Doctor" || state.form.user_type == "Nurse"
? state.form.qualification
: undefined,
doctor_experience_commenced_on:
state.form.user_type === "Doctor"
Expand Down Expand Up @@ -650,15 +658,17 @@ export const UserAdd = (props: UserProps) => {
optionValue={(o) => o.id}
/>

{(state.form.user_type === "Doctor" ||
state.form.user_type === "Nurse") && (
<TextFormField
{...field("qualification")}
required
label={t("qualification")}
placeholder={t("qualification")}
/>
)}
{state.form.user_type === "Doctor" && (
<>
<TextFormField
{...field("doctor_qualification")}
required
label="Qualification"
placeholder="Qualification of the Doctor"
/>

<TextFormField
{...field("doctor_experience_commenced_on")}
required
Expand Down
44 changes: 29 additions & 15 deletions src/Components/Users/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type EditForm = {
phoneNumber: string;
altPhoneNumber: string;
user_type: string | undefined;
doctor_qualification: string | undefined;
qualification: string | undefined;
doctor_experience_commenced_on: number | string | undefined;
doctor_medical_council_registration: string | undefined;
weekly_working_hours: string | null | undefined;
Expand All @@ -54,7 +54,7 @@ type ErrorForm = {
phoneNumber: string;
altPhoneNumber: string;
user_type: string | undefined;
doctor_qualification: string | undefined;
qualification: string | undefined;
doctor_experience_commenced_on: number | string | undefined;
doctor_medical_council_registration: string | undefined;
weekly_working_hours: string | undefined;
Expand All @@ -77,7 +77,7 @@ const initForm: EditForm = {
phoneNumber: "",
altPhoneNumber: "",
user_type: "",
doctor_qualification: undefined,
qualification: undefined,
doctor_experience_commenced_on: undefined,
doctor_medical_council_registration: undefined,
weekly_working_hours: undefined,
Expand Down Expand Up @@ -149,6 +149,7 @@ export default function UserProfile() {
} = useQuery(routes.currentUser, {
onResponse: (result) => {
if (!result || !result.res || !result.data) return;

const formData: EditForm = {
firstName: result.data.first_name,
lastName: result.data.last_name,
Expand All @@ -159,7 +160,7 @@ export default function UserProfile() {
phoneNumber: result.data.phone_number?.toString() || "",
altPhoneNumber: result.data.alt_phone_number?.toString() || "",
user_type: result.data.user_type,
doctor_qualification: result.data.doctor_qualification,
qualification: result.data.qualification,
doctor_experience_commenced_on: dayjs().diff(
dayjs(result.data.doctor_experience_commenced_on),
"years",
Expand Down Expand Up @@ -277,7 +278,16 @@ export default function UserProfile() {
invalidForm = true;
}
return;
case "doctor_qualification":
case "qualification":
if (
(states.form.user_type === "Doctor" ||
states.form.user_type === "Nurse") &&
!states.form[field]
) {
errors[field] = t("field_required");
invalidForm = true;
}
return;
case "doctor_medical_council_registration":
if (states.form.user_type === "Doctor" && !states.form[field]) {
errors[field] = t("field_required");
Expand Down Expand Up @@ -344,9 +354,10 @@ export default function UserProfile() {
alt_phone_number: parsePhoneNumber(states.form.altPhoneNumber) ?? "",
gender: states.form.gender,
date_of_birth: dateQueryString(states.form.date_of_birth),
doctor_qualification:
states.form.user_type === "Doctor"
? states.form.doctor_qualification
qualification:
states.form.user_type === "Doctor" ||
states.form.user_type === "Nurse"
? states.form.qualification
: undefined,
doctor_experience_commenced_on:
states.form.user_type === "Doctor"
Expand Down Expand Up @@ -727,15 +738,18 @@ export default function UserProfile() {
required
type="email"
/>
{(states.form.user_type === "Doctor" ||
states.form.user_type === "Nurse") && (
<TextFormField
{...fieldProps("qualification")}
required
className="col-span-6 sm:col-span-3"
label={t("qualification")}
placeholder={t("qualification")}
/>
)}
{states.form.user_type === "Doctor" && (
<>
<TextFormField
{...fieldProps("doctor_qualification")}
required
className="col-span-6 sm:col-span-3"
label="Qualification"
placeholder="Doctor's Qualification"
/>
<TextFormField
{...fieldProps("doctor_experience_commenced_on")}
required
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Users/models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type UserModel = UserBareMinimum & {
local_body_object?: LocalBodyModel;
district_object?: DistrictModel;
state_object?: StateModel;
doctor_qualification?: string;
qualification?: string;
doctor_experience_commenced_on?: string;
doctor_medical_council_registration?: string;
weekly_working_hours?: string | null;
Expand Down Expand Up @@ -82,7 +82,7 @@ export interface UserAssignedModel extends UserBareMinimum {
verified?: boolean;
home_facility?: string;
home_facility_object?: HomeFacilityObjectModel;
doctor_qualification?: string;
qualification?: string;
doctor_experience_commenced_on?: Date;
doctor_medical_council_registration?: string;
weekly_working_hours?: string;
Expand Down
7 changes: 4 additions & 3 deletions src/Locale/en/Common.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
"treating_doctor": "Treating Doctor",
"hubs": "Hub Facilities",
"spokes": "Spoke Facilities",
"add_spoke" : "Add Spoke Facility",
"add_spoke": "Add Spoke Facility",
"ration_card__NO_CARD": "Non-card holder",
"ration_card__BPL": "BPL",
"ration_card__APL": "APL",
Expand Down Expand Up @@ -232,5 +232,6 @@
"SORT_OPTIONS__bed__name": "Bed No. 1-N",
"SORT_OPTIONS__-bed__name": "Bed No. N-1",
"middleware_hostname": "Middleware Hostname",
"local_ipaddress": "Local IP Address"
}
"local_ipaddress": "Local IP Address",
"qualification": "Qualification"
}

0 comments on commit e44e245

Please sign in to comment.