Java Code Examples for org.hl7.fhir.dstu3.model.Extension#addExtension()

The following examples show how to use org.hl7.fhir.dstu3.model.Extension#addExtension() . 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: TestData.java    From bunsen with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a new Patient for testing.
 *
 * @return a FHIR Patient for testing.
 */
public static Patient newPatient() {

  Patient patient = new Patient();

  patient.setId("test-patient");
  patient.setGender(AdministrativeGender.MALE);
  patient.setActive(true);
  patient.setMultipleBirth(new IntegerType(1));

  patient.setBirthDateElement(new DateType("1945-01-02"));

  patient.addGeneralPractitioner().setReference("Practitioner/12345");

  Identifier practitionerIdentifier = new Identifier();
  practitionerIdentifier.setId("P123456");
  practitionerIdentifier.getAssigner().setReference("Organization/123456");
  patient.getGeneralPractitionerFirstRep().setIdentifier(practitionerIdentifier);

  Address address = patient.addAddress();
  address.addLine("123 Fake Street");
  address.setCity("Chicago");
  address.setState("IL");
  address.setDistrict("12345");

  Extension birthSex = patient.addExtension();

  birthSex.setUrl(US_CORE_BIRTHSEX);
  birthSex.setValue(new CodeType("M"));

  Extension ethnicity = patient.addExtension();
  ethnicity.setUrl(US_CORE_ETHNICITY);
  ethnicity.setValue(null);

  Coding ombCoding = new Coding();

  ombCoding.setSystem("urn:oid:2.16.840.1.113883.6.238");
  ombCoding.setCode("2135-2");
  ombCoding.setDisplay("Hispanic or Latino");

  // Add category to ethnicity extension
  Extension ombCategory = ethnicity.addExtension();

  ombCategory.setUrl("ombCategory");
  ombCategory.setValue(ombCoding);

  // Add multiple detailed sub-extension to ethnicity extension
  Coding detailedCoding1 = new Coding();
  detailedCoding1.setSystem("urn:oid:2.16.840.1.113883.6.238");
  detailedCoding1.setCode("2165-9");
  detailedCoding1.setDisplay("South American");

  Coding detailedCoding2 = new Coding();
  detailedCoding2.setSystem("urn:oid:2.16.840.1.113883.6.238");
  detailedCoding2.setCode("2166-7");
  detailedCoding2.setDisplay("Argentinean");

  final Extension detailed1 = ethnicity.addExtension();
  detailed1.setUrl("detailed");
  detailed1.setValue(detailedCoding1);

  final Extension detailed2 = ethnicity.addExtension();
  detailed2.setUrl("detailed");
  detailed2.setValue(detailedCoding2);

  // Add text display to ethnicity extension
  Extension ethnicityText = ethnicity.addExtension();
  ethnicityText.setUrl("text");
  ethnicityText.setValue(new StringType("Not Hispanic or Latino"));

  // Human Name
  HumanName humanName = new HumanName();
  humanName.setFamily("family_name");
  humanName.addGiven("given_name");
  humanName.addGiven("middle_name");
  patient.addName(humanName);

  return patient;
}