Java Code Examples for org.hl7.fhir.dstu3.model.DomainResource

The following examples show how to use org.hl7.fhir.dstu3.model.DomainResource. These examples are extracted from open source projects. 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 Project: org.hl7.fhir.core   Source File: ShExGenerator.java    License: Apache License 2.0 6 votes vote down vote up
private ValueSet resolveBindingReference(DomainResource ctxt, Type reference) {
  if (reference instanceof UriType) {
    return context.fetchResource(ValueSet.class, ((UriType) reference).getValue().toString());
  }
  else if (reference instanceof Reference) {
    String s = ((Reference) reference).getReference();
    if (s.startsWith("#")) {
      for (Resource c : ctxt.getContained()) {
        if (c.getId().equals(s.substring(1)) && (c instanceof ValueSet))
          return (ValueSet) c;
      }
      return null;
    } else {
      return context.fetchResource(ValueSet.class, ((Reference) reference).getReference());
    }
  }
  else
    return null;
}
 
Example 2
Source Project: elexis-3-core   Source File: ConditionAccessor.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public ConditionCategory getCategory(DomainResource resource){
	org.hl7.fhir.dstu3.model.Condition fhirCondition =
		(org.hl7.fhir.dstu3.model.Condition) resource;
	if (!fhirCondition.getCategory().isEmpty()) {
		List<Coding> coding = fhirCondition.getCategory().get(0).getCoding();
		if (!coding.isEmpty()) {
			for (Coding categoryCoding : coding) {
				if (categoryCoding.getSystem()
					.equals("http://hl7.org/fhir/condition-category")) {
					return (ConditionCategory) categoryMapping
						.getLocalEnumValueByCode(categoryCoding.getCode().toUpperCase());
				}
			}
		}
	}
	return ConditionCategory.UNKNOWN;
}
 
Example 3
Source Project: elexis-3-core   Source File: ConditionAccessor.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public Optional<String> getEnd(DomainResource resource){
	org.hl7.fhir.dstu3.model.Condition fhirCondition =
		(org.hl7.fhir.dstu3.model.Condition) resource;
	try {
		if (fhirCondition.hasAbatementDateTimeType()) {
			DateTimeType dateTime = fhirCondition.getAbatementDateTimeType();
			if (dateTime != null) {
				Date date = dateTime.getValue();
				SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");
				return Optional.of(format.format(date));
			}
		} else if (fhirCondition.hasAbatementStringType()) {
			return Optional.of(fhirCondition.getAbatementStringType().getValue());
		}
	} catch (FHIRException e) {
		LoggerFactory.getLogger(ConditionAccessor.class).error("Could not access end.", e);
	}
	return Optional.empty();
}
 
Example 4
Source Project: elexis-3-core   Source File: ObservationAccessor.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public void setCategory(DomainResource resource, ObservationCategory category){
	org.hl7.fhir.dstu3.model.Observation fhirObservation =
		(org.hl7.fhir.dstu3.model.Observation) resource;
	CodeableConcept categoryCode = new CodeableConcept();
	if (category.name().startsWith("SOAP_")) {
		// elexis soap categories
		categoryCode.setCoding(
			Collections.singletonList(new Coding(IdentifierSystem.ELEXIS_SOAP.getSystem(),
				category.getCode(), category.getLocalized())));
	} else {
		org.hl7.fhir.dstu3.model.codesystems.ObservationCategory fhirCategoryCode =
			(org.hl7.fhir.dstu3.model.codesystems.ObservationCategory) categoryMapping
				.getFhirEnumValueByEnum(category);
		if (fhirCategoryCode != null) {
			// lookup matching fhir category
			categoryCode
				.setCoding(Collections.singletonList(new Coding(fhirCategoryCode.getSystem(),
					fhirCategoryCode.toCode(), fhirCategoryCode.getDisplay())));
		} else {
			throw new IllegalStateException("Unknown observation category " + category);
		}
	}
	if (!categoryCode.getCoding().isEmpty()) {
		fhirObservation.setCategory(Collections.singletonList(categoryCode));
	}
}
 
Example 5
Source Project: elexis-3-core   Source File: EncounterAccessor.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public void setConsultationId(DomainResource resource, String consultationId) {
	org.hl7.fhir.dstu3.model.Encounter fhirEncounter = (org.hl7.fhir.dstu3.model.Encounter) resource;
	boolean identifierFound = false;
	List<Identifier> existing = fhirEncounter.getIdentifier();
	for (Identifier existingIdentifier : existing) {
		if (IdentifierSystem.ELEXIS_CONSID.getSystem().equals(existingIdentifier.getSystem())) {
			existingIdentifier.setValue(consultationId);
			identifierFound = true;
			break;
		}
	}
	if (!identifierFound) {
		Identifier identifier = fhirEncounter.addIdentifier();
		identifier.setSystem(IdentifierSystem.ELEXIS_CONSID.getSystem());
		identifier.setValue(consultationId);
	}
}
 
Example 6
Source Project: elexis-3-core   Source File: Encounter.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public List<ICondition> getIndication(){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent()) {
		return accessor.getIndication((DomainResource) resource.get());
	}
	return new ArrayList<>();
}
 
Example 7
Source Project: elexis-3-core   Source File: Observation.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void setStringValue(String value){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent()) {
		accessor.setStringValue((DomainResource) resource.get(), value);
		saveResource(resource.get());
	}
}
 
Example 8
Source Project: org.hl7.fhir.core   Source File: CCDAConverter.java    License: Apache License 2.0 5 votes vote down vote up
protected String addReference(DomainResource r, String title, String id) throws Exception {
	if (r.getText() == null)
		r.setText(new Narrative());
	if (r.getText().getDiv() == null) {
		r.getText().setStatus(NarrativeStatus.GENERATED);
		new NarrativeGenerator("", "", context).generate(r);
	}
	r.setMeta(new Meta().setLastUpdatedElement(InstantType.now()));
	r.setId(id);
	feed.getEntry().add(new BundleEntryComponent().setResource(r));
	return id;
}
 
Example 9
Source Project: elexis-3-core   Source File: Observation.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Optional<String> getStringValue(){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent()) {
		return accessor.getStringValue((DomainResource) resource.get());
	}
	return Optional.empty();
}
 
Example 10
Source Project: org.hl7.fhir.core   Source File: XmlParserBase.java    License: Apache License 2.0 5 votes vote down vote up
protected DomainResource parseDomainResourceContained(XmlPullParser xpp)  throws IOException, FHIRFormatError, XmlPullParserException {
	next(xpp);
	int eventType = nextNoWhitespace(xpp);
	if (eventType == XmlPullParser.START_TAG) { 
		DomainResource dr = (DomainResource) parseResource(xpp);
		nextNoWhitespace(xpp);
		next(xpp);
		return dr;
	} else {
		unknownContent(xpp);
		return null;
	}
}
 
Example 11
Source Project: elexis-3-core   Source File: Condition.java    License: 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 12
public void setDocumentClass(DomainResource resource, ICoding coding){
	org.hl7.fhir.dstu3.model.DocumentReference fhirResource =
		(org.hl7.fhir.dstu3.model.DocumentReference) resource;
	CodeableConcept codeableConcept = new CodeableConcept();
	ModelUtil.setCodingToConcept(codeableConcept, coding);
	fhirResource.setClass_(codeableConcept);
}
 
Example 13
Source Project: org.hl7.fhir.core   Source File: ToolingExtensions.java    License: Apache License 2.0 5 votes vote down vote up
public static void addMarkdownExtension(DomainResource dr, String url, String content) {
  if (!StringUtils.isBlank(content)) {
    Extension ex = getExtension(dr, url);
    if (ex != null)
      ex.setValue(new StringType(content));
    else
      dr.getExtension().add(Factory.newExtension(url, new MarkdownType(content), true));   
  }
}
 
Example 14
Source Project: elexis-3-core   Source File: Observation.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void setNumericValue(BigDecimal bigDecimal, String unit){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent()) {
		accessor.setNumericValue((DomainResource) resource.get(), bigDecimal, unit);
		saveResource(resource.get());
	}
}
 
Example 15
Source Project: org.hl7.fhir.core   Source File: ToolingExtensions.java    License: Apache License 2.0 5 votes vote down vote up
public static void addIntegerExtension(DomainResource dr, String url, int value) {
  Extension ex = getExtension(dr, url);
  if (ex != null)
    ex.setValue(new IntegerType(value));
  else
    dr.getExtension().add(Factory.newExtension(url, new IntegerType(value), true));   
}
 
Example 16
Source Project: elexis-3-core   Source File: Condition.java    License: 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 17
Source Project: org.hl7.fhir.core   Source File: ToolingExtensions.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static PrimitiveType<Type> readPrimitiveExtension(DomainResource c, String uri) {
  Extension ex = getExtension(c, uri);
  if (ex == null)
    return null;
  return (PrimitiveType<Type>) ex.getValue();
}
 
Example 18
Source Project: org.hl7.fhir.core   Source File: ToolingExtensions.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param name the identity of the extension of interest
 * @return The extension, if on this element, else null
 */
public static Extension getExtension(DomainResource resource, String name) {
  if (name == null)
    return null;
  if (!resource.hasExtension())
    return null;
  for (Extension e : resource.getExtension()) {
    if (name.equals(e.getUrl()))
      return e;
  }
  return null;
}
 
Example 19
Source Project: elexis-3-core   Source File: Condition.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Optional<LocalDate> getDateRecorded(){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent()) {
		return accessor.getDateRecorded((DomainResource) resource.get());
	}
	return Optional.empty();
}
 
Example 20
Source Project: org.hl7.fhir.core   Source File: ToolingExtensions.java    License: Apache License 2.0 5 votes vote down vote up
public static void setCodeExtension(DomainResource resource, String uri, String value) {
  Extension ext = getExtension(resource, uri);
  if (ext != null)
    ext.setValue(new CodeType(value));
  else
    resource.getExtension().add(new Extension(new UriType(uri)).setValue(new CodeType(value)));
}
 
Example 21
Source Project: elexis-3-core   Source File: Condition.java    License: 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 22
Source Project: elexis-3-core   Source File: Condition.java    License: 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 23
Source Project: org.hl7.fhir.core   Source File: ToolingExtensions.java    License: Apache License 2.0 5 votes vote down vote up
public static void removeExtension(DomainResource focus, String url) {
  Iterator<Extension> i = focus.getExtension().iterator();
  while (i.hasNext()) {
    Extension e = i.next(); // must be called before you can call i.remove()
    if (e.getUrl().equals(url)) {
      i.remove();
    }
  }
}
 
Example 24
Source Project: org.hl7.fhir.core   Source File: ToolingExtensions.java    License: Apache License 2.0 5 votes vote down vote up
public static int readIntegerExtension(DomainResource dr, String uri, int defaultValue) {
  Extension ex = ExtensionHelper.getExtension(dr, uri);
  if (ex == null)
    return defaultValue;
  if (ex.getValue() instanceof IntegerType)
    return ((IntegerType) ex.getValue()).getValue();
  throw new Error("Unable to read extension "+uri+" as an integer");
}
 
Example 25
public List<ICoding> getFacilityType(DomainResource resource){
	org.hl7.fhir.dstu3.model.DocumentReference fhirResource =
		(org.hl7.fhir.dstu3.model.DocumentReference) resource;
	DocumentReferenceContextComponent fhirContext = fhirResource.getContext();
	if (fhirContext != null) {
		CodeableConcept codeableConcept = fhirContext.getFacilityType();
		if (codeableConcept != null) {
			return ModelUtil.getCodingsFromConcept(codeableConcept);
		}
	}
	return Collections.emptyList();
}
 
Example 26
Source Project: org.hl7.fhir.core   Source File: NarrativeGenerator.java    License: Apache License 2.0 5 votes vote down vote up
public boolean generate(Bundle b, boolean evenIfAlreadyHasNarrative) throws EOperationOutcome, FHIRException, IOException {
  boolean res = false;
  this.bundle = b;
  for (BundleEntryComponent be : b.getEntry()) {
    if (be.hasResource() && be.getResource() instanceof DomainResource) {
      DomainResource dr = (DomainResource) be.getResource();
      if (evenIfAlreadyHasNarrative || !dr.getText().hasDiv())
        res = generate(new ResourceContext(b, dr), dr) || res;
    }
  }
  return res;
}
 
Example 27
Source Project: elexis-3-core   Source File: DocumentReference.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void setPracticeSetting(ICoding coding){
	Optional<IBaseResource> resource = loadResource();
	if (resource.isPresent()) {
		accessor.setPracticeSetting((DomainResource) resource.get(), coding);
		saveResource(resource.get());
	}
}
 
Example 28
Source Project: org.hl7.fhir.core   Source File: NarrativeGenerator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public List<ResourceWrapper> getContained() {
  List<ResourceWrapper> list = new ArrayList<NarrativeGenerator.ResourceWrapper>();
  if (wrapped instanceof DomainResource) {
    DomainResource dr = (DomainResource) wrapped;
    for (Resource c : dr.getContained()) {
      list.add(new ResourceWrapperDirect(c));
    }
  }
  return list;
}
 
Example 29
Source Project: org.hl7.fhir.core   Source File: NarrativeGenerator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public XhtmlNode getNarrative() {
  if (wrapped instanceof DomainResource) {
    DomainResource dr = (DomainResource) wrapped;
    if (dr.hasText() && dr.getText().hasDiv())
      return dr.getText().getDiv();
  }
  return null;
}
 
Example 30
Source Project: org.hl7.fhir.core   Source File: NarrativeGenerator.java    License: Apache License 2.0 5 votes vote down vote up
private boolean generateByProfile(DomainResource r, StructureDefinition profile, boolean showCodeDetails) {
  XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
  x.para().b().tx("Generated Narrative"+(showCodeDetails ? " with Details" : ""));
  try {
    generateByProfile(r, profile, r, profile.getSnapshot().getElement(), profile.getSnapshot().getElement().get(0), getChildrenForPath(profile.getSnapshot().getElement(), r.getResourceType().toString()), x, r.getResourceType().toString(), showCodeDetails);
  } catch (Exception e) {
    e.printStackTrace();
    x.para().b().setAttribute("style", "color: maroon").tx("Exception generating Narrative: "+e.getMessage());
  }
  inject(r, x,  NarrativeStatus.GENERATED);
  return true;
}