ObservableList Werte hinzufügen

Hallo zusammen,

ich brauche eure Unterstützung.
In meinem Programm wird ein Server mit Test Patientendaten abgefragt.
Dieser Server Antwortet und gibt zu jedem Patienteneintrag mehrere Informationen zurück.
Jede dieser Info: ( studyInstanceUID:1.2.826.0.1.3680043.6.30452.15777.20210115165916.792.13test image001test20210115 ) soll in eine Liste angezeigt werden.

Leider bekomme ich es nicht hin die Informationen in eine ObservableList einzufügen.
Wie kann ich es in meinem Programm am besten machen:

Hier mein Programm:

[CODE lang="java" title="DICOM QR" highlight="137-158"]import java.util.Properties;

import com.pixelmed.dicom.Attribute;
import com.pixelmed.dicom.AttributeList;
import com.pixelmed.dicom.DicomException;
import com.pixelmed.dicom.SOPClass;
import com.pixelmed.dicom.SpecificCharacterSet;
import com.pixelmed.dicom.TagFromName;
import com.pixelmed.network.FindSOPClassSCU;
import com.pixelmed.network.IdentifierHandler;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableArray;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;

public class DicomCfindApp extends Application{



@Override
public void start(Stage primaryStage) throws Exception {
Group root = new Group();
Scene scene = new Scene(root,500,520);

Label label = new Label("QR");
label.setFont(new Font(20));
TextField patname = new TextField();
Button button = new Button("Suchen");

TableView<IOD> tableView = new TableView<IOD>();

TableColumn<IOD, String> patnameCol = new TableColumn<IOD, String>("Name");
TableColumn<IOD, String> patidCol = new TableColumn<IOD, String>("PAT_ID");
TableColumn<IOD, String> dobCol = new TableColumn<IOD, String>("DOB");
TableColumn<IOD, String> sexCol = new TableColumn<IOD, String>("Sex");
TableColumn<IOD, String> studyDescCol = new TableColumn<IOD, String>("StudyDesc");
TableColumn<IOD, String> studyiuidCol = new TableColumn<IOD, String>("StudyIUID");

tableView.getColumns().addAll(patnameCol,patidCol,dobCol,sexCol,studyDescCol,studyiuidCol);

patnameCol.setCellValueFactory(new PropertyValueFactory("PatientName"));
patidCol.setCellValueFactory(new PropertyValueFactory("PatientID"));
dobCol.setCellValueFactory(new PropertyValueFactory("dOb"));
sexCol.setCellValueFactory(new PropertyValueFactory("seX"));
studyDescCol.setCellValueFactory(new PropertyValueFactory("dEsc"));
studyiuidCol.setCellValueFactory(new PropertyValueFactory("sIUID"));

ObservableList<IOD> list = getPatIOD();
tableView.setItems(list);

VBox vBox = new VBox(10);
vBox.setPadding(new Insets(0, 0, 0, 10));
vBox.getChildren().addAll(label,patname,button,tableView);
root.getChildren().addAll(vBox);

button.setOnAction(new EventHandler<ActionEvent>() {

@Override
public void handle(ActionEvent event) {
if ( !patname.getText().isEmpty()) {

String pname = patname.getText();
cfind(pname);

}
else {
System.out.println("Kein Namen angegeben");
}
}
});


primaryStage.setScene(scene);
primaryStage.show();

}

private ObservableList<IOD> getPatIOD() {
IOD pat1 = new IOD("TEST^Allergator","6702200","19450706","M","MR-Schädel","1.2.826.0.1.3680043.6.30452.15777.20210115165916.792.13");
ObservableList<IOD> list = FXCollections.observableArrayList(pat1);
return list;
}

protected void cfind(String pname) {
try {
// use the default character set for VR encoding - override this as necessary
SpecificCharacterSet specificCharacterSet = new SpecificCharacterSet((String[])null);
AttributeList identifier = new AttributeList();

//build the attributes that you would like to retrieve as well as passing in any search criteria
identifier.putNewAttribute(TagFromName.QueryRetrieveLevel).addValue("STUDY"); //specific query root
identifier.putNewAttribute(TagFromName.PatientName,specificCharacterSet).addValue(pname);
System.out.println(pname);
identifier.putNewAttribute(TagFromName.PatientID,specificCharacterSet);
identifier.putNewAttribute(TagFromName.PatientBirthDate);
identifier.putNewAttribute(TagFromName.PatientSex);
identifier.putNewAttribute(TagFromName.StudyInstanceUID);
identifier.putNewAttribute(TagFromName.SeriesInstanceUID);
identifier.putNewAttribute(TagFromName.SOPInstanceUID);
identifier.putNewAttribute(TagFromName.StudyDescription);
identifier.putNewAttribute(TagFromName.StudyDate);

//retrieve all studies belonging to patient with name 'Bowen'
new FindSOPClassSCU("www.dicomserver.co.uk",
104,
"MEDCONNEC",
"OURCLIENT",
SOPClass.StudyRootQueryRetrieveInformationModelFind,identifier,
//new IdentifierHandler());
new OurCustomFindIdentifierHandler());

}
catch (Exception e) {
e.printStackTrace(System.err); // in real life, do something about this exception
System.exit(0);
}
}

class OurCustomFindIdentifierHandler extends IdentifierHandler {

//add additional constructors here as necessary to pass more information handling

@Override
public void doSomethingWithIdentifier(AttributeList attributeListForFindResult) throws DicomException {
//System.out.println("Matched result:" + attributeListForFindResult);

String studyInstanceUID = attributeListForFindResult.get(TagFromName.StudyInstanceUID).getSingleStringValueOrEmptyString();
String studyDesc = attributeListForFindResult.get(TagFromName.StudyDescription).getSingleStringValueOrEmptyString();
String patid = attributeListForFindResult.get(TagFromName.PatientID).getSingleStringValueOrEmptyString();
String patname = attributeListForFindResult.get(TagFromName.PatientName).getSingleStringValueOrEmptyString();
String dob = attributeListForFindResult.get(TagFromName.PatientBirthDate).getSingleStringValueOrEmptyString();
String studyDate = attributeListForFindResult.get(TagFromName.StudyDate).getSingleStringValueOrEmptyString();
System.out.println("studyInstanceUID:" + studyInstanceUID + studyDesc + patid + patname + dob + studyDate);



//do other things you need to do with the matched results
}

}



public static void main(String[] args) {
launch(args);
}
}


[/CODE]

Im OurCustomFindIdentifierHandler werden die Info vom Server zurückgeholt.

Für jede Hilfe wäre ich sehr dankbar.

Viele Grüße
 
Beste Antwort
In doSomethingWithIdentifier müsstest du keine neue Liste erstellen, sondern die Daten der bestehenden Liste hinzufügen. Am einfachsten dürfte dabei sein, dem OurCustomFindIdentifierHandler die bestehende Liste im Konstruktor zu übergeben.

Alternativ etwas wie MVC nutzen und das ganze entkoppelt – ist erstmal etwas mehr Arbeit, zahlt sich aber am Ende aus 🙂
In OurCustomFindIdentifierHandler#doSomethingWithIdentifier müsstest du den Eintrag in die ObservableList einfügen, denke ich. Aber du machst dort nichts. Wieso?
 
Hallo Looparda,

vielen Dank für deine Antwort und für den Tipp.
Habe auch die Idee, in der OurCustomFindIdentifierHandler#doSomethingWithIdentifier die Einträge in der ObservableList einzufügen. Aber wie genau kann ich das machen?
Mein Problem ist, wie werde ich die Klasse im Hauptprogramm aufrufen, damit die Einträge in tableView.setItems(list) hin einfließen?

Viele Grüße
 
Der TableView bindet sich als Datenquelle die Observable list (bereits umgesetzt). Du fügst die Einträge zur list hinzu (fehlt). Entweder machst du die list als Feld, oder übergibst sie der OurCustomFindIdentifierHandler#doSomethingWithIdentifier, damit du dort die Einträge hinzufügen kannst.
 
Hallo Looparda,

die Datenquelle ist nicht die Observable list (Die Observable List habe nur zum Testen erstellt).

[CODE lang="java" title="ObservableList"] private ObservableList<Person> getPatIOD() {
Person pat1= new Person("TEST^Alligator", "6702050", "19250706","M");
ObservableList<Person> list = FXCollections.observableArrayList(pat1);
return list;
}[/CODE]

Sondern in der OurCustomFindIdentifierHandler#doSomethingWithIdentifier befinden sich die Antworten des Servers.

[CODE lang="java" title="OurCustomFindIdentifierHandler" highlight="17-18"] class OurCustomFindIdentifierHandler extends IdentifierHandler {

//add additional constructors here as necessary to pass more information handling

@Override
public void doSomethingWithIdentifier(AttributeList attributeListForFindResult) throws DicomException {
//System.out.println("Matched result:" + attributeListForFindResult);

String studyInstanceUID = attributeListForFindResult.get(TagFromName.StudyInstanceUID).getSingleStringValueOrEmptyString();
String studyDesc = attributeListForFindResult.get(TagFromName.StudyDescription).getSingleStringValueOrEmptyString();
String patid = attributeListForFindResult.get(TagFromName.PatientID).getSingleStringValueOrEmptyString();
String patname = attributeListForFindResult.get(TagFromName.PatientName).getSingleStringValueOrEmptyString();
String dob = attributeListForFindResult.get(TagFromName.PatientBirthDate).getSingleStringValueOrEmptyString();
String studyDate = attributeListForFindResult.get(TagFromName.StudyDate).getSingleStringValueOrEmptyString();
System.out.println("studyInstanceUID:" + studyInstanceUID + studyDesc + patid + patname + dob + studyDate);

Person pat1= new Person(patname, patid, dob,studyDesc);
ObservableList<Person> list = FXCollections.observableArrayList(pat1);

//do other things you need to do with the matched results
}

}[/CODE]

Habe diese Class erweitert mit der ObservableList, aber wie kann ich die Tabelle meinen "Hauptprogamm" übergeben?

[CODE lang="java" title="abfragen der Liste"]ObservableList<Person> list =getPatIOD();
tableView.setItems(list);[/CODE]


So funktioniert es leider auch nicht:
[CODE lang="java" title="List"]Person pat1= new Person(patname, patid, dob,studyDesc);
ObservableList<Person> list = FXCollections.observableArrayList(pat1);
tableView.setItems(list);[/CODE]

Hier auch das ganze Programm:

[CODE lang="java" title="GanzesProgramm"]import com.pixelmed.dicom.Attribute;
import com.pixelmed.dicom.AttributeList;
import com.pixelmed.dicom.DicomException;
import com.pixelmed.dicom.SOPClass;
import com.pixelmed.dicom.SpecificCharacterSet;
import com.pixelmed.dicom.TagFromName;
import com.pixelmed.network.FindSOPClassSCU;
import com.pixelmed.network.IdentifierHandler;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableArray;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;

public class DicomCfindApp extends Application{



@Override
public void start(Stage primaryStage) throws Exception {
Group root = new Group();
Scene scene = new Scene(root,500,520);

Label label = new Label("QR");
label.setFont(new Font(20));
TextField patname = new TextField();
Button button = new Button("Suchen");

TableView<Person> tableView = new TableView<Person>();

TableColumn<Person, String> patnameCol = new TableColumn<Person, String>("Name");
TableColumn<Person, String> patidCol = new TableColumn<Person, String>("PAT_ID");
TableColumn<Person, String> dobCol = new TableColumn<Person, String>("DOB");
TableColumn<Person, String> sexCol = new TableColumn<Person, String>("Sex");
TableColumn<Person, String> studyDateCol = new TableColumn<Person, String>("StudyDate");
TableColumn<Person, String> studyiuidCol = new TableColumn<Person, String>("StudyIUID");

tableView.getColumns().addAll(patnameCol,patidCol,dobCol,sexCol,studyDateCol,studyiuidCol);

patnameCol.setCellValueFactory(new PropertyValueFactory("userName"));
patidCol.setCellValueFactory(new PropertyValueFactory("firstName"));
dobCol.setCellValueFactory(new PropertyValueFactory("lastName"));
sexCol.setCellValueFactory(new PropertyValueFactory("email"));
ObservableList<Person> list =getPatIOD();
tableView.setItems(list);


VBox vBox = new VBox(10);
vBox.setPadding(new Insets(0, 0, 0, 10));
vBox.getChildren().addAll(label,patname,button,tableView);
root.getChildren().addAll(vBox);

button.setOnAction(new EventHandler<ActionEvent>() {

@Override
public void handle(ActionEvent event) {
if ( !patname.getText().isEmpty()) {

String pname = patname.getText();
cfind(pname);

}
else {
System.out.println("Kein Namen angegeben");
}
}
});


primaryStage.setScene(scene);
primaryStage.show();

}

private ObservableList<Person> getPatIOD() {
Person pat1= new Person("TEST^Alligator", "6702500", "194507068,"O");
ObservableList<Person> list = FXCollections.observableArrayList(pat1);
return list;
}

protected void cfind(String pname) {
try {
// use the default character set for VR encoding - override this as necessary
SpecificCharacterSet specificCharacterSet = new SpecificCharacterSet((String[])null);
AttributeList identifier = new AttributeList();

//build the attributes that you would like to retrieve as well as passing in any search criteria
identifier.putNewAttribute(TagFromName.QueryRetrieveLevel).addValue("STUDY"); //specific query root
identifier.putNewAttribute(TagFromName.PatientName,specificCharacterSet).addValue(pname);
System.out.println(pname);
identifier.putNewAttribute(TagFromName.PatientID,specificCharacterSet);
identifier.putNewAttribute(TagFromName.PatientBirthDate);
identifier.putNewAttribute(TagFromName.PatientSex);
identifier.putNewAttribute(TagFromName.StudyInstanceUID);
identifier.putNewAttribute(TagFromName.SeriesInstanceUID);
identifier.putNewAttribute(TagFromName.SOPInstanceUID);
identifier.putNewAttribute(TagFromName.StudyDescription);
identifier.putNewAttribute(TagFromName.StudyDate);

//retrieve all studies belonging to patient with name 'Bowen'
new FindSOPClassSCU("www.dicomserver.co.uk",
104,
"MEDCONNECT",
"OURCLIENT",
SOPClass.StudyRootQueryRetrieveInformationModelFind,identifier,
//new IdentifierHandler());
new OurCustomFindIdentifierHandler());

}
catch (Exception e) {
e.printStackTrace(System.err); // in real life, do something about this exception
System.exit(0);
}
}

class OurCustomFindIdentifierHandler extends IdentifierHandler {

//add additional constructors here as necessary to pass more information handling

@Override
public void doSomethingWithIdentifier(AttributeList attributeListForFindResult) throws DicomException {
//System.out.println("Matched result:" + attributeListForFindResult);

String studyInstanceUID = attributeListForFindResult.get(TagFromName.StudyInstanceUID).getSingleStringValueOrEmptyString();
String studyDesc = attributeListForFindResult.get(TagFromName.StudyDescription).getSingleStringValueOrEmptyString();
String patid = attributeListForFindResult.get(TagFromName.PatientID).getSingleStringValueOrEmptyString();
String patname = attributeListForFindResult.get(TagFromName.PatientName).getSingleStringValueOrEmptyString();
String dob = attributeListForFindResult.get(TagFromName.PatientBirthDate).getSingleStringValueOrEmptyString();
String studyDate = attributeListForFindResult.get(TagFromName.StudyDate).getSingleStringValueOrEmptyString();
System.out.println("studyInstanceUID:" + studyInstanceUID + studyDesc + patid + patname + dob + studyDate);

Person pat1= new Person(patname, patid, dob,studyDesc);
ObservableList<Person> list = FXCollections.observableArrayList(pat1);
tableView.setItems(list);

//do other things you need to do with the matched results
}

}






public static void main(String[] args) {
launch(args);
}
}


[/CODE]
 
In doSomethingWithIdentifier müsstest du keine neue Liste erstellen, sondern die Daten der bestehenden Liste hinzufügen. Am einfachsten dürfte dabei sein, dem OurCustomFindIdentifierHandler die bestehende Liste im Konstruktor zu übergeben.

Alternativ etwas wie MVC nutzen und das ganze entkoppelt – ist erstmal etwas mehr Arbeit, zahlt sich aber am Ende aus 🙂
 
Beste Antwort
Vielen Dank für die Antwort.

Das Ziel ist es, dass OurCustomFindIdentifierHandler die Daten in einer Liste erstellt und diese zur Verfügung stellt. Damit ich diese dann in der TabelView anzeigen lassen kann.



Siehe Abbildung:

TabelView.png


In der Console sieht man das Ergebnis der Abfrage, dieses Ergebnis soll in der ObservableList bzw. TabelView eingeblendet werden.



Wie mache ich das genau? Habe kaum Erfahrung mit JAVA, daher wäre es für mich hilfreich, wenn in den Antworten auch ein Beispiel Code mit dabei wäre.
 

Zurück
Oben