I am trying to create an HL7 message in Java and then print the resulting message. I am faking basic patient information and then adding the Drug Prescription information. Then, I want to print the complete message but I wasn't able to use the API correctly. I am new at using HL7, so I know I'm probably missing some required segments and even using the wrong ones, can you please help? This is my current code:
public RXO runDrugPrescriptionEvent(CMSGeneric cmsgen) {
CMSDrugPrescriptionEvent cmsic = (CMSDrugPrescriptionEvent) cmsgen;
ADT_A28 adt23 = new ADT_A28();
try {
adt23.initQuickstart("ADT", "A08", cmsic.getPDE_EVENT_ID());
// We set the sex identity (male or female)
if (cmsic.getBENE_SEX_IDENT_CD() == 1) {
adt23.getPID().getSex().setValue("Male");
}
else {
adt23.getPID().getSex().setValue("Female");
}
// We set a fake name and family name
adt23.getPID().insertPatientName(0).getGivenName().setValue("CMS Name " + MainTest.NEXT_PATIENT_ID);
adt23.getPID().insertPatientName(0).getFamilyName().setValue("CMS Family name " + MainTest.NEXT_PATIENT_ID);
MainTest.NEXT_PATIENT_ID++;
RXO rxo = new RXO(adt23, new DefaultModelClassFactory());
rxo.getRxo1_RequestedGiveCode().getCe1_Identifier().setValue("" + cmsic.getPDE_DRUG_CD());
rxo.getRxo18_RequestedGiveStrength().setValue("" + cmsic.getPDE_DRUG_STR_CD());
rxo.getRxo19_RequestedGiveStrengthUnits().getCe1_Identifier().setValue("" + cmsic.getPDE_DRUG_STR_UNITS());
rxo.getRxo5_RequestedDosageForm().getCe1_Identifier().setValue("" + cmsic.getPDE_DRUG_DOSE_CD());
rxo.getRxo11_RequestedDispenseAmount().setValue("" + cmsic.getPDE_DRUG_QTY_DIS());
HapiContext context = new DefaultHapiContext();
Parser parser = context.getPipeParser();
String encodedMessage = adt23.getParser().encode(rxo.getMessage());
logger.debug("Printing Message:");
logger.debug(encodedMessage);
return rxo;
} catch (IOException e) {
System.out.println("IOException creating HL7 message. " + e.getMessage());
e.printStackTrace();
} catch (HL7Exception e) {
System.out.println("HL7Exception creating HL7 message. " + e.getMessage());
e.printStackTrace();
}
return null;
}
With this code, the logger prints the following message:
MSH|^~\&|||||20160331101349.8+0100||ADT^A08|110001|PDE-00001E6FADAD3F57|2.3
PID|||||CMS Family name 100~^CMS Name 100|||Female
But I was expecting to see the RXO segment as well. How can I achieve that?
I found that changing the message type from ADT_A28 to ORP_O10 would let me have all the fields I need, as ADT_A28 wasn't the appropriate message for the kind of information I needed. There's a complete example on how to set a great amount of segments in this type of message here. Then, I was able to print the complete message using the PipeParser:
HapiContext context = new DefaultHapiContext();
Parser parser = context.getPipeParser();
String encodedMessage = parser.encode(msg);
logger.debug("Printing EREncoded Message:");
logger.debug(encodedMessage);
Related
I'm trying to play with jose4j and for example I tried to verify JsonWebSignature without setting the first part of CompactSerialization (as we use unprotected header).
It returns me
org.jose4j.lang.JoseException: Parsing error: org.jose4j.json.internal.json_simple.parser.ParseException: Unexpected character (�) at position 0.
Do you have any idea to permit that?
Thanks
Edit
Code is:
JsonWebSignature jws = new JsonWebSignature();
LicenseKeystore lk = new LicenseKeystore();
jws.setAlgorithmConstraints(new AlgorithmConstraints(ConstraintType.PERMIT, lk.KS_ALG));
JsonCanonicalizer jc = new JsonCanonicalizer(jsonSigned);
jws.setCompactSerialization(new Base64Url().base64UrlEncodeUtf8ByteRepresentation(null) + "." +
new Base64Url().base64UrlEncodeUtf8ByteRepresentation(jc.getEncodedString()) + "." +
cs.getSignature());
jws.setKey(lk.getPublicKey());
try {
return jws.verifySignature();
} catch (InvalidAlgorithmException e) {
return false;
}
JWS is in the type of .[payload].[signature]
i have several .pst files and need all the mail-addresses, i sent mails to. The example code of the library allows me to traverse every mail in the file, but i can't find the right getter to extract the mail address of the receiver.
To traverse every mail, i use the code from this site:
https://code.google.com/p/java-libpst/
PSTMessage email = (PSTMessage) folder.getNextChild();
while (email != null) {
printDepth();
System.out.println("Email: " + email.getSubject());
printDepth();
System.out.println("Adress: " + email.getDisplayTo());
email = (PSTMessage) folder.getNextChild();
}
The getDisplayTo() method only displays the receivers names but not their mail addresses.
What getter do i need to use to get the addresses?
Best,
Michael
First method : : available getters
getSenderEmailAddress
getNumberOfRecipients
getRecipient(int)
Second Method : parse the header and collect the email address (a_sHeader is a string)
Session s = Session.getDefaultInstance(new Properties());
InputStream is = new ByteArrayInputStream(a_sHeader.getBytes());
try {
m_message = new MimeMessage(s, is);
m_message.getAllHeaderLines();
for (Enumeration<Header> e = m_message.getAllHeaders(); e.hasMoreElements();) {
Header h = e.nextElement();
// Recipients
if (h.getName().equalsIgnoreCase(getHeaderName(RecipientType.REC_TYPE_TO))) {
m_RecipientsTo = processAddresses(h.getValue());
}
...
}
} catch (MessagingException e1) {
...
}
I want to pass an object using xmlrpc as this is the only possible way it seems that I can pass an Integer and a String to a method on the server. Is it possible to do this using an object? If not is there some other way of doing it?
I have attempted to do it but am getting this error:
JavaClient: XML-RPC Consumer Fault #java.io.IOException: unsupported
Java type: class Client.Article
This is the code on the client side:
public void addHash()
{
try {
addAuthorName = txtAddAuthorName.getText();
int addArticleNumber = Integer.parseInt(txtAddArticleNumber.getText());
newArticle = new Article(addAuthorName, addArticleNumber);
Vector<Object> addArticleArglist = new Vector<Object>();
addArticleArglist.addElement(newArticle);
System.out.println(newArticle);
// make the call
String callit = ("GetSize.addHash");
articleID = (Integer) client.execute(callit, addArticleArglist);
} // Use XmlRpcException errors
catch (XmlRpcException exception) {
System.err.println("JavaClient: XML-RPC Consumer Fault #"
+ Integer.toString(exception.code) + ": "
+ exception.getCause() + "" + exception.toString());
} catch (Exception exception) {
System.err.println("JavaClient: XML-RPC Consumer Fault #" + exception.toString());
}
}
This is the code on the server side however by using System.out.println I have discovered that for whatever reason none of the code within this method is being executed:
public void addHash(Article newArticle)
{
theHashtable.addHash(newArticle.getArticleName(), newArticle.getAuthorID());
}
Assuming you are using ws-xmlrpc the documentation states the following:
DOM nodes, or JAXB objects, can be transmitted. So are objects implementing the java.io.Serializable interface.
So by declaring your object serializable you would be able to transmit it. Depending what you want to do it might be a good idea to take a good look at jaxb.
See http://ws.apache.org/xmlrpc/ for more info.
I've made an E- Mail Client for my Android- Phone using the JavaMail API. I dont knoq how to get the E- Mail Content if it's a html- Mail. I'm using the following Code to get the Content:
public void printMessage(int messageNo) throws Exception {
Log.i("MsgNo", "Getting message number: " + messageNo);
Message m = null;
try {
m = folder.getMessage(messageNo);
dumpPart(m);
} catch (IndexOutOfBoundsException iex) {
Log.i("Out of Range","Message number out of range");
}
}
public static void dumpPart(Part p) throws Exception {
if (p instanceof Message)
dumpEnvelope((Message)p);
Object content = p.getContent();
Log.i("dumpPart",(String) content);
String ct = p.getContentType();
try {
pr("CONTENT-TYPE: " + (new ContentType(ct)).toString());
Log.i("MsgNo", "Content Type");
} catch (ParseException pex) {
pr("BAD CONTENT-TYPE: " + ct);
Log.i("MsgNo", "Bad Content Type");
}
//* Using isMimeType to determine the content type avoids
// * fetching the actual content data until we need it.
if (p.isMimeType("text/plain")) {
pr("This is plain text");
pr("---------------------------");
Log.i("Text", (String)p.getContent());
} else {
Log.i("MsgNo", "Just a Separator");
// just a separator
pr("---------------------------");
}
}
In the Logcat, i get the return value of dumpenvelope((Message)p); , but after that nothing.
Does anybody know what to do?
Is any exception thrown?
Did you enable debugging and examine the protocol trace to see what might have failed?
Are you using IMAP?
It looks like your program was created out of pieces of the JavaMail sample program called msgshow.java, did you find the complete original sample program?
This JavaMail FAQ entry might help as well.
I have written a code in java, where there are forms (input fields) and finally a send email button at the bottom. when the user clicks on the button, the data from the input fields should get extracted then be used as data for the body in the email.
this is the code i have:
if (role.getValue().equals("1")) {
Desktop desktop = Desktop.getDesktop();
String message = "mailto:username#domain.com?subject=Profildaten&body=" +
"Externe%20Referenz:%20" +
person.getExternalReference() + "%20" + "-%20" +
person.getExternalReferenceType() + "%0A" +
person.getTitle() + "%20" +
person.getContactLandline() + "%0A" +
"Mobil:%20" + person.getContactMobile() + "%0A" +
"Addresse:" + person.getContactStreet();
URI uri = URI.create(message);
try {
desktop.mail(uri);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
It all works perfectly, but the only issue is for Address: person.getContactStreet() the actual input field requires the user to enter a street name, and usually it would be two words, e.g. Cromwell Road - with a space inbetween cromwell and road. now the body of the email doesnt allow to have spaces and other invalid characters, hence why it is popping an error message saying invalid characters have been entered. how can i make it accept this or convert the invalid characters automatically to url encodings?
Have a look at this site, it tells you how to encode the URLS in the body automatically.
Best way to encode URL in Java