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

User (Doctor) Autocomplete for Consultation Verified By #6194

Merged
merged 13 commits into from
Sep 7, 2023
3 changes: 2 additions & 1 deletion cypress/e2e/patient_spec/patient_crud.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ describe("Patient Creation with consultation", () => {
"170",
"IP007",
"generalnote",
"generalnote"
"Dev Doctor"
);
patientConsultationPage.submitConsultation();

// Below code for the prescription module only present while creating a new consultation
patientConsultationPage.clickAddPrescription();
patientConsultationPage.interceptMediaBase();
Expand Down
3 changes: 2 additions & 1 deletion cypress/pageobject/Facility/FacilityCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class FacilityPage {
}

clickManageFacilityDropdown() {
cy.get("#manage-facility-dropdown button").scrollIntoView();
cy.get("#manage-facility-dropdown button")
.contains("Manage Facility")
.click();
Expand All @@ -118,7 +119,7 @@ class FacilityPage {
}

clickInventoryManagementOption() {
cy.get("[id=inventory-management]").click();
cy.get("#inventory-management").click();
}

clickResourceRequestOption() {
Expand Down
9 changes: 7 additions & 2 deletions cypress/pageobject/Patient/PatientConsultation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class PatientConsultationPage {
}

fillIllnessHistory(history: string) {
cy.get("#history_of_present_illness").scrollIntoView;
cy.get("#history_of_present_illness").scrollIntoView();
cy.get("#history_of_present_illness").should("be.visible");
cy.get("#history_of_present_illness").click().type(history);
}
Expand Down Expand Up @@ -52,7 +52,12 @@ export class PatientConsultationPage {
.click();

cy.get("#consultation_notes").click().type(consulationNotes);
cy.get("#verified_by").click().type(verificationBy);
cy.get("#verified_by")
.click()
.type(verificationBy)
.then(() => {
cy.get("[role='option']").contains("Dev Doctor").click();
});
}

submitConsultation() {
Expand Down
13 changes: 10 additions & 3 deletions src/Components/Common/UserAutocompleteFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import {
} from "../Form/FormFields/Utils";
import { UserModel } from "../Users/models";
import { isUserOnline } from "../../Utils/utils";
import { UserRole } from "../../Common/constants";

type Props = FormFieldBaseProps<UserModel> & {
placeholder?: string;
facilityId?: string;
userType?: string;
homeFacility?: string;
userType?: UserRole;
showActiveStatus?: boolean;
};

Expand All @@ -26,6 +28,7 @@ export default function UserAutocompleteFormField(props: Props) {
let search_filter: {
limit: number;
offset: number;
home_facility?: string;
user_type?: string;
search_text?: string;
} = { limit: 5, offset: 0 };
Expand All @@ -34,6 +37,10 @@ export default function UserAutocompleteFormField(props: Props) {
search_filter = { ...search_filter, user_type: props.userType };
}

if (props.homeFacility) {
search_filter = { ...search_filter, home_facility: props.homeFacility };
}

const getStatusIcon = (option: UserModel) => {
if (!props.showActiveStatus) return null;

Expand Down Expand Up @@ -69,11 +76,11 @@ export default function UserAutocompleteFormField(props: Props) {
onQuery={(query) =>
fetchOptions(
props.facilityId
? getFacilityUsers(props.facilityId)
: getUserList({
? getFacilityUsers(props.facilityId, {
...search_filter,
search_text: query,
})
: getUserList({ ...search_filter, search_text: query })
)
}
isLoading={isLoading}
Expand Down
7 changes: 5 additions & 2 deletions src/Components/Facility/ConsultationDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,15 @@ export const ConsultationDetails = (props: any) => {
label="Diagnosis (as per ICD-11 recommended by WHO)"
/>

{consultationData.verified_by && (
{(consultationData.verified_by_object ||
consultationData.deprecated_verified_by) && (
<div className="mt-2 text-sm">
<span className="font-semibold leading-relaxed">
Verified By:{" "}
</span>
{consultationData.verified_by}
{consultationData.verified_by_object
? `${consultationData.verified_by_object.first_name} ${consultationData.verified_by_object.last_name}`
: consultationData.deprecated_verified_by}
<i className="fas fa-check ml-2 fill-current text-lg text-green-500"></i>
</div>
)}
Expand Down
40 changes: 25 additions & 15 deletions src/Components/Facility/ConsultationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ import CheckBoxFormField from "../Form/FormFields/CheckBoxFormField";
import DateFormField from "../Form/FormFields/DateFormField";
import { DiagnosisSelectFormField } from "../Common/DiagnosisSelectFormField";
import { FacilitySelect } from "../Common/FacilitySelect";
import { FieldChangeEventHandler } from "../Form/FormFields/Utils";
import {
FieldChangeEvent,
FieldChangeEventHandler,
} from "../Form/FormFields/Utils";
import { FormAction } from "../Form/Utils";
import PatientCategorySelect from "../Patient/PatientCategorySelect";
import { SelectFormField } from "../Form/FormFields/SelectFormField";
Expand Down Expand Up @@ -83,6 +86,7 @@ type FormDetails = {
icd11_provisional_diagnoses_object: ICD11DiagnosisModel[];
icd11_principal_diagnosis?: ICD11DiagnosisModel["id"];
verified_by: string;
verified_by_object: UserModel | null;
is_kasp: BooleanStrings;
kasp_enabled_date: null;
examination_details: string;
Expand Down Expand Up @@ -128,6 +132,7 @@ const initForm: FormDetails = {
icd11_provisional_diagnoses_object: [],
icd11_principal_diagnosis: undefined,
verified_by: "",
verified_by_object: null,
is_kasp: "false",
kasp_enabled_date: null,
examination_details: "",
Expand Down Expand Up @@ -329,12 +334,13 @@ export const ConsultationForm = (props: any) => {
?.id ?? "Comfort"
: "Comfort",
patient_no: res.data.patient_no ?? "",
verified_by: res.data.verified_by ? res.data.verified_by : "",
OPconsultation: res.data.consultation_notes,
is_telemedicine: `${res.data.is_telemedicine}`,
is_kasp: `${res.data.is_kasp}`,
assigned_to: res.data.assigned_to || "",
assigned_to_object: res.data.assigned_to_object,
verified_by: res.data.verified_by || "",
verified_by_object: res.data.verified_by_object,
ett_tt: res.data.ett_tt ? Number(res.data.ett_tt) : 3,
special_instruction: res.data.special_instruction || "",
weight: res.data.weight ? res.data.weight : "",
Expand Down Expand Up @@ -745,7 +751,6 @@ export const ConsultationForm = (props: any) => {
symptoms_onset_date: new Date(),
category: "Critical",
suggestion: "DD",
verified_by: "Brought Dead",
},
});
} else if (event.name === "suggestion" && event.value === "DD") {
Expand Down Expand Up @@ -778,23 +783,23 @@ export const ConsultationForm = (props: any) => {
}
};

const handleDoctorSelect = (doctor: UserModel | null) => {
if (doctor?.id) {
const handleDoctorSelect = (event: FieldChangeEvent<UserModel | null>) => {
if (event.value?.id) {
dispatch({
type: "set_form",
form: {
...state.form,
assigned_to: doctor.id.toString(),
assigned_to_object: doctor,
[event.name]: event.value.id.toString(),
[`${event.name}_object`]: event.value,
},
});
} else {
dispatch({
type: "set_form",
form: {
...state.form,
assigned_to: "",
assigned_to_object: null,
[event.name]: "",
[`${event.name}_object`]: null,
},
});
}
Expand Down Expand Up @@ -1309,11 +1314,17 @@ export const ConsultationForm = (props: any) => {
className="col-span-6"
ref={fieldRef["verified_by"]}
>
<TextAreaFormField
{...field("verified_by")}
<UserAutocompleteFormField
name={"verified_by"}
label="Verified by"
required
placeholder="Attending Doctors Name and Designation"
required
value={state.form.verified_by_object ?? undefined}
onChange={handleDoctorSelect}
showActiveStatus
userType={"Doctor"}
homeFacility={facilityId}
error={state.errors.verified_by}
/>
</div>

Expand Down Expand Up @@ -1358,11 +1369,10 @@ export const ConsultationForm = (props: any) => {
value={
state.form.assigned_to_object ?? undefined
}
onChange={(option) =>
handleDoctorSelect(option.value)
}
onChange={handleDoctorSelect}
userType={"Doctor"}
name={"assigned_to"}
label="Assigned to"
/>
</div>
)}
Expand Down
3 changes: 3 additions & 0 deletions src/Components/Facility/models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { AssignedToObjectModel } from "../Patient/models";
import { ProcedureType } from "../Common/prescription-builder/ProcedureBuilder";
import { NormalPrescription, PRNPrescription } from "../Medicine/models";
import { AssetData } from "../Assets/AssetTypes";
import { UserBareMinimum } from "../Users/models";

export interface LocalBodyModel {
name: string;
Expand Down Expand Up @@ -113,7 +114,9 @@ export interface ConsultationModel {
icd11_diagnoses_object?: ICD11DiagnosisModel[];
icd11_provisional_diagnoses_object?: ICD11DiagnosisModel[];
icd11_principal_diagnosis?: ICD11DiagnosisModel["id"];
deprecated_verified_by?: string;
verified_by?: string;
verified_by_object?: UserBareMinimum;
suggestion_text?: string;
symptoms?: Array<number>;
symptoms_text?: string;
Expand Down
17 changes: 7 additions & 10 deletions src/Components/Users/models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ interface HomeFacilityObjectModel {
id?: string;
name?: string;
}
export type UserModel = {

export type UserBareMinimum = {
id: number;
username: string;
first_name: string;
last_name: string;
email: string;
user_type: UserRole;
last_login: string | undefined;
};

export type UserModel = UserBareMinimum & {
local_body?: number;
district?: number;
state?: number;
Expand All @@ -21,7 +26,6 @@ export type UserModel = {
age?: number;
is_superuser?: boolean;
verified?: boolean;
last_login: string | undefined;
home_facility_object?: HomeFacilityObjectModel;
local_body_object?: LocalBodyModel;
district_object?: DistrictModel;
Expand All @@ -42,13 +46,7 @@ export interface SkillModel {
skill_object: SkillObjectModel;
}

export interface UserAssignedModel {
id?: number;
username?: string;
first_name?: string;
last_name?: string;
email?: string;
user_type?: number | string;
export interface UserAssignedModel extends UserBareMinimum {
local_body?: number;
district?: number;
state?: number;
Expand All @@ -58,7 +56,6 @@ export interface UserAssignedModel {
age?: number;
is_superuser?: boolean;
verified?: boolean;
last_login?: Date;
home_facility_object?: HomeFacilityObjectModel;
doctor_qualification?: string;
doctor_experience_commenced_on?: Date;
Expand Down