Skip to content

Instantly share code, notes, and snippets.

@blt
Created March 19, 2014 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blt/9651707 to your computer and use it in GitHub Desktop.
Save blt/9651707 to your computer and use it in GitHub Desktop.
-module(met_or_resp).
-export([whatdo/1]).
-type diagnosis() :: metabolic_acidosis |
respiratory_acidosis |
respiratory_alkalosis |
metabolic_acidosis_respiratory_alkalosis |
metabolic_acidosis_respiratory_acidosis |
respiratory_acidosis_metabolic_alkalosis |
respiratory_acidosis_metabolic_acidosis.
-record(body_chem, {
paco2 :: non_neg_integer(),
hco3 :: non_neg_integer()
}).
-define(PACOGOOD, 10).
-define(HCOGOOD, 10).
%%%===================================================================
%%% API
%%%===================================================================
-spec whatdo(#body_chem{}) -> diagnosis() | {error, patient_is_witch}.
whatdo(B=#body_chem{paco2=P, hco3=H}) when P > ?PACOGOOD, H > ?HCOGOOD ->
case inc(hco_cmp_paco, B) of
eq -> respiratory_acidosis;
gt -> respiratory_acidosis_metabolic_alkalosis;
lt -> respiratory_acidosis_metabolic_acidosis
end;
whatdo(B=#body_chem{paco2=P, hco3=H}) when P =< ?PACOGOOD, H =< ?HCOGOOD ->
case inc(paco_cmp_hco, B) of
eq -> metabolic_acidosis;
gt -> metabolic_acidosis_respiratory_alkalosis;
lt -> metabolic_acidosis_respiratory_acidosis
end;
whatdo(_) ->
{error, patient_is_witch}.
%%%===================================================================
%%% Internal Functions
%%%===================================================================
inc(hco_cmp_paco, #body_chem{paco2=P, hco3=H}) ->
cmp(H, P);
inc(paco_cmp_hco, #body_chem{paco2=P, hco3=H}) ->
cmp(P, H).
cmp(X, Y) when X > Y -> gt;
cmp(X, Y) when X < Y -> lt;
cmp(X, X) -> eq.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment