Exemple #1
0
        private ArrayList ImportRefFilesFromDicomdir(string dicomDir, HLI.DataSet dataset)
        {
            int recordsCount = 0;
            ArrayList refFileNames = new ArrayList();
            FileInfo dicomDirInfo = new FileInfo(dicomDir);
            HLI.Attribute recordSeqAttr = dataset["0x00041220"];
            if (recordSeqAttr.Exists)
            {
                recordsCount = recordSeqAttr.ItemCount;

                for (int i = 0; i < recordsCount; i++)
                {
                    HLI.SequenceItem record = recordSeqAttr.GetItem(i + 1);
                    Values values = record["0x00041430"].Values;
                    System.String recType = values[0];
                    if ((recType == "IMAGE") || (recType == "PRESENTATION"))
                    {
                        Values refFileIds = record["0x00041500"].Values;

                        string refFile = "";
                        for (int j = 0; j < refFileIds.Count; j++)
                        {
                            refFile += refFileIds[j];
                            refFile += @"\";
                        }

                        refFile = refFile.Remove((refFile.Length - 1), 1);
                        refFileNames.Add(Path.Combine(dicomDirInfo.DirectoryName, refFile));
                    }
                }
            }

            return refFileNames;
        }
Exemple #2
0
        /// <summary>
        /// Update the attributes in the composite with the new values
        /// </summary>
        /// <param name="composite">
        /// composite for Anonymization
        /// </param>
        public void UpdateAnonymizedAttributes( HLI.Attribute composite)
        {
            //Iterate through all attributes specified for anonymization by DICOM
            //and anonymize them.
            try
            {
                string[] tempAnonymizedAttributes = null;
                if(anonymizationType)
                {
                    tempAnonymizedAttributes = anonymizedAttributes ;
                }
                else
                {
                    tempAnonymizedAttributes = anonymizedAttributesComplete;
                }
                string attributeValue = TagString(composite.GroupNumber , composite.ElementNumber);
                for (int i = 0; i < tempAnonymizedAttributes.Length; i++)
                {
                    if (attributeValue == tempAnonymizedAttributes[i])
                    {

                        HLI.Attribute attrValue = composite ;

                        string anonymised = null;
                        if (attrValue != null)
                        {
                            DvtkData.Dimse.VR dicomVR = attrValue.VR;
                            switch (dicomVR)
                            {
                                case VR.PN:
                                    if (tempAnonymizedAttributes[i] == TagString(sequenceTag.PATIENTS_NAME))
                                    {
                                        // Tag not found in in-params
                                        // assigning patient id
                                        if (anonymised == null)
                                        {
                                            //todo Later
                                            anonymised = Guid.NewGuid().ToString().Replace("-","p").Substring(1,15);
                                        }
                                        composite.Values.Clear();
                                        composite.Values.Add(anonymised);

                                    }
                                    else
                                    {
                                        HLI.Values tempValue = attrValue.Values;
                                        if(tempValue.Count>0)
                                        {
                                            for( int j = 0 ; j<tempValue.Count ;j++)
                                            {
                                                tempValue[j] = anonymised;
                                            }
                                        }
                                        composite.Values.Clear();
                                        composite.Values.Add(tempValue);
                                    }

                                    break;
                                case VR.UI:

                                    composite.Values.Clear();
                                    composite.Values.Add(anonymised);

                                    break;
                                case VR.SH:
                                    if (
                                        tempAnonymizedAttributes[i] ==
                                        TagString(sequenceTag.ACCESSION_NUMBER) &&
                                        anonymised == null
                                        )
                                    {
                                        anonymised = Guid.NewGuid().ToString().Replace("-","a").Substring(1,9);
                                    }
                                    composite.Values.Clear();
                                    composite.Values.Add(anonymised);
                                    break;
                                case VR.AS:
                                    composite.Values.Clear();
                                    composite.Values.Add(anonymised);
                                    break;
                                case VR.LO:
                                    composite.Values.Clear();
                                    composite.Values.Add(anonymised);
                                    break;
                                case VR.DA:
                                    if (tempAnonymizedAttributes[i] == TagString(sequenceTag.PATIENTS_BIRTH_DATE))
                                    {
                                        // Tag not found in in-params
                                        // assigning patient id
                                        if (anonymised == null)
                                        {
                                            //todo Later
                                            anonymised = System.DateTime.Today.Year.ToString() + System.DateTime.Today.Month.ToString("00") + System.DateTime.Today.Day.ToString("00");
                                        }
                                        composite.Values.Clear();
                                        composite.Values.Add(anonymised);
                                    }
                                    else
                                    {
                                        composite.Values.Clear();
                                        composite.Values.Add(anonymised);
                                    }
                                    break;
                                case VR.TM:
                                    if (tempAnonymizedAttributes[i] == TagString(sequenceTag.PATIENTS_BIRTH_TIME))
                                    {
                                        // Tag not found in in-params
                                        // assigning patient id
                                        if (anonymised == null)
                                        {
                                            //todo Later
                                            anonymised = System.DateTime.Now.TimeOfDay.Hours.ToString("00") + System.DateTime.Now.TimeOfDay.Minutes.ToString("00") + System.DateTime.Now.TimeOfDay.Seconds.ToString("00");
                                        }
                                        composite.Values.Clear();
                                        composite.Values.Add(anonymised);
                                    }
                                    else
                                    {
                                        composite.Values.Clear();
                                        composite.Values.Add(anonymised);
                                    }
                                    break;
                                case VR.LT:
                                    composite.Values.Clear();
                                    composite.Values.Add(anonymised);
                                    break;
                                case VR.ST:
                                    composite.Values.Clear();
                                    composite.Values.Add(anonymised);
                                    break;
                                case VR.CS:
                                    if (tempAnonymizedAttributes[i] == TagString(sequenceTag.PATIENTS_SEX))
                                    {
                                        // Tag not found in in-params
                                        // assigning patient id
                                        if (anonymised == null)
                                        {
                                            //todo Later
                                            anonymised = "O" ;
                                        }
                                        composite.Values.Clear();
                                        composite.Values.Add(anonymised);
                                    }
                                    else
                                    {
                                        composite.Values.Clear();
                                        composite.Values.Add(anonymised);
                                    }
                                    break;
                                case VR.DS:
                                    composite.Values.Clear();
                                    composite.Values.Add(anonymised);
                                    break;
                            }
                        }
                    }
                }
            }
            catch ( Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemple #3
0
        public void PatientAttributes(HLI.DataSet dcmDataset)
        {
            try
            {
                    HLI.Values	initialPatientName = dcmDataset.GetValues(TagString(sequenceTag.PATIENTS_NAME));
                    HLI.Values	initialPatientId = dcmDataset.GetValues(TagString(sequenceTag.PATIENT_ID));
                    string patientHashKey = initialPatientName[0] + "*!#@" + initialPatientId[0];
                    string patientName = "";
                    string patientId = "";
                    if (allUIDInfo.Contains(patientHashKey))
                    {
                        string temp = allUIDInfo[patientHashKey].ToString();
                        string tempName = temp.Substring(0,temp.IndexOf("*!#@"));
                        string tempPatientId = temp.Substring(temp.IndexOf("*!#@")+4);
                        if ( dcmDataset.Exists(TagString(sequenceTag.PATIENTS_NAME)))
                        {
                            dcmDataset.Set(TagString(sequenceTag.PATIENTS_NAME), VR.PN,tempName);
                        }
                        if ( dcmDataset.Exists(TagString(sequenceTag.PATIENT_ID)))
                        {
                            dcmDataset.Set(TagString(sequenceTag.PATIENT_ID), VR.LO, tempPatientId);
                        }
                    }
                    else
                    {
                        if ( dcmDataset.Exists(TagString(sequenceTag.PATIENTS_NAME)))
                        {
                            patientName = Guid.NewGuid().ToString().Replace("-","p0").Substring(0,15);
                            dcmDataset.Set(TagString(sequenceTag.PATIENTS_NAME), VR.PN,patientName);
                        }
                        if ( dcmDataset.Exists(TagString(sequenceTag.PATIENT_ID)))
                        {
                            patientId = Guid.NewGuid().ToString().Replace("-","p1").Substring(0,15);
                            dcmDataset.Set(TagString(sequenceTag.PATIENT_ID), VR.LO, patientId);
                        }

                        allUIDInfo[patientHashKey] = patientName + "*!#@" + patientId;
                    }
            }
            catch(Exception ex)
            {
                string MessageText = ex.Message ;
                Console.WriteLine(MessageText);
            }
        }
Exemple #4
0
        public void SequenceAttribute_recursive(HLI.Attribute seqAttr)
        {
            int numberOfItems = seqAttr.ItemCount;
            for( int i=0; i<numberOfItems;i++)
            {
                HLI.SequenceItem item = seqAttr.GetItem(i+1);
                int numberOfattributes = item.Count ;
                for (int j=0; j <numberOfattributes ; j++)
                {
                    HLI.Attribute attrInItem = item[j];
                    if(attrInItem.VR != VR.SQ)
                    {
                        CacheAndRepairIdentifyingAttribute(attrInItem);
                        UpdateAnonymizedAttributes(attrInItem);

                    }
                    else
                    {
                        SequenceAttribute_recursive(attrInItem);
                    }
                }
            }
        }
Exemple #5
0
        // <summary>
        /// Cache the patient information for reference updation in Presentation 
        /// State later.
        /// </summary>
        /// <param name="composite">
        /// The composite to be anonymized
        /// </param>
        /// <param name="isImage">
        /// if isImage is true then we are updating for image otherwise we are 
        /// updating for ps
        /// when the composite is PS object the SeriesInstaceUID will be repaired later.
        ///</param>
        public void CacheAndRepairIdentifyingAttribute(HLI.Attribute composite)
        {
            try
            {
                string attributeValue = TagString(composite.GroupNumber , composite.ElementNumber);
                string oldValue;
                string[] tempcompositeKeyTags = null;
                if(!anonymizationType)
                {
                    tempcompositeKeyTags = compositeKeyTagsComplete ;
                }
                else
                {
                    tempcompositeKeyTags = compositeKeyTags;
                }

                for (int i = 0; i < tempcompositeKeyTags.Length; i++)
                {
                    if (attributeValue == tempcompositeKeyTags[i])
                    {
                        HLI.Attribute attrValue = composite;
                        if (attrValue != null)
                        {
                            HLI.Values initialValues = composite.Values ;
                            oldValue = initialValues[0];
                            DvtkData.Dimse.VR dicomVR = attrValue.VR;
                            switch (dicomVR)
                            {
                                case VR.UI:
                                    string tempUIID ;
                                    if (nullPatientID)
                                    {
                                        tempUIID = HLI.UID.Create();
                                    }
                                    else
                                    {
                                        tempUIID = (string)allUIDInfo[oldValue];
                                        if (tempUIID == null)
                                        {
                                            tempUIID = UIDModifier(oldValue);
                                        }
                                    }
                                    // In case of Series always store the current ID in the map.
                                    // This will be used while updating the series reference.
                                    allUIDInfo[oldValue] = tempUIID;
                                    composite.Values.Clear();
                                    composite.Values.Add(tempUIID);
                                    break;

                                case VR.SH:
                                    string uniqueAccesionNumber ;
                                    if (nullPatientID)
                                    {
                                        uniqueAccesionNumber = Guid.NewGuid().ToString().Replace("-","a").Substring(1,9);
                                    }
                                    else
                                    {
                                        uniqueAccesionNumber = (string)allUIDInfo[oldValue];
                                        if (uniqueAccesionNumber == null)
                                        {
                                            uniqueAccesionNumber = Guid.NewGuid().ToString().Replace("-","a").Substring(1,9);
                                        }
                                    }
                                    // In case of Series always store the current ID in the map.
                                    // This will be used while updating the series reference.
                                    allUIDInfo[oldValue] = uniqueAccesionNumber;
                                    //dcmDataset.Set(compositeKeyTags[i],VR.SH,uniqueAccesionNumber);
                                    composite.Values.Clear();
                                    composite.Values.Add(uniqueAccesionNumber);
                                    break;
                            }
                        }
                    }
                }
            }
            catch ( Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }