use of org.hl7.fhir.r5.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));
}
use of org.hl7.fhir.r5.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()));
}
use of org.hl7.fhir.r5.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()));
}
use of org.hl7.fhir.r5.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;
}
use of org.hl7.fhir.r5.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());
}
Aggregations