use of org.hl7.fhir.dstu2.model.Period in project openmrs-module-fhir2 by openmrs.
the class GroupMemberTranslatorImpl_2_1Test method shouldUpdateCohortMembershipStartDate.
@Test
public void shouldUpdateCohortMembershipStartDate() {
Period period = mock(Period.class);
GroupMember groupMember = mock(GroupMember.class);
// Existing cohortMembership
CohortMembership cohortMembership = new CohortMembership();
cohortMembership.setStartDate(Date.from(Instant.parse("2020-12-04T08:07:00Z")));
when(groupMember.hasPeriod()).thenReturn(true);
when(groupMember.getPeriod()).thenReturn(period);
// Mocked updated date is today
when(period.getStart()).thenReturn(Date.from(Instant.now()));
CohortMembership membership = groupMemberTranslator.toOpenmrsType(groupMember);
assertThat(membership, notNullValue());
assertThat(membership.getStartDate(), notNullValue());
assertThat(membership.getStartDate(), DateMatchers.sameDay(Date.from(Instant.now())));
}
use of org.hl7.fhir.dstu2.model.Period in project openmrs-module-fhir2 by openmrs.
the class EncounterTranslatorImplTest method toOpenMrsType_shouldTranslatePeriodToEncounterDatetime.
@Test
public void toOpenMrsType_shouldTranslatePeriodToEncounterDatetime() {
Date encounterDate = new java.util.Date();
Period period = new Period();
period.setStart(encounterDate);
fhirEncounter.setPeriod(period);
when(encounterPeriodTranslator.toOpenmrsType(ArgumentMatchers.any(), ArgumentMatchers.any())).then(invocation -> {
org.openmrs.Encounter encounter = invocation.getArgument(0);
encounter.setEncounterDatetime(((Period) invocation.getArgument(1)).getStart());
return encounter;
});
when(patientReferenceTranslator.toOpenmrsType(patientRef)).thenReturn(patient);
org.openmrs.Encounter result = encounterTranslator.toOpenmrsType(fhirEncounter);
assertThat(result, notNullValue());
assertThat(result.getEncounterDatetime(), equalTo(encounterDate));
}
use of org.hl7.fhir.dstu2.model.Period in project openmrs-module-fhir2 by openmrs.
the class EncounterPeriodTranslatorImplTest method toOpenmrsObject_shouldMapPeriodStartToEncounterDatetime.
@Test
public void toOpenmrsObject_shouldMapPeriodStartToEncounterDatetime() {
Date encounterDate = new java.util.Date();
Encounter encounter = new Encounter();
Period period = new Period();
period.setStart(encounterDate);
Encounter result = encounterPeriodTranslator.toOpenmrsType(encounter, period);
assertThat(result, notNullValue());
assertThat(result.getEncounterDatetime(), equalTo(encounterDate));
}
use of org.hl7.fhir.dstu2.model.Period in project openmrs-module-fhir2 by openmrs.
the class EncounterPeriodTranslatorImplTest method toOpenmrsObject_shouldNotTouchEncounterDatetimeIfPeriodHasNoStartOrEnd.
@Test
public void toOpenmrsObject_shouldNotTouchEncounterDatetimeIfPeriodHasNoStartOrEnd() {
Date encounterDate = new java.util.Date();
Encounter encounter = new Encounter();
encounter.setEncounterDatetime(encounterDate);
Period period = new Period();
Encounter result = encounterPeriodTranslator.toOpenmrsType(encounter, period);
assertThat(result, notNullValue());
assertThat(result.getEncounterDatetime(), equalTo(encounterDate));
}
use of org.hl7.fhir.dstu2.model.Period in project openmrs-module-fhir2 by openmrs.
the class EncounterTranslatorImplTest method toFhirResource_shouldTranslateEncounterDatetimeToPeriod.
@Test
public void toFhirResource_shouldTranslateEncounterDatetimeToPeriod() {
Date encounterDate = new java.util.Date();
Period period = new Period();
omrsEncounter.setEncounterDatetime(encounterDate);
period.setStart(encounterDate);
when(encounterPeriodTranslator.toFhirResource(ArgumentMatchers.any())).thenReturn(period);
Encounter result = encounterTranslator.toFhirResource(omrsEncounter);
assertThat(result, notNullValue());
assertThat(result.getPeriod(), equalTo(period));
}
Aggregations