1 | /* Command
|
---|
2 | event & command must be added to TrackingController.as */
|
---|
3 |
|
---|
4 | package gov.va.med.edp.command
|
---|
5 | {
|
---|
6 | import com.adobe.cairngorm.commands.ICommand;
|
---|
7 | import com.adobe.cairngorm.control.CairngormEvent;
|
---|
8 |
|
---|
9 | import gov.va.med.edp.business.AddPatientToLogDelegate;
|
---|
10 | import gov.va.med.edp.control.PatientSelectEvent;
|
---|
11 | import gov.va.med.edp.factory.TrackingFactory;
|
---|
12 | import gov.va.med.edp.model.TrackingModelLocator;
|
---|
13 | import gov.va.med.edp.util.Vista;
|
---|
14 | import gov.va.med.edp.widget.InfoDialog;
|
---|
15 |
|
---|
16 | import mx.collections.ArrayCollection;
|
---|
17 | import mx.collections.Sort;
|
---|
18 | import mx.collections.SortField;
|
---|
19 | import mx.rpc.IResponder;
|
---|
20 | import mx.rpc.events.FaultEvent;
|
---|
21 | import mx.rpc.events.ResultEvent;
|
---|
22 |
|
---|
23 | public class AddPatientToLogCommand extends AbstractResponderCommand implements ICommand, IResponder
|
---|
24 | {
|
---|
25 | private var model:TrackingModelLocator = TrackingModelLocator.getInstance();
|
---|
26 |
|
---|
27 | public function execute(event:CairngormEvent):void
|
---|
28 | {
|
---|
29 | var delegate:AddPatientToLogDelegate = new AddPatientToLogDelegate(this);
|
---|
30 | var addEvent:PatientSelectEvent = PatientSelectEvent(event);
|
---|
31 | var localTime: String = Vista.DatetoFM(model.buildSiteDate());
|
---|
32 |
|
---|
33 | delegate.addPatientToLog(addEvent.newPatient, model.logArea, localTime, model.logEdit.choiceTS);
|
---|
34 | }
|
---|
35 |
|
---|
36 | public override function result(data:Object):void
|
---|
37 | {
|
---|
38 | var xml:XML = ResultEvent(data).result as XML;
|
---|
39 |
|
---|
40 | if (xml.add.@status == "fail") {
|
---|
41 | InfoDialog.show("Patient could not be added to the log: " + xml.add.@msg);
|
---|
42 | return;
|
---|
43 | }
|
---|
44 |
|
---|
45 | // make sure the choices are set up before setting the logEntry
|
---|
46 | model.logEdit.setChoices(xml.choices[0]);
|
---|
47 | // now that the choices are in place, we can set the log entry
|
---|
48 | model.logEdit.setEntry(TrackingFactory.buildLogEntryFromXML(xml.logEntry[0]));
|
---|
49 | model.logEdit.entry.isStub = true;
|
---|
50 | model.logEdit.dirty = true;
|
---|
51 | model.setEditState();
|
---|
52 |
|
---|
53 | // refresh the list of log entries
|
---|
54 | model.logEntryList.entries =
|
---|
55 | new ArrayCollection(TrackingFactory.buildLogSelectorListFromXML(xml.logEntries.log));
|
---|
56 | model.logEntryList.token = xml.logEntries.@token;
|
---|
57 |
|
---|
58 | // sort based on previous settings
|
---|
59 | if (model.logEntryList.sortField.length > 0) {
|
---|
60 | var sort:Sort = new Sort();
|
---|
61 | sort.fields = [new SortField(model.logEntryList.sortField, true, model.logEntryList.sortDescending)];
|
---|
62 | model.logEntryList.entries.sort = sort;
|
---|
63 | model.logEntryList.entries.refresh();
|
---|
64 | }
|
---|
65 | // now that it is sorted, set the selected index to the just added patient
|
---|
66 | // (must set initial -1 to fire bindings)
|
---|
67 | model.logEntryList.selectedIndex = -1;
|
---|
68 | model.logEntryList.selectedIndex =
|
---|
69 | Vista.locateIndex(model.logEntryList.entries, model.logEdit.entry.id, "id");
|
---|
70 | model.logEntryList.selectedID = model.logEdit.entry.id;
|
---|
71 |
|
---|
72 | model.logEdit.patientSelected = true;
|
---|
73 | }
|
---|
74 |
|
---|
75 | protected override function getFaultMessage(faultEvent:FaultEvent):String {
|
---|
76 | return "Add patient to log failed: " + super.getFaultMessage(faultEvent);
|
---|
77 | }
|
---|
78 | }
|
---|
79 | }
|
---|