patientFile.as 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  1. import com.imt.intimamedia.events.patient.CreateAppointmentEvent;
  2. import com.imt.intimamedia.events.patient.CreatePatientEvent;
  3. import com.imt.intimamedia.events.patient.SearchAppointmentsEvent;
  4. import com.imt.intimamedia.events.patient.SearchPatientEvent;
  5. import com.imt.intimamedia.events.patient.UpdateAppointmentEvent;
  6. import com.imt.intimamedia.events.patient.UpdatePatientEvent;
  7. import com.imt.intimamedia.events.measures.GetCTPAEvent;
  8. import com.imt.intimamedia.helpers.AES;
  9. import com.imt.intimamedia.helpers.ComboBoxHelper;
  10. import com.imt.intimamedia.helpers.FlashHelper;
  11. import com.imt.intimamedia.helpers.FormatString;
  12. import com.imt.intimamedia.helpers.HelpUtils;
  13. import com.imt.intimamedia.model.ApplicationModelLocator;
  14. import com.imt.intimamedia.views.common.ImtToaster;
  15. import com.imt.intimamedia.views.physician.measure.MeasureView;
  16. import com.imt.intimamedia.views.physician.patient.PatientView;
  17. import com.imt.intimamedia.vo.AppointmentVo;
  18. import com.imt.intimamedia.vo.AtsVo;
  19. import com.imt.intimamedia.vo.CvExaminatorVo;
  20. import com.imt.intimamedia.vo.FamilyHistoryVo;
  21. import com.imt.intimamedia.vo.PatientVo;
  22. import com.imt.intimamedia.vo.PersonalHistoryVo;
  23. import com.imt.intimamedia.vo.TobaccoVo;
  24. import flash.display.Stage;
  25. import flash.events.Event;
  26. import flash.events.FocusEvent;
  27. import flash.events.KeyboardEvent;
  28. import flash.events.MouseEvent;
  29. import flash.events.TextEvent;
  30. import flash.ui.Mouse;
  31. import flash.utils.ByteArray;
  32. import mx.collections.ArrayCollection;
  33. import mx.controls.Alert;
  34. import mx.controls.ComboBox;
  35. import mx.controls.Image;
  36. import mx.controls.dataGridClasses.DataGridColumn;
  37. import mx.core.Application;
  38. import mx.core.UIComponent;
  39. import mx.events.DataGridEvent;
  40. import mx.events.ListEvent;
  41. import mx.events.ValidationResultEvent;
  42. import mx.formatters.DateFormatter;
  43. import mx.managers.CursorManager;
  44. import mx.resources.ResourceManager;
  45. import mx.utils.ObjectUtil;
  46. import mx.validators.Validator;
  47. private var _viewMessageSearch : Boolean = false;
  48. private var _viewMessageDisplay : Boolean = false;
  49. [Bindable]
  50. private var _model : ApplicationModelLocator = ApplicationModelLocator.getInstance();
  51. [Bindable]
  52. private var _minYearOfBirth : int = new Date().fullYear - 100;
  53. [Bindable]
  54. private var _maxYearOfBirth : int = new Date().fullYear - 2;
  55. [Bindable]
  56. private var _currentYear : int = new Date().fullYear;
  57. [Bindable]
  58. private var _disabledRangesDateOfBirth : Array = [ {rangeEnd: new Date(new Date().fullYear - 110, new Date().getMonth(), new Date().getDate())}, {rangeStart: new Date()} ];
  59. [Bindable]
  60. //private var _disabledRangesVisitDate : Array = [ {rangeStart: new Date(new Date().fullYear, new Date().getMonth(), new Date().getDate()+1)} ];
  61. private var _disabledRangesVisitDate : Array = [ {rangeEnd: new Date(new Date().fullYear, new Date().getMonth(), new Date().getDate())}, {rangeStart: new Date(new Date().fullYear, new Date().getMonth(), new Date().getDate())} ];
  62. [Bindable]
  63. private var _currentPatientVisit : String = "1";
  64. private function creationCompleteHandler() : void
  65. {
  66. loadKeyboardListeners();
  67. searchPatientHelp.source = 'images/help/' + ResourceManager.getInstance().getString('labels', 'lang') + '/patientSearch.png';
  68. createPatientHelp.source = 'images/help/' + ResourceManager.getInstance().getString('labels', 'lang') + '/patientCreate.png';
  69. patientTabHelp.source = 'images/help/' + ResourceManager.getInstance().getString('labels', 'lang') + '/patientTab.png';
  70. }
  71. private function navigationNext() : void
  72. {
  73. var parent : PatientView = this.parentDocument as PatientView;
  74. parent.selectView(parent.atsStart, parent.atsEnd, parent.atsBox, parent.atsLinkButton, 1)
  75. }
  76. private function showInformation( zone : String ) : void { }
  77. private function loadKeyboardListeners() : void
  78. {
  79. firstNameTextInput.addEventListener(KeyboardEvent.KEY_UP, translateFirstCharToUpperCase);
  80. lastNameTextInput.addEventListener(KeyboardEvent.KEY_DOWN, translateToUpperCase);
  81. lastNameTextInput.addEventListener(KeyboardEvent.KEY_UP, checkTranslateToUpperCase);
  82. }
  83. public function showHelp(image : Image) : void
  84. {
  85. if (ApplicationModelLocator.getInstance().application.menuPhysician.selectedIndex == 0
  86. && ApplicationModelLocator.getInstance().application.menuPhysician.patient.patientView.selectedIndex == 0)
  87. HelpUtils.loadPatientHelp(image);
  88. else
  89. HelpUtils.showHelp(this, image, zoomHelpAdd, zoomHelpRemove);
  90. }
  91. private function patientFileController() : PatientVo
  92. {
  93. var toastMessage : ImtToaster;
  94. var validators : Array = [ firstNameValidator, lastNameValidator, sexValidator, dateOfBirthValidator ];
  95. var validatorsError : Array = Validator.validateAll( validators );
  96. if (dateOfBirthDateField.errorString)
  97. {
  98. dateOfBirthDateText.setStyle("color", "#7c0b13");
  99. dateOfBirthDateText.setStyle("fontWeight", "bold");
  100. }
  101. else
  102. {
  103. dateOfBirthDateText.setStyle("color", "#555557");
  104. dateOfBirthDateText.setStyle("fontWeight", "normal");
  105. }
  106. if (firstNameTextInput.errorString)
  107. {
  108. firstNameLabel.setStyle("color", "#7c0b13");
  109. firstNameLabel.setStyle("fontWeight", "bold");
  110. }
  111. else
  112. {
  113. firstNameLabel.setStyle("color", "#555557");
  114. firstNameLabel.setStyle("fontWeight", "normal");
  115. }
  116. if (lastNameTextInput.errorString)
  117. {
  118. lastNameLabel.setStyle("color", "#7c0b13");
  119. lastNameLabel.setStyle("fontWeight", "bold");
  120. }
  121. else
  122. {
  123. lastNameLabel.setStyle("color", "#555557");
  124. lastNameLabel.setStyle("fontWeight", "normal");
  125. }
  126. if (!sexRadioButtonGroup.selectedValue)
  127. {
  128. sexLabel.setStyle("color", "#7c0b13");
  129. sexLabel.setStyle("fontWeight", "bold");
  130. }
  131. else
  132. {
  133. sexLabel.setStyle("color", "#555557");
  134. sexLabel.setStyle("fontWeight", "normal");
  135. }
  136. if( validatorsError.length != 0 || !isDateOfBirthValid())
  137. {
  138. toastMessage = new ImtToaster();
  139. toastMessage.titleMessage = ResourceManager.getInstance().getString('labels', 'error.allFieldsTitle');
  140. toastMessage.timeToLive = 7;
  141. toastMessage.message = ResourceManager.getInstance().getString('labels', 'error.allFieldsCreatePatient');
  142. toastMessage.level = ImtToaster.WARNING;
  143. _model.toaster.toast( toastMessage );
  144. return null;
  145. }
  146. var patientVo : PatientVo = new PatientVo();
  147. patientVo.uid = uidPatientLabel.text;
  148. patientVo.firstName = firstNameTextInput.text;
  149. patientVo.lastName = lastNameTextInput.text;
  150. patientVo.sex = sexRadioButtonGroup.selectedValue as String;
  151. patientVo.birthDate = dateOfBirthDateField.selectedDate;
  152. patientVo.birthDate.setHours(12,0,0,0);
  153. patientVo.lastVisit = new Date();
  154. for each (var currentPatient : PatientVo in _model.listOfPatients)
  155. {
  156. if (currentPatient.firstName.toLowerCase() == patientVo.firstName.toLowerCase()
  157. && currentPatient.lastName.toLowerCase() == patientVo.lastName.toLowerCase()
  158. && currentPatient.birthDate.toDateString() == patientVo.birthDate.toDateString())
  159. {
  160. toastMessage = new ImtToaster();
  161. toastMessage.titleMessage = ResourceManager.getInstance().getString('labels', 'warning.use');
  162. toastMessage.message = ResourceManager.getInstance().getString('labels', 'error.patientAlreadyExists');
  163. toastMessage.level = ImtToaster.WARNING;
  164. _model.toaster.toast( toastMessage );
  165. return null;
  166. }
  167. }
  168. if ( ethnicGroupComboBox.selectedItem != null )
  169. patientVo.ethnicGroup = ethnicGroupComboBox.selectedItem.code;
  170. return patientVo;
  171. }
  172. private function createPatient() : void
  173. {
  174. Application.application.menuPhysician.acquire.label = ResourceManager.getInstance().getString('labels', 'physicianAcquire');
  175. // reset patient data and appointment
  176. resetAppointment();
  177. resetPatientData();
  178. // not an existing patient but a new patient
  179. _model.noAppointmentSelected = false;
  180. _model.enabledAcquire = false;
  181. _model.enabledMeasure = false;
  182. _model.enabledReport = false;
  183. _model.patientActive = false;
  184. _model.updatePatient = false;
  185. _model.viewPatient = false;
  186. _model.acquireViewLoaded = false;
  187. _model.appointmentSelected = null;
  188. // reset acquire and measure pages if needed
  189. Application.application.menuPhysician.acquire.clearPage();
  190. Application.application.menuPhysician.generalMeasure.measures.clearPage();
  191. var newPatient : PatientVo = patientFileController();
  192. if (!newPatient)
  193. return;
  194. var appointmentVo : AppointmentVo = new AppointmentVo();
  195. appointmentVo.number = 1;
  196. appointmentVo.date = visitDateField.selectedDate;
  197. appointmentVo.date.setHours(12,0,0,0);
  198. _model.patientSelected = newPatient;
  199. _model.patientActive = true;
  200. new CreatePatientEvent( newPatient, appointmentVo, _model.connectedUser.person.id, this ).dispatch();
  201. this.parentDocument.selectView(this.parentDocument.atsStart, this.parentDocument.atsEnd, this.parentDocument.atsBox, this.parentDocument.atsLinkButton, 1);
  202. }
  203. public function createPatientCompleted() : void
  204. {
  205. var toastMessage : ImtToaster = new ImtToaster();
  206. toastMessage = new ImtToaster();
  207. toastMessage.titleMessage = ResourceManager.getInstance().getString('labels', 'patient.createdTitle');
  208. toastMessage.message = ResourceManager.getInstance().getString('labels', 'patient.createdMessage');
  209. toastMessage.level = ImtToaster.VALIDATION;
  210. _model.toaster.toast( toastMessage );
  211. _model.patientName = firstNameTextInput.text + " " + lastNameTextInput.text;
  212. firstNameValidator.enabled = false;
  213. lastNameValidator.enabled = false;
  214. sexValidator.enabled = false;
  215. dateOfBirthValidator.enabled = false;
  216. firstNameValidator.enabled = true;
  217. lastNameValidator.enabled = true;
  218. sexValidator.enabled = true;
  219. dateOfBirthValidator.enabled = true;
  220. uidPatientLabel.text = FormatString.generateRandomUID();
  221. _model.appointmentNumber = 1;
  222. visitNumberLabel.text = _currentPatientVisit = _model.appointmentNumber.toString();
  223. _model.enabledAcquire = true;
  224. // refresh patient list
  225. new SearchPatientEvent( "", this ).dispatch();
  226. new SearchAppointmentsEvent( _model.patientSelected.uid, this ).dispatch();
  227. }
  228. private function searchPatient() : void
  229. {
  230. var toastMessage : ImtToaster;
  231. var searchCriteria : String = criteria.text;
  232. criteria.text = ResourceManager.getInstance().getString('labels', 'search.patient.info');
  233. if (searchCriteria.length > 0 && searchCriteria != ResourceManager.getInstance().getString('labels', 'search.patient.info'))
  234. {
  235. var keyWords : Array = searchCriteria.split(' ');
  236. if (keyWords.length > 2)
  237. {
  238. toastMessage = new ImtToaster();
  239. toastMessage.titleMessage = ResourceManager.getInstance().getString('labels', 'patient.searchTitle');
  240. toastMessage.message = ResourceManager.getInstance().getString('labels', 'patient.searchMessageError');
  241. toastMessage.level = ImtToaster.ERROR;
  242. _model.toaster.toast( toastMessage );
  243. }
  244. _model.listOfDisplayedPatients.removeAll();
  245. for each (var patient : PatientVo in _model.listOfPatients)
  246. {
  247. if (
  248. ( keyWords.length == 2
  249. && patient.firstName.toLowerCase() == (keyWords[0] as String).toLowerCase()
  250. && patient.lastName.toLowerCase() == (keyWords[1] as String).toLowerCase()
  251. )
  252. ||
  253. ( keyWords.length == 2
  254. && patient.firstName.toLowerCase() == (keyWords[1] as String).toLowerCase()
  255. && patient.lastName.toLowerCase() == (keyWords[0] as String).toLowerCase()
  256. )
  257. ||
  258. ( keyWords.length == 1 && patient.firstName.toLowerCase() == (keyWords[0] as String).toLowerCase() )
  259. ||
  260. ( keyWords.length == 1 && patient.lastName.toLowerCase() == (keyWords[0] as String).toLowerCase() )
  261. )
  262. {
  263. _model.listOfDisplayedPatients.addItem(patient);
  264. }
  265. }
  266. }
  267. else
  268. {
  269. _model.listOfDisplayedPatients.removeAll();
  270. _model.listOfDisplayedPatients.addAll(_model.listOfPatients);
  271. }
  272. searchButton.setFocus();
  273. }
  274. private function selectPatient( event : ListEvent ) : void
  275. {
  276. actionOnSearch.visible = true;
  277. _model.patientSelected = event.currentTarget.selectedItem as PatientVo;
  278. // to do later
  279. //_patientSelectedIndex = event.currentTarget.selectedIndex;
  280. _model.patientName = _model.patientSelected.firstName + " " + _model.patientSelected.lastName;
  281. _model.patientActive = true;
  282. _model.updatePatient = false;
  283. _model.enabledAcquire = false;
  284. _model.enabledMeasure = false;
  285. _model.enabledReport = false;
  286. _model.noAppointmentSelected = true;
  287. resetPatientData();
  288. if (_model.patientSelected.uid)
  289. {
  290. //dg.enabled = false;
  291. new SearchAppointmentsEvent( _model.patientSelected.uid, this ).dispatch();
  292. }
  293. }
  294. private function modifyPatient() : void
  295. {
  296. _model.updatePatient = true;
  297. firstNameTextInput.text = _model.patientSelected.firstName;
  298. lastNameTextInput.text = _model.patientSelected.lastName;
  299. sexRadioButtonGroup.selectedValue = _model.patientSelected.sex;
  300. dateOfBirthDateField.text = dateFormatter.format(_model.patientSelected.birthDate);
  301. dateOfBirthDateField.selectedDate = _model.patientSelected.birthDate;
  302. }
  303. private function updatePatient() : void
  304. {
  305. var patientVo : PatientVo = patientFileController();
  306. if (!patientVo)
  307. return;
  308. patientVo.id = _model.patientSelected.id;
  309. _model.patientSelected.firstName = patientVo.firstName;
  310. _model.patientSelected.lastName = patientVo.lastName;
  311. _model.patientSelected.birthCountry = patientVo.birthCountry;
  312. _model.patientSelected.birthDate = patientVo.birthDate;
  313. _model.patientSelected.ethnicGroup = patientVo.ethnicGroup;
  314. _model.patientSelected.sex = patientVo.sex;
  315. new UpdatePatientEvent(_model.patientSelected, this).dispatch();
  316. }
  317. public function updatePatientComplete() : void
  318. {
  319. _model.updatePatient = false;
  320. }
  321. private function prepareCreateAppointment( event : Event ) : void
  322. {
  323. if ( _model.patientSelected.uid == "" )
  324. {
  325. var toastMessage : ImtToaster = new ImtToaster();
  326. toastMessage.titleMessage = ResourceManager.getInstance().getString('labels', 'warning.use');
  327. toastMessage.message = ResourceManager.getInstance().getString('labels', 'warning.choosePatient');
  328. toastMessage.timeToLive = 6;
  329. toastMessage.level = ImtToaster.WARNING;
  330. ApplicationModelLocator.getInstance().toaster.toast( toastMessage );
  331. return;
  332. }
  333. _model.patientActive = true;
  334. _model.updatePatient = false;
  335. _model.viewPatient = false;
  336. _model.enabledAcquire = false;
  337. _model.enabledMeasure = false;
  338. _model.enabledReport = false;
  339. _model.acquireViewLoaded = false;
  340. _model.cptMesuresVisite = 0;
  341. Application.application.menuPhysician.acquire.label = ResourceManager.getInstance().getString('labels', 'physicianAcquire');
  342. _model.appointmentNumber++;
  343. // to do : decide if we keep prepareCreateAppointment or not
  344. createAppointment();
  345. }
  346. public function createAppointment() : void
  347. {
  348. // create an appointment so reset acquire and measure pages if needed
  349. Application.application.menuPhysician.acquire.clearPage();
  350. Application.application.menuPhysician.generalMeasure.measures.clearPage();
  351. var appointmentVo : AppointmentVo = new AppointmentVo();
  352. appointmentVo.patientId = _model.patientSelected.id;
  353. appointmentVo.number = _model.appointmentNumber;
  354. appointmentVo.date = visitDateField.selectedDate;
  355. appointmentVo.date.setHours(12,0,0,0);
  356. _currentPatientVisit = _model.appointmentNumber.toString();
  357. _model.noAppointmentSelected = false;
  358. _model.acquireViewLoaded = false;
  359. new CreateAppointmentEvent( appointmentVo, _model.patientSelected.uid, this ).dispatch();
  360. }
  361. public function createAppointmentComplete() : void
  362. {
  363. FlashHelper.resetAll();
  364. var toastMessage : ImtToaster = new ImtToaster();
  365. toastMessage = new ImtToaster();
  366. toastMessage.titleMessage = ResourceManager.getInstance().getString('labels', 'patient.addAppointmentTitle');
  367. toastMessage.message = ResourceManager.getInstance().getString('labels', 'patient.addAppointmentMessage');
  368. toastMessage.timeToLive = 7;
  369. toastMessage.level = ImtToaster.VALIDATION;
  370. _model.toaster.toast( toastMessage );
  371. dateOfBirthDateField.text = "";
  372. _model.patientName = _model.patientSelected.firstName + " " + _model.patientSelected.lastName;
  373. _model.enabledAcquire = true;
  374. _model.enabledMeasure = false;
  375. _model.enabledReport = false;
  376. // to do later
  377. //_appointmentSelectedIndex = -1;
  378. // appointmentNumber - 1 => last appointment (or current appointment)
  379. // appointmentNumber - 2 => previous appointment
  380. if (_model.appointmentNumber > 1)
  381. {
  382. var previousAppointmentVo : AppointmentVo = _model.listOfAppointments.getItemAt(_model.appointmentNumber-2) as AppointmentVo;
  383. // copy previous appointment in treatmentCollection
  384. _model.appointmentSelected.treatmentCollection.addAll(previousAppointmentVo.treatmentCollection);
  385. var parent : PatientView = this.parentDocument as PatientView;
  386. // load appointment data from previous appointment
  387. _model.appointmentSelected.height = previousAppointmentVo.height;
  388. _model.appointmentSelected.weight = previousAppointmentVo.weight;
  389. var newAppointment : Boolean = true;
  390. parent.loadAppointmentData(previousAppointmentVo, newAppointment);
  391. updateAppointment();
  392. }
  393. this.parentDocument.selectView(this.parentDocument.atsStart, this.parentDocument.atsEnd, this.parentDocument.atsBox, this.parentDocument.atsLinkButton, 1);
  394. //new SearchAppointmentsEvent( _model.patientSelected.uid, this ).dispatch();
  395. }
  396. private function selectAppointment( event : ListEvent ) : void
  397. {
  398. _model.appointmentSelected = event.currentTarget.selectedItem as AppointmentVo;
  399. // to do later
  400. //_appointmentSelectedIndex = event.currentTarget.selectedIndex;
  401. visitDateField.selectedDate = event.currentTarget.selectedItem.date;
  402. dateAppointment.text = dateFormatter.format(event.currentTarget.selectedItem.date);
  403. _model.appointmentNumber = event.currentTarget.selectedItem.number;
  404. visitNumberLabel.text = _currentPatientVisit = event.currentTarget.selectedItem.number;
  405. if (!_model.appointmentSelected.type)
  406. {
  407. recoverLastAppointment(false);
  408. return;
  409. }
  410. _model.patientActive = true;
  411. _model.updatePatient = false;
  412. _model.viewPatient = true;
  413. _model.enabledAcquire = true;
  414. _model.enabledMeasure = true;
  415. _model.enabledReport = true;
  416. _model.noAppointmentSelected = false;
  417. _model.acquireViewLoaded = false;
  418. // select an appointment so reset acquire and measure pages if needed
  419. Application.application.menuPhysician.acquire.clearPage();
  420. Application.application.menuPhysician.acquire.label = ResourceManager.getInstance().getString('labels', 'physicianDisplay');
  421. Application.application.menuPhysician.generalMeasure.measures.clearPage();
  422. Application.application.menuPhysician.report.clearReportConfiguration();
  423. var parent : PatientView = this.parentDocument as PatientView;
  424. parent.loadAppointmentData(_model.appointmentSelected, false);
  425. }
  426. public function recoverLastAppointment(displayToaster : Boolean) : void
  427. {
  428. if (displayToaster)
  429. {
  430. var toastMessage : ImtToaster = new ImtToaster();
  431. toastMessage.titleMessage = ResourceManager.getInstance().getString('labels', 'information');
  432. toastMessage.message = ResourceManager.getInstance().getString('labels', 'goToLastIncompleteAppointment');
  433. toastMessage.timeToLive = 7;
  434. toastMessage.level = ImtToaster.WARNING;
  435. ApplicationModelLocator.getInstance().toaster.toast( toastMessage );
  436. }
  437. _model.patientActive = true;
  438. _model.updatePatient = false;
  439. _model.viewPatient = false;
  440. _model.enabledAcquire = true;
  441. _model.enabledMeasure = false;
  442. _model.enabledReport = false;
  443. _model.noAppointmentSelected = false;
  444. _model.acquireViewLoaded = false;
  445. var lastAppointmentId : int = 0;
  446. var lastAppointmentNumber : int = 0;
  447. var lastAppointmentVo : AppointmentVo = null;
  448. for each (var appointmentVo : AppointmentVo in _model.listOfAppointments)
  449. {
  450. if (lastAppointmentId < appointmentVo.id)
  451. {
  452. lastAppointmentId = appointmentVo.id;
  453. lastAppointmentNumber = appointmentVo.number;
  454. lastAppointmentVo = appointmentVo;
  455. }
  456. }
  457. _model.appointmentNumber = lastAppointmentNumber;
  458. _model.appointmentSelected = lastAppointmentVo;
  459. _model.patientName = _model.patientSelected.firstName + " " + _model.patientSelected.lastName;
  460. _model.appointmentSelected.livingCountry = appointmentVo.livingCountry;
  461. visitDateField.selectedDate = new Date();
  462. lastAppointmentVo.date = new Date();
  463. visitNumberLabel.text = _model.appointmentNumber.toString();
  464. _currentPatientVisit = _model.appointmentNumber.toString();
  465. var idx : int = -1;
  466. for( var i : int = 0; i < _model.countries.length; i++ )
  467. {
  468. if( _model.countries.getItemAt(i).code == appointmentVo.livingCountry )
  469. {
  470. idx = i;
  471. break;
  472. }
  473. }
  474. // select an appointment so reset acquire and measure pages if needed
  475. Application.application.menuPhysician.acquire.clearPage();
  476. Application.application.menuPhysician.generalMeasure.measures.clearPage();
  477. Application.application.menuPhysician.acquire.label = ResourceManager.getInstance().getString('labels', 'physicianAcquire');
  478. var parent : PatientView = this.parentDocument as PatientView;
  479. parent.loadAppointmentData(lastAppointmentVo, false);
  480. this.parentDocument.selectView(this.parentDocument.atsStart, this.parentDocument.atsEnd, this.parentDocument.atsBox, this.parentDocument.atsLinkButton, 1);
  481. }
  482. public function updateAppointment() : void
  483. {
  484. if (!_model.viewPatient && _model.appointmentSelected && _model.appointmentSelected.id > 0)
  485. {
  486. _model.application.menuPhysician.patient.updateAts();
  487. _model.application.menuPhysician.patient.updateCve();
  488. _model.application.menuPhysician.patient.updatePersonalHistory();
  489. _model.application.menuPhysician.patient.updateFamilyHistory();
  490. // be more smart in the future : when save patient informations ?
  491. new UpdateAppointmentEvent( _model.appointmentSelected, _model.patientSelected.uid ).dispatch();
  492. }
  493. }
  494. public function updatePatientFile() : void
  495. {
  496. _currentPatientVisit = _model.appointmentNumber.toString();
  497. var idx : int = -1;
  498. for( var i : int = 0; i < _model.countries.length; i++ )
  499. {
  500. if( _model.countries.getItemAt(i).code == _model.appointmentSelected.livingCountry )
  501. {
  502. idx = i;
  503. break;
  504. }
  505. }
  506. _model.appointmentSelected.livingCountry = _model.appointmentSelected.livingCountry;
  507. visitNumberLabel.text = _model.appointmentNumber.toString();
  508. dateAppointment.text = dateFormatter.format( _model.appointmentSelected.date );
  509. }
  510. public function resetView() : void
  511. {
  512. firstNameTextInput.text = "";
  513. lastNameTextInput.text = "";
  514. sexRadioButtonGroup.selection = null;
  515. dateOfBirthDateField.selectedDate = null;
  516. ethnicGroupComboBox.selectedIndex = -1;
  517. visitDateField.selectedDate = new Date();
  518. criteria.text = "";
  519. _currentPatientVisit = "1";
  520. dateOfBirthDateText.setStyle("color", "#555557");
  521. dateOfBirthDateText.setStyle("fontWeight", "normal");
  522. dateOfBirthDateText.errorString = "";
  523. firstNameLabel.setStyle("color", "#555557");
  524. firstNameLabel.setStyle("fontWeight", "normal");
  525. firstNameTextInput.errorString = "";
  526. lastNameLabel.setStyle("color", "#555557");
  527. lastNameLabel.setStyle("fontWeight", "normal");
  528. lastNameTextInput.errorString = "";
  529. sexLabel.setStyle("color", "#555557");
  530. sexLabel.setStyle("fontWeight", "normal");
  531. _model.patientActive = false;
  532. _model.updatePatient = false;
  533. _model.viewPatient = false;
  534. actionOnSearch.visible = false;
  535. _model.appointmentNumber = 1;
  536. }
  537. public function resetPatientData() : void
  538. {
  539. var parent : PatientView = this.parentDocument as PatientView;
  540. parent.resetPatientData();
  541. }
  542. public function resetAppointment() : void
  543. {
  544. _model.appointmentSelected = new AppointmentVo();
  545. _model.appointmentSelected.ats = new AtsVo();
  546. _model.appointmentSelected.cvExaminator = new CvExaminatorVo();
  547. _model.appointmentSelected.familyHistory = new FamilyHistoryVo();
  548. _model.appointmentSelected.personalHistory = new PersonalHistoryVo();
  549. _model.appointmentSelected.tobacco = new TobaccoVo();
  550. _model.appointmentSelected.treatments = new Array();
  551. }
  552. private function formatBirthDate( item : Object, column : DataGridColumn ) : String
  553. {
  554. var dateFormatter : DateFormatter = new DateFormatter();
  555. dateFormatter.formatString = ResourceManager.getInstance().getString( 'labels', 'date' );
  556. return dateFormatter.format( item.birthDate );
  557. }
  558. private function formatLastVisit( item : Object, column : DataGridColumn ) : String
  559. {
  560. var dateFormatter : DateFormatter = new DateFormatter();
  561. dateFormatter.formatString = ResourceManager.getInstance().getString( 'labels', 'date' );
  562. return dateFormatter.format( item.lastVisit );
  563. }
  564. private function formatAppointment( item : Object ) : String
  565. {
  566. var dateFormatter : DateFormatter = new DateFormatter();
  567. dateFormatter.formatString = ResourceManager.getInstance().getString( 'labels', 'date' );
  568. var zone : String = "";
  569. switch (item.type)
  570. {
  571. case 'CL':
  572. case 'CR':
  573. zone = ' (' + ResourceManager.getInstance().getString( 'labels', 'carotids' ) + ')';
  574. break;
  575. case 'AR':
  576. case 'AL':
  577. zone = ' (' + ResourceManager.getInstance().getString( 'labels', 'arms' ) + ')';
  578. break;
  579. case 'LL':
  580. case 'LR':
  581. zone = ' (' + ResourceManager.getInstance().getString( 'labels', 'legs' ) + ')';
  582. break;
  583. case 'BO':
  584. zone = ' (' + ResourceManager.getInstance().getString( 'labels', 'body' ) + ')';
  585. break;
  586. default:
  587. break;
  588. }
  589. return dateFormatter.format( item.date ) + zone;
  590. }
  591. private function resetCreatePatientForm() : void
  592. {
  593. _model.enabledAcquire = false;
  594. _model.enabledMeasure = false;
  595. _model.enabledReport = false;
  596. _model.cptMesuresVisite = 0;
  597. resetPatientData();
  598. resetView();
  599. }
  600. private function removeSearchPatientText() : void
  601. {
  602. criteria.text = "";
  603. }
  604. public function setSearchPatientText() : void
  605. {
  606. searchButton.setFocus();
  607. criteria.text = ResourceManager.getInstance().getString('labels', 'search.patient.info');
  608. }
  609. private function translateFirstCharToUpperCase( e : KeyboardEvent ) : void
  610. {
  611. if (firstNameTextInput.text.length == 1)
  612. {
  613. if (e.keyCode > 64 && e.keyCode < 91)
  614. {
  615. var b:String = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  616. firstNameTextInput.text = b.charAt(e.keyCode - 65);
  617. }
  618. }
  619. else
  620. {
  621. var firstCharFirstName : String = firstNameTextInput.text.substr(0, 1);
  622. var firstNameLessFirstChar : String = firstNameTextInput.text.substr(1, firstNameTextInput.text.length);
  623. firstNameTextInput.text = firstCharFirstName.toUpperCase() + firstNameLessFirstChar;
  624. }
  625. }
  626. private function checkTranslateToUpperCase( e : KeyboardEvent ) : void
  627. {
  628. lastNameTextInput.text = lastNameTextInput.text.toUpperCase();
  629. }
  630. private function translateToUpperCase( e : KeyboardEvent ) : void
  631. {
  632. var lastName : String = "";
  633. if (lastNameTextInput.text.length > 1)
  634. lastName = lastNameTextInput.text.substr(0, lastNameTextInput.text.length);
  635. else
  636. lastName = lastNameTextInput.text;
  637. if (e.keyCode > 64 && e.keyCode < 91)
  638. {
  639. var b:String = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  640. lastName += b.charAt(e.keyCode - 65);
  641. }
  642. lastNameTextInput.text = lastName;
  643. lastNameTextInput.width = 160;
  644. }
  645. private function setFieldError() : void
  646. {
  647. lastNameValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  648. firstNameValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  649. dateOfBirthValidator.requiredFieldError = ResourceManager.getInstance().getString('labels', 'required');
  650. dateOfBirthValidator.formatError = ResourceManager.getInstance().getString('labels', 'errorField');
  651. dateOfBirthValidator.invalidCharError = ResourceManager.getInstance().getString('labels', 'errorField');
  652. dateOfBirthValidator.invalidCharError = ResourceManager.getInstance().getString('labels', 'errorField');
  653. dateOfBirthValidator.wrongDayError = ResourceManager.getInstance().getString('labels', 'errorField');
  654. dateOfBirthValidator.wrongLengthError = ResourceManager.getInstance().getString('labels', 'errorField');
  655. dateOfBirthValidator.wrongMonthError = ResourceManager.getInstance().getString('labels', 'errorField');
  656. dateOfBirthValidator.wrongYearError = ResourceManager.getInstance().getString('labels', 'errorField');
  657. }
  658. private function initListeners() : void
  659. {
  660. setFieldError();
  661. lastNameValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler);
  662. firstNameValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler);
  663. dateOfBirthValidator.addEventListener(ValidationResultEvent.VALID, stringValidatorHandler);
  664. }
  665. public function updateErrorStrings() : void
  666. {
  667. setFieldError();
  668. if (lastNameTextInput.errorString)
  669. lastNameTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  670. if (firstNameTextInput.errorString)
  671. firstNameTextInput.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  672. if (dateOfBirthDateField.errorString)
  673. dateOfBirthDateField.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  674. }
  675. private function stringValidatorHandler(event : ValidationResultEvent) : void
  676. {
  677. if (event.target.errorString)
  678. event.target.errorString = null;
  679. }
  680. private function isDateOfBirthValid() : Boolean
  681. {
  682. var date : Date = new Date();
  683. if (ObjectUtil.compare(date, dateOfBirthDateField.selectedDate) < 0
  684. || dateOfBirthDateField.selectedDate.getFullYear() < _minYearOfBirth
  685. || dateOfBirthDateField.selectedDate.getFullYear() > _maxYearOfBirth)
  686. {
  687. var toastMessage : ImtToaster = new ImtToaster();
  688. toastMessage.titleMessage = ResourceManager.getInstance().getString('labels', 'warning.use');
  689. if (dateOfBirthDateField.selectedDate.getFullYear() < _minYearOfBirth)
  690. toastMessage.message = ResourceManager.getInstance().getString('labels', 'tooEarlyDate', [_minYearOfBirth]);
  691. else if (dateOfBirthDateField.selectedDate.getFullYear() > _maxYearOfBirth)
  692. toastMessage.message = ResourceManager.getInstance().getString('labels', 'tooLateDate', [_maxYearOfBirth]);
  693. else
  694. toastMessage.message = ResourceManager.getInstance().getString('labels', 'dateError');
  695. toastMessage.timeToLive = 7;
  696. toastMessage.level = ImtToaster.WARNING;
  697. ApplicationModelLocator.getInstance().toaster.toast( toastMessage );
  698. dateOfBirthDateField.text = "";
  699. dateOfBirthDateField.errorString = ResourceManager.getInstance().getString('labels', 'errorField');
  700. dateOfBirthDateField.selectedDate = null;
  701. return false;
  702. }
  703. return true;
  704. }
  705. // to do later, to highlight current patient
  706. /*public function updatePatientDatagrid() : void
  707. {
  708. if (_patientSelectedIndex != -1)
  709. {
  710. dg.invalidateDisplayList();
  711. dg.selectedIndex = _patientSelectedIndex;
  712. dg.selectedIndices = [_patientSelectedIndex];
  713. dg.validateNow();
  714. dg.scrollToIndex(_patientSelectedIndex);
  715. }
  716. comboBoxAppointmentSelected.selectedIndex = _appointmentSelectedIndex;
  717. }*/