All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.linuxforhealth.hl7.expression.specification.HL7Specification Maven / Gradle / Ivy

Go to download

FHIR converter is a Java based library that enables converting Hl7v2 messages to FHIR resources

There is a newer version: 1.0.19
Show newest version
/*
 * (C) Copyright IBM Corp. 2020
 *
 * SPDX-License-Identifier: Apache-2.0
 */
package io.github.linuxforhealth.hl7.expression.specification;

import java.util.Map;
import io.github.linuxforhealth.api.EvaluationResult;
import io.github.linuxforhealth.api.InputDataExtractor;
import io.github.linuxforhealth.api.Specification;
import io.github.linuxforhealth.hl7.message.HL7MessageData;


/**
 * Represents HL7 data specification. It defines segment, field, component and subcomponent
 * names/identifiers that can be used for extracting data.
 * 
 *
 * @author pbhallam
 */

public class HL7Specification implements Specification {

  private String segment;
  private String field;
  private int component;
  private int subComponent;
  private boolean isExtractMultiple;
  private String stringRep;
  private Class sourceInputDataClass = HL7MessageData.class;
  
  public HL7Specification(String segment, String field, int component, int subComponent,
      boolean isMultiple) {
    this.segment = segment;
    this.field = field;
    this.component = component;
    this.subComponent = subComponent;
    this.isExtractMultiple = isMultiple;
    this.stringRep = getToStringRep();
  }


  public HL7Specification(String segment, String field, int component, int subComponent) {
    this(segment, field, component, subComponent, false);

  }

  public String getSegment() {
    return segment;
  }

  public String getField() {
    return field;
  }

  public int getComponent() {
    return component;
  }

  public int getSubComponent() {
    return subComponent;
  }




  @Override
  public String toString() {
    return this.stringRep;


  }

  private String getToStringRep() {
    StringBuilder sb = new StringBuilder();
    sb.append("[");
    if (segment != null) {
      sb.append(segment);
    }

    if (field != null) {
      sb.append(".").append(field);
    }
    if (component > -1) {
      sb.append(".").append(component);
    }
    if (subComponent > -1) {
      sb.append(".").append(subComponent);
    }

    return sb.append("]").toString();


  }


  public boolean isExtractMultiple() {
    return isExtractMultiple;
  }


  public Class getSourceInputDataClass() {
    return sourceInputDataClass;
  }


  @Override
  public EvaluationResult extractValueForSpec(InputDataExtractor dataSource,
      Map contextValues) {
    if (this.isExtractMultiple()) {
      return dataSource.extractMultipleValuesForSpec(this, contextValues);
    } else {
    return dataSource.extractValueForSpec(this, contextValues);
    }
  }


  @Override
  public EvaluationResult extractMultipleValuesForSpec(InputDataExtractor dataSource,
      Map contextValues) {
    return dataSource.extractMultipleValuesForSpec(this, contextValues);
  }



}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy