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

5f7b80ce48272bf5c73bec961311096fb1d9af34 — Umgeher Torgersen 5 months ago 58fa26b
removed wb stuff
5 files changed, 1 insertions(+), 147 deletions(-)

M rebar.config
M src/utos_usr_local_hcs_exam_ecg.erl
D src/utos_usr_local_hcs_exam_ecg_wb_create.erl
D src/utos_usr_local_hcs_exam_ecg_wb_delete.erl
D src/utos_usr_local_hcs_exam_ecg_wb_drop.erl
M rebar.config => rebar.config +0 -2
@@ 7,8 7,6 @@
        {utos_usr_local_bus, {git, "https://git.sr.ht/~umgeher/utos-usr-local-bus", {tag, "0.1.1"}}},
        {utos_usr_local_hcs_exam_include, 
         {git, "https://git.sr.ht/~umgeher/utos-usr-local-hcs-exam-include", {tag, "0.1.3"}}},
        {utos_usr_local_hcs_exam_ecg_corelead_generator,
         {git, "https://git.sr.ht/~umgeher/utos-usr-local-hcs-exam-ecg-corelead-generator", {tag, "0.2.1"}}},
        {utos_usr_local_hcs_exam_ecg_storage,
         {git, "https://git.sr.ht/~umgeher/utos-usr-local-hcs-exam-ecg-storage", {tag, "0.6.0"}}},
        {utos_usr_local_hcs_exam_w_qt_ai,

M src/utos_usr_local_hcs_exam_ecg.erl => src/utos_usr_local_hcs_exam_ecg.erl +1 -48
@@ 21,15 21,7 @@
         settings_ecg_pause_min/0,
         settings_ecg_pause_max/0,
         settings_influx_db/0,
         uid/1,
         wb_create/1,
         wb_create/2,
         wb_delete/2,
         wb_delete/3,
         wb_drop/1,
         wb_drop/2,
         wb_uid/1,
         wb_uid/2
         uid/1
        ]).

corelead_drop(Exam) when is_binary(Exam) ->


@@ 107,42 99,3 @@ settings_influx_db() ->

uid(Exam) ->
    utos_crypto:sha256({hex, ["HCS-EXAM-ECG:", Exam]}).

wb_create(WB) when is_record(WB, wb) ->
    {ok, DB} = settings_influx_db(),
    {ok, Pid} = influx(),
    {ok, TaskID} = utos_usr_local_tsk:new(#tsk{tag = {wb, create}}),
    spawn(utos_usr_local_hcs_exam_ecg_wb_create, create, [WB, {Pid, DB}, TaskID]),
    {ok, TaskID}.

wb_create(Exam, Phy) ->
    wb_create(#wb{exam = Exam, phy = Phy}).

wb_delete(WB, TS) when is_record(WB, wb) ->
    {ok, DB} = settings_influx_db(),
    {ok, Pid} = influx(),
    {ok, TaskID} = utos_usr_local_tsk:new(#tsk{tag = {wb, delete}}),
    spawn(utos_usr_local_hcs_exam_ecg_wb_delete, delete, [WB, TS, {Pid, DB}]),
    {ok, TaskID}.

wb_delete(Exam, Phy, TS) ->
    wb_delete(#wb{exam = Exam, phy = Phy}, TS).

wb_drop(WB) when is_record(WB, wb) ->
    {ok, DB} = settings_influx_db(),
    {ok, Pid} = influx(),
    {ok, TaskID} = utos_usr_local_tsk:new(#tsk{tag = {wb, drop}}),
    spawn(utos_usr_local_hcs_exam_ecg_wb_drop, drop, [WB, {Pid, DB}]),
    {ok, TaskID}.

wb_drop(Exam, Phy) when is_binary(Exam), is_binary(Phy) ->
    wb_drop(#wb{exam = Exam, phy = Phy}).

wb_uid(#wb{exam = Exam, ecg = null, uid = null} = WB) when is_binary(Exam) ->
    {ok, ECG} = uid(Exam),
    wb_uid(WB#wb{ecg = ECG});
wb_uid(#wb{ecg = ECG, phy = Phy, uid = null}) when is_binary(ECG), is_binary(Phy) ->
    utos_crypto:sha256({hex, ["HCS-EXAM-ECG-WB:", ECG, "|", Phy]}).

wb_uid(ECG, Phy) when is_binary(ECG), is_binary(Phy) ->
    wb_uid(#wb{ecg = ECG, phy = Phy}).

D src/utos_usr_local_hcs_exam_ecg_wb_create.erl => src/utos_usr_local_hcs_exam_ecg_wb_create.erl +0 -60
@@ 1,60 0,0 @@
-module(utos_usr_local_hcs_exam_ecg_wb_create).

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

-export([create/3]).

create(#wb{ecg = null, exam = Exam, uid = null} = WB, Influx, TSK) ->
    {ok, ECG} = utos_usr_local_hcs_exam_ecg:uid(Exam),
    create(WB#wb{ecg = ECG}, Influx, TSK);
create(#wb{ecg = ECG, phy = Phy, uid = null} = WB, Influx, TSK) ->
    {ok, UID} = utos_usr_local_hcs_exam_ecg:wb_uid(ECG, Phy),
    create(WB#wb{uid = UID}, Influx, TSK);
create(WB, Influx, TSK) ->
    {ok, update} = utos_usr_local_tsk:update_obj(TSK, WB#wb.uid),
    {ok, drop} = utos_usr_local_hcs_exam_ecg:wb_drop(WB),
    {ok, update} = utos_usr_local_tsk:update(TSK, <<"drop done">>),
    {ok, seek} = seek(WB, Influx, 0),
    {ok, done} = utos_usr_local_tsk:done(TSK),
    {ok, WB#wb.uid}.

data_to_lp(_, [], Swap) ->
    {ok, Swap};
data_to_lp(#wb{uid = UID} = WB, [[Time, Label, Lead, _, C1, C2, C3] | T], Swap) ->
    LP = #lp{
            f = [{"value", 0}],
            m = erlang:binary_to_list(UID),
            t = [
                 {"cluster_l1", C1},
                 {"cluster_l2", C2},
                 {"cluster_l3", C3},
                 {"label", Label},
                 {"lead_origin", Lead}
                ],
            ts = Time
           },
    data_to_lp(WB, T, lists:append(Swap, [LP])).

seek(#wb{ecg = ECG} = WB, {Influx, DB}, TS) ->
    Query = "SELECT time, label, lead_origin, value, cluster_l1, cluster_l2, cluster_l3 FROM \""
        ++ erlang:binary_to_list(ECG) ++ "_golden_l0\" WHERE time > "
        ++ erlang:integer_to_list(TS) ++ " LIMIT 3000",
    case catch utos_usr_db_influx:query(Influx, DB, Query) of
        {ok, {_, #{<<"results">> := [#{<<"series">> := [#{<<"values">> := R}]}]}}} ->
            {ok, LP} = data_to_lp(WB, R, []),
            {ok, Data} = utos_usr_db_influx:lp_encode(LP),
            {ok, write} = write(Influx, DB, Data),
            [TF | _ ] = lists:last(R),
            seek(WB, {Influx, DB}, TF);
        _ ->
            {ok, seek}
    end.

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

D src/utos_usr_local_hcs_exam_ecg_wb_delete.erl => src/utos_usr_local_hcs_exam_ecg_wb_delete.erl +0 -21
@@ 1,21 0,0 @@
-module(utos_usr_local_hcs_exam_ecg_wb_delete).

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

-export([delete/4]).

delete(WB, [T0, T1], Influx, TSK) when is_binary(T0) ->
    delete(WB, [erlang:binary_to_integer(T0), T1], Influx, TSK);
delete(WB, [T0, T1], Influx, TSK) when is_binary(T1) ->
    delete(WB, [T0, erlang:binary_to_integer(T1)], Influx, TSK);
delete(#wb{ecg = null, exam = Exam, uid = null} = WB, TS, Influx, TSK) ->
    {ok, ECG} = utos_usr_local_Hcs_exam_ecg:uid(Exam),
    delete(WB#wb{ecg = ECG}, TS, Influx, TSK);
delete(#wb{ecg = ECG, phy = Phy, uid = null} = WB, TS, Influx, TSK) ->
    {ok, UID} = utos_usr_local_hcs_exam_ecg:wb_uid(ECG, Phy),
    delete(WB#wb{uid = UID}, TS, Influx, TSK);
delete(#wb{uid = UID}, [T0, T1], {Influx, DB}, TSK) when is_binary(UID) ->
    _ = utos_usr_db_influx:delete(Influx, DB, UID, [T0, T1]),
    _ = utos_usr_local_tsk:done(TSK),
    {ok, delete}.

D src/utos_usr_local_hcs_exam_ecg_wb_drop.erl => src/utos_usr_local_hcs_exam_ecg_wb_drop.erl +0 -16
@@ 1,16 0,0 @@
-module(utos_usr_local_hcs_exam_ecg_wb_drop).

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

-export([drop/2]).

drop(#wb{ecg = ECG, phy = Phy, uid = null} = WB, Influx) when is_binary(ECG), is_binary(Phy) ->
    {ok, UID} = utos_usr_local_hcs_exam_ecg:wb_uid(ECG, Phy),
    drop(WB#wb{uid = UID}, Influx);
drop(#wb{exam = Exam, uid = null} = WB, Influx) when is_binary(Exam) ->
    {ok, ECG} = utos_usr_local_hcs_exam_ecg:uid(Exam),
    drop(WB#wb{ecg = ECG}, Influx);
drop(#wb{uid = UID} = WB, {Influx, DB}) when is_binary(UID) ->
    utos_usr_local_hcs_exam_ecg:notify_bus({wb, drop, WB}),
    _ = utos_usr_db_influx:drop_measurement(Influx, DB, UID),
    {ok, drop}.