// to produce a valid message, but for demonstration purposes we'll skip a few
// fields.
mdmMessage.getMSH().getEncodingCharacters().setValue("^~\\&");
mdmMessage.getMSH().getFieldSeparator().setValue("|");
OBX obx = mdmMessage.getOBX();
// This is not a complete CDA document, but it serves as a good example
String sampleClinicalDocument = "<ClinicalDocument xsi:schemaLocation=\"urn:hl7-org:v3 CDA.ReleaseTwo.CommitteeBallot03.Aug.2004.xsd\" templateId=\"2.16.840.1.113883.3.27.1776\">\r\n" +
" <id extension=\"c266\" root=\"2.16.840.1.113883.3.933\"/>\r\n" +
" <code code=\"11488-4\" codeSystem=\"2.16.840.1.113883.6.1\" displayName=\"Consultation note\"/>\r\n" +
" <title>Good Health Clinic Consultation Note</title>\r\n" +
" <effectiveTime value=\"20000407\"/>\r\n" +
"</ClinicalDocument>";
MimeMultipart mimeMessage = new MimeMultipart();
MimeBodyPart bodyPart = new MimeBodyPart();
bodyPart.setText(sampleClinicalDocument);
mimeMessage.addBodyPart(bodyPart);
// send the MIME message into a ByteArrayOutputStream
ByteArrayOutputStream byte1 = new ByteArrayOutputStream();
mimeMessage.writeTo(byte1);
// set the value of ED with the String
ED encapsuledData = new ED(mdmMessage);
encapsuledData.getTypeOfData().setValue("multipart");
encapsuledData.getDataSubtype().setValue("x-hl7-cda-level-one");
encapsuledData.getEncoding().setValue("A");
encapsuledData.getData().setValue( byte1.toString() );
// setting the data in the OBX segment
obx.getObservationIdentifier().getIdentifier().setValue("1");
obx.getValueType().setValue("CE");
obx.getObservationValue(0).setData(encapsuledData);
// Print the message out
System.out.println(new PipeParser().encode(mdmMessage));
/*