Skip to content

Instantly share code, notes, and snippets.

@blt blt/met_or_resp.erl
Created Mar 19, 2014

Embed
What would you like to do?
-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
You can’t perform that action at this time.