Java Code Examples for org.hl7.fhir.dstu3.model.Quantity#setUnit()

The following examples show how to use org.hl7.fhir.dstu3.model.Quantity#setUnit() . 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: Convert.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public Quantity makeQuantityFromPQ(Element pq, String units) throws Exception {
if (pq == null)
   return null;
Quantity qty = new Quantity();
String n = pq.getAttribute("value").replace(",", "").trim();
try {
  qty.setValue(new BigDecimal(n));
} catch (Exception e) {
	throw new Exception("Unable to process value '"+n+"'", e);
}			
units = Utilities.noString(pq.getAttribute("unit")) ? units : pq.getAttribute("unit");
if (!Utilities.noString(units)) {
	if (ucumSvc == null || ucumSvc.validate(units) != null)
		qty.setUnit(units);
	else {
		qty.setCode(units);
		qty.setSystem("http://unitsofmeasure.org");
		qty.setUnit(ucumSvc.getCommonDisplay(units));
	}
}
return qty;		
}
 
Example 2
Source File: TestData.java    From bunsen with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a FHIR Observation for testing purposes.
 */
public static Observation newObservation() {

  // Observation based on https://www.hl7.org/FHIR/observation-example-bloodpressure.json.html
  Observation observation = new Observation();

  observation.setId("blood-pressure");

  Identifier identifier = observation.addIdentifier();
  identifier.setSystem("urn:ietf:rfc:3986");
  identifier.setValue("urn:uuid:187e0c12-8dd2-67e2-99b2-bf273c878281");

  observation.setStatus(Observation.ObservationStatus.FINAL);

  Quantity quantity = new Quantity();
  quantity.setValue(new java.math.BigDecimal("123.45"));
  quantity.setUnit("mm[Hg]");
  observation.setValue(quantity);

  return observation;
}
 
Example 3
Source File: ObservationStatsBuilder.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private static Type makeQty(int sat, String human, String ucum) {
  Quantity q = new Quantity();
  q.setCode(ucum);
  q.setSystem("http://unitsofmeasure.org");
  q.setUnit(human);
  q.setValue(new BigDecimal(sat));
  return q;
}
 
Example 4
Source File: ObservationStatsBuilder.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private static Type makeQty(double val, String human, String ucum) {
  Quantity q = new Quantity();
  q.setCode(ucum);
  q.setSystem("http://unitsofmeasure.org");
  q.setUnit(human);
  q.setValue(new BigDecimal(val));
  return q;
}
 
Example 5
Source File: TestData.java    From bunsen with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new Observation for testing.
 *
 * @return a FHIR Observation for testing.
 */
public static Observation newObservation() {
  Observation observation = new Observation();

  observation.setId("blood-pressure");

  Identifier identifier = observation.addIdentifier();
  identifier.setSystem("urn:ietf:rfc:3986");
  identifier.setValue("urn:uuid:187e0c12-8dd2-67e2-99b2-bf273c878281");

  observation.setStatus(Observation.ObservationStatus.FINAL);

  CodeableConcept obsCode = new CodeableConcept();

  observation.setCode(obsCode);

  Quantity quantity = new Quantity();
  quantity.setValue(new java.math.BigDecimal("123.45"));
  quantity.setUnit("mm[Hg]");
  quantity.setSystem("http://unitsofmeasure.org");
  observation.setValue(quantity);

  ObservationComponentComponent component = observation.addComponent();

  CodeableConcept code = new CodeableConcept()
      .addCoding(new Coding()
          .setCode("abc")
          .setSystem("PLACEHOLDER"));

  component.setCode(code);

  return observation;
}
 
Example 6
Source File: ObservationAccessor.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public void setNumericValue(DomainResource resource, BigDecimal value, String unit){
	org.hl7.fhir.dstu3.model.Observation fhirObservation =
		(org.hl7.fhir.dstu3.model.Observation) resource;
	Quantity q = new Quantity();
	q.setUnit(unit);
	q.setValue(value);
	fhirObservation.setValue(q);
}