Search in sources :

Example 6 with Bundle

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

the class SlotResourceProvider method getSlotByIds.

@Search
public Bundle getSlotByIds(@RequiredParam(name = "start") DateParam startDate, @RequiredParam(name = "end") DateParam endDate, @RequiredParam(name = "status") String status, @OptionalParam(name = "searchFilter") TokenAndListParam searchFilters, @IncludeParam(allow = { "Slot:schedule", "Schedule:actor:Practitioner", "Schedule:actor:Location", "Location:managingOrganization" }) Set<Include> theIncludes) {
    boolean foundSchedule = false;
    for (Include anInclude : theIncludes) {
        // getParamName returns any text between the first and second colons
        if (anInclude.getParamName().equals("schedule")) {
            foundSchedule = true;
            break;
        }
    }
    if (!foundSchedule) {
        // TODO check not invalid parameter?
        throwInvalidRequest400_BadRequestException("No include Slot:schedule parameter has been provided");
    }
    Bundle bundle = new Bundle();
    String bookingOdsCode = "";
    String bookingOrgType = "";
    if (!status.equals("free")) {
        throwUnprocessableEntityInvalid422_ParameterException("Status incorrect: Must be equal to free");
    }
    try {
        startDate.isEmpty();
        endDate.isEmpty();
    } catch (Exception e) {
        throwUnprocessableEntityInvalid422_ParameterException("Start Date and End Date must be populated with a correct date format");
    }
    if (startDate.getPrefix() != ParamPrefixEnum.GREATERTHAN_OR_EQUALS || endDate.getPrefix() != ParamPrefixEnum.LESSTHAN_OR_EQUALS) {
        throwUnprocessableEntityInvalid422_ParameterException("Invalid Prefix used");
    }
    validateStartDateParamAndEndDateParam(startDate, endDate);
    if (searchFilters != null) {
        List<TokenOrListParam> searchFilter = searchFilters.getValuesAsQueryTokens();
        for (TokenOrListParam filter : searchFilter) {
            TokenParam token = filter.getValuesAsQueryTokens().get(0);
            if (token.getSystem().equals(SystemURL.VS_GPC_ORG_TYPE)) {
                bookingOrgType = token.getValue();
            }
            if (token.getSystem().equals(SystemURL.ID_ODS_ORGANIZATION_CODE)) {
                bookingOdsCode = token.getValue();
            }
        }
    }
    boolean actorPractitioner = false;
    boolean actorLocation = false;
    boolean managingOrganisation = false;
    for (Include include : theIncludes) {
        switch(include.getValue()) {
            case "Schedule:actor:Practitioner":
                actorPractitioner = true;
                break;
            case "Schedule:actor:Location":
                actorLocation = true;
                break;
            case "Location:managingOrganization":
                managingOrganisation = true;
                break;
        }
    }
    startDate.getValueAsInstantDt().getValue();
    getScheduleOperation.populateBundle(bundle, new OperationOutcome(), startDate.getValueAsInstantDt().getValue(), endDate.getValueAsInstantDt().getValue(), actorPractitioner, actorLocation, managingOrganisation, bookingOdsCode, bookingOrgType);
    return bundle;
}
Also used : TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) Bundle(org.hl7.fhir.dstu3.model.Bundle) TokenParam(ca.uhn.fhir.rest.param.TokenParam) OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) Include(ca.uhn.fhir.model.api.Include) FhirRequestGenericIntercepter.throwUnprocessableEntityInvalid422_ParameterException(uk.gov.hscic.common.filters.FhirRequestGenericIntercepter.throwUnprocessableEntityInvalid422_ParameterException) FhirRequestGenericIntercepter.throwInvalidRequest400_BadRequestException(uk.gov.hscic.common.filters.FhirRequestGenericIntercepter.throwInvalidRequest400_BadRequestException) InternalErrorException(ca.uhn.fhir.rest.server.exceptions.InternalErrorException) FhirRequestGenericIntercepter.throwUnprocessableEntity422_BadRequestException(uk.gov.hscic.common.filters.FhirRequestGenericIntercepter.throwUnprocessableEntity422_BadRequestException) Search(ca.uhn.fhir.rest.annotation.Search) SlotSearch(uk.gov.hscic.appointment.slot.SlotSearch)

Example 7 with Bundle

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

the class FunctionsTest method bundleToJson.

@Test
public void bundleToJson() {
    String jsonBundle = Functions.toJsonBundle(conditions);
    Bundle bundle = (Bundle) CONTEXT.newJsonParser().parseResource(jsonBundle);
    Condition parsedCondition = (Condition) bundle.getEntryFirstRep().getResource();
    Assert.assertEquals(condition.getId(), parsedCondition.getId());
}
Also used : Condition(org.hl7.fhir.dstu3.model.Condition) Bundle(org.hl7.fhir.dstu3.model.Bundle) Test(org.junit.Test)

Example 8 with Bundle

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

the class Functions method toBundle.

/**
 * Returns a bundle containing all resources in the dataset. This should be used
 * with caution for large datasets, since the returned bundle will include all data.
 *
 * @param dataset a dataset of FHIR resoruces
 * @return a bundle containing those resources.
 */
public static Bundle toBundle(Dataset<? extends Resource> dataset) {
    List<Resource> resources = (List<Resource>) dataset.collectAsList();
    Bundle bundle = new Bundle();
    for (Resource resource : resources) {
        bundle.addEntry().setResource(resource);
    }
    return bundle;
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) Resource(org.hl7.fhir.dstu3.model.Resource) BaseResource(org.hl7.fhir.dstu3.model.BaseResource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) List(java.util.List)

Example 9 with Bundle

use of org.hl7.fhir.dstu3.model.Bundle in project loinc2hpo by monarch-initiative.

the class ObservationDownloader method retrieveObservation.

static List<Observation> retrieveObservation(String loincCode) {
    List<Observation> results = new ArrayList<>();
    Bundle bundle = client.search().forResource(Observation.class).where(new TokenClientParam("code").exactly().systemAndCode(LOINC_SYSTEM, loincCode)).prettyPrint().returnBundle(Bundle.class).execute();
    while (true) {
        for (Bundle.BundleEntryComponent bundleEntryComponent : bundle.getEntry()) {
            Observation observation = (Observation) bundleEntryComponent.getResource();
            results.add(observation);
        }
        if (bundle.getLink(IBaseBundle.LINK_NEXT) != null) {
            bundle = client.loadPage().next(bundle).execute();
        } else {
            break;
        }
    }
    return results;
}
Also used : TokenClientParam(ca.uhn.fhir.rest.gclient.TokenClientParam) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) ArrayList(java.util.ArrayList)

Example 10 with Bundle

use of org.hl7.fhir.dstu3.model.Bundle in project loinc2hpo by monarch-initiative.

the class ObservationDownloader method retrievePatient.

static List<Patient> retrievePatient(String given, String family) {
    List<Patient> patients = new ArrayList<>();
    Bundle bundle = client.search().forResource(Patient.class).where(new StringClientParam("given").matches().value(given)).where(new StringClientParam("family").matches().value(family)).prettyPrint().returnBundle(Bundle.class).execute();
    while (true) {
        for (Bundle.BundleEntryComponent bundleEntryComponent : bundle.getEntry()) {
            Patient patient = (Patient) bundleEntryComponent.getResource();
            patients.add(patient);
        }
        if (bundle.getLink(IBaseBundle.LINK_NEXT) != null) {
            bundle = client.loadPage().next(bundle).execute();
        } else {
            break;
        }
    }
    return patients;
}
Also used : StringClientParam(ca.uhn.fhir.rest.gclient.StringClientParam) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) ArrayList(java.util.ArrayList)

Aggregations

IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)5 ArrayList (java.util.ArrayList)4 Bundle (org.hl7.fhir.dstu3.model.Bundle)4 BundleEntryComponent (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent)4 UnprocessableEntityException (ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException)3 OrganizationDetails (uk.gov.hscic.model.organization.OrganizationDetails)3 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)2 FHIRException (org.hl7.fhir.exceptions.FHIRException)2 PopulateMedicationBundle (uk.gov.hscic.medications.PopulateMedicationBundle)2 PatientDetails (uk.gov.hscic.model.patient.PatientDetails)2 Include (ca.uhn.fhir.model.api.Include)1 Search (ca.uhn.fhir.rest.annotation.Search)1 ReferenceClientParam (ca.uhn.fhir.rest.gclient.ReferenceClientParam)1 StringClientParam (ca.uhn.fhir.rest.gclient.StringClientParam)1 TokenClientParam (ca.uhn.fhir.rest.gclient.TokenClientParam)1 TokenOrListParam (ca.uhn.fhir.rest.param.TokenOrListParam)1 TokenParam (ca.uhn.fhir.rest.param.TokenParam)1 ForbiddenOperationException (ca.uhn.fhir.rest.server.exceptions.ForbiddenOperationException)1 InternalErrorException (ca.uhn.fhir.rest.server.exceptions.InternalErrorException)1 InvalidRequestException (ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)1