-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
233 lines (194 loc) · 7.41 KB
/
app.js
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
class Agendar {
constructor(name, cpf, carteira, endereco, sexo, nascimento, tel, ubs, especialidades, doutor, data,){
this.name = name
this.cpf = cpf
this.carteira = carteira
this.endereco = endereco
this.sexo = sexo
this.nascimento = nascimento
this.tel = tel
this.ubs = ubs
this.especialidades = especialidades
this.doutor = doutor
this.data = data
}
validarDados(){
for(let i in this){
if (this[i] == undefined || this[i] == '' || this[i] == null){
return false
}
}
return true
}
}
// CRIA BD
class Bd {
//cria id
constructor(){
let id = localStorage.getItem('id')
if (id === null){
localStorage.setItem('id', 0)
}
}
//gera id para itens no localStorage
getProximoId(){
let proximoId = localStorage.getItem('id')
return parseInt(proximoId) + 1
}
gravar(a) {
let id = this.getProximoId()
//converte objeto para string
localStorage.setItem(id, JSON.stringify(a))
localStorage.setItem('id', id)
}
recuperarTodosRegistros() {
let agendamento = Array()
//faz requisição do agendamento
let id = localStorage.getItem('id')
for(let i = 1; i <= id; i++){
let agenda = JSON.parse(localStorage.getItem(i))
if(agenda == null){
continue
}
agenda.id = i
agendamento.push(agenda)
}
return agendamento
}
//modal exlui agendamento
remover(id){
localStorage.removeItem(id)
}
}
let bd = new Bd()
function cadastrarAgendamento(){
let name = document.getElementById('name')
let cpf = document.getElementById('cpf')
let carteira = document.getElementById('carteira')
let endereco = document.getElementById('endereco')
let sexo = document.getElementById('sexo')
let nascimento = document.getElementById('nascimento')
let tel = document.getElementById('tel')
let ubs = document.getElementById('ubs')
let especialidades = document.getElementById('especialidades')
let doutor = document.getElementById('doutor')
let data = document.getElementById('data')
let agendar = new Agendar(
name.value,
cpf.value,
carteira.value,
endereco.value,
sexo.value,
nascimento.value,
tel.value,
ubs.value,
especialidades.value,
doutor.value,
data.value
)
if (agendar.validarDados()){
bd.gravar(agendar)
document.getElementById('modal_titulo_div').className = 'modal-header text-success'
document.getElementById('modal_titulo').innerHTML = 'Cadastrado com Sucesso!'
document.getElementById('modal_conteudo').innerHTML = 'Não esqueça de levar a carteirinha do SUS no dia da consulta'
document.getElementById('modal_btn').innerHTML = 'Confirma'
document.getElementById('modal_btn').className = 'btn btn-success'
$('#modalRegistraAgendamento').modal('show')
name.value = ''
cpf.value = ''
carteira.value = ''
endereco.value = ''
sexo.value = ''
nascimento.value = ''
tel.value = ''
plano.value = ''
especialidades.value = ''
doutor.value = ''
data.value = ''
} else {
document.getElementById('modal_titulo_div').className = 'modal-header text-danger'
document.getElementById('modal_titulo').innerHTML = 'Todos os campos são obrigatórios'
document.getElementById('modal_conteudo').innerHTML = 'Preencha todos os dados corretamente.'
document.getElementById('modal_btn').innerHTML = 'Voltar'
document.getElementById('modal_btn').className = 'btn btn-danger'
$('#modalRegistraAgendamento').modal('show')
}
}
function carregaListaAgendamento( pesquisar = Array(), filtro = false ){
if (pesquisar.length == 0 && filtro == false){
pesquisar = bd.recuperarTodosRegistros()
}
let listaAgendamento = document.getElementById('listaAgendamento')
listaAgendamento.innerHTML = ''
//CRIA ESTRUTURA DO BD linhas e colunas
pesquisar.forEach(function(a){
let linha = listaAgendamento.insertRow()
linha.insertCell(0).innerHTML = a.name
linha.insertCell(1).innerHTML = a.cpf
linha.insertCell(2).innerHTML = a.carteira
linha.insertCell(3).innerHTML = a.endereco
switch (a.sexo){
case '1': a.sexo = 'Feminino'
break
case '2': a.sexo = 'Masculino'
break
case '3': a.sexo = 'Prefiro não informar'
break
}
linha.insertCell(4).innerHTML = a.sexo
let nasc_1 = new Date(a.nascimento).toLocaleDateString('pt-br')
linha.insertCell(5).innerHTML = nasc_1
linha.insertCell(6).innerHTML = a.tel
switch (a.ubs){
case '1': a.ubs = 'UBS Alto Independência'
break
case '2': a.ubs = 'UBS Morin'
break
case '3': a.ubs = 'UBS Mosela'
break
case '4': a.ubs = 'UBS Quitandinha'
break
}
linha.insertCell(7).innerHTML = a.ubs
switch (a.especialidades){
case '1': a.especialidades = 'Atendimento Clínico'
break
case '2': a.especialidades = 'Atendimento pediátrico'
break
case '3': a.especialidades = 'Saúde Bucal'
break
}
linha.insertCell(8).innerHTML = a.especialidades
switch (a.doutor){
case '1': a.doutor = 'Dr. Emerson de Souza'
break
case '2': a.doutor = 'Dr. João Victor Rodrigues'
break
case '3': a.doutor = 'Drª. Jéssica Coutinho de Mattos'
break
case '4': a.doutor = 'Drª. Ana Carolina M Corrêa'
break
case '5': a.doutor = 'Drª. Larissa Marques'
break
}
linha.insertCell(9).innerHTML = a.doutor
let data_a = new Date(a.data).toLocaleDateString('pt-br')
linha.insertCell(10).innerHTML = data_a
//botao de exluir modal
let btn = document.createElement('button')
btn.className = 'btn btn-danger'
btn.innerHTML = '<i class="fa fa-trash"></i>'
btn.id = `id_despesa_${a.id}`
btn.onclick = function (){
let id = this.id.replace('id_despesa_', '')
document.getElementById('modal_titulo_div').className = 'modal-header text-danger'
document.getElementById('modal_titulo').innerHTML = 'Exclusão de agendamento!'
document.getElementById('modal_conteudo').innerHTML = 'Deseja excluir esse agendamento de forma permanente?'
document.getElementById('modal_btn').innerHTML = 'Excluir'
document.getElementById('modal_btn').className = 'btn btn-danger'
$('#modalExclusaoAgendamento').modal('show')
bd.remover(id)
}
linha.insertCell(11).append(btn)
})
}