Java Code Examples for org.hl7.fhir.dstu3.model.Observation#setStatus()

The following examples show how to use org.hl7.fhir.dstu3.model.Observation#setStatus() . 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: ObservationStatsBuilder.java    From org.hl7.fhir.core with Apache License 2.0 7 votes vote down vote up
private static void addAge(Bundle b, int y, int m, String v) throws FHIRException {
  Observation obs = new Observation();
  obs.setId("obs-example-age-weight-"+Integer.toString(y)+"-"+Integer.toString(m));
  obs.setSubject(new Reference().setReference("Patient/123"));
  obs.setStatus(ObservationStatus.FINAL);
  Calendar when = Calendar.getInstance();
  when.add(Calendar.YEAR, -y);
  when.add(Calendar.MONTH, m);
  obs.setEffective(new DateTimeType(when));
  obs.getCode().addCoding().setCode("29463-7").setSystem("http://loinc.org");
  obs.setValue(new Quantity());
  obs.getValueQuantity().setCode("kg");
  obs.getValueQuantity().setSystem("http://unitsofmeasure.org");
  obs.getValueQuantity().setUnit("kg");
  obs.getValueQuantity().setValue(new BigDecimal(v));
  b.addEntry().setFullUrl("http://hl7.org/fhir/Observation/"+obs.getId()).setResource(obs);
}
 
Example 2
Source File: ArgonautConverter.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private void processSocialHistorySection(CDAUtilities cda, Convert convert, Element section, Context context) throws Exception {
	scanSection("Social History", section);
	int i = 0;
	for (Element c : cda.getChildren(section, "entry")) {
		Element o = cda.getChild(c, "observation");
		Observation obs = new Observation();
		obs.setId(context.baseId+"-smoking-"+(i == 0 ? "" : Integer.toString(i)));
		obs.setUserData("profile", "http://hl7.org/fhir/StructureDefinition/observation-daf-smokingstatus-dafsmokingstatus");
		i++;
		obs.setSubject(context.subjectRef);
		obs.setContext(new Reference().setReference("Encounter/"+context.encounter.getId()));
		obs.setCode(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(o, "code")), new Coding().setSystem("http://loinc.org").setCode("72166-2")));

		boolean found = false;
		for (Element e : cda.getChildren(o, "id")) {
			Identifier id = convert.makeIdentifierFromII(e);
			obs.getIdentifier().add(convert.makeIdentifierFromII(e));
		}
		if (!found) {
			obs.setStatus(ObservationStatus.FINAL);
			obs.setEffective(convert.makeDateTimeFromTS(cda.getChild(o, "effectiveTime")));
			obs.setValue(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(o, "value")), null));
			saveResource(obs, "-sh");
		}
	}
}
 
Example 3
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 4
Source File: Example34_ContainedResources.java    From fhirstarters with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void main(String[] args) {

      // Create an Observation
      Observation obs = new Observation();
      obs.setStatus(Observation.ObservationStatus.FINAL);
      obs.setValue(new StringType("This is a value"));

      // Create a Patient
      Patient pat = new Patient();
      pat.addName().setFamily("Simpson").addGiven("Homer");

      // Assign the Patient to the Observation
      obs.getSubject().setResource(pat);

      FhirContext ctx = FhirContext.forDstu3();
      String output = ctx.newJsonParser().setPrettyPrint(true).encodeResourceToString(obs);
      System.out.println(output);

   }
 
Example 5
Source File: ObservationStatsBuilder.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private static Observation baseVitals(Bundle b, Calendar when, int min, String name, String lCode, String text) throws FHIRFormatError {
  Observation obs = new Observation();
  obs.setId("obs-vitals-"+name+"-"+Integer.toString(min));
  obs.setSubject(new Reference().setReference("Patient/123"));
  obs.setStatus(ObservationStatus.FINAL);
  obs.setEffective(new DateTimeType(when));
  obs.addCategory().setText("Vital Signs").addCoding().setSystem("http://hl7.org/fhir/observation-category").setCode("vital-signs").setDisplay("Vital Signs");
  obs.getCode().setText(text).addCoding().setCode(lCode).setSystem("http://loinc.org");
  b.addEntry().setFullUrl("http://hl7.org/fhir/Observation/"+obs.getId()).setResource(obs);
  return obs;
}
 
Example 6
Source File: ArgonautConverter.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private Observation processObservation(CDAUtilities cda, Convert convert, Context context, Element o) throws Exception {
	Observation obs = new Observation();
	obs.setId(context.baseId+"-results-"+Integer.toString(context.obsId));
	context.obsId++;
	obs.setSubject(context.subjectRef);
	obs.setContext(new Reference().setReference("Encounter/"+context.encounter.getId()));
	obs.setStatus(ObservationStatus.FINAL);
	obs.setEffective(convert.makeDateTimeFromTS(cda.getChild(o, "effectiveTime")));
	obs.setCode(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(o, "code")), null));
	obs.setInterpretation(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(o, "interpretationCode")), null));
	Element rr = cda.getChild(o, "referenceRange");
	if (rr != null)
		obs.addReferenceRange().setText(cda.getChild(cda.getChild(rr, "observationRange"), "text").getTextContent());

	Element v = cda.getChild(o, "value");
	String type = v.getAttribute("xsi:type");
	if ("ST".equals(type)) {
		obs.setUserData("profile", "http://hl7.org/fhir/StructureDefinition/observation-daf-results-dafresultobsother");
		obs.setValue(new StringType(v.getTextContent()));
	} else if ("CD".equals(type)) {
		obs.setUserData("profile", "http://hl7.org/fhir/StructureDefinition/observation-daf-results-dafresultobscode");
		obs.setValue(inspectCode(convert.makeCodeableConceptFromCD(v), null));
	} else if ("PQ".equals(type)) {
		obs.setUserData("profile", "http://hl7.org/fhir/StructureDefinition/observation-daf-results-dafresultobsquantity");
		String va = cda.getChild(o, "value").getAttribute("value");
		if (!Utilities.isDecimal(va, true)) {
			obs.setDataAbsentReason(inspectCode(new CodeableConcept().setText(va), null));
		} else
			obs.setValue(convert.makeQuantityFromPQ(cda.getChild(o, "value"), null));
	} else
		throw new Exception("Unknown type '"+type+"'");

	for (Element e : cda.getChildren(o, "id")) {
		Identifier id = convert.makeIdentifierFromII(e);
		obs.getIdentifier().add(id);
	}
	saveResource(obs, "-gen");
	return obs;
}
 
Example 7
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 8
Source File: ArgonautConverter.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private void processVitalSignsSection(CDAUtilities cda, Convert convert, Element section, Context context) throws Exception {
	scanSection("Vital Signs", section);
	ListResource list = new ListResource();
	list.setId(context.baseId+"-list-vitalsigns");
	//. list.setUserData("profile", "http://hl7.org/fhir/StructureDefinition/list-daf-dafproblemlist"); no list
	list.setSubject(context.subjectRef);
	list.setCode(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(section, "code")), null));
	list.setTitle(cda.getChild(section, "title").getTextContent());
	list.setStatus(ListStatus.CURRENT);
	list.setMode(ListMode.SNAPSHOT);
	list.setDateElement(context.now);
	list.setSource(context.authorRef);
	buildNarrative(list, cda.getChild(section, "text"));

	int i = 0;
	for (Element c : cda.getChildren(section, "entry")) {
		Element org = cda.getChild(c, "organizer"); // problem concern act
		for (Element oc : cda.getChildren(org, "component")) {
			Element o = cda.getChild(oc, "observation"); // problem concern act
			Observation obs = new Observation();
			obs.setId(context.baseId+"-vitals-"+Integer.toString(i));
			obs.setUserData("profile", "http://hl7.org/fhir/StructureDefinition/observation-daf-vitalsigns-dafvitalsigns");
			i++;
			obs.setSubject(context.subjectRef);
			obs.setContext(new Reference().setReference("Encounter/"+context.encounter.getId()));
			obs.setCode(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(o, "code")), null));

			boolean found = false;
			for (Element e : cda.getChildren(o, "id")) {
				Identifier id = convert.makeIdentifierFromII(e);
				obs.getIdentifier().add(id);
			}

			if (!found) {
				list.addEntry().setItem(new Reference().setReference("Observation/"+obs.getId()));
				obs.setStatus(ObservationStatus.FINAL);
				obs.setEffective(convert.makeDateTimeFromTS(cda.getChild(o, "effectiveTime")));
				String v = cda.getChild(o, "value").getAttribute("value");
				if (!Utilities.isDecimal(v, true)) {
					obs.setDataAbsentReason(inspectCode(new CodeableConcept().setText(v), null));
				} else
					obs.setValue(convert.makeQuantityFromPQ(cda.getChild(o, "value")));
				saveResource(obs, "-vs");
			}
		}
	}
	saveResource(list, "-vs");
}
 
Example 9
Source File: ExampleServerDstu3IT.java    From hapi-fhir-jpaserver-starter with Apache License 2.0 4 votes vote down vote up
@Test
public void testWebsocketSubscription() throws Exception {
	/*
	 * Create subscription
	 */
	Subscription subscription = new Subscription();
	subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
	subscription.setStatus(Subscription.SubscriptionStatus.REQUESTED);
	subscription.setCriteria("Observation?status=final");

	Subscription.SubscriptionChannelComponent channel = new Subscription.SubscriptionChannelComponent();
	channel.setType(Subscription.SubscriptionChannelType.WEBSOCKET);
	channel.setPayload("application/json");
	subscription.setChannel(channel);

	MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute();
	IIdType mySubscriptionId = methodOutcome.getId();

	// Wait for the subscription to be activated
	waitForSize(1, () -> ourClient.search().forResource(Subscription.class).where(Subscription.STATUS.exactly().code("active")).cacheControl(new CacheControlDirective().setNoCache(true)).returnBundle(Bundle.class).execute().getEntry().size());

	/*
	 * Attach websocket
	 */

	WebSocketClient myWebSocketClient = new WebSocketClient();
	SocketImplementation mySocketImplementation = new SocketImplementation(mySubscriptionId.getIdPart(), EncodingEnum.JSON);

	myWebSocketClient.start();
	URI echoUri = new URI("ws://localhost:" + ourPort + "/hapi-fhir-jpaserver/websocket");
	ClientUpgradeRequest request = new ClientUpgradeRequest();
	ourLog.info("Connecting to : {}", echoUri);
	Future<Session> connection = myWebSocketClient.connect(mySocketImplementation, echoUri, request);
	Session session = connection.get(2, TimeUnit.SECONDS);

	ourLog.info("Connected to WS: {}", session.isOpen());

	/*
	 * Create a matching resource
	 */
	Observation obs = new Observation();
	obs.setStatus(Observation.ObservationStatus.FINAL);
	ourClient.create().resource(obs).execute();

	// Give some time for the subscription to deliver
	Thread.sleep(2000);

	/*
	 * Ensure that we receive a ping on the websocket
	 */
	waitForSize(1, () -> mySocketImplementation.myPingCount);

	/*
	 * Clean up
	 */
	ourClient.delete().resourceById(mySubscriptionId).execute();
}