web stats
Mirth FHIR Technology Preview 1 Released! - Page 2 - Mirth Community

Go Back   Mirth Community > Mirth Connect > General Discussion

Reply
 
Thread Tools Display Modes
  #11  
Old 07-27-2015, 11:15 AM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,124
narupley is on a distinguished road
Default

Try this instead:
Code:
var ctx = new Packages.ca.uhn.fhir.context.FhirContext();
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #12  
Old 07-27-2015, 01:08 PM
vpnath vpnath is offline
OBX.1 Kenobi
 
Join Date: Jun 2010
Posts: 36
vpnath is on a distinguished road
Default

Quote:
Originally Posted by narupley View Post
The HAPI-FHIR libraries are bundled with it, so you can use them to convert between XML and JSON if needed. FhirContext is the class you may want to use.
Quote:
Originally Posted by narupley View Post
Try this instead:
Code:
var ctx = new Packages.ca.uhn.fhir.context.FhirContext();
Thanks!

I came up with a code template to convert the FHIR response to/from JSON/XML. It may be of help to others.

Let me know what you think:

Code:
function fhirConvertResponse(res_str, from, to) {
	var ctx = new Packages.ca.uhn.fhir.context.FhirContext();
	var xmlparser = ctx.newXmlParser();
	var jsonparser = ctx.newJsonParser();
	var resource  = (from == "xml") ? xmlparser.parseResource(res_str) : jsonparser.parseResource(res_str);

	return (from == "xml") ? jsonparser.encodeResourceToString(resource) : xmlparser.encodeResourceToString(resource)

}
Reply With Quote
  #13  
Old 07-27-2015, 02:30 PM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,124
narupley is on a distinguished road
Default

Nice! That's a pretty good idea, we'll probably add that and other helpful methods to a utility class in the next preview.
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #14  
Old 07-29-2015, 08:05 AM
vpnath vpnath is offline
OBX.1 Kenobi
 
Join Date: Jun 2010
Posts: 36
vpnath is on a distinguished road
Default

Quote:
Originally Posted by narupley View Post
Nice! That's a pretty good idea, we'll probably add that and other helpful methods to a utility class in the next preview.
Thanks Nick!

I've been playing with some of the add/set methods and there might be some opportunities to simplify working with codeable Enum data like gender.

Here's some example code I wrote to add a new name value and work contact# to a Patient record:

Code:
var data = result.getClob('data');
var value = org.apache.commons.io.IOUtils.toString(data.getCharacterStream());
var ctx = new Packages.ca.uhn.fhir.context.FhirContext();
	
jsonparser = ctx.newJsonParser();
		
var patient = jsonparser.parseResource(Packages.ca.uhn.fhir.model.dstu.resource.Patient, value);
patient.addName().setUse(Packages.ca.uhn.fhir.model.dstu.valueset.NameUseEnum.NICKNAME).addGiven("SLIM").addGiven("SHADY");
patient.addTelecom(Packages.ca.uhn.fhir.model.dstu.valueset.ContactUseEnum.WORK, "1-888-651-3231");
		
var encoded = jsonparser.encodeResourceToString(patient);
response = FhirResponseFactory.getReadResponse(encoded, result.getString('version'), null, 200, result.getString('mimetype'));
Reply With Quote
  #15  
Old 07-31-2015, 12:48 PM
vpnath vpnath is offline
OBX.1 Kenobi
 
Join Date: Jun 2010
Posts: 36
vpnath is on a distinguished road
Default

Is there a way to enable CORS on the FHIR Listener? I don't see any option to set the response headers the way you can with an HTTP Listener. Perhaps there is a way via Javascript?
Reply With Quote
  #16  
Old 08-06-2015, 12:21 PM
vpnath vpnath is offline
OBX.1 Kenobi
 
Join Date: Jun 2010
Posts: 36
vpnath is on a distinguished road
Default

OK, I figured it out. I added this call:

Code:
response.addHeader('Access-Control-Allow-Origin','*');
Now I'm having a problem setting the Content-Type to be 'application/json+fhir'.

I've even tried:

Code:
response.setMimeType('application/json+fhir');
But it always seems to default to 'application/xml+fhir' for some reason.
Reply With Quote
  #17  
Old 08-11-2015, 01:26 PM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,124
narupley is on a distinguished road
Default

Hmm good catch. It appears that's a bug in the code right now; it's only setting a custom Content-Type header for the Binary resource. All other resources are always being sent with the default charset (application/xml+fhir). I'll make the fix and try to get it updated soon...
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #18  
Old 08-13-2015, 07:46 AM
vpnath vpnath is offline
OBX.1 Kenobi
 
Join Date: Jun 2010
Posts: 36
vpnath is on a distinguished road
Default

Quote:
Originally Posted by narupley View Post
Hmm good catch. It appears that's a bug in the code right now; it's only setting a custom Content-Type header for the Binary resource. All other resources are always being sent with the default charset (application/xml+fhir). I'll make the fix and try to get it updated soon...
Thanks Nick! I wrote my web app to work with the XML response but find working with JSON much easier
Reply With Quote
  #19  
Old 08-17-2015, 02:31 PM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,124
narupley is on a distinguished road
Default

Quote:
Originally Posted by vpnath View Post
Thanks Nick! I wrote my web app to work with the XML response but find working with JSON much easier
FYI, that bug has been fixed, and the latest version is up on the website!
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #20  
Old 08-18-2015, 07:25 AM
vpnath vpnath is offline
OBX.1 Kenobi
 
Join Date: Jun 2010
Posts: 36
vpnath is on a distinguished road
Default

Quote:
Originally Posted by narupley View Post
FYI, that bug has been fixed, and the latest version is up on the website!
Thanks! Downloaded it and am getting proper JSON response back now!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 08:33 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation