Search in sources :

Example 91 with Location

use of com.ibm.watson.compare_comply.v1.model.Location in project metacat by Netflix.

the class S3ConnectorInfoConverter method toStorageInfo.

/**
 * Converts from s3 table info to storage info.
 * @param table table info
 * @return table info
 */
StorageInfo toStorageInfo(final Table table) {
    StorageInfo result = null;
    final Location location = table.getLocation();
    if (location != null) {
        final Map<String, String> infoParameters = Maps.newHashMap();
        result = new StorageInfo();
        result.setUri(location.getUri());
        final Info info = location.getInfo();
        if (info != null) {
            result.setOwner(info.getOwner());
            result.setInputFormat(info.getInputFormat());
            result.setOutputFormat(info.getOutputFormat());
            result.setSerializationLib(info.getSerializationLib());
            if (info.getParameters() != null) {
                infoParameters.putAll(info.getParameters());
            }
        }
        result.setSerdeInfoParameters(infoParameters);
        result.setParameters(Maps.newHashMap());
    }
    return result;
}
Also used : StorageInfo(com.netflix.metacat.common.server.connectors.model.StorageInfo) AuditInfo(com.netflix.metacat.common.server.connectors.model.AuditInfo) DatabaseInfo(com.netflix.metacat.common.server.connectors.model.DatabaseInfo) FieldInfo(com.netflix.metacat.common.server.connectors.model.FieldInfo) PartitionInfo(com.netflix.metacat.common.server.connectors.model.PartitionInfo) StorageInfo(com.netflix.metacat.common.server.connectors.model.StorageInfo) Info(com.netflix.metacat.connector.s3.model.Info) TableInfo(com.netflix.metacat.common.server.connectors.model.TableInfo) Location(com.netflix.metacat.connector.s3.model.Location)

Example 92 with Location

use of com.ibm.watson.compare_comply.v1.model.Location in project metacat by Netflix.

the class S3ConnectorInfoConverter method getOwner.

/**
 * Gets the owner for the given table.
 * @param table table info
 * @return owner name
 */
public String getOwner(final Table table) {
    String result = null;
    final Location location = table.getLocation();
    if (location != null) {
        final Info info = location.getInfo();
        if (info != null) {
            result = info.getOwner();
        }
    }
    return result;
}
Also used : AuditInfo(com.netflix.metacat.common.server.connectors.model.AuditInfo) DatabaseInfo(com.netflix.metacat.common.server.connectors.model.DatabaseInfo) FieldInfo(com.netflix.metacat.common.server.connectors.model.FieldInfo) PartitionInfo(com.netflix.metacat.common.server.connectors.model.PartitionInfo) StorageInfo(com.netflix.metacat.common.server.connectors.model.StorageInfo) Info(com.netflix.metacat.connector.s3.model.Info) TableInfo(com.netflix.metacat.common.server.connectors.model.TableInfo) Location(com.netflix.metacat.connector.s3.model.Location)

Example 93 with Location

use of com.ibm.watson.compare_comply.v1.model.Location in project gpconnect-demonstrator by nhsconnect.

the class LocationResourceProvider method locationDetailsToLocation.

/**
 * convert locationDetails to fhir resource
 * @param locationDetails
 * @return Location resource
 */
private Location locationDetailsToLocation(LocationDetails locationDetails) {
    Location location = new Location();
    String resourceId = String.valueOf(locationDetails.getId());
    String versionId = String.valueOf(locationDetails.getLastUpdated().getTime());
    String resourceType = location.getResourceType().toString();
    IdType id = new IdType(resourceType, resourceId, versionId);
    location.setId(id);
    location.getMeta().setVersionId(versionId);
    location.getMeta().setLastUpdated(locationDetails.getLastUpdated());
    location.getMeta().addProfile(SystemURL.SD_GPC_LOCATION);
    location.setName(locationDetails.getName());
    // #207 no site code
    // location.setIdentifier(Collections.singletonList(new Identifier().setSystem(SystemURL.ID_ODS_SITE_CODE).setValue(locationDetails.getSiteOdsCode())));
    // #246 remove type element
    // Coding locationCommTypeCode = new Coding();
    // locationCommTypeCode.setCode("COMM");
    // locationCommTypeCode.setSystem(SystemURL.VS_CC_SER_DEL_LOCROLETYPE);
    // locationCommTypeCode.setDisplay("Community Location");
    // 
    // Coding locationGachTypeCode = new Coding();
    // locationGachTypeCode.setCode("GACH");
    // locationGachTypeCode.setSystem(SystemURL.VS_CC_SER_DEL_LOCROLETYPE);
    // locationGachTypeCode.setDisplay("Hospitals; General Acute Care Hospital");
    // 
    // @SuppressWarnings("deprecation")
    // CodeableConcept locationType = new CodeableConcept();
    // locationType.addCoding(locationCommTypeCode);
    // locationType.addCoding(locationGachTypeCode);
    // location.setType(locationType);
    Organization orgz = FindOrganization(locationDetails.getOrgOdsCode());
    if (orgz != null) {
        Reference mngOrg = new Reference();
        mngOrg.setReference(orgz.getId());
        // #246 remove display element
        // mngOrg.setDisplay(orgz.getName());
        location.setManagingOrganization(mngOrg);
    }
    EnumSet<LocationStatus> statusList = EnumSet.allOf(LocationStatus.class);
    LocationStatus locationStatus = null;
    String status = locationDetails.getStatus();
    if (status != null) {
        for (LocationStatus statusItem : statusList) {
            if (statusItem.toCode().equalsIgnoreCase(status)) {
                locationStatus = statusItem;
                break;
            }
        }
    }
    location.setAddress(createAddress(locationDetails));
    location.setStatus(locationStatus);
    return location;
}
Also used : Organization(org.hl7.fhir.dstu3.model.Organization) Reference(org.hl7.fhir.dstu3.model.Reference) LocationStatus(org.hl7.fhir.dstu3.model.Location.LocationStatus) Location(org.hl7.fhir.dstu3.model.Location) IdType(org.hl7.fhir.dstu3.model.IdType)

Example 94 with Location

use of com.ibm.watson.compare_comply.v1.model.Location in project gpconnect-demonstrator by nhsconnect.

the class PopulateSlotBundle method populateBundle.

/**
 * @param bundle Bundle resource to populate
 * @param operationOutcome
 * @param planningHorizonStart Date
 * @param planningHorizonEnd Date
 * @param actorPractitioner boolean
 * @param actorLocation boolean
 * @param managingOrganisation boolean
 * @param bookingOdsCode String
 * @param bookingOrgType String eg "urgent-care"
 */
public void populateBundle(Bundle bundle, OperationOutcome operationOutcome, Date planningHorizonStart, Date planningHorizonEnd, boolean actorPractitioner, boolean actorLocation, boolean managingOrganisation, String bookingOdsCode, String bookingOrgType) {
    bundle.getMeta().addProfile(SystemURL.SD_GPC_SRCHSET_BUNDLE);
    // TODO remove hard coding pick up from providerRouting.json ?
    final String OUR_ODS_CODE = "A20047";
    // find all locations for this ODS practice code and construct Resources for them
    // #144 generalise to handle 1..n locations for a practice
    HashMap<String, BundleEntryComponent> locationEntries = new HashMap<>();
    for (LocationDetails aLocationDetail : locationSearch.findAllLocations()) {
        if (aLocationDetail.getOrgOdsCode().equals(OUR_ODS_CODE)) {
            Location aLocationResource = locationResourceProvider.getLocationById(new IdType(aLocationDetail.getId()));
            BundleEntryComponent locationEntry = new BundleEntryComponent();
            locationEntry.setResource(aLocationResource);
            // #202 use full urls
            // #215 full url removed completely
            // locationEntry.setFullUrl(serverBaseUrl + "Location/" + aLocationResource.getIdElement().getIdPart());
            locationEntries.put(aLocationResource.getIdElement().getIdPart(), locationEntry);
        }
    }
    // find the provider organization from the ods code
    List<OrganizationDetails> ourOrganizationsDetails = organizationSearch.findOrganizationDetailsByOrgODSCode(OUR_ODS_CODE);
    OrganizationDetails ourOrganizationDetails = null;
    if (!ourOrganizationsDetails.isEmpty()) {
        // at 1.2.2 these are added regardless of the status of the relevant parameter
        // Just picks the first organization. There should only be one.
        ourOrganizationDetails = ourOrganizationsDetails.get(0);
    } else {
    // do something here .. should never happen
    }
    // find the bookng organization from the ods code
    List<OrganizationDetails> bookingOrganizationsDetails = organizationSearch.findOrganizationDetailsByOrgODSCode(bookingOdsCode);
    OrganizationDetails bookingOrganizationDetails = null;
    if (!bookingOrganizationsDetails.isEmpty()) {
        // at 1.2.2 these are added regardless of the status of the relevant parameter
        // Just picks the first organization. There should only be one.
        bookingOrganizationDetails = bookingOrganizationsDetails.get(0);
    }
    HashSet<BundleEntryComponent> addedSchedule = new HashSet<>();
    HashSet<BundleEntryComponent> addedLocation = new HashSet<>();
    HashSet<String> addedPractitioner = new HashSet<>();
    HashSet<String> addedOrganization = new HashSet<>();
    // issue #165 don't add duplicate slots, hashSet contains slot id as String
    HashSet<String> addedSlot = new HashSet<>();
    // #144 process all locations
    for (String locationId : locationEntries.keySet()) {
        // process the schedules
        for (Schedule schedule : scheduleResourceProvider.getSchedulesForLocationId(locationId, planningHorizonStart, planningHorizonEnd)) {
            boolean slotsAdded = false;
            schedule.getMeta().addProfile(SystemURL.SD_GPC_SCHEDULE);
            BundleEntryComponent scheduleEntry = new BundleEntryComponent();
            scheduleEntry.setResource(schedule);
            // #202 use full urls
            // #215 full url removed completely
            // scheduleEntry.setFullUrl(serverBaseUrl + "Schedule/" + schedule.getIdElement().getIdPart());
            // This Set does not work as expected because Slot does not implement hashCode
            // so the second set call to getSlots returns different objects with the same slot id
            Set<Slot> slots = new HashSet<>();
            // 
            if (bookingOrgType.isEmpty() && bookingOdsCode.isEmpty()) {
                // OPTION 1 get slots Specfying  neither org type nor org code
                slots.addAll(slotResourceProvider.getSlotsForScheduleIdNoOrganizationTypeOrODS(schedule.getIdElement().getIdPart(), planningHorizonStart, planningHorizonEnd));
            } else if (!bookingOrgType.isEmpty() && bookingOdsCode.isEmpty()) {
                // OPTION 2 organisation type only
                for (Slot slot : slotResourceProvider.getSlotsForScheduleId(schedule.getIdElement().getIdPart(), planningHorizonStart, planningHorizonEnd)) {
                    SlotDetail slotDetail = slotSearch.findSlotByID(Long.parseLong(slot.getId()));
                    if (slotDetail.getOrganizationIds().isEmpty() && (slotDetail.getOrganizationTypes().isEmpty() || slotDetail.getOrganizationTypes().contains(bookingOrgType))) {
                        slots.add(slot);
                    }
                }
            } else if (!bookingOdsCode.isEmpty() && bookingOrgType.isEmpty()) {
                // OPTION 3 org code only
                for (Slot slot : slotResourceProvider.getSlotsForScheduleId(schedule.getIdElement().getIdPart(), planningHorizonStart, planningHorizonEnd)) {
                    SlotDetail slotDetail = slotSearch.findSlotByID(Long.parseLong(slot.getId()));
                    if (slotDetail.getOrganizationTypes().isEmpty() && (slotDetail.getOrganizationIds().isEmpty() || bookingOrganizationDetails != null && slotDetail.getOrganizationIds().contains(bookingOrganizationDetails.getId()))) {
                        slots.add(slot);
                    }
                }
            } else if (!bookingOrgType.isEmpty() && !bookingOdsCode.isEmpty()) {
                // OPTION 4 both org code and org type
                for (Slot slot : slotResourceProvider.getSlotsForScheduleId(schedule.getIdElement().getIdPart(), planningHorizonStart, planningHorizonEnd)) {
                    SlotDetail slotDetail = slotSearch.findSlotByID(Long.parseLong(slot.getId()));
                    if (((slotDetail.getOrganizationTypes().isEmpty() || slotDetail.getOrganizationTypes().contains(bookingOrgType))) && (slotDetail.getOrganizationIds().isEmpty() || bookingOrganizationDetails != null && slotDetail.getOrganizationIds().contains(bookingOrganizationDetails.getId()))) {
                        slots.add(slot);
                    }
                }
            }
            // added at 1.2.2 add the organisation but only if there are some slots available
            if (slots.size() > 0 && ourOrganizationDetails != null && !addedOrganization.contains(ourOrganizationDetails.getOrgCode())) {
                addOrganisation(ourOrganizationDetails, bundle);
                addedOrganization.add(ourOrganizationDetails.getOrgCode());
            }
            String freeBusyType = "FREE";
            // process all the slots to be returned
            for (Slot slot : slots) {
                if (freeBusyType.equalsIgnoreCase(slot.getStatus().toString())) {
                    String slotId = slot.getIdElement().getIdPart();
                    if (!addedSlot.contains(slotId)) {
                        BundleEntryComponent slotEntry = new BundleEntryComponent();
                        slotEntry.setResource(slot);
                        // #202 use full urls
                        // #215 full url removed completely
                        // slotEntry.setFullUrl(serverBaseUrl + "Slot/" + slotId);
                        bundle.addEntry(slotEntry);
                        addedSlot.add(slotId);
                        slotsAdded = true;
                    }
                    if (!addedSchedule.contains(scheduleEntry)) {
                        // only add a schedule if there's a reference to it and only add it once
                        bundle.addEntry(scheduleEntry);
                        addedSchedule.add(scheduleEntry);
                    }
                    if (actorLocation == true) {
                        // only add a unique location once
                        if (!addedLocation.contains(locationEntries.get(locationId))) {
                            bundle.addEntry(locationEntries.get(locationId));
                            addedLocation.add(locationEntries.get(locationId));
                        }
                    }
                }
            // if free/busy status matches
            }
            // # 193 for each schedule only add a practitioner if there have been some slots added.
            if (slotsAdded) {
                // practitioners for this schedule
                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) {
                            if (!addedPractitioner.contains(practitioner.getIdElement().getIdPart())) {
                                addPractitioner(practitioner, bundle);
                                addedPractitioner.add(practitioner.getIdElement().getIdPart());
                            }
                        }
                    }
                // for practitioner
                }
            // if non empty practitioner list
            }
        // if slots added
        }
    // for schedules
    }
// for location
}
Also used : HashMap(java.util.HashMap) LocationDetails(uk.gov.hscic.model.location.LocationDetails) Reference(org.hl7.fhir.dstu3.model.Reference) OrganizationDetails(uk.gov.hscic.model.organization.OrganizationDetails) IdType(org.hl7.fhir.dstu3.model.IdType) 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) SlotDetail(uk.gov.hscic.model.appointment.SlotDetail) Location(org.hl7.fhir.dstu3.model.Location) HashSet(java.util.HashSet) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 95 with Location

use of com.ibm.watson.compare_comply.v1.model.Location in project metacat by Netflix.

the class S3ConnectorTableService method update.

@Override
public void update(@Nonnull final ConnectorContext context, @Nonnull final TableInfo tableInfo) {
    log.debug("Start: Update table {}", tableInfo.getName());
    final QualifiedName tableName = tableInfo.getName();
    final Table table = tableDao.getBySourceDatabaseTableName(catalogName, tableName.getDatabaseName(), tableName.getTableName());
    if (table == null) {
        throw new TableNotFoundException(tableName);
    }
    //we can update the fields, the uri, or the full serde
    final Location newLocation = infoConverter.toLocation(tableInfo);
    Location location = table.getLocation();
    if (location == null) {
        location = new Location();
        location.setTable(table);
        table.setLocation(location);
    }
    if (newLocation.getUri() != null) {
        location.setUri(newLocation.getUri());
    }
    final Info newInfo = newLocation.getInfo();
    if (newInfo != null) {
        final Info info = location.getInfo();
        if (info == null) {
            location.setInfo(newInfo);
            newInfo.setLocation(location);
        } else {
            if (newInfo.getInputFormat() != null) {
                info.setInputFormat(newInfo.getInputFormat());
            }
            if (newInfo.getOutputFormat() != null) {
                info.setOutputFormat(newInfo.getOutputFormat());
            }
            if (newInfo.getOwner() != null) {
                info.setOwner(newInfo.getOwner());
            }
            if (newInfo.getSerializationLib() != null) {
                info.setSerializationLib(newInfo.getSerializationLib());
            }
            if (newInfo.getParameters() != null && !newInfo.getParameters().isEmpty()) {
                info.setParameters(newInfo.getParameters());
            }
        }
    }
    final Schema newSchema = newLocation.getSchema();
    if (newSchema != null) {
        final List<Field> newFields = newSchema.getFields();
        if (newFields != null && !newFields.isEmpty()) {
            final Schema schema = location.getSchema();
            if (schema == null) {
                location.setSchema(newSchema);
                newSchema.setLocation(location);
            } else {
                final List<Field> fields = schema.getFields();
                if (fields.isEmpty()) {
                    newFields.forEach(field -> {
                        field.setSchema(schema);
                        fields.add(field);
                    });
                } else {
                    for (int i = 0; i < newFields.size(); i++) {
                        final Field newField = newFields.get(i);
                        newField.setPos(i);
                        newField.setSchema(schema);
                        if (newField.getType() == null) {
                            newField.setType(newField.getSourceType());
                        }
                    }
                    schema.setFields(null);
                    fieldDao.delete(fields);
                    tableDao.save(table, true);
                    schema.setFields(newFields);
                }
            }
        }
    }
    log.debug("End: Update table {}", tableInfo.getName());
}
Also used : TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) Field(com.netflix.metacat.connector.s3.model.Field) Table(com.netflix.metacat.connector.s3.model.Table) QualifiedName(com.netflix.metacat.common.QualifiedName) Schema(com.netflix.metacat.connector.s3.model.Schema) Info(com.netflix.metacat.connector.s3.model.Info) TableInfo(com.netflix.metacat.common.server.connectors.model.TableInfo) Location(com.netflix.metacat.connector.s3.model.Location)

Aggregations

Test (org.junit.Test)120 Location (org.hl7.fhir.r4.model.Location)93 Location (org.hl7.fhir.dstu3.model.Location)66 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)59 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)42 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)30 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)27 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)21 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)20 StringOrListParam (ca.uhn.fhir.rest.param.StringOrListParam)20 StringParam (ca.uhn.fhir.rest.param.StringParam)20 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)16 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)16 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)16 MockIBundleProvider (org.openmrs.module.fhir2.providers.r4.MockIBundleProvider)16 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)13 Test (org.junit.jupiter.api.Test)13 ArrayList (java.util.ArrayList)11 HashSet (java.util.HashSet)11 TokenParam (ca.uhn.fhir.rest.param.TokenParam)10