public byte[] getDocumentAsBytes(String docType, String patientId) throws InvalidTypeException, InvalidIdentifierException, DocumentBuilderException { POCDMT000040ClinicalDocument clinDoc = getDocument(docType, patientId); try { return XMLUtil.toCanonicalXMLBytes(clinDoc); } catch (JAXBException ex) { log.error(ex); throw new DocumentBuilderException( "Failed to convert POCDMT000040ClinicalDocument object to String."); } }
public POCDMT000040ClinicalDocument getDocument(String docType, String patientId) throws InvalidTypeException, InvalidIdentifierException, DocumentBuilderException { // check for valid document type if (docType == null) { throw new InvalidTypeException("Must specify a document type."); } if (!DocumentTypeDAO.getInstance().isValidDocumentType(docType)) { log.debug("Requested document type \"" + docType + "\" is not supported!"); throw new InvalidTypeException( "Requested document type \"" + docType + "\" is not supported."); } documentType = docType; // check for valid patient identifier parameter if (patientId == null || patientId.length() < 1) { log.debug("Patient identifier \"" + patientId + "\" is invalid!"); throw new InvalidIdentifierException("Identifier is invalid."); } log.debug("Requesting document of type=" + docType + " for patient=" + patientId); // get a document builder CDADocumentBuilder docBuilder = AssemblerFactory.cdaBuilder(docType); docBuilder.setPatientId(patientId); POCDMT000040ClinicalDocument clinDoc = docBuilder.build(); log.debug("NEW DOCUMENT=" + XMLUtil.toPrettyXML(clinDoc)); log.debug( "Request for document=\"" + docBuilder.getDocumentType().getDisplayName() + "\" for patient[" + patientId + "] completed!"); return clinDoc; }