ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException Java Examples

The following examples show how to use ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestApplicationHints.java    From fhirstarters with BSD 3-Clause "New" or "Revised" License 7 votes vote down vote up
public static void step1_read_a_resource() {

		FhirContext ctx = FhirContext.forDstu3();
		IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu3");

		Patient patient;
		try {
			// Try changing the ID from 952975 to 999999999999
			patient = client.read().resource(Patient.class).withId("952975").execute();
		} catch (ResourceNotFoundException e) {
			System.out.println("Resource not found!");
			return;
		}

		String string = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(patient);
		System.out.println(string);

	}
 
Example #2
Source File: Dstu3FhirTerminologyProvider.java    From cql_engine with Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<Code> expand(ValueSetInfo valueSet) throws ResourceNotFoundException {
    if (resolveByUrl(valueSet) == null) {
        return Collections.emptyList();
    }
    Parameters respParam = fhirClient
            .operation()
            .onInstance(new IdType("ValueSet", valueSet.getId()))
            .named("expand")
            .withNoParameters(Parameters.class)
            .execute();

    ValueSet expanded = (ValueSet) respParam.getParameter().get(0).getResource();
    List<Code> codes = new ArrayList<>();
    for (ValueSet.ValueSetExpansionContainsComponent codeInfo : expanded.getExpansion().getContains()) {
        Code nextCode = new Code()
                .withCode(codeInfo.getCode())
                .withSystem(codeInfo.getSystem())
                .withVersion(codeInfo.getVersion())
                .withDisplay(codeInfo.getDisplay());
        codes.add(nextCode);
    }
    return codes;
}
 
Example #3
Source File: R4FhirTerminologyProvider.java    From cql_engine with Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<Code> expand(ValueSetInfo valueSet) throws ResourceNotFoundException {
    if (resolveByUrl(valueSet) == null) {
        return Collections.emptyList();
    }
    Parameters respParam = fhirClient
            .operation()
            .onInstance(new IdType("ValueSet", valueSet.getId()))
            .named("expand")
            .withNoParameters(Parameters.class)
            .execute();

    ValueSet expanded = (ValueSet) respParam.getParameter().get(0).getResource();
    List<Code> codes = new ArrayList<>();
    for (ValueSet.ValueSetExpansionContainsComponent codeInfo : expanded.getExpansion().getContains()) {
        Code nextCode = new Code()
                .withCode(codeInfo.getCode())
                .withSystem(codeInfo.getSystem())
                .withVersion(codeInfo.getVersion())
                .withDisplay(codeInfo.getDisplay());
        codes.add(nextCode);
    }
    return codes;
}
 
Example #4
Source File: PatientResourceProvider.java    From fhirstarters with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * The "@Update" annotation indicates that this method supports replacing an existing
 * resource (by ID) with a new instance of that resource.
 *
 * @param theId      This is the ID of the patient to update
 * @param thePatient This is the actual resource to save
 * @return This method returns a "MethodOutcome"
 */
@Update()
public MethodOutcome updatePatient(@IdParam IdType theId, @ResourceParam Patient thePatient) {
   validateResource(thePatient);

   Long id;
   try {
      id = theId.getIdPartAsLong();
   } catch (DataFormatException e) {
      throw new InvalidRequestException("Invalid ID " + theId.getValue() + " - Must be numeric");
   }

   /*
    * Throw an exception (HTTP 404) if the ID is not known
    */
   if (!myIdToPatientVersions.containsKey(id)) {
      throw new ResourceNotFoundException(theId);
   }

   addNewVersion(thePatient, id);

   return new MethodOutcome();
}
 
Example #5
Source File: R4ApelonFhirTerminologyProvider.java    From cqf-ruler with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<Code> expand(ValueSetInfo valueSet) throws ResourceNotFoundException {
    String id = valueSet.getId();
    if (this.cache.containsKey(id)) {
        return this.cache.get(id);
    }

    String url = this.resolveByIdentifier(valueSet);

    Parameters respParam = this.getFhirClient()
            .operation()
            .onType(ValueSet.class)
            .named("expand")
            .withSearchParameter(Parameters.class, "url", new StringParam(url))
            .andSearchParameter("includeDefinition", new StringParam("true"))
            .useHttpGet()
            .execute();
    
    ValueSet expanded = (ValueSet) respParam.getParameter().get(0).getResource();
    List<Code> codes = new ArrayList<>();
    for (ValueSet.ValueSetExpansionContainsComponent codeInfo : expanded.getExpansion().getContains()) {
        Code nextCode = new Code()
                .withCode(codeInfo.getCode())
                .withSystem(codeInfo.getSystem())
                .withVersion(codeInfo.getVersion())
                .withDisplay(codeInfo.getDisplay());
        codes.add(nextCode);
    }

    this.cache.put(id, codes);
    return codes;
}
 
Example #6
Source File: ConsentProvider.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
@Read()
public Consent get(@IdParam IdType consentId) {

	resourcePermissionProvider.checkPermission("read");
	
    Consent consent = consentDao.read(ctx,consentId);

    if ( consent == null) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(
                new ResourceNotFoundException("No Consent/ " + consentId.getIdPart()),
                 OperationOutcome.IssueType.NOTFOUND);
    }

    return consent;
}
 
Example #7
Source File: JpaTerminologyProvider.java    From cqf-ruler with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized boolean in(Code code, ValueSetInfo valueSet) throws ResourceNotFoundException {
    for (Code c : expand(valueSet)) {
        if (c == null) continue;
        if (c.getCode().equals(code.getCode()) && c.getSystem().equals(code.getSystem())) {
            return true;
        }
    }
    return false;
}
 
Example #8
Source File: Hints.java    From fhirstarters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Simple implementation of the "read" method */
@Read(version = false)
public Patient read(@IdParam IdType theId) {
	Patient retVal = myPatients.get(theId.getIdPart());
	if (retVal == null) {
		throw new ResourceNotFoundException(theId);
	}
	return retVal;
}
 
Example #9
Source File: Example01_PatientResourceProvider.java    From fhirstarters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Simple implementation of the "read" method
 */
@Read()
public Patient read(@IdParam IdType theId) {
   Patient retVal = myPatients.get(theId.getIdPart());
   if (retVal == null) {
      throw new ResourceNotFoundException(theId);
   }
   return retVal;
}
 
Example #10
Source File: OrganizationResourceProvider.java    From fhirstarters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * The "@Read" annotation indicates that this method supports the read operation. It takes one argument, the Resource type being returned.
 * 
 * @param theId
 *            The read operation takes one parameter, which must be of type IdDt and must be annotated with the "@Read.IdParam" annotation.
 * @return Returns a resource matching this identifier, or null if none exists.
 */
@Read()
public MyOrganization getResourceById(@IdParam IdType theId) {
	
	/*
	 * We only support one organization, so the follwing
	 * exception causes an HTTP 404 response if the 
	 * ID of "1" isn't used.
	 */
	if (!"1".equals(theId.getValue())) {
		throw new ResourceNotFoundException(theId);
	}
	
	MyOrganization retVal = new MyOrganization();
	retVal.setId("1");
	retVal.addIdentifier().setSystem("urn:example:orgs").setValue("FooOrganization");
	retVal.addAddress().addLine("123 Fake Street").setCity("Toronto");
	retVal.addTelecom().setUse(ContactPointUse.WORK).setValue("1-888-123-4567");
	
	// Populate the first, primitive extension
	retVal.setBillingCode(new CodeType("00102-1"));
	
	// The second extension is repeatable and takes a block type
	MyOrganization.EmergencyContact contact = new MyOrganization.EmergencyContact();
	contact.setActive(new BooleanType(true));
	contact.setContact(new ContactPoint());
	retVal.getEmergencyContact().add(contact);
	
	return retVal;
}
 
Example #11
Source File: PatientResourceProvider.java    From fhirstarters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * This is the "read" operation. The "@Read" annotation indicates that this method supports the read and/or vread operation.
 * <p>
 * Read operations take a single parameter annotated with the {@link IdParam} paramater, and should return a single resource instance.
 * </p>
 *
 * @param theId The read operation takes one parameter, which must be of type IdDt and must be annotated with the "@Read.IdParam" annotation.
 * @return Returns a resource matching this identifier, or null if none exists.
 */
@Read(version = true)
public Patient readPatient(@IdParam IdType theId) {
   Deque<Patient> retVal;
   try {
      retVal = myIdToPatientVersions.get(theId.getIdPartAsLong());
   } catch (NumberFormatException e) {
      /*
       * If we can't parse the ID as a long, it's not valid so this is an unknown resource
       */
      throw new ResourceNotFoundException(theId);
   }

   if (theId.hasVersionIdPart() == false) {
      return retVal.getLast();
   } else {
      for (Patient nextVersion : retVal) {
         String nextVersionId = nextVersion.getIdElement().getVersionIdPart();
         if (theId.getVersionIdPart().equals(nextVersionId)) {
            return nextVersion;
         }
      }
      // No matching version
      throw new ResourceNotFoundException("Unknown version: " + theId.getValue());
   }

}
 
Example #12
Source File: MedicationAdministrationProvider.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
@Read()
public MedicationAdministration get(@IdParam IdType administrationId) {
	resourcePermissionProvider.checkPermission("read");
    MedicationAdministration administration = administrationDao.read(ctx,administrationId);

    if ( administration == null) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(
                new ResourceNotFoundException("No MedicationAdministration/ " + administrationId.getIdPart()),
                OperationOutcome.IssueType.NOTFOUND);
    }

    return administration;
}
 
Example #13
Source File: Dstu3ApelonFhirTerminologyProvider.java    From cqf-ruler with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<Code> expand(ValueSetInfo valueSet) throws ResourceNotFoundException {
    String id = valueSet.getId();
    if (this.cache.containsKey(id)) {
        return this.cache.get(id);
    }

    String url = this.resolveByIdentifier(valueSet);

    Parameters respParam = this.getFhirClient()
            .operation()
            .onType(ValueSet.class)
            .named("expand")
            .withSearchParameter(Parameters.class, "url", new StringParam(url))
            .andSearchParameter("includeDefinition", new StringParam("true"))
            .useHttpGet()
            .execute();
    
    ValueSet expanded = (ValueSet) respParam.getParameter().get(0).getResource();
    List<Code> codes = new ArrayList<>();
    for (ValueSet.ValueSetExpansionContainsComponent codeInfo : expanded.getExpansion().getContains()) {
        Code nextCode = new Code()
                .withCode(codeInfo.getCode())
                .withSystem(codeInfo.getSystem())
                .withVersion(codeInfo.getVersion())
                .withDisplay(codeInfo.getDisplay());
        codes.add(nextCode);
    }

    this.cache.put(id, codes);
    return codes;
}
 
Example #14
Source File: JpaTerminologyProvider.java    From cqf-ruler with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized Code lookup(Code code, CodeSystemInfo codeSystem) throws ResourceNotFoundException {
    CodeSystem cs = terminologySvcR4.fetchCodeSystem(context, codeSystem.getId());
    for (CodeSystem.ConceptDefinitionComponent concept : cs.getConcept()) {
        if (concept.getCode().equals(code.getCode()))
            return code.withSystem(codeSystem.getId()).withDisplay(concept.getDisplay());
    }
    return code;
}
 
Example #15
Source File: Dstu3FhirTerminologyProvider.java    From cql_engine with Apache License 2.0 5 votes vote down vote up
@Override
public Code lookup(Code code, CodeSystemInfo codeSystem) throws ResourceNotFoundException {
    Parameters respParam = fhirClient
            .operation()
            .onType(CodeSystem.class)
            .named("lookup")
            .withParameter(Parameters.class, "code", new CodeType(code.getCode()))
            .andParameter("system", new UriType(codeSystem.getId()))
            .execute();

    return code.withSystem(codeSystem.getId())
            .withDisplay(((StringType)respParam.getParameter().get(1).getValue()).getValue());
}
 
Example #16
Source File: R4FhirTerminologyProvider.java    From cql_engine with Apache License 2.0 5 votes vote down vote up
@Override
public boolean in(Code code, ValueSetInfo valueSet) throws ResourceNotFoundException {
    // Potential problems:
    // ValueSetInfo void of id --> want .ontype() instead
    if (resolveByUrl(valueSet) == null) {
        return false;
    }

    Parameters respParam;
    if (code.getSystem() != null) {
        respParam = fhirClient
                .operation()
                .onInstance(new IdType("ValueSet", valueSet.getId()))
                // .onType(ValueSet.class)
                .named("validate-code")
                .withParameter(Parameters.class, "code", new StringType(code.getCode()))
                .andParameter("system", new StringType(code.getSystem()))
                .useHttpGet()
                .execute();
    }
    else {
        respParam = fhirClient
                .operation()
                .onInstance(new IdType("ValueSet", valueSet.getId()))
                // .onType(ValueSet.class)
                .named("validate-code")
                .withParameter(Parameters.class, "code", new StringType(code.getCode()))
                .useHttpGet()
                .execute();
    }
    return ((BooleanType)respParam.getParameter().get(0).getValue()).booleanValue();
}
 
Example #17
Source File: R4FhirTerminologyProvider.java    From cql_engine with Apache License 2.0 5 votes vote down vote up
@Override
public Code lookup(Code code, CodeSystemInfo codeSystem) throws ResourceNotFoundException {
    Parameters respParam = fhirClient
            .operation()
            .onType(CodeSystem.class)
            .named("lookup")
            .withParameter(Parameters.class, "code", new CodeType(code.getCode()))
            .andParameter("system", new UriType(codeSystem.getId()))
            .execute();

    return code.withSystem(codeSystem.getId())
            .withDisplay(((StringType)respParam.getParameter().get(1).getValue()).getValue());
}
 
Example #18
Source File: PatientProvider.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
@Read
public Patient read(@IdParam IdType internalId) {
	
	resourcePermissionProvider.checkPermission("read");
	
    Patient patient = patientDao.read(ctx,internalId);
    if (patient == null) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(
                new ResourceNotFoundException("No patient details found for patient ID: " + internalId.getIdPart()),
                 OperationOutcome.IssueType.NOTFOUND);
    }

    return patient;
}
 
Example #19
Source File: EpisodeOfCareProvider.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
@Read()
public EpisodeOfCare get(@IdParam IdType episodeId) {
	resourcePermissionProvider.checkPermission("read");
    EpisodeOfCare episode = episodeDao.read(ctx,episodeId);

    if ( episode == null) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(
                new ResourceNotFoundException("No EpisodeOfCare/ " + episodeId.getIdPart()),
                 OperationOutcome.IssueType.NOTFOUND);
    }

    return episode;
}
 
Example #20
Source File: MedicationDispenseProvider.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
@Read()
public MedicationDispense get(@IdParam IdType dispenseId) {
	resourcePermissionProvider.checkPermission("read");
    MedicationDispense dispense = dispenseDao.read(ctx,dispenseId);

    if ( dispense == null) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(
                new ResourceNotFoundException("No MedicationDispense/ " + dispenseId.getIdPart()),
                 OperationOutcome.IssueType.NOTFOUND);
    }

    return dispense;
}
 
Example #21
Source File: AppointmentProvider.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
@Read()
public Appointment getAppointment(@IdParam IdType serviceId) {
	resourcePermissionProvider.checkPermission("read");
	
    Appointment appointment = appointmentDao.read(ctx,serviceId);

    if ( appointment == null) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(
                new ResourceNotFoundException("No Appointment/ " + serviceId.getIdPart()),
                 OperationOutcome.IssueType.NOTFOUND);
    }

    return appointment;
}
 
Example #22
Source File: GraphDefinitionProvider.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
@Read
public GraphDefinition get
        (@IdParam IdType internalId) {
	resourcePermissionProvider.checkPermission("read");
    GraphDefinition graph = graphDao.read(ctx, internalId);

    if ( graph == null) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(
                new ResourceNotFoundException("No GraphDefinition/" + internalId.getIdPart()),
                OperationOutcome.IssueType.NOTFOUND);
    }

    return graph;
}
 
Example #23
Source File: OrganizationProvider.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
@Read()
public Organization getOrganizationById(@IdParam IdType organisationId) {
	resourcePermissionProvider.checkPermission("read");
    Organization organisation = organisationDao.read(ctx, organisationId);

    if ( organisation == null) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(
                new ResourceNotFoundException("No Organization/" + organisationId.getIdPart()),
                 OperationOutcome.IssueType.NOTFOUND);
    }
    return organisation;
}
 
Example #24
Source File: ListProvider.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
@Read()
public ListResource getList(@IdParam IdType listId) {
	resourcePermissionProvider.checkPermission("read");
    ListResource form = listDao.read(ctx,listId);

    if ( form == null) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(
                new ResourceNotFoundException("No List/ " + listId.getIdPart()),
                 OperationOutcome.IssueType.NOTFOUND);
    }

    return form;
}
 
Example #25
Source File: ConditionProvider.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
@Read()
public Condition get(@IdParam IdType conditionId) {

	resourcePermissionProvider.checkPermission("read");
    Condition condition = conditionDao.read(ctx,conditionId);

    if ( condition == null) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(
                new ResourceNotFoundException("No Condition/ " + conditionId.getIdPart()),
                 OperationOutcome.IssueType.NOTFOUND);
    }

    return condition;
}
 
Example #26
Source File: ClaimProvider.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
@Read()
public Claim get(@IdParam IdType claimId) {

	resourcePermissionProvider.checkPermission("read");
    Claim claim = claimDao.read(ctx,claimId);

    if ( claim == null) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(
                new ResourceNotFoundException("No Claim/ " + claimId.getIdPart()),
                 OperationOutcome.IssueType.NOTFOUND);
    }

    return claim;
}
 
Example #27
Source File: NamingSystemProvider.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
@Read
public NamingSystem get
        (@IdParam IdType internalId) {
    resourcePermissionProvider.checkPermission("read");
    NamingSystem namingSystem = namingSystemDao.read(ctx, internalId);

    if (namingSystem == null) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(
                new ResourceNotFoundException("No NamingSystem/" + internalId.getIdPart()),
                 OperationOutcome.IssueType.NOTFOUND);
    }

    return namingSystem;
}
 
Example #28
Source File: MessageDefinitionProvider.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
@Read
public MessageDefinition get
        (@IdParam IdType internalId) {
	resourcePermissionProvider.checkPermission("read");
    MessageDefinition messageDefinition = messageDefinitionDao.read(ctx, internalId);

    if ( messageDefinition == null) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(
                new ResourceNotFoundException("No MessageDefinition/" + internalId.getIdPart()),
                 OperationOutcome.IssueType.NOTFOUND);
    }

    return messageDefinition;
}
 
Example #29
Source File: StructureDefinitionProvider.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
@Read
public StructureDefinition get
        (@IdParam IdType internalId) {
    resourcePermissionProvider.checkPermission("read");
    StructureDefinition structureDefinition = structureDefinitionDao.read( ctx, internalId);

    if ( structureDefinition == null) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(
                new ResourceNotFoundException("No StructureDefinition/" + internalId.getIdPart()),
                 OperationOutcome.IssueType.NOTFOUND);
    }

    return structureDefinition;
}
 
Example #30
Source File: ProcedureProvider.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
@Read()
public Procedure get(@IdParam IdType procedureId) {
	resourcePermissionProvider.checkPermission("read");
    Procedure procedure = procedureDao.read(ctx, procedureId);

    if ( procedure == null) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(
                new ResourceNotFoundException("No Procedure/ " + procedureId.getIdPart()),
                 OperationOutcome.IssueType.NOTFOUND);
    }

    return procedure;
}