Example #1
0
        public ActionResult Upload(UploadModel model, HttpPostedFileBase file)
        {
            model.OriginalIDs = GetValidOriginalIDs();
            model.EndographBrands = GetEndographBrands();

            if (ModelState.IsValid)
            {
                if (file != null)
                {

                    String extension = Path.GetExtension(file.FileName);
                    if (extension.Equals(".zip"))
                    {
                        Unzip(model, file.InputStream);
                    }
                    else if (extension.Equals(".xlsx"))
                    {

                    }
                    else
                    {
                        Response.Write("<script>alert('File type not supported. Use zip or xlsx.');</script>");
                    }
                }
                else
                {
                    Response.Write("<script>alert('No file selected.');</script>");
                }
            }
            return View(model);
        }
Example #2
0
        private void Unzip(UploadModel um, Stream zipStream)
        {
            String tmpFileName = Path.GetTempPath() + "\\" + Path.GetRandomFileName();
            while (System.IO.File.Exists(tmpFileName))
            {
                tmpFileName = Path.GetTempPath() + "\\" + Path.GetRandomFileName();
            }
            ZipInputStream zipInputStream = new ZipInputStream(zipStream);
            ZipEntry entry = zipInputStream.GetNextEntry();
            while (entry != null)
            {
                
                String entryName = entry.Name;
                if (!entryName.EndsWith("DICOMDIR"))
                {
                    entry = zipInputStream.GetNextEntry();
                    continue;
                }
                //Alert(entryName);
                
                if (entry.IsFile)
                {
                    if (System.IO.File.Exists(tmpFileName))
                    {
                        System.IO.File.Delete(tmpFileName);
                    }
                    long bufSize = (entry.Size + 4096) - (entry.Size % 4096);
                    byte[] buffer = new byte[bufSize];
                    using (FileStream streamOut = System.IO.File.Create(tmpFileName))
                    {
                        StreamUtils.Copy(zipInputStream, streamOut, buffer);
                    }
                    if (System.IO.Path.GetFileName(entryName).Equals("DICOMDIR"))
                    {
                        try
                        {
                            ReadDICOMDIR(um, System.IO.Path.GetPathRoot(entryName), tmpFileName);
                        }
                        catch (Exception e)
                        {

                        }
                    }

                }
               
                entry = zipInputStream.GetNextEntry();
            }
            System.IO.File.Delete(tmpFileName);

        }
Example #3
0
 public ActionResult Upload()
 {
     var model = new UploadModel();
     model.OriginalIDs = GetValidOriginalIDs();
     model.EndographBrands = GetEndographBrands();
     return View(model);
 }
Example #4
0
        private void ReadDICOMDIR(UploadModel um, string path, string filename)
        {
            var dBytes = System.IO.File.ReadAllBytes(filename);
            var dcm = DICOMObject.Read(dBytes);

            var pt_originalID = dcm.FindFirst(TagHelper.PATIENT_ID).DData.ToString();
            if (!pt_originalID.Equals(um.originalID.ToString()))
            {
             //   Alert("Patient ID in DICOM file (" + pt_originalID + ") does not match the selected patient ID (" + um.originalID.ToString() + ")");
            }

            var allStudies = dcm.FindAll(TagHelper.STUDY_ID);
            var allElements = dcm.AllElements;
            Study currentStudy = null;
            Series currentSeries = null;
            for (int i = 0; i < allElements.Count; i++)
            {
                var currElement = allElements[i];
                if (currElement.Tag.Equals(TagHelper.DIRECTORY_RECORD_TYPE))
                {
                    if (currElement.DData.ToString().Equals("STUDY"))
                    {
                        Study nextStudy = GetStudyInfo(allElements, i+1);
                        nextStudy.patientID = GetPatientIDFromOriginalID(um.originalID);
                        currentStudy = InsertStudy(nextStudy);
                    }
                    else if (currElement.DData.ToString().Equals("SERIES"))
                    {
                        Series nextSeries = GetSeriesInfo(allElements, i+1);
                        nextSeries.studyID = currentStudy.studyID;
                        currentSeries = InsertSeries(nextSeries);
                    }
                    else if (currElement.DData.ToString().Equals("IMAGE"))
                    {
                        Image nextImage = GetImageInfo(allElements, i+1);
                        nextImage.seriesID = currentSeries.seriesID;
                        nextImage.imageFilename = String.Join("/", new string[] 
                            {"{IMAGE_DIR}", currentStudy.patientID.ToString(), currentStudy.studyID.ToString(), currentSeries.seriesID.ToString(), nextImage.imageOrder.ToString()});
                        InsertImage(nextImage);
                    }
                }

            }
            //Alert(dcm.ToString());
        }