public MdhtDataFormat() { renderer = new CDAR2Renderer(); parser = new CDAR2Parser(); }
@Override public Object unmarshal(Exchange exchange, InputStream stream) throws Exception { return parser.parse(stream, (Object[]) null); }
@Override public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception { renderer.render((ClinicalDocument) graph, stream, (Object[]) null); }
/** * Test whether MDHT POJO can be used as input for Continua HRN. */ @Test public void testMdhtInputDatatype() throws Exception { String uri = "xds-iti41://localhost:" + getPort() + "/continuaHRNService"; // prepare request, delete original document contents ProvideAndRegisterDocumentSet request = EbXML30Converters.convert(hrnRequest); assertEquals(1, request.getDocuments().size()); Document xdsDocument = request.getDocuments().get(0); xdsDocument.removeContent(DataHandler.class); assertEquals(0, xdsDocument.getContentsCount()); // read in CCD file as MDHT and make it the new document contents InputStream stream = getClass().getClassLoader().getResourceAsStream("continua-hrn/SampleCCDDocument.xml"); ClinicalDocument mdhtDocument = new CDAR2Parser().parse(stream); xdsDocument.setContent(ClinicalDocument.class, mdhtDocument); // create data handler from MDHT document xdsDocument.getContent(byte[].class); xdsDocument.getContent(DataHandler.class); assertEquals(3, xdsDocument.getContentsCount()); // send the resulting request Response response = (Response) send(uri, hrnRequest, Response.class); assertEquals(Status.SUCCESS, response.getStatus()); }
private void doTest(String fileName) throws Exception { InputStream stream = getClass().getClassLoader().getResourceAsStream("continua-hrn/" + fileName); ClinicalDocument document = CDAUtil.load(stream); new CDAR2Validator().validate(document, null); } }
/** * Retrieves validation handler from context. If none found returns a * default validation handler. * * @param context * @return Validation handler */ private ValidationHandler retrieveValidationHandler(Map<Object, Object> context) { if (context != null) { ValidationHandler handler = (ValidationHandler) context.get(ValidationHandler.class); if (handler != null) { return handler; } } return new DefaultValidationHandler(); }
@Override public void validate(ClinicalDocument doc, Map<Object, Object> context) { boolean isValid = CDAUtil.validate(doc, retrieveValidationHandler(context)); if (! isValid) { throw new ValidationException("Clinical Document not valid!"); } }
public Writer render(ClinicalDocument doc, Writer writer, Object... options) throws IOException { String s = render(doc, options); writer.write(s); return writer; }
public ClinicalDocument parse(String s, Object... options) { try { return parse(new ByteArrayInputStream(s.getBytes()), options); } catch (IOException e) { throw new ParseException(e); } }
@Converter public static String toString(ClinicalDocument document, Exchange exchange) { return renderer.render(document,(Object[]) null); } }
public String render(ClinicalDocument doc, Object... options) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { render(doc, bos, options); return bos.toString(); } catch (IOException e) { throw new RenderException(e); } }
@Converter public static InputStream toInputStream(ClinicalDocument document, Exchange exchange) { Charset charset = Charset.defaultCharset(); if (exchange != null) { String charsetName = exchange.getProperty(Exchange.CHARSET_NAME, String.class); if (charsetName != null) { charset = Charset.forName(charsetName); } } return new ByteArrayInputStream(renderer.render(document, (Object[]) null).getBytes(charset)); }