FirelyTeam / firely-validator-api

Firely's official FHIR validator API for validating HL7 FHIR resources against profiles.
Other
8 stars 2 forks source link

Add hand-written business rules from the Java Validator #266

Open ewoutkramer opened 9 months ago

ewoutkramer commented 9 months ago

This picture show (in purple) the lines that call the methods that contain all the hand-written validations in the Java validator.

java-validator-business-rules

We should be adding those to the validator and monitor newly added ones.

mmsmits commented 9 months ago

Here is the actual line in java validator: https://github.com/hapifhir/org.hl7.fhir.core/blob/0178bf751ac9473323bee51afe81cd5e02e1ce6f/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java#L5546

ewoutkramer commented 1 month ago

Here's the relevant Java. As you can see, Grahame has combined the rules per type of resource in specialized validators. Some of them really complex (like the Bundle one), others (like Observation) much more simple. I'd say this is VERY useful to do, as this would bridge a lot of the gaps between the two validators. But also, as a rough estimate I think it would take about 20 days.

 if (element.getType().equals(BUNDLE)) {
        return new BundleValidator(this, serverBase).validateBundle(errors, element, stack, checkSpecials, valContext, pct, mode) && ok;
      } else if (element.getType().equals("Observation")) {
        return new ObservationValidator(this).validateObservation(valContext, errors, element, stack, pct, mode) && ok;
      } else if (element.getType().equals("Questionnaire")) {
        return new QuestionnaireValidator(this, myEnableWhenEvaluator, fpe, questionnaireMode).validateQuestionannaire(errors, element, element, stack) && ok;
      } else if (element.getType().equals("QuestionnaireResponse")) {
        return new QuestionnaireValidator(this, myEnableWhenEvaluator, fpe, questionnaireMode).validateQuestionannaireResponse(valContext, errors, element, stack) && ok;
      } else if (element.getType().equals("Measure")) {
        return new MeasureValidator(this).validateMeasure(valContext, errors, element, stack) && ok;      
      } else if (element.getType().equals("MeasureReport")) {
        return new MeasureValidator(this).validateMeasureReport(valContext, errors, element, stack) && ok;
      } else if (element.getType().equals("CapabilityStatement")) {
        return validateCapabilityStatement(errors, element, stack) && ok;
      } else if (element.getType().equals("CodeSystem")) {
        return new CodeSystemValidator(this).validateCodeSystem(errors, element, stack, baseOptions.withLanguage(stack.getWorkingLang())) && ok;
      } else if (element.getType().equals("ConceptMap")) {
        return new ConceptMapValidator(this).validateConceptMap(errors, element, stack, baseOptions.withLanguage(stack.getWorkingLang())) && ok;
      } else if (element.getType().equals("SearchParameter")) {
        return new SearchParameterValidator(this, fpe).validateSearchParameter(errors, element, stack) && ok;
      } else if (element.getType().equals("StructureDefinition")) {
        return new StructureDefinitionValidator(this, fpe, wantCheckSnapshotUnchanged).validateStructureDefinition(errors, element, stack) && ok;
      } else if (element.getType().equals("StructureMap")) {
        return new StructureMapValidator(this, fpe, profileUtilities).validateStructureMap(errors, element, stack) && ok;
      } else if (element.getType().equals("ValueSet")) {
        return new ValueSetValidator(this).validateValueSet(errors, element, stack) && ok;