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

ref: 67b7a6f4e83990d7d5591d5cd8c3f01486a4efa4 utos-usr-local-hcs-exam-ecg/src/utos_usr_local_hcs_exam_ecg_raw.erl -rw-r--r-- 1.2 KiB
67b7a6f4Umgeher Torgersen qt-ai upgraded to 0.2.0 1 year, 23 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
-module(utos_usr_local_hcs_exam_ecg_raw).

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

-export([
         set/3,
         ts_first/1,
         ts_last/1
        ]).

-define(OP, <<"utos">>).

set(<<Exam/binary>>, TS, Data) ->
    {ok, UID} = utos_usr_local_hcs_exam_ecg:uid(Exam),
    ECG = #ecg{uid = UID, exam = Exam, ts_created = TS},
    {ok, TaskID} = utos_usr_local_tsk:new(#tsk{obj = ECG, tag = {ecg, {raw, set}}}),
    {ok, enqueue} = utos_usr_local_hcs_exam_ecg_storage:enqueue(TaskID, ECG, Data),
    {ok, TaskID}.

ts(<<Exam/binary>>, <<Name/binary>>) ->
    {ok, C} = utos_usr_local_hcs_exam_ecg:flux_context(Exam),
    case catch utos_usr_local_hcs_exam_ecg_influx_flux_exec:exec(?OP, Name, C) of
        {ok, {200, _, CSV}} ->
            {ok, Pid} = utos_usr_share_csv:start(CSV),
            [_, [Last, _]] = utos_usr_share_csv:next(Pid, 2),
            {ok, stop} = utos_usr_share_csv:stop(Pid),
            utos_datetime:rfc3339_to_ns(Last);
        _ ->
            {error, generic}
    end.

ts_first(<<Exam/binary>>) ->
    ts(Exam, <<"ecg-ts-first">>).

ts_last(<<Exam/binary>>) ->
    ts(Exam, <<"ecg-ts-last">>).