Search in sources :

Example 71 with Practitioner

use of org.hl7.fhir.r4.model.Practitioner 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 72 with Practitioner

use of org.hl7.fhir.r4.model.Practitioner 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 73 with Practitioner

use of org.hl7.fhir.r4.model.Practitioner 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 74 with Practitioner

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

the class PractitionerTranslatorUserImplTest method shouldTranslateOpenMrsDateChangedToLastUpdatedDate.

@Test
public void shouldTranslateOpenMrsDateChangedToLastUpdatedDate() {
    user.setDateChanged(new Date());
    Practitioner result = practitionerTranslatorUser.toFhirResource(user);
    assertThat(result, notNullValue());
    assertThat(result.getMeta().getLastUpdated(), DateMatchers.sameDay(new Date()));
}
Also used : Practitioner(org.hl7.fhir.r4.model.Practitioner) Date(java.util.Date) Test(org.junit.Test)

Example 75 with Practitioner

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

the class PractitionerTranslatorUserImplTest method setup.

@Before
public void setup() {
    practitionerTranslatorUser = new PractitionerTranslatorUserImpl();
    practitionerTranslatorUser.setNameTranslator(nameTranslator);
    practitionerTranslatorUser.setAddressTranslator(addressTranslator);
    practitionerTranslatorUser.setGenderTranslator(genderTranslator);
    practitionerTranslatorUser.setBirthDateTranslator(birthDateTranslator);
    user = new User();
    user.setUuid(USER_UUID);
    user.setSystemId(SYSTEM_ID);
    Identifier identifier = new Identifier();
    identifier.setValue((SYSTEM_ID));
    identifier.setSystem(FhirConstants.OPENMRS_FHIR_EXT_USER_IDENTIFIER);
    practitioner = new Practitioner();
    practitioner.setId(USER_UUID);
    practitioner.addIdentifier(identifier);
}
Also used : Practitioner(org.hl7.fhir.r4.model.Practitioner) User(org.openmrs.User) Identifier(org.hl7.fhir.r4.model.Identifier) Before(org.junit.Before)

Aggregations

Test (org.junit.Test)185 Practitioner (org.hl7.fhir.r4.model.Practitioner)139 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)86 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)81 Test (org.junit.jupiter.api.Test)68 Practitioner (org.hl7.fhir.dstu3.model.Practitioner)62 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)59 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)54 StringParam (ca.uhn.fhir.rest.param.StringParam)54 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)52 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)37 Identifier (org.hl7.fhir.r4.model.Identifier)32 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)30 Resource (org.hl7.fhir.r4.model.Resource)30 ArrayList (java.util.ArrayList)25 Reference (org.hl7.fhir.r4.model.Reference)24 Bundle (org.hl7.fhir.r4.model.Bundle)22 Date (java.util.Date)21 List (java.util.List)21 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)20