Skip to content

Commit

Permalink
Merge pull request #1038 from TIP-Global-Health/develop
Browse files Browse the repository at this point in the history
Developments starting February 25, 2024
  • Loading branch information
anvmn authored Feb 26, 2024
2 parents d29093d + ff34056 commit 645a72c
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 74 deletions.
2 changes: 1 addition & 1 deletion client/src/elm/App/Update.elm
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ update msg model =
data.prenatalRecurrentEncounterPages
|> Dict.get id
|> Maybe.withDefault Pages.Prenatal.RecurrentEncounter.Model.emptyModel
|> Pages.Prenatal.RecurrentEncounter.Update.update id subMsg
|> Pages.Prenatal.RecurrentEncounter.Update.update currentDate id subMsg
in
( { data | prenatalRecurrentEncounterPages = Dict.insert id subModel data.prenatalRecurrentEncounterPages }
, Cmd.map (MsgLoggedIn << MsgPagePrenatalRecurrentEncounter id) subCmd
Expand Down
9 changes: 5 additions & 4 deletions client/src/elm/Backend/Measurement/Encoder.elm
Original file line number Diff line number Diff line change
Expand Up @@ -1816,11 +1816,12 @@ encodeVitalsValueWithType type_ value =
[ ( "respiratory_rate", int value.respiratoryRate )
, ( "body_temperature", float value.bodyTemperature )
]
++ encodeNullable "sys" value.sys float
++ encodeNullable "dia" value.dia float
++ encodeNullable "heart_rate" value.heartRate int
-- Not all CT got the repeated fields. Therefore we use
-- Not all Vitals CTs got the sys, dia, sys_repeated,
-- dia_repeated and heart_rate fields. Therefore we use
-- encodeIfSet, to send the field only if it has a value.
++ encodeIfSet "sys" value.sys float
++ encodeIfSet "dia" value.dia float
++ encodeIfSet "heart_rate" value.heartRate int
++ encodeIfSet "sys_repeated" value.sysRepeated float
++ encodeIfSet "dia_repeated" value.diaRepeated float
++ [ ( "deleted", bool False )
Expand Down
121 changes: 66 additions & 55 deletions client/src/elm/Backend/Update.elm
Original file line number Diff line number Diff line change
Expand Up @@ -1690,8 +1690,11 @@ updateIndexedDb language currentDate currentTime zscores site features nurseId h
if atPrenatalRecurrentPhase activePage then
generatePrenatalRecurrentPhaseCompletedMsgs currentDate isLabTech newModel encounterId_

else
else if atPrenatalInitialPhase activePage then
generatePrenatalInitialPhaseCompletedMsgs currentDate site newModel encounterId_

else
[]
in
labsResultsMsgs ++ possibleEndEncounterMsgs
)
Expand Down Expand Up @@ -1761,8 +1764,11 @@ updateIndexedDb language currentDate currentTime zscores site features nurseId h
if atPrenatalRecurrentPhase activePage then
generatePrenatalRecurrentPhaseCompletedMsgs currentDate isLabTech newModel encounterId_

else
else if atPrenatalInitialPhase activePage then
generatePrenatalInitialPhaseCompletedMsgs currentDate site newModel encounterId_

else
[]
in
labsResultsMsgs ++ possibleEndEncounterMsgs
)
Expand Down Expand Up @@ -6314,63 +6320,55 @@ generatePrenatalLabsResultsAddedMsgs currentDate isLabTech after test testPrereq
(\assembled ->
Maybe.map
(\( resultsId, results ) ->
if
EverySet.member test results.value.completedTests
&& EverySet.member test results.value.performedTests
then
-- Do not update value if we have it set up properly already.
[]

else
let
( performedTests, completedTests ) =
Pages.GlobalCaseManagement.Utils.labsResultsTestData currentDate results

updatedValue =
(\value ->
let
-- Since lab results can be entered right away (at poit of care),
-- or at latter stage (after test was ordered at lab), we
-- update both performed and completed tests.
-- Since data structure is EverySet, it will not create duplicacies.
updatedPerformedTests =
EverySet.insert test performedTests

updatedCompletedTests =
EverySet.insert test completedTests

allLabsCompleted =
EverySet.size updatedCompletedTests == EverySet.size updatedPerformedTests
let
( performedTests, completedTests ) =
Pages.GlobalCaseManagement.Utils.labsResultsTestData currentDate results

updatedTestsWithFollowUp =
-- Mark tests which results were entered by Lab Tech, and got
-- follow up questions that will have to be completed by nurse.
if isLabTech && List.member test [ TestHIV, TestSyphilis ] then
Maybe.map (EverySet.insert test >> Just) value.testsWithFollowUp
|> Maybe.withDefault (Just <| EverySet.singleton test)
updatedValue =
(\value ->
let
-- Since lab results can be entered right away (at poit of care),
-- or at latter stage (after test was ordered at lab), we
-- update both performed and completed tests.
-- Since data structure is EverySet, it will not create duplicacies.
updatedPerformedTests =
EverySet.insert test performedTests

updatedCompletedTests =
EverySet.insert test completedTests

allLabsCompleted =
EverySet.size updatedCompletedTests == EverySet.size updatedPerformedTests

updatedTestsWithFollowUp =
-- Mark tests which results were entered by Lab Tech, and got
-- follow up questions that will have to be completed by nurse.
if isLabTech && List.member test [ TestHIV, TestSyphilis ] then
Maybe.map (EverySet.insert test >> Just) value.testsWithFollowUp
|> Maybe.withDefault (Just <| EverySet.singleton test)

else
value.testsWithFollowUp
else
value.testsWithFollowUp

reviewState =
-- For lab technician, request review if all labs were
-- completed, and review state was not set previously.
if isLabTech && isNothing value.reviewState && allLabsCompleted then
Just LabsResultsReviewRequested
reviewState =
-- For lab technician, request review if all labs were
-- completed, and review state was not set previously.
if isLabTech && isNothing value.reviewState && allLabsCompleted then
Just LabsResultsReviewRequested

else
value.reviewState
in
{ value
| performedTests = updatedPerformedTests
, completedTests = updatedCompletedTests
, testsWithFollowUp = updatedTestsWithFollowUp
, reviewState = reviewState
}
)
results.value
in
[ savePrenatalLabsResultsMsg id assembled.participant.person (Just resultsId) updatedValue ]
else
value.reviewState
in
{ value
| performedTests = updatedPerformedTests
, completedTests = updatedCompletedTests
, testsWithFollowUp = updatedTestsWithFollowUp
, reviewState = reviewState
}
)
results.value
in
[ savePrenatalLabsResultsMsg id assembled.participant.person (Just resultsId) updatedValue ]
)
assembled.measurements.labsResults
)
Expand Down Expand Up @@ -6455,6 +6453,19 @@ generatePrenatalRecurrentPhaseCompletedMsgs currentDate isLabTech after id =
|> Maybe.withDefault []


atPrenatalInitialPhase : Page -> Bool
atPrenatalInitialPhase activePage =
case activePage of
UserPage (PrenatalEncounterPage _) ->
True

UserPage (PrenatalActivityPage _ _) ->
True

_ ->
False


atPrenatalRecurrentPhase : Page -> Bool
atPrenatalRecurrentPhase activePage =
case activePage of
Expand Down
9 changes: 1 addition & 8 deletions client/src/elm/Pages/GlobalCaseManagement/View.elm
Original file line number Diff line number Diff line change
Expand Up @@ -895,10 +895,6 @@ viewPrenatalLabsPane language currentDate isLabTech itemsDict db model =
Date.compare currentDate item.value.resolutionDate == LT

roleDependantCondition =
let
diff =
EverySet.diff item.value.performedTests item.value.completedTests
in
if isLabTech then
-- If review was requested (by lab technician), or completed
-- (by nurse) we do not display entry for lab technician.
Expand All @@ -907,10 +903,7 @@ viewPrenatalLabsPane language currentDate isLabTech itemsDict db model =
-- vitals recheck, we do not display entry for lab technician.
-- For nurse,all tests were completed condition des not apply,
-- since there maybe follow up quesitons to fill.
(case EverySet.toList diff of
[] ->
False

(case EverySet.toList item.value.performedTests of
[ TestVitalsRecheck ] ->
False

Expand Down
7 changes: 6 additions & 1 deletion client/src/elm/Pages/Prenatal/ProgressReport/View.elm
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,12 @@ viewContent language currentDate site features isChw isLabTech isResultsReviewer
(\( resultsId, _ ) value ->
button
[ class "ui primary fluid button"
, onClick <| ReviewAndAcceptLabsResults assembled.participant.person encounterId resultsId value
, onClick <|
ReviewAndAcceptLabsResults
assembled.participant.person
encounterId
resultsId
value
]
[ text <| translate language Translate.ReviewAndAccept ]
)
Expand Down
3 changes: 3 additions & 0 deletions client/src/elm/Pages/Prenatal/RecurrentEncounter/Model.elm
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Pages.Prenatal.RecurrentEncounter.Model exposing (..)

import Backend.Entities exposing (..)
import Backend.Measurement.Model exposing (LabsResultsValue)
import Pages.Page exposing (Page)


Expand All @@ -20,6 +22,7 @@ type Msg
= SetActivePage Page
| SetAlertsDialogState Bool
| SetSelectedTab Tab
| ConcludeEncounter PersonId PrenatalEncounterId PrenatalLabsResultsId LabsResultsValue


type Tab
Expand Down
18 changes: 16 additions & 2 deletions client/src/elm/Pages/Prenatal/RecurrentEncounter/Update.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ module Pages.Prenatal.RecurrentEncounter.Update exposing (update)

import App.Model
import Backend.Entities exposing (PrenatalEncounterId)
import Backend.Model
import Backend.PrenatalActivity.Model exposing (PrenatalRecurrentActivity(..))
import Backend.PrenatalEncounter.Model
import Gizra.NominalDate exposing (NominalDate)
import Gizra.Update exposing (sequenceExtra)
import Pages.Page exposing (Page(..), UserPage(..))
import Pages.Prenatal.Activity.Types exposing (WarningPopupType(..))
import Pages.Prenatal.RecurrentActivity.Model
import Pages.Prenatal.RecurrentEncounter.Model exposing (..)


update : PrenatalEncounterId -> Msg -> Model -> ( Model, Cmd Msg, List App.Model.Msg )
update id msg model =
update : NominalDate -> PrenatalEncounterId -> Msg -> Model -> ( Model, Cmd Msg, List App.Model.Msg )
update currentDate id msg model =
case msg of
SetActivePage page ->
let
Expand All @@ -35,3 +39,13 @@ update id msg model =

SetSelectedTab tab ->
( { model | selectedTab = tab }, Cmd.none, [] )

ConcludeEncounter personId encounterId labsResultsId value ->
( model
, Cmd.none
, [ Backend.PrenatalEncounter.Model.SaveLabsResults personId (Just labsResultsId) { value | resolutionDate = currentDate }
|> Backend.Model.MsgPrenatalEncounter encounterId
|> App.Model.MsgIndexedDb
]
)
|> sequenceExtra (update currentDate id) [ SetActivePage <| UserPage GlobalCaseManagementPage ]
31 changes: 29 additions & 2 deletions client/src/elm/Pages/Prenatal/RecurrentEncounter/View.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Pages.Prenatal.RecurrentEncounter.View exposing (view)

import Backend.Entities exposing (..)
import Backend.IndividualEncounterParticipant.Model exposing (IndividualEncounterType(..))
import Backend.Measurement.Utils exposing (getMeasurementValueFunc)
import Backend.Model exposing (ModelIndexedDb)
import Backend.Nurse.Model exposing (Nurse)
import Backend.Nurse.Utils exposing (isLabTechnician)
Expand Down Expand Up @@ -155,14 +156,40 @@ viewMainPageContent language currentDate nurse assembled model =
]

content =
let
( label, action ) =
let
leaveEncounterTuple =
( Translate.LeaveEncounter, SetActivePage <| UserPage GlobalCaseManagementPage )
in
if not isLabTech && List.isEmpty pendingActivities then
-- Nurse has completed all activities => end the
-- encounter (by setting resolution date to today).
Maybe.map2
(\( resultsId, _ ) value ->
( Translate.EndEncounter
, ConcludeEncounter
assembled.participant.person
assembled.id
resultsId
value
)
)
assembled.measurements.labsResults
(getMeasurementValueFunc assembled.measurements.labsResults)
|> Maybe.withDefault leaveEncounterTuple

else
leaveEncounterTuple
in
div [ class "ui full segment" ]
[ innerContent
, div [ class "actions" ]
[ button
[ class "ui fluid primary button"
, onClick (SetActivePage <| UserPage GlobalCaseManagementPage)
, onClick action
]
[ text <| translate language Translate.LeaveEncounter ]
[ text <| translate language label ]
]
]
in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1692,7 +1692,6 @@ function hedley_stats_get_child_scorecard_data($health_center_id) {
// Populate data of the encounters.
foreach ($result as $row) {
$items[$row->field_individual_participant]['encounters'][$row->nid] = [
// Field for 'created' is added at hedley_stats_get_base_query().
'start_date' => date_format(date_create($row->field_scheduled_date), 'Y-m-d'),
];
}
Expand Down

0 comments on commit 645a72c

Please sign in to comment.