FHIR Chat · Using Java Validator · implementers

Stream: implementers

Topic: Using Java Validator


view this post on Zulip Mritunjay Dubey (Oct 03 2016 at 04:37):

Hello all,
I was trying to use java-validator to validate profiles. I found an existing one here, https://www.hl7.org/fhir/uslab/uslab-patient.profile.xml.html and an example patient for this profile https://www.hl7.org/fhir/uslab/patient-uslab-example1.xml.html. I downloaded the java-validator and FHIR Definitions as xml from downloads page.

I am running it as below

java -jar org.hl7.fhir.validator.jar example_us_lab_patient.xml -defn validation-min.xml.zip -profile patient-us-lab.profile.xml

below is the result

Validating valid_patient_with_mandatory_fields.xml: 2 messages ERROR @ /f:Patient/f:extension[1] (line 3, col505) Element is unknown or does not match any slice (src = InstanceValidator) ERROR @ /f:Patient/f:extension (line 10, col78) Element is unknown or does not match any slice (src = InstanceValidator) …failure

I am not sure whether I am missing something or the example patient is incorrect. I also want to know how to do the same using java code.

view this post on Zulip Grahame Grieve (Oct 03 2016 at 04:49):

the java question - the validator is also packaged in HAPI - org.hl7.fhir.dstu2.validation.ValidationEngine is the java class that the jar uses to launch the actual validator

view this post on Zulip Grahame Grieve (Oct 03 2016 at 04:50):

I'm not sure why you're getting that error - it looks uncorrect to me

view this post on Zulip Mritunjay Dubey (Oct 03 2016 at 05:14):

hey @Grahame Grieve, thanks for your response. I tried using it in java code. I added downloaded org.hl7.fhir.validator.jar itself as a dependency for my project, but it fails when I say below

view this post on Zulip Mritunjay Dubey (Oct 03 2016 at 05:16):

engine.loadProfile("/Users/mritunjd/Downloads/validator/patient-us-lab.profile.xml");

view this post on Zulip Mritunjay Dubey (Oct 03 2016 at 05:16):

It goes to SimpleWorkerContext and fails saying java.lang.Error: not done yet.

view this post on Zulip Mritunjay Dubey (Oct 03 2016 at 05:17):

Even I tried adding me.fhir:fhir-dstu2:1.0.1.7108 as dependency and do it, but same problem, can you please tell me what can be wrong here ?

view this post on Zulip Grahame Grieve (Oct 03 2016 at 05:54):

You have to refer to the profile by it's url, not it's location

view this post on Zulip Mritunjay Dubey (Oct 03 2016 at 06:12):

okey, I tried changing this with engine.loadProfile("patient-us-lab.profile.xml"), it fails with an error Unable to find named profile (source = patient-us-lab.profile.xml), but if I pass the same from command line it works fine. Is there a way to load the profile from file?

view this post on Zulip Mritunjay Dubey (Oct 03 2016 at 06:15):

if I see the code, there it says if it's a url(i.e. startswith http(s)), load it from url otherwise load it from file.

view this post on Zulip Mritunjay Dubey (Oct 03 2016 at 06:16):

but when I pass it as a profile location, it fails in SimpleWorkerContext.

view this post on Zulip Grahame Grieve (Oct 03 2016 at 06:38):

well, whatever you put in the -profile parameter is passed straight to ValidationEngine.loadprofile()

view this post on Zulip Mritunjay Dubey (Oct 03 2016 at 07:41):

I also thought the same, and passed the same argument (value for -profile option) to loadProfile() method, but seems like there is something missing. What is the recomonnded way to validate against a profile.xml file. Is there a tutorial available for this ?

view this post on Zulip Grahame Grieve (Oct 03 2016 at 10:19):

All we have at the moment is the validation page in the spec. And that doesn't deal with using it in java, but the code for Validator.java is in the fhir svn

view this post on Zulip Mritunjay Dubey (Oct 06 2016 at 03:01):

hey @Grahame Grieve, I cloned the fhir-svn repo, and run the build with sh publish.sh, the build fails saying error: cannot find symbol return StringUtils.equals(getValueAsString(), theString);
I am using it on macos.

view this post on Zulip Mritunjay Dubey (Oct 06 2016 at 03:01):

pasted image

view this post on Zulip Vadim Peretokin (Oct 06 2016 at 03:39):

What does java -version say?

view this post on Zulip Mritunjay Dubey (Oct 06 2016 at 03:53):

java 1.8.0_92

view this post on Zulip Mritunjay Dubey (Oct 06 2016 at 04:19):

Well, I checked out a specific commit 6cc899af2017c3819f5448165434450bced7b047 because I wanted the DSTU2-last, and here it build successfuly.

view this post on Zulip Grahame Grieve (Oct 06 2016 at 04:26):

DSTU2? carumna. that's a problem. why do you want to build

view this post on Zulip Mritunjay Dubey (Oct 06 2016 at 04:28):

As I told above, I was trying to use java-validator jar in my code directly. For some reason it is failing, but I am not able to debug it beacasue I don't have codebase of same version.

view this post on Zulip Mritunjay Dubey (Oct 06 2016 at 04:28):

I thought I will build the jar with DSTU2 version and debug it on same code base, to get an idea of what's going wrong while validation.

view this post on Zulip Grahame Grieve (Oct 06 2016 at 04:29):

hm. well, you don't need to run the build, but ok, you do need to get it compiling. I'll have to figure out what your problem is .....

view this post on Zulip Mritunjay Dubey (Oct 06 2016 at 13:22):

I got it working, thanks for the support, Now I have a different question. In my patient profile I am making patient.name, patient.name.family and patient .name.given as mandatory (i.e. cardinality 1..1).

When I try to validate it gives error for patient.name(when I don't send patient.name, expexted), but for patient.name.given and patient.name.family it's validating. I think that might be because of they are grand-child of parent(patient=>name=>family). Is there another way to validate them?

view this post on Zulip Mritunjay Dubey (Oct 06 2016 at 13:22):

below is the relavant part of profile-differential generated by Forge tool

<element>
  <path value="Patient.name" />
  <min value="1" />
  <max value="1" />
  <base>
    <path value="Patient.name" />
    <min value="0" />
    <max value="*" />
  </base>
</element>
<element>
  <path value="Patient.name.family" />
  <min value="1" />
  <max value="1" />
  <base>
    <path value="Patient.name.family" />
    <min value="0" />
    <max value="*" />
  </base>
</element>
<element>
  <path value="Patient.name.given" />
  <min value="1" />
  <max value="1" />
  <base>
    <path value="Patient.name.given" />
    <min value="0" />
    <max value="*" />
  </base>
</element>

view this post on Zulip Grahame Grieve (Oct 06 2016 at 18:41):

that should work

view this post on Zulip Grahame Grieve (Oct 06 2016 at 18:41):

what does 'I got it working' mean?

view this post on Zulip Mritunjay Dubey (Oct 07 2016 at 02:49):

what does 'I got it working' mean?

I meant that I was not able to Use org.hl7.fhir.dstu2.validation.ValidationEngine for some reason, but I am able to use it in a fresh project, but I am still facing problem validation for field which are not directly children to parent. I think it might be because to validate patient.name.family it might be reading the standard humanname.profile.xml. Is there a way I can force it to use overridden snapshot? The snapshot says family and given are mandatory fields.


Last updated: Apr 12 2022 at 19:14 UTC