hapifhir / hapi-fhir

🔥 HAPI FHIR - Java API for HL7 FHIR Clients and Servers
http://hapifhir.io
Apache License 2.0
2.04k stars 1.33k forks source link

Issue in parsing json string in hapi-fhir-validation library #5744

Open indusankar89 opened 8 months ago

indusankar89 commented 8 months ago

Describe the bug This is in continuation with issue - https://github.com/hapifhir/hapi-fhir/issues/5727 (Raising new issue as I am unable to reopen it) I used to pass object of Patient class which would have caused the warning to be lost.

Now I am trying to use raw string itself, but getting another issue. Pasting the code here:

        FhirContext ctx = FhirContext.forR4();
        FhirValidator validator = ctx.newValidator();
        String test = """
                {
                  "resourceType": "Patient",
                  "id": "123345",
                  "meta": {
                           "profile": [{"uri" :"xxxxx"}]  //uri of fhir profile
                      },
                  "identifier": [
                    {
                      "system": "urn:oid:2.16.840.1.113883.19.5",
                      "value": "12345"
                    }
                  ],
                  "active": true                      
                """;
        ValidationResult validationResult = validator.validateWithResult(test);

Issue log:

    java.lang.UnsupportedOperationException: JsonObject
at com.google.gson.JsonElement.getAsString(JsonElement.java:187)
at org.hl7.fhir.common.hapi.validation.validator.ValidatorWrapper.validate(ValidatorWrapper.java:184)
at org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator.validate(FhirInstanceValidator.java:239)
at org.hl7.fhir.common.hapi.validation.validator.BaseValidatorBridge.doValidate(BaseValidatorBridge.java:23)
at org.hl7.fhir.common.hapi.validation.validator.BaseValidatorBridge.validateResource(BaseValidatorBridge.java:59)
at org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator.validateResource(FhirInstanceValidator.java:27)
at ca.uhn.fhir.validation.FhirValidator.validateResource(FhirValidator.java:357)
at ca.uhn.fhir.validation.FhirValidator.doValidate(FhirValidator.java:273)
at ca.uhn.fhir.validation.FhirValidator.validateWithResult(FhirValidator.java:241)
at ca.uhn.fhir.validation.FhirValidator.validateWithResult(FhirValidator.java:224)

To Reproduce validate payload with java hapi-fhir-validation library's validateWithResult method by passing a patient payload in json format.

Environment -library used: implementation group: 'ca.uhn.hapi.fhir', name: 'hapi-fhir-validation', version: '6.10.2'

indusankar89 commented 8 months ago

@jamesagnew please suggest what can be done to fix this issue.