All files / src/actions news.js

100% Statements 28/28
100% Branches 14/14
100% Functions 8/8
100% Lines 28/28

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168                                                            7x 7x   6x             1x                 8x 8x   7x             1x                 7x 7x   6x             1x                 7x 7x   6x             1x                 18x   3x             15x 15x   14x           1x               7x 7x   6x             1x                 5x                   3x            
/*
 * Part of Pleiar.no - a collection of tools for nurses
 *
 * Copyright (C) Fagforbundet 2020
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
 
// @flow
 
import type { newsAction } from '../reducers/news';
import { BPValues, pulseValues, tempValues, RFValues, SpO2Values, consciousnessValues } from '../reducers/news';
 
/**
 * Redux action. Sets the BP value for the NEWS calculator
 */
function setNewsBP(BP: string): newsAction
{
    const validated = BPValues[BP];
    if (validated)
    {
        return {
            type: 'NEWS_SET_BP',
            BP: validated
        };
    }
    else
    {
        throw('Invalid BP value: '+BP);
    }
}
 
/**
 * Redux action. Sets the BP value for the NEWS calculator
 */
function setNewsPulse(pulse: string): newsAction
{
    const validated = pulseValues[pulse];
    if (validated)
    {
        return {
            type: 'NEWS_SET_PULSE',
            pulse: validated
        };
    }
    else
    {
        throw('Invalid pulse value: '+pulse);
    }
}
 
/**
 * Redux action. Sets the BP value for the NEWS calculator
 */
function setNewsTemp(temp: string): newsAction
{
    const validated = tempValues[temp];
    if (validated)
    {
        return {
            type: 'NEWS_SET_TEMP',
            temp: validated
        };
    }
    else
    {
        throw('Invalid temp value: '+temp);
    }
}
 
/**
 * Redux action. Sets the RF value for the NEWS calculator
 */
function setNewsRF(RF: string): newsAction
{
    const validated = RFValues[RF];
    if (validated)
    {
        return {
            type: 'NEWS_SET_RF',
            RF: validated
        };
    }
    else
    {
        throw('Invalid RF value: '+RF);
    }
}
 
/**
 * Redux action. Sets the SpO2 value for the NEWS calculator
 */
function setNewsSpO2(SpO2: string | null): newsAction
{
    if(SpO2 == null)
    {
        return {
            type: 'NEWS_SET_SPO2',
            SpO2: null
        };
    }
    else
    {
        const validated = SpO2Values[SpO2];
        if (validated)
        {
            return {
                type: 'NEWS_SET_SPO2',
                SpO2: validated
            };
        }
    }
    throw('Invalid SpO2 value: '+SpO2);
}
 
/**
 * Redux action. Sets the consciousness state value for the NEWS calculator
 */
function setNewsConsciousness(consciousness: string): newsAction
{
    const validated = consciousnessValues[consciousness];
    if (validated)
    {
        return {
            type: 'NEWS_SET_CONSCIOUSNESS',
            consciousness: validated
        };
    }
    else
    {
        throw('Invalid consciousness value: '+consciousness);
    }
}
 
/**
 * Redux action. Toggles use of the alternate O2 table for NEWS
 */
function toggleNewsAlternateO2Table (): newsAction
{
    return {
        type: 'NEWS_TOGGLE_ALTERNATEO2TABLE'
    };
}
 
/**
 * Redux action. Toggles the O2 state for NEWS.
 */
function toggleNewsO2 (): newsAction
{
    return {
        type: 'NEWS_TOGGLE_O2'
    };
}
 
export { setNewsBP, setNewsConsciousness, setNewsRF, setNewsSpO2, setNewsTemp, setNewsPulse, toggleNewsO2, toggleNewsAlternateO2Table};