Skip to content

Commit

Permalink
Merge pull request #1048 from TIP-Global-Health/issue-p-3107
Browse files Browse the repository at this point in the history
[Hotfix] Aggregated NCDA socrecard fixes
  • Loading branch information
anvmn authored Mar 3, 2024
2 parents 622691e + f41cf6a commit 47c3faa
Show file tree
Hide file tree
Showing 11 changed files with 1,082 additions and 562 deletions.
4 changes: 2 additions & 2 deletions ci-scripts/install_elm_format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ set -e
#
# ---------------------------------------------------------------------------- #

wget https://github.com/avh4/elm-format/releases/download/0.8.5/elm-format-0.8.5-linux-x64.tgz
tar xfz elm-format-0.8.5-linux-x64.tgz
wget https://github.com/avh4/elm-format/releases/download/0.8.7/elm-format-0.8.7-linux-x64.tgz
tar xfz elm-format-0.8.7-linux-x64.tgz
sudo mv elm-format /usr/bin/
17 changes: 15 additions & 2 deletions client/src/elm/Gizra/NominalDate.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Gizra.NominalDate exposing
, fromLocalDateTime
, diffDays, diffCalendarMonthsAndDays
, NominalDateRange, decodeDrupalRange, encodeDrupalRange
, allMonths, daysInMonth, diffCalendarMonths, diffCalendarYearsAndMonths, diffMonths, diffWeeks, diffYears, formatDDMMYY, formatDDMMYYYY, isDiffTruthy, isLeapYear, monthMM, yearYY, yearYYNumber
, allMonths, daysInMonth, diffCalendarMonths, diffCalendarYearsAndMonths, diffMonths, diffWeeks, diffYears, formatDDMMYY, formatDDMMYYYY, isDiffTruthy, isLeapYear, monthMM, toLastDayOfMonth, yearYY, yearYYNumber
)

{-| Some utilities for dealing with "pure" dates that have no time or
Expand All @@ -24,7 +24,7 @@ time zone information.
-}

import Date
import Date exposing (..)
import Gizra.String exposing (addLeadingZero)
import Json.Decode exposing (Decoder, andThen, field, map2, string)
import Json.Decode.Extra exposing (fromResult)
Expand Down Expand Up @@ -93,6 +93,19 @@ fromLocalDateTime =
Date.fromPosix Time.utc


{-| Given a date, return date representing it's last month day.
toLastDayOfMonth 2019-08-01" --> 2019-08-31"
toLastDayOfMonth 2017-02-20" --> 2017-02-28"
-}
toLastDayOfMonth : NominalDate -> NominalDate
toLastDayOfMonth =
Date.floor Month
>> Date.add Months 1
>> Date.add Days -1


{-| Decodes nominal date from string of the form "2017-02-20".
import Json.Decode exposing (..)
Expand Down
9 changes: 4 additions & 5 deletions client/src/elm/Pages/Dashboard/Utils.elm
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import Backend.PrenatalEncounter.Types exposing (PrenatalDiagnosis(..))
import Backend.Village.Model exposing (Village)
import Date exposing (Unit(..), isBetween)
import EverySet
import Gizra.NominalDate exposing (NominalDate)
import Gizra.NominalDate exposing (NominalDate, toLastDayOfMonth)
import List.Extra
import Maybe.Extra exposing (isJust)
import Measurement.Model exposing (VaccinationProgressDict)
Expand All @@ -79,7 +79,6 @@ import Pages.GlobalCaseManagement.View
, generateNutritionFollowUpEntries
, generatePrenatalFollowUpEntries
)
import Pages.Utils exposing (getLastDayOfMonth)
import SyncManager.Model exposing (Site)
import Translate exposing (Language)
import Utils.NominalDate exposing (sortByDate, sortByDateDesc)
Expand Down Expand Up @@ -1236,7 +1235,7 @@ generateTotalBeneficiariesMonthlyDuringPastYear currentDate stats =
let
maxJoinDate =
Date.add Months (-1 * index) currentDate
|> getLastDayOfMonth
|> toLastDayOfMonth

minGraduationDate =
Date.add Months (-1 * index) currentDate
Expand Down Expand Up @@ -1462,15 +1461,15 @@ filterStatsByPeriod fiterFunc currentDate period stats =
( Date.add Months -1 currentDate
|> Date.floor Date.Month
, Date.add Months -1 currentDate
|> getLastDayOfMonth
|> toLastDayOfMonth
)

ThreeMonthsAgo ->
-- From the beginning of 3 months ago to the end of 3 months ago.
( Date.add Months -2 currentDate
|> Date.floor Date.Month
, Date.add Months -2 currentDate
|> getLastDayOfMonth
|> toLastDayOfMonth
)

filterPartial =
Expand Down
5 changes: 2 additions & 3 deletions client/src/elm/Pages/Dashboard/View.elm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import Date exposing (Month, Unit(..), numberToMonth)
import Debug exposing (toString)
import EverySet
import Gizra.Html exposing (emptyNode, showMaybe)
import Gizra.NominalDate exposing (NominalDate, isDiffTruthy)
import Gizra.NominalDate exposing (NominalDate, isDiffTruthy, toLastDayOfMonth)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onClick, onInput)
Expand Down Expand Up @@ -1664,8 +1664,7 @@ viewBeneficiariesTable language currentDate stats currentPeriodStats malnourishe
let
maxJoinDate =
Date.add Months -1 currentDate
|> Date.ceiling Date.Month
|> Date.add Days -1
|> toLastDayOfMonth

minGraduationDate =
Date.add Months -1 currentDate
Expand Down
9 changes: 2 additions & 7 deletions client/src/elm/Pages/Utils.elm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Backend.Utils exposing (reportToWhatsAppEnabled)
import Date
import EverySet exposing (EverySet)
import Gizra.Html exposing (emptyNode, showIf)
import Gizra.NominalDate exposing (NominalDate, formatDDMMYYYY)
import Gizra.NominalDate exposing (NominalDate, formatDDMMYYYY, toLastDayOfMonth)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
Expand Down Expand Up @@ -433,12 +433,7 @@ resolveSelectedDateForMonthSelector currentDate monthGap =

else
Date.add Date.Months (-1 * monthGap) currentDate
|> getLastDayOfMonth


getLastDayOfMonth : NominalDate -> NominalDate
getLastDayOfMonth =
Date.ceiling Date.Month >> Date.add Date.Days -1
|> toLastDayOfMonth



Expand Down
3 changes: 3 additions & 0 deletions server/elm/src/Backend/Scoreboard/Decoder.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Backend.Scoreboard.Model exposing (..)
import Backend.Scoreboard.Utils exposing (..)
import Date
import EverySet exposing (EverySet)
import Gizra.Json exposing (decodeInt)
import Gizra.NominalDate exposing (NominalDate, decodeYYYYMMDD, diffMonths)
import Json.Decode exposing (Decoder, andThen, bool, fail, list, map, maybe, string, succeed)
import Json.Decode.Pipeline exposing (optional, required)
Expand Down Expand Up @@ -47,6 +48,8 @@ decodeSelectedEntity =
decodePatientData : NominalDate -> Decoder PatientData
decodePatientData currentDate =
succeed PatientData
|> required "id" decodeInt
|> required "created" decodeYYYYMMDD
|> required "birth_date" decodeYYYYMMDD
|> required "edd_date" decodeYYYYMMDD
|> optional "low_birth_weight" (maybe bool) Nothing
Expand Down
4 changes: 3 additions & 1 deletion server/elm/src/Backend/Scoreboard/Model.elm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ type SelectedEntity


type alias PatientData =
{ birthDate : NominalDate
{ id : Int
, created : NominalDate
, birthDate : NominalDate
, eddDate : NominalDate
, lowBirthWeight : Maybe Bool
, nutrition : NutritionCriterionsData
Expand Down
16 changes: 14 additions & 2 deletions server/elm/src/Gizra/NominalDate.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Gizra.NominalDate exposing
, fromLocalDateTime
, diffDays, diffCalendarMonthsAndDays
, NominalDateRange, decodeDrupalRange, encodeDrupalRange
, allMonths, daysInMonth, diffCalendarMonths, diffCalendarYearsAndMonths, diffMonths, diffWeeks, diffYears, formatDDMMYY, formatDDMMYYYY, isDiffTruthy, isLeapYear, yearYYNumber
, allMonths, daysInMonth, diffCalendarMonths, diffCalendarYearsAndMonths, diffMonths, diffWeeks, diffYears, formatDDMMYY, formatDDMMYYYY, isDiffTruthy, isLeapYear, toLastDayOfMonth, yearYYNumber
)

{-| Some utilities for dealing with "pure" dates that have no time or
Expand All @@ -24,7 +24,7 @@ time zone information.
-}

import Date
import Date exposing (..)
import Json.Decode exposing (Decoder, andThen, field, map2, string)
import Json.Decode.Extra exposing (fromResult)
import Json.Encode exposing (Value, object)
Expand Down Expand Up @@ -91,6 +91,18 @@ fromLocalDateTime : Time.Posix -> NominalDate
fromLocalDateTime =
Date.fromPosix Time.utc

{-| Given a date, return date representing it's last month day.
toLastDayOfMonth 2019-08-01" --> 2019-08-31"
toLastDayOfMonth 2017-02-20" --> 2017-02-28"
-}
toLastDayOfMonth : NominalDate -> NominalDate
toLastDayOfMonth =
Date.floor Month
>> Date.add Months 1
>> Date.add Days -1


{-| Decodes nominal date from string of the form "2017-02-20".
Expand Down
Loading

0 comments on commit 47c3faa

Please sign in to comment.