-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5dc825
commit c8847b2
Showing
120 changed files
with
3,241 additions
and
2,327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
override.exs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...gers/icu_occupancy/daily_icu_occupancy.ex → ...agers/hospital_capacity/daily_icu_rate.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
defmodule HealthBoard.Contexts.Info.Sources do | ||
alias HealthBoard.Contexts.Info.Source | ||
alias HealthBoard.Repo | ||
|
||
@type schema :: %Source{} | ||
|
||
@schema Source | ||
|
||
@spec get(String.t()) :: {:ok, schema} | {:error, :not_found} | ||
def get(id) do | ||
case Repo.get(@schema, id) do | ||
nil -> {:error, :not_found} | ||
struct -> {:ok, struct} | ||
end | ||
end | ||
|
||
@spec update(String.t(), map) :: {:ok, schema} | {:error, Ecto.Changeset.t()} | ||
def update(id, params) do | ||
with {:ok, struct} <- get(id) do | ||
struct | ||
|> @schema.changeset(params) | ||
|> Repo.update() | ||
end | ||
end | ||
end |
4 changes: 2 additions & 2 deletions
4
...chemas/icu_occupancy/day_icu_occupancy.ex → ...schemas/hospital_capacity/day_icu_rate.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
defmodule HealthBoard.Contexts.Seeder do | ||
alias HealthBoard.Repo | ||
require Logger | ||
|
||
@spec csv_from_context!(String.t(), String.t(), list(atom), String.t() | nil) :: :ok | ||
def csv_from_context!(context, table_name, fields, base_path \\ nil) do | ||
base_path | ||
|> Kernel.||(data_path()) | ||
|> Path.join(context) | ||
|> Path.join(table_name <> ".csv") | ||
|> csv_from_file_path!(table_name, fields) | ||
end | ||
|
||
@spec csvs_from_context!(String.t(), String.t(), list(atom), String.t() | nil) :: :ok | ||
def csvs_from_context!(context, table_name, fields, base_path \\ nil) do | ||
context | ||
|> Path.join(table_name) | ||
|> csvs_from_path!(table_name, fields, base_path) | ||
end | ||
|
||
@spec csvs_from_path!(String.t(), String.t(), list(atom), String.t() | nil) :: :ok | ||
def csvs_from_path!(path, table_name, fields, base_path \\ nil) do | ||
path = Path.join(base_path || data_path(), path) | ||
|
||
path | ||
|> File.ls!() | ||
|> Enum.sort() | ||
|> Enum.map(&Path.join(path, &1)) | ||
|> Enum.each(&csv_from_file_path!(&1, table_name, fields)) | ||
end | ||
|
||
@spec csv_from_file_path!(String.t(), String.t(), list(atom)) :: :ok | ||
def csv_from_file_path!(path, table_name, fields) do | ||
Logger.info(~s(Seeding #{Path.basename(path)} for table #{table_name})) | ||
|
||
path | ||
|> csv_copy_query(table_name, fields) | ||
|> Repo.query!() | ||
|
||
:ok | ||
end | ||
|
||
defp csv_copy_query(csv_path, table_name, fields) do | ||
fields = Enum.join(fields, ",") | ||
"COPY #{table_name}(#{fields}) FROM '#{csv_path}' WITH CSV;" | ||
end | ||
|
||
defp data_path do | ||
Application.get_env(:health_board, :data_path) | ||
end | ||
|
||
@spec down!(String.t()) :: :ok | ||
def down!(table_name) do | ||
Repo.query!("TRUNCATE #{table_name} CASCADE;") | ||
:ok | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
defmodule HealthBoard.Contexts.Seeders.Demographic do | ||
alias HealthBoard.Contexts.Seeders | ||
|
||
@spec down!(keyword) :: :ok | ||
def down!(opts \\ []) do | ||
what = Keyword.get(opts, :what, :all) | ||
|
||
if what in [:all, :yearly_populations], do: Seeders.YearlyPopulations.down!() | ||
|
||
:ok | ||
end | ||
|
||
@spec reseed!(keyword) :: :ok | ||
def reseed!(opts \\ []) do | ||
down!(opts) | ||
up!(opts) | ||
end | ||
|
||
@spec up!(keyword) :: :ok | ||
def up!(opts \\ []) do | ||
what = Keyword.get(opts, :what, :all) | ||
base_path = Keyword.get(opts, :base_path) | ||
|
||
if what in [:all, :yearly_populations], do: Seeders.YearlyPopulations.up!(base_path) | ||
|
||
:ok | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
defmodule HealthBoard.Contexts.Seeders.FluSyndrome do | ||
alias HealthBoard.Contexts.Seeders | ||
|
||
@spec down!(keyword) :: :ok | ||
def down!(opts \\ []) do | ||
what = Keyword.get(opts, :what, :all) | ||
|
||
if what in [:all, :flu_syndrome, :daily_flu_syndrome_cases], do: Seeders.DailyFluSyndromeCases.down!() | ||
if what in [:all, :flu_syndrome, :weekly_flu_syndrome_cases], do: Seeders.WeeklyFluSyndromeCases.down!() | ||
if what in [:all, :flu_syndrome, :monthly_flu_syndrome_cases], do: Seeders.MonthlyFluSyndromeCases.down!() | ||
if what in [:all, :flu_syndrome, :pandemic_flu_syndrome_cases], do: Seeders.PandemicFluSyndromeCases.down!() | ||
|
||
:ok | ||
end | ||
|
||
@spec reseed!(keyword) :: :ok | ||
def reseed!(opts \\ []) do | ||
down!(opts) | ||
up!(opts) | ||
end | ||
|
||
@spec up!(keyword) :: :ok | ||
def up!(opts \\ []) do | ||
what = Keyword.get(opts, :what, :all) | ||
base_path = Keyword.get(opts, :base_path) | ||
|
||
if what in [:all, :flu_syndrome, :pandemic_flu_syndrome_cases], do: Seeders.PandemicFluSyndromeCases.up!(base_path) | ||
if what in [:all, :flu_syndrome, :monthly_flu_syndrome_cases], do: Seeders.MonthlyFluSyndromeCases.up!(base_path) | ||
if what in [:all, :flu_syndrome, :weekly_flu_syndrome_cases], do: Seeders.WeeklyFluSyndromeCases.up!(base_path) | ||
if what in [:all, :flu_syndrome, :daily_flu_syndrome_cases], do: Seeders.DailyFluSyndromeCases.up!(base_path) | ||
|
||
:ok | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.