hn.getPrefix().add(makeString(v)); else if (n.getLocalName().equals("suffix")) hn.getSuffix().add(makeString(v));
private void checkHumanName(List<ValidationMessage> errors, String path, Element focus, HumanName fixed) { checkFixedValue(errors, path + ".use", focus.getNamedChild("use"), fixed.getUseElement(), "use", focus); checkFixedValue(errors, path + ".text", focus.getNamedChild("text"), fixed.getTextElement(), "text", focus); checkFixedValue(errors, path + ".period", focus.getNamedChild("period"), fixed.getPeriod(), "period", focus); List<Element> parts = new ArrayList<Element>(); focus.getNamedChildren("family", parts); if (rule(errors, IssueType.VALUE, focus.line(), focus.col(), path, parts.size() > 0 == fixed.hasFamily(), "Expected " + (fixed.hasFamily() ? "1" : "0") + " but found " + Integer.toString(parts.size()) + " family elements")) { for (int i = 0; i < parts.size(); i++) checkFixedValue(errors, path + ".family", parts.get(i), fixed.getFamilyElement(), "family", focus); } focus.getNamedChildren("given", parts); if (rule(errors, IssueType.VALUE, focus.line(), focus.col(), path, parts.size() == fixed.getGiven().size(), "Expected " + Integer.toString(fixed.getGiven().size()) + " but found " + Integer.toString(parts.size()) + " given elements")) { for (int i = 0; i < parts.size(); i++) checkFixedValue(errors, path + ".given", parts.get(i), fixed.getGiven().get(i), "given", focus); } focus.getNamedChildren("prefix", parts); if (rule(errors, IssueType.VALUE, focus.line(), focus.col(), path, parts.size() == fixed.getPrefix().size(), "Expected " + Integer.toString(fixed.getPrefix().size()) + " but found " + Integer.toString(parts.size()) + " prefix elements")) { for (int i = 0; i < parts.size(); i++) checkFixedValue(errors, path + ".prefix", parts.get(i), fixed.getPrefix().get(i), "prefix", focus); } focus.getNamedChildren("suffix", parts); if (rule(errors, IssueType.VALUE, focus.line(), focus.col(), path, parts.size() == fixed.getSuffix().size(), "Expected " + Integer.toString(fixed.getSuffix().size()) + " but found " + Integer.toString(parts.size()) + " suffix elements")) { for (int i = 0; i < parts.size(); i++) checkFixedValue(errors, path + ".suffix", parts.get(i), fixed.getSuffix().get(i), "suffix", focus); } }
/** * Returns all repetitions of {@link #getSuffix() suffix} as a space separated string * * @see DatatypeUtil#joinStringsSpaceSeparated(List) */ public String getSuffixAsSingleString() { return joinStringsSpaceSeparated(getSuffix()); }
public org.hl7.fhir.instance.model.HumanName convertHumanName(org.hl7.fhir.dstu3.model.HumanName src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.instance.model.HumanName tgt = new org.hl7.fhir.instance.model.HumanName(); copyElement(src, tgt); tgt.setUse(convertNameUse(src.getUse())); tgt.setText(src.getText()); if (src.hasFamily()) tgt.addFamily(src.getFamily()); for (org.hl7.fhir.dstu3.model.StringType t : src.getGiven()) tgt.addGiven(t.getValue()); for (org.hl7.fhir.dstu3.model.StringType t : src.getPrefix()) tgt.addPrefix(t.getValue()); for (org.hl7.fhir.dstu3.model.StringType t : src.getSuffix()) tgt.addSuffix(t.getValue()); tgt.setPeriod(convertPeriod(src.getPeriod())); return tgt; }
public static org.hl7.fhir.dstu2016may.model.HumanName convertHumanName(org.hl7.fhir.dstu3.model.HumanName src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.dstu2016may.model.HumanName tgt = new org.hl7.fhir.dstu2016may.model.HumanName(); copyElement(src, tgt); tgt.setUse(convertNameUse(src.getUse())); if (src.hasText()) tgt.setText(src.getText()); if (src.hasFamily()) tgt.addFamily(src.getFamily()); for (org.hl7.fhir.dstu3.model.StringType t : src.getGiven()) tgt.addGiven(t.getValue()); for (org.hl7.fhir.dstu3.model.StringType t : src.getPrefix()) tgt.addPrefix(t.getValue()); for (org.hl7.fhir.dstu3.model.StringType t : src.getSuffix()) tgt.addSuffix(t.getValue()); tgt.setPeriod(convertPeriod(src.getPeriod())); return tgt; }
/** * Returns all of the components of the name (prefix, given, family, suffix) as a single string with a single spaced * string separating each part. * <p> * If none of the parts are populated, returns the {@link #getTextElement() text} element value instead. * </p> */ public String getNameAsSingleString() { List<StringType> nameParts = new ArrayList<StringType>(); nameParts.addAll(getPrefix()); nameParts.addAll(getGiven()); nameParts.add(getFamilyElement()); nameParts.addAll(getSuffix()); if (nameParts.size() > 0) { return joinStringsSpaceSeparated(nameParts); } else { return getTextElement().getValue(); } }
hn.getPrefix().add(makeString(v)); else if (n.getLocalName().equals("suffix")) hn.getSuffix().add(makeString(v));
@Override public Base setProperty(String name, Base value) throws FHIRException { if (name.equals("use")) { value = new NameUseEnumFactory().fromType(castToCode(value)); this.use = (Enumeration) value; // Enumeration<NameUse> } else if (name.equals("text")) { this.text = castToString(value); // StringType } else if (name.equals("family")) { this.family = castToString(value); // StringType } else if (name.equals("given")) { this.getGiven().add(castToString(value)); } else if (name.equals("prefix")) { this.getPrefix().add(castToString(value)); } else if (name.equals("suffix")) { this.getSuffix().add(castToString(value)); } else if (name.equals("period")) { this.period = castToPeriod(value); // Period } else return super.setProperty(name, value); return value; }
private void checkHumanName(List<ValidationMessage> errors, String path, Element focus, HumanName fixed) { checkFixedValue(errors, path + ".use", focus.getNamedChild("use"), fixed.getUseElement(), "use", focus); checkFixedValue(errors, path + ".text", focus.getNamedChild("text"), fixed.getTextElement(), "text", focus); checkFixedValue(errors, path + ".period", focus.getNamedChild("period"), fixed.getPeriod(), "period", focus); List<Element> parts = new ArrayList<Element>(); focus.getNamedChildren("family", parts); if (rule(errors, IssueType.VALUE, focus.line(), focus.col(), path, parts.size() > 0 == fixed.hasFamily(), "Expected " + (fixed.hasFamily() ? "1" : "0") + " but found " + Integer.toString(parts.size()) + " family elements")) { for (int i = 0; i < parts.size(); i++) checkFixedValue(errors, path + ".family", parts.get(i), fixed.getFamilyElement(), "family", focus); } focus.getNamedChildren("given", parts); if (rule(errors, IssueType.VALUE, focus.line(), focus.col(), path, parts.size() == fixed.getGiven().size(), "Expected " + Integer.toString(fixed.getGiven().size()) + " but found " + Integer.toString(parts.size()) + " given elements")) { for (int i = 0; i < parts.size(); i++) checkFixedValue(errors, path + ".given", parts.get(i), fixed.getGiven().get(i), "given", focus); } focus.getNamedChildren("prefix", parts); if (rule(errors, IssueType.VALUE, focus.line(), focus.col(), path, parts.size() == fixed.getPrefix().size(), "Expected " + Integer.toString(fixed.getPrefix().size()) + " but found " + Integer.toString(parts.size()) + " prefix elements")) { for (int i = 0; i < parts.size(); i++) checkFixedValue(errors, path + ".prefix", parts.get(i), fixed.getPrefix().get(i), "prefix", focus); } focus.getNamedChildren("suffix", parts); if (rule(errors, IssueType.VALUE, focus.line(), focus.col(), path, parts.size() == fixed.getSuffix().size(), "Expected " + Integer.toString(fixed.getSuffix().size()) + " but found " + Integer.toString(parts.size()) + " suffix elements")) { for (int i = 0; i < parts.size(); i++) checkFixedValue(errors, path + ".suffix", parts.get(i), fixed.getSuffix().get(i), "suffix", focus); } }
@Override public String serialize(HumanName value) { return value.getFamily() + 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().toCode(); }
@Override public Base setProperty(int hash, String name, Base value) throws FHIRException { switch (hash) { case 116103: // use value = new NameUseEnumFactory().fromType(castToCode(value)); this.use = (Enumeration) value; // Enumeration<NameUse> return value; case 3556653: // text this.text = castToString(value); // StringType return value; case -1281860764: // family this.family = castToString(value); // StringType return value; case 98367357: // given this.getGiven().add(castToString(value)); // StringType return value; case -980110702: // prefix this.getPrefix().add(castToString(value)); // StringType return value; case -891422895: // suffix this.getSuffix().add(castToString(value)); // StringType return value; case -991726143: // period this.period = castToPeriod(value); // Period return value; default: return super.setProperty(hash, name, value); } }
public org.hl7.fhir.instance.model.HumanName convertHumanName(org.hl7.fhir.dstu3.model.HumanName src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.instance.model.HumanName tgt = new org.hl7.fhir.instance.model.HumanName(); copyElement(src, tgt); tgt.setUse(convertNameUse(src.getUse())); tgt.setText(src.getText()); if (src.hasFamily()) tgt.addFamily(src.getFamily()); for (org.hl7.fhir.dstu3.model.StringType t : src.getGiven()) tgt.addGiven(t.getValue()); for (org.hl7.fhir.dstu3.model.StringType t : src.getPrefix()) tgt.addPrefix(t.getValue()); for (org.hl7.fhir.dstu3.model.StringType t : src.getSuffix()) tgt.addSuffix(t.getValue()); tgt.setPeriod(convertPeriod(src.getPeriod())); return tgt; }
@Test public void test() { NameSerializer ns = new NameSerializer(); HumanName name = new HumanName(); name.setFamily("Martin"); name.addGiven("Douglas"); name.addGiven("Kent"); name.addPrefix("Dr."); name.addSuffix("M.D."); name.getUseElement().setValue(NameUse.OFFICIAL); String s = ns.serialize(name); System.out.println(s); HumanName name2 = ns.deserialize(s); assertEquals(name.getFamily(), name2.getFamily()); assertListEquals(name.getGiven(), name2.getGiven()); assertListEquals(name.getPrefix(), name2.getPrefix()); assertListEquals(name.getSuffix(), name2.getSuffix()); assertEquals(name.getUse(), name2.getUse()); }
public static org.hl7.fhir.dstu2016may.model.HumanName convertHumanName(org.hl7.fhir.dstu3.model.HumanName src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.dstu2016may.model.HumanName tgt = new org.hl7.fhir.dstu2016may.model.HumanName(); copyElement(src, tgt); tgt.setUse(convertNameUse(src.getUse())); if (src.hasText()) tgt.setText(src.getText()); if (src.hasFamily()) tgt.addFamily(src.getFamily()); for (org.hl7.fhir.dstu3.model.StringType t : src.getGiven()) tgt.addGiven(t.getValue()); for (org.hl7.fhir.dstu3.model.StringType t : src.getPrefix()) tgt.addPrefix(t.getValue()); for (org.hl7.fhir.dstu3.model.StringType t : src.getSuffix()) tgt.addSuffix(t.getValue()); tgt.setPeriod(convertPeriod(src.getPeriod())); return tgt; }