Verticon
Verticon

Reputation: 2513

How Can I Access A Patient's Id?

Please have a look at the following Patient response that I received from http://fhirtest.uhn.ca/baseDstu3. I would like to access the 4081340 value in the id tag but I have been unable to find it in the org.hl7.fhir.dstu3.model.Patient API. Would someone please show me how?

<Patient xmlns="http://hl7.org/fhir">
    <id value="4081340"></id>
    <meta>
        <versionId value="1"></versionId>
        <lastUpdated value="2018-06-04T15:13:28.069+00:00"></lastUpdated>
    </meta>
    <text>
        <status value="generated"></status>
        <div xmlns="http://www.w3.org/1999/xhtml">
     <div class="hapiHeaderText">Robert Jozef 
        <b>VAESSEN </b>
     </div>
     <table class="hapiPropertyTable">
        <tbody>
           <tr>
              <td>Identifier</td>
              <td>12345</td>
           </tr>
           <tr>
              <td>Date of birth</td>
              <td>
                 <span>30 January 1954</span>
              </td>
           </tr>
        </tbody>
     </table>
  </div>
</text>
<identifier>
  <system value="http://dmw.levy.com/mrn"></system>
  <value value="12345"></value>
</identifier>
<name>
  <family value="Vaessen"></family>
  <given value="Robert"></given>
  <given value="Jozef"></given>
</name>
<gender value="male"></gender>
<birthDate value="1954-01-30"></birthDate>
</Patient>

Update:

The reason that I want to access the 4081340 value is that I need it in order to execute code such as this:

private void deletePatient(String id) {
    try {
        OperationOutcome outcome = (OperationOutcome) client.delete().resourceById(new IdDt("Patient", id)).execute();
    }
    catch (Exception e) {
        System.out.printf("Cannot delete patient with id = %s\n%s\n", id, e.getMessage());
    }
}

private void retrievePatient(String id) {
    try {
        Patient patient = client.read().resource(Patient.class).withId(id).execute();
        String description = parser.encodeResourceToString(patient); 
        System.out.printf("Successfully retrieved patient with ID = %s:\n%s\n", id, description);
    }
    catch (ResourceNotFoundException e) {
        System.out.printf("Cannot find patient with id = %s\n", id);
    }
}

The following statements all print http://hapi.fhir.org/baseDstu3/Patient/4081340/_history/1. I could parse that to obtain the 4081340

System.out.printf("\t%s\n", patient.getId());
System.out.printf("\t%s\n", patient.getIdBase());
System.out.printf("\t%s\n", patient.getIdElement());

When I examine a Patient in the debugger, I can see the value in the field myUnqualifiedId but I cannot discover how to get at it.

enter image description here

Upvotes: 2

Views: 1809

Answers (1)

Verticon
Verticon

Reputation: 2513

I found it:

patient.getIdElement().getIdPart()

Upvotes: 2

Related Questions