Search in sources :

Example 31 with Period

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())));
}
Also used : GroupMember(org.openmrs.module.fhir2.model.GroupMember) Period(org.hl7.fhir.r4.model.Period) CohortMembership(org.openmrs.CohortMembership) Test(org.junit.Test)

Example 32 with Period

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));
}
Also used : Period(org.hl7.fhir.r4.model.Period) Date(java.util.Date) Test(org.junit.Test)

Example 33 with Period

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));
}
Also used : Encounter(org.openmrs.Encounter) Period(org.hl7.fhir.r4.model.Period) Date(java.util.Date) Test(org.junit.Test)

Example 34 with Period

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));
}
Also used : Encounter(org.openmrs.Encounter) Period(org.hl7.fhir.r4.model.Period) Date(java.util.Date) Test(org.junit.Test)

Example 35 with Period

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));
}
Also used : Period(org.hl7.fhir.r4.model.Period) Encounter(org.hl7.fhir.r4.model.Encounter) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Period (org.hl7.fhir.r4.model.Period)87 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)44 Date (java.util.Date)42 Test (org.junit.Test)42 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)40 Coding (org.hl7.fhir.r4.model.Coding)34 Test (org.junit.jupiter.api.Test)34 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)32 Period (org.hl7.fhir.dstu3.model.Period)30 ArrayList (java.util.ArrayList)29 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)27 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)20 Encounter (org.hl7.fhir.r4.model.Encounter)20 Reference (org.hl7.fhir.r4.model.Reference)20 Patient (org.hl7.fhir.r4.model.Patient)19 Reference (org.hl7.fhir.dstu3.model.Reference)18 HashMap (java.util.HashMap)17 Identifier (org.hl7.fhir.r4.model.Identifier)17 NotImplementedException (org.apache.commons.lang3.NotImplementedException)15 List (java.util.List)14