Search in sources :

Example 96 with ORGANIZATION

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ORGANIZATION in project gpconnect-demonstrator by nhsconnect.

the class OrganizationResourceProvider method getValidAddress.

private Address getValidAddress(Organization organization) {
    List<LocationDetails> locationsDetails = locationSearch.findAllLocations();
    LocationDetails location = null;
    for (LocationDetails locationDetails : locationsDetails) {
        if (locationDetails.getOrgOdsCode().equals(organization.getIdentifierFirstRep().getValue())) {
            location = locationDetails;
            break;
        }
    }
    Address orgAddress = null;
    if (location != null) {
        orgAddress = new Address();
        orgAddress.setUse(AddressUse.WORK);
        // #152
        // this looks very odd but is deliberate, there's a similar issue in locationResourceProvider.createAddress
        // They result from a change to spec to remove the state attribute from the address
        // See the commit cd26528 by James Cox 6/3/18
        orgAddress.addLine(location.getAddressLine());
        orgAddress.addLine(location.getAddressCity());
        orgAddress.setCity(location.getAddressDistrict());
        orgAddress.setDistrict(location.getAddressState());
        orgAddress.setPostalCode(location.getAddressPostalCode());
    }
    return orgAddress;
}
Also used : Address(org.hl7.fhir.dstu3.model.Address) LocationDetails(uk.gov.hscic.model.location.LocationDetails)

Example 97 with ORGANIZATION

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ORGANIZATION in project dpc-app by CMSgov.

the class OrganizationList method run.

@Override
public void run(Bootstrap<?> bootstrap, Namespace namespace) {
    System.out.println("Listing");
    final String attributionService = namespace.getString(ATTR_HOSTNAME);
    System.out.println(String.format("Connecting to Attribution service at: %s", attributionService));
    final IGenericClient client = ctx.newRestfulGenericClient(attributionService);
    final Bundle organizations = client.search().forResource(Organization.class).encodedJson().returnBundle(Bundle.class).execute();
    // Generate the table
    final String[] headers = { "ID", "NPI", "NAME" };
    // noinspection FuseStreamOperations Fusing the operation here actually causes an issue with the print output
    final List<String[]> collect = organizations.getEntry().stream().filter(Bundle.BundleEntryComponent::hasResource).map(Bundle.BundleEntryComponent::getResource).map(resource -> (Organization) resource).map(resource -> List.of(resource.getId(), resource.getIdentifierFirstRep().getValue(), resource.getName())).map(values -> values.toArray(new String[0])).collect(Collectors.toList());
    System.out.println(FlipTable.of(headers, collect.toArray(new String[0][])));
}
Also used : Organization(org.hl7.fhir.dstu3.model.Organization) List(java.util.List) Bundle(org.hl7.fhir.dstu3.model.Bundle) FlipTable(com.jakewharton.fliptables.FlipTable) AbstractAttributionCommand(gov.cms.dpc.api.cli.AbstractAttributionCommand) Bootstrap(io.dropwizard.setup.Bootstrap) Namespace(net.sourceforge.argparse4j.inf.Namespace) Subparser(net.sourceforge.argparse4j.inf.Subparser) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Collectors(java.util.stream.Collectors) Organization(org.hl7.fhir.dstu3.model.Organization) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Bundle(org.hl7.fhir.dstu3.model.Bundle)

Example 98 with ORGANIZATION

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ORGANIZATION in project dpc-app by CMSgov.

the class OrganizationRegistration method registerOrganization.

private void registerOrganization(Bundle organization, String attributionService, boolean noToken, String apiService) throws IOException, URISyntaxException {
    System.out.println(String.format("Connecting to Attribution service at: %s", attributionService));
    final IGenericClient client = ctx.newRestfulGenericClient(attributionService);
    final Parameters parameters = new Parameters();
    parameters.addParameter().setResource(organization);
    UUID organizationID = null;
    try {
        final Organization createdOrg = client.operation().onType(Organization.class).named("submit").withParameters(parameters).returnResourceType(Organization.class).encodedJson().execute();
        organizationID = UUID.fromString(createdOrg.getIdElement().getIdPart());
        System.out.println(String.format("Registered organization: %s", organizationID));
    } catch (Exception e) {
        System.err.println(String.format("Unable to register organization. %s", e.getMessage()));
        System.exit(1);
    }
    // Now, create a token, unless --no-token has been passed
    if (!noToken) {
        System.out.println(String.format("Connecting to API service at: %s", apiService));
        try (final CloseableHttpClient httpClient = HttpClients.createDefault()) {
            final URIBuilder builder = new URIBuilder(String.format("%s/generate-token", apiService));
            builder.setParameter("organization", organizationID.toString());
            final HttpPost httpPost = new HttpPost(builder.build());
            try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
                final String token = EntityUtils.toString(response.getEntity());
                System.out.println(String.format("Organization token: %s", token));
            }
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) Parameters(org.hl7.fhir.dstu3.model.Parameters) Organization(org.hl7.fhir.dstu3.model.Organization) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) UUID(java.util.UUID) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 99 with ORGANIZATION

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ORGANIZATION in project dpc-app by CMSgov.

the class OrganizationRegistration method run.

@Override
public void run(Bootstrap<?> bootstrap, Namespace namespace) throws Exception {
    System.out.println("Registering Organization");
    // Read the file and parse it
    final Path filePath = FileSystems.getDefault().getPath(namespace.getString(ORG_FILE)).normalize().toAbsolutePath();
    Bundle organization;
    try (FileInputStream fileInputStream = new FileInputStream(new File(filePath.toUri()))) {
        final IParser parser = ctx.newJsonParser();
        organization = (Bundle) parser.parseResource(fileInputStream);
    }
    final boolean noToken = Boolean.parseBoolean(namespace.getString("no-token"));
    final String apiService = namespace.getString("api-service");
    registerOrganization(organization, namespace.getString(ATTR_HOSTNAME), noToken, apiService);
}
Also used : Path(java.nio.file.Path) Bundle(org.hl7.fhir.dstu3.model.Bundle) File(java.io.File) FileInputStream(java.io.FileInputStream) IParser(ca.uhn.fhir.parser.IParser)

Example 100 with ORGANIZATION

use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ORGANIZATION in project dpc-app by CMSgov.

the class TokenCreate method run.

@Override
public void run(Bootstrap<?> bootstrap, Namespace namespace) throws Exception {
    final IdType orgID = new IdType(namespace.getString("org-reference"));
    final String apiService = namespace.getString(API_HOSTNAME);
    System.out.println(String.format("Connecting to API service at: %s", apiService));
    try (final CloseableHttpClient httpClient = HttpClients.createDefault()) {
        final URIBuilder builder = new URIBuilder(String.format("%s/generate-token", apiService));
        builder.addParameter("organization", orgID.getIdPart());
        final String label = namespace.getString("token-label");
        if (label != null) {
            builder.addParameter("label", label);
        }
        final String expiration = namespace.getString("token-expiration");
        if (expiration != null) {
            final LocalDate offset = LocalDate.parse(expiration);
            builder.addParameter("expiration", offset.atStartOfDay(ZoneOffset.UTC).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));
        }
        final HttpPost post = new HttpPost(builder.build());
        post.addHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON);
        post.addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
        try (CloseableHttpResponse response = httpClient.execute(post)) {
            if (!HttpStatus.isSuccess(response.getStatusLine().getStatusCode())) {
                System.err.println("Error fetching organization: " + response.getStatusLine().getReasonPhrase());
                System.exit(1);
            }
            final String token = EntityUtils.toString(response.getEntity());
            System.out.println(String.format("Organization token: %s", token));
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) LocalDate(java.time.LocalDate) IdType(org.hl7.fhir.dstu3.model.IdType) URIBuilder(org.apache.http.client.utils.URIBuilder)

Aggregations

Test (org.junit.jupiter.api.Test)101 Organization (org.hl7.fhir.dstu3.model.Organization)90 Organization (org.hl7.fhir.r4.model.Organization)69 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)41 Resource (org.hl7.fhir.r4.model.Resource)38 ArrayList (java.util.ArrayList)34 List (java.util.List)33 Reference (org.hl7.fhir.r4.model.Reference)33 Identifier (org.hl7.fhir.r4.model.Identifier)30 Bundle (org.hl7.fhir.dstu3.model.Bundle)27 UUID (java.util.UUID)26 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)25 Patient (org.hl7.fhir.r4.model.Patient)25 IdType (org.hl7.fhir.dstu3.model.IdType)24 Bundle (org.hl7.fhir.r4.model.Bundle)24 Coding (org.hl7.fhir.r4.model.Coding)24 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)19 ContactPoint (org.hl7.fhir.r4.model.ContactPoint)17 Reference (org.hl7.fhir.dstu3.model.Reference)16 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)16