Skip to content

Commit b67c1af

Browse files
authored
create Template for simple note & update models a lot (#4)
* small cleanup * Fixed some models * Revert "Fixed some models" This reverts commit 4abde12. * fix token * Add base models for frontend * add editor component * add link to editor * method for getting templateinfo * Editor route implementation * fix for templateinfo method * dinamic add components to editor * try * add autosuggest to form * add tagging * save model * add date picker * add basic doctor's visit form * get scheme and model from backend * New models for json schemes * fix for getting scheme * Saving last opened document * little fix for post method * Add medicine class * Last openedDocumetns impl * Little fix * post&put now work together * AutoComplete fix * small fix
1 parent 8fdf662 commit b67c1af

39 files changed

Lines changed: 1161 additions & 232 deletions

ClientApp/@types/alltypes.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module 'vue-form-generator'
2+
declare module 'vue-search-select'
3+
declare module 'vue-multiselect';

ClientApp/auth/AuthService.ts

Lines changed: 64 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,78 @@
11
import auth0, { WebAuth } from 'auth0-js'
2-
import {EventEmitter} from '../models/EventEmmiter'
2+
import { EventEmitter } from '../models/EventEmmiter'
33
import Router from '../router/router'
4+
import { ApiService } from '../models/ApiService';
45

56

67
export default class AuthService {
7-
authenticated = this.isAuthenticated()
8-
auth0: WebAuth
9-
constructor(hostname:string, port:string, protocol:string) {
10-
this.login = this.login.bind(this);
11-
this.setSession = this.setSession.bind(this)
12-
this.logout = this.logout.bind(this)
13-
this.isAuthenticated = this.isAuthenticated.bind(this)
14-
var stringBuild = protocol + "//" + hostname;
15-
if (port !== "")
16-
stringBuild += ':' + port
17-
stringBuild += '/callback'
18-
this.auth0 = new auth0.WebAuth({
19-
domain: 'dotnextrussia.eu.auth0.com',
20-
clientID: 'g7saZcm47evyY3kWWP26ZxifDpxycl9h',
21-
redirectUri: stringBuild,
22-
audience: 'http://medhelp20171124063439.azurewebsites.net/',
23-
responseType: 'token id_token',
24-
scope: 'openid profile read:templates'
25-
});
26-
}
27-
8+
authenticated = this.isAuthenticated()
9+
auth0: WebAuth
10+
constructor(hostname: string, port: string, protocol: string) {
11+
this.login = this.login.bind(this);
12+
this.setSession = this.setSession.bind(this)
13+
this.logout = this.logout.bind(this)
14+
this.isAuthenticated = this.isAuthenticated.bind(this)
15+
var stringBuild = protocol + "//" + hostname;
16+
if (port !== "")
17+
stringBuild += ':' + port
18+
stringBuild += '/callback'
19+
this.auth0 = new auth0.WebAuth({
20+
domain: 'dotnextrussia.eu.auth0.com',
21+
clientID: 'g7saZcm47evyY3kWWP26ZxifDpxycl9h',
22+
redirectUri: stringBuild,
23+
audience: 'http://medhelp20171124063439.azurewebsites.net/',
24+
responseType: 'token id_token',
25+
scope: 'openid profile read:templates'
26+
});
27+
}
2828

2929

3030

31-
login() {
32-
this.auth0.authorize();
33-
}
3431

35-
handleAuthentication () {
36-
this.auth0.parseHash((err, authResult) => {
37-
if (authResult && authResult.accessToken && authResult.idToken) {
38-
this.setSession(authResult)
39-
Router.replace('home')
40-
} else if (err) {
41-
Router.replace('home')
42-
console.log(err)
43-
alert(`Error: ${err.error}. Check the console for further details.`)
44-
}
45-
})
46-
}
47-
48-
setSession (authResult : any) {
49-
// Set the time that the access token will expire at
50-
let expiresAt = JSON.stringify(
51-
authResult.expiresIn * 1000 + new Date().getTime()
52-
)
53-
localStorage.setItem('access_token', authResult.accessToken)
54-
localStorage.setItem('id_token', authResult.idToken)
55-
localStorage.setItem('expires_at', expiresAt)
56-
EventEmitter.emit('authChange', true)
57-
}
32+
login() {
33+
this.auth0.authorize();
34+
}
5835

59-
logout () {
60-
// Clear access token and ID token from local storage
61-
localStorage.removeItem('access_token')
62-
localStorage.removeItem('id_token')
63-
localStorage.removeItem('expires_at')
64-
//this.userProfile = null
65-
EventEmitter.emit('authChange', false)
66-
// navigate to the home route
36+
handleAuthentication() {
37+
this.auth0.parseHash((err, authResult) => {
38+
if (authResult && authResult.accessToken && authResult.idToken) {
39+
this.setSession(authResult)
40+
Router.replace('home')
41+
} else if (err) {
6742
Router.replace('home')
43+
console.log(err)
44+
alert(`Error: ${err.error}. Check the console for further details.`)
6845
}
46+
})
47+
}
6948

70-
isAuthenticated () {
71-
// Check whether the current time is past the
72-
// access token's expiry time
73-
let expiresAt = JSON.parse(localStorage.getItem('expires_at') || '{}')
74-
return new Date().getTime() < expiresAt
75-
}
49+
setSession(authResult: any) {
50+
// Set the time that the access token will expire at
51+
let expiresAt = JSON.stringify(
52+
authResult.expiresIn * 1000 + new Date().getTime()
53+
)
54+
localStorage.setItem('access_token', authResult.accessToken)
55+
localStorage.setItem('id_token', authResult.idToken)
56+
localStorage.setItem('expires_at', expiresAt)
57+
ApiService.defaults.headers = { authorization: 'Bearer ' + authResult.accessToken };
58+
EventEmitter.emit('authChange', true)
59+
}
60+
61+
logout() {
62+
// Clear access token and ID token from local storage
63+
localStorage.removeItem('access_token')
64+
localStorage.removeItem('id_token')
65+
localStorage.removeItem('expires_at')
66+
//this.userProfile = null
67+
EventEmitter.emit('authChange', false)
68+
// navigate to the home route
69+
Router.replace('home')
70+
}
71+
72+
isAuthenticated() {
73+
// Check whether the current time is past the
74+
// access token's expiry time
75+
let expiresAt = JSON.parse(localStorage.getItem('expires_at') || '{}')
76+
return new Date().getTime() < expiresAt
77+
}
7678
}

ClientApp/boot.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Vue from 'vue';
44
import VueRouter from 'vue-router';
55
import router from './router/router'
66
import App from './components/app/app'
7+
import VueFormGenerator from "vue-form-generator";
78
Vue.use(VueRouter);
89

910
Vue.config.devtools = true //enable Vue dev tools in browser //TODO: Change at prod

ClientApp/components/app/app.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,4 @@ var { login, logout } = auth
2626
}
2727
})
2828
export default class App extends Vue {
29-
// data() {
30-
31-
// }
32-
3329
}

ClientApp/components/app/app.vue.html

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@
66
<router-view :auth="auth">
77
</router-view>
88
</div>
9-
109
</template>
1110

12-
13-
14-
15-
16-
17-
18-
1911
<script src="./app.ts"></script>
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
import "vue-multiselect/dist/vue-multiselect.min.css";
2+
import 'eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css'
3+
import 'eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.css'
4+
// import 'eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker-standalone.css'
5+
import Vue from 'vue';
6+
import VueFormGenerator from "vue-form-generator";
7+
import { Component, Prop } from 'vue-property-decorator';
8+
import { ApiService } from '../../models/ApiService';
9+
import { Template } from '../../models/Template';
10+
import "vue-form-generator/dist/vfg.css";
11+
import AutoSuggest from '../types/autosuggest/autosuggest';
12+
import Multiselect from 'vue-multiselect';
13+
import { EventEmitter } from "../../models/EventEmmiter";
14+
import eonosdandatetimepicker from 'eonasdan-bootstrap-datetimepicker';
15+
import { LastOpenedDocument } from "../../models/LastOpenedDocument";
16+
import { VueRouter } from "vue-router/types/router";
17+
18+
// register globally
19+
Vue.component('multiselect', Multiselect)
20+
21+
Vue.component('fieldAutoSuggest', AutoSuggest)
22+
23+
Vue.component('datetimepicker', eonosdandatetimepicker);
24+
25+
Vue.use(VueFormGenerator)
26+
27+
28+
@Component({
29+
components: {
30+
MultiLine: require('../types/multiLine/multiLine.vue.html'),
31+
SingleLine: require('../types/singleLine/singleLine.vue.html'),
32+
AutoSuggest: require('../types/autosuggest/autosuggest.vue.html')
33+
}
34+
})
35+
export default class Editor extends Vue {
36+
@Prop()
37+
templateId: number
38+
@Prop()
39+
lastOpenedDocumentId: number
40+
41+
42+
template: Template = new Template();
43+
medicines: any = []
44+
model: any = {};
45+
schema: any = {};
46+
47+
mounted() {
48+
let self = this;
49+
EventEmitter.on('model_changed', (value: any) => {
50+
self.model.medicines = value;
51+
self.schema.fields[9].values = self.medicines;
52+
})
53+
54+
55+
ApiService.get('Templates/GetTemplateWithProperties/' + this.templateId)
56+
.then(response => {
57+
this.template = response.data;
58+
if (self.lastOpenedDocumentId == null) {
59+
this.model = JSON.parse(response.data.modelJson);
60+
}
61+
this.schema = JSON.parse(response.data.schemeJson);
62+
ApiService.get('medicine/getmedicines')
63+
.then(response => {
64+
self.medicines = response.data
65+
self.schema.fields[9].values = self.medicines;
66+
self.schema.fields[9].selectOptions.onNewTag = function (newTag: any, id: any, options: any, value: any) {
67+
EventEmitter.emit('model_changed', value);
68+
}
69+
})
70+
.catch(e => {
71+
alert(e);
72+
});
73+
})
74+
.catch(e => {
75+
alert(e);
76+
});
77+
78+
if (this.lastOpenedDocumentId != null) {
79+
ApiService.get('LastOpenedDocuments/GetLastOpenedDocument/' + this.lastOpenedDocumentId)
80+
.then(response => {
81+
this.model = JSON.parse(response.data.modelJson);
82+
console.log(
83+
this.model = JSON.parse(response.data.modelJson));
84+
})
85+
.catch(e => {
86+
alert(e);
87+
});
88+
}
89+
90+
}
91+
92+
93+
// model = {
94+
// patientName: "",
95+
// medicines: [],
96+
// patientBirthday: new Date(),
97+
// visitDay: new Date(),
98+
// speciality: "",
99+
// doctorName: "",
100+
// complaints: "",
101+
// anammnesis: "",
102+
// recommended: ""
103+
// }
104+
// getTest()
105+
// {
106+
// return this.medicines == null ? [1, 2, 3] : this.medicines;
107+
// }
108+
109+
// schema = {
110+
// fields: [
111+
// {
112+
// type: "vueMultiSelect",
113+
// label: "Лекарства",
114+
// placeholder: "Пожалуйста, выберите лекарства",
115+
// values: this.getTest(),
116+
// selectOptions: {
117+
// multiple: true,
118+
// hideselected: true,
119+
// multiSelect: true,
120+
// closeOnSelect: true,
121+
// showLabels: false,
122+
// searchable: true,
123+
// taggable: true,
124+
// limit: 10,
125+
// onNewTag: function (newTag : any, id: any, options: any, value: any) {
126+
// EventEmitter.emit('model_changed', value);
127+
// }
128+
// }
129+
// }
130+
// ]
131+
// }
132+
133+
save() {
134+
var newLastOpenedDocument = new LastOpenedDocument();
135+
newLastOpenedDocument.lastOpenedTime = new Date();
136+
newLastOpenedDocument.modelJson = JSON.stringify(this.model);
137+
newLastOpenedDocument.templateId = this.templateId;
138+
newLastOpenedDocument.patient = this.model.patientName;
139+
if (this.lastOpenedDocumentId == null) {
140+
ApiService.post('LastOpenedDocuments/InsertNewLastOpenedDocument', newLastOpenedDocument)
141+
.then(response => {
142+
this.$router.replace('editor?lastOpenedDocumentId=' + response.data + "&templateId=" + this.templateId);
143+
this.lastOpenedDocumentId = response.data;
144+
console.log(response);
145+
})
146+
.catch(e => {
147+
console.log(e);
148+
})
149+
}
150+
else {
151+
newLastOpenedDocument.lastOpenedDocumentId = this.lastOpenedDocumentId;
152+
ApiService.put('LastOpenedDocuments/UpdateDocument/' + this.lastOpenedDocumentId, newLastOpenedDocument)
153+
.then(response => {
154+
console.log(response);
155+
})
156+
.catch(e => {
157+
console.log(e);
158+
})
159+
}
160+
}
161+
162+
formOptions: any = {
163+
validateAfterLoad: false,
164+
validateAfterChanged: false
165+
}
166+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<template>
2+
<div>
3+
<!-- <div v-for="property in template.properties">
4+
<h1>{{property.theme}}</h1>
5+
<component :is="property.type.typeName"></component>
6+
<br/>
7+
</div> -->
8+
<form v-on:submit.prevent="save">
9+
<vue-form-generator :schema="schema" :model="model" :options="formOptions"></vue-form-generator>
10+
</form>
11+
</div>
12+
</template>
13+
14+
<script src="./editor.ts" />
15+

0 commit comments

Comments
 (0)