public virtual FileMetaInfo NewFileMetaInfo(Dataset ds, System.String transferSyntaxUID) { try { return new FileMetaInfo().Init(ds.GetString(Tags.SOPClassUID, null), ds.GetString(Tags.SOPInstanceUID, null), transferSyntaxUID, Implementation.ClassUID, Implementation.VersionName); } catch (DcmValueException ex) { throw new System.ArgumentException(ex.Message); } }
private FutureRSP SendDataset(ActiveAssociation active, DcmParser parser, Dataset ds) { String sopInstUID = ds.GetString(Tags.SOPInstanceUID); if (sopInstUID == null) { log.Error( "SOP instance UID is null" ); return null; } String sopClassUID = ds.GetString(Tags.SOPClassUID); if (sopClassUID == null) { log.Error( "SOP class UID is null" ); return null; } PresContext pc = null; Association assoc = active.Association; if (parser != null) { if (parser.DcmDecodeParam.encapsulated) { String tsuid = ds.GetFileMetaInfo().TransferSyntaxUID; if ((pc = assoc.GetAcceptedPresContext(sopClassUID, tsuid)) == null) { log.Error( "SOP class UID not supported" ); return null; } } else if ((pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ImplicitVRLittleEndian)) == null && (pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ExplicitVRLittleEndian)) == null && (pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ExplicitVRBigEndian)) == null) { log.Error( "SOP class UID not supported" ); return null; } return active.Invoke(aFact.NewDimse(pc.pcid(), oFact.NewCommand().InitCStoreRQ(assoc.NextMsgID(), sopClassUID, sopInstUID, 0), new FileDataSource(parser, ds, new byte[2048]))); } else { if ((ds.GetFileMetaInfo() != null) && (ds.GetFileMetaInfo().TransferSyntaxUID != null)) { String tsuid = ds.GetFileMetaInfo().TransferSyntaxUID; if ((pc = assoc.GetAcceptedPresContext(sopClassUID, tsuid)) == null) { log.Error( "SOP class UID not supported" ); return null; } } else if ((pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ImplicitVRLittleEndian)) == null && (pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ExplicitVRLittleEndian)) == null && (pc = assoc.GetAcceptedPresContext(sopClassUID, UIDs.ExplicitVRBigEndian)) == null) { log.Error( "SOP class UID not supported" ); return null; } return active.Invoke(aFact.NewDimse(pc.pcid(), oFact.NewCommand().InitCStoreRQ(assoc.NextMsgID(), sopClassUID, sopInstUID, 0), ds)); } return null; }
/// <summary> /// Send C-STORE /// </summary> /// <param name="ds"></param> public bool CStore( Dataset ds ) { int pcid = PCID_START; PCID_START += 2; try { // // Prepare association // String classUID = ds.GetString( Tags.SOPClassUID); String tsUID = ds.GetString(Tags.TransferSyntaxUID); if( (tsUID == null || tsUID.Equals( "" )) && (ds.GetFileMetaInfo() != null) ) tsUID = ds.GetFileMetaInfo().GetString(Tags.TransferSyntaxUID); if( tsUID == null || tsUID.Equals( "" ) ) tsUID = UIDs.ImplicitVRLittleEndian; m_assocRQ.AddPresContext(aFact.NewPresContext(pcid, classUID, new String[]{ tsUID } )); ActiveAssociation active = OpenAssoc(); if (active != null) { bool bResponse = false; FutureRSP frsp = SendDataset(active, null, ds); if (frsp != null) { active.WaitOnRSP(); bResponse = true; } active.Release(true); return bResponse; } } finally { m_assocRQ.RemovePresContext(pcid); } return false; }
//glowna funkcja private void mainOperations(Dataset _ds) { //inicjalizacja double[,] maxDose = new double[1, 2]; //maksymalna dawka i numer wiazki dla tej dawki maxDose[0, 0] = 0; maxDose[0, 1] = 0; double tmpDose = 0; //tymczasowa zmienna przechowujaca ostatnia dawke string[] tmpLeafPostionBoundariesOrJaws; Dataset dsFractionGroupSequence; if (_ds != null) { dsFractionGroupSequence = _ds.GetItem(Tags.FractionGroupSeq, 0); } else { dsFractionGroupSequence = null; } if (dsFractionGroupSequence != null) { try { this.treatmentPlanName = _ds.GetString(Tags.RTPlanName); //pobranie nazwy planu string message = "Nazwa planu: " + this.treatmentPlanName + Environment.NewLine; #region wiązki this.numberOfBeams = Convert.ToInt16(dsFractionGroupSequence.GetString(Tags.NumberOfBeams, 0)); this.numberOfFractions = Convert.ToInt16(dsFractionGroupSequence.GetString(Tags.NumberOfFractionsPlanned, 0)); //inicjalizacja this.beamDoses = new double[this.numberOfBeams]; this.TPR = new double[this.numberOfBeams]; this.MU = new double[this.numberOfBeams]; this.SSD = new double[this.numberOfBeams]; this.SSDDepth = new double[this.numberOfBeams]; this.radDepth = new double[this.numberOfBeams]; this.beamMetersets = new double[this.numberOfBeams]; this.nominalBeamEnergy = new double[this.numberOfBeams]; DcmElement dcmeReferencedBeamSequence = dsFractionGroupSequence.Get(Tags.RefBeamSeq); message += "Liczba wiązek: " + numberOfBeams.ToString() + Environment.NewLine; message += "Frakcje: " + this.numberOfFractions + Environment.NewLine; Dataset dsReferencedBeams = null; for (int i = 0; i < numberOfBeams; i++) { dsReferencedBeams = dcmeReferencedBeamSequence.GetItem(i); tmpDose = Convert.ToDouble(dsReferencedBeams.GetString(Tags.BeamDose, 0).Replace('.', ',')) * 100; //zamiana dawki na cGy message += "Wiązka " + (i + 1) + " = " + Math.Round(tmpDose, 2).ToString() + " cGy" + Environment.NewLine; //wpisanie dawek do tablicy this.beamDoses[i] = tmpDose; //wpisanie MU do tablicy this.beamMetersets[i] = Convert.ToDouble(dsReferencedBeams.GetString(Tags.BeamMeterset, 0).Replace('.', ',')); message += "Zapisane MU = " + Math.Round(this.beamMetersets[i], 2).ToString() + Environment.NewLine; //wyświetlenie //maksymalna dawka if (tmpDose > maxDose[0, 0]) { maxDose[0, 0] = tmpDose; maxDose[0, 1] = i; //numer wiazki } } message += "Maksymalna dawka: " + Math.Round(maxDose[0, 0], 3).ToString() + ", wiązka nr " + maxDose[0, 1].ToString() + Environment.NewLine; #endregion #region listki, nominalna energia wiązek i SSD DcmElement dcmeBeamSequence = _ds.Get(Tags.BeamSeq); for (int i = 0; i < this.numberOfBeams; i++) { Dataset dsBeamParams = dcmeBeamSequence.GetItem(i); DcmElement dcmeBeamLimitingDeviceSequence = dsBeamParams.Get(Tags.BeamLimitingDeviceSeq); Dataset dsLeafs = dcmeBeamLimitingDeviceSequence.GetItem(1); message += Environment.NewLine + "Listki" + Environment.NewLine; //string[] test = dsLeafs.GetStrings(Tags.LeafPositionBoundaries); tmpLeafPostionBoundariesOrJaws = dsLeafs.GetString(Tags.LeafPositionBoundaries).Split('\\'); //wczytanie wsp x listkow message += "Parametry " + i + ": " + dsLeafs.GetString(Tags.LeafPositionBoundaries); //jesli nie istnieje tablica tworzymy ja lub (jesli istnieje) zmieniamy jej rozmiar, gdy jest za maly/duzy dla nowego pliku //GetUpperBound(poziom) - indeks ostatniego el na danym poziomie tablicy if (this.leafPositionBoundaries == null || (this.leafPositionBoundaries.GetUpperBound(0) + 1) != this.numberOfBeams || (this.leafPositionBoundaries.GetUpperBound(1) + 1) != tmpLeafPostionBoundariesOrJaws.Length) { this.leafPositionBoundaries = new double[this.numberOfBeams, tmpLeafPostionBoundariesOrJaws.Length]; } for (int j = 0; j < tmpLeafPostionBoundariesOrJaws.Length; j++) { this.leafPositionBoundaries[i, j] = Convert.ToDouble(tmpLeafPostionBoundariesOrJaws[j].Replace('.', ',')); } DcmElement dcmeControlPointSequence = dsBeamParams.Get(Tags.ControlPointSeq); Dataset dsControlPointSequence = dcmeControlPointSequence.GetItem(0); #region nominal beam energy nominalBeamEnergy[i] = Convert.ToDouble(dsControlPointSequence.GetString(Tags.NominalBeamEnergy).Replace('.', ',')); message += Environment.NewLine + "nominalBeamEnergy: " + nominalBeamEnergy[i].ToString() + Environment.NewLine; #endregion #region leaf jaw positions DcmElement dcmeBeamLimitingDevicePositionSequence = dsControlPointSequence.Get(Tags.BeamLimitingDevicePositionSeq); //wsp x Dataset dsLeafJawPositionsX = dcmeBeamLimitingDevicePositionSequence.GetItem(1); message += Environment.NewLine + "LeafJawPositions(X): " + dsLeafJawPositionsX.GetString(Tags.LeafJawPositions) + Environment.NewLine; #region zapisanie do tablicy tmpLeafPostionBoundariesOrJaws = dsLeafJawPositionsX.GetString(Tags.LeafJawPositions).Split('\\'); //tymczasowa tablica //jesli nie istnieje tablica tworzymy ja lub (jesli istnieje) zmieniamy jej rozmiar, gdy jest za maly/duzy dla nowego pliku if (this.leafJawPositionsX == null || (this.leafJawPositionsX.GetUpperBound(0) + 1) != this.numberOfBeams || (this.leafJawPositionsX.GetUpperBound(1) + 1) != tmpLeafPostionBoundariesOrJaws.Length) { this.leafJawPositionsX = new double[this.numberOfBeams, tmpLeafPostionBoundariesOrJaws.Length]; } for (int j = 0; j < tmpLeafPostionBoundariesOrJaws.Length; j++) { this.leafJawPositionsX[i, j] = Convert.ToDouble(tmpLeafPostionBoundariesOrJaws[j].Replace('.', ',')); } #endregion //wsp y Dataset dsLeafJawPositionsY = dcmeBeamLimitingDevicePositionSequence.GetItem(0); message += Environment.NewLine + "LeafJawPositions(Y): " + dsLeafJawPositionsY.GetString(Tags.LeafJawPositions) + Environment.NewLine; #region zapisanie do tablicy tmpLeafPostionBoundariesOrJaws = dsLeafJawPositionsY.GetString(Tags.LeafJawPositions).Split('\\'); //tymczasowa tablica //jesli nie istnieje tablica tworzymy ja lub (jesli istnieje) zmieniamy jej rozmiar, gdy jest za maly/duzy dla nowego pliku if (this.leafJawPositionsY == null || (this.leafJawPositionsY.GetUpperBound(0) + 1) != this.numberOfBeams || (this.leafJawPositionsY.GetUpperBound(1) + 1) != tmpLeafPostionBoundariesOrJaws.Length) { this.leafJawPositionsY = new double[this.numberOfBeams, tmpLeafPostionBoundariesOrJaws.Length]; } for (int j = 0; j < tmpLeafPostionBoundariesOrJaws.Length; j++) { this.leafJawPositionsY[i, j] = Convert.ToDouble(tmpLeafPostionBoundariesOrJaws[j].Replace('.', ',')); } #endregion #endregion #region SSD i glebokosc izocentrum Dataset dsSourceAxisDistance = dcmeBeamSequence.GetItem(i); SSD[i] = Convert.ToDouble(dsControlPointSequence.GetString(Tags.SourceToSurfaceDistance).Replace('.', ',')) / 10; SSDDepth[i] = (Convert.ToDouble(dsSourceAxisDistance.GetString(Tags.SourceAxisDistance).Replace('.', ',')) / 10) - SSD[i]; message += Environment.NewLine + "SSD(cm): " + SSD[i].ToString() + Environment.NewLine; message += "Głębokość izocentrum(cm): " + SSDDepth[i].ToString() + Environment.NewLine; #endregion } #endregion this.properRTPlanLoaded = true; logTextbox.Text = message; MessageBox.Show("Pomyślnie załadowano plik RT Planu!", "Sukces", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (NullReferenceException) //wyłapywanie braku którychś danych { MessageBox.Show("Ten plik nie zawiera wszystkich potrzebnych do obliczeń danych!" + Environment.NewLine + "Spróbuj załadować prawidłowy plik!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); this.properRTPlanLoaded = false; } if (this.properRTPlanLoaded) { #region wczytywanie parametrow z plikow DOSE //inicjalizacja bool[] doseLoaded = new bool[this.numberOfBeams]; if (MessageBox.Show("Czy chcesz załadować pliki RT Dose?", "Ładowanie RT Dose", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { #region automatyczne wczytywanie plikow DOSE string RTPlanPath = Path.GetDirectoryName(fileNameTextbox.Text); IEnumerable<string> RTPlanDirDoseFiles = Directory.EnumerateFiles(RTPlanPath, "RD*.dcm"); int j = 0; foreach (string doseFileName in RTPlanDirDoseFiles) { DOSELoad doseload = this.doseFileLoad(doseFileName); List<List<string>> doseData = doseload.beamData(); if (doseload.success) { if (doseData[1].Count > 0) //sprawdzenie, czy potrzebne dane sa w pliku { this.SSD[doseload.beamNumber - 1] = Convert.ToDouble(doseData[1][3].Replace('.', ',')) / 10; this.SSDDepth[doseload.beamNumber - 1] = Convert.ToDouble(doseData[1][4].Replace('.', ',')) / 10; this.radDepth[doseload.beamNumber - 1] = Convert.ToDouble(doseData[1][5].Replace('.', ',')) / 10; doseLoaded[j] = true; } else { j--; //zmniejszenie licznika aby zaladowac wlasciwy plik dla kazdej wiazki } } else { doseLoaded[j] = false; } j++; } if (j > 0) { MessageBox.Show("Załadowano " + j.ToString() + " plików RT Dose", "Pliki RT Dose", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Nie znaleziono w katalogu RT Planu plików RT Dose", "Pliki RT Dose", MessageBoxButtons.OK, MessageBoxIcon.Information); } #endregion } else { MessageBox.Show("W związku z niewybraniem plików RT Dose niektóre wyniki mogą być nieprecyzyjne!", "Ostrzeżenie", MessageBoxButtons.OK, MessageBoxIcon.Warning); } #endregion #region automatyczne ladowanie tabeli wydajnosci i pdg dla danego aparatu bool properLoadWyd = false; bool properLoadPDG = false; if (nominalBeamEnergy[0].ToString() == "6") { properLoadWyd = this.loadTables(ref this.tlWyd, defaultTablePath6 + "wyd.dat"); properLoadPDG = this.loadTables(ref this.tlPDG, defaultTablePath6 + "pdg.dat"); } else if (nominalBeamEnergy[0].ToString() == "15") { properLoadWyd = this.loadTables(ref this.tlWyd, defaultTablePath15 + "wyd.dat"); properLoadPDG = this.loadTables(ref this.tlPDG, defaultTablePath15 + "pdg.dat"); } if (properLoadWyd && properLoadPDG) { MessageBox.Show("Pomyślnie załadowano pliki tabel wydajności i pdg!", "Sukces", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (properLoadWyd) { MessageBox.Show("Pomyślnie załadowano plik tabeli wydajności!", "Sukces", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Błąd ładowania pliku tabeli pdg!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (properLoadPDG) { MessageBox.Show("Pomyślnie załadowano plik tabeli pdg!", "Sukces", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Błąd ładowania pliku tabeli wydajności!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Błąd ładowania plików tabel wydajności i pdg!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } #endregion } } else //w przypadku, gdy nie jest to RT Plan { MessageBox.Show("Ten plik nie zawiera potrzebnych danych!" + Environment.NewLine + "Najprawdopodobniej nie jest to RTPlan - spróbuj załadować prawidłowy plik!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private String ToFileID(Dataset ds, uint tag) { try { String s = ds.GetString(tag); if (s == null || s.Length == 0) return "__NULL__"; char[] ins = s.ToUpper().ToCharArray(); char[] outs = new char[System.Math.Min(8, ins.Length)]; for (int i = 0; i < outs.Length; ++i) { outs[i] = ins[i] >= '0' && ins[i] <= '9' || ins[i] >= 'A' && ins[i] <= 'Z'?ins[i]:'_'; } return new String(outs); } catch (DcmValueException e) { return "__ERR__"; } }
private FileInfo toFile(Dataset ds) { String studyInstUID = null; try { studyInstUID = ds.GetString(Tags.StudyInstanceUID); if (studyInstUID == null) { throw new DcmServiceException(MISSING_UID, "Missing Study Instance UID"); } if (ds.vm(Tags.SeriesInstanceUID) <= 0) { throw new DcmServiceException(MISSING_UID, "Missing Series Instance UID"); } String instUID = ds.GetString(Tags.SOPInstanceUID); if (instUID == null) { throw new DcmServiceException(MISSING_UID, "Missing SOP Instance UID"); } String classUID = ds.GetString(Tags.SOPClassUID); if (classUID == null) { throw new DcmServiceException(MISSING_UID, "Missing SOP Class UID"); } if (!instUID.Equals(ds.GetFileMetaInfo().MediaStorageSOPInstanceUID)) { throw new DcmServiceException(MISMATCH_UID, "SOP Instance UID in Dataset differs from Affected SOP Instance UID"); } if (!classUID.Equals(ds.GetFileMetaInfo().MediaStorageSOPClassUID)) { throw new DcmServiceException(MISMATCH_UID, "SOP Class UID in Dataset differs from Affected SOP Class UID"); } } catch (DcmValueException e) { throw new DcmServiceException(CANNOT_UNDERSTAND, e); } String pn = ToFileID(ds, Tags.PatientName) + "____"; FileInfo dir = archiveDir; for (int i = 0; i < dirSplitLevel; ++i) { dir = new FileInfo(dir.FullName + "\\" + pn.Substring(0, (i + 1) - (0))); } dir = new FileInfo(dir.FullName + "\\" + studyInstUID); dir = new FileInfo(dir.FullName + "\\" + ToFileID(ds, Tags.SeriesNumber)); FileInfo file = new FileInfo(dir.FullName + "\\" + ToFileID(ds, Tags.InstanceNumber) + ".dcm"); return file; }