<template>
	<ViewData name="Vitals" :resultset="resultset" />
</template>

<script>
	import { strftime_vista } from './util.mjs';

	import ViewData from './ViewData.vue';

	const mapping = {
		'T': { range: '35 - 38' },
		'P': { range: '60 - 100', unit: 'bpm' },
		'R': { range: '12 - 19', unit: 'bpm' },
		'Pulse Oximetry': { range: '95 - 100' }
	};

	function normalize(rs) {
		return rs.map(function(x) {
			var res = {
				time: x.datetime,
				name: x.name,
				unit: x.unit,
				value: x.value,
				flag: x.flag,
				comment: x.user
			};
			return mapping[x.name] ? Object.assign(res, mapping[x.name]) : res;
		});
	}

	export default {
		components: {
			ViewData
		},
		props: {
			client: Object,
			dfn: String,
			date_begin: Date,
			date_end: Date
		},
		data() {
			return {
				resultset: null
			};
		},
		computed: {
			params() {
				return { dfn: this.dfn, date_begin: strftime_vista(this.date_begin), date_end: strftime_vista(this.date_end) };
			}
		},
		watch: {
			async params(value) {
				this.resultset = normalize(await this.client.GMV_EXTRACT_REC(value.dfn, value.date_end, value.date_begin));
			}
		}
	};
</script>
