All files / src/reducers news.js

100% Statements 23/23
100% Branches 10/10
100% Functions 1/1
100% Lines 23/23

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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277                                                    38x                                   38x           38x                                     38x           38x                                   38x           38x                                   38x           38x                                                   38x             38x                                   38x                                                                                   38x                         667x     6x         7x         6x         6x         17x         6x         3x         5x         611x        
/*
 * 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
 
/**
 * This is an object that is used to build the union in {@link BPValuesType}. It is
 * also used to build {@link BPValues}, which is probably what you're after.
 */
const BPValuesList = {
    'under91': 'under91',
    '91-100' : '91-100',
    '101-110': '101-110',
    '111-219': '111-219',
    'over219': 'over219',
};
 
/**
 * Type for BP values
 */
export type BPValuesType = $Keys<typeof BPValuesList>;
 
/*
 * You can use this to refine a value and make sure it is one of the elements in
 * BPValuesType. If a BPValues[string] === 1, then it is a valid value for
 * BPValuesType.
 */
export const BPValues: { [key: string]: ?BPValuesType} = BPValuesList;
 
/**
 * This is an object that is used to build the union in {@link pulseValuesType}. It is
 * also used to build {@link pulseValues}, which is probably what you're after.
 */
const pulseValuesList ={
    'under41': 'under41',
    '41-50'  : '41-50',
    '51-90'  : '51-90',
    '91-110' : '91-110',
    '111-130': '111-130',
    'over130': 'over130',
};
 
/**
 * Type for pulse values
 */
export type pulseValuesType = $Keys<typeof pulseValuesList>;
 
/*
 * You can use this to refine a value and make sure it is one of the elements in
 * pulseValuesType. If a pulseValues[string] === 1, then it is a valid value for
 * pulseValuesType.
 */
export const pulseValues: { [key: string]: ?pulseValuesType} = pulseValuesList;
 
/**
 * This is an object that is used to build the union in {@link tempValuesType}. It is
 * also used to build {@link tempValues}, which is probably what you're after.
 */
const tempValuesList = {
    'under35.1': 'under35.1',
    '35.1-36.0': '35.1-36.0',
    '36.1-38.0': '36.1-38.0',
    '38.1-39.0': '38.1-39.0',
    'over39.0' : 'over39.0',
};
 
/**
 * Type for temp values
 */
export type tempValuesType = $Keys<typeof tempValuesList>;
 
/*
 * You can use this to refine a value and make sure it is one of the elements in
 * tempValuesType. If a tempValues[string] === 1, then it is a valid value for
 * tempValuesType.
 */
export const tempValues: { [key: string]: ?tempValuesType} = tempValuesList;
 
/**
 * This is an object that is used to build the union in {@link RFValuesType}. It is
 * also used to build {@link RFValues}, which is probably what you're after.
 */
const RFValuesList = {
    'under9': 'under9',
    '9-11'  : '9-11',
    '12-20' : '12-20',
    '21-24' : '21-24',
    'over24': 'over24',
};
 
/**
 * Type for RF values
 */
export type RFValuesType = $Keys<typeof RFValuesList>;
 
/*
 * You can use this to refine a value and make sure it is one of the elements in
 * RFValuesType. If a RFValues[string] === 1, then it is a valid value for
 * RFValuesType.
 */
export const RFValues: { [key: string]: ?RFValuesType} = RFValuesList;
 
/**
 * This is an object that is used to build the union in {@link SpO2ValuesType}. It is
 * also used to build {@link SpO2Values}, which is probably what you're after.
 */
const SpO2ValuesList = {
    'under92'   : 'under92',
    '92-93'     : '92-93',
    '94-95'     : '94-95',
    'over95'    : 'over95',
 
    // Alternate
    'under84'   : 'under84',
    '84-85'     : '84-85',
    '86-87'     : '86-87',
    '88-92'     : '88-92',
    '93-94'     : '93-94',
    '94-96'     : '94-96',
    'over96'    : 'over96',
};
 
/**
 * Type for SpO2 values
 */
export type SpO2ValuesType = $Keys<typeof SpO2ValuesList>;
 
/*
 * You can use this to refine a value and make sure it is one of the elements in
 * SpO2ValuesType. If a SpO2Values[string] === 1, then it is a valid value for
 * SpO2ValuesType.
 */
export const SpO2Values: { [key: string]: ?SpO2ValuesType} = SpO2ValuesList;
 
/**
 * This is an object that is used to build the union in {@link
 * consciousnessValuesType}. It is also used to build {@link
 * consciousnessValues}, which is probably what you're after.
 */
export const consciousnessValuesList = {
    'awake'   : 'awake',
    'confused': 'confused',
    'speech'  : 'speech',
    'pain'    : 'pain',
    'none'    : 'none',
};
 
/**
 * Type for consciousness state
 */
export type consciousnessValuesType = $Keys<typeof consciousnessValuesList>;
 
/*
 * You can use this to refine a value and make sure it is one of the elements
 * in consciousnessValuesType. If a consciousnessValues[string] === 1, then it
 * is a valid value for consciousnessValuesType.
 */
export const consciousnessValues: { [key: string]: ?consciousnessValuesType} = consciousnessValuesList;
 
/**
 * The news redux state
 */
export type newsState = {|
    BP              : BPValuesType            | null,
    pulse           : pulseValuesType         | null,
    temp            : tempValuesType          | null,
    RF              : RFValuesType            | null,
    SpO2            : SpO2ValuesType          | null,
    consciousness   : consciousnessValuesType | null,
    usingO2         : boolean,
    alternateO2Table: boolean,
|};
/**
 * Actions accepted by the news reducer
 */
export type newsAction = {|
    type         : 'NEWS_SET_BP',
    BP           : BPValuesType              | null
|} | {|
    type         : 'NEWS_SET_PULSE',
    pulse        : pulseValuesType           | null
|} | {|
    type         : 'NEWS_SET_TEMP',
    temp         : tempValuesType            | null
|} | {|
    type         : 'NEWS_SET_RF',
    RF           : RFValuesType              | null
|} | {|
    type         : 'NEWS_SET_SPO2',
    SpO2         : SpO2ValuesType            | null
|} | {|
    type         : 'NEWS_SET_CONSCIOUSNESS',
    consciousness: consciousnessValuesType   | null
|} | {|
    type         : 'NEWS_TOGGLE_ALTERNATEO2TABLE'
|} | {|
    type         : 'NEWS_TOGGLE_O2'
|};
 
const initialState: newsState = {
    BP              : null,
    pulse           : null,
    temp            : null,
    RF              : null,
    SpO2            : null,
    consciousness   : null,
    usingO2         : false,
    alternateO2Table: false,
};
 
function news (state: newsState = initialState,action: newsAction): newsState
{
    switch(action.type)
    {
        case 'NEWS_SET_BP':
        return {
                ...state,
                BP: action.BP
            };
        case 'NEWS_SET_PULSE':
        return {
                ...state,
                pulse: action.pulse
            };
        case 'NEWS_SET_TEMP':
        return {
                ...state,
                temp: action.temp
            };
        case 'NEWS_SET_RF':
        return {
                ...state,
                RF: action.RF
            };
        case 'NEWS_SET_SPO2':
        return {
                ...state,
                SpO2: action.SpO2
            };
        case 'NEWS_SET_CONSCIOUSNESS':
        return {
                ...state,
                consciousness: action.consciousness
            };
        case 'NEWS_TOGGLE_O2':
            return {
                ...state,
                usingO2: !state.usingO2
            };
        case 'NEWS_TOGGLE_ALTERNATEO2TABLE':
            return {
                ...state,
                alternateO2Table: !state.alternateO2Table
            };
        default:
            return state;
    }
}
export default news;