Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResourceFingerprintVisitor fails to account for integer values #3616

Closed
lmsurpre opened this issue May 3, 2022 · 2 comments
Closed

ResourceFingerprintVisitor fails to account for integer values #3616

lmsurpre opened this issue May 3, 2022 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@lmsurpre
Copy link
Member

lmsurpre commented May 3, 2022

Describe the bug
I found that the ResourceFingerprintVisitor is failing to add integer values to its digest.

Environment
main

To Reproduce

    @Test
    public void testUnequalResources_intVals() throws Exception {
        Patient patient = TestUtil.getMinimalResource(Patient.class).toBuilder()
                .multipleBirth(1)
                .build();

        ResourceFingerprintVisitor resourceFingerprintVisitor = new ResourceFingerprintVisitor();
        patient.accept(resourceFingerprintVisitor);
        SaltHash baseline = resourceFingerprintVisitor.getSaltAndHash();

        patient = patient.toBuilder()
                .multipleBirth(2)
                .build();
        resourceFingerprintVisitor = new ResourceFingerprintVisitor(baseline);
        patient.accept(resourceFingerprintVisitor);
        assertNotEquals(resourceFingerprintVisitor.getSaltAndHash(), baseline);
    }

Expected behavior
the test should succeed

Additional context
does the ByteBuffer need to get flipped before we add it to the digest?

    @Override
    public void visit(java.lang.String elementName, java.lang.Integer value) {
        ByteBuffer bb = ByteBuffer.allocate(4);
        bb.putInt(value);
        // flip here?
        digest.update(bb);
    }
@lmsurpre lmsurpre added the bug Something isn't working label May 3, 2022
@lmsurpre lmsurpre changed the title ResourceFingerprinter fails to account for integer values ResourceFingerprintVisitor fails to account for integer values May 3, 2022
@lmsurpre lmsurpre self-assigned this May 3, 2022
lmsurpre added a commit that referenced this issue May 3, 2022
lmsurpre added a commit that referenced this issue May 3, 2022
lmsurpre added a commit that referenced this issue May 4, 2022
issue #3616 - flip the bytebuffer before we use it to update the digest
@punktilious
Copy link
Collaborator

punktilious commented Aug 7, 2022

Defined a new extension search parameter:

{
    "resourceType": "Bundle",
    "type": "collection",
    "entry": [
                    {
                "fullUrl": "http://ibm.com/fhir/SearchParameter/Basic-favorite-number",
                "resource": {
                        "resourceType": "SearchParameter",
                        "id": "Basic-favorite-number",
                        "url": "http://ibm.com/fhir/SearchParameter/Basic-favorite-number",
                        "version": "4.0.0",
                        "name": "favorite-number",
                        "status": "draft",
                        "experimental": false,
                        "date": "2018-12-27T22:37:54+11:00",
                        "publisher": "IBM FHIR Server Test",
                        "contact": [{
                                "telecom": [{
                                        "system": "url",
                                        "value": "http://ibm.com/fhir"
                                }]
                        },
                        {
                                "telecom": [{
                                        "system": "url",
                                        "value": "http://ibm.com/fhir"
                                }]
                        }],
                        "description": "the patient's favorite number",
                        "code": "favorite-number",
                        "base": ["Basic"],
                        "type": "number",
                        "xpathUsage": "normal",
                        "xpath": "f:Basic/f:extension[@url='http://ibm.com/fhir/extension/Basic/favorite-number']/f:valueInteger",
                        "expression": "Basic.extension.where(url='http://ibm.com/fhir/extension/Basic/favorite-number').value.as(Integer)",
                        "multipleOr": true,
                        "multipleAnd": true,
                        "modifier": []
                }
        }
    ]
}

Create an instance of the resource:

{
  "resourceType": "Basic",
  "id": "basic1",
  "code": {
    "text": "test"
  },
  "extension": [
    {
      "url": "http://ibm.com/fhir/extension/Basic/favorite-number",
      "valueInteger": 12
    },
    {
      "url": "http://ibm.com/fhir/extension/Basic/favorite-decimal",
      "valueDecimal": 99.99
    },
    {
      "url": "http://ibm.com/fhir/extension/Basic/favorite-boolean",
      "valueBoolean": true
    },
    {
      "url": "http://ibm.com/fhir/extension/Basic/favorite-precision",
      "valueDecimal": 100.25
    }
  ]
}

Inspect the database to see the current parameter_hash value:

fhirdb=> select * from fhirdata.logical_resources where logical_id = 'basic1';
fhirdb=> select * from fhirdata.logical_resources where logical_id = 'basic1';
 logical_resource_id | resource_type_id | logical_id |   reindex_tstamp    | reindex_txid |        last_updated        | is_deleted |                parameter_hash                
---------------------+------------------+------------+---------------------+--------------+----------------------------+------------+----------------------------------------------
            85745130 |                8 | basic1     | 1970-01-01 00:00:00 |            0 | 2022-08-07 21:44:31.124855 | N          | L47pUAnksDJO9VVp8Ey00DP1gFgoMqzdfNdcOvYI0zQ=

And the stored search parameter value should be 12

fhirdb=> select * from fhirdata.basic_number_values where logical_resource_id = 85745130;
 parameter_name_id | number_value | logical_resource_id | number_value_low | number_value_high | composite_id 
-------------------+--------------+---------------------+------------------+-------------------+--------------
            239000 |           12 |            85745130 |               12 |                12 |             

Next UPDATE the resource using a different integer value then inspect the database:

fhirdb=> select * from fhirdata.logical_resources where logical_id = 'basic1';
 logical_resource_id | resource_type_id | logical_id |   reindex_tstamp    | reindex_txid |        last_updated        | is_deleted |                parameter_hash                
---------------------+------------------+------------+---------------------+--------------+----------------------------+------------+----------------------------------------------
            85745130 |                8 | basic1     | 1970-01-01 00:00:00 |            0 | 2022-08-07 21:45:15.992466 | N          | z2jgGWiFiBTOFTV94cJlUTxSksI4T2zhJlfU0PdqKao=
(1 row)

fhirdb=> select * from fhirdata.basic_number_values where logical_resource_id = 85745130;
 parameter_name_id | number_value | logical_resource_id | number_value_low | number_value_high | composite_id 
-------------------+--------------+---------------------+------------------+-------------------+--------------
            239000 |           42 |            85745130 |               42 |                42 |             

Note the new value is stored and the parameter_hash is different, as expected.

@punktilious
Copy link
Collaborator

Reviewed above with Lee and agreed we can close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants