public org.hl7.fhir.instance.model.Patient convertPatient(org.hl7.fhir.dstu3.model.Patient src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.instance.model.Patient tgt = new org.hl7.fhir.instance.model.Patient(); copyDomainResource(src, tgt); for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(convertIdentifier(t)); tgt.setActive(src.getActive()); for (org.hl7.fhir.dstu3.model.HumanName t : src.getName()) tgt.addName(convertHumanName(t)); for (org.hl7.fhir.dstu3.model.ContactPoint t : src.getTelecom()) tgt.addTelecom(convertContactPoint(t)); tgt.setGender(convertAdministrativeGender(src.getGender())); tgt.setBirthDate(src.getBirthDate()); tgt.setDeceased(convertType(src.getDeceased())); for (org.hl7.fhir.dstu3.model.Address t : src.getAddress()) tgt.addAddress(convertAddress(t)); tgt.setMaritalStatus(convertCodeableConcept(src.getMaritalStatus())); tgt.setMultipleBirth(convertType(src.getMultipleBirth())); for (org.hl7.fhir.dstu3.model.Attachment t : src.getPhoto()) tgt.addPhoto(convertAttachment(t)); for (org.hl7.fhir.dstu3.model.Patient.ContactComponent t : src.getContact()) tgt.addContact(convertContactComponent(t)); tgt.setAnimal(convertAnimalComponent(src.getAnimal())); for (org.hl7.fhir.dstu3.model.Patient.PatientCommunicationComponent t : src.getCommunication()) tgt.addCommunication(convertPatientCommunicationComponent(t)); for (org.hl7.fhir.dstu3.model.Reference t : src.getGeneralPractitioner()) tgt.addCareProvider(convertReference(t)); tgt.setManagingOrganization(convertReference(src.getManagingOrganization())); for (org.hl7.fhir.dstu3.model.Patient.PatientLinkComponent t : src.getLink())
Patient p = new Patient(); p.addName().setFamily("Smith").addGiven("John").addGiven("Q"); p.addIdentifier().setSystem("urn:foo:identifiers").setValue("12345"); p.addTelecom().setSystem(ContactPointSystem.PHONE).setValue("416 123-4567");
@Create public MethodOutcome createPatient(@ResourceParam Patient patient) { patient.setId(createId(counter, 1L)); patients.put(String.valueOf(counter), patient); return new MethodOutcome(patient.getIdElement()); }
@Read() public Patient readPatient(@IdParam IdType theId) { Patient retVal = new Patient(); // ..populate demographics, contact, or anything else you usually would.. // Populate some tags retVal.getMeta().addTag("http://animals", "Dog", "Canine Patient"); // TODO: more realistic example retVal.getMeta().addTag("http://personality", "Friendly", "Friendly"); // TODO: more realistic example return retVal; } //END SNIPPET: readTags
switch (hash) { case -1618432855: // identifier this.getIdentifier().add(castToIdentifier(value)); // Identifier return value; case -1422950650: // active this.active = castToBoolean(value); // BooleanType return value; case 3373707: // name this.getName().add(castToHumanName(value)); // HumanName return value; case -1429363305: // telecom this.getTelecom().add(castToContactPoint(value)); // ContactPoint return value; case -1249512767: // gender value = new AdministrativeGenderEnumFactory().fromType(castToCode(value)); this.gender = (Enumeration) value; // Enumeration<AdministrativeGender> return value; case -1210031859: // birthDate this.birthDate = castToDate(value); // DateType return value; case 561497972: // deceased this.deceased = castToType(value); // Type return value; case -1147692044: // address this.getAddress().add(castToAddress(value)); // Address return value; case 1756919302: // maritalStatus this.maritalStatus = castToCodeableConcept(value); // CodeableConcept return value;
public org.hl7.fhir.dstu3.model.Patient convertPatient(org.hl7.fhir.instance.model.Patient src) throws FHIRException { if (src == null || src.isEmpty()) return null; org.hl7.fhir.dstu3.model.Patient tgt = new org.hl7.fhir.dstu3.model.Patient(); copyDomainResource(src, tgt); for (org.hl7.fhir.instance.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(convertIdentifier(t)); tgt.setActive(src.getActive()); for (org.hl7.fhir.instance.model.HumanName t : src.getName()) tgt.addName(convertHumanName(t)); for (org.hl7.fhir.instance.model.ContactPoint t : src.getTelecom()) tgt.addTelecom(convertContactPoint(t)); tgt.setGender(convertAdministrativeGender(src.getGender())); tgt.setBirthDate(src.getBirthDate()); tgt.setDeceased(convertType(src.getDeceased())); for (org.hl7.fhir.instance.model.Address t : src.getAddress()) tgt.addAddress(convertAddress(t)); tgt.setMaritalStatus(convertCodeableConcept(src.getMaritalStatus())); tgt.setMultipleBirth(convertType(src.getMultipleBirth())); for (org.hl7.fhir.instance.model.Attachment t : src.getPhoto()) tgt.addPhoto(convertAttachment(t)); for (org.hl7.fhir.instance.model.Patient.ContactComponent t : src.getContact()) tgt.addContact(convertContactComponent(t)); tgt.setAnimal(convertAnimalComponent(src.getAnimal())); for (org.hl7.fhir.instance.model.Patient.PatientCommunicationComponent t : src.getCommunication()) tgt.addCommunication(convertPatientCommunicationComponent(t)); for (org.hl7.fhir.instance.model.Reference t : src.getCareProvider()) tgt.addGeneralPractitioner(convertReference(t)); tgt.setManagingOrganization(convertReference(src.getManagingOrganization())); for (org.hl7.fhir.instance.model.Patient.PatientLinkComponent t : src.getLink())
pat.getIdentifier().add(convert.makeIdentifierFromII(e)); pat.getAddress().add(convert.makeAddressFromAD(e)); for (Element e : cda.getChildren(pr, "telecom")) pat.getTelecom().add(convert.makeContactFromTEL(e)); for (Element e : cda.getChildren(p, "name")) pat.getName().add(convert.makeNameFromEN(e)); pat.setGender(convert.makeGenderFromCD(cda.getChild(p, "administrativeGenderCode"))); pat.setBirthDateElement(convert.makeDateFromTS(cda.getChild(p, "birthTime"))); pat.setMaritalStatus(convert.makeCodeableConceptFromCD(cda.getChild(p, "maritalStatusCode"))); pat.getExtension().add(Factory.newExtension(CcdaExtensions.NAME_RELIGION, convert.makeCodeableConceptFromCD(cda.getChild(p, "religiousAffiliationCode")), false)); pat.getExtension().add(Factory.newExtension(CcdaExtensions.DAF_NAME_RACE, convert.makeCodeableConceptFromCD(cda.getChild(p, "raceCode")), false)); pat.getExtension().add(Factory.newExtension(CcdaExtensions.DAF_NAME_ETHNICITY, convert.makeCodeableConceptFromCD(cda.getChild(p, "ethnicGroupCode")), false)); pat.getExtension().add(Factory.newExtension(CcdaExtensions.NAME_BIRTHPLACE, convert.makeAddressFromAD(cda.getChild(p, new String[] {"birthplace", "place", "addr"})), false)); pat.getContact().add(guardian); guardian.getRelationship().add(Factory.newCodeableConcept("GUARD", "urn:oid:2.16.840.1.113883.5.110", "guardian")); Element g = cda.getChild(p, "guardian"); c.setCode(cda.getChild(l, "languageCode").getAttribute("code")); cc.getCoding().add(c); pat.addCommunication().setLanguage(cc); pat.getExtension().add(Factory.newExtension(CcdaExtensions.NAME_RELIGION, convert.makeCodeableConceptFromCD(cda.getChild(p, "religiousAffiliationCode")), false)); pat.setManagingOrganization(Factory.makeReference(makeOrganization(cda.getChild(pr, "providerOrganization"), "Provider"))); return addReference(pat, "Subject", makeUUIDReference());
/** * Retrieves a formatted header for the current patient. * * @return Formatted header. */ public String getPatientInfo() { Patient patient = PatientContext.getActivePatient(); String text; if (patient == null) { text = "No Patient Selected"; } else { Identifier mrn = FhirUtil.getMRN(patient); // May be null! text = FhirUtil.formatName(patient.getName()); if (mrn != null) { text += " #" + mrn.getValue(); } String gender = patient.hasGender() ? patient.getGender().getDisplay() : ""; if (!StringUtils.isEmpty(gender)) { text += " (" + gender + ")"; } Date deceased = patient.getDeceased() instanceof DateType ? ((DateType) patient.getDeceased()).getValue() : null; String age = DateUtil.formatAge(patient.getBirthDate(), true, deceased); text += " Age: " + age; if (deceased != null) { text += " Died: " + DateUtil.formatDate(deceased); } } return text; }
@Read(version=true) public Patient readOrVread(@IdParam IdType theId) { Patient retVal = new Patient(); if (theId.hasVersionIdPart()) { // this is a vread } else { // this is a read } // ...populate... return retVal; } //END SNIPPET: vread
@Override public Base makeProperty(int hash, String name) throws FHIRException { switch (hash) { case -1618432855: return addIdentifier(); case -1422950650: return getActiveElement(); case 3373707: return addName(); case -1429363305: return addTelecom(); case -1249512767: return getGenderElement(); case -1210031859: return getBirthDateElement(); case -1311442804: return getDeceased(); case 561497972: return getDeceased(); case -1147692044: return addAddress(); case 1756919302: return getMaritalStatus(); case -1764672111: return getMultipleBirth(); case -677369713: return getMultipleBirth(); case 106642994: return addPhoto(); case 951526432: return addContact(); case -1413116420: return getAnimal(); case -1035284522: return addCommunication(); case 1488292898: return addGeneralPractitioner(); case -2058947787: return getManagingOrganization(); case 3321850: return addLink(); default: return super.makeProperty(hash, name); } }
for (HumanName name : patient.getName()) { for (Identifier id : patient.getIdentifier()) { if (needsHeader) { needsHeader = false; for (PatientCommunicationComponent comm : patient.getCommunication()) { if (needsHeader) { needsHeader = false; List<ContactPoint> telecoms = new ArrayList<>(patient.getTelecom()); Collections.sort(telecoms, new Comparator<ContactPoint>() { for (Address address : patient.getAddress()) { if (needsHeader) { needsHeader = false;
Image photo = new Image(); photo.setStyles("max-height:300px;max-width:300px;padding-bottom:10px"); photo.setSrc(Util.getImage(patient.getPhoto(), Util.SILHOUETTE_IMAGE).getSrc()); root.addChild(photo); addDemographic(root, null, FhirUtil.formatName(patient.getName()), "font-weight: bold"); addDemographic(root, "mrn", FhirUtil.getMRNString(patient)); addDemographic(root, "gender", patient.getGender()); addDemographic(root, "age", DateUtil.formatAge(patient.getBirthDate())); addDemographic(root, "dob", patient.getBirthDate()); addDemographic(root, "dod", patient.getDeceased()); addDemographic(root, "language", patient.getLanguage()); addContact(root, patient.getTelecom(), "home:phone", null); addContact(root, patient.getTelecom(), "home:email", null); addContact(root, patient.getTelecom(), "home:fax", "home fax"); addContact(root, patient.getTelecom(), "work:phone", null); addContact(root, patient.getTelecom(), "work:email", null); addContact(root, patient.getTelecom(), "work:fax", "work fax"); Address address = FhirUtil.getAddress(patient.getAddress(), AddressUse.HOME);
@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
HumanNameParser hnp = new HumanNameParser(); changeUserContext(); Patient patient1 = new Patient(); patient1.setId("321"); patient1.getName().add(hnp.fromString(null, "Smith, Joe")); Identifier ssn = new Identifier(); ssn.setType(FhirTerminology.IDENT_SSN); ssn.setValue("999-99-9999"); patient1.getIdentifier().add(ssn); patient1.setBirthDate(DateUtil.parseDate("1958-07-27")); Patient patient2 = new Patient(); patient2.setId("123"); patient2.getName().add(hnp.fromString(null, "Doe, Jane")); Identifier ssn2 = new Identifier(); ssn2.setType(FhirTerminology.IDENT_SSN); ssn2.setValue("123-45-6789"); patient2.getIdentifier().add(ssn2); patient2.setBirthDate(DateUtil.parseDate("1963-05-01")); Object subscriber = new ContextChangeSubscriber(); // Create a patient context change subscriber
Patient patient = new Patient(); patient.addIdentifier().setUse(IdentifierUse.OFFICIAL).setSystem("urn:example").setValue("7000135"); patient.addExtension(ext); HumanName name = patient.addName(); name.setFamily("Shmoe"); List<Extension> resourceExts = patient.getExtensionsByUrl("http://fooextensions.com#exts"); List<Extension> nonModExts = patient.getExtension(); List<Extension> modExts = patient.getModifierExtension();
public static void main(String[] theArgs) { // Create a resource instance Patient pat = new Patient(); // Add a "name" element HumanName name = pat.addName(); name.setFamily("Simpson").addGiven("Homer").addGiven("J"); // Add an "identifier" element Identifier identifier = pat.addIdentifier(); identifier.setSystem("http://acme.org/MRNs").setValue("7000135"); // Model is designed to be chained pat.addIdentifier().setSystem("http://acme.org/MRNs").setValue("12345"); } }
@Override public Base addChild(String name) throws FHIRException { if (name.equals("identifier")) { return addIdentifier(); return addName(); return addTelecom(); return addAddress(); return addPhoto(); return addContact(); return addCommunication(); return addGeneralPractitioner(); return addLink();
@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
public void clientRead() { //START SNIPPET: clientReadTags IPatientClient client = FhirContext.forDstu2().newRestfulClient(IPatientClient.class, "http://foo/fhir"); Patient patient = client.readPatient(new IdType("1234")); // Access the tag list List<Coding> tagList = patient.getMeta().getTag(); for (Coding next : tagList) { // ..process the tags somehow.. } //END SNIPPET: clientReadTags //START SNIPPET: clientCreateTags Patient newPatient = new Patient(); // Populate the resource object newPatient.addIdentifier().setUse(IdentifierUse.OFFICIAL).setValue("123"); newPatient.addName().setFamily("Jones").addGiven("Frank"); // Populate some tags newPatient.getMeta().addTag("http://animals", "Dog", "Canine Patient"); // TODO: more realistic example newPatient.getMeta().addTag("http://personality", "Friendly", "Friendly"); // TODO: more realistic example // ...invoke the create method on the client... //END SNIPPET: clientCreateTags }