@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())); } }
@SuppressWarnings("unused") public static void main(String[] args) throws DataFormatException, IOException { Patient patient = new Patient(); patient.addIdentifier().setUse(IdentifierUseEnum.OFFICIAL).setSystem("urn:fake:mrns").setValue("7000135"); patient.addIdentifier().setUse(IdentifierUseEnum.SECONDARY).setSystem("urn:fake:otherids").setValue("3287486"); patient.addName().addFamily("Smith").addGiven("John").addGiven("Q").addSuffix("Junior"); patient.setGender(AdministrativeGenderEnum.MALE); FhirContext ctx = FhirContext.forDstu2(); String xmlEncoded = ctx.newXmlParser().encodeResourceToString(patient); String jsonEncoded = ctx.newJsonParser().encodeResourceToString(patient); MyClientInterface client = ctx.newRestfulClient(MyClientInterface.class, "http://foo/fhir"); IdentifierDt searchParam = new IdentifierDt("urn:someidentifiers", "7000135"); List<Patient> clients = client.findPatientsByIdentifier(searchParam); }
/** * Gets the first repetition for <b>suffix</b> (), * creating it if it does not already exist. * * <p> * <b>Definition:</b> * Part of the name that is acquired as a title due to academic, legal, employment or nobility status, etc. and that appears at the end of the name * </p> */ public StringDt getSuffixFirstRep() { if (getSuffix().isEmpty()) { return addSuffix(); } return getSuffix().get(0); } /**
@Test public void test() { NameSerializer ns = new NameSerializer(); HumanNameDt name = new HumanNameDt(); name.addFamily("Martin"); name.addGiven("Douglas"); name.addGiven("Kent"); name.addPrefix("Dr."); name.addSuffix("M.D."); name.getUseElement().setValueAsEnum(NameUseEnum.OFFICIAL); String s = ns.serialize(name); System.out.println(s); HumanNameDt name2 = ns.deserialize(s); assertEquals(name.getFamily(), name2.getFamily()); assertEquals(name.getGiven(), name2.getGiven()); assertEquals(name.getPrefix(), name2.getPrefix()); assertEquals(name.getSuffix(), name2.getSuffix()); assertEquals(name.getUse(), name2.getUse()); }