Search in sources :

Example 56 with DateType

use of org.hl7.fhir.r4.model.DateType in project openmrs-module-fhir2 by openmrs.

the class PatientTranslatorImplTest method shouldTranslateToOpenMRSBirthDate.

@Test
public void shouldTranslateToOpenMRSBirthDate() {
    org.hl7.fhir.r4.model.Patient openMRSPatient = new org.hl7.fhir.r4.model.Patient();
    Date date = new Date();
    DateType dateType = new DateType();
    // for TemporalPrecisionEnum.DAY
    dateType.setValue(date, TemporalPrecisionEnum.DAY);
    openMRSPatient.setBirthDateElement(dateType);
    org.openmrs.Patient result = patientTranslator.toOpenmrsType(openMRSPatient);
    assertThat(result, notNullValue());
    assertThat(result.getBirthdateEstimated(), equalTo(false));
    assertThat(result.getBirthdate(), equalTo(date));
    // for TemporalPrecisionEnum.Month
    dateType.setValue(date, TemporalPrecisionEnum.MONTH);
    openMRSPatient.setBirthDateElement(dateType);
    result = patientTranslator.toOpenmrsType(openMRSPatient);
    assertThat(result, notNullValue());
    assertThat(result.getBirthdateEstimated(), equalTo(true));
    assertThat(result.getBirthdate(), equalTo(date));
    // for TemporalPrecisionEnum.YEAR
    dateType.setValue(date, TemporalPrecisionEnum.YEAR);
    openMRSPatient.setBirthDateElement(dateType);
    result = patientTranslator.toOpenmrsType(openMRSPatient);
    assertThat(result, notNullValue());
    assertThat(result.getBirthdateEstimated(), equalTo(true));
    assertThat(result.getBirthdate(), equalTo(date));
}
Also used : Patient(org.hl7.fhir.r4.model.Patient) DateType(org.hl7.fhir.r4.model.DateType) Patient(org.hl7.fhir.r4.model.Patient) Date(java.util.Date) Test(org.junit.Test)

Example 57 with DateType

use of org.hl7.fhir.r4.model.DateType in project openmrs-module-fhir2 by openmrs.

the class PatientTranslatorImplTest method shouldTranslateToFhirBirthDate.

@Test
public void shouldTranslateToFhirBirthDate() {
    org.openmrs.Patient patient = new org.openmrs.Patient();
    Calendar calendar = Calendar.getInstance();
    DateType dateType = new DateType();
    // when birthdate more than 5 year
    calendar.set(2000, Calendar.AUGUST, 12);
    patient.setBirthdateEstimated(true);
    patient.setBirthdate(calendar.getTime());
    Patient result = patientTranslator.toFhirResource(patient);
    assertThat(result, notNullValue());
    assertThat(result.getBirthDateElement().getPrecision(), equalTo(TemporalPrecisionEnum.YEAR));
    assertThat(result.getBirthDateElement().getYear(), equalTo(2000));
    // when birthDate less then 5 year
    Date date = new Date();
    patient.setBirthdate(date);
    dateType.setValue(date, TemporalPrecisionEnum.MONTH);
    result = patientTranslator.toFhirResource(patient);
    assertThat(result, notNullValue());
    assertThat(result.getBirthDateElement().getPrecision(), equalTo(TemporalPrecisionEnum.MONTH));
    assertThat(result.getBirthDateElement().getYear(), equalTo(dateType.getYear()));
    assertThat(result.getBirthDateElement().getMonth(), equalTo(dateType.getMonth()));
}
Also used : Calendar(java.util.Calendar) Patient(org.hl7.fhir.r4.model.Patient) DateType(org.hl7.fhir.r4.model.DateType) Date(java.util.Date) Test(org.junit.Test)

Example 58 with DateType

use of org.hl7.fhir.r4.model.DateType in project openmrs-module-fhir2 by openmrs.

the class RelatedPersonTranslatorImplTest method shouldTranslateToFhirBirthdate.

@Test
public void shouldTranslateToFhirBirthdate() {
    Person person = new Person();
    Calendar calendar = Calendar.getInstance();
    DateType dateType = new DateType();
    // when birthdate more than 5 year
    calendar.set(2000, Calendar.AUGUST, 12);
    person.setBirthdateEstimated(true);
    person.setBirthdate(calendar.getTime());
    relationship.setPersonA(person);
    RelatedPerson result = relatedPersonTranslator.toFhirResource(relationship);
    assertThat(result, notNullValue());
    assertThat(result.getBirthDateElement().getPrecision(), equalTo(TemporalPrecisionEnum.YEAR));
    assertThat(result.getBirthDateElement().getYear(), equalTo(2000));
    // when birthDate less then 5 year
    Date date = new Date();
    person.setBirthdate(date);
    dateType.setValue(date, TemporalPrecisionEnum.MONTH);
    relationship.setPersonA(person);
    result = relatedPersonTranslator.toFhirResource(relationship);
    assertThat(result, notNullValue());
    assertThat(result.getBirthDateElement().getPrecision(), equalTo(TemporalPrecisionEnum.MONTH));
    assertThat(result.getBirthDateElement().getYear(), equalTo(dateType.getYear()));
    assertThat(result.getBirthDateElement().getMonth(), equalTo(dateType.getMonth()));
}
Also used : Calendar(java.util.Calendar) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) Person(org.openmrs.Person) DateType(org.hl7.fhir.r4.model.DateType) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) Date(java.util.Date) Test(org.junit.Test)

Example 59 with DateType

use of org.hl7.fhir.r4.model.DateType in project quality-measure-and-cohort-service by Alvearie.

the class R4ParameterDefinitionWithDefaultToCohortParameterConverter method toCohortParameter.

public static Parameter toCohortParameter(Extension extension) {
    Parameter parameter;
    Type extensionValue = extension.getValue();
    if (extensionValue instanceof Base64BinaryType) {
        parameter = new StringParameter(((Base64BinaryType) extensionValue).asStringValue());
    } else if (extensionValue instanceof BooleanType) {
        parameter = new BooleanParameter(((BooleanType) extensionValue).booleanValue());
    } else if (extensionValue instanceof DateType) {
        parameter = new DateParameter(((DateType) extensionValue).asStringValue());
    } else if (extensionValue instanceof DateTimeType) {
        parameter = convertDateTimeType((DateTimeType) extensionValue);
    } else if (extensionValue instanceof DecimalType) {
        parameter = new DecimalParameter(((DecimalType) extensionValue).getValueAsString());
    } else if (extensionValue instanceof InstantType) {
        parameter = new DatetimeParameter(((InstantType) extensionValue).getValueAsString());
    } else if (extensionValue instanceof IntegerType) {
        parameter = new IntegerParameter(((IntegerType) extensionValue).getValue());
    } else if (extensionValue instanceof StringType) {
        parameter = new StringParameter(((StringType) extensionValue).getValue());
    } else if (extensionValue instanceof TimeType) {
        parameter = new TimeParameter(((TimeType) extensionValue).asStringValue());
    } else if (extensionValue instanceof UriType) {
        parameter = new StringParameter(((UriType) extensionValue).getValue());
    } else if (extensionValue instanceof Coding) {
        parameter = convertCoding((Coding) extensionValue);
    } else if (extensionValue instanceof CodeableConcept) {
        parameter = convertCodeableConcept((CodeableConcept) extensionValue);
    } else if (extensionValue instanceof Period) {
        Period castValue = (Period) extensionValue;
        parameter = new IntervalParameter(convertDateTimeType(castValue.getStartElement()), true, convertDateTimeType(castValue.getEndElement()), true);
    } else if (extensionValue instanceof Quantity) {
        parameter = convertQuantity((Quantity) extensionValue);
    } else if (extensionValue instanceof Range) {
        Range castValue = (Range) extensionValue;
        parameter = new IntervalParameter(convertQuantity(castValue.getLow()), true, convertQuantity(castValue.getHigh()), true);
    } else if (extensionValue instanceof Ratio) {
        Ratio castValue = (Ratio) extensionValue;
        parameter = new RatioParameter().setDenominator(convertQuantity(castValue.getDenominator())).setNumerator(convertQuantity(castValue.getNumerator()));
    } else {
        throw new UnsupportedFhirTypeException(extensionValue);
    }
    return parameter;
}
Also used : IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) StringType(org.hl7.fhir.r4.model.StringType) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) TimeType(org.hl7.fhir.r4.model.TimeType) UriType(org.hl7.fhir.r4.model.UriType) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) Coding(org.hl7.fhir.r4.model.Coding) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) Ratio(org.hl7.fhir.r4.model.Ratio) InstantType(org.hl7.fhir.r4.model.InstantType) DateType(org.hl7.fhir.r4.model.DateType) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) UnsupportedFhirTypeException(com.ibm.cohort.engine.measure.parameter.UnsupportedFhirTypeException) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) BooleanType(org.hl7.fhir.r4.model.BooleanType) Period(org.hl7.fhir.r4.model.Period) Quantity(org.hl7.fhir.r4.model.Quantity) Range(org.hl7.fhir.r4.model.Range) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) IntegerType(org.hl7.fhir.r4.model.IntegerType) Type(org.hl7.fhir.r4.model.Type) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) StringType(org.hl7.fhir.r4.model.StringType) DecimalType(org.hl7.fhir.r4.model.DecimalType) IntegerType(org.hl7.fhir.r4.model.IntegerType) DateType(org.hl7.fhir.r4.model.DateType) TimeType(org.hl7.fhir.r4.model.TimeType) BooleanType(org.hl7.fhir.r4.model.BooleanType) InstantType(org.hl7.fhir.r4.model.InstantType) UriType(org.hl7.fhir.r4.model.UriType) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) ConceptParameter(com.ibm.cohort.cql.evaluation.parameters.ConceptParameter) QuantityParameter(com.ibm.cohort.cql.evaluation.parameters.QuantityParameter) RatioParameter(com.ibm.cohort.cql.evaluation.parameters.RatioParameter) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) CodeParameter(com.ibm.cohort.cql.evaluation.parameters.CodeParameter) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) DecimalType(org.hl7.fhir.r4.model.DecimalType) RatioParameter(com.ibm.cohort.cql.evaluation.parameters.RatioParameter) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 60 with DateType

use of org.hl7.fhir.r4.model.DateType in project quality-measure-and-cohort-service by Alvearie.

the class CQLToFHIRMeasureReportHelperTest method testDate.

@Test
public void testDate() {
    String dateString = "2020-01-02";
    Date expected = new Date(dateString);
    IBaseDatatype fhirTypeValue = CQLToFHIRMeasureReportHelper.getFhirTypeValue(expected);
    assertTrue(fhirTypeValue instanceof DateType);
    assertEquals(dateString, ((DateType) fhirTypeValue).getValueAsString());
}
Also used : IBaseDatatype(org.hl7.fhir.instance.model.api.IBaseDatatype) DateType(org.hl7.fhir.r4.model.DateType) Date(org.opencds.cqf.cql.engine.runtime.Date) Test(org.junit.Test)

Aggregations

DateType (org.hl7.fhir.r4.model.DateType)36 Test (org.junit.jupiter.api.Test)21 Date (java.util.Date)17 Coding (org.hl7.fhir.r4.model.Coding)15 Test (org.junit.Test)11 SupportingInformationComponent (org.hl7.fhir.r4.model.ExplanationOfBenefit.SupportingInformationComponent)10 DateType (org.hl7.fhir.r4b.model.DateType)10 FHIRException (org.hl7.fhir.exceptions.FHIRException)9 ArrayList (java.util.ArrayList)8 DateType (org.hl7.fhir.r5.model.DateType)8 DateType (org.hl7.fhir.dstu3.model.DateType)7 Extension (org.hl7.fhir.r4.model.Extension)6 Calendar (java.util.Calendar)5 DisplayName (org.junit.jupiter.api.DisplayName)5 InvalidRifValueException (gov.cms.bfd.model.rif.parse.InvalidRifValueException)4 DateType (org.hl7.fhir.dstu2016may.model.DateType)4 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)4 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)4 Patient (org.hl7.fhir.r4.model.Patient)4 Reference (org.hl7.fhir.r4.model.Reference)4