diff --git a/app/controllers/patients_controller.rb b/app/controllers/patients_controller.rb index e8c07f70..d00f5628 100644 --- a/app/controllers/patients_controller.rb +++ b/app/controllers/patients_controller.rb @@ -3,15 +3,7 @@ class PatientsController < ApplicationController # GET /patients/ def index - @search_text = params.fetch(:search, "") - @facility_id = params.fetch(:facility, "") - - @facilities = policy_scope(Facility).map { |f| [f.name, f.id] } - @facilities.unshift(["all", nil]) - - # filter and paginate - @patients = filter_patients(@search_text, @facility_id) - authorize Patient + @patients = Patient.get_formatted end # GET /patients/new @@ -102,13 +94,4 @@ def patient_params :facility_id, ) end - - def filter_patients(search_text, facility_id) - return policy_scope(Patient).where(facility_id: facility_id) if (facility_id != "") - - policy_scope(Patient).where( - "full_name ILIKE :search_text", - search_text: "%#{search_text}%", - ) - end end diff --git a/app/javascript/Patient/Patients.res b/app/javascript/Patient/Patients.res new file mode 100644 index 00000000..94168cef --- /dev/null +++ b/app/javascript/Patient/Patients.res @@ -0,0 +1,31 @@ +type patient = Patients__Types.patient +type props = Patients__Types.props + +let s = React.string + +@react.component +let make = (~props: props) => { + +
+
+
+
{s("Patients")}
+ +
+ +
+
+
+
+
+ +
+
+
+
+
+} \ No newline at end of file diff --git a/app/javascript/Patient/Patients__Types.res b/app/javascript/Patient/Patients__Types.res new file mode 100644 index 00000000..fa5e91cf --- /dev/null +++ b/app/javascript/Patient/Patients__Types.res @@ -0,0 +1,23 @@ +type patient = { + id: string, + name: string, + dob: Js.Date.t, + phone: string, + address: string, +} + +type patients = array + +type props = {patients: patients} + + +let decode = json => { + open Json.Decode + { + id: field("id", string, json), + name: field("name", string, json), + dob: field("dob", date, json), + phone: field("phone", string, json), + address: field("address", string, json) + } +} \ No newline at end of file diff --git a/app/javascript/Patient/components/Link.res b/app/javascript/Patient/components/Link.res new file mode 100644 index 00000000..db8984db --- /dev/null +++ b/app/javascript/Patient/components/Link.res @@ -0,0 +1,15 @@ +@val external window: {..} = "window" + +let s = React.string + +@react.component +let make = (~className: string, ~href: string, ~text: string) => { + { + event->ReactEvent.Mouse.stopPropagation + window["location"]["href"] = href + }}> + {s(text)} + +} \ No newline at end of file diff --git a/app/javascript/Patient/components/Patients__PatientsTable.res b/app/javascript/Patient/components/Patients__PatientsTable.res new file mode 100644 index 00000000..da062f07 --- /dev/null +++ b/app/javascript/Patient/components/Patients__PatientsTable.res @@ -0,0 +1,84 @@ +type patient = Patients__Types.patient +type patients = Patients__Types.patients + +let s = React.string + + +module Patient = { + @react.component + let make = (~patient: patient) => { + + + {s(patient.name)} + + + + {s(patient.dob->Js.Date.toDateString)} + + + + {s(patient.phone)} + + + + {s(patient.address)} + + + + + + + } +} + + +@react.component +let make = (~patients: patients) => { + + +
+ + + + + + + + + + + + { + patients->Js.Array2.map(patient => + + )->React.array + } + +
+ {s("Full Name")} + + {s("Date of Birth")} + + {s("Phone")} + + {s("Address")} + + {s("Actions")} +
+
+} \ No newline at end of file diff --git a/app/javascript/packs/PatientsPack.res b/app/javascript/packs/PatientsPack.res new file mode 100644 index 00000000..55b08493 --- /dev/null +++ b/app/javascript/packs/PatientsPack.res @@ -0,0 +1,15 @@ +type props = Patients__Types.props + +let decode: Js.Json.t => props = json => { + open Json.Decode + { + patients: field("patients", array(Patients__Types.decode), json), + } +} +let props = DomUtils.parseJSONTag(~id="patients-data", ()) |> decode + + +switch ReactDOM.querySelector(`#patients`) { +| Some(id) => ReactDOM.render(, id) +| None => () +} \ No newline at end of file diff --git a/app/javascript/schedule/Schedule.res b/app/javascript/schedule/Schedule.res index b052841c..67578503 100644 --- a/app/javascript/schedule/Schedule.res +++ b/app/javascript/schedule/Schedule.res @@ -10,10 +10,10 @@ let make = (~props: props) => { let (sortOption, setSortOption) = React.useState(_ => "next_visit") let (sortAscending, setSortAscending) = React.useState(_ => true) let (patients, updatePatients) = React.useReducer( - Patients.reducer, + Schedule__Patients.reducer, {unselectedPatients: props.patients, selectedPatients: []}, ) - let (filters, updateFilters) = React.useReducer(Filter.reducer, {procedures: [], wards: []}) + let (filters, updateFilters) = React.useReducer(Schedule__Filter.reducer, {procedures: [], wards: []}) React.useEffect4(() => { let procedure_filtered_patients = !(filters.procedures->length == 0) @@ -41,20 +41,20 @@ let make = (~props: props) => { let sorted_patients = filtered_patients->Schedule__Utils.jssort(sortOption, sortAscending) - Patients.SetUnSelectedPatients(sorted_patients)->updatePatients + Schedule__Patients.SetUnSelectedPatients(sorted_patients)->updatePatients None }, (searchTerm, sortOption, sortAscending, filters))
- - - + + Schedule__Utils.jsunion("procedures")} selectedFilters={filters} updateFilters />
- +
} diff --git a/app/javascript/schedule/components/Filter.res b/app/javascript/schedule/components/Schedule__Filter.res similarity index 97% rename from app/javascript/schedule/components/Filter.res rename to app/javascript/schedule/components/Schedule__Filter.res index 88069aa4..9b4912ff 100644 --- a/app/javascript/schedule/components/Filter.res +++ b/app/javascript/schedule/components/Schedule__Filter.res @@ -82,7 +82,7 @@ module FilterSection = {
{s(name ++ "(s)")}
- {searchbar ? :
} + {searchbar ? :
}
{options ->Belt.Array.map(option => diff --git a/app/javascript/schedule/components/Pagination.res b/app/javascript/schedule/components/Schedule__Pagination.res similarity index 100% rename from app/javascript/schedule/components/Pagination.res rename to app/javascript/schedule/components/Schedule__Pagination.res diff --git a/app/javascript/schedule/components/Patients.res b/app/javascript/schedule/components/Schedule__Patients.res similarity index 95% rename from app/javascript/schedule/components/Patients.res rename to app/javascript/schedule/components/Schedule__Patients.res index 7d4aeb3e..ad65f0bb 100644 --- a/app/javascript/schedule/components/Patients.res +++ b/app/javascript/schedule/components/Schedule__Patients.res @@ -43,20 +43,20 @@ let make = (~patients, ~updatePatients) => { upatients ->Js.Array2.slice(~start=(pageNumber - 1) * perPage, ~end_=pageNumber * perPage) ->Js.Array2.map(patient => - patient->SelectPatient->updatePatients} /> )
- patient->UnselectPatient->updatePatients} />
    {patientList->React.array}
- - <%= patient.full_name %> + <%= patient.name %> diff --git a/app/views/patients/index.html.erb b/app/views/patients/index.html.erb index 5d0bf09c..afb48950 100644 --- a/app/views/patients/index.html.erb +++ b/app/views/patients/index.html.erb @@ -1,78 +1,11 @@ -
-
-
-
Patients
+<%=content_for(:tail) do %> + <%= javascript_pack_tag 'PatientsPack', "data-turbo-track": "reload", nonce: true %> +<% end %> -
- <%= form_with url: "/patients", method: :get, class: "flex space-x-4 items-center" do |form| %> - <%= form.label "Filter By Facility" %> - <%= form.select :facility, @facilities, {selected: @facility_id}, {class: "border border-gray-300 rounded-md shadow-md w-32", onchange: "this.form.submit()"} %> - <% end %> - <%= link_to 'Create New Patient', new_patient_path, class: 'inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500' %> -
-
-
-
-
- <%= form_tag patients_path, method: :get do %> -
- <%= text_field_tag :search, @search_text,placeholder: "Search for Patient name", class: "block w-full bg-white border border-gray-300 rounded-md py-2 pl-3 text-sm placeholder-gray-500 focus:outline-none focus:text-gray-900 focus:placeholder-gray-400 focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" %> -
- -
-
- <% end %> -
-
- - - - - - - - - - - - <% @patients.each do |patient| %> - <%= render partial: 'table-row', locals: { patient: patient} %> - <% end %> - -
- Full Name - - Date of Birth - - Phone - - Address - - Actions -
-
-
-
-
-
-
+ + +
\ No newline at end of file