Search in sources :

Example 1 with OrganizationDetails

use of uk.gov.hscic.model.organization.OrganizationDetails in project gpconnect-demonstrator by nhsconnect.

the class OrganizationEntityToObjectTransformer method transform.

@Override
public OrganizationDetails transform(final OrganizationEntity organizationEntity) {
    OrganizationDetails organization = new OrganizationDetails();
    organization.setId(organizationEntity.getId());
    organization.setOrgCode(organizationEntity.getOrgCode());
    organization.setOrgName(organizationEntity.getOrgName());
    organization.setLastUpdated(organizationEntity.getLastUpdated());
    return organization;
}
Also used : OrganizationDetails(uk.gov.hscic.model.organization.OrganizationDetails)

Example 2 with OrganizationDetails

use of uk.gov.hscic.model.organization.OrganizationDetails in project gpconnect-demonstrator by nhsconnect.

the class OrganizationResourceProvider method convertOrganizaitonDetailsListToOrganizationList.

private List<Organization> convertOrganizaitonDetailsListToOrganizationList(List<OrganizationDetails> organizationDetails) {
    Map<String, Organization> map = new HashMap<>();
    for (OrganizationDetails organizationDetail : organizationDetails) {
        String mapKey = String.format("%s", organizationDetail.getOrgCode());
        if (map.containsKey(mapKey)) {
            continue;
        }
        Identifier identifier = new Identifier().setSystem(SystemURL.ID_ODS_ORGANIZATION_CODE).setValue(organizationDetail.getOrgCode());
        Organization organization = new Organization().setName(organizationDetail.getOrgName()).addIdentifier(identifier);
        String resourceId = String.valueOf(organizationDetail.getId());
        String versionId = String.valueOf(organizationDetail.getLastUpdated().getTime());
        String resourceType = organization.getResourceType().toString();
        IdType id = new IdType(resourceType, resourceId, versionId);
        organization.setId(id);
        organization.getMeta().setVersionId(versionId);
        organization.getMeta().setLastUpdated(organizationDetail.getLastUpdated());
        organization.getMeta().addProfile(SystemURL.SD_GPC_ORGANIZATION);
        organization = addAdditionalProperties(organization);
        map.put(mapKey, organization);
    }
    return new ArrayList<>(map.values());
}
Also used : Organization(org.hl7.fhir.dstu3.model.Organization) Identifier(org.hl7.fhir.dstu3.model.Identifier) HashMap(java.util.HashMap) OrganizationDetails(uk.gov.hscic.model.organization.OrganizationDetails) ArrayList(java.util.ArrayList) IdType(org.hl7.fhir.dstu3.model.IdType)

Example 3 with OrganizationDetails

use of uk.gov.hscic.model.organization.OrganizationDetails in project gpconnect-demonstrator by nhsconnect.

the class OrganizationResourceProvider method getOrganizationById.

@Read(version = true)
public Organization getOrganizationById(@IdParam IdType organizationId) {
    OrganizationDetails organizationDetails = null;
    String idPart = organizationId.getIdPart();
    try {
        Long id = Long.parseLong(idPart);
        organizationDetails = organizationSearch.findOrganizationDetails(id);
        if (organizationDetails == null) {
            throw OperationOutcomeFactory.buildOperationOutcomeException(new ResourceNotFoundException("No organization details found for organization ID: " + idPart), SystemCode.ORGANISATION_NOT_FOUND, IssueType.INVALID);
        }
    } catch (NumberFormatException nfe) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(new ResourceNotFoundException("No organization details found for organization ID: " + idPart), SystemCode.ORGANISATION_NOT_FOUND, IssueType.INVALID);
    }
    return IdentifierValidator.versionComparison(organizationId, convertOrganizaitonDetailsListToOrganizationList(Collections.singletonList(organizationDetails)).get(0));
}
Also used : OrganizationDetails(uk.gov.hscic.model.organization.OrganizationDetails) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) Read(ca.uhn.fhir.rest.annotation.Read)

Example 4 with OrganizationDetails

use of uk.gov.hscic.model.organization.OrganizationDetails in project gpconnect-demonstrator by nhsconnect.

the class PopulateSlotBundle method populateBundle.

public void populateBundle(Bundle bundle, OperationOutcome operationOutcome, Date planningHorizonStart, Date planningHorizonEnd, boolean actorPractitioner, boolean actorLocation, String bookingOdsCode, String bookingOrgType) {
    bundle.getMeta().addProfile(SystemURL.SD_GPC_SRCHSET_BUNDLE);
    List<Location> locations = locationResourceProvider.getAllLocationDetails();
    BundleEntryComponent locationEntry = new BundleEntryComponent();
    locationEntry.setResource(locations.get(0));
    locationEntry.setFullUrl("Location/" + locations.get(0).getIdElement().getIdPart());
    // find the organization from the ods code
    List<OrganizationDetails> organizations = organizationSearch.findOrganizationDetailsByOrgODSCode(bookingOdsCode);
    // schedules
    List<Schedule> schedules = scheduleResourceProvider.getSchedulesForLocationId(locations.get(0).getIdElement().getIdPart(), planningHorizonStart, planningHorizonEnd);
    if (!schedules.isEmpty()) {
        for (Schedule schedule : schedules) {
            schedule.getMeta().addProfile(SystemURL.SD_GPC_SCHEDULE);
            BundleEntryComponent scheduleEntry = new BundleEntryComponent();
            scheduleEntry.setResource(schedule);
            scheduleEntry.setFullUrl("Schedule/" + schedule.getIdElement().getIdPart());
            // practitioners
            List<Reference> practitionerActors = scheduleResourceProvider.getPractitionerReferences(schedule);
            if (!practitionerActors.isEmpty()) {
                for (Reference practitionerActor : practitionerActors) {
                    Practitioner practitioner = practitionerResourceProvider.getPractitionerById((IdType) practitionerActor.getReferenceElement());
                    if (practitioner == null) {
                        Coding errorCoding = new Coding().setSystem(SystemURL.VS_GPC_ERROR_WARNING_CODE).setCode(SystemCode.REFERENCE_NOT_FOUND);
                        CodeableConcept errorCodableConcept = new CodeableConcept().addCoding(errorCoding);
                        errorCodableConcept.setText("Invalid Reference");
                        operationOutcome.addIssue().setSeverity(IssueSeverity.ERROR).setCode(IssueType.NOTFOUND).setDetails(errorCodableConcept);
                        throw new ResourceNotFoundException("Practitioner Reference returning null");
                    }
                    if (actorPractitioner == true) {
                        BundleEntryComponent practionerEntry = new BundleEntryComponent();
                        practionerEntry.setResource(practitioner);
                        practionerEntry.setFullUrl("Practitioner/" + practitioner.getIdElement().getIdPart());
                        bundle.addEntry(practionerEntry);
                    }
                }
            }
            Set<Slot> slots = new HashSet<Slot>();
            if (!organizations.isEmpty()) {
                slots.addAll(slotResourceProvider.getSlotsForScheduleIdAndOrganizationId(schedule.getIdElement().getIdPart(), planningHorizonStart, planningHorizonEnd, organizations.get(0).getId()));
            }
            slots.addAll(slotResourceProvider.getSlotsForScheduleIdAndOrganizationType(schedule.getIdElement().getIdPart(), planningHorizonStart, planningHorizonEnd, bookingOrgType));
            String freeBusyType = "FREE";
            if (!slots.isEmpty()) {
                for (Slot slot : slots) {
                    if (freeBusyType.equalsIgnoreCase(slot.getStatus().toString())) {
                        BundleEntryComponent slotEntry = new BundleEntryComponent();
                        slotEntry.setResource(slot);
                        slotEntry.setFullUrl("Slot/" + slot.getIdElement().getIdPart());
                        bundle.addEntry(slotEntry);
                        bundle.addEntry(scheduleEntry);
                        if (actorLocation == true) {
                            bundle.addEntry(locationEntry);
                        }
                    }
                }
            }
        }
    }
}
Also used : Reference(org.hl7.fhir.dstu3.model.Reference) OrganizationDetails(uk.gov.hscic.model.organization.OrganizationDetails) Practitioner(org.hl7.fhir.dstu3.model.Practitioner) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.dstu3.model.Coding) Schedule(org.hl7.fhir.dstu3.model.Schedule) Slot(org.hl7.fhir.dstu3.model.Slot) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) Location(org.hl7.fhir.dstu3.model.Location) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) HashSet(java.util.HashSet)

Aggregations

OrganizationDetails (uk.gov.hscic.model.organization.OrganizationDetails)4 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)2 Read (ca.uhn.fhir.rest.annotation.Read)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 BundleEntryComponent (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent)1 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)1 Coding (org.hl7.fhir.dstu3.model.Coding)1 IdType (org.hl7.fhir.dstu3.model.IdType)1 Identifier (org.hl7.fhir.dstu3.model.Identifier)1 Location (org.hl7.fhir.dstu3.model.Location)1 Organization (org.hl7.fhir.dstu3.model.Organization)1 Practitioner (org.hl7.fhir.dstu3.model.Practitioner)1 Reference (org.hl7.fhir.dstu3.model.Reference)1 Schedule (org.hl7.fhir.dstu3.model.Schedule)1 Slot (org.hl7.fhir.dstu3.model.Slot)1