You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
619 lines
24 KiB
619 lines
24 KiB
|
1 month ago
|
program DfcRptz;
|
||
|
|
|
||
|
|
{$APPTYPE CONSOLE}
|
||
|
|
|
||
|
|
uses
|
||
|
|
ControlsAtomFix,
|
||
|
|
DefineTypes,
|
||
|
|
|
||
|
|
Windows,
|
||
|
|
ActiveX,
|
||
|
|
Classes,
|
||
|
|
DfcRpts,
|
||
|
|
Graphics,
|
||
|
|
IniFiles,
|
||
|
|
JPEG,
|
||
|
|
msxml,
|
||
|
|
SysUtils;
|
||
|
|
|
||
|
|
|
||
|
|
var
|
||
|
|
nI, nX1Len : Integer;
|
||
|
|
gPSInStr, gPPInStr : string;
|
||
|
|
gSourceImgFile, gTargetDcmFile, gSourcePdfFile, gSourceStcFile : string;
|
||
|
|
gDcmFileInfo : TDcmFileInfo;
|
||
|
|
gDebugOutput, gDebugConvert : Boolean;
|
||
|
|
|
||
|
|
function InitP1XMLStr:string;
|
||
|
|
var
|
||
|
|
sDate, sTime, aAccNo: string;
|
||
|
|
|
||
|
|
function GetPSex:string;
|
||
|
|
begin
|
||
|
|
if Odd(Random(2)) then
|
||
|
|
Result := 'M'
|
||
|
|
else
|
||
|
|
Result := 'F';
|
||
|
|
end;
|
||
|
|
begin
|
||
|
|
Randomize;
|
||
|
|
sDate := GetRndDateStr(5);
|
||
|
|
sTime := GetRndTimeStr;
|
||
|
|
aAccNo := GetRndStr(8);
|
||
|
|
Result := '<XML>';
|
||
|
|
Result := Result + '<ODSP>';
|
||
|
|
Result := Result + '<EXEPIN DICOMType="2000">'; //DICOMType : 1000=Image, 2000=Report, 3000=Data
|
||
|
|
|
||
|
|
//Result := Result + '<Patient PatientID="!"@#$^&*()<>'':;'12345" PatientName="P' + GetRndStr(7);
|
||
|
|
//Result := Result + '" PatientSex="" PatientDOB=""></Patient>';
|
||
|
|
|
||
|
|
Result := Result + '<Patient PatientID="' + GetRndStr(8) + '" PatientName="P' + GetRndStr(7);
|
||
|
|
Result := Result + '" PatientSex="' + GetPSex + '" PatientDOB="' + GetRndDateStr(100) + '"></Patient>';
|
||
|
|
|
||
|
|
Result := Result + '<Study StudyDate="' + sDate + '" StudyTime="' + sTime + '" StudyID="' + GetRndStr(8);
|
||
|
|
Result := Result + '" AccessionNumber="' + GetRndStr(8)+ '" SOPClassUID=" 1.2.840.10008.5.1.4.1.1.7"></Study>';
|
||
|
|
Result := Result + '<Series SeriesDate="' + sDate + '" SeriesTime="' + sTime + '" SeriesNumber="' + GetRndStr(1);
|
||
|
|
Result := Result + '" Modality="OP" InstitutionName="HuiMu IT Co., Ltd." ModelName="Data Convertor" Manufacturer="HM-OEIS"></Series>';
|
||
|
|
//Result := Result + '<Image InstanceNumber="1" Laterality="L" ImageLaterality="R" BurnedInAnnotation="#NULL#" ';
|
||
|
|
Result := Result + '<Image InstanceNumber="1" Laterality="L" ImageLaterality="R" BurnedInAnnotation="YES" ';
|
||
|
|
Result := Result + 'SamplesPerPixel="1" Rows="1000" Columns="512" BitAllocated="16" BitStored="16" HighBit="15"></Image>';
|
||
|
|
Result := Result + '</EXEPIN>';
|
||
|
|
Result := Result + '</ODSP>';
|
||
|
|
Result := Result + '</XML>';
|
||
|
|
end;
|
||
|
|
|
||
|
|
function InitXMLP1Info(aXMLData: string):Boolean;
|
||
|
|
var
|
||
|
|
//tFile: TextFile;
|
||
|
|
//sXML : string;
|
||
|
|
node : IXMLDOMElement;
|
||
|
|
vXMLHelper : IXMLDOMDocument;
|
||
|
|
begin
|
||
|
|
Result := False;
|
||
|
|
nX1Len := Length(aXMLData);
|
||
|
|
WriteLogText(44, 'I', 'InitXMLP1Info ' + IntToStr(nX1Len) + ' bytes');
|
||
|
|
try
|
||
|
|
{
|
||
|
|
sXML := '';
|
||
|
|
AssignFile(tFile, 'C:\Users\User\Desktop\ImgList.xml');
|
||
|
|
Reset(tFile);
|
||
|
|
while not Eof(tFile) do
|
||
|
|
begin
|
||
|
|
Readln(tFile, sTmp);
|
||
|
|
sXML := sXML + sTmp;
|
||
|
|
end;
|
||
|
|
CloseFile(tFile);
|
||
|
|
//Showmessage(sXML);
|
||
|
|
//}
|
||
|
|
|
||
|
|
if Length(aXMLData) < 1 then
|
||
|
|
aXMLData := InitP1XMLStr;
|
||
|
|
|
||
|
|
vXMLHelper := CoDOMDocument.Create;
|
||
|
|
if vXMLHelper.loadXML(aXMLData) then
|
||
|
|
begin
|
||
|
|
node := IXMLDOMElement(vXMLHelper.selectSingleNode('/XML/ODSP/EXEPIN'));
|
||
|
|
if node <> nil then
|
||
|
|
begin
|
||
|
|
if node.attributes.getNamedItem('DICOMType') <> nil then
|
||
|
|
gDcmFileInfo.DICOMType := StrToIntDef(node.attributes.getNamedItem('DICOMType').Text, 0);
|
||
|
|
if node.attributes.getNamedItem('DebugConvert') <> nil then
|
||
|
|
begin
|
||
|
|
if node.attributes.getNamedItem('DebugConvert').Text = '1' then
|
||
|
|
gDebugConvert := True;
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
|
||
|
|
node := IXMLDOMElement(vXMLHelper.selectSingleNode('/XML/ODSP/EXEPIN/Patient'));
|
||
|
|
if node <> nil then
|
||
|
|
begin
|
||
|
|
if node.attributes.getNamedItem('PatientID') <> nil then
|
||
|
|
gDcmFileInfo.PatientID := Trim(node.attributes.getNamedItem('PatientID').Text);
|
||
|
|
if node.attributes.getNamedItem('PatientIssuerID') <> nil then
|
||
|
|
gDcmFileInfo.PatientIssuerID := Trim(node.attributes.getNamedItem('PatientIssuerID').Text);
|
||
|
|
if node.attributes.getNamedItem('PatientName') <> nil then
|
||
|
|
gDcmFileInfo.PatientName := Trim(node.attributes.getNamedItem('PatientName').Text);
|
||
|
|
if node.attributes.getNamedItem('PatientDOB') <> nil then
|
||
|
|
gDcmFileInfo.PatientDOB := Trim(node.attributes.getNamedItem('PatientDOB').Text);
|
||
|
|
if node.attributes.getNamedItem('PatientSex') <> nil then
|
||
|
|
gDcmFileInfo.PatientSex := Trim(node.attributes.getNamedItem('PatientSex').Text);
|
||
|
|
end;
|
||
|
|
|
||
|
|
node := IXMLDOMElement(vXMLHelper.selectSingleNode('/XML/ODSP/EXEPIN/Study'));
|
||
|
|
if node <> nil then
|
||
|
|
begin
|
||
|
|
if node.attributes.getNamedItem('AccessionNumber') <> nil then
|
||
|
|
gDcmFileInfo.AccessionNumber := Trim(node.attributes.getNamedItem('AccessionNumber').Text);
|
||
|
|
if node.attributes.getNamedItem('StudyInstanceUID') <> nil then
|
||
|
|
gDcmFileInfo.StudyInstanceUID := Trim(node.attributes.getNamedItem('StudyInstanceUID').Text);
|
||
|
|
if node.attributes.getNamedItem('StudyID') <> nil then
|
||
|
|
gDcmFileInfo.StudyID := Trim(node.attributes.getNamedItem('StudyID').Text);
|
||
|
|
if node.attributes.getNamedItem('StudyDate') <> nil then
|
||
|
|
gDcmFileInfo.StudyDate := Trim(node.attributes.getNamedItem('StudyDate').Text);
|
||
|
|
if node.attributes.getNamedItem('StudyTime') <> nil then
|
||
|
|
gDcmFileInfo.StudyTime := Trim(node.attributes.getNamedItem('StudyTime').Text);
|
||
|
|
if node.attributes.getNamedItem('StudyDescription') <> nil then
|
||
|
|
gDcmFileInfo.StudyDescription := Trim(node.attributes.getNamedItem('StudyDescription').Text);
|
||
|
|
if node.attributes.getNamedItem('ReferringPhysicianName') <> nil then
|
||
|
|
gDcmFileInfo.ReferringPhysicianName := Trim(node.attributes.getNamedItem('ReferringPhysicianName').Text);
|
||
|
|
end;
|
||
|
|
|
||
|
|
node := IXMLDOMElement(vXMLHelper.selectSingleNode('/XML/ODSP/EXEPIN/Series'));
|
||
|
|
if node <> nil then
|
||
|
|
begin
|
||
|
|
if node.attributes.getNamedItem('SeriesInstanceUID') <> nil then
|
||
|
|
gDcmFileInfo.SeriesInstanceUID := Trim(node.attributes.getNamedItem('SeriesInstanceUID').Text);
|
||
|
|
if node.attributes.getNamedItem('Modality') <> nil then
|
||
|
|
gDcmFileInfo.Modality := Trim(node.attributes.getNamedItem('Modality').Text);
|
||
|
|
if node.attributes.getNamedItem('SeriesNumber') <> nil then
|
||
|
|
gDcmFileInfo.SeriesNumber := Trim(node.attributes.getNamedItem('SeriesNumber').Text);
|
||
|
|
if node.attributes.getNamedItem('SeriesDate') <> nil then
|
||
|
|
gDcmFileInfo.SeriesDate := Trim(node.attributes.getNamedItem('SeriesDate').Text);
|
||
|
|
if node.attributes.getNamedItem('SeriesTime') <> nil then
|
||
|
|
gDcmFileInfo.SeriesTime := Trim(node.attributes.getNamedItem('SeriesTime').Text);
|
||
|
|
if node.attributes.getNamedItem('SeriesDescription') <> nil then
|
||
|
|
gDcmFileInfo.SeriesDescription := Trim(node.attributes.getNamedItem('SeriesDescription').Text);
|
||
|
|
if node.attributes.getNamedItem('InstitutionName') <> nil then
|
||
|
|
gDcmFileInfo.InstitutionName := Trim(node.attributes.getNamedItem('InstitutionName').Text);
|
||
|
|
if node.attributes.getNamedItem('Manufacturer') <> nil then
|
||
|
|
gDcmFileInfo.Manufacturer := Trim(node.attributes.getNamedItem('Manufacturer').Text);
|
||
|
|
if node.attributes.getNamedItem('ModelName') <> nil then
|
||
|
|
gDcmFileInfo.ModelName := Trim(node.attributes.getNamedItem('ModelName').Text);
|
||
|
|
if node.attributes.getNamedItem('SoftwareVersions') <> nil then
|
||
|
|
gDcmFileInfo.SoftwareVersions := Trim(node.attributes.getNamedItem('SoftwareVersions').Text);
|
||
|
|
if node.attributes.getNamedItem('CreatorVersionUID') <> nil then
|
||
|
|
gDcmFileInfo.CreatorVersionUID := Trim(node.attributes.getNamedItem('CreatorVersionUID').Text);
|
||
|
|
end;
|
||
|
|
|
||
|
|
node := IXMLDOMElement(vXMLHelper.selectSingleNode('/XML/ODSP/EXEPIN/Image'));
|
||
|
|
if node <> nil then
|
||
|
|
begin
|
||
|
|
if node.attributes.getNamedItem('SOPInstanceUID') <> nil then
|
||
|
|
gDcmFileInfo.SOPInstanceUID := Trim(node.attributes.getNamedItem('SOPInstanceUID').Text);
|
||
|
|
if node.attributes.getNamedItem('ImageDate') <> nil then
|
||
|
|
gDcmFileInfo.ImageDate := Trim(node.attributes.getNamedItem('ImageDate').Text);
|
||
|
|
if node.attributes.getNamedItem('ImageTime') <> nil then
|
||
|
|
gDcmFileInfo.ImageTime := Trim(node.attributes.getNamedItem('ImageTime').Text);
|
||
|
|
if node.attributes.getNamedItem('ImageType') <> nil then
|
||
|
|
gDcmFileInfo.ImageType := Trim(node.attributes.getNamedItem('ImageType').Text);
|
||
|
|
if node.attributes.getNamedItem('InstanceNumber') <> nil then
|
||
|
|
gDcmFileInfo.ImageNumber := StrToIntDef(node.attributes.getNamedItem('InstanceNumber').Text, 1);
|
||
|
|
if node.attributes.getNamedItem('Laterality') <> nil then
|
||
|
|
gDcmFileInfo.Laterality := Trim(node.attributes.getNamedItem('Laterality').Text);
|
||
|
|
if node.attributes.getNamedItem('ImageLaterality') <> nil then
|
||
|
|
gDcmFileInfo.ImageLaterality := Trim(node.attributes.getNamedItem('ImageLaterality').Text);
|
||
|
|
if node.attributes.getNamedItem('PdfDocTitle') <> nil then
|
||
|
|
gDcmFileInfo.PdfDocTitle := Trim(node.attributes.getNamedItem('PdfDocTitle').Text);
|
||
|
|
if node.attributes.getNamedItem('BurnedInAnnotation') <> nil then
|
||
|
|
gDcmFileInfo.BurnedInAnnotation := Trim(node.attributes.getNamedItem('BurnedInAnnotation').Text);
|
||
|
|
end;
|
||
|
|
|
||
|
|
if Trim(gDcmFileInfo.ImageDate) = '' then
|
||
|
|
gDcmFileInfo.ImageDate := gDcmFileInfo.SeriesDate;
|
||
|
|
if Trim(gDcmFileInfo.ImageTime) = '' then
|
||
|
|
gDcmFileInfo.ImageTime := gDcmFileInfo.SeriesTime;
|
||
|
|
|
||
|
|
Result := True;
|
||
|
|
WriteLogText(44, 'I', 'InitXMLP1Info done');
|
||
|
|
end
|
||
|
|
else
|
||
|
|
begin
|
||
|
|
WriteLogText(0, 'E', 'Load P1 XML string Failed');
|
||
|
|
end;
|
||
|
|
except
|
||
|
|
on e:exception do
|
||
|
|
begin
|
||
|
|
WriteLogText(0, 'W', 'Load P1 XML string with error : ' + e.Message);
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
|
||
|
|
function InitXMLP2Info(aXMLData: string):Boolean;
|
||
|
|
var
|
||
|
|
sTmp, sTaskIDStr : string;
|
||
|
|
vXMLHelper : IXMLDOMDocument;
|
||
|
|
node : IXMLDOMElement;
|
||
|
|
begin
|
||
|
|
Result := False;
|
||
|
|
sTaskIDStr := '';
|
||
|
|
WriteLogText(44, 'I', 'InitXMLP2Info ' + IntToStr(Length(aXMLData)) + ' bytes');
|
||
|
|
try
|
||
|
|
if Length(aXMLData) < 1 then
|
||
|
|
Exit;
|
||
|
|
|
||
|
|
vXMLHelper := CoDOMDocument.Create;
|
||
|
|
if vXMLHelper.loadXML(aXMLData) then
|
||
|
|
begin
|
||
|
|
sTaskIDStr := '54321';
|
||
|
|
//<XML><ODSP><EXESIN Type="0" ReportFile="D:\Data\ReportFile.pdf" RSTCFile="D:\Data\RSTCFile.dat" ImageFile="D:\Data\ImageFile.jpg" OutputFile="D:\Data\OutFile.dcm"/></ODSP></XML>
|
||
|
|
node := IXMLDOMElement(vXMLHelper.selectSingleNode('/XML/ODSP/EXESIN'));
|
||
|
|
sTmp := Trim(node.attributes.getNamedItem('Type').Text);
|
||
|
|
if sTmp = '0' then
|
||
|
|
begin
|
||
|
|
//�Ա���ͼ���ļ�ת���ļ�
|
||
|
|
if node.attributes.getNamedItem('OutputFile') <> nil then
|
||
|
|
gTargetDcmFile := Trim(node.attributes.getNamedItem('OutputFile').Text);
|
||
|
|
if node.attributes.getNamedItem('TaskID') <> nil then
|
||
|
|
sTaskIDStr := Trim(node.attributes.getNamedItem('TaskID').Text);
|
||
|
|
if Pos('0' + IntToStr(nX1Len), sTaskIDStr) > 1 then
|
||
|
|
begin
|
||
|
|
if node.attributes.getNamedItem('ImageFile') <> nil then
|
||
|
|
gSourceImgFile := Trim(node.attributes.getNamedItem('ImageFile').Text);
|
||
|
|
if node.attributes.getNamedItem('ReportFile') <> nil then
|
||
|
|
gSourcePdfFile := Trim(node.attributes.getNamedItem('ReportFile').Text);
|
||
|
|
gTaskInitP1 := False;
|
||
|
|
gTaskInitP2 := True;
|
||
|
|
end
|
||
|
|
else
|
||
|
|
begin
|
||
|
|
if node.attributes.getNamedItem('ImageFile') <> nil then
|
||
|
|
gSourceImgFile := Trim(node.attributes.getNamedItem('ImageFile').Text);
|
||
|
|
if node.attributes.getNamedItem('ReportFile') <> nil then
|
||
|
|
gSourcePdfFile := Trim(node.attributes.getNamedItem('ReportFile').Text);
|
||
|
|
end;
|
||
|
|
if node.attributes.getNamedItem('RSTCFile') <> nil then
|
||
|
|
gSourceStcFile := Trim(node.attributes.getNamedItem('RSTCFile').Text);
|
||
|
|
end
|
||
|
|
else if sTmp = '1' then
|
||
|
|
begin
|
||
|
|
//�����ݿ���ȡת����Ϣ���ѽ��ã�
|
||
|
|
end;
|
||
|
|
Result := True;
|
||
|
|
WriteLogText(44, 'I', 'InitXMLP2Info done');
|
||
|
|
end
|
||
|
|
else
|
||
|
|
begin
|
||
|
|
WriteLogText(0, 'E', 'Load P2 XML string Failed');
|
||
|
|
end;
|
||
|
|
|
||
|
|
except
|
||
|
|
on e:exception do
|
||
|
|
begin
|
||
|
|
WriteLogText(0, 'W', 'Load P2 XML string with error : ' + e.Message);
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
|
||
|
|
function ProcessReportDSP:Boolean;
|
||
|
|
var
|
||
|
|
jpgA : TJPEGImage;
|
||
|
|
msJPG, msPdfReport, msStc : TMemoryStream;
|
||
|
|
iImgWidth, iImgHeight : Integer;
|
||
|
|
//sDebugInfo : string;
|
||
|
|
begin
|
||
|
|
Result := False;
|
||
|
|
WriteLogText(44, 'I', 'Start ProcessReportDSP');
|
||
|
|
iImgWidth := 0;
|
||
|
|
iImgHeight := 0;
|
||
|
|
msPdfReport := TMemoryStream.Create;
|
||
|
|
msStc := TMemoryStream.Create;
|
||
|
|
msJPG := TMemoryStream.Create;
|
||
|
|
|
||
|
|
WriteLogText(44, 'I', 'PdfReportFile = [' + gSourcePdfFile + ']');
|
||
|
|
if Length(gSourcePdfFile) > 0 then
|
||
|
|
begin
|
||
|
|
if FileExists(gSourcePdfFile) then
|
||
|
|
begin
|
||
|
|
try
|
||
|
|
WriteLogText(44, 'I', 'Loading PdfReportFile(' + gSourcePdfFile + ')');
|
||
|
|
msPdfReport.LoadFromFile(gSourcePdfFile);
|
||
|
|
if msPdfReport.Size > 0 then
|
||
|
|
begin
|
||
|
|
gDcmFileInfo.SourceDataAddress := Integer(msPdfReport.Memory);
|
||
|
|
gDcmFileInfo.SourceDataSize := msPdfReport.Size;
|
||
|
|
end;
|
||
|
|
except
|
||
|
|
on e:exception do
|
||
|
|
begin
|
||
|
|
WriteLogText(0, 'E', 'Load PdfReportFile error : ' + e.Message);
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
end
|
||
|
|
else
|
||
|
|
WriteLogText(10, 'W', 'PdfReportFile(' + gSourcePdfFile + ') not exists');
|
||
|
|
end;
|
||
|
|
|
||
|
|
WriteLogText(44, 'I', 'StcFile = [' + gSourceStcFile + ']');
|
||
|
|
if Length(gSourceStcFile) > 0 then
|
||
|
|
begin
|
||
|
|
if FileExists(gSourceStcFile) then
|
||
|
|
begin
|
||
|
|
try
|
||
|
|
WriteLogText(44, 'I', 'Loading StcFile(' + gSourceStcFile + ')');
|
||
|
|
msStc.LoadFromFile(gSourceStcFile);
|
||
|
|
if msStc.Size > 0 then
|
||
|
|
begin
|
||
|
|
gDcmFileInfo.SourceStcAddress := Integer(msStc.Memory);
|
||
|
|
gDcmFileInfo.SourceStcSize := msStc.Size;
|
||
|
|
end
|
||
|
|
else
|
||
|
|
begin
|
||
|
|
gDcmFileInfo.SourceStcAddress := 0;
|
||
|
|
gDcmFileInfo.SourceStcSize := 0;
|
||
|
|
end;
|
||
|
|
except
|
||
|
|
on e:exception do
|
||
|
|
begin
|
||
|
|
gDcmFileInfo.SourceStcAddress := 0;
|
||
|
|
gDcmFileInfo.SourceStcSize := 0;
|
||
|
|
WriteLogText(0, 'E', 'Load StcFile error : ' + e.Message);
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
end
|
||
|
|
else
|
||
|
|
WriteLogText(10, 'W', 'StcFile(' + gSourceStcFile + ') not exists');
|
||
|
|
end;
|
||
|
|
|
||
|
|
WriteLogText(44, 'I', 'ImageFile = [' + gSourceImgFile + ']');
|
||
|
|
if Length(gSourceImgFile) > 0 then
|
||
|
|
begin
|
||
|
|
if FileExists(gSourceImgFile) then
|
||
|
|
begin
|
||
|
|
jpgA := TJPEGImage.Create;
|
||
|
|
try
|
||
|
|
jpgA.LoadFromFile(gSourceImgFile);
|
||
|
|
jpgA.SaveToStream(msJPG);
|
||
|
|
iImgWidth := jpgA.Width;
|
||
|
|
iImgHeight := jpgA.Height;
|
||
|
|
if msJPG.Size > 0 then
|
||
|
|
begin
|
||
|
|
gDcmFileInfo.ImageBuffAddress := Integer(msJPG.Memory);
|
||
|
|
gDcmFileInfo.ImageBuffSize := msJPG.Size;
|
||
|
|
gDcmFileInfo.ImageCompressed := True;
|
||
|
|
gDcmFileInfo.ImageTypeCompress:= 'JPEG';
|
||
|
|
gDcmFileInfo.ImagePhotometricInterpretation := 'YBR_FULL';
|
||
|
|
gDcmFileInfo.ImgSamplePixel := 3;
|
||
|
|
gDcmFileInfo.ImgBitAllocated := 8;
|
||
|
|
gDcmFileInfo.ImgBitHigh := 7;
|
||
|
|
gDcmFileInfo.ImgWidth := iImgWidth;
|
||
|
|
gDcmFileInfo.ImgHeight := iImgHeight;
|
||
|
|
gDcmFileInfo.ImageWinCenter := 128;
|
||
|
|
gDcmFileInfo.ImageWinWidth := 256;
|
||
|
|
|
||
|
|
gDcmFileInfo.ImagePixelSpacing:= '1.000000\1.000000 ';
|
||
|
|
|
||
|
|
end;
|
||
|
|
except
|
||
|
|
on e:exception do
|
||
|
|
begin
|
||
|
|
WriteLogText(0, 'E', 'Load ImageFile error : ' + e.Message);
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
jpgA.Free;
|
||
|
|
end
|
||
|
|
else
|
||
|
|
WriteLogText(10, 'W', 'ImageFile(' + gSourceImgFile + ') not exists');
|
||
|
|
end;
|
||
|
|
|
||
|
|
if (gDcmFileInfo.SourceDataSize > 0) or
|
||
|
|
(gDcmFileInfo.SourceStcSize > 0) or
|
||
|
|
(gDcmFileInfo.ImageBuffSize > 0) then
|
||
|
|
begin
|
||
|
|
if Length(gDcmFileInfo.Modality) < 1 then
|
||
|
|
gDcmFileInfo.Modality := 'DOC';
|
||
|
|
|
||
|
|
//gDcmFileInfo.StudyDescription := 'OCT Scan';
|
||
|
|
//gDcmFileInfo.SeriesDescription:= 'Scan Sequence 1';
|
||
|
|
//gDcmFileInfo.StudyID := '1001';
|
||
|
|
//gDcmFileInfo.SeriesNumber := '2001';
|
||
|
|
|
||
|
|
if Length(gDcmFileInfo.StudyDate) < 1 then
|
||
|
|
gDcmFileInfo.StudyDate := FormatDateTime('yyyyMMdd', Now);
|
||
|
|
if Length(gDcmFileInfo.SeriesDate) < 1 then
|
||
|
|
gDcmFileInfo.SeriesDate := gDcmFileInfo.StudyDate;
|
||
|
|
if Length(gDcmFileInfo.StudyTime) < 1 then
|
||
|
|
gDcmFileInfo.StudyTime := FormatDateTime('hhnnss', Now);
|
||
|
|
if Length(gDcmFileInfo.SeriesTime) < 1 then
|
||
|
|
gDcmFileInfo.SeriesTime := gDcmFileInfo.StudyTime;
|
||
|
|
|
||
|
|
|
||
|
|
//if Length(gDcmFileInfo.PatientName) < 1 then
|
||
|
|
//gDcmFileInfo.PatientName := '����';
|
||
|
|
//if Length(gDcmFileInfo.PatientID) < 1 then
|
||
|
|
//gDcmFileInfo.PatientID := GetRndStr(10);
|
||
|
|
//if Length(gDcmFileInfo.PatientDOB) < 1 then
|
||
|
|
//gDcmFileInfo.PatientDOB := GetRndDateStr(100);
|
||
|
|
//if Length(gDcmFileInfo.PatientSex) < 1 then
|
||
|
|
//gDcmFileInfo.PatientSex := 'M';
|
||
|
|
|
||
|
|
if gDcmFileInfo.ImageNumber < 0 then
|
||
|
|
gDcmFileInfo.ImageNumber := 1;
|
||
|
|
gDcmFileInfo.AcquisitionNumber := IntToStr(gDcmFileInfo.ImageNumber);
|
||
|
|
|
||
|
|
//Add Pdf Document
|
||
|
|
if gDcmFileInfo.SourceDataSize > 0 then
|
||
|
|
begin
|
||
|
|
WriteLogText(44, 'I', 'Processing [Pdf Report Data] data size ' + IntToStr(msPdfReport.Size) + ' bytes');
|
||
|
|
end;
|
||
|
|
|
||
|
|
//Add Stc Data
|
||
|
|
if gDcmFileInfo.SourceStcSize > 0 then
|
||
|
|
begin
|
||
|
|
WriteLogText(44, 'I', 'Processing [Stc Data] data size ' + IntToStr(msStc.Size) + ' bytes');
|
||
|
|
end;
|
||
|
|
|
||
|
|
//Add DICOM Image
|
||
|
|
if gDcmFileInfo.ImageBuffSize > 0 then
|
||
|
|
begin
|
||
|
|
WriteLogText(44, 'I', 'Processing [Image Data] image size [' + IntToStr(iImgWidth) + ' x ' + IntToStr(iImgHeight) + '], data size ' + IntToStr(msJPG.Size) + ' bytes');
|
||
|
|
|
||
|
|
if Length(gDcmFileInfo.ImageDate) < 1 then
|
||
|
|
gDcmFileInfo.ImageDate := gDcmFileInfo.StudyDate;
|
||
|
|
if Length(gDcmFileInfo.ImageTime) < 1 then
|
||
|
|
gDcmFileInfo.ImageTime := gDcmFileInfo.StudyTime;
|
||
|
|
end;
|
||
|
|
|
||
|
|
if Length(gTargetDcmFile) < 1 then
|
||
|
|
begin
|
||
|
|
gTargetDcmFile := 'DCMOUT_' + FormatDateTime('yyyyMMdd_hhnnss_zzz', Now) + '.dcm';
|
||
|
|
WriteLogText(44, 'I', 'Start convert target file [' + gTargetDcmFile + ']');
|
||
|
|
if gDebugConvert then
|
||
|
|
Result := SaveDcmFile(gAppPath + gTargetDcmFile, gDcmFileInfo);
|
||
|
|
end
|
||
|
|
else
|
||
|
|
begin
|
||
|
|
WriteLogText(44, 'I', 'Start convert target file [' + StringReplace(gTargetDcmFile, '%ImageInstanceUID%', '%SOPInstanceUID%', [rfReplaceAll, rfIgnoreCase]) + ']');
|
||
|
|
if Pos('%IMAGEINSTANCEUID%', UpperCase(gTargetDcmFile)) < 1 then
|
||
|
|
begin
|
||
|
|
if FileExists(gTargetDcmFile) then
|
||
|
|
DeleteFile(gTargetDcmFile);
|
||
|
|
end;
|
||
|
|
Result := SaveDcmFile(gTargetDcmFile, gDcmFileInfo);
|
||
|
|
end;
|
||
|
|
end
|
||
|
|
else
|
||
|
|
begin
|
||
|
|
WriteLogText(10, 'W', 'No data to convert');
|
||
|
|
end;
|
||
|
|
|
||
|
|
msJPG.Free;
|
||
|
|
msStc.Free;
|
||
|
|
msPdfReport.Free;
|
||
|
|
WriteLogText(44, 'I', 'ProcessReportDSP done');
|
||
|
|
end;
|
||
|
|
|
||
|
|
procedure ReadConfigFile(aIniFile: string);
|
||
|
|
var
|
||
|
|
iCfg : TIniFile;
|
||
|
|
begin
|
||
|
|
iCfg := TIniFile.Create(aIniFile);
|
||
|
|
try
|
||
|
|
gLogLevel := iCfg.ReadInteger('DfcRptz', 'LogLevel', 0);
|
||
|
|
gDcmCharacterSet := iCfg.ReadString('DfcRptz', 'DcmCharacterSet', gDcmCharacterSet);
|
||
|
|
gDcmUIDPreFix := iCfg.ReadString('DfcRptz', 'DcmUIDPreFix', gDcmUIDPreFix);
|
||
|
|
gDcmWriteNullPIID := Str2BoolDef(iCfg.ReadString('DfcRptz', 'DcmWriteNullPIID', ''), gDcmWriteNullPIID);
|
||
|
|
gDcmWriteSeriesDescription := Str2BoolDef(iCfg.ReadString('DfcRptz', 'DcmWriteSeriesDescription', ''), gDcmWriteSeriesDescription);
|
||
|
|
gDcmMemDump := Str2BoolDef(iCfg.ReadString('DfcRptz', 'MemDump', '0'), gDcmMemDump);
|
||
|
|
except
|
||
|
|
end;
|
||
|
|
iCfg.Free;
|
||
|
|
if gLogLevel < 0 then gLogLevel := 0;
|
||
|
|
if gLogLevel > 100 then gLogLevel := 100;
|
||
|
|
end;
|
||
|
|
|
||
|
|
begin
|
||
|
|
ExitCode := 9999;
|
||
|
|
SetErrorMode(SEM_FAILCRITICALERRORS or SEM_NOGPFAULTERRORBOX or SEM_NOOPENFILEERRORBOX);
|
||
|
|
try
|
||
|
|
CoInitialize(nil);
|
||
|
|
gPSInStr := '';
|
||
|
|
gPPInStr := '';
|
||
|
|
gLogLevel := 10;
|
||
|
|
gAppFile := ParamStr(0);
|
||
|
|
gAppPath := ExtractFilePath(gAppFile);
|
||
|
|
gAppFile := ExtractFileName(gAppFile);
|
||
|
|
gLogFile := ChangeFileExt(gAppFile, '.log');
|
||
|
|
gCfgFile := gAppPath + ChangeFileExt(gAppFile, '.ini');
|
||
|
|
gDcmCharacterSet:= '';
|
||
|
|
gSourcePdfFile := '';
|
||
|
|
gSourceImgFile := '';
|
||
|
|
gSourceStcFile := '';
|
||
|
|
gTargetDcmFile := '';
|
||
|
|
gDcmUIDPreFix := DICOM_UIDPRE_HEAD;
|
||
|
|
gDcmWriteSeriesDescription := True;
|
||
|
|
gDcmWriteNullPIID := True;
|
||
|
|
gTaskInitP1 := True;
|
||
|
|
gTaskInitP2 := False;
|
||
|
|
gDcmMemDump := False;
|
||
|
|
gDebugOutput := False;
|
||
|
|
gDebugConvert := False;
|
||
|
|
|
||
|
|
gLogWriteMutex := CreateMutex(nil, False, 'hmDfcRptzLogwMutex');
|
||
|
|
ReleaseMutex(gLogWriteMutex);
|
||
|
|
ExitCode := 9000;
|
||
|
|
|
||
|
|
Randomize;
|
||
|
|
if FileExists(gCfgFile) then
|
||
|
|
ReadConfigFile(gCfgFile);
|
||
|
|
WriteLogText(44, 'I', '.');
|
||
|
|
WriteLogText(44, 'I', 'Application started');
|
||
|
|
|
||
|
|
WriteLogText(44, 'I', 'Application ParamCount=' + IntToStr(ParamCount));
|
||
|
|
if ParamCount > 1 then
|
||
|
|
begin
|
||
|
|
ExitCode := 8000;
|
||
|
|
|
||
|
|
//����1��ѡ����Ϣ����
|
||
|
|
//����2���ļ���Ϣ����<XML><ODSP><EXESIN Type="0" ReportFile="D:\Data\ReportFile.pdf" RSTCFile="D:\Data\RSTCFile.dat" ImageFile="D:\Data\ImageFile.jpg" OutputFile="D:\Data\OutFile.dcm"/></ODSP></XML>
|
||
|
|
gPPInStr := ParamStr(1);
|
||
|
|
gPSInStr := ParamStr(2);
|
||
|
|
|
||
|
|
if ParamCount > 2 then
|
||
|
|
begin
|
||
|
|
for nI := 3 to ParamCount do
|
||
|
|
begin
|
||
|
|
if (UpperCase(ParamStr(nI))='/DEBUGCONVERT') or
|
||
|
|
(UpperCase(ParamStr(nI))='-DEBUGCONVERT') then
|
||
|
|
begin
|
||
|
|
gDebugConvert := True;
|
||
|
|
WriteLogText(44, 'I', 'Application DebugConvert=True');
|
||
|
|
end
|
||
|
|
else if (UpperCase(ParamStr(nI))='/DEBUGOUTPUT') or
|
||
|
|
(UpperCase(ParamStr(nI))='-DEBUGOUTPUT') then
|
||
|
|
begin
|
||
|
|
gDebugOutput := True;
|
||
|
|
WriteLogText(44, 'I', 'Application DebugOutput=True');
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
|
||
|
|
ClearDcmFileInfo(gDcmFileInfo);
|
||
|
|
if Length(gPPInStr) < 30 then
|
||
|
|
begin
|
||
|
|
InitXMLP1Info('');
|
||
|
|
end
|
||
|
|
else
|
||
|
|
begin
|
||
|
|
if gDebugOutput then
|
||
|
|
begin
|
||
|
|
WriteLogText(44, 'D', DecStr(gPPInStr, ''));
|
||
|
|
WriteLn(DecStr(gPPInStr, ''));
|
||
|
|
end;
|
||
|
|
InitXMLP1Info(DecStr(gPPInStr, ''));
|
||
|
|
ExitCode := 7000;
|
||
|
|
end;
|
||
|
|
|
||
|
|
if Length(gPSInStr) < 30 then
|
||
|
|
begin
|
||
|
|
if gDebugConvert then
|
||
|
|
begin
|
||
|
|
//gPSInStr := '<XML><ODSP><EXESIN Type="0" ReportFile="D:\Document\OISReports\20190826180826.pdf" RSTCFile="D:\Document\OISReports\RSTCFile.dat" ';
|
||
|
|
//gPSInStr := '<XML><ODSP><EXESIN Type="0" ReportFile="D:\ColFiles\PDFFiles\OIS\WMU\Cirrus HD-OCT_02.pdf" RSTCFile="D:\ColFiles\PDFFiles\OIS\WMU\LS900_01.pdf" ';
|
||
|
|
//gPSInStr := gPSInStr + 'ImageFile="D:\Document\Pictures\20190826180826.jpg" OutputFile="OutDcmFile.dcm"/></ODSP></XML>';
|
||
|
|
|
||
|
|
//gPSInStr := '<XML><ODSP><EXESIN Type="0" ReportFile="F:\DEVZEISS\Stage1\AB��\Quantel Medical AVISO\20210407_083929_015.pdf" ';
|
||
|
|
//gPSInStr := gPSInStr + 'ImageFile="F:\DEVZEISS\Stage1\AB��\Quantel Medical AVISO\20210407_083931_405.Jpg" OutputFile="OutDcmFile.dcm"/></ODSP></XML>';
|
||
|
|
|
||
|
|
gPSInStr := '<XML><ODSP><EXESIN Type="0" ReportFile="F:\HMOISFiles\OISFiles\Cannon_CR2\CANONCR2TJ91\20170316_092548.pdf" OutputFile="OutDcmFile.dcm"/></ODSP></XML>';
|
||
|
|
|
||
|
|
WriteLn(gPSInStr);
|
||
|
|
gPSInStr := EncStr(gPSInStr, '');
|
||
|
|
InitXMLP2Info(DecStr(gPSInStr, ''));
|
||
|
|
end;
|
||
|
|
end
|
||
|
|
else
|
||
|
|
begin
|
||
|
|
if gDebugOutput then
|
||
|
|
begin
|
||
|
|
WriteLogText(44, 'D', DecStr(gPSInStr, ''));
|
||
|
|
WriteLn(DecStr(gPSInStr, ''));
|
||
|
|
end;
|
||
|
|
InitXMLP2Info(DecStr(gPSInStr, ''));
|
||
|
|
ExitCode := 6000;
|
||
|
|
end;
|
||
|
|
|
||
|
|
ExitCode := 2000;
|
||
|
|
if ProcessReportDSP then
|
||
|
|
ExitCode := 1000
|
||
|
|
else
|
||
|
|
ExitCode := 1999;
|
||
|
|
|
||
|
|
CoUnInitialize;
|
||
|
|
WriteLogText(44, 'I', '..');
|
||
|
|
except
|
||
|
|
ExitCode := 9998;
|
||
|
|
end;
|
||
|
|
//Readln;
|
||
|
|
end.
|