~umgeher/utos-usr-local-hcs-exam-ecg

3e4705bf02c8d64a55b5e3fc1f3f63bdb641f7dc — Umgeher Torgersen 5 months ago 2fcf4d1 develop master 0.9.0
influx and etu removed
M src/utos_usr_local_hcs_exam_ecg.app.src => src/utos_usr_local_hcs_exam_ecg.app.src +0 -2
@@ 10,8 10,6 @@
    utos_crypto,
    utos_etc,
    utos_usr_local_bus,
    utos_usr_local_hcs_exam_ecg_corelead_generator,
    utos_usr_local_hcs_exam_ecg_influx,
    utos_usr_local_hcs_exam_ecg_storage,
    utos_usr_local_hcs_exam_w_qt_ai,
    utos_usr_local_hcs_exam_w_qt_etu,

M src/utos_usr_local_hcs_exam_ecg.erl => src/utos_usr_local_hcs_exam_ecg.erl +0 -1
@@ 8,7 8,6 @@
         corelead_uid/1,
         flux_context/1,
         flux_context/2,
         influx/0,
         notify_bus/1,
         process/2,
         raw_set/3,

M src/utos_usr_local_hcs_exam_ecg_corelead_etu.erl => src/utos_usr_local_hcs_exam_ecg_corelead_etu.erl +0 -74
@@ 1,85 1,11 @@
-module(utos_usr_local_hcs_exam_ecg_corelead_etu).

-include_lib("utos_usr_db_influx/src/utos_usr_db_influx.hrl").

-export([
         process/3,
         uid/1
        ]).

cl_to_etu_data([], Swap) ->
    {ok, Swap};
cl_to_etu_data([[Time, Label | _] | T], Swap) ->
    cl_to_etu_data(T, lists:append(Swap, [[Time, Label]])).

ect_to_influx(_, [], Swap) ->
    {ok, Swap};
ect_to_influx(UID, [#{<<"timestamp">> := TS, <<"label">> := L, <<"count">> := C, <<"max-bpm">> := MX, <<"min-bpm">> := MN, <<"average-bpm">> := AV} | T], Swap) ->
    LP = #lp{
            f = [{"count", C}, {"maxbpm", MX}, {"minbpm", MN}, {"avbpm", AV}],
            m = UID,
            t = [{"label", L}],
            ts = erlang:integer_to_list(TS)
           },
    ect_to_influx(UID, T, lists:append(Swap, [LP])).

pause_to_influx(_, [], Swap) ->
    {ok, Swap};
pause_to_influx(UID, [#{<<"timestamp">> := TS, <<"duration">> := V} | T], Swap) ->
    LP = #lp{
            f = [{"value", V}],
            m = UID,
            ts = erlang:integer_to_list(TS)
           },
    pause_to_influx(UID, T, lists:append(Swap, [LP])).

process(Exam, {T0, T1}, Influx) ->
    case catch utos_usr_local_hcs_exam_ecg:corelead_get(Exam, {T0, T1}) of
        {ok, CLData} ->
            {ok, Data} = cl_to_etu_data(CLData, []),
            {ok, MinMax} = utos_usr_local_hcs_exam_ecg:settings_ecg_pause(),
            {ok, service} = service_call(Exam, MinMax, Data, Influx);
        {'EXIT', {{badmatch, {ok, {200, #{<<"results">> := [#{<<"statement_id">> := 0}]}}}}, _}} ->
            {error, nodata};
        {error, generic} ->
            {error, nodata}
    end.

rr_to_influx(_, [], Swap) ->
    {ok, Swap};
rr_to_influx(UID, [[TS, Label, Interval] | T], Swap) ->
    LP = #lp{
            f = [{"value", Interval}],
            m = UID,
            t = [{"label", Label}],
            ts = erlang:integer_to_list(TS)
           },
    rr_to_influx(UID, T, lists:append(Swap, [LP])).

service_call(Exam, MinMax, Data, Influx) ->
    case catch utos_usr_local_hcs_exam_w_qt_etu:count_ectopies(MinMax, Data) of
        {ok, {RR, ECT, P}} ->
            {ok, {URR, UECT, UP}} = uid(Exam),
            {ok, LP0} = rr_to_influx(erlang:binary_to_list(URR), RR, []),
            {ok, LP1} = ect_to_influx(erlang:binary_to_list(UECT), ECT, []),
            {ok, LP2} = pause_to_influx(erlang:binary_to_list(UP), P, []),
            {ok, Payload} = utos_usr_db_influx:lp_encode(lists:append(LP0, lists:append(LP1, LP2))),
            {ok, write} = write(Influx, Payload),
            {ok, service};
        {error, Error} ->
            {error, Error}
    end.

uid(Exam) ->
    {ok, RR} = utos_crypto:sha256({hex, ["HCS-EXAM-ECG-CORELEAD-ETU-RR:", Exam]}),
    {ok, ECT} = utos_crypto:sha256({hex, ["HCS-EXAM-ECG-CORELEAD-ETU-ECTOPIES:", Exam]}),
    {ok, P} = utos_crypto:sha256({hex, ["HCS-EXAM-ECG-CORELEAD-ETU-PAUSE:", Exam]}),
    {ok, {RR, ECT, P}}.

write({Influx, DB}, Data) ->
    case catch utos_usr_db_influx:write(Influx, DB, Data) of
        {ok, {204, _}} ->
            {ok, write};
        {error, _} ->
            write({Influx, DB}, Data)
    end.

M src/utos_usr_local_hcs_exam_ecg_sup.erl => src/utos_usr_local_hcs_exam_ecg_sup.erl +1 -3
@@ 9,9 9,7 @@
-define(SERVER, ?MODULE).

start_link() ->
    R = supervisor:start_link({local, ?SERVER}, ?MODULE, []),
    utos_usr_local_hcs_exam_ecg_flux_setup:main(),
    R.
    supervisor:start_link({local, ?SERVER}, ?MODULE, []).

init([]) ->
    SupFlags = #{strategy => one_for_one,