Reactive state cookie
This commit is contained in:
parent
030487d728
commit
6ae57cfd79
@ -44,7 +44,6 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import cookie from './cookie.mjs';
|
|
||||||
import vistax from './vistax.mjs';
|
import vistax from './vistax.mjs';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -74,7 +73,7 @@
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
show: false,
|
show: false,
|
||||||
host: cookie.get('host'),
|
host: vistax.state.host,
|
||||||
x_client: this.client,
|
x_client: this.client,
|
||||||
x_server: this.server,
|
x_server: this.server,
|
||||||
x_user: this.user,
|
x_user: this.user,
|
||||||
@ -85,7 +84,7 @@
|
|||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
host(value) {
|
host(value) {
|
||||||
cookie.set('host', value);
|
vistax.state.host = value;
|
||||||
this.logout();
|
this.logout();
|
||||||
},
|
},
|
||||||
client(value) { this.x_client = value; },
|
client(value) { this.x_client = value; },
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import cookie from './cookie.mjs';
|
import { state } from './vistax.mjs';
|
||||||
import { groupByArray, strtr_unscramble, strHashHSL, strftime_vista, debounce } from './util.mjs';
|
import { groupByArray, strtr_unscramble, strHashHSL, strftime_vista, debounce } from './util.mjs';
|
||||||
|
|
||||||
import ViewResourceLookup from './ViewResourceLookup.vue';
|
import ViewResourceLookup from './ViewResourceLookup.vue';
|
||||||
@ -62,7 +62,7 @@
|
|||||||
client: Object
|
client: Object
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
var resources = cookie.get('vista.resources');
|
var resources = state.resources;
|
||||||
var today = dateonly(new Date());
|
var today = dateonly(new Date());
|
||||||
return {
|
return {
|
||||||
selection: resources ? (resources.split(',').filter(x => x) || []) : [],
|
selection: resources ? (resources.split(',').filter(x => x) || []) : [],
|
||||||
@ -95,7 +95,7 @@
|
|||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.debounced_selection = debounce(async function(value) {
|
this.debounced_selection = debounce(async function(value) {
|
||||||
cookie.set('vista.resources', value.join(','), 7);
|
state.resources = value.join(',');
|
||||||
var patients = this.selection.length > 0 ? groupByArray(await this.client.SDEC_CLINLET(this.selection.join('|') + '|', strftime_vista(this.date_begin), strftime_vista(this.date_end)), x => x.HRN) : [], now = new Date(), group, values, appt;
|
var patients = this.selection.length > 0 ? groupByArray(await this.client.SDEC_CLINLET(this.selection.join('|') + '|', strftime_vista(this.date_begin), strftime_vista(this.date_end)), x => x.HRN) : [], now = new Date(), group, values, appt;
|
||||||
for(var i = patients.length - 1; i >= 0; --i) {
|
for(var i = patients.length - 1; i >= 0; --i) {
|
||||||
group = patients[i];
|
group = patients[i];
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import cookie from './cookie.mjs';
|
import { state } from './vistax.mjs';
|
||||||
|
|
||||||
import ViewResourceLookup from './ViewResourceLookup.vue';
|
import ViewResourceLookup from './ViewResourceLookup.vue';
|
||||||
import DateRangePicker from './DateRangePicker.vue';
|
import DateRangePicker from './DateRangePicker.vue';
|
||||||
@ -37,7 +37,7 @@
|
|||||||
client: Object
|
client: Object
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
var resources = cookie.get('vista.resources');
|
var resources = state.resources;
|
||||||
return {
|
return {
|
||||||
selection: resources ? (resources.split(',').filter(x => x) || []) : [],
|
selection: resources ? (resources.split(',').filter(x => x) || []) : [],
|
||||||
date: dateonly(new Date()),
|
date: dateonly(new Date()),
|
||||||
@ -46,7 +46,7 @@
|
|||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
selection(value, oldvalue) {
|
selection(value, oldvalue) {
|
||||||
cookie.set('vista.resources', value.join(','), 7);
|
state.resources = value.join(',');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import cookie from './cookie.mjs';
|
import { state } from './vistax.mjs';
|
||||||
import { uniq, strtr_unscramble, strHashHSL, strfdate_vista, debounce } from './util.mjs';
|
import { uniq, strtr_unscramble, strHashHSL, strfdate_vista, debounce } from './util.mjs';
|
||||||
|
|
||||||
import Autocomplete from './Autocomplete.vue';
|
import Autocomplete from './Autocomplete.vue';
|
||||||
@ -60,15 +60,15 @@
|
|||||||
strtr_unscramble,
|
strtr_unscramble,
|
||||||
set_practitioner(patient, practitioner) {
|
set_practitioner(patient, practitioner) {
|
||||||
this.practitioner[patient] = practitioner;
|
this.practitioner[patient] = practitioner;
|
||||||
cookie.set('vista.practitioner', JSON.stringify(this.practitioner), 1);
|
state.practitioner = this.practitioner;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.debounced_params = debounce(async function(value) { this.appointments = value.selection.length > 0 ? (await this.client.SDEC_CLINLET(value.selection.join('|') + '|', strfdate_vista(value.date_begin), strfdate_vista(value.date_end))).sort((a, b) => (new Date(a.ApptDate)) - (new Date(b.ApptDate))) : []; }, 500);
|
this.debounced_params = debounce(async function(value) { this.appointments = value.selection.length > 0 ? (await this.client.SDEC_CLINLET(value.selection.join('|') + '|', strfdate_vista(value.date_begin), strfdate_vista(value.date_end))).sort((a, b) => (new Date(a.ApptDate)) - (new Date(b.ApptDate))) : []; }, 500);
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
var practitioner = cookie.get('vista.practitioner');
|
var practitioner = state.practitioner;
|
||||||
if(practitioner) this.practitioner = JSON.parse(practitioner);
|
if(practitioner) this.practitioner = practitioner;
|
||||||
this.production = (await this.client.serverinfo()).result.production == '1';
|
this.production = (await this.client.serverinfo()).result.production == '1';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,8 +1,16 @@
|
|||||||
|
import { reactive, watch } from 'vue';
|
||||||
|
|
||||||
import vista from './vista.mjs';
|
import vista from './vista.mjs';
|
||||||
import cookie from './cookie.mjs';
|
import cookie from './cookie.mjs';
|
||||||
import { lab_parse, lab_reparse_results, measurement_parse } from './reportparser.mjs';
|
import { lab_parse, lab_reparse_results, measurement_parse } from './reportparser.mjs';
|
||||||
|
|
||||||
const COOKIE_TIME = 45;
|
export const state = reactive(cookie.get('state') ? JSON.parse(cookie.get('state')) : {});
|
||||||
|
if((!state.secret) && (cookie.get('secret'))) state.resources = cookie.get('secret');
|
||||||
|
if((!state.cid) && (cookie.get('cid'))) state.resources = cookie.get('cid');
|
||||||
|
if((!state.host) && (cookie.get('host'))) state.resources = cookie.get('host');
|
||||||
|
if((!state.resources) && (cookie.get('vista.resources'))) state.resources = cookie.get('vista.resources');
|
||||||
|
if((!state.practitioner) && (cookie.get('vista.practitioner'))) state.practitioner = JSON.parse(cookie.get('vista.practitioner'));
|
||||||
|
watch(state, value => cookie.set('state', JSON.stringify(value), 45), { immediate: true, deep: true });
|
||||||
|
|
||||||
function RPCError(type, ...args) {
|
function RPCError(type, ...args) {
|
||||||
this.name = type;
|
this.name = type;
|
||||||
@ -131,57 +139,57 @@ Client.fromScratch = async function(secret, host='vista.northport.med.va.gov', p
|
|||||||
};
|
};
|
||||||
|
|
||||||
Client.fromCookie = async function(secret, defaulthost='vista.northport.med.va.gov:19209') {
|
Client.fromCookie = async function(secret, defaulthost='vista.northport.med.va.gov:19209') {
|
||||||
if(!secret) secret = cookie.get('secret');
|
if(!secret) secret = state.secret;
|
||||||
if(secret) {
|
if(secret) {
|
||||||
var host = cookie.get('host');
|
var host = state.host;
|
||||||
host = (host || defaulthost).split(':');
|
host = (host || defaulthost).split(':');
|
||||||
if(secret != cookie.get('secret')) {
|
if(secret != state.secret) {
|
||||||
console.log('Using new secret', secret);
|
console.log('Using new secret', secret);
|
||||||
var client = await Client.fromScratch(secret, host[0], host[1]);
|
var client = await Client.fromScratch(secret, host[0], host[1]);
|
||||||
if(client) {
|
if(client) {
|
||||||
cookie.set('host', host.join(':'), COOKIE_TIME);
|
state.host = host.join(':');
|
||||||
cookie.set('secret', secret);
|
state.secret = secret;
|
||||||
cookie.set('cid', client.cid);
|
state.cid = client.cid;
|
||||||
console.log('Established connection', client.cid);
|
console.log('Established connection', client.cid);
|
||||||
return client;
|
return client;
|
||||||
} else {
|
} else {
|
||||||
cookie.reset('secret');
|
delete state.secret;
|
||||||
cookie.reset('cid');
|
delete state.cid;
|
||||||
console.log('Failed to connect');
|
console.log('Failed to connect');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} else if(!cookie.get('cid')) {
|
} else if(!state.cid) {
|
||||||
console.log('Using saved secret', secret);
|
console.log('Using saved secret', secret);
|
||||||
var client = await Client.fromScratch(secret, host[0], host[1]);
|
var client = await Client.fromScratch(secret, host[0], host[1]);
|
||||||
if(client) {
|
if(client) {
|
||||||
cookie.set('host', host.join(':'), COOKIE_TIME);
|
state.host = host.join(':');
|
||||||
cookie.set('secret', secret);
|
state.secret = secret;
|
||||||
cookie.set('cid', client.cid);
|
state.cid = client.cid;
|
||||||
console.log('Established connection', client.cid);
|
console.log('Established connection', client.cid);
|
||||||
return client;
|
return client;
|
||||||
} else {
|
} else {
|
||||||
cookie.reset('secret');
|
delete state.secret;
|
||||||
cookie.reset('cid');
|
delete state.cid;
|
||||||
console.log('Failed connection');
|
console.log('Failed connection');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('Using saved secret and connection', secret);
|
console.log('Using saved secret and connection', secret);
|
||||||
var cid = cookie.get('cid');
|
var cid = state.cid;
|
||||||
var client = Client.fromID(cid, secret);
|
var client = Client.fromID(cid, secret);
|
||||||
if((await vista.call(cid, 'XWB_IM_HERE')).result == '1') {
|
if((await vista.call(cid, 'XWB_IM_HERE')).result == '1') {
|
||||||
var server = await client.serverinfo();
|
var server = await client.serverinfo();
|
||||||
if((host[0] == server.result.host) && (host[1] == server.result.port)) {
|
if((host[0] == server.result.host) && (host[1] == server.result.port)) {
|
||||||
cookie.set('host', host.join(':'), COOKIE_TIME);
|
state.host = host.join(':');
|
||||||
return client;
|
return client;
|
||||||
} else console.log('Rejecting previous connection to different server', server);
|
} else console.log('Rejecting previous connection to different server', server);
|
||||||
}
|
}
|
||||||
cookie.reset('cid');
|
delete state.cid;
|
||||||
return await Client.fromCookie(secret, host.join(':'));
|
return await Client.fromCookie(secret, host.join(':'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default window.vistax = {
|
export default window.vistax = {
|
||||||
RPCError, Client, connect: Client.fromCookie
|
state, RPCError, Client, connect: Client.fromCookie
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user