Skip to content

Commit

Permalink
Diagnosis: Adds field Principal Diagnosis (#6218)
Browse files Browse the repository at this point in the history
* adds field principle diagnosis

* show in consultation details

* fix typo

* fix cypress

* try adding wait

* fix tests
  • Loading branch information
rithviknishad authored Sep 6, 2023
1 parent dcc7b70 commit 8a6e526
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cypress/e2e/patient_spec/patient_crud.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,24 @@ describe("Patient Creation with consultation", () => {
cy.get("#weight").click().type("70");
cy.get("#height").click().type("170");
cy.get("#patient_no").type("IP007");

cy.intercept("GET", "**/icd/**").as("getIcdResults");
cy.get(
"#icd11_diagnoses_object input[placeholder='Select'][role='combobox']"
)
.click()
.type("1A");
cy.wait(1000);
cy.get("#icd11_diagnoses_object [role='option']")
.contains("1A03 Intestinal infections due to Escherichia coli")
.click();
cy.get("label[for='icd11_diagnoses_object']").click();
cy.wait("@getIcdResults").its("response.statusCode").should("eq", 200);

cy.get("#icd11_principal_diagnosis [role='combobox']").click().type("1A");
cy.get("#icd11_principal_diagnosis [role='option']")
.contains("1A03 Intestinal infections due to Escherichia coli")
.click();

cy.get("#consultation_notes").click().type("generalnote");
cy.get("#verified_by").click().type("generalnote");
cy.get("#submit").click();
Expand Down
16 changes: 16 additions & 0 deletions src/Components/Facility/ConsultationDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,22 @@ export const ConsultationDetails = (props: any) => {
</div>
)*/}

{consultationData.icd11_principal_diagnosis && (
<ShowDiagnosis
label="Principal Diagnosis (as per ICD-11 recommended by WHO)"
diagnoses={[
[
...(consultationData?.icd11_diagnoses_object ?? []),
...(consultationData?.icd11_provisional_diagnoses_object ??
[]),
].find(
(d) =>
d.id === consultationData.icd11_principal_diagnosis
)!,
]}
/>
)}

<ShowDiagnosis
diagnoses={
consultationData?.icd11_provisional_diagnoses_object
Expand Down
68 changes: 68 additions & 0 deletions src/Components/Facility/ConsultationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import useConfig from "../../Common/hooks/useConfig";
import { useDispatch } from "react-redux";
import useVisibility from "../../Utils/useVisibility";
import dayjs from "../../Utils/dayjs";
import AutocompleteFormField from "../Form/FormFields/Autocomplete.js";

const Loading = lazy(() => import("../Common/Loading"));
const PageTitle = lazy(() => import("../Common/PageTitle"));
Expand All @@ -80,6 +81,7 @@ type FormDetails = {
referred_to_external?: string;
icd11_diagnoses_object: ICD11DiagnosisModel[];
icd11_provisional_diagnoses_object: ICD11DiagnosisModel[];
icd11_principal_diagnosis?: ICD11DiagnosisModel["id"];
verified_by: string;
is_kasp: BooleanStrings;
kasp_enabled_date: null;
Expand Down Expand Up @@ -124,6 +126,7 @@ const initForm: FormDetails = {
referred_to_external: "",
icd11_diagnoses_object: [],
icd11_provisional_diagnoses_object: [],
icd11_principal_diagnosis: undefined,
verified_by: "",
is_kasp: "false",
kasp_enabled_date: null,
Expand Down Expand Up @@ -551,6 +554,42 @@ export const ConsultationForm = (props: any) => {
return;
}

case "icd11_principal_diagnosis": {
if (!state.form[field]) {
errors[field] = "Please select Principal Diagnosis";
invalidForm = true;
break;
}

if (
state.form[field] &&
state.form["icd11_diagnoses_object"].length &&
!state.form["icd11_diagnoses_object"]
.map((d) => d.id)
.includes(state.form[field]!)
) {
errors[field] =
"Please select Principal Diagnosis from Final Diagnosis";
invalidForm = true;
break;
}

if (
state.form[field] &&
state.form["icd11_provisional_diagnoses_object"].length &&
!state.form["icd11_provisional_diagnoses_object"]
.map((d) => d.id)
.includes(state.form[field]!)
) {
errors[field] =
"Please select Principal Diagnosis from Provisional Diagnosis";
invalidForm = true;
break;
}

return;
}

default:
return;
}
Expand Down Expand Up @@ -630,6 +669,7 @@ export const ConsultationForm = (props: any) => {
state.form.icd11_provisional_diagnoses_object.map(
(o: ICD11DiagnosisModel) => o.id
),
icd11_principal_diagnosis: state.form.icd11_principal_diagnosis,
verified_by: state.form.verified_by,
investigation: state.form.InvestigationAdvice,
procedure: state.form.procedures,
Expand Down Expand Up @@ -718,6 +758,18 @@ export const ConsultationForm = (props: any) => {
verified_by: "Declared Dead",
},
});
} else if (
event.name === "icd11_diagnoses_object" ||
event.name === "icd11_provisional_diagnoses_object"
) {
dispatch({
type: "set_form",
form: {
...state.form,
[event.name]: event.value,
icd11_principal_diagnosis: undefined,
},
});
} else {
dispatch({
type: "set_form",
Expand Down Expand Up @@ -1152,6 +1204,22 @@ export const ConsultationForm = (props: any) => {
label="Final Diagnosis"
/>
</div>

<div ref={fieldRef["icd11_principal_diagnosis"]}>
<AutocompleteFormField
{...field("icd11_principal_diagnosis")}
label="Principal Diagnosis"
placeholder="Search for diagnosis"
options={
state.form.icd11_diagnoses_object.length
? state.form.icd11_diagnoses_object
: state.form.icd11_provisional_diagnoses_object
}
optionLabel={(option) => option.label}
optionValue={(option) => option.id}
required
/>
</div>
</div>

<div className="grid grid-cols-1 gap-4 gap-x-6">
Expand Down
1 change: 1 addition & 0 deletions src/Components/Facility/models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export interface ConsultationModel {
diagnosis?: string;
icd11_diagnoses_object?: ICD11DiagnosisModel[];
icd11_provisional_diagnoses_object?: ICD11DiagnosisModel[];
icd11_principal_diagnosis?: ICD11DiagnosisModel["id"];
verified_by?: string;
suggestion_text?: string;
symptoms?: Array<number>;
Expand Down

0 comments on commit 8a6e526

Please sign in to comment.