Box DICOM Viewer
Before using the Box DICOM Viewer, you will need to import your DICOM studies into Box. There are two ways to import DICOM studies into Box:
The Box DICOM Import Tool: A web-based widget that enables you to upload DICOM studies to Box from your desktop or from a CD to Box.
The Box DICOM Proxy: An on-premise piece of software that uploads DICOM images to Box directly from your Patient Archiving and Communications System (PACS) or from your on-premise server.
You must use the Box DICOM Import Tool to generate a ".boxdicom" file.
Note: If you use the normal Box file uploader to add your DICOM files, they may not load in the Box DICOM Viewer correctly. For that you have to create ".boxdicom" file manually.
Box dicom viewer uses the ".boxdicom" file for displaying the images and files. this file contains all the necessary information related to Study.
If you want to create the ".boxdicom" file manually then you have to store enough information in your DB that is used in viewer file. Like patient information,study information,series information and file information.
Following are the steps for creating ".boxdicom" file manually.
There is a fix structure of ".boxdicom" file.it contains all the information related to study like patient information,study, series and file information and its stored fileId’s in box.
1. Create the class that contains the structure of .boxdicom file
namespace CreateBoxdicomViewerFile
{
public class Meta
{
public string folderId { get; set; }
}
public class DicomMetadata
{
public string StudyInstanceUID { get; set; }
public string StudyDate { get; set; }
public string StudyDescription { get; set; }
public string InstitutionName { get; set; }
public string ReferringPhysicianName { get; set; }
public string PatientName { get; set; }
public string PatientID { get; set; }
public string PatientBirthDate { get; set; }
public string Modality { get; set; }
public string BodyPartExamined { get; set; }
public string PatientAge { get; set; }
public string PatientSex { get; set; }
public string History { get; set; }
}
public class SeriesMeta
{
public string folderId { get; set; }
}
public class SeriesDicomMetadata
{
public string SeriesInstanceUID { get; set; }
public string SeriesNumber { get; set; }
public string SeriesDescription { get; set; }
}
public class ImageMeta
{
public string dicomUrl { get; set; }
public string fileId { get; set; }
public string fileVersionId { get; set; }
}
public class ImageDicomMetadata
{
public string SOPInstanceUID { get; set; }
public string InstanceNumber { get; set; }
public int NumberOfFrames { get; set; }
public string AcquisitionDate { get; set; }
public string AcquisitionTime { get; set; }
public int Columns { get; set; }
public int Rows { get; set; }
public string ImageOrientationPatient { get; set; }
public string ImagePositionPatient { get; set; }
public string ContentDate { get; set; }
public string ContentTime { get; set; }
public string PixelSpacing { get; set; }
}
public class ImageList
{
public ImageMeta meta { get; set; }
public ImageDicomMetadata dicomMetadata { get; set; }
}
public class series
{
public SeriesMeta meta { get; set; }
public SeriesDicomMetadata dicomMetadata { get; set; }
public List<ImageList> objects { get; set; }
}
public class study
{
public Meta meta { get; set; }
public DicomMetadata dicomMetadata { get; set; }
public List<series> series { get; set; }
}
public class RootObject
{
public study study { get; set; }
}
}
2. After that add the class that contains the enough information for creating viewer file
namespace CreateBoxdicomViewerFile
{
public class Metadata
{
public string BodyPartExamined { get; set; }
public string InstitutionName { get; set; }
public string Modality { get; set; }
public string PatientBirthDate { get; set; }
public string PatientID { get; set; }
public string PatientName { get; set; }
public string ReferringPhysicianName { get; set; }
public string StudyDate { get; set; }
public string StudyDescription { get; set; }
public string StudyInstanceUID { get; set; }
public string AdditionalPatientHistory { get; set; }
public string PatientAge { get; set; }
public string PatientSex { get; set; }
public string SeriesDescription { get; set; }
public string SeriesInstanceUID { get; set; }
public string SeriesNumber { get; set; }
public string SeriesFolderId { get; set; }
public string AcquisitionDate { get; set; }
public string AcquisitionTime { get; set; }
public string Columns { get; set; }
public string ContentDate { get; set; }
public string ContentTime { get; set; }
public string ImageOrientationPatient { get; set; }
public string ImagePositionPatient { get; set; }
public string InstanceNumber { get; set; }
public string NumberOfFrames { get; set; }
public string PixelSpacing { get; set; }
public string Rows { get; set; }
public string SOPInstanceUID { get; set; }
public string FileId { get; set; }
public string FileVersionId { get; set; }
}
}
3. After that get the information from DB and fill the information in the list of object. This contains the all the images information in one study.
List<Metadata> metadataList = new List<Metadata>();
4. After that add the function “CreateViewerFileStructure” and pass the list of metdata object to this function. It will create the json for viewer file.
private static string CreateViewerFileStructure(List<Metadata> metadataList)
{
try
{
metadataList = metadataList.OrderBy(x => x.SeriesInstanceUID).ToList();
ImageList clsobject = new ImageList();
List<series> series = new List<series>();
string seriesInstanceuid = "";
foreach (var metadata in metadataList)
{
if (seriesInstanceuid != metadata.SeriesInstanceUID)
{
var seriesImages = metadataList.Where(x => x.SeriesInstanceUID == metadata.SeriesInstanceUID).ToList();
List<ImageList> imglist = new List<ImageList>();
foreach (var imgMetadata in seriesImages)
{
imglist.Add(new ImageList()
{
dicomMetadata = new ImageDicomMetadata()
{
AcquisitionDate = imgMetadata.AcquisitionDate,
AcquisitionTime = imgMetadata.AcquisitionTime,
Columns = string.IsNullOrEmpty(imgMetadata.Columns) ? 0 : Convert.ToInt32(imgMetadata.Columns),
ContentDate = imgMetadata.ContentDate,
ContentTime = imgMetadata.ContentTime,
ImageOrientationPatient = imgMetadata.ImageOrientationPatient,
ImagePositionPatient = imgMetadata.ImagePositionPatient,
InstanceNumber = imgMetadata.InstanceNumber,
NumberOfFrames = string.IsNullOrEmpty(imgMetadata.NumberOfFrames) ? 0 : Convert.ToInt32(imgMetadata.NumberOfFrames),
PixelSpacing = imgMetadata.PixelSpacing,
Rows = string.IsNullOrEmpty(imgMetadata.Rows) ? 0 : Convert.ToInt32(imgMetadata.Rows),
SOPInstanceUID = imgMetadata.SOPInstanceUID
},
meta = new ImageMeta() { dicomUrl = "", fileId = imgMetadata.FileId, fileVersionId = imgMetadata.FileVersionId }
});
}
series.Add(new series()
{
dicomMetadata = new SeriesDicomMetadata()
{
SeriesDescription = metadata.SeriesDescription,
SeriesInstanceUID = metadata.SeriesInstanceUID,
SeriesNumber = metadata.SeriesNumber
},
meta = new SeriesMeta()
{
folderId = metadata.SeriesFolderId
},
objects = imglist
});
}
seriesInstanceuid = metadata.SeriesInstanceUID;
}
RootObject rootObject = new RootObject()
{
study = new study()
{
meta = new Meta() { folderId = "" },
dicomMetadata = new DicomMetadata()
{
BodyPartExamined = "",
InstitutionName = metadataList[0].InstitutionName,
Modality = metadataList[0].Modality,
PatientBirthDate = metadataList[0].PatientBirthDate,
PatientID = metadataList[0].PatientID,
PatientName = metadataList[0].PatientName,
ReferringPhysicianName = metadataList[0].ReferringPhysicianName,
StudyDate = metadataList[0].StudyDate,
StudyDescription = metadataList[0].StudyDescription,
StudyInstanceUID = metadataList[0].StudyInstanceUID,
History = metadataList[0].AdditionalPatientHistory,
PatientAge = metadataList[0].PatientAge,
PatientSex = metadataList[0].PatientSex
},
series = series,
}
};
var fileJson = JsonConvert.SerializeObject(rootObject);
return fileJson;
}
catch(Exception ex)
{
throw ex;
}
}
5. After that you have to upload this json string on Box Dicom. In this function you have to pass the json string and FolderId in which you want to upload .boxdicom file
private static async Task UploadViewerFile(string viewerString,string FolderId)
{
try
{
string appPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
appPath = Path.Combine(appPath, "BoxConfigFile");
appPath = appPath + "\\boxConfig.json";
string jsonConfig = File.ReadAllText(appPath);
BoxJwt boxJwt = new BoxJwt(jsonConfig);
boxClient = boxJwt.GetBoxUserClient();
BoxFile newFile;
using (var toUpload = GenerateStreamFromString(viewerString))
{
BoxFileRequest req = new BoxFileRequest()
{
Name = "ViewerFile.boxdicom",
Parent = new BoxRequestEntity() { Id = FolderId }
};
newFile = await boxClient.FilesManager.UploadAsync(req, toUpload);
}
}
catch(Exception ex)
{
throw ex;
}
}
public static Stream GenerateStreamFromString(string s)
{
var stream = new MemoryStream();
var writer = new StreamWriter(stream);
writer.Write(s);
writer.Flush();
stream.Position = 0;
return stream;
}
6. After that you have to use Box Dicom Viewer.
The Box DICOM Viewer can be embedded in your custom applications. It can be embedded in an IFrame or directly with the JavaScript SDK.
<script>
box.dicom.createViewer(document.body, {
'accessToken': 'MY_ACCESS_TOKEN',
'studies': [{
'fileId': 'MY_FILE_ID'
}]
});
</script>
You have to provide the access token in place of 'MY_ACCESS_TOKEN' and provide the .boxdicom file id in place of 'MY_FILE_ID' that you have uploaded above.
No comments:
Post a Comment