-
Notifications
You must be signed in to change notification settings - Fork 0
/
UMRecord.pas
316 lines (281 loc) · 7.43 KB
/
UMRecord.pas
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
unit UMRecord;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.StdCtrls, System.StrUtils,
Vcl.ExtCtrls, Vcl.Grids, Vcl.ValEdit, Vcl.Buttons, Vcl.Samples.Spin, SQLiteWrap;
type
TfrmMedicalRecord = class(TForm)
grp1: TGroupBox;
pgc1: TPageControl;
ts1: TTabSheet;
ts2: TTabSheet;
vlsExam: TValueListEditor;
rgType: TRadioGroup;
lblHospital: TLabel;
lblSeeTime: TLabel;
lblRecord: TLabel;
mmoRecord: TMemo;
edtHospital: TEdit;
dtpInDocTime: TDateTimePicker;
tvLisItem: TTreeView;
pnl1: TPanel;
grpLisInfo: TGroupBox;
mmoRemark: TMemo;
btnSave: TButton;
btnClose: TButton;
lblTreatment: TLabel;
edtID: TEdit;
lvLis: TListView;
lblLisName: TLabel;
btnSaveLis: TButton;
chkPositive: TCheckBox;
edtLisValue: TEdit;
edtTreatment: TMemo;
lbl1: TLabel;
lbl2: TLabel;
edtLisScope: TEdit;
procedure FormCreate(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure btnSaveLisClick(Sender: TObject);
procedure tvLisItemClick(Sender: TObject);
private
procedure InitExamAndLis;
procedure FillExamList;
procedure FillLisList;
procedure FillLisDict;
procedure MarkTree(tab: TSQLiteTable; TreeView: TTreeView);
{ Private declarations }
public
{ Public declarations }
mrType: Integer;
medId: Integer; //medicalrecord.id
end;
var
frmMedicalRecord: TfrmMedicalRecord;
implementation
{$R *.dfm}
uses UModels, UDB;
procedure TfrmMedicalRecord.btnSaveClick(Sender: TObject);
var mr: TMedicalRecord;
begin
mr := TMedicalRecord.Create();
with mr do
begin
id := StrToInt(edtId.Text);
patientId := patient.id;
hospital := Trim(edtHospital.Text);
seeTime := DateToStr(dtpInDocTime.Date);
treatment := Trim(edtTreatment.Text);
mrRecord := Trim(mmoRecord.Text);
mrType := rgType.ItemIndex + 1;
publishTime := DateTimeToStr(now());
updateTime := publishTime;
if id = 0 then
begin
medId :=mr.Insert();
edtId.Text := IntToStr(medId);
pgc1.Visible := True;
top := top - 200;
Height := 610;
FillExamList;
end else
begin
mr.Update();
TMedicalExam.UpdateAll(mr.id, vlsExam.Strings);
end;
end;
end;
procedure TfrmMedicalRecord.btnCloseClick(Sender: TObject);
begin
close;
end;
procedure TfrmMedicalRecord.FillExamList;
begin
TMedicalExam.FindAll(medId);
with Tab do
begin
if Tab.Row <> 0 then
begin
while not EOF do
begin
vlsExam.InsertRow(Tab.FieldByName['exam_name'], Tab.FieldByName['exam_value'], True);
Next;
end;
end;
end;
end;
procedure TfrmMedicalRecord.FillLisList;
var ListItem: TListItem;
begin
lvLis.Items.Clear;
TMedicalLis.FindAll(medId);
with Tab do
begin
if Tab.Row <> 0 then
begin
while not EOF do
begin
ListItem := lvLis.Items.Add;
ListItem.Caption := Tab.FieldByName['lis_name'];
ListItem.SubItems.Add(Tab.FieldByName['lis_value']);
ListItem.SubItems.Add(IfThen(Tab.FieldByName['positive']='1', '阳性', '阴性'));
ListItem.SubItems.Add(Tab.FieldByName['id']);
Next;
end;
end;
end;
end;
procedure TfrmMedicalRecord.FormCreate(Sender: TObject);
begin
medId := 0;
FillLisDict;
end;
procedure TfrmMedicalRecord.FormShow(Sender: TObject);
begin
if medId = 0 then
begin
pgc1.Visible := false;
Height := Height - pgc1.Height;
rgType.ItemIndex := mrType -1;
dtpInDocTime.Date := Date();
//InitExamLis;
end else if medId > 0 then
begin
TMedicalRecord.One(medId);
if Tab.Row <> 0 then
begin
edtHospital.Text := Tab.FieldByName['hospital'];
dtpInDocTime.Date := StrToDate(Tab.FieldByName['seeTime']);
edtTreatment.Text := Tab.FieldByName['treatment'];
mmoRecord.Text := Tab.FieldByName['record'];
mrType := StrToInt(Tab.FieldByName['type']);
rgType.ItemIndex := StrToInt(Tab.FieldByName['type']) - 1;
edtID.Text := Tab.FieldByName['id'];
FillExamList;
FillLisList;
end;
end;
if mrType=3 then
begin
lblHospital.Caption := '体检医院:';
lblSeeTime.Caption := '体检时间:';
lblRecord.Caption := '异常项目:';
lblTreatment.Caption := '体检结果:';
end;
pgc1.ActivePageIndex := 0;
rgType.Enabled := False;
edtHospital.SetFocus;
end;
procedure TfrmMedicalRecord.InitExamAndLis;
begin
with vlsExam do
begin
InsertRow('心电图', '正常', true);
InsertRow('心血管造影', '', true);
InsertRow('B超', '', true);
InsertRow('X光检查', '', true);
InsertRow('MR/DR', '', true);
InsertRow('CT', '', true);
InsertRow('核磁', '', true);
InsertRow('PED-CI', '', true);
InsertRow('病理', '', true);
InsertRow('其它', '', true);
end;
//with vlsLis do
//begin
// InsertRow('总胆红素', '10', true);
// InsertRow('间接胆红素', '11', true);
// InsertRow('直接胆红素', '2', true);
// InsertRow('钠(Na)', '120', true);
// InsertRow('钙(Ca)', '3', true);
//end;
end;
procedure TfrmMedicalRecord.tvLisItemClick(Sender: TObject);
var
sql: string;
begin
with tvLisItem.Selected do
begin
grpLisInfo.Enabled := not HasChildren;
if not HasChildren then
begin
lblLisName.Caption := Text;
edtLisValue.Text := '';
sql := 'Select * from medicallisdict where lis_name =''#lisname''';
sql := StringReplace(sql, '#lisname', Text, []);
Tab:= db.GetTable(sql);
if Not Tab.EOF then
begin
edtLisScope.Text := tab.FieldByName['scope'];
mmoRemark.Lines.Clear;
mmoRemark.Lines.Add(tab.FieldByName['remark']);
end;
end;
end;
end;
procedure TfrmMedicalRecord.btnSaveLisClick(Sender: TObject);
begin
if SameText(Trim(edtLisValue.Text), EmptyStr) then
begin
ShowMessage('请填写检验结果!');
edtLisValue.SetFocus;
exit;
end else
begin
with TMedicalLis.Create() do
begin
med_id := medId;
lis_name := StringReplace(lblLisName.Caption, ':', '', []);
lis_value := edtLisValue.Text;
positive := StrToInt(IfThen(chkPositive.Checked, '1', '0'));
if Insert <> 0 then
begin
ShowMessage('成功增加检验项目!');
FillLisList;
end;
end;
end;
end;
procedure TfrmMedicalRecord.FillLisDict;
var
dictTab: TSQLiteTable;
begin
dictTab := db.GetTable('select id, parent_id, lis_name from medicallisdict order by parent_id');
MarkTree(dictTab, tvLisItem)
end;
procedure TfrmMedicalRecord.MarkTree(tab: TSQliteTable; TreeView: TTreeView);
var
List: TStringList;
Node: TTreeNode;
Index: Integer;
begin
TreeView.Items.BeginUpdate;
try
TreeView.Items.Clear;
List := TStringList.Create;
try
List.Sorted := True;
while not tab.Eof do
begin
if tab.FieldByName['parent_id'] = '0' then { ParentID=0,顶层节点 }
Node := TreeView.Items.AddChild(nil, tab.FieldByName['lis_name'])
else
begin
Index := List.IndexOf(tab.FieldByName['parent_id']);
Node := TreeView.Items.AddChild(TTreeNode(List.Objects[Index]),
tab.FieldByName['lis_name']);
end;
List.AddObject(tab.FieldByName['id'], Node);
tab.Next;
end;
finally
List.Free;
end;
finally
TreeView.Items.EndUpdate;
end;
end;
end.