---
title: "SQL-177: MedicareQueryProvider.FindMedicareHistoryMatch"
summary: Read operation for `MedicareQueryProvider.FindMedicareHistoryMatch`
status: draft
owner: SAIF.Core documentation team
last_reviewed: 2026-09-24
library: SAIF.Data
reference_type: package
---

# SQL-177: MedicareQueryProvider.FindMedicareHistoryMatch

This statement is a read operation invoked through ORM (NHibernate LINQ). Executed by `MedicareQueryProvider.FindMedicareHistoryMatch`.

## Classification

| Field | Value |
| --- | --- |
| **SQL ID** | SQL-177 |
| **Operation type** | Read |
| **Execution method** | ORM (NHibernate LINQ) |
| **Database** | Oracle* |
| **Schema** | [unqualified]** |
| **Command type** | N/A (ORM-generated) |
| **Business object** | `MedicareQueryProvider` |
| **Criteria property** | N/A — ORM |
| **Lifecycle method** | `FindMedicareHistoryMatch` |

## Parameters

| Parameter | Direction | Type | Max length | Description |
| --- | --- | --- | --- | --- |
| `medicareBeneficiary` | Input | MedicareBeneficiaryQuery | N/A | Method argument of `MedicareQueryProvider.FindMedicareHistoryMatch` bound into the ORM expression; NHibernate generates the bind variable at runtime |

## Tables

| Table | Access | Columns used |
| --- | --- | --- |
| [MEDICARE_QUERY_HISTORY](../database-tables.md#medicare_query_history) | SELECT | MEDICARE_QUERY_HISTORY_SEQ_NUM, UPDATE_NUM, CLAIM_PERSON_ID, FIRST_SUBMISSION_DATE, LAST_SUBMISSION_DATE, TAX_ID, LAST_NAME, FIRST_INITIAL, GENDER_CODE, BIRTH_DATE, PRIMARY_TAX_ID_FLAG, MEDICARE_BENEFICIARY_FLAG, RESPONSE_MEDICARE_CLAIM_NUMBER, RESPONSE_TAX_ID, RESPONSE_LAST_NAME, RESPONSE_FIRST_INITIAL, RESPONSE_GENDER_CODE, RESPONSE_BIRTH_DATE, UPDATE_USER, UPDATE_DATE |

## LINQ statement

Source: `Data/SAIF.Data/Queries/Claims/MedicareQueryProvider.cs:30-44`. The repository/queryable is initialised at `Data/SAIF.Data/Queries/Claims/MedicareQueryProvider.cs:19`.

```csharp
// Data/SAIF.Data/Queries/Claims/MedicareQueryProvider.cs:19
medicareHistoryRepository = factory.GetRepository<MedicareQueryHistory>().Query();

// Data/SAIF.Data/Queries/Claims/MedicareQueryProvider.cs:30-44
public MedicareQueryHistory FindMedicareHistoryMatch(MedicareBeneficiaryQuery medicareBeneficiary)
{
        return medicareHistoryRepository.SingleOrDefault(x => x.PersonId == medicareBeneficiary.PersonId
          && x.TaxId == medicareBeneficiary.TaxId
          && x.LastName == medicareBeneficiary.LastName
          && x.FirstInitial == medicareBeneficiary.FirstInitial
          && x.GenderCode == medicareBeneficiary.GenderCode
          && x.BirthDate == medicareBeneficiary.BirthDate
          && x.IsPrimaryTaxId == medicareBeneficiary.IsPrimaryTaxId
          && x.IsMedicareBeneficiary == medicareBeneficiary.IsMedicareBeneficiary
          && x.ResponseMedicareClaimNumber == medicareBeneficiary.ResponseMedicareClaimNumber
          && x.ResponseTaxId == medicareBeneficiary.ResponseTaxId
          && x.ResponseLastName == medicareBeneficiary.ResponseLastName
          && x.ResponseFirstInitial == medicareBeneficiary.ResponseFirstInitial
          && x.ResponseGenderCode == medicareBeneficiary.ResponseGenderCode
          && x.ResponseBirthDate == medicareBeneficiary.ResponseBirthDate
          );
}
```

## Sample SQL

> **Inferred SQL:** This SQL was inferred from the LINQ statement above and the NHibernate mappings. It is not concrete SQL from source code; NHibernate generates the executed statement at runtime, so aliases, column order, join syntax, and bind-parameter names may differ.

```sql
-- Inferred from LINQ (NHibernate mapping translation); not concrete SQL
SELECT
  MQH.MEDICARE_QUERY_HISTORY_SEQ_NUM,
  MQH.UPDATE_NUM,
  MQH.CLAIM_PERSON_ID,
  MQH.FIRST_SUBMISSION_DATE,
  MQH.LAST_SUBMISSION_DATE,
  MQH.TAX_ID,
  MQH.LAST_NAME,
  MQH.FIRST_INITIAL,
  MQH.GENDER_CODE,
  MQH.BIRTH_DATE,
  MQH.PRIMARY_TAX_ID_FLAG,
  MQH.MEDICARE_BENEFICIARY_FLAG,
  MQH.RESPONSE_MEDICARE_CLAIM_NUMBER,
  MQH.RESPONSE_TAX_ID,
  MQH.RESPONSE_LAST_NAME,
  MQH.RESPONSE_FIRST_INITIAL,
  MQH.RESPONSE_GENDER_CODE,
  MQH.RESPONSE_BIRTH_DATE,
  MQH.UPDATE_USER,
  MQH.UPDATE_DATE
FROM MEDICARE_QUERY_HISTORY MQH
WHERE MQH.CLAIM_PERSON_ID = :PersonId
  AND MQH.TAX_ID = :TaxId
  AND MQH.LAST_NAME = :LastName
  AND MQH.FIRST_INITIAL = :FirstInitial
  AND MQH.GENDER_CODE = :GenderCode
  AND MQH.BIRTH_DATE = :BirthDate
  AND MQH.PRIMARY_TAX_ID_FLAG = :IsPrimaryTaxId
  AND MQH.MEDICARE_BENEFICIARY_FLAG = :IsMedicareBeneficiary
  AND MQH.RESPONSE_MEDICARE_CLAIM_NUMBER = :ResponseMedicareClaimNumber
  AND MQH.RESPONSE_TAX_ID = :ResponseTaxId
  AND MQH.RESPONSE_LAST_NAME = :ResponseLastName
  AND MQH.RESPONSE_FIRST_INITIAL = :ResponseFirstInitial
  AND MQH.RESPONSE_GENDER_CODE = :ResponseGenderCode
  AND MQH.RESPONSE_BIRTH_DATE = :ResponseBirthDate
-- SingleOrDefault: NHibernate expects at most one row
```

Translation notes:
- Every right-hand operand is a member of the method argument, not of the lambda parameter, so each one becomes a bind variable.
- `IsPrimaryTaxId`/`IsMedicareBeneficiary` map with `CustomType<YesNoType>()` (`MedicareQueryHistoryMap.cs:22-23`). The bound booleans are converted to `'Y'`/`'N'`.
- `PersonId` maps to `CLAIM_PERSON_ID` in this table (`MedicareQueryHistoryMap.cs:14`), not `PERSON_ID`.
- Nullable operands: equality is shown as `=`. Depending on the NHibernate version, a comparison against a captured null may render as `IS NULL`. Plain `= NULL` would never match, so a history row with null response fields may not be found. Record this as a behavioral caveat, not a mapping fact.

## Operations and processes

- [Other query providers](../operations/other-query-providers.md)

## Business rules

- [SD-BR-095 Medicare history match requires all fields equal](../business-rules.md#sd-br-095-medicare-history-match-requires-all-fields-equal)

## Sources
- `Data/SAIF.Data/Queries/Claims/MedicareQueryProvider.cs:30`
