1: <?php
2: 3: 4: 5:
6:
7: use Nette\Forms\Form,
8: Nette\Diagnostics\Debugger;
9:
10: 11: 12: 13: 14: 15:
16: class NavstevaPresenter extends BasePresenter {
17:
18: 19: 20: 21:
22: public function handleAddDiagnoza() {
23: $this->template->showDiagnozaForm = true;
24: if ($this->presenter->isAjax()) {
25: $this->invalidateControl('diagnozaForm');
26: }
27: }
28:
29: 30: 31: 32: 33:
34: public function handleEditDiagnoza($id) {
35: if ($this->presenter->isAjax()) {
36: $form = $this['diagnozaForm'];
37: if (!$form->isSubmitted()) {
38: $row = $this->getService('model')->getDiagnoza($id);
39: $row->diagnoza_name = $row->mkn10->nazev;
40: if (!$row) $this->error('Záznam nenalezen');
41: }
42: $this->template->showDiagnozaForm = true;
43: $form->setDefaults($row);
44: $this->invalidateControl('diagnozaForm');
45: }
46: }
47:
48: 49: 50: 51:
52: public function handleAddTerapie() {
53: $this->template->showTerapieForm = true;
54: if ($this->presenter->isAjax()) {
55: $this->invalidateControl('terapieForm');
56: }
57: }
58:
59: 60: 61: 62: 63:
64: public function handleEditTerapie($id) {
65: $this->template->showTerapieForm = true;
66: if ($this->presenter->isAjax()) {
67: $form = $this['terapieForm'];
68: if (!$form->isSubmitted()) {
69: $row = $this->getService('model')->getTerapie($id);
70: if (!$row) $this->error('Záznam nenalezen');
71: }
72: $form->setDefaults($row);
73: $this->invalidateControl('terapieForm');
74: }
75: }
76:
77: 78: 79: 80: 81: 82:
83: public function handleAddInfo($id) {
84: $this->template->showInfoForm = true;
85: if ($this->presenter->isAjax()) {
86: $form = $this['infoForm'];
87: if (!$form->isSubmitted()) {
88: $row = $this->getService('model')->getInfoByNavsteva($id);
89: if ($row) $form->setDefaults($row);
90: }
91: $this->invalidateControl('infoForm');
92: }
93: }
94:
95: 96: 97: 98:
99: public function handleAddZamestnanec() {
100: $this->template->showZamestnanecForm = true;
101: if ($this->presenter->isAjax()) {
102: $this->invalidateControl('zamestnanecForm');
103: }
104: }
105:
106: 107: 108: 109:
110: public function actionDeleteDiagnoza($id,$navsteva_id) {
111: $this->getService('model')->getDiagnoza($id)->delete();
112: $this->flashMessage('Diagnoza byla vymazána');
113: $this->redirect('Navsteva:view',$navsteva_id);
114: }
115:
116: 117: 118: 119:
120: public function actionDeleteTerapie($id,$navsteva_id) {
121: $this->getService('model')->getTerapie($id)->delete();
122: $this->flashMessage('Terapie byla vymazána');
123: $this->redirect('Navsteva:view',$navsteva_id);
124: }
125:
126: 127: 128: 129:
130: public function actionDeleteZamestnanec($id,$navsteva_id) {
131: $this->getService('model')->deleteZamestnanec($id,$navsteva_id);
132: $this->flashMessage('Zaměstnanec byl odebrát z návštevy');
133: $this->redirect('Navsteva:view',$navsteva_id);
134: }
135:
136: 137: 138: 139:
140: public function renderView($id) {
141: if (is_null($id)) $this->redirect ('Navsteva:');
142: $navsteva = $this->getService('model')->getNavsteva($id);
143: $this->template->navsteva = $navsteva;
144: $this->template->diagnozy = $navsteva->related('diagnoza');
145: $this->template->terapies = $navsteva->related('terapie');
146: $this->template->zdrav_info = $navsteva->related('zdrav_info');
147:
148: $this->template->pacient = $navsteva->pacient;
149:
150: $this->template->id = $id;
151: }
152:
153: 154: 155: 156: 157:
158: public function renderDasta($id) {
159: if (is_null($id)) $this->redirect ('Navsteva:');
160: $navsteva = $this->getService('model')->getNavsteva($id);
161: $this->template->navsteva = $navsteva;
162: $this->template->diagnozy = $navsteva->related('diagnoza');
163: $this->template->terapies = $navsteva->related('terapie');
164:
165: $pacient = $navsteva->pacient;
166: $pacient->date_born = DateTime::createFromFormat('ymd',substr($pacient->id, 0, 6));
167:
168: $this->template->pacient = $pacient;
169:
170: $zamestnanci = $navsteva->related('navsteva_has_zamestnanec')->fetch();
171:
172: if (!$zamestnanci) {
173: $this->flashMessage('Návštěva musí mít zaměstance, aby se dal vytvořit DASTA záznam!','error');
174: $this->redirect('Navsteva:view',$id);
175: }else {
176: $this->template->zamestnanec = $zamestnanci->zamestnanec;
177: }
178:
179: }
180: 181: 182: 183: 184:
185: public function actionAutocompleteDiagnoza($term) {
186: $this->template->list = $this->getService('model')->getDiagnozaByTerm($term);
187: }
188:
189: 190: 191: 192: 193:
194: public function actionAutocompleteZamestnanec($term) {
195: $this->template->list = $this->getService('model')->getZamestnanecByTerm($term);
196: }
197:
198: 199: 200: 201: 202:
203: public function actionSearchNavsteva($term) {
204: $this->template->list = $this->getService('model')->getNavstevaByTerm($term);
205: }
206:
207: 208: 209: 210: 211:
212: protected function createComponentDiagnozaForm($name) {
213: $form = new Nette\Application\UI\Form;
214:
215: $form->addHidden('id');
216: $form->addHidden('navsteva_id',$this->getParameter('id'));
217: $form->addHidden('mkn10_id')
218: ->setRequired('Vyberte prosím diagnozu ze seznamu');
219: $form->addText('diagnoza_name', 'Diagnóza',30)
220: ->setRequired('Vyplňte diagnozu')
221: ->addRule(Form::MAX_LENGTH, 'Maximální délka je %d znaků', 30)
222: ->setAttribute('placeholder', 'napište alespoň 3 písmena');
223: $form->addText('pristroj', 'Přístroj')
224: ->addRule(Form::MAX_LENGTH, 'Maximální délka je %d znaků', 45);
225: $form->addText('material', 'Materiál')
226: ->addRule(Form::MAX_LENGTH, 'Maximální délka je %d znaků', 255);
227: $form->addTextArea('komentar', 'Komentář');
228:
229: $form->addSubmit('submitButton', 'Uložit');
230: $form->onSuccess[] = callback($this, 'submitDiagnozaForm');
231:
232: return $form;
233: }
234:
235: 236: 237: 238: 239:
240: public function submitDiagnozaForm($form) {
241: $values = $form->getValues();
242: $id = (int) $values['id'];
243: $navsteva_id = $values['navsteva_id'];
244: unset($values['id']);
245: unset($values['diagnoza_name']);
246:
247: if ($id > 0) {
248: unset($values['navsteva_id']);
249: $this->getService('model')->getDiagnoza($id)->update($values);
250: $this->flashMessage('Diagnóza byla aktualizována.');
251: } else {
252: $this->getService('model')->addDiagnoza($values);
253: $this->flashMessage('Diagnóza byla přidána k návštěvě.');
254: }
255: $this->redirect('Navsteva:view',$navsteva_id);
256: }
257:
258: 259: 260: 261: 262:
263: protected function createComponentTerapieForm($name) {
264: $form = new Nette\Application\UI\Form;
265:
266: $form->addHidden('id');
267: $form->addHidden('navsteva_id',$this->getParameter('id'));
268: $form->addText('terapie', 'Terapie',40)
269: ->setRequired('Vyplňte terapii')
270: ->addRule(Form::MAX_LENGTH, 'Maximální délka je %d znaků', 255);
271: $form->addText('lecivo', 'Léčivo',40)
272: ->addRule(Form::MAX_LENGTH, 'Maximální délka je %d znaků', 45);
273: $form->addText('pristroj', 'Přístroj',40)
274: ->addRule(Form::MAX_LENGTH, 'Maximální délka je %d znaků', 45);
275: $form->addText('material', 'Materiál',40)
276: ->addRule(Form::MAX_LENGTH, 'Maximální délka je %d znaků', 255);
277: $form->addTextArea('komentar', 'Komentář');
278:
279: $form->addSubmit('submitButton', 'Uložit');
280: $form->onSuccess[] = callback($this, 'submitTerapieForm');
281:
282: return $form;
283: }
284:
285: 286: 287: 288: 289:
290: public function submitTerapieForm($form) {
291: $values = $form->getValues();
292: $id = (int) $values['id'];
293: $navsteva_id = $values['navsteva_id'];
294:
295: unset($values['id']);
296:
297: if ($id > 0) {
298: unset($values['navsteva_id']);
299: $this->getService('model')->getTerapie($id)->update($values);
300: $this->flashMessage('Terapie byla akualizována.');
301: } else {
302: $this->getService('model')->addTerapie($values);
303: $this->flashMessage('Terapie byla přidána k návštěvě.');
304: }
305: $this->redirect('Navsteva:view',$navsteva_id);
306:
307: }
308:
309: 310: 311: 312: 313:
314: protected function createComponentInfoForm($name) {
315: $form = new Nette\Application\UI\Form;
316:
317: $form->addHidden('id');
318: $form->addHidden('navsteva_id',$this->getParameter('id'));
319:
320: $form->addText('vyska', 'Výška',3)
321: ->addRule(Form::INTEGER, 'Výška musí být číslo')
322: ->addRule(Form::RANGE, 'Výška musí být od %d do %d', array(10, 300))
323: ->setAttribute('type','number')
324: ->setOption('description', 'cm');
325:
326: $form->addText('vaha', 'Váha',3)
327: ->addRule(Form::INTEGER, 'Váha musí být číslo')
328: ->addRule(Form::RANGE, 'Váha musí být od %d do %d', array(1, 500))
329: ->setAttribute('type','number')
330: ->setOption('description', 'kg');
331:
332: $form->addSelect('koureni_id', 'Kouření',
333: $this->getService('model')->getSelectArray('koureni')
334: );
335:
336: $form->addText('alergie', 'Alergie',15)
337: ->addRule(Form::MAX_LENGTH, 'Popis alerige musí být dlouhý max. %d znaků',30);
338:
339: $form->addText('tlak_s', 'Systolický tlak',3)
340: ->addRule(Form::INTEGER, 'Tlak musí být číslo')
341: ->addRule(Form::RANGE, 'Tlak musí být od %d do %d', array(1, 500))
342: ->setAttribute('type','number')
343: ->setOption('description', 'mmHg');
344:
345: $form->addText('tlak_d', 'Diastolický tlak',3)
346: ->addRule(Form::INTEGER, 'Tlak musí být číslo')
347: ->addRule(Form::RANGE, 'Tlak musí být od %d do %d', array(1, 500))
348: ->setAttribute('type','number')
349: ->setOption('description', 'mmHg');
350:
351: $form->addText('tep', 'Tep',3)
352: ->addRule(Form::INTEGER, 'Tep musí být číslo')
353: ->addRule(Form::RANGE, 'Tep musí být od %d do %d', array(1, 500))
354: ->setAttribute('type','number')
355: ->setOption('description', 'tepů za minutu');
356:
357: $form->addText('teplota', 'Teplota',3)
358: ->addRule(Form::FLOAT, 'Teplota musí být číslo')
359: ->addRule(Form::RANGE, 'Teplota musí být od %d do %d', array(20, 80))
360: ->setAttribute('type','number')
361: ->setOption('description', '°C');
362:
363: $form->addCheckbox('tehotenstvi', 'Těhotenstvi');
364:
365: $form->addSubmit('submitButton', 'Uložit');
366: $form->onSuccess[] = callback($this, 'submitInfoForm');
367:
368: return $form;
369: }
370:
371: 372: 373: 374: 375:
376: public function submitInfoForm($form) {
377: $values = $form->getValues(TRUE);
378: $id = (int) $values['id'];
379: $navsteva_id = $values['navsteva_id'];
380:
381: unset($values['id']);
382:
383: $values = array_filter($values,'strlen');
384:
385: if ($id > 0) {
386: unset($values['navsteva_id']);
387: $this->getService('model')->getInfoByNavsteva($navsteva_id)->update($values);
388: $this->flashMessage('Zdravotní informace byli aktualizovány.');
389: } else {
390: $this->getService('model')->addInfo($values);
391: $this->flashMessage('Zdravotní informace byli přidány.');
392: }
393: $this->redirect('Navsteva:view',$navsteva_id);
394:
395: }
396:
397: 398: 399: 400: 401:
402: protected function createComponentZamestnanecForm($name) {
403: $form = new Nette\Application\UI\Form;
404:
405: $form->addHidden('navsteva_id',$this->getParameter('id'));
406:
407: $form->addHidden('zamestnanec_id')
408: ->setRequired('Vyberte zaměstnance ze seznamu');
409:
410: $form->addText('zamestnanec_name', 'Zaměstnanec',30)
411: ->setRequired('Vyplňte jméno zaměstnance')
412: ->setAttribute('placeholder','napište alespoň 3 písmena');
413:
414: $form->addSubmit('submitButton', 'Přidat');
415: $form->onSuccess[] = callback($this, 'submitZamestnanecForm');
416:
417: return $form;
418: }
419:
420: 421: 422: 423: 424:
425: public function submitZamestnanecForm($form) {
426: $zamestnanec_id = $form['zamestnanec_id']->value;
427: $navsteva_id = $form['navsteva_id']->value;
428:
429: $this->getService('model')->addZamestnanec($zamestnanec_id, $navsteva_id);
430: $this->flashMessage('Zaměstananec byl přidán k návštěvě.');
431: $this->redirect('Navsteva:view',$navsteva_id);
432: }
433:
434:
435: }