/** * 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()); }
String familyName = patient.getName().get(0).getFamily().get(0).getValue(); String gender = patient.getGender();
ArrayList<StringDt> allNames = new ArrayList<StringDt>(); HumanNameDt nextHumanName = (HumanNameDt) nextObject; allNames.addAll(nextHumanName.getFamily()); allNames.addAll(nextHumanName.getGiven()); for (StringDt nextName : allNames) {
/** * Adds a given new value for <b>family</b> () * * <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> * @param theValue The family to add (must not be <code>null</code>) */ public HumanNameDt addFamily(StringDt theValue) { if (theValue == null) { throw new NullPointerException("theValue must not be null"); } getFamily().add(theValue); return this; }
/** * 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); } /**
/** * Adds and returns a new value for <b>family</b> () * * <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 addFamily() { StringDt newType = new StringDt(); getFamily().add(newType); return newType; }
@Override public String toString(HumanNameDt name) { StringBuilder sb = new StringBuilder(); append(sb, name.getPrefix()); append(sb, name.getFamily()); sb.append(","); append(sb, name.getGiven()); append(sb, name.getSuffix()); return sb.toString(); }
@Override public void buildQuery(PractitionerSearchCriteria criteria, IQuery<Bundle> query) { super.buildQuery(criteria, query); if (criteria.getDEA() != null) { query.where(Practitioner.IDENTIFIER.exactly().identifier(criteria.getDEA())); } if (criteria.getSSN() != null) { query.where(Practitioner.IDENTIFIER.exactly().identifier(criteria.getSSN())); } if (criteria.getGender() != null) { query.where(Practitioner.GENDER.exactly().code(criteria.getGender())); } if (criteria.getName() != null) { HumanNameDt name = criteria.getName(); if (!name.getFamily().isEmpty()) { query.where(Practitioner.FAMILY.matches().values(FhirUtil.toStringList(name.getFamily()))); } if (!name.getGiven().isEmpty()) { query.where(Practitioner.GIVEN.matches().values(FhirUtil.toStringList(name.getGiven()))); } } }
@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(); }
@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()); }