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

Search by ID #1375

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
40 changes: 40 additions & 0 deletions client/src/assets/scss/_custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,46 @@ h3.ui.header {
width: 100%;
}

.ui.form.search .form-input.yes-no {
padding-bottom: 15px;
margin-left: 25px;
margin-top: 15px;

label {
font-size: 25px;
margin-left: 10px;
}

label:before {
content: " ";
display: inline-block;
position: relative;
top: 5px;
margin-right: 10px;
width: 26px;
height: 26px;
border-radius: 13px;
border: 2px solid $color-gray-border;
background-color: transparent;
}

input[type=radio] {
display: none;
}

input[type=radio]:checked + label:after {
content: " ";
border-radius: 7px;
width: 14px;
height: 14px;
position: absolute;
top: 25px;
left: 30px;
display: block;
background: $color-text;
}
}

.results-summary {
margin-top: 15px;
margin-bottom: 15px;
Expand Down
2 changes: 2 additions & 0 deletions client/src/assets/scss/_new.scss
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ div.page-people {
display: flex;
flex-direction: column;
height: 100%;
overflow-x: hidden;
AronNovak marked this conversation as resolved.
Show resolved Hide resolved
overflow-y: hidden;

div.search-middle {
Expand Down Expand Up @@ -3553,6 +3554,7 @@ div.page-participants {
display: flex;
flex-direction: column;
height: 100%;
overflow-x: hidden;
overflow-y: hidden;

div.search-middle {
Expand Down
2 changes: 1 addition & 1 deletion client/src/elm/App/Fetch.elm
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fetch model =
getLoggedInData model
|> Maybe.map
(\( _, loggedIn ) ->
Pages.People.Fetch.fetch relation initiator loggedIn.personsPage
Pages.People.Fetch.fetch relation loggedIn.personsPage
|> List.map MsgIndexedDb
)
|> Maybe.withDefault []
Expand Down
3 changes: 2 additions & 1 deletion client/src/elm/App/Model.elm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import Backend.TuberculosisActivity.Model exposing (TuberculosisActivity)
import Backend.WellChildActivity.Model exposing (WellChildActivity)
import Browser
import Browser.Navigation as Nav
import Components.PatientsSearchForm.Model
import Config.Model
import Device.Model exposing (Device)
import Error.Model exposing (Error, ErrorType)
Expand Down Expand Up @@ -330,7 +331,7 @@ emptyLoggedInModel site villageId nurse =
, globalCaseManagementPage = Pages.GlobalCaseManagement.Model.emptyModel
, editPersonPages = Dict.empty
, personsPage = Pages.People.Model.emptyModel
, individualEncounterParticipantsPage = Pages.IndividualEncounterParticipants.Model.emptyModel
, individualEncounterParticipantsPage = Components.PatientsSearchForm.Model.emptyModel
, clinicsPage = Pages.Clinics.Model.emptyModel
, stockManagementPage = Pages.StockManagement.Model.emptyModel
, relationshipPages = Dict.empty
Expand Down
4 changes: 4 additions & 0 deletions client/src/elm/Backend/Endpoints.elm
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ personEndpoint =

type PersonParams
= ParamsNameContains String
| ParamsNationalIdContains String
| ParamsGeoFields String


Expand All @@ -111,6 +112,9 @@ encodePersonParams params =
ParamsNameContains value ->
[ ( "name_contains", value ) ]

ParamsNationalIdContains value ->
[ ( "national_id_contains", value ) ]

ParamsGeoFields value ->
[ ( "geo_fields", value ) ]

Expand Down
12 changes: 10 additions & 2 deletions client/src/elm/Backend/Fetch.elm
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ shouldFetch currentTime model msg =
isNotAsked model.participantForms

FetchPeopleByName search ->
Dict.get (String.trim search) model.personSearches
Dict.get (String.trim search) model.personSearchesByName
|> Maybe.withDefault NotAsked
|> isNotAsked

FetchPeopleByNationalId search ->
Dict.get (String.trim search) model.personSearchesByNationalId
|> Maybe.withDefault NotAsked
|> isNotAsked

Expand Down Expand Up @@ -502,7 +507,10 @@ forget msg model =
{ model | participantForms = NotAsked }

FetchPeopleByName search ->
{ model | personSearches = Dict.remove (String.trim search) model.personSearches }
{ model | personSearchesByName = Dict.remove (String.trim search) model.personSearchesByName }

FetchPeopleByNationalId search ->
{ model | personSearchesByNationalId = Dict.remove (String.trim search) model.personSearchesByNationalId }

FetchPeopleInVillage id ->
{ model | peopleInVillage = Dict.remove id model.peopleInVillage }
Expand Down
11 changes: 9 additions & 2 deletions client/src/elm/Backend/Model.elm
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ type alias ModelIndexedDb =

-- Tracks searchs for participants by name. The key is the phrase we are
-- searching for.
, personSearches : Dict String (WebData (Dict PersonId Person))
, personSearchesByName : Dict String (WebData (Dict PersonId Person))

-- Tracks searchs for participants by name. The key is the phrase we are
anvmn marked this conversation as resolved.
Show resolved Hide resolved
-- searching for.
, personSearchesByNationalId : Dict String (WebData (Dict PersonId Person))
, peopleInVillage : Dict VillageId (WebData (Dict PersonId Person))

-- A simple cache of several things.
Expand Down Expand Up @@ -247,7 +251,8 @@ emptyModelIndexedDb =
, participantsByPerson = Dict.empty
, people = Dict.empty
, traceContacts = Dict.empty
, personSearches = Dict.empty
, personSearchesByName = Dict.empty
, personSearchesByNationalId = Dict.empty
, peopleInVillage = Dict.empty
, prenatalEncounterRequests = Dict.empty
, nutritionEncounterRequests = Dict.empty
Expand Down Expand Up @@ -373,6 +378,7 @@ type MsgIndexedDb
| FetchParticipantsForPerson PersonId
| FetchPeople (List PersonId)
| FetchPeopleByName String
| FetchPeopleByNationalId String
| FetchPeopleInVillage VillageId
| FetchPerson PersonId
| FetchPrenatalEncounter PrenatalEncounterId
Expand Down Expand Up @@ -446,6 +452,7 @@ type MsgIndexedDb
| HandleFetchedParticipantsForPerson PersonId (WebData (Dict PmtctParticipantId PmtctParticipant))
| HandleFetchedPeople (WebData (Dict PersonId Person))
| HandleFetchedPeopleByName String (WebData (Dict PersonId Person))
| HandleFetchedPeopleByNationalId String (WebData (Dict PersonId Person))
| HandleFetchedPeopleInVillage VillageId (WebData (Dict PersonId Person))
| HandleFetchedPerson PersonId (WebData Person)
| HandleFetchedPrenatalEncounter PrenatalEncounterId (WebData PrenatalEncounter)
Expand Down
26 changes: 23 additions & 3 deletions client/src/elm/Backend/Update.elm
Original file line number Diff line number Diff line change
Expand Up @@ -1431,14 +1431,33 @@ updateIndexedDb language currentDate currentTime zscores site features nurseId h
in
-- We'll limit the search to 500 each for now ... basically,
-- just to avoid truly pathological cases.
( { model | personSearches = Dict.insert trimmed Loading model.personSearches }
( { model | personSearchesByName = Dict.insert trimmed Loading model.personSearchesByName }
, sw.selectRange personEndpoint (ParamsNameContains trimmed) 0 (Just 500)
|> toCmd (RemoteData.fromResult >> RemoteData.map (.items >> Dict.fromList) >> HandleFetchedPeopleByName trimmed)
, []
)

HandleFetchedPeopleByName trimmed data ->
( { model | personSearches = Dict.insert trimmed data model.personSearches }
( { model | personSearchesByName = Dict.insert trimmed data model.personSearchesByName }
, Cmd.none
, []
)

FetchPeopleByNationalId nationalId ->
let
trimmed =
String.trim nationalId
in
-- We'll limit the search to 500 each for now ... basically,
-- just to avoid truly pathological cases.
( { model | personSearchesByNationalId = Dict.insert trimmed Loading model.personSearchesByNationalId }
, sw.selectRange personEndpoint (ParamsNationalIdContains trimmed) 0 (Just 500)
|> toCmd (RemoteData.fromResult >> RemoteData.map (.items >> Dict.fromList) >> HandleFetchedPeopleByNationalId trimmed)
, []
)

HandleFetchedPeopleByNationalId trimmed data ->
( { model | personSearchesByNationalId = Dict.insert trimmed data model.personSearchesByNationalId }
, Cmd.none
, []
)
Expand Down Expand Up @@ -5886,7 +5905,8 @@ handleRevision currentDate healthCenterId villageId revision (( model, recalc )
Dict.update uuid (Maybe.map (always (Success data))) model.people
in
( { model
| personSearches = Dict.empty
| personSearchesByName = Dict.empty
, personSearchesByNationalId = Dict.empty
, people = people
}
, True
Expand Down
29 changes: 29 additions & 0 deletions client/src/elm/Components/PatientsSearchForm/Fetch.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module Components.PatientsSearchForm.Fetch exposing (fetch)

import Backend.Entities exposing (..)
import Backend.Model exposing (MsgIndexedDb(..))
import Backend.Person.Model exposing (Initiator)
import Components.PatientsSearchForm.Model exposing (..)
import Maybe.Extra


fetch : Model -> List MsgIndexedDb
fetch model =
let
trimmed =
Maybe.withDefault "" model.search
in
if String.isEmpty trimmed then
[]

else
let
fetchMsg =
case model.mode of
ModeSearchByName ->
FetchPeopleByName

ModeSearchByNationalId ->
FetchPeopleByNationalId
in
[ fetchMsg trimmed ]
38 changes: 38 additions & 0 deletions client/src/elm/Components/PatientsSearchForm/Model.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module Components.PatientsSearchForm.Model exposing (..)

import Debouncer.Basic as Debouncer exposing (Debouncer, debounce, toDebouncer)


{-| The `input` field represents what the user has typed as an input.

The `search` field represents what we're searching for. (We delay
searches briefly while the user is typing).

-}
type alias Model =
{ debouncer : Debouncer Msg Msg
, mode : PatientsSearchFormMode
, search : Maybe String
, input : String
}


type PatientsSearchFormMode
= ModeSearchByName
| ModeSearchByNationalId


emptyModel : Model
emptyModel =
{ debouncer = debounce 500 |> toDebouncer
, mode = ModeSearchByName
, search = Nothing
, input = ""
}


type Msg
= MsgDebouncer (Debouncer.Msg Msg)
| SetMode Bool
| SetInput String
| SetSearch String
72 changes: 72 additions & 0 deletions client/src/elm/Components/PatientsSearchForm/Update.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
module Components.PatientsSearchForm.Update exposing (update)

import Components.PatientsSearchForm.Model exposing (..)
import Debouncer.Basic as Debouncer exposing (provideInput)
import Maybe.Extra exposing (isJust)
import Update.Extra exposing (sequence)


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
MsgDebouncer subMsg ->
let
( subModel, subCmd, extraMsg ) =
Debouncer.update subMsg model.debouncer
in
( { model | debouncer = subModel }
, Cmd.map MsgDebouncer subCmd
)
|> sequence update (Maybe.Extra.toList extraMsg)

SetMode byName ->
let
mode =
if byName then
ModeSearchByName

else
ModeSearchByNationalId
in
( { model | mode = mode, input = "", search = Nothing }
, Cmd.none
)

SetSearch search ->
let
trimmed =
String.trim search

maybeSearch =
if String.isEmpty trimmed then
Nothing

else
Just trimmed
in
( { model | search = maybeSearch }
, Cmd.none
)

SetInput input ->
case model.mode of
ModeSearchByName ->
( { model | input = input }
, Cmd.none
)
|> sequence update [ MsgDebouncer <| provideInput <| SetSearch input ]

ModeSearchByNationalId ->
let
asNumber =
String.toInt input
in
if isJust asNumber then
( { model | input = input }
, Cmd.none
)
|> sequence update
[ MsgDebouncer <| provideInput <| SetSearch input ]

else
( model, Cmd.none )
32 changes: 32 additions & 0 deletions client/src/elm/Components/PatientsSearchForm/Utils.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Components.PatientsSearchForm.Utils exposing (..)

import AssocList as Dict exposing (Dict)
import Backend.Entities exposing (..)
import Backend.Model exposing (ModelIndexedDb)
import Backend.Person.Model exposing (Person)
import Components.PatientsSearchForm.Model exposing (..)
import RemoteData exposing (RemoteData(..), WebData)


getSearchResults : ModelIndexedDb -> Model -> WebData (Dict PersonId Person)
getSearchResults db model =
let
searchValue =
getSearchValue model

resultsDictFunc =
case model.mode of
ModeSearchByName ->
.personSearchesByName

ModeSearchByNationalId ->
.personSearchesByNationalId
in
resultsDictFunc db
|> Dict.get searchValue
|> Maybe.withDefault NotAsked


getSearchValue : Model -> String
getSearchValue =
.search >> Maybe.withDefault ""
Loading