Search in sources :

Example 1 with Identifier

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

the class OrganizationResourceProvider method getOrganizationsByODSCode.

@Search
public List<Organization> getOrganizationsByODSCode(@RequiredParam(name = Organization.SP_IDENTIFIER) TokenParam tokenParam, @Sort SortSpec sort, @Count Integer count) {
    if (StringUtils.isBlank(tokenParam.getSystem()) || StringUtils.isBlank(tokenParam.getValue())) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException("Missing identifier token"), SystemCode.INVALID_PARAMETER, IssueType.INVALID);
    }
    if (tokenParam.getSystem().equals(SystemURL.ID_ODS_ORGANIZATION_CODE) || tokenParam.getSystem().equals(SystemURL.ID_ODS_OLD_ORGANIZATION_CODE)) {
        List<Organization> organizationDetails = convertOrganizaitonDetailsListToOrganizationList(organizationSearch.findOrganizationDetailsByOrgODSCode(tokenParam.getValue()));
        if (organizationDetails.isEmpty()) {
            return null;
        }
        if (sort != null && sort.getParamName().equalsIgnoreCase(Location.SP_STATUS)) {
            Collections.sort(organizationDetails, (Organization a, Organization b) -> {
                String aStatus = a.getName();
                String bStatus = b.getName();
                if (aStatus == null && bStatus == null) {
                    return 0;
                }
                if (aStatus == null && bStatus != null) {
                    return -1;
                }
                if (aStatus != null && bStatus == null) {
                    return 1;
                }
                return aStatus.compareToIgnoreCase(bStatus);
            });
        }
        // Update startIndex if we do paging
        return count != null ? organizationDetails.subList(0, count) : organizationDetails;
    } else {
        throw OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException("Invalid system code"), SystemCode.INVALID_PARAMETER, IssueType.INVALID);
    }
}
Also used : Organization(org.hl7.fhir.dstu3.model.Organization) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) Search(ca.uhn.fhir.rest.annotation.Search)

Example 2 with Identifier

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

the class PatientResourceProvider method setStaticPatientData.

private Patient setStaticPatientData(Patient patient) {
    patient.setLanguage(("en-GB"));
    patient.addExtension(createCodingExtension("CG", "Greek Cypriot", SystemURL.CS_CC_ETHNIC_CATEGORY, SystemURL.SD_CC_EXT_ETHNIC_CATEGORY));
    patient.addExtension(createCodingExtension("SomeSnomedCode", "Some Snomed Code", SystemURL.CS_CC_RELIGIOUS_AFFILI, SystemURL.SD_CC_EXT_RELIGIOUS_AFFILI));
    patient.addExtension(new Extension(SystemURL.SD_PATIENT_CADAVERIC_DON, new BooleanType(false)));
    patient.addExtension(createCodingExtension("H", "UK Resident", SystemURL.CS_CC_RESIDENTIAL_STATUS, SystemURL.SD_CC_EXT_RESIDENTIAL_STATUS));
    patient.addExtension(createCodingExtension("3", "To pay hotel fees only", SystemURL.CS_CC_TREATMENT_CAT, SystemURL.SD_CC_EXT_TREATMENT_CAT));
    Extension nhsCommExtension = new Extension();
    nhsCommExtension.setUrl(SystemURL.SD_CC_EXT_NHS_COMMUNICATION);
    nhsCommExtension.addExtension(createCodingExtension("en", "English", SystemURL.CS_CC_HUMAN_LANG, SystemURL.SD_CC_EXT_COMM_LANGUAGE));
    nhsCommExtension.addExtension(new Extension(SystemURL.SD_CC_COMM_PREFERRED, new BooleanType(false)));
    nhsCommExtension.addExtension(createCodingExtension("RWR", "Received written", SystemURL.CS_CC_LANG_ABILITY_MODE, SystemURL.SD_CC_MODE_OF_COMM));
    nhsCommExtension.addExtension(createCodingExtension("E", "Excellent", SystemURL.CS_CC_LANG_ABILITY_PROFI, SystemURL.SD_CC_COMM_PROFICIENCY));
    nhsCommExtension.addExtension(new Extension(SystemURL.SD_CC_INTERPRETER_REQUIRED, new BooleanType(false)));
    patient.addExtension(nhsCommExtension);
    Identifier localIdentifier = new Identifier();
    localIdentifier.setUse(IdentifierUse.USUAL);
    localIdentifier.setSystem(SystemURL.ID_LOCAL_PATIENT_IDENTIFIER);
    localIdentifier.setValue("123456");
    CodeableConcept liType = new CodeableConcept();
    Coding liTypeCoding = new Coding();
    liTypeCoding.setCode("EN");
    liTypeCoding.setDisplay("Employer number");
    liTypeCoding.setSystem(SystemURL.VS_IDENTIFIER_TYPE);
    liType.addCoding(liTypeCoding);
    localIdentifier.setType(liType);
    localIdentifier.setAssigner(new Reference("Organization/1"));
    patient.addIdentifier(localIdentifier);
    Calendar calendar = Calendar.getInstance();
    calendar.set(2017, 1, 1);
    DateTimeDt endDate = new DateTimeDt(calendar.getTime());
    calendar.set(2016, 1, 1);
    DateTimeDt startDate = new DateTimeDt(calendar.getTime());
    Period pastPeriod = new Period().setStart(calendar.getTime()).setEnd(calendar.getTime());
    patient.addName().setFamily("AnotherOfficialFamilyName").addGiven("AnotherOfficialGivenName").setUse(NameUse.OFFICIAL).setPeriod(pastPeriod);
    patient.addName().setFamily("AdditionalFamily").addGiven("AdditionalGiven").setUse(NameUse.TEMP);
    patient.addTelecom(staticElHelper.getValidTelecom());
    patient.addAddress(staticElHelper.getValidAddress());
    return patient;
}
Also used : Extension(org.hl7.fhir.dstu3.model.Extension) Identifier(org.hl7.fhir.dstu3.model.Identifier) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) Coding(org.hl7.fhir.dstu3.model.Coding) Reference(org.hl7.fhir.dstu3.model.Reference) Calendar(java.util.Calendar) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) Period(org.hl7.fhir.dstu3.model.Period) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 3 with Identifier

use of org.hl7.fhir.dstu3.model.Identifier 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 4 with Identifier

use of org.hl7.fhir.dstu3.model.Identifier in project bunsen by cerner.

the class TestData method newObservation.

/**
 * Returns a FHIR Observation for testing purposes.
 */
public static Observation newObservation() {
    // Observation based on https://www.hl7.org/FHIR/observation-example-bloodpressure.json.html
    Observation observation = new Observation();
    observation.setId("blood-pressure");
    Identifier identifier = observation.addIdentifier();
    identifier.setSystem("urn:ietf:rfc:3986");
    identifier.setValue("urn:uuid:187e0c12-8dd2-67e2-99b2-bf273c878281");
    observation.setStatus(Observation.ObservationStatus.FINAL);
    Quantity quantity = new Quantity();
    quantity.setValue(new java.math.BigDecimal("123.45"));
    quantity.setUnit("mm[Hg]");
    observation.setValue(quantity);
    return observation;
}
Also used : Identifier(org.hl7.fhir.dstu3.model.Identifier) Observation(org.hl7.fhir.dstu3.model.Observation) Quantity(org.hl7.fhir.dstu3.model.Quantity)

Example 5 with Identifier

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

the class AppointmentResourceProvider method appointmentResourceConverterToAppointmentDetail.

/**
 * fhir resource Appointment to AppointmentDetail
 *
 * @param appointment Resource
 * @return populated AppointmentDetail
 */
private AppointmentDetail appointmentResourceConverterToAppointmentDetail(Appointment appointment) {
    appointmentValidation.validateAppointmentExtensions(appointment.getExtension());
    if (appointmentValidation.appointmentDescriptionTooLong(appointment)) {
        throwUnprocessableEntity422_InvalidResourceException("Appointment description cannot be greater then " + APPOINTMENT_DESCRIPTION_LENGTH + " characters");
    }
    AppointmentDetail appointmentDetail = new AppointmentDetail();
    Long id = appointment.getIdElement().getIdPartAsLong();
    appointmentDetail.setId(id);
    appointmentDetail.setLastUpdated(getLastUpdated(appointment.getMeta().getLastUpdated()));
    List<Extension> cnlExtension = appointment.getExtensionsByUrl(SystemURL.SD_EXTENSION_GPC_APPOINTMENT_CANCELLATION_REASON);
    if (cnlExtension != null && !cnlExtension.isEmpty()) {
        IBaseDatatype value = cnlExtension.get(0).getValue();
        if (null == value) {
            throwInvalidRequest400_BadRequestException("Cancellation reason missing.");
        }
        appointmentDetail.setCancellationReason(value.toString());
    }
    appointmentDetail.setStatus(appointment.getStatus().toString().toLowerCase(Locale.UK));
    appointmentDetail.setMinutesDuration(appointment.getMinutesDuration());
    appointmentDetail.setPriority(appointment.getPriority());
    appointmentDetail.setStartDateTime(appointment.getStart());
    appointmentDetail.setEndDateTime(appointment.getEnd());
    List<Long> slotIds = new ArrayList<>();
    for (Reference slotReference : appointment.getSlot()) {
        // #200 check slots for absolute references
        checkReferenceIsRelative(slotReference.getReference());
        try {
            String here = slotReference.getReference().substring("Slot/".length());
            Long slotId = new Long(here);
            slotIds.add(slotId);
        } catch (NumberFormatException ex) {
            throwUnprocessableEntity422_InvalidResourceException(String.format("The slot reference value data type for %s is not valid.", slotReference.getReference()));
        }
    }
    appointmentDetail.setSlotIds(slotIds);
    if (appointmentValidation.appointmentCommentTooLong(appointment)) {
        throwUnprocessableEntity422_InvalidResourceException("Appointment comment cannot be greater than " + APPOINTMENT_COMMENT_LENGTH + " characters");
    }
    appointmentDetail.setComment(appointment.getComment());
    appointmentDetail.setDescription(appointment.getDescription());
    for (AppointmentParticipantComponent participant : appointment.getParticipant()) {
        if (participant.getActor() != null) {
            String participantReference = participant.getActor().getReference();
            String actorIdString = participantReference.substring(participantReference.lastIndexOf("/") + 1);
            Long actorId;
            if (actorIdString.equals("null")) {
                actorId = null;
            } else {
                actorId = Long.valueOf(actorIdString);
            }
            if (participantReference.contains("Patient/")) {
                appointmentDetail.setPatientId(actorId);
            } else if (participantReference.contains("Practitioner/")) {
                appointmentDetail.setPractitionerId(actorId);
            } else if (participantReference.contains("Location/")) {
                appointmentDetail.setLocationId(actorId);
            }
        } else {
            throwUnprocessableEntity422_InvalidResourceException("Participant Actor cannot be null");
        }
    }
    if (appointment.getCreated() != null) {
        Date created = appointment.getCreated();
        appointmentDetail.setCreated(created);
    }
    // #200 check extensions for absolute references
    List<Extension> extensions = appointment.getExtension();
    for (Extension extension : extensions) {
        try {
            Reference reference = (Reference) extension.getValue();
            if (reference != null) {
                checkReferenceIsRelative(reference.getReference());
            }
        } catch (ClassCastException ex) {
        }
    }
    List<Resource> contained = appointment.getContained();
    if (contained != null && !contained.isEmpty()) {
        Resource org = contained.get(0);
        Organization bookingOrgRes = (Organization) org;
        BookingOrgDetail bookingOrgDetail = new BookingOrgDetail();
        appointmentValidation.validateBookingOrganizationValuesArePresent(bookingOrgRes);
        bookingOrgDetail.setName(bookingOrgRes.getName());
        // #198 add system and optional use type. Pick system phone if > 1 and available otherwise use the one supplied
        Iterator<ContactPoint> iter = bookingOrgRes.getTelecom().iterator();
        ContactPoint telecom = bookingOrgRes.getTelecomFirstRep();
        while (iter.hasNext()) {
            ContactPoint thisTelecom = iter.next();
            if (thisTelecom.getSystem() == ContactPoint.ContactPointSystem.PHONE) {
                telecom = thisTelecom;
                break;
            }
        }
        bookingOrgDetail.setTelephone(telecom.getValue());
        bookingOrgDetail.setSystem(telecom.getSystem().toString());
        if (telecom.getUse() != null && !telecom.getUse().toString().trim().isEmpty()) {
            bookingOrgDetail.setUsetype(telecom.getUse().toString());
        }
        if (!bookingOrgRes.getIdentifier().isEmpty()) {
            bookingOrgDetail.setOrgCode(bookingOrgRes.getIdentifierFirstRep().getValue());
            String system = bookingOrgRes.getIdentifierFirstRep().getSystem();
            // check that organization identifier system is https://fhir.nhs.uk/Id/ods-organization-code
            if (system != null && !system.trim().isEmpty()) {
                if (!system.equals(ID_ODS_ORGANIZATION_CODE)) {
                    throwUnprocessableEntity422_InvalidResourceException("Appointment organisation identifier system must be an ODS code!");
                }
            } else {
                throwUnprocessableEntity422_InvalidResourceException("Appointment organisation identifier system must be populated!");
            }
        }
        bookingOrgDetail.setAppointmentDetail(appointmentDetail);
        appointmentDetail.setBookingOrganization(bookingOrgDetail);
        // 1.2.7
        appointmentDetail.setServiceCategory(appointment.getServiceCategory().getText());
        appointmentDetail.setServiceType(appointment.getServiceTypeFirstRep().getText());
    }
    return appointmentDetail;
}
Also used : AppointmentParticipantComponent(org.hl7.fhir.dstu3.model.Appointment.AppointmentParticipantComponent) IBaseDatatype(org.hl7.fhir.instance.model.api.IBaseDatatype) AppointmentDetail(uk.gov.hscic.model.appointment.AppointmentDetail) BookingOrgDetail(uk.gov.hscic.model.appointment.BookingOrgDetail)

Aggregations

IdType (org.hl7.fhir.dstu3.model.IdType)7 Identifier (org.hl7.fhir.dstu3.model.Identifier)7 ArrayList (java.util.ArrayList)5 Organization (org.hl7.fhir.dstu3.model.Organization)5 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)4 Coding (org.hl7.fhir.dstu3.model.Coding)4 Extension (org.hl7.fhir.dstu3.model.Extension)4 UnprocessableEntityException (ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException)3 Period (org.hl7.fhir.dstu3.model.Period)3 Reference (org.hl7.fhir.dstu3.model.Reference)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 Search (ca.uhn.fhir.rest.annotation.Search)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 AppointmentParticipantComponent (org.hl7.fhir.dstu3.model.Appointment.AppointmentParticipantComponent)2 Location (org.hl7.fhir.dstu3.model.Location)2 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)1 IdDt (ca.uhn.fhir.model.primitive.IdDt)1 Count (ca.uhn.fhir.rest.annotation.Count)1 IdParam (ca.uhn.fhir.rest.annotation.IdParam)1