Search in sources :

Example 86 with Practitioner

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

the class PractitionerTranslatorProviderImpl method toOpenmrsType.

@Override
public Provider toOpenmrsType(@Nonnull Provider existingProvider, @Nonnull Practitioner practitioner) {
    if (existingProvider == null) {
        return null;
    }
    if (practitioner == null) {
        return null;
    }
    existingProvider.setUuid(practitioner.getId());
    existingProvider.setIdentifier(practitioner.getIdentifierFirstRep().getValue());
    if (existingProvider.getPerson() == null) {
        existingProvider.setPerson(new Person());
    }
    if (practitioner.hasBirthDateElement()) {
        birthDateTranslator.toOpenmrsType(existingProvider.getPerson(), practitioner.getBirthDateElement());
    }
    for (HumanName name : practitioner.getName()) {
        existingProvider.getPerson().addName(nameTranslator.toOpenmrsType(name));
    }
    if (practitioner.hasGender()) {
        existingProvider.getPerson().setGender(genderTranslator.toOpenmrsType(practitioner.getGender()));
    }
    for (Address address : practitioner.getAddress()) {
        existingProvider.getPerson().addAddress(addressTranslator.toOpenmrsType(address));
    }
    practitioner.getTelecom().stream().map(contactPoint -> (ProviderAttribute) telecomTranslator.toOpenmrsType(new ProviderAttribute(), contactPoint)).filter(Objects::nonNull).forEach(existingProvider::addAttribute);
    return existingProvider;
}
Also used : HumanName(org.hl7.fhir.r4.model.HumanName) Address(org.hl7.fhir.r4.model.Address) PersonAddress(org.openmrs.PersonAddress) ProviderAttribute(org.openmrs.ProviderAttribute) Person(org.openmrs.Person)

Example 87 with Practitioner

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

the class PractitionerTranslatorProviderImpl method toFhirResource.

@Override
public Practitioner toFhirResource(@Nonnull Provider provider) {
    if (provider == null) {
        return null;
    }
    Practitioner practitioner = new Practitioner();
    Identifier identifier = new Identifier();
    identifier.setSystem(FhirConstants.OPENMRS_FHIR_EXT_PROVIDER_IDENTIFIER);
    identifier.setValue(provider.getIdentifier());
    practitioner.addIdentifier(identifier);
    practitioner.setId(provider.getUuid());
    practitioner.setActive(provider.getRetired());
    practitioner.setTelecom(getProviderContactDetails(provider));
    if (provider.getPerson() != null) {
        practitioner.setBirthDateElement(birthDateTranslator.toFhirResource(provider.getPerson()));
        practitioner.setGender(genderTranslator.toFhirResource(provider.getPerson().getGender()));
        for (PersonName name : provider.getPerson().getNames()) {
            practitioner.addName(nameTranslator.toFhirResource(name));
        }
        for (PersonAddress address : provider.getPerson().getAddresses()) {
            practitioner.addAddress(addressTranslator.toFhirResource(address));
        }
    }
    practitioner.getMeta().setLastUpdated(provider.getDateChanged());
    practitioner.addContained(provenanceTranslator.getCreateProvenance(provider));
    practitioner.addContained(provenanceTranslator.getUpdateProvenance(provider));
    return practitioner;
}
Also used : Practitioner(org.hl7.fhir.r4.model.Practitioner) PersonName(org.openmrs.PersonName) Identifier(org.hl7.fhir.r4.model.Identifier) PersonAddress(org.openmrs.PersonAddress)

Example 88 with Practitioner

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

the class PractitionerTranslatorUserImpl method toFhirResource.

@Override
public Practitioner toFhirResource(@Nonnull User user) {
    notNull(user, "The User object should not be null");
    Practitioner practitioner = new Practitioner();
    practitioner.setId(user.getUuid());
    Identifier userIdentifier = new Identifier();
    userIdentifier.setSystem(FhirConstants.OPENMRS_FHIR_EXT_USER_IDENTIFIER);
    userIdentifier.setValue(user.getSystemId());
    practitioner.addIdentifier(userIdentifier);
    if (user.getPerson() != null) {
        practitioner.setBirthDateElement(birthDateTranslator.toFhirResource(user.getPerson()));
        practitioner.setGender(genderTranslator.toFhirResource(user.getPerson().getGender()));
        for (PersonName name : user.getPerson().getNames()) {
            practitioner.addName(nameTranslator.toFhirResource(name));
        }
        for (PersonAddress address : user.getPerson().getAddresses()) {
            practitioner.addAddress(addressTranslator.toFhirResource(address));
        }
    }
    practitioner.getMeta().setLastUpdated(user.getDateChanged());
    return practitioner;
}
Also used : Practitioner(org.hl7.fhir.r4.model.Practitioner) PersonName(org.openmrs.PersonName) Identifier(org.hl7.fhir.r4.model.Identifier) PersonAddress(org.openmrs.PersonAddress)

Example 89 with Practitioner

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

the class PractitionerFhirResourceProviderWebTest method getPractitionerHistoryById_shouldReturnBundleWithEmptyEntriesIfPractitionerContainedIsEmpty.

@Test
public void getPractitionerHistoryById_shouldReturnBundleWithEmptyEntriesIfPractitionerContainedIsEmpty() throws Exception {
    org.hl7.fhir.r4.model.Practitioner practitioner = new org.hl7.fhir.r4.model.Practitioner();
    practitioner.setId(PRACTITIONER_UUID);
    practitioner.setContained(new ArrayList<>());
    when(practitionerService.get(PRACTITIONER_UUID)).thenReturn(practitioner);
    MockHttpServletResponse response = getPractitionerHistoryByIdRequest();
    Bundle results = readBundleResponse(response);
    assertThat(results.hasEntry(), is(false));
}
Also used : Practitioner(org.hl7.fhir.dstu3.model.Practitioner) Bundle(org.hl7.fhir.dstu3.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 90 with Practitioner

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

the class PractitionerFhirResourceProviderWebTest method deletePractitioner_shouldDeletePractitioner.

@Test
public void deletePractitioner_shouldDeletePractitioner() throws Exception {
    OperationOutcome retVal = new OperationOutcome();
    retVal.setId(PRACTITIONER_UUID);
    retVal.getText().setDivAsString("Deleted successfully");
    org.hl7.fhir.r4.model.Practitioner practitioner = new org.hl7.fhir.r4.model.Practitioner();
    practitioner.setId(PRACTITIONER_UUID);
    when(practitionerService.delete(PRACTITIONER_UUID)).thenReturn(practitioner);
    MockHttpServletResponse response = delete("/Practitioner/" + PRACTITIONER_UUID).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
}
Also used : Practitioner(org.hl7.fhir.dstu3.model.Practitioner) OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

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