package org.openhealthtools.uml.xdw; import java.util.LinkedList; import java.util.Queue; import net.ihe.gazelle.oasis.OASISFactory; import net.ihe.gazelle.v3.V3Factory; import net.ihe.gazelle.xdw.DocumentRoot; import net.ihe.gazelle.xdw.TXDWWorkflowDocument; import net.ihe.gazelle.xdw.XDWFactory; import net.ihe.gazelle.xdw.validator.XDWUtil.ValidationHandler; import org.eclipse.emf.common.util.Diagnostic; import org.eclipse.emf.ecore.util.Diagnostician; import org.eclipse.emf.ecore.util.EcoreUtil; public class XDWManualValidator { public static void main(String[] args) throws Exception { DocumentRoot dr = XDWFactory.eINSTANCE.createDocumentRoot(); TXDWWorkflowDocument txw = XDWFactory.eINSTANCE.createTXDWWorkflowDocument(); txw.setTitle(V3Factory.eINSTANCE.createST1()); txw.getTitle().setLanguage("langgg"); txw.setId(V3Factory.eINSTANCE.createII()); txw.getId().setRoot("rrrrrrrrhahahaha"); txw.setWorkflowInstanceID("ee"); txw.setWorkflowDocumentSequenceNumber(3333); txw.setPatient(XDWFactory.eINSTANCE.createTXDWpatient()); txw.getPatient().setBirthTime(V3Factory.eINSTANCE.createTS1()); txw.getPatient().getBirthTime().setValue("eeeeee"); txw.getAuthor().add(XDWFactory.eINSTANCE.createTXDWAuthor()); txw.getAuthor().get(0).setAssignedPerson(V3Factory.eINSTANCE.createPOCDMT000040Person()); txw.setTaskList(XDWFactory.eINSTANCE.createTaskListType()); txw.getTaskList().getXDWTask().add(XDWFactory.eINSTANCE.createTXDWTask()); txw.getTaskList().getXDWTask().get(0).setTaskData(OASISFactory.eINSTANCE.createTTaskInstanceData()); txw.getTaskList().getXDWTask().get(0).getTaskData().setComments(OASISFactory.eINSTANCE.createTComments()); System.err.println(txw.getAuthor().get(0).getAssignedPerson().getClassCode()); boolean validateDoc = validateXDW(txw, new ValidationHandler() { public void handleError(Diagnostic diagnostic) { System.out.println("ERROR: " + diagnostic.getMessage()); } @Override public void handleWarning(Diagnostic diagnostic) { System.out.println("WARNING: " + diagnostic.getMessage()); } @Override public void handleInfo(Diagnostic diagnostic) { System.out.println("INFO: " + diagnostic.getMessage()); } }); System.out.println("validation ==" + validateDoc); } public static boolean validateXDW(TXDWWorkflowDocument clinicalDocument, ValidationHandler handler){ if (clinicalDocument.eResource() != null) { // process diagnostics that were produced during EMF deserialization processDiagnostic(EcoreUtil.computeDiagnostic(clinicalDocument.eResource(), true), handler); } Diagnostic diagnostic = Diagnostician.INSTANCE.validate(clinicalDocument); if (handler != null) { processDiagnostic(diagnostic, handler); } return diagnostic.getSeverity() != Diagnostic.ERROR; } private static void processDiagnostic(Diagnostic diagnostic, ValidationHandler handler) { Queue queue = new LinkedList(); queue.add(diagnostic); // root while (!queue.isEmpty()) { Diagnostic d = queue.remove(); if (shouldHandle(d)) { handleDiagnostic(d, handler); // visit } for (Diagnostic childDiagnostic : d.getChildren()) { // process successors queue.add(childDiagnostic); } } } private static boolean shouldHandle(Diagnostic diagnostic) { // filter out diagnostics with no message or with root diagnostic message if (diagnostic.getMessage() == null || diagnostic.getMessage().startsWith("Diagnosis of")) { return false; } return true; } private static void handleDiagnostic(Diagnostic diagnostic, ValidationHandler handler) { switch (diagnostic.getSeverity()) { case Diagnostic.ERROR: handler.handleError(diagnostic); break; case Diagnostic.WARNING: handler.handleWarning(diagnostic); break; case Diagnostic.INFO: handler.handleInfo(diagnostic); break; } } }