fhir-crucible / fhir_models

FHIR Resource Models
Apache License 2.0
87 stars 26 forks source link

Validation fails on contained resources #75

Closed BillyYarosh-WellSky closed 4 years ago

BillyYarosh-WellSky commented 4 years ago

When building a FHIR::MedicationRequest, you can include the medication in the contained section. In this case, the medicationReference is a relatively linked resource. Validation fails in this case.

Example:

puts FHIR::MedicationRequest.new(
  medicationReference: 
    FHIR::Reference.new(
      reference: "#medication-1234",
      display: 'Med Name',
      type: 'Medication'
    ),
  contained: [FHIR::Medication.new]
).validate

This outputs the error:

"medicationReference"=>["MedicationRequest.medication[x]: incorrect Reference type, expected Medication"]

In the case of medicationReference, you should be able to specify a reference URL this is a hash tag. More info here: http://hl7.org/fhir/STU3/references.html#contained

arscan commented 4 years ago

I'm not sure if this will make a difference, but the I believe the contained resource should be FHIR::Medication.new(id: 'medication-1234'). Does that help?

BillyYarosh-WellSky commented 4 years ago

Sorry, I didn't supply a fully built resource but just enough to exercise the issue. Yes, if I add an ID, the issue persists.

BillyYarosh-WellSky commented 4 years ago

Ah yes, the ID is required in the contained medication. The specific issue was that my ID was an integer type so when the library checks equality it fails because 1234 != '1234'.