Java Code Examples for ca.uhn.fhir.context.FhirContext#newJsonParser()

The following examples show how to use ca.uhn.fhir.context.FhirContext#newJsonParser() . 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: BunsenTestStu3ProfileProvider.java    From bunsen with Apache License 2.0 6 votes vote down vote up
private static void addBunsenTestStu3ProfileDefinitions(PrePopulatedValidationSupport support,
    FhirContext context) {

  IParser parser = context.newJsonParser();

  load(support, parser, "definitions/StructureDefinition-bunsen-test-profile-booleanfield.json");
  load(support, parser, "definitions/StructureDefinition-bunsen-test-profile-integerfield.json");
  load(support, parser, "definitions/StructureDefinition-bunsen-test-profile-Patient.json");
  load(support, parser,
      "definitions/StructureDefinition-bunsen-test-profile-integerArrayField.json");
  load(support, parser,
      "definitions/StructureDefinition-bunsen-test-profile-nested-extension.json");
  load(support, parser,
      "definitions/StructureDefinition-bunsen-test-profile-codeableconcept-ext.json");
  load(support, parser,
      "definitions/StructureDefinition-bunsen-test-codeableConcept-modifierExt.json");
  load(support, parser,
      "definitions/StructureDefinition-bunsen-test-string-modifierExt.json");
}
 
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: UsCoreStu3ProfileProvider.java    From bunsen with Apache License 2.0 5 votes vote down vote up
private static void addUsCoreDefinitions(PrePopulatedValidationSupport support,
    FhirContext context) {

  IParser parser = context.newJsonParser();

  load(support, parser, "definitions/StructureDefinition-us-core-allergyintolerance.json");
  load(support, parser, "definitions/StructureDefinition-us-core-birthsex.json");
  load(support, parser, "definitions/StructureDefinition-us-core-careplan.json");
  load(support, parser, "definitions/StructureDefinition-us-core-careteam.json");
  load(support, parser, "definitions/StructureDefinition-us-core-condition.json");
  load(support, parser, "definitions/StructureDefinition-us-core-device.json");
  load(support, parser, "definitions/StructureDefinition-us-core-diagnosticreport.json");
  load(support, parser, "definitions/StructureDefinition-us-core-direct.json");
  load(support, parser, "definitions/StructureDefinition-us-core-documentreference.json");
  load(support, parser, "definitions/StructureDefinition-us-core-encounter.json");
  load(support, parser, "definitions/StructureDefinition-us-core-ethnicity.json");
  load(support, parser, "definitions/StructureDefinition-us-core-goal.json");
  load(support, parser, "definitions/StructureDefinition-us-core-immunization.json");
  load(support, parser, "definitions/StructureDefinition-us-core-location.json");
  load(support, parser, "definitions/StructureDefinition-us-core-medication.json");
  load(support, parser, "definitions/StructureDefinition-us-core-medicationrequest.json");
  load(support, parser, "definitions/StructureDefinition-us-core-medicationstatement.json");
  load(support, parser, "definitions/StructureDefinition-us-core-observationresults.json");
  load(support, parser, "definitions/StructureDefinition-us-core-organization.json");
  load(support, parser, "definitions/StructureDefinition-us-core-patient.json");
  load(support, parser, "definitions/StructureDefinition-us-core-practitioner.json");
  load(support, parser, "definitions/StructureDefinition-us-core-practitionerrole.json");
  load(support, parser, "definitions/StructureDefinition-us-core-procedure.json");
  load(support, parser, "definitions/StructureDefinition-us-core-profile-link.json");
  load(support, parser, "definitions/StructureDefinition-us-core-race.json");
  load(support, parser, "definitions/StructureDefinition-us-core-smokingstatus.json");

}
 
Example 4
Source File: Example35_ParserErrorHandler.java    From fhirstarters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(String[] args) {

      String input =
         "{" +
            "\"resourceType\": \"Patient\"," +
            "\"foo\": \"bar\"" +
            "}";

      FhirContext ctx = FhirContext.forDstu3();
      IParser parser = ctx.newJsonParser();
      parser.setParserErrorHandler(new StrictErrorHandler());
      IBaseResource output = parser.parseResource(input);
   }
 
Example 5
Source File: Example05_ParseResource.java    From fhirstarters with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static void main(String[] theArgs) {
	
	String resourceBody = "{\"resourceType\":\"Patient\",\"identifier\":[{\"system\":\"http://acme.org/MRNs\",\"value\":\"7000135\"}],\"name\":[{\"family\":[\"Simpson\"],\"given\":[\"Homer\",\"J\"]}]}";

	// Create a context
	FhirContext ctx = FhirContext.forDstu3();
	
	// Create a JSON parser
	IParser parser = ctx.newJsonParser();
	Patient pat = parser.parseResource(Patient.class, resourceBody);
	
	List<Identifier> identifiers = pat.getIdentifier();
	String idSystemString = identifiers.get(0).getSystem();
	String idValueString = identifiers.get(0).getValue();
	
	System.out.println(idSystemString + " " + idValueString);
	
}