Search in sources :

Example 6 with HumanName

use of org.hl7.fhir.dstu3.model.HumanName in project gpconnect-demonstrator by nhsconnect.

the class PractitionerResourceProvider method practitionerDetailsToPractitionerResourceConverter.

private Practitioner practitionerDetailsToPractitionerResourceConverter(PractitionerDetails practitionerDetails) {
    Identifier identifier = new Identifier().setSystem(SystemURL.ID_SDS_USER_ID).setValue(practitionerDetails.getUserId());
    Practitioner practitioner = new Practitioner().addIdentifier(identifier);
    practitionerDetails.getRoleIds().stream().distinct().map(roleId -> new Identifier().setSystem(SystemURL.ID_SDS_ROLE_PROFILE_ID).setValue(roleId)).forEach(practitioner::addIdentifier);
    String resourceId = String.valueOf(practitionerDetails.getId());
    String versionId = String.valueOf(practitionerDetails.getLastUpdated().getTime());
    String resourceType = practitioner.getResourceType().toString();
    IdType id = new IdType(resourceType, resourceId, versionId);
    practitioner.setId(id);
    practitioner.getMeta().setVersionId(versionId);
    practitioner.getMeta().setLastUpdated(practitionerDetails.getLastUpdated());
    practitioner.getMeta().addProfile(SystemURL.SD_GPC_PRACTITIONER);
    HumanName name = new HumanName().setFamily(practitionerDetails.getNameFamily()).addGiven(practitionerDetails.getNameGiven()).addPrefix(practitionerDetails.getNamePrefix()).setUse(NameUse.USUAL);
    practitioner.addName(name);
    switch(practitionerDetails.getGender().toLowerCase(Locale.UK)) {
        case "male":
            practitioner.setGender(AdministrativeGender.MALE);
            break;
        case "female":
            practitioner.setGender(AdministrativeGender.FEMALE);
            break;
        case "other":
            practitioner.setGender(AdministrativeGender.OTHER);
            break;
        default:
            practitioner.setGender(AdministrativeGender.UNKNOWN);
            break;
    }
    Coding roleCoding = new Coding(SystemURL.VS_SDS_JOB_ROLE_NAME, practitionerDetails.getRoleCode(), practitionerDetails.getRoleDisplay());
    for (int i = 0; i < practitionerDetails.getComCode().size(); i++) {
        Coding comCoding = new Coding(SystemURL.VS_HUMAN_LANGUAGE, practitionerDetails.getComCode().get(i), null).setDisplay(practitionerDetails.getComDisplay().get(i));
        practitioner.addCommunication().addCoding(comCoding);
    }
    return practitioner;
}
Also used : Practitioner(org.hl7.fhir.dstu3.model.Practitioner) IdParam(ca.uhn.fhir.rest.annotation.IdParam) Identifier(org.hl7.fhir.dstu3.model.Identifier) Coding(org.hl7.fhir.dstu3.model.Coding) IdType(org.hl7.fhir.dstu3.model.IdType) Autowired(org.springframework.beans.factory.annotation.Autowired) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) Extension(org.hl7.fhir.dstu3.model.Extension) RequiredParam(ca.uhn.fhir.rest.annotation.RequiredParam) Locale(java.util.Locale) Search(ca.uhn.fhir.rest.annotation.Search) IResourceProvider(ca.uhn.fhir.rest.server.IResourceProvider) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) Location(org.hl7.fhir.dstu3.model.Location) Read(ca.uhn.fhir.rest.annotation.Read) Practitioner(org.hl7.fhir.dstu3.model.Practitioner) Sort(ca.uhn.fhir.rest.annotation.Sort) Count(ca.uhn.fhir.rest.annotation.Count) Collectors(java.util.stream.Collectors) SystemURL(uk.gov.hscic.SystemURL) IssueType(org.hl7.fhir.dstu3.model.OperationOutcome.IssueType) TokenParam(ca.uhn.fhir.rest.param.TokenParam) PractitionerDetails(uk.gov.hscic.model.practitioner.PractitionerDetails) AdministrativeGender(org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender) OperationOutcomeFactory(uk.gov.hscic.OperationOutcomeFactory) List(java.util.List) Component(org.springframework.stereotype.Component) SortSpec(ca.uhn.fhir.rest.api.SortSpec) IdentifierValidator(uk.gov.hscic.common.validators.IdentifierValidator) SystemCode(uk.gov.hscic.SystemCode) Collections(java.util.Collections) HumanName(org.hl7.fhir.dstu3.model.HumanName) NameUse(org.hl7.fhir.dstu3.model.HumanName.NameUse) HumanName(org.hl7.fhir.dstu3.model.HumanName) Identifier(org.hl7.fhir.dstu3.model.Identifier) Coding(org.hl7.fhir.dstu3.model.Coding) IdType(org.hl7.fhir.dstu3.model.IdType)

Example 7 with HumanName

use of org.hl7.fhir.dstu3.model.HumanName in project gpconnect-demonstrator by nhsconnect.

the class PatientResourceProvider method patientDetailsToPatientResourceConverter.

private Patient patientDetailsToPatientResourceConverter(PatientDetails patientDetails) throws FHIRException {
    Patient patient = patientDetailsToMinimalPatient(patientDetails);
    HumanName name = getPatientNameFromPatientDetails(patientDetails);
    patient.addName(name);
    String addressLines = patientDetails.getAddress();
    if (addressLines != null) {
        patient.addAddress().setUse(AddressUse.HOME).setType(AddressType.PHYSICAL).setText(addressLines);
    }
    Long gpId = patientDetails.getGpId();
    if (gpId != null) {
        Practitioner prac = practitionerResourceProvider.getPractitionerById(new IdType(gpId));
        HumanName practitionerName = prac.getNameFirstRep();
        Reference practitionerReference = new Reference("Practitioner/" + gpId).setDisplay(practitionerName.getPrefix() + " " + practitionerName.getGivenAsSingleString() + " " + practitionerName.getFamily());
    // patient.getCareProvider().add(practitionerReference);
    }
    String telephoneNumber = patientDetails.getTelephone();
    if (telephoneNumber != null) {
        ContactPoint telephone = new ContactPoint().setSystem(ContactPointSystem.PHONE).setValue(telephoneNumber).setUse(ContactPointUse.HOME);
        patient.setTelecom(Collections.singletonList(telephone));
    }
    String managingOrganization = patientDetails.getManagingOrganization();
    if (managingOrganization != null) {
        patient.setManagingOrganization(new Reference("Organization/" + managingOrganization));
    }
    return patient;
}
Also used : Practitioner(org.hl7.fhir.dstu3.model.Practitioner) HumanName(org.hl7.fhir.dstu3.model.HumanName) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) Reference(org.hl7.fhir.dstu3.model.Reference) Patient(org.hl7.fhir.dstu3.model.Patient) IdType(org.hl7.fhir.dstu3.model.IdType)

Example 8 with HumanName

use of org.hl7.fhir.dstu3.model.HumanName in project gpconnect-demonstrator by nhsconnect.

the class PatientResourceProvider method IsActiveName.

private Boolean IsActiveName(HumanName name) {
    Period period = name.getPeriod();
    if (null == period) {
        return true;
    }
    Date start = period.getStart();
    Date end = period.getEnd();
    if ((null == end || end.after(new Date())) && (null == start || start.equals(new Date()) || start.before(new Date()))) {
        return true;
    }
    return false;
}
Also used : Period(org.hl7.fhir.dstu3.model.Period) Date(java.util.Date)

Example 9 with HumanName

use of org.hl7.fhir.dstu3.model.HumanName in project gpconnect-demonstrator by nhsconnect.

the class PatientResourceProvider method registerPatientResourceConverterToPatientDetail.

private PatientDetails registerPatientResourceConverterToPatientDetail(Patient patientResource) {
    PatientDetails patientDetails = new PatientDetails();
    HumanName name = patientResource.getNameFirstRep();
    String givenNames = name.getGiven().stream().map(n -> n.getValue()).collect(Collectors.joining(","));
    patientDetails.setForename(givenNames);
    patientDetails.setSurname(name.getFamily());
    patientDetails.setDateOfBirth(patientResource.getBirthDate());
    if (patientResource.getGender() != null) {
        patientDetails.setGender(patientResource.getGender().toString());
    }
    patientDetails.setNhsNumber(patientResource.getIdentifierFirstRep().getValue());
    Type multipleBirth = patientResource.getMultipleBirth();
    if (multipleBirth != null) {
        try {
            patientDetails.setMultipleBirth((multipleBirth));
        } catch (ClassCastException cce) {
            throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException("The multiple birth property is expected to be a boolean"), SystemCode.INVALID_RESOURCE, IssueType.INVALID);
        }
    }
    DateTimeType deceased = (DateTimeType) patientResource.getDeceased();
    if (deceased != null) {
        try {
            patientDetails.setDeceased((deceased.getValue()));
        } catch (ClassCastException cce) {
            throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException("The multiple deceased property is expected to be a datetime"), SystemCode.INVALID_RESOURCE, IssueType.INVALID);
        }
    }
    patientDetails.setRegistrationStartDateTime(new Date());
    // patientDetails.setRegistrationEndDateTime(getRegistrationEndDate(patientResource));
    patientDetails.setRegistrationStatus(ACTIVE_REGISTRATION_STATUS);
    patientDetails.setRegistrationType(TEMPORARY_RESIDENT_REGISTRATION_TYPE);
    return patientDetails;
}
Also used : IdParam(ca.uhn.fhir.rest.annotation.IdParam) ParametersParameterComponent(org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent) Type(org.hl7.fhir.dstu3.model.Type) Bundle(org.hl7.fhir.dstu3.model.Bundle) ContactDetail(org.hl7.fhir.dstu3.model.ContactDetail) AppointmentResourceProvider(uk.gov.hscic.appointments.AppointmentResourceProvider) MedicationAdministration(org.hl7.fhir.dstu3.model.MedicationAdministration) Date(java.util.Date) Identifier(org.hl7.fhir.dstu3.model.Identifier) Coding(org.hl7.fhir.dstu3.model.Coding) IdType(org.hl7.fhir.dstu3.model.IdType) Autowired(org.springframework.beans.factory.annotation.Autowired) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) Operation(ca.uhn.fhir.rest.annotation.Operation) Extension(org.hl7.fhir.dstu3.model.Extension) IdentifierUse(org.hl7.fhir.dstu3.model.Identifier.IdentifierUse) NhsCodeValidator(uk.gov.hscic.util.NhsCodeValidator) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) Locale(java.util.Locale) IResourceProvider(ca.uhn.fhir.rest.server.IResourceProvider) Map(java.util.Map) EnumSet(java.util.EnumSet) IdDt(ca.uhn.fhir.model.primitive.IdDt) Reference(org.hl7.fhir.dstu3.model.Reference) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) Set(java.util.Set) Count(ca.uhn.fhir.rest.annotation.Count) Collectors(java.util.stream.Collectors) Appointment(org.hl7.fhir.dstu3.model.Appointment) IssueType(org.hl7.fhir.dstu3.model.OperationOutcome.IssueType) AdministrativeGender(org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender) List(java.util.List) SortSpec(ca.uhn.fhir.rest.api.SortSpec) IdentifierValidator(uk.gov.hscic.common.validators.IdentifierValidator) PostConstruct(javax.annotation.PostConstruct) ContactPointSystem(org.hl7.fhir.dstu3.model.ContactPoint.ContactPointSystem) SystemCode(uk.gov.hscic.SystemCode) OptionalParam(ca.uhn.fhir.rest.annotation.OptionalParam) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) NameUse(org.hl7.fhir.dstu3.model.HumanName.NameUse) PatientSearch(uk.gov.hscic.patient.details.PatientSearch) AddressType(org.hl7.fhir.dstu3.model.Address.AddressType) MedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest) PatientStore(uk.gov.hscic.patient.details.PatientStore) HashMap(java.util.HashMap) PractitionerResourceProvider(uk.gov.hscic.practitioner.PractitionerResourceProvider) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RequiredParam(ca.uhn.fhir.rest.annotation.RequiredParam) Calendar(java.util.Calendar) UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) MedicationOrderResourceProvider(uk.gov.hscic.medications.MedicationOrderResourceProvider) AddressUse(org.hl7.fhir.dstu3.model.Address.AddressUse) Search(ca.uhn.fhir.rest.annotation.Search) Period(org.hl7.fhir.dstu3.model.Period) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) Read(ca.uhn.fhir.rest.annotation.Read) Practitioner(org.hl7.fhir.dstu3.model.Practitioner) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) Sort(ca.uhn.fhir.rest.annotation.Sort) PatientDetails(uk.gov.hscic.model.patient.PatientDetails) BundleType(org.hl7.fhir.dstu3.model.Bundle.BundleType) SystemURL(uk.gov.hscic.SystemURL) TokenParam(ca.uhn.fhir.rest.param.TokenParam) MedicationAdministrationResourceProvider(uk.gov.hscic.medications.MedicationAdministrationResourceProvider) OperationOutcomeFactory(uk.gov.hscic.OperationOutcomeFactory) Component(org.springframework.stereotype.Component) ResourceParam(ca.uhn.fhir.rest.annotation.ResourceParam) StaticElementsHelper(uk.gov.hscic.common.helpers.StaticElementsHelper) MedicationDispenseResourceProvider(uk.gov.hscic.medications.MedicationDispenseResourceProvider) Patient(org.hl7.fhir.dstu3.model.Patient) DateAndListParam(ca.uhn.fhir.rest.param.DateAndListParam) ContactPointUse(org.hl7.fhir.dstu3.model.ContactPoint.ContactPointUse) Parameters(org.hl7.fhir.dstu3.model.Parameters) OrganizationResourceProvider(uk.gov.hscic.organization.OrganizationResourceProvider) MedicationDispense(org.hl7.fhir.dstu3.model.MedicationDispense) FHIRException(org.hl7.fhir.exceptions.FHIRException) Collections(java.util.Collections) HumanName(org.hl7.fhir.dstu3.model.HumanName) HumanName(org.hl7.fhir.dstu3.model.HumanName) UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) Type(org.hl7.fhir.dstu3.model.Type) IdType(org.hl7.fhir.dstu3.model.IdType) IssueType(org.hl7.fhir.dstu3.model.OperationOutcome.IssueType) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) AddressType(org.hl7.fhir.dstu3.model.Address.AddressType) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) BundleType(org.hl7.fhir.dstu3.model.Bundle.BundleType) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) PatientDetails(uk.gov.hscic.model.patient.PatientDetails) Date(java.util.Date)

Aggregations

HumanName (org.hl7.fhir.dstu3.model.HumanName)8 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)4 IdType (org.hl7.fhir.dstu3.model.IdType)4 Patient (org.hl7.fhir.dstu3.model.Patient)4 Practitioner (org.hl7.fhir.dstu3.model.Practitioner)4 Count (ca.uhn.fhir.rest.annotation.Count)3 IdParam (ca.uhn.fhir.rest.annotation.IdParam)3 Read (ca.uhn.fhir.rest.annotation.Read)3 RequiredParam (ca.uhn.fhir.rest.annotation.RequiredParam)3 Search (ca.uhn.fhir.rest.annotation.Search)3 Sort (ca.uhn.fhir.rest.annotation.Sort)3 SortSpec (ca.uhn.fhir.rest.api.SortSpec)3 TokenParam (ca.uhn.fhir.rest.param.TokenParam)3 IResourceProvider (ca.uhn.fhir.rest.server.IResourceProvider)3 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 List (java.util.List)3 Locale (java.util.Locale)3 Collectors (java.util.stream.Collectors)3