Search in sources :

Example 51 with Person

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

the class PractitionerTranslatorProviderImplTest method shouldTranslateProviderGenderToFhirPractitionerType.

@Test
public void shouldTranslateProviderGenderToFhirPractitionerType() {
    Person person = new Person();
    PersonName name = new PersonName();
    name.setGivenName(GIVEN_NAME);
    name.setFamilyName(FAMILY_NAME);
    person.addName(name);
    provider.setPerson(person);
    HumanName humanName = new HumanName();
    humanName.setFamily(FAMILY_NAME);
    humanName.addGiven(GIVEN_NAME);
    when(nameTranslator.toFhirResource(name)).thenReturn(humanName);
    Practitioner practitioner = practitionerTranslator.toFhirResource(provider);
    assertThat(practitioner, notNullValue());
    assertThat(practitioner.getName(), notNullValue());
    assertThat(practitioner.getName(), not(empty()));
    assertThat(practitioner.getName().get(0).getGiven().get(0).getValue(), equalTo(GIVEN_NAME));
    assertThat(practitioner.getName().get(0).getFamily(), equalTo(FAMILY_NAME));
}
Also used : Practitioner(org.hl7.fhir.r4.model.Practitioner) HumanName(org.hl7.fhir.r4.model.HumanName) PersonName(org.openmrs.PersonName) Person(org.openmrs.Person) Test(org.junit.Test)

Example 52 with Person

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

the class PractitionerTranslatorUserImplTest method shouldTranslateUserGenderToFhirPractitionerType.

@Test
public void shouldTranslateUserGenderToFhirPractitionerType() {
    Person person = new Person();
    PersonName name = new PersonName();
    name.setGivenName(GIVEN_NAME);
    name.setFamilyName(FAMILY_NAME);
    person.addName(name);
    user.setPerson(person);
    HumanName humanName = new HumanName();
    humanName.setFamily(FAMILY_NAME);
    humanName.addGiven(GIVEN_NAME);
    when(nameTranslator.toFhirResource(name)).thenReturn(humanName);
    Practitioner practitioner = practitionerTranslatorUser.toFhirResource(user);
    assertThat(practitioner, notNullValue());
    assertThat(practitioner.getName(), notNullValue());
    assertThat(practitioner.getName(), not(empty()));
    assertThat(practitioner.getName().get(0).getGiven().get(0).getValue(), equalTo(GIVEN_NAME));
    assertThat(practitioner.getName().get(0).getFamily(), equalTo(FAMILY_NAME));
}
Also used : Practitioner(org.hl7.fhir.r4.model.Practitioner) HumanName(org.hl7.fhir.r4.model.HumanName) PersonName(org.openmrs.PersonName) Person(org.openmrs.Person) Test(org.junit.Test)

Example 53 with Person

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

the class PractitionerTranslatorUserImplTest method shouldTranslateToFhirBirthDate.

@Test
public void shouldTranslateToFhirBirthDate() {
    User user = new User();
    Calendar calendar = Calendar.getInstance();
    DateType dateType = new DateType();
    // when birthdate more than 5 year
    calendar.set(2000, Calendar.AUGUST, 12);
    Person person = new Person();
    person.setBirthdateEstimated(true);
    person.setBirthdate(calendar.getTime());
    user.setPerson(person);
    Practitioner result = practitionerTranslatorUser.toFhirResource(user);
    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();
    user.getPerson().setBirthdate(date);
    dateType.setValue(date, TemporalPrecisionEnum.MONTH);
    result = practitionerTranslatorUser.toFhirResource(user);
    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 : Practitioner(org.hl7.fhir.r4.model.Practitioner) User(org.openmrs.User) Calendar(java.util.Calendar) DateType(org.hl7.fhir.r4.model.DateType) Person(org.openmrs.Person) Date(java.util.Date) Test(org.junit.Test)

Example 54 with Person

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

the class PractitionerTranslatorUserImplTest method shouldTranslateUserGenderToFhirPractitionerGender.

@Test
public void shouldTranslateUserGenderToFhirPractitionerGender() {
    Person person = new Person();
    person.setGender(GENDER);
    user.setPerson(person);
    when(genderTranslator.toFhirResource(GENDER)).thenReturn(Enumerations.AdministrativeGender.MALE);
    Practitioner practitioner = practitionerTranslatorUser.toFhirResource(user);
    assertThat(practitioner, notNullValue());
    assertThat(practitioner.getGender(), notNullValue());
    assertThat(practitioner.getGender(), equalTo(Enumerations.AdministrativeGender.MALE));
}
Also used : Practitioner(org.hl7.fhir.r4.model.Practitioner) Person(org.openmrs.Person) Test(org.junit.Test)

Example 55 with Person

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

the class ProvenanceTranslatorImplTest method shouldGetUpdateProvenanceWithCorrectAgentRoleForOpenmrsData.

@Test
public void shouldGetUpdateProvenanceWithCorrectAgentRoleForOpenmrsData() {
    Provenance provenance = personProvenanceTranslator.getUpdateProvenance(person);
    assertThat(provenance, notNullValue());
    assertThat(provenance.getAgent(), not(empty()));
    assertThat(provenance.getAgentFirstRep().getRoleFirstRep(), notNullValue());
    assertThat(provenance.getAgentFirstRep().getRoleFirstRep().getCodingFirstRep(), notNullValue());
    assertThat(provenance.getAgentFirstRep().getRoleFirstRep().getCodingFirstRep().getCode(), equalTo(AGENT_ROLE_CODE));
    assertThat(provenance.getAgentFirstRep().getRoleFirstRep().getCodingFirstRep().getDisplay(), equalTo(AGENT_ROLE_DISPLAY));
    assertThat(provenance.getAgentFirstRep().getRoleFirstRep().getCodingFirstRep().getSystem(), equalTo(FhirConstants.FHIR_TERMINOLOGY_PARTICIPATION_TYPE));
}
Also used : Provenance(org.hl7.fhir.r4.model.Provenance) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)181 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)54 Date (java.util.Date)50 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)48 Person (org.hl7.fhir.r4.model.Person)47 Person (model.Person)44 Person (com.google.api.services.people.v1.model.Person)38 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)37 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)32 Reference (org.hl7.fhir.r4.model.Reference)31 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)30 StringParam (ca.uhn.fhir.rest.param.StringParam)30 VCard (ezvcard.VCard)30 Person (org.openmrs.Person)29 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)23 List (java.util.List)22 Collectors (java.util.stream.Collectors)22 Person (org.hl7.fhir.dstu3.model.Person)22 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)22 DocumentReference (org.hl7.fhir.r4.model.DocumentReference)21