ValidationResult result = val.validateWithResult(input); IBaseOperationOutcome oo = result.toOperationOutcome(); ourLog.info("Result:\n{}", xmlParser.setPrettyPrint(true).encodeResourceToString(oo));
public Object returnResponse(ServletRequestDetails theRequest, ParseAction<?> outcome, int operationStatus, boolean allowPrefer, MethodOutcome response, String resourceName) throws IOException { HttpServletResponse servletResponse = theRequest.getServletResponse(); servletResponse.setStatus(operationStatus); servletResponse.setCharacterEncoding(Constants.CHARSET_NAME_UTF8); addHeadersToResponse(servletResponse); if (allowPrefer) { addContentLocationHeaders(theRequest, servletResponse, response, resourceName); } Writer writer; if (outcome != null) { ResponseEncoding encoding = RestfulServerUtils.determineResponseEncodingWithDefault(theRequest); servletResponse.setContentType(encoding.getResourceContentType()); writer = servletResponse.getWriter(); IParser parser = encoding.getEncoding().newParser(getFhirContext()); parser.setPrettyPrint(RestfulServerUtils.prettyPrintResponse(this, theRequest)); outcome.execute(parser, writer); } else { servletResponse.setContentType(Constants.CT_TEXT_WITH_UTF8); writer = servletResponse.getWriter(); } return writer; }
String outputString = parser.setPrettyPrint(true).encodeResourceToString(input); StringBuilder b = new StringBuilder(); for (String nextLine : outputString.split("\\n")) {
private static void testSearchForPatients() { List<IBaseResource> resources = new IncludesExamples().searchForPatients(); // Create a bundle with both FhirContext ctx = FhirContext.forDstu2(); Dstu2BundleFactory bf = new Dstu2BundleFactory(ctx); bf.initializeBundleFromResourceList(null, resources, "http://example.com/base", "http://example.com/base/Patient", 1, BundleTypeEnum.SEARCHSET); IBaseResource b = bf.getResourceBundle(); // Encode the bundle String encoded = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b); System.out.println(encoded); }
parser.setPrettyPrint(prettyPrint); parser.setServerBaseUrl(theRequestDetails.getFhirServerBase());
private static void tmp() { // Create a FHIR Context FhirContext ctx = FhirContext.forDstu2(); // Create a client IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu2"); // Read a patient with the given ID Patient patient = client .read() .resource(Patient.class) .withId("952975") .execute(); // Print the patient's name String string = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(patient); System.out.println(string); }
public static void main(String[] args) { // START SNIPPET: usage // Create a context. Note that we declare the custom types we'll be using // on the context before actually using them FhirContext ctx = FhirContext.forDstu3(); ctx.registerCustomType(CustomResource.class); ctx.registerCustomType(CustomDatatype.class); // Now let's create an instance of our custom resource type // and populate it with some data CustomResource res = new CustomResource(); // Add some values, including our custom datatype DateType value0 = new DateType("2015-01-01"); res.getTelevision().add(value0); CustomDatatype value1 = new CustomDatatype(); value1.setDate(new DateTimeType(new Date())); value1.setKittens(new StringType("FOO")); res.getTelevision().add(value1); res.setDogs(new StringType("Some Dogs")); // Now let's serialize our instance String output = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(res); System.out.println(output); // END SNIPPET: usage }
@SuppressWarnings("unused") public static void main(String[] args) throws DataFormatException, IOException { //START SNIPPET: patientUse MyPatient patient = new MyPatient(); patient.setPetName(new StringDt("Fido")); patient.getImportantDates().add(new DateTimeDt("2010-01-02")); patient.getImportantDates().add(new DateTimeDt("2014-01-26T11:11:11")); patient.addName().addFamily("Smith").addGiven("John").addGiven("Quincy").addSuffix("Jr"); IParser p = FhirContext.forDstu2().newXmlParser().setPrettyPrint(true); String messageString = p.encodeResourceToString(patient); System.out.println(messageString); //END SNIPPET: patientUse //START SNIPPET: patientParse IParser parser = FhirContext.forDstu2().newXmlParser(); MyPatient newPatient = parser.parseResource(MyPatient.class, messageString); //END SNIPPET: patientParse { FhirContext ctx2 = FhirContext.forDstu2(); RuntimeResourceDefinition def = ctx2.getResourceDefinition(patient); System.out.println(ctx2.newXmlParser().setPrettyPrint(true).encodeResourceToString(def.toProfile())); } }
public void fluent() throws DataFormatException { FhirContext ctx = new FhirContext(Patient.class, Observation.class); String encoded; //START SNIPPET: encodeMsgFluent Patient patient = new Patient(); patient.addIdentifier().setSystem("http://example.com/fictitious-mrns").setValue("MRN001"); patient.addName().setUse(NameUseEnum.OFFICIAL).addFamily("Tester").addGiven("John").addGiven("Q"); encoded = ctx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient); System.out.println(encoded); //END SNIPPET: encodeMsgFluent }
public static void manualContained() { // START SNIPPET: manualContained // Create an organization, and give it a local ID Organization org = new Organization(); org.setId("#localOrganization"); org.getNameElement().setValue("Contained Test Organization"); // Create a patient Patient patient = new Patient(); patient.setId("Patient/1333"); patient.addIdentifier().setSystem("urn:mrns").setValue("253345"); // Set the reference, and manually add the contained resource patient.getManagingOrganization().setReference("#localOrganization"); patient.getContained().getContainedResources().add(org); String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(patient); System.out.println(encoded); // END SNIPPET: manualContained }
String results = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(oo); System.out.println(results);
jsonParser.setPrettyPrint(true); encoded = jsonParser.encodeResourceToString(patient); System.out.println(encoded);
public static void main(String[] args) throws DataFormatException, IOException { //START SNIPPET: example1 Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:foo").setValue("7000135"); patient.addName().addFamily("Smith").addGiven("John").addGiven("Edward"); patient.addAddress().addLine("742 Evergreen Terrace").setCity("Springfield").setState("ZZ"); FhirContext ctx = FhirContext.forDstu2(); // Use the narrative generator ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); // Encode the output, including the narrative String output = ctx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient); System.out.println(output); //END SNIPPET: example1 }
private String encodeContents(Boolean thePrettyPrint, EncodingEnum encoding) { IParser parser; if (encoding == EncodingEnum.JSON) { parser = getContext().newJsonParser(); } else { parser = getContext().newXmlParser(); } if (thePrettyPrint != null) { parser.setPrettyPrint(thePrettyPrint); } if (myForceResourceId != null) { parser.setEncodeForceResourceId(myForceResourceId); } parser.setOmitResourceId(myOmitResourceId); if (myResources != null) { IVersionSpecificBundleFactory bundleFactory = getContext().newBundleFactory(); bundleFactory.initializeBundleFromResourceList("", myResources, "", "", myResources.size(), myBundleType); IBaseResource bundle = bundleFactory.getResourceBundle(); if (bundle != null) { return parser.encodeResourceToString(bundle); } IBaseResource bundleRes = bundleFactory.getResourceBundle(); return parser.encodeResourceToString(bundleRes); } else if (myContents != null) { return myContents; } else { return parser.encodeResourceToString(myResource); } }
ourLog.info("Response:\n{}", ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(response));
System.out.println(ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(responseBundle));
String output = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(patient); System.out.println(output);
extension.addUndeclaredExtension(new ExtensionDt(false, "cont", new StringDt("hola"))); System.out.println(FhirContext.forDstu2().newJsonParser().setPrettyPrint(true).encodeResourceToString(q)); String output = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(patient); System.out.println(output);
String output = FhirContext.forDstu2().newXmlParser().setPrettyPrint(true).encodeResourceToString(patient); System.out.println(output);
System.out.println(ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(bundle)); System.out.println(ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(resp));