Repository: hapifhir/org.hl7.fhir.core
Issue: maxValue contraint on decimal values is ignored and doesn't produce errors

### Problem description

It seems, that the validator doesn't evaluate the maxValue constraint for decimal data types in profiles (**maxValueDecimal**). If the constraint is violated, no errors are produced. The following minimal example ([MedicationRequestWithDispenseRequestQuantityLimit.zip](https://github.com/hapifhir/org.hl7.fhir.core/files/9888003/MedicationRequestWithDispenseRequestQuantityLimit.zip)) demonstrates the behavior (take notice of the profile constraint maxValueDecimal = 999 and the actual value of 1000):

#### Profile
`{
  "resourceType": "StructureDefinition",
  "id": "MedicationRequestWithDispenseRequestQuantityLimit",
  "extension": [
    {
      "url": "http://hl7.org/fhir/StructureDefinition/structuredefinition-category",
      "valueString": "Clinical.Medications"
    },
    {
      "url": "http://hl7.org/fhir/StructureDefinition/structuredefinition-security-category",
      "valueCode": "patient"
    }
  ],
  "url": "http://example.org/StructureDefinition/MedicationRequestWithDispenseRequestQuantityLimit",
  "version": "1.0.0",
  "name": "MedicationRequestWithDispenseRequestQuantityLimit",
  "title": "Example of MedicationRequest profile for demonstration of HL7 Java Validator Bug with maxValueDecimal-Evaluation",
  "status": "active",
  "description": "Validator doesn't throw any errors for instances with MedicationRequest.dispenseRequest.quantity.value > specified maxValueDecimal",
  "fhirVersion": "4.0.1",
  "mapping": [
    {
      "identity": "workflow",
      "uri": "http://hl7.org/fhir/workflow",
      "name": "Workflow Pattern"
    },
    {
      "identity": "script10.6",
      "uri": "http://ncpdp.org/SCRIPT10_6",
      "name": "Mapping to NCPDP SCRIPT 10.6"
    },
    {
      "identity": "rim",
      "uri": "http://hl7.org/v3",
      "name": "RIM Mapping"
    },
    {
      "identity": "w5",
      "uri": "http://hl7.org/fhir/fivews",
      "name": "FiveWs Pattern Mapping"
    },
    {
      "identity": "v2",
      "uri": "http://hl7.org/v2",
      "name": "HL7 v2 Mapping"
    }
  ],
  "kind": "resource",
  "abstract": false,
  "type": "MedicationRequest",
  "baseDefinition": "http://hl7.org/fhir/StructureDefinition/MedicationRequest",
  "derivation": "constraint",
  "differential": {
    "element": [
      {
        "id": "MedicationRequest.dispenseRequest",
        "path": "MedicationRequest.dispenseRequest",
        "min": 1,
        "mustSupport": true
      },
      {
        "id": "MedicationRequest.dispenseRequest.quantity",
        "path": "MedicationRequest.dispenseRequest.quantity",
        "min": 1,
        "mustSupport": true
      },
      {
        "id": "MedicationRequest.dispenseRequest.quantity.value",
        "path": "MedicationRequest.dispenseRequest.quantity.value",
        "min": 1,
        "maxValueDecimal": 999,
        "mustSupport": true
      }
    ]
  }
}`

#### Instance
`<MedicationRequest xmlns="http://hl7.org/fhir">
    <id value="medrx0304" />
    <meta>
        <profile value="http://example.org/StructureDefinition/MedicationRequestWithDispenseRequestQuantityLimit" />
    </meta>
    <contained>
        <Medication>
            <id value="med0312" />
            <code>
                <coding>
                    <system value="http://snomed.info/sct" />
                    <code value="324689003" />
                    <display value="Nystatin 100000 unit/mL oral suspension" />
                </coding>
            </code>
        </Medication>
    </contained>
    <status value="completed" />
    <intent value="order" />
    <medicationReference>
        <reference value="#med0312" />
        <display value="Nystatin 100,000 u/ml oral suspension" />
    </medicationReference>
    <subject>
        <reference value="http://example.org/Patient/pat1" />
        <display value="Donald Duck" />
    </subject>
    <authoredOn value="2015-01-15" />
    <dispenseRequest>
        <quantity>
            <value value="1000" />
        </quantity>
    </dispenseRequest>
</MedicationRequest>`

#### Call to validator
`java -jar .\\validator_cli.jar .\\MedicationRequest.xml -ig .\\StructureDefinition-MedicationRequestWithDispenseRequestQuantityLimit.json -profile http://example.org/StructureDefinition/MedicationRequestWithDispenseRequestQuantityLimit`

#### Output

> FHIR Validation tool Version 5.6.74 (Git# 325fd0736d48). Built 2022-10-25T09:35:43.821Z (3 days old)
>   Java:   11.0.14.1 from C:\\Program Files\\OpenJDK\\openjdk-11.0.14.1_1 on amd64 (64bit). 8136MB available
> 
> WARNING: Default file encoding is windows-1252 which may cause unexpected results.
>          To fix this issue, run this program with the parameter '-Dfile.encoding=UTF-8'
>          Future releases may not be able to run at all with encoding windows-1252
> 
>   Paths:  Current = C:\\Dev\\fhir validator, Package Cache = C:\\Users\\...\\.fhir\\packages
>   Params: .\\MedicationRequest.xml -ig .\\StructureDefinition-MedicationRequestWithDispenseRequestQuantityLimit.json -profile http://example.org/StructureDefinition/MedicationRequestWithDispenseRequestQuantityLimit
> Scanning for versions (no -version parameter):
>   fhirVersion in .\\StructureDefinition-MedicationRequestWithDispenseRequestQuantityLimit.json: 4.0
> -> use version 4.0
>   Jurisdiction: No Jurisdiction
> Loading
>   Load FHIR v4.0 from hl7.fhir.r4.core#4.0.1  Load hl7.terminology.r4#4.0.0 - 4164 resources (00:04.884)
>  - 7383 resources (00:00.000)
>   Load hl7.terminology#4.0.0 - 4164 resources (00:00.724)
>   Load R5 Extensions - 123 resources (00:06.213)
>   Terminology server http://tx.fhir.org - Version 2.0.14 (00:01.082)
>   Load .\\StructureDefinition-MedicationRequestWithDispenseRequestQuantityLimit.json - 1 resources (00:00.002)
>   Get set...  go (00:00.014)
> Validating
>   Profiles: [http://example.org/StructureDefinition/MedicationRequestWithDispenseRequestQuantityLimit]
>   Validate .\\MedicationRequest.xml
> Validate MedicationRequest against http://example.org/StructureDefinition/MedicationRequestWithDispenseRequestQuantityLimit..........20..........40..........60..........80.........|
>  00:00.405
> Done. Times: Loading: 00:13.215, validation: 00:00.405. Memory = 526Mb
> 
> Success: 0 errors, 0 warnings, 1 notes
>   Information: All OK

#### Expected output

> *FAILURE*: 1 errors, 0 warnings, 0 notes
>   Error @ MedicationRequest.dispenseRequest.quantity.value (line 31, col35): value is greater than permitted maximum value of DecimalType[999]

### Possible fix
The error seems to locate in InstanceValidator:2415 and InstanceValidator:2416 which assume an integer datatype instead of a decimal one. A fix can be:
`ok = rule(errors, IssueType.INVALID, e.line(), e.col(), path, !context.hasMaxValueDecimalType() ||
                !context.getMaxValueDecimalType().hasValue() || checkDecimalMaxValue(v, context.getMaxValueDecimalType().getValue()), I18nConstants.TYPE_SPECIFIC_CHECKS_DT_DECIMAL_GT, (context.hasMaxValueDecimalType() ? context.getMaxValueDecimalType() : "")) && ok;`   


Changed files:
org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java

diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java
index b0f084daa..069635dcc 100644
--- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java
+++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java
@@ -2412,8 +2412,8 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
           warning(errors, IssueType.VALUE, e.line(), e.col(), path, ds != DecimalStatus.RANGE, I18nConstants.TYPE_SPECIFIC_CHECKS_DT_DECIMAL_RANGE, e.primitiveValue());
           try {
             Decimal v = new Decimal(e.getValue());
-            ok = rule(errors, IssueType.INVALID, e.line(), e.col(), path, !context.hasMaxValueIntegerType() || 
-                !context.getMaxValueIntegerType().hasValue() || checkDecimalMaxValue(v, context.getMaxValueDecimalType().getValue()), I18nConstants.TYPE_SPECIFIC_CHECKS_DT_DECIMAL_GT, (context.hasMaxValueIntegerType() ? context.getMaxValueIntegerType() : "")) && ok;
+            ok = rule(errors, IssueType.INVALID, e.line(), e.col(), path, !context.hasMaxValueDecimalType() ||
+                !context.getMaxValueDecimalType().hasValue() || checkDecimalMaxValue(v, context.getMaxValueDecimalType().getValue()), I18nConstants.TYPE_SPECIFIC_CHECKS_DT_DECIMAL_GT, (context.hasMaxValueDecimalType() ? context.getMaxValueDecimalType() : "")) && ok;
             ok = rule(errors, IssueType.INVALID, e.line(), e.col(), path, !context.hasMinValueIntegerType() || 
                 !context.getMinValueIntegerType().hasValue() || checkDecimalMinValue(v, context.getMaxValueDecimalType().getValue()), I18nConstants.TYPE_SPECIFIC_CHECKS_DT_DECIMAL_LT, (context.hasMinValueIntegerType() ? context.getMinValueIntegerType() : "")) && ok;
           } catch (Exception ex) {