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;
}
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][])));
}
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));
}
}
}
}
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);
}
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));
}
}
}
Aggregations