@Read() public Patient getResourceById(@IdParam IdType theId) { Patient retVal = new Patient(); // ...populate... retVal.addIdentifier().setSystem("urn:mrns").setValue("12345"); retVal.addName().setFamily("Smith").addGiven("Tester").addGiven("Q"); // ...etc... // if you know the version ID of the resource, you should set it and HAPI will // include it in a Content-Location header retVal.setId(new IdType("Patient", "123", "2")); return retVal; } //END SNIPPET: read
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; }
public org.hl7.fhir.dstu3.model.HumanName convertHumanName(org.hl7.fhir.instance.model.HumanName src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.dstu3.model.HumanName tgt = new org.hl7.fhir.dstu3.model.HumanName(); copyElement(src, tgt); tgt.setUse(convertNameUse(src.getUse())); tgt.setText(src.getText()); for (org.hl7.fhir.instance.model.StringType t : src.getFamily()) tgt.setFamily(t.getValue()); for (org.hl7.fhir.instance.model.StringType t : src.getGiven()) tgt.addGiven(t.getValue()); for (org.hl7.fhir.instance.model.StringType t : src.getPrefix()) tgt.addPrefix(t.getValue()); for (org.hl7.fhir.instance.model.StringType t : src.getSuffix()) tgt.addSuffix(t.getValue()); tgt.setPeriod(convertPeriod(src.getPeriod())); return tgt; }
public HumanName makeNameFromEN(Element e) { if (e == null) return null; HumanName hn = new HumanName(); String use = e.getAttribute("use"); if (use != null) { if (use.equals("L")) hn.setUse(NameUse.USUAL); else if (use.equals("C")) hn.setUse(NameUse.OFFICIAL); else if (use.equals("P") || use.equals("A")) hn.setUse(NameUse.ANONYMOUS); else if (use.equals("TMP")) hn.setUse(NameUse.TEMP); else if (use.equals("BAD")) hn.setUse(NameUse.OLD); String v = n.getTextContent(); if (n.getLocalName().equals("family")) hn.setFamilyElement(makeString(v)); else if (n.getLocalName().equals("given")) hn.getGiven().add(makeString(v)); else if (n.getLocalName().equals("prefix")) hn.getPrefix().add(makeString(v)); else if (n.getLocalName().equals("suffix")) hn.getSuffix().add(makeString(v));
@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()); }
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); } }
/** * @param patientName - * @return fhir human name object for the patient. */ static private HumanName createHumanName( final String patientName ) { final Collection<String> prefixes = Arrays.asList( "Dr. ", "Mr. ", "Mrs. ", "Miss ", "Ms. ", "Sir " ); final HumanName humanName = new HumanName(); humanName.setUse( HumanName.NameUse.USUAL ); String fullName = patientName; for ( String prefix : prefixes ) { if ( patientName.startsWith( prefix ) ) { humanName.addPrefix( prefix ); fullName = patientName.substring( prefix.length() + 1 ); break; } } final int spaceIndex = fullName.indexOf( ' ' ); if ( spaceIndex > 0 ) { humanName.setFamily( fullName.substring( spaceIndex + 1 ) ); humanName.addGiven( fullName.substring( 0, spaceIndex ) ); } else { humanName.addGiven( fullName ); } return humanName; }
@Override public HumanName deserialize(String value) { String pcs[] = value.split("\\" + NAME_DELIM); HumanName result = new HumanName(); int i = 0; if ((value = getComponent(pcs, i++)) != null) { result.setFamily(value); } if ((value = getComponent(pcs, i++)) != null) { result.addGiven(value); } if ((value = getComponent(pcs, i++)) != null) { result.addGiven(value); } if ((value = getComponent(pcs, i++)) != null) { result.addSuffix(value); } if ((value = getComponent(pcs, i++)) != null) { result.addPrefix(value); } if ((value = getComponent(pcs, i++)) != null) { result.addSuffix(value); } if ((value = getComponent(pcs, i++)) != null) { result.getUseElement().setValueAsString(value.toLowerCase()); } return result; }
@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); } }
@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(); }
public HumanName addName() { //3 HumanName t = new HumanName(); if (this.name == null) this.name = new ArrayList<HumanName>(); this.name.add(t); return t; }
/** * 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(); } }
ArrayList<StringType> allNames = new ArrayList<StringType>(); HumanName nextHumanName = (HumanName) nextObject; if (isNotBlank(nextHumanName.getFamily())) { allNames.add(nextHumanName.getFamilyElement()); allNames.addAll(nextHumanName.getGiven()); for (StringType nextName : allNames) { addSearchTerm(theEntity, retVal, nextSpName, nextName.getValue());
@Override public Base makeProperty(int hash, String name) throws FHIRException { switch (hash) { case 116103: return getUseElement(); case 3556653: return getTextElement(); case -1281860764: return getFamilyElement(); case 98367357: return addGivenElement(); case -980110702: return addPrefixElement(); case -891422895: return addSuffixElement(); case -991726143: return getPeriod(); default: return super.makeProperty(hash, name); } }
name.setFamily("Shmoe"); StringType given = name.addGivenElement(); given.setValue("Joe");
@History() public List<Patient> getPatientHistory( @IdParam IdType theId, @Since InstantType theSince, @At DateRangeParam theAt ) { List<Patient> retVal = new ArrayList<Patient>(); Patient patient = new Patient(); patient.addName().setFamily("Smith"); // Set the ID and version patient.setId(theId.withVersion("1")); // ...populate the rest... return retVal; } //END SNIPPET: history
/** /** * Returns all repetitions of {@link #getGiven() given name} as a space separated string * * @see DatatypeUtil#joinStringsSpaceSeparated(List) */ public String getGivenAsSingleString() { return joinStringsSpaceSeparated(getGiven()); }
@Test public void testGetResource() { PdqPatient p = client.read() .resource(PdqPatient.class) .withId("4711") .execute(); assertEquals("Test", p.getName().get(0).getFamily()); assertEquals(String.format("http://localhost:%d/Patient/4711", DEMO_APP_PORT), p.getId()); AbstractMockedAuditMessageQueue sender = getAuditSender(); assertEquals(1, sender.getMessages().size()); AuditMessage event = sender.getMessages().get(0); // Patient ParticipantObjectIdentificationType patient = event.getParticipantObjectIdentifications().get(0); assertEquals(ParticipantObjectTypeCode.Person, patient.getParticipantObjectTypeCode()); assertEquals(ParticipantObjectTypeCodeRole.Patient, patient.getParticipantObjectTypeCodeRole()); assertEquals("Patient/4711", patient.getParticipantObjectID()); }