Java Code Examples for ca.uhn.fhir.parser.IParser#encodeResourceToString()

The following examples show how to use ca.uhn.fhir.parser.IParser#encodeResourceToString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FhirTransactionCustomizer.java    From syndesis with Apache License 2.0 6 votes vote down vote up
public void afterProducer(Exchange exchange) {
    final Message in = exchange.getIn();
    @SuppressWarnings("unchecked")
    List<IBaseResource> body = in.getBody(List.class);

    StringBuilder transaction = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" +
        "<Transaction xmlns=\"http://hl7.org/fhir\">");
    IParser parser = fhirContext.newXmlParser();
    for (IBaseResource resource: body) {
        String encodedResource = parser.encodeResourceToString(resource);
        transaction.append(encodedResource);
    }
    transaction.append("</Transaction>");

    in.setBody(transaction.toString());
}
 
Example 2
Source File: Example04_EncodeResource.java    From fhirstarters with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void main(String[] theArgs) {

		// Create a Patient
		Patient pat = new Patient();
		pat.addName().setFamily("Simpson").addGiven("Homer").addGiven("J");
		pat.addIdentifier().setSystem("http://acme.org/MRNs").setValue("7000135");
		pat.addTelecom().setUse(ContactPointUse.HOME).setSystem(ContactPointSystem.PHONE).setValue("1 (416) 340-4800");
		pat.setGender(AdministrativeGender.MALE);

		// Create a context
		FhirContext ctx = FhirContext.forDstu3();

		// Create a JSON parser
		IParser parser = ctx.newJsonParser();
		parser.setPrettyPrint(true);

		String encode = parser.encodeResourceToString(pat);
		System.out.println(encode);

	}
 
Example 3
Source File: Example33_UseExtendedPatient.java    From fhirstarters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(String[] args) {
     Example32_ExtendedPatient pat = new Example32_ExtendedPatient();
	pat.addName().setFamily("Simpson").addGiven("Homer");

	pat.setEyeColour(new CodeType("blue"));

	IParser p = FhirContext.forDstu3().newXmlParser().setPrettyPrint(true);
	String encoded = p.encodeResourceToString(pat);
	
	System.out.println(encoded);
}
 
Example 4
Source File: Functions.java    From bunsen with Apache License 2.0 3 votes vote down vote up
/**
 * Converts a resource to its XML representation.
 *
 * @param resource the resource
 * @return a string containing XML for the resource.
 */
public static String resourceToXml(Resource resource) {

  IParser parser = CONTEXT.newXmlParser();

  return parser.encodeResourceToString(resource);
}
 
Example 5
Source File: Functions.java    From bunsen with Apache License 2.0 3 votes vote down vote up
/**
 * Converts a resource to its JSON representation.
 *
 * @param resource the resource
 * @return a string containing JSON for the resource.
 */
public static String resourceToJson(Resource resource) {

  IParser parser = CONTEXT.newJsonParser();

  return parser.encodeResourceToString(resource);
}
 
Example 6
Source File: Functions.java    From bunsen with Apache License 2.0 3 votes vote down vote up
/**
 * Converts a resource to its XML representation.
 *
 * @param resource the resource
 * @return a string containing XML for the resource.
 */
public static String resourceToXml(Resource resource) {

  IParser parser = CONTEXT.newXmlParser();

  return parser.encodeResourceToString(resource);
}
 
Example 7
Source File: Functions.java    From bunsen with Apache License 2.0 3 votes vote down vote up
/**
 * Converts a resource to its JSON representation.
 *
 * @param resource the resource
 * @return a string containing JSON for the resource.
 */
public static String resourceToJson(Resource resource) {

  IParser parser = CONTEXT.newJsonParser();

  return parser.encodeResourceToString(resource);
}
 
Example 8
Source File: Example99_UseExtensions.java    From fhirstarters with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
public static void main(String[] args) {

      Example32_ExtendedPatient pat = new Example32_ExtendedPatient();
      pat.addName().setFamily("Simpson").addGiven("Homer");
      pat.setEyeColour(new CodeType("blue"));

      IParser p = FhirContext.forDstu3().newXmlParser().setPrettyPrint(true);
      String encoded = p.encodeResourceToString(pat);

      System.out.println(encoded);

   }