ArrayList<StringDt> allNames = new ArrayList<StringDt>(); HumanNameDt nextHumanName = (HumanNameDt) nextObject; allNames.addAll(nextHumanName.getFamily()); allNames.addAll(nextHumanName.getGiven()); for (StringDt nextName : allNames) { addSearchTerm(theEntity, retVal, nextSpName, nextName.getValue());
@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); }
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 }
@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()); }
@Override public String serialize(HumanNameDt value) { return getComponent(value.getFamily(), 0) + NAME_DELIM + getComponent(value.getGiven(), 0) + NAME_DELIM + getComponent(value.getGiven(), 1) + NAME_DELIM + getComponent(value.getSuffix(), 0) + NAME_DELIM + getComponent(value.getPrefix(), 0) + NAME_DELIM + getComponent(value.getSuffix(), 1) + NAME_DELIM + value.getUse(); }
@Override public HumanNameDt deserialize(String value) { String pcs[] = value.split("\\" + NAME_DELIM); HumanNameDt result = new HumanNameDt(); int i = 0; result.addFamily(value); result.addGiven(value); result.addGiven(value); result.addSuffix(value); result.addPrefix(value); result.addSuffix(value); result.getUseElement().setValueAsString(value);
name = new HumanNameDt(); name.addFamily(pc); name.addGiven(pc);
/** * Gets the first repetition for <b>family</b> (), * creating it if it does not already exist. * * <p> * <b>Definition:</b> * The part of a name that links to the genealogy. In some cultures (e.g. Eritrea) the family name of a son is the first name of his father. * </p> */ public StringDt getFamilyFirstRep() { if (getFamily().isEmpty()) { return addFamily(); } return getFamily().get(0); } /**
/** * The main method here will directly call an open FHIR server and retrieve a * list of resources matching a given criteria, then load a linked resource. */ public static void main(String[] args) throws IOException { // Create a client factory FhirContext ctx = FhirContext.forDstu2(); // Create the client String serverBase = "http://fhir.healthintersections.com.au/open"; ClientInterface client = ctx.newRestfulClient(ClientInterface.class, serverBase); // Invoke the client to search for patient List<Patient> patients = client.findPatientsForMrn(new IdentifierDt("urn:oid:1.2.36.146.595.217.0.1", "12345")); System.out.println("Found " + patients.size() + " patients"); // Print a value from the loaded resource Patient patient = patients.get(0); System.out.println("Patient Last Name: " + patient.getName().get(0).getFamily().get(0).getValue()); // Load a referenced resource ResourceReferenceDt managingRef = patient.getManagingOrganization(); Organization org = (Organization) managingRef.loadResource(client); // Print organization name System.out.println(org.getName()); }
/** * 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); } /**
/** * Gets the value(s) for <b>name</b> (). * creating it if it does * not exist. Will not return <code>null</code>. * * <p> * <b>Definition:</b> * A name associated with the contact person * </p> */ public HumanNameDt getName() { if (myName == null) { myName = new HumanNameDt(); } return myName; }
/** * Gets the first repetition for <b>prefix</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 start of the name * </p> */ public StringDt getPrefixFirstRep() { if (getPrefix().isEmpty()) { return addPrefix(); } return getPrefix().get(0); } /**
/** * Adds a given new value for <b>given</b> () * * <p> * <b>Definition:</b> * Given name * </p> * @param theValue The given to add (must not be <code>null</code>) */ public HumanNameDt addGiven(StringDt theValue) { if (theValue == null) { throw new NullPointerException("theValue must not be null"); } getGiven().add(theValue); return this; }
/** * Adds a given new value for <b>prefix</b> () * * <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 start of the name * </p> * @param theValue The prefix to add (must not be <code>null</code>) */ public HumanNameDt addPrefix(StringDt theValue) { if (theValue == null) { throw new NullPointerException("theValue must not be null"); } getPrefix().add(theValue); return this; }
/** * Adds a given new value for <b>suffix</b> () * * <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> * @param theValue The suffix to add (must not be <code>null</code>) */ public HumanNameDt addSuffix(StringDt theValue) { if (theValue == null) { throw new NullPointerException("theValue must not be null"); } getSuffix().add(theValue); return this; }
/** * Returns a name of the desired use category from a list. * * @param list List of names to consider. * @param uses One or more use categories. These are searched in order until one is found. A * null value matches any use category. * @return A name with a matching use category, or null if none found. */ public static HumanNameDt getName(List<HumanNameDt> list, NameUseEnum... uses) { for (NameUseEnum use : uses) { for (HumanNameDt name : list) { if (use == null || use.equals(name.getUse())) { return name; } } } return null; }