Untitled diff

Created Diff never expires
33 removals
39 lines
45 additions
50 lines
function TTextTestImporter.ParseHeader(Lines: TStrings): Boolean;
function TTextTestImporter.ParseHeader(Lines: TStrings): Boolean;
var
var
i, Pos1, Pos2, Pos3, Pos4, Age: Integer;
PatientFound, DateFound: Boolean;
Line, PatientName: String;
Line, PatientName, AgeStr, BirthDateStr, DateStr: String;
PatientRegex, DateRegex: TRegExpr;
i: Integer;
begin
begin
PatientRegex := TRegExpr.Create;
PatientRegex.Expression := 'Paciente\s+:*(.*)\s{2,}Idade:+(\d+)\s*anos\s*Nascimento:*(.+)';
PatientRegex.ModifierI := True;
PatientRegex.ModifierG := True;

DateRegex := TRegExpr.Create;
DateRegex.Expression := 'Data\s*de\s*Cadastro\.*\s*:*(.+)';
DateRegex.ModifierI := True;
DateRegex.ModifierG := True;

Result := False;
Result := False;
for i := 0 to Lines.Count -1 do
PatientFound := False;
DateFound := False;
for i := 0 to Lines.Count - 1 do
begin
begin
if Result then
if (DateFound and PatientFound) or (i > 20) then
Exit;
break;
Line := UpperCase(Trim(Lines[i]));
Line := Trim(Lines[i]);
if AnsiStartsStr('PACIENTE', Line) then
if not PatientFound and PatientRegex.Exec(Line) then
begin
PatientFound := True;
PatientName := Trim(PatientRegex.Match[1]);
AgeStr := Trim(PatientRegex.Match[2]);
BirthDateStr := Trim(PatientRegex.Match[3]);
FData.Strings['name'] := PatientName;
FData.Integers['age'] := StrToIntDef(AgeStr, 0);
FData.Floats['birthdate'] := ScanDateTime('dd/mm/yy', BirthDateStr);
continue;
end;

if not DateFound and DateRegex.Exec(Line) then
begin
begin
Pos1 := PosEx(':', Line, Length('PACIENTE') + 1);
DateFound := True;
if Pos1 > 0 then
DateStr := Trim(DateRegex.Match[1]);
begin
FData.Floats['date'] := ScanDateTime('dd/mm/yyyy', DateStr);
Pos2 := RPos('IDADE', Line);
if Pos2 > 0 then
begin
PatientName := Trim(Copy(Line, Pos1 + 1, Pos2 - Pos1 - 1));
if PatientName <> '' then
begin
Result := True;
FData.Strings['name'] := PatientName;
Pos3 := PosEx(':', Line, Pos2);
if Pos3 <> 0 then
begin
Pos4 := PosEx('ANOS', Line, Pos3);
if TryStrToInt(Trim(Copy(Line, Pos3 + 1, Pos4 - Pos3 - 1)), Age) then
FData.Integers['age'] := Age;
end;
end;
end;
end;
end;
end;
end;
end;
Result := DateFound and PatientFound
and (FData.Get('name', '') <> '')
and (FData.Get('age', 0) <> 0)
and (FData.Get('birthdate', 0.0) <> 0)
and (FData.Get('date', 0.0) <> 0);
end;
end;