List of usage examples for org.dom4j Node selectNodes
List<Node> selectNodes(String xpathExpression);
selectNodes
evaluates an XPath expression and returns the result as a List
of Node
instances or String
instances depending on the XPath expression.
From source file:org.mskcc.cbio.portal.scripts.ImportCaisesClinicalXML.java
License:Open Source License
private static void parseMedicalTherapies(List<ClinicalEvent> clinicalEvents, Node patientNode, String patientId, int cancerStudyId) { List<Node> treatmentNodes = patientNode.selectNodes("MedicalTherapies/MedicalTherapy"); for (Node treatmentNode : treatmentNodes) { Patient patient = DaoPatient.getPatientByCancerStudyAndPatientId(cancerStudyId, patientId); ClinicalEvent clinicalEvent = new ClinicalEvent(); clinicalEvent.setPatientId(patient.getInternalId()); clinicalEvent.setEventType("TREATMENT"); clinicalEvent.addEventDatum("TREATMENT_TYPE", "Medical Therapy"); Node node = treatmentNode.selectSingleNode("MedTxDate"); if (node == null) { System.err.println("no date"); continue; }//from w w w.ja v a2 s .c om clinicalEvent.setStartDate(Long.parseLong(node.getText())); node = treatmentNode.selectSingleNode("MedTxStopDate"); if (node != null) { clinicalEvent.setStopDate(Long.parseLong(node.getText())); } node = treatmentNode.selectSingleNode("MedTxType"); if (node != null) { clinicalEvent.addEventDatum("SUBTYPE", node.getText()); } node = treatmentNode.selectSingleNode("MedTxIndication"); if (node != null) { clinicalEvent.addEventDatum("INDICATION", node.getText()); } node = treatmentNode.selectSingleNode("MedTxAgent"); if (node != null) { clinicalEvent.addEventDatum("AGENT", node.getText()); } node = treatmentNode.selectSingleNode("MedTxDose"); if (node != null) { clinicalEvent.addEventDatum("DOSE", node.getText()); } node = treatmentNode.selectSingleNode("MedTxTotalDose"); if (node != null) { clinicalEvent.addEventDatum("TOTAL_DOSE", node.getText()); } node = treatmentNode.selectSingleNode("MedTxUnits"); if (node != null) { clinicalEvent.addEventDatum("UNIT", node.getText()); } node = treatmentNode.selectSingleNode("MedTxSchedule"); if (node != null) { clinicalEvent.addEventDatum("SCHEDULE", node.getText()); } node = treatmentNode.selectSingleNode("MedTxRoute"); if (node != null) { clinicalEvent.addEventDatum("ROUTE", node.getText()); } clinicalEvents.add(clinicalEvent); } }
From source file:org.mskcc.cbio.portal.scripts.ImportCaisesClinicalXML.java
License:Open Source License
private static void parseRadiationTherapies(List<ClinicalEvent> clinicalEvents, Node patientNode, String patientId, int cancerStudyId) { List<Node> treatmentNodes = patientNode.selectNodes("RadiationTherapies/RadiationTherapy"); for (Node treatmentNode : treatmentNodes) { Patient patient = DaoPatient.getPatientByCancerStudyAndPatientId(cancerStudyId, patientId); ClinicalEvent clinicalEvent = new ClinicalEvent(); clinicalEvent.setPatientId(patient.getInternalId()); clinicalEvent.setEventType("TREATMENT"); clinicalEvent.addEventDatum("TREATMENT_TYPE", "Radiation Therapy"); Node node = treatmentNode.selectSingleNode("RadTxDate"); if (node == null) { System.err.println("no date"); continue; }/*from w ww .j a v a 2s . c o m*/ clinicalEvent.setStartDate(Long.parseLong(node.getText())); node = treatmentNode.selectSingleNode("RadTxStopDate"); if (node != null) { clinicalEvent.setStopDate(Long.parseLong(node.getText())); } node = treatmentNode.selectSingleNode("RadTxType"); if (node != null) { clinicalEvent.addEventDatum("SUBTYPE", node.getText()); } node = treatmentNode.selectSingleNode("RadTxIndication"); if (node != null) { clinicalEvent.addEventDatum("INDICATION", node.getText()); } node = treatmentNode.selectSingleNode("RadTxIntent"); if (node != null) { clinicalEvent.addEventDatum("INTENT", node.getText()); } node = treatmentNode.selectSingleNode("RadTxDosePerFraction"); if (node != null) { clinicalEvent.addEventDatum("DOSE_PER_FRACTION", node.getText()); } node = treatmentNode.selectSingleNode("RadTxTotalDose"); if (node != null) { clinicalEvent.addEventDatum("TOTAL_DOSE", node.getText()); } node = treatmentNode.selectSingleNode("RadTxUnits"); if (node != null) { clinicalEvent.addEventDatum("UNIT", node.getText()); } node = treatmentNode.selectSingleNode("RadTxNumFractions"); if (node != null) { clinicalEvent.addEventDatum("NUM_FRACTIONS", node.getText()); } node = treatmentNode.selectSingleNode("RadTxTarget"); if (node != null) { clinicalEvent.addEventDatum("TARGET", node.getText()); } clinicalEvents.add(clinicalEvent); } }
From source file:org.mskcc.cbio.portal.scripts.ImportCaisesClinicalXML.java
License:Open Source License
private static void parseBrachyTherapies(List<ClinicalEvent> clinicalEvents, Node patientNode, String patientId, int cancerStudyId) { List<Node> treatmentNodes = patientNode.selectNodes("BrachyTherapies/BrachyTherapy"); for (Node treatmentNode : treatmentNodes) { Patient patient = DaoPatient.getPatientByCancerStudyAndPatientId(cancerStudyId, patientId); ClinicalEvent clinicalEvent = new ClinicalEvent(); clinicalEvent.setPatientId(patient.getInternalId()); clinicalEvent.setEventType("TREATMENT"); clinicalEvent.addEventDatum("TREATMENT_TYPE", "Brachytherapy"); Node node = treatmentNode.selectSingleNode("BrachyDate"); if (node == null) { System.err.println("no date"); continue; }/*w w w. j a va 2 s .c o m*/ clinicalEvent.setStartDate(Long.parseLong(node.getText())); node = treatmentNode.selectSingleNode("BrachyIsotope"); if (node != null) { clinicalEvent.addEventDatum("BRACHY_ISOTOPE", node.getText()); } node = treatmentNode.selectSingleNode("BrachyPrescribedDose"); if (node != null) { clinicalEvent.addEventDatum("DOSE", node.getText()); } node = treatmentNode.selectSingleNode("BrachyDoseNotes"); if (node != null) { clinicalEvent.addEventDatum("DOSE_NOTES", node.getText()); } clinicalEvents.add(clinicalEvent); } }
From source file:org.mskcc.cbio.portal.scripts.ImportCaisesClinicalXML.java
License:Open Source License
private static void parseDiagnostics(List<ClinicalEvent> clinicalEvents, Node patientNode, String patientId, int cancerStudyId) { List<Node> diagnosticNodes = patientNode.selectNodes("Diagnostics/Diagnostic"); for (Node diagnosticNode : diagnosticNodes) { Patient patient = DaoPatient.getPatientByCancerStudyAndPatientId(cancerStudyId, patientId); ClinicalEvent clinicalEvent = new ClinicalEvent(); clinicalEvent.setPatientId(patient.getInternalId()); clinicalEvent.setEventType("DIAGNOSTIC"); Node node = diagnosticNode.selectSingleNode("DxDate"); if (node == null) { System.err.println("no date"); continue; }/* w w w . j a va 2 s.com*/ clinicalEvent.setStartDate(Long.parseLong(node.getText())); node = diagnosticNode.selectSingleNode("DxType"); if (node != null) { clinicalEvent.addEventDatum("DIAGNOSTIC_TYPE", node.getText()); } node = diagnosticNode.selectSingleNode("DxTarget"); if (node != null) { clinicalEvent.addEventDatum("TARGET", node.getText()); } node = diagnosticNode.selectSingleNode("DxResult"); if (node != null) { clinicalEvent.addEventDatum("RESULT", node.getText()); } node = diagnosticNode.selectSingleNode("DxNotes"); if (node != null) { clinicalEvent.addEventDatum("NOTES", node.getText()); } node = diagnosticNode.selectSingleNode("DxSide"); if (node != null) { clinicalEvent.addEventDatum("SIDE", node.getText()); } node = diagnosticNode.selectSingleNode("DxStatus"); if (node != null) { clinicalEvent.addEventDatum("STATUS", node.getText()); } node = diagnosticNode.selectSingleNode("ImgBaseline"); if (node != null) { clinicalEvent.addEventDatum("BASELINE", node.getText()); } node = diagnosticNode.selectSingleNode("DxNumNewTumors"); if (node != null) { clinicalEvent.addEventDatum("NUM_NEW_TUMORS", node.getText()); } clinicalEvents.add(clinicalEvent); } }
From source file:org.mskcc.cbio.portal.scripts.ImportCaisesClinicalXML.java
License:Open Source License
private static void parseLabTests(List<ClinicalEvent> clinicalEvents, Node patientNode, String patientId, int cancerStudyId) { List<Node> labTestNodes = patientNode.selectNodes("LabTests/LabTest"); for (Node labTestNode : labTestNodes) { Patient patient = DaoPatient.getPatientByCancerStudyAndPatientId(cancerStudyId, patientId); ClinicalEvent clinicalEvent = new ClinicalEvent(); clinicalEvent.setPatientId(patient.getInternalId()); clinicalEvent.setEventType("LAB_TEST"); Node node = labTestNode.selectSingleNode("LabDate"); if (node == null) { System.err.println("no date"); continue; }/*from www . j av a 2s.co m*/ clinicalEvent.setStartDate(Long.parseLong(node.getText())); node = labTestNode.selectSingleNode("LabTest"); if (node == null) { System.err.println("no lab test name"); continue; } clinicalEvent.addEventDatum("TEST", node.getText()); node = labTestNode.selectSingleNode("LabResult"); if (node == null) { System.err.println("no lab result"); continue; } clinicalEvent.addEventDatum("RESULT", node.getText()); node = labTestNode.selectSingleNode("LabUnits"); if (node != null) { clinicalEvent.addEventDatum("UNIT", node.getText()); } node = labTestNode.selectSingleNode("LabNormalRange"); if (node != null) { clinicalEvent.addEventDatum("NORMAL_RANGE", node.getText()); } node = labTestNode.selectSingleNode("LabNotes"); if (node != null) { clinicalEvent.addEventDatum("NOTES", node.getText()); } clinicalEvents.add(clinicalEvent); } }
From source file:org.mskcc.cbio.portal.scripts.ImportCaisesClinicalXML.java
License:Open Source License
private static void parseClinicalEventsFromSpecimen(List<ClinicalEvent> clinicalEvents, Node patientNode, String patientId, int cancerStudyId) { List<Node> specimenAccessionNodes = patientNode.selectNodes("SpecimenAccessions/SpecimenAccession"); for (Node specimenAccessionNode : specimenAccessionNodes) { Node node = specimenAccessionNode.selectSingleNode("AccessionDate"); if (node == null) { System.err.println("no date"); continue; }/*from w w w . ja va2s . c om*/ long date = Long.parseLong(node.getText()); String site = null, type = null, instrument = null; node = specimenAccessionNode.selectSingleNode("AccessionAnatomicSite"); if (node != null) { site = node.getText(); } node = specimenAccessionNode.selectSingleNode("AccessionVisitType"); if (node != null) { type = node.getText(); } node = specimenAccessionNode.selectSingleNode("AccessionProcInstrument"); if (node != null) { instrument = node.getText(); } List<Node> specimenNodes = specimenAccessionNode.selectNodes("Specimens/Specimen"); for (Node specimenNode : specimenNodes) { Patient patient = DaoPatient.getPatientByCancerStudyAndPatientId(cancerStudyId, patientId); ClinicalEvent clinicalEvent = new ClinicalEvent(); clinicalEvent.setPatientId(patient.getInternalId()); clinicalEvent.setEventType("SPECIMEN"); clinicalEvent.setStartDate(date); if (site != null) { clinicalEvent.addEventDatum("SPECIMEN_SITE", site); } if (type != null) { clinicalEvent.addEventDatum("ANATOMIC_SITE", type); } if (instrument != null) { clinicalEvent.addEventDatum("PROC_INSTRUMENT", instrument); } addAllDataUnderNode(clinicalEvent, Element.class.cast(specimenNode)); clinicalEvents.add(clinicalEvent); } } }
From source file:org.mskcc.cbio.portal.scripts.ImportCaisesClinicalXML.java
License:Open Source License
private static List<ClinicalData> parseClinicalDataFromSpecimen(Node patientNode, int cancerStudyId, Map<String, String> mapSu2cSampleIdSampleId) { List<ClinicalData> clinicalData = new ArrayList<ClinicalData>(); List<Node> specimenAccessionNodes = patientNode.selectNodes("SpecimenAccessions/SpecimenAccession"); for (Node specimenAccessionNode : specimenAccessionNodes) { String site = null, instrument = null; Node node = specimenAccessionNode.selectSingleNode("AccessionAnatomicSite"); if (node != null) { site = node.getText();/* w ww . ja v a 2 s .co m*/ } node = specimenAccessionNode.selectSingleNode("AccessionProcInstrument"); if (node != null) { instrument = node.getText(); } List<Node> specimenNodes = specimenAccessionNode.selectNodes("Specimens/Specimen"); for (Node specimenNode : specimenNodes) { node = specimenNode.selectSingleNode("SpecimenReferenceNumber"); if (node == null) { continue; } String su2cSampleId = node.getText(); String sampleId = mapSu2cSampleIdSampleId.get(su2cSampleId); if (sampleId == null) { continue; } if (site != null) { ClinicalData clinicalDatum = new ClinicalData(cancerStudyId, sampleId, "TUMOR_SITE", site); clinicalData.add(clinicalDatum); } if (instrument != null) { ClinicalData clinicalDatum = new ClinicalData(cancerStudyId, sampleId, "PROC_INSTRUMENT", instrument); clinicalData.add(clinicalDatum); } } } return clinicalData; }
From source file:org.mskcc.cbio.portal.scripts.ImportCaisesClinicalXML.java
License:Open Source License
private static long parseStatusesAndReturnDiagnosisDate(List<ClinicalEvent> clinicalEvents, Node patientNode, String patientId, int cancerStudyId) { List<Node> statusNodes = patientNode.selectNodes("Statuses/Status"); long diagnosisDate = 0; for (Node statusNode : statusNodes) { Patient patient = DaoPatient.getPatientByCancerStudyAndPatientId(cancerStudyId, patientId); ClinicalEvent clinicalEvent = new ClinicalEvent(); clinicalEvent.setPatientId(patient.getInternalId()); clinicalEvent.setEventType("STATUS"); Node node = statusNode.selectSingleNode("StatusDate"); if (node == null) { System.err.println("no date"); continue; }/*w ww. j a v a2s. co m*/ long statusDate = Long.parseLong(node.getText()); clinicalEvent.setStartDate(statusDate); node = statusNode.selectSingleNode("Status"); if (node == null) { System.err.println("no status"); continue; } clinicalEvent.addEventDatum("STATUS", node.getText()); if (node.getText().equalsIgnoreCase("Diagnosis Date")) { diagnosisDate = statusDate; } clinicalEvents.add(clinicalEvent); } return diagnosisDate; }
From source file:org.onecmdb.core.utils.transform.xml.XPathInstanceSelector.java
License:Open Source License
public List<IInstance> getInstances(DataSet ds) throws IOException { if (ds.getDataSource() instanceof XMLDataSource) { List<IInstance> rows = new ArrayList<IInstance>(); for (Node node : ((XMLDataSource) ds.getDataSource()).getNodes()) { List<Node> selectedNodes = node.selectNodes(getXpath()); for (Node selectedNode : selectedNodes) { XMLRow row = new XMLRow(ds, selectedNode); row.setAutoCreate(isAutoCreate()); String temp = null; if (templatePath != null) { Node n = row.getNode(); Object sNode = n.selectObject(templatePath); if (sNode instanceof Node) { temp = ((Node) sNode).getText(); } else if (sNode instanceof String) { temp = (String) sNode; }//from ww w .j a va2 s . c om } if (temp == null) { temp = getTemplate(); } row.setTemplate(temp); rows.add(row); } } return (rows); } throw new IllegalArgumentException("XPath selector must operate on an XML data source"); }
From source file:org.openadaptor.auxil.convertor.xml.XmlToOrderedMapConvertor.java
License:Open Source License
/** * Select Elements using an XPATH expression. Firstly the expression is used to select * Nodes. Then the Element subset of selected Nodes is returned. * * @param node the root node containing the elements to select * * @param xpathExpression the XPath expression used to selected the elements * * @return a possibly empty Element[]//from w ww .ja va2 s .co m * * @throws RecordException if there was an XPath error */ private Element[] selectElements(Node node, String xpathExpression) throws RecordException { List selectedNodes = node.selectNodes(xpathExpression); List selectedElements = new ArrayList(); Iterator it = selectedNodes.iterator(); while (it.hasNext()) { Object entry = it.next(); if (entry instanceof Node) { if (entry instanceof Element) selectedElements.add(entry); } else { String exceptionDetail = "XPATH selection using expression " + xpathExpression + " failed to return nodes."; if (throwRecordExceptionOnBadSelection) { log.warn(exceptionDetail); log.warn( "set throwRecordExceptionOnBadSelection to false to prevent an exception in this case."); throw new RecordException(exceptionDetail); } else { log.warn(exceptionDetail); log.warn("set throwRecordExceptionOnBadSelection to true to force an exception in this case."); } } } return (Element[]) selectedElements.toArray(new Element[selectedElements.size()]); }