diff --git a/Pacs_Simulator/README.md b/Pacs_Simulator/README.md index 42f38c7..676db50 100644 --- a/Pacs_Simulator/README.md +++ b/Pacs_Simulator/README.md @@ -40,11 +40,11 @@ You may also generate a sample DICOM file with minimum patient detail and relate This is useful when you do not want to run the simulator, but want to upload a DICOM file manually using "dcmsnd" command yourself. -> java -cp target/pacssimulator-1.0-SNAPSHOT-jar-with-dependencies.jar org.bahmni.pacssimulator.DicomFileGenerator [patientId] [givenName] [familyName] [accessionNumber] +> java -cp target/pacssimulator-1.0-SNAPSHOT-jar-with-dependencies.jar org.bahmni.pacssimulator.DicomFileGenerator [patientId] [givenName] [familyName] [accessionNumber] [filepath] example -> java -cp target/pacssimulator-1.0-SNAPSHOT-jar-with-dependencies.jar org.bahmni.pacssimulator.DicomFileGenerator GAN123 Gajendra Singh ORD-309 +> java -cp target/pacssimulator-1.0-SNAPSHOT-jar-with-dependencies.jar org.bahmni.pacssimulator.DicomFileGenerator GAN123 Gajendra Singh ORD-309 /tmp/test.dcm The above should tell you the location of the generated file. diff --git a/Pacs_Simulator/src/main/java/org/bahmni/pacssimulator/DicomFile.java b/Pacs_Simulator/src/main/java/org/bahmni/pacssimulator/DicomFile.java index 3133f34..5d8a5b6 100644 --- a/Pacs_Simulator/src/main/java/org/bahmni/pacssimulator/DicomFile.java +++ b/Pacs_Simulator/src/main/java/org/bahmni/pacssimulator/DicomFile.java @@ -12,10 +12,13 @@ import java.io.BufferedOutputStream; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.net.URISyntaxException; +import java.nio.file.Paths; import java.text.SimpleDateFormat; import java.util.Date; import java.util.UUID; @@ -64,32 +67,43 @@ public File writeFile(DicomObject dicomObject) { } public File generateFor(String patientId, String givenName, String familyName, String orderId) throws URISyntaxException, IOException, DicomException { - UIDGenerator uidGenerator = new UIDGenerator(); - - DicomInputStream dicomInputStream = new DicomInputStream(ClassLoader.getSystemResourceAsStream(fileName)); - DicomObject dicomObject = dicomInputStream.readDicomObject(); - -// String patientId = ormMessage.getPATIENT().getPID().getPatientID().getIDNumber().getValue(); - String studyId = UUID.randomUUID().toString(); - String instanceUid = uidGenerator.getNewSOPInstanceUID(studyId,"1","1").toString(); - String seriesInstanceUid = uidGenerator.getNewSeriesInstanceUID(studyId, "1").toString(); - String studyInstanceUid = uidGenerator.getNewStudyInstanceUID(studyId).toString(); - - dicomObject.putString(Tag.PatientName, VR.PN, givenName + " " + familyName); - dicomObject.putString(Tag.PatientID, VR.LO, patientId); - dicomObject.putString(Tag.AccessionNumber, VR.LO, orderId); - dicomObject.putString(Tag.StudyID, VR.LO, studyId); - dicomObject.putString(Tag.MediaStorageSOPInstanceUID, VR.UI, instanceUid); - dicomObject.putString(Tag.SOPInstanceUID, VR.UI, instanceUid); - dicomObject.putString(Tag.SeriesInstanceUID, VR.UI, seriesInstanceUid); - dicomObject.putString(Tag.StudyInstanceUID, VR.UI, studyInstanceUid); + File someFile = Paths.get(fileName).toFile(); + InputStream inputStream; + if (someFile.exists()) { + inputStream = new FileInputStream(someFile); + } else { + inputStream = ClassLoader.getSystemResourceAsStream(fileName); + } + if (inputStream == null) { + throw new RuntimeException("Could not load file"); + } + try { + UIDGenerator uidGenerator = new UIDGenerator(); + DicomInputStream dicomInputStream = new DicomInputStream(inputStream); + DicomObject dicomObject = dicomInputStream.readDicomObject(); + // String patientId = ormMessage.getPATIENT().getPID().getPatientID().getIDNumber().getValue(); + String studyId = UUID.randomUUID().toString(); + String instanceUid = uidGenerator.getNewSOPInstanceUID(studyId, "1", "1").toString(); + String seriesInstanceUid = uidGenerator.getNewSeriesInstanceUID(studyId, "1").toString(); + String studyInstanceUid = uidGenerator.getNewStudyInstanceUID(studyId).toString(); -// System.out.println("The Dicom file for patient"+patientId+givenName+familyName+orderId); -// System.out.println(dicomObject.toString()); + dicomObject.putString(Tag.PatientName, VR.PN, givenName + " " + familyName); + dicomObject.putString(Tag.PatientID, VR.LO, patientId); + dicomObject.putString(Tag.AccessionNumber, VR.LO, orderId); + dicomObject.putString(Tag.StudyID, VR.LO, studyId); + dicomObject.putString(Tag.MediaStorageSOPInstanceUID, VR.UI, instanceUid); + dicomObject.putString(Tag.SOPInstanceUID, VR.UI, instanceUid); + dicomObject.putString(Tag.SeriesInstanceUID, VR.UI, seriesInstanceUid); + dicomObject.putString(Tag.StudyInstanceUID, VR.UI, studyInstanceUid); - dicomObject.putString(Tag.StudyDate, VR.DT, new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())); + // System.out.println("The Dicom file for patient"+patientId+givenName+familyName+orderId); + // System.out.println(dicomObject.toString()); - return writeFile(dicomObject); + dicomObject.putString(Tag.StudyDate, VR.DT, new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())); + return writeFile(dicomObject); + } finally { + inputStream.close(); + } } public static void main(String[] args) { diff --git a/Pacs_Simulator/src/main/java/org/bahmni/pacssimulator/DicomFileGenerator.java b/Pacs_Simulator/src/main/java/org/bahmni/pacssimulator/DicomFileGenerator.java index 7775971..6adae71 100644 --- a/Pacs_Simulator/src/main/java/org/bahmni/pacssimulator/DicomFileGenerator.java +++ b/Pacs_Simulator/src/main/java/org/bahmni/pacssimulator/DicomFileGenerator.java @@ -5,16 +5,23 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.util.Random; public class DicomFileGenerator { + public static void main(String[] args) { + String[] sampleFiles = { "U_2015_05_26_14_18_35.dcm", "U_2015_05_26_14_23_16.dcm"}; + int i = new Random().nextInt(sampleFiles.length - 0) + 1; + System.out.println("arguments passed: " + String.join(",", args)); String patientId = "GAN203006"; String givenName = "Rutgar"; String familyName = "Ragos"; String accessionNumber = "ORD-307"; + String dicomFilePath = sampleFiles[i-1]; + //String dicomFilePath = "/Users/angshus/work/bahmni/utilities/Pacs_Simulator/0002.DCM"; if (args.length > 0) { patientId = args[0]; @@ -27,12 +34,15 @@ public static void main(String[] args) { if (args.length > 3) { accessionNumber = args[3]; } + if (args.length > 4) { + dicomFilePath = args[4]; + } } - System.out.println(String.format("Creating sample DICOM file with patientId:%s, givenName:%s, familyName:%s, accessionNumber:%s", - patientId, givenName, familyName, accessionNumber)); + System.out.println(String.format("Creating sample DICOM file with patientId:%s, givenName:%s, familyName:%s, accessionNumber:%s, file:%s", + patientId, givenName, familyName, accessionNumber, dicomFilePath)); //loaded from classpath, so put file in resources directory - DicomFile dicomFile = new DicomFile("U_2015_05_26_14_18_35.dcm"); + DicomFile dicomFile = new DicomFile(dicomFilePath); File file = null; try { file = dicomFile.generateFor(patientId, givenName, familyName, accessionNumber);