diff --git a/client/src/elm/App/Update.elm b/client/src/elm/App/Update.elm index a29e537610..9c954af6fb 100644 --- a/client/src/elm/App/Update.elm +++ b/client/src/elm/App/Update.elm @@ -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 diff --git a/client/src/elm/Backend/Measurement/Encoder.elm b/client/src/elm/Backend/Measurement/Encoder.elm index cdebe796fa..1da4eddf7f 100644 --- a/client/src/elm/Backend/Measurement/Encoder.elm +++ b/client/src/elm/Backend/Measurement/Encoder.elm @@ -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 ) diff --git a/client/src/elm/Backend/Update.elm b/client/src/elm/Backend/Update.elm index 3dde0e5f22..789d1e83cc 100644 --- a/client/src/elm/Backend/Update.elm +++ b/client/src/elm/Backend/Update.elm @@ -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 ) @@ -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 ) @@ -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 ) @@ -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 diff --git a/client/src/elm/Pages/GlobalCaseManagement/View.elm b/client/src/elm/Pages/GlobalCaseManagement/View.elm index b7a8c7079f..2e32e0bbd6 100644 --- a/client/src/elm/Pages/GlobalCaseManagement/View.elm +++ b/client/src/elm/Pages/GlobalCaseManagement/View.elm @@ -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. @@ -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 diff --git a/client/src/elm/Pages/Prenatal/ProgressReport/View.elm b/client/src/elm/Pages/Prenatal/ProgressReport/View.elm index f8d658138a..05c504dd38 100644 --- a/client/src/elm/Pages/Prenatal/ProgressReport/View.elm +++ b/client/src/elm/Pages/Prenatal/ProgressReport/View.elm @@ -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 ] ) diff --git a/client/src/elm/Pages/Prenatal/RecurrentEncounter/Model.elm b/client/src/elm/Pages/Prenatal/RecurrentEncounter/Model.elm index 90234a7d5c..2e47044228 100644 --- a/client/src/elm/Pages/Prenatal/RecurrentEncounter/Model.elm +++ b/client/src/elm/Pages/Prenatal/RecurrentEncounter/Model.elm @@ -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) @@ -20,6 +22,7 @@ type Msg = SetActivePage Page | SetAlertsDialogState Bool | SetSelectedTab Tab + | ConcludeEncounter PersonId PrenatalEncounterId PrenatalLabsResultsId LabsResultsValue type Tab diff --git a/client/src/elm/Pages/Prenatal/RecurrentEncounter/Update.elm b/client/src/elm/Pages/Prenatal/RecurrentEncounter/Update.elm index f5a76f48ba..fc5a8a1943 100644 --- a/client/src/elm/Pages/Prenatal/RecurrentEncounter/Update.elm +++ b/client/src/elm/Pages/Prenatal/RecurrentEncounter/Update.elm @@ -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 @@ -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 ] diff --git a/client/src/elm/Pages/Prenatal/RecurrentEncounter/View.elm b/client/src/elm/Pages/Prenatal/RecurrentEncounter/View.elm index 3a08afdbf0..6a3a14193a 100644 --- a/client/src/elm/Pages/Prenatal/RecurrentEncounter/View.elm +++ b/client/src/elm/Pages/Prenatal/RecurrentEncounter/View.elm @@ -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) @@ -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 diff --git a/server/hedley/modules/custom/hedley_stats/hedley_stats.module b/server/hedley/modules/custom/hedley_stats/hedley_stats.module index c8211248f3..f578598321 100644 --- a/server/hedley/modules/custom/hedley_stats/hedley_stats.module +++ b/server/hedley/modules/custom/hedley_stats/hedley_stats.module @@ -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'), ]; }