org.hl7.fhir.instance.model.api.IBaseResource Java Examples

The following examples show how to use org.hl7.fhir.instance.model.api.IBaseResource. 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: FindingsFormatUtilTest.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void convertEncounter20() throws IOException {
	// encounter format of HAPI FHIR 2.0
	String oldContent = AllTests.getResourceAsString("/rsc/json/EncounterFormat20.json");
	assertFalse(FindingsFormatUtil.isCurrentFindingsFormat(oldContent));

	Optional<String> newContent = FindingsFormatUtil.convertToCurrentFindingsFormat(oldContent);
	assertTrue(newContent.isPresent());

	IBaseResource resource = AllTests.getJsonParser().parseResource(newContent.get());
	assertTrue(resource instanceof Encounter);
	Encounter encounter = (Encounter) resource;

	// indication changed to diagnosis
	List<DiagnosisComponent> diagnosis = encounter.getDiagnosis();
	assertNotNull(diagnosis);
	assertFalse(diagnosis.isEmpty());
	DiagnosisComponent component = diagnosis.get(0);
	Reference conditionRef = component.getCondition();
	assertNotNull(conditionRef);
	assertTrue(conditionRef.getReference().contains("CONDITIONA"));
	// patient changed to subject
	Reference subjectRef = encounter.getSubject();
	assertNotNull(subjectRef);
	assertTrue(subjectRef.getReference().contains("PATIENTID"));
}
 
Example #2
Source File: CodeSystemUpdateProvider.java    From cqf-ruler with Apache License 2.0 6 votes vote down vote up
/***
 * Update existing CodeSystems with the codes in all ValueSet resources.
 * System level CodeSystem update operation
 *
 * @return FHIR OperationOutcome detailing the success or failure of the operation
 */
@Operation(name = "$updateCodeSystems", idempotent = true)
public OperationOutcome updateCodeSystems()
{
    IBundleProvider valuesets = this.valueSetDao.search(new SearchParameterMap());
    OperationOutcome response = new OperationOutcome();

    OperationOutcome outcome;
    for (IBaseResource valueSet : valuesets.getResources(0, valuesets.size()))
    {
        outcome = this.performCodeSystemUpdate((ValueSet) valueSet);
        if (outcome.hasIssue())
        {
            for (OperationOutcome.OperationOutcomeIssueComponent issue : outcome.getIssue())
            {
                response.addIssue(issue);
            }
        }
    }

    return response;
}
 
Example #3
Source File: GraphQLEngineTests.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
@Override
public ReferenceResolution lookup(Object appInfo, IBaseResource context, IBaseReference reference) throws FHIRException {
  try {
    if (reference.getReferenceElement().isLocal()) {
      if (!(context instanceof DomainResource))
        return null;
      for (Resource r : ((DomainResource) context).getContained()) {
        if (('#' + r.getId()).equals(reference.getReferenceElement().getValue())) {
          return new ReferenceResolution(context, r);
        }
      }
    } else {
      String[] parts = reference.getReferenceElement().getValue().split("/");
      String filename = TestingUtilities.resourceNameToFile(parts[0].toLowerCase() + '-' + parts[1].toLowerCase() + ".xml");
      if (new File(filename).exists())
        return new ReferenceResolution(null, new XmlParser().parse(new FileInputStream(filename)));
    }
    return null;
  } catch (Exception e) {
    throw new FHIRException(e);
  }
}
 
Example #4
Source File: GraphQLEngine.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private void processSearchSimple(ObjectValue target, Field field, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException {
  if (services == null)
    throw new EGraphQLException("Resource Referencing services not provided");
  List<IBaseResource> list = new ArrayList<>();
  services.listResources(appInfo, field.getName().substring(0, field.getName().length() - 4), field.getArguments(), list);
  Argument arg = null;
  ObjectValue obj = null;

  List<Resource> vl = filterResources(field.argument("fhirpath"), list);
  if (!vl.isEmpty()) {
    arg = target.addField(field.getAlias() + suffix, listStatus(field, true));
    for (Resource v : vl) {
      obj = new ObjectValue();
      arg.addValue(obj);
      processObject(v, v, obj, field.getSelectionSet(), inheritedList, suffix);
    }
  }
}
 
Example #5
Source File: Observation.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Optional<BigDecimal> getNumericValue(){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent()) {
		if (FindingsScriptingUtil.hasScript(this)) {
			FindingsScriptingUtil.evaluate(this);
			resource = loadResource();
		}
		return accessor.getNumericValue((DomainResource) resource.get());
	}
	return Optional.empty();
}
 
Example #6
Source File: GraphQLEngineTests.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Override
public void listResources(Object appInfo, String type, List<Argument> searchParams, List<IBaseResource> matches) throws FHIRException {
  try {
    if (type.equals("Condition")) 
      matches.add(new XmlParser().parse(TestingUtilities.loadTestResourceStream("r5", "condition-example.xml")));
    else if (type.equals("Patient")) {
      matches.add(new XmlParser().parse(TestingUtilities.loadTestResourceStream("r5", "patient-example.xml")));
      matches.add(new XmlParser().parse(TestingUtilities.loadTestResourceStream("r5", "patient-example-xds.xml")));
    }
  } catch (Exception e) {
    throw new FHIRException(e);
  }
}
 
Example #7
Source File: Observation.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void setPatientId(String patientId){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent()) {
		accessor.setPatientId((DomainResource) resource.get(), patientId);
		saveResource(resource.get());
	}
	
	getEntity().setPatientId(patientId);
}
 
Example #8
Source File: Condition.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Optional<String> getStart(){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent()) {
		return accessor.getStart((DomainResource) resource.get());
	}
	return Optional.empty();
}
 
Example #9
Source File: LibraryOperationsProvider.java    From cqf-ruler with Apache License 2.0 5 votes vote down vote up
private Iterable<org.hl7.fhir.r4.model.Library> resolveLibraries(List< IBaseResource > resourceList) {
    List<org.hl7.fhir.r4.model.Library> ret = new ArrayList<>();
    for (IBaseResource res : resourceList) {
        Class<?> clazz = res.getClass();
        ret.add((org.hl7.fhir.r4.model.Library)clazz.cast(res));
    }
    return ret;
}
 
Example #10
Source File: Encounter.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Optional<LocalDateTime> getEndTime(){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent()) {
		return accessor.getEndTime((DomainResource) resource.get());
	}
	return Optional.empty();
}
 
Example #11
Source File: GraphQLEngineTests.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Override
public void listResources(Object appInfo, String type, List<Argument> searchParams, List<IBaseResource> matches) throws FHIRException {
  try {
    if (type.equals("Condition"))
      matches.add(new XmlParser().parse(new FileInputStream(TestingUtilities.resourceNameToFile("condition-example.xml"))));
    else if (type.equals("Patient")) {
      matches.add(new XmlParser().parse(new FileInputStream(TestingUtilities.resourceNameToFile("patient-example.xml"))));
      matches.add(new XmlParser().parse(new FileInputStream(TestingUtilities.resourceNameToFile("patient-example-xds.xml"))));
    }
  } catch (Exception e) {
    throw new FHIRException(e);
  }
}
 
Example #12
Source File: CareConnectProfileDbValidationSupportR4.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
/**
 * Method to fetch a CodeSystem based on a provided URL. Tries to fetch it
 * from remote server. If it succeeds, it caches it in our global cache.
 *
 * @param theContext FHIR Context
 * @param theSystem The CodeSystem URL
 * @return Returns the retrieved FHIR Resource object or null
 */
@Override
public final CodeSystem fetchCodeSystem(
        final FhirContext theContext, final String theSystem) {
    logD(
            "CareConnectValidator asked to fetch Code System: %s%n",
            theSystem);


    if (!isSupported(theSystem)) {
        log.trace("  Returning null as it's an HL7 one");
        return null;
    }

    CodeSystem newCS;

    if (cachedResource.get(theSystem) == null) {
        log.trace(" Not cached");
        IBaseResource response = fetchURL(theSystem);
        if (response != null) {
            log.trace("  Retrieved");
            cachedResource.put(theSystem, (CodeSystem) response);
            log.trace("   Cached");
        }
    }
    if (cachedResource.get(theSystem) == null && cachedResource.get(theSystem) instanceof CodeSystem) {
        log.trace("  Couldn't fetch it, so returning null");
        return null;
    } else {
        log.trace(" Provided from cache");
        return newCS = (CodeSystem) cachedResource.get(theSystem);

    }
    //return newCS;
}
 
Example #13
Source File: CareConnectProfileDbValidationSupportSTU3.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
/**
 * Method to fetch a remote StructureDefinition resource.
 *
 * Caches results.
 *
 * @param theCtx FHIR Context
 * @param theUrl The URL to fetch from
 * @return The StructureDefinition resource or null
 */
@Override
public final StructureDefinition fetchStructureDefinition(
        final FhirContext theCtx,
        final String theUrl) {
    logD(
            "CareConnectValidator asked to fetch StructureDefinition: %s%n",
            theUrl);

    if (!isSupported(theUrl)) {
        log.trace("  Returning null as it's an HL7 one");
        return null;
    }

    if (cachedResource.get(theUrl) == null) {
        IBaseResource response = fetchURL(theUrl);
        log.trace("  About to parse response into a StructureDefinition");

        cachedResource.put(theUrl, CareConnectProfileFix.fixProfile((StructureDefinition) response));
        logD("  StructureDefinition now added to the cache: %s%n", theUrl);
    } else {
        logD("  This URL was already loaded: %s%n", theUrl);
    }
    StructureDefinition sd
            = (StructureDefinition)
            cachedResource.get(theUrl);
    return sd;
}
 
Example #14
Source File: Condition.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void setStart(String start){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent()) {
		accessor.setStart((DomainResource) resource.get(), start);
		saveResource(resource.get());
	}
}
 
Example #15
Source File: CareConnectProfileDbValidationSupportR4.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
private DomainResource fetchCodeSystemOrValueSet(FhirContext theContext, String theSystem, boolean codeSystem) {
  synchronized (this) {
    logW("******* CareConnect fetchCodeSystemOrValueSet: system="+theSystem);

    Map<String, IBaseResource> codeSystems = cachedResource;

    return null;
  }
}
 
Example #16
Source File: Encounter.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public void setType(List<ICoding> coding){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent()) {
		accessor.setType((DomainResource) resource.get(), coding);
		saveResource(resource.get());
	}
}
 
Example #17
Source File: CareConnectProfileValidationSupport.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
/**
 * Method to fetch a CodeSystem based on a provided URL. Tries to fetch it
 * from remote server. If it succeeds, it caches it in our global cache.
 *
 * @param theContext FHIR Context
 * @param theSystem The CodeSystem URL
 * @return Returns the retrieved FHIR Resource object or null
 */
@Override
public final CodeSystem fetchCodeSystem(
        final FhirContext theContext, final String theSystem) {
    logD(
            "MyInstanceValidator asked to fetch Code System: %s%n",
            theSystem);


    if (!isSupported(theSystem)) {
        log.trace("  Returning null as it's an HL7 one");
        return null;
    }

    CodeSystem newCS;

    if (cachedResource.get(theSystem) == null) {
        log.trace(" Not cached");
        IBaseResource response = fetchURL(theSystem);
        if (response != null) {
            log.trace("  Retrieved");
            cachedResource.put(theSystem, (CodeSystem) response);
            log.trace("   Cached");
        }
    }
    if (cachedResource.get(theSystem) == null && cachedResource.get(theSystem) instanceof CodeSystem) {
        log.trace("  Couldn't fetch it, so returning null");
        return null;
    } else {
        log.trace(" Provided from cache");
        return newCS = (CodeSystem) cachedResource.get(theSystem);

    }
    //return newCS;
}
 
Example #18
Source File: DocumentReference.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void setFacilityType(ICoding coding){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent()) {
		accessor.setFacilityType((DomainResource) resource.get(), coding);
		saveResource(resource.get());
	}
	
}
 
Example #19
Source File: IdType.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the ID from the given resource instance
 */
public static IdType of(IBaseResource theResouce) {
  if (theResouce == null) {
    throw new NullPointerException("theResource can not be null");
  } else {
    IIdType retVal = theResouce.getIdElement();
    if (retVal == null) {
      return null;
    } else if (retVal instanceof IdType) {
      return (IdType) retVal;
    } else {
      return new IdType(retVal.getValue());
    }
  }
}
 
Example #20
Source File: Encounter.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public List<ICoding> getType(){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent()) {
		return accessor.getType((DomainResource) resource.get());
	}
	return new ArrayList<>();
}
 
Example #21
Source File: JpaFhirRetrieveProvider.java    From cqf-ruler with Apache License 2.0 5 votes vote down vote up
public synchronized Collection<Object> resolveResourceList(List<IBaseResource> resourceList) {
    List<Object> ret = new ArrayList<>();
    for (IBaseResource res : resourceList) {
        Class<?> clazz = res.getClass();
        ret.add(clazz.cast(res));
    }
    // ret.addAll(resourceList);
    return ret;
}
 
Example #22
Source File: DocumentReference.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void setDocumentClass(ICoding coding){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent()) {
		accessor.setDocumentClass((DomainResource) resource.get(), coding);
		saveResource(resource.get());
	}
}
 
Example #23
Source File: Observation.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void setCoding(List<ICoding> coding){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent()) {
		accessor.setCoding((DomainResource) resource.get(), coding);
		saveResource(resource.get());
	}
}
 
Example #24
Source File: LibraryOperationsProvider.java    From cqf-ruler with Apache License 2.0 5 votes vote down vote up
private Iterable<org.hl7.fhir.dstu3.model.Library> resolveLibraries(List< IBaseResource > resourceList) {
    List<org.hl7.fhir.dstu3.model.Library> ret = new ArrayList<>();
    for (IBaseResource res : resourceList) {
        Class<?> clazz = res.getClass();
        ret.add((org.hl7.fhir.dstu3.model.Library)clazz.cast(res));
    }
    return ret;
}
 
Example #25
Source File: Observation.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void setCategory(ObservationCategory category){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent()) {
		accessor.setCategory((DomainResource) resource.get(), category);
		saveResource(resource.get());
	}
}
 
Example #26
Source File: Observation.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void addComponent(ObservationComponent component){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent()) {
		accessor.addComponent((DomainResource) resource.get(), component);
		saveResource(resource.get());
	}
}
 
Example #27
Source File: Observation.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void updateComponent(ObservationComponent component){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent()) {
		accessor.updateComponent((DomainResource) resource.get(), component);
		saveResource(resource.get());
	}
}
 
Example #28
Source File: Observation.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public List<ICoding> getCoding(){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent()) {
		return accessor.getCoding((DomainResource) resource.get());
	}
	return Collections.emptyList();
}
 
Example #29
Source File: Encounter.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void setEndTime(LocalDateTime time){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent()) {
		accessor.setEndTime((DomainResource) resource.get(), time);
		saveResource(resource.get());
	}
}
 
Example #30
Source File: CareConnectProfileValidationSupport.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
/**
 * Method to fetch a remote StructureDefinition resource.
 *
 * Caches results.
 *
 * @param theCtx FHIR Context
 * @param theUrl The URL to fetch from
 * @return The StructureDefinition resource or null
 */
@Override
public final StructureDefinition fetchStructureDefinition(
        final FhirContext theCtx,
        final String theUrl) {
    logD(
            "MyInstanceValidator asked to fetch StructureDefinition: %s%n",
            theUrl);

    if (!isSupported(theUrl)) {
        log.trace("  Returning null as it's an HL7 one");
        return null;
    }

    if (cachedResource.get(theUrl) == null) {
        IBaseResource response = fetchURL(theUrl);
        log.trace("  About to parse response into a StructureDefinition");

        cachedResource.put(theUrl, (StructureDefinition) response);
        logD("  StructureDefinition now added to the cache: %s%n", theUrl);
    } else {
        logD("  This URL was already loaded: %s%n", theUrl);
    }
    StructureDefinition sd
            = (StructureDefinition)
            cachedResource.get(theUrl);
    return sd;
}