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

The following examples show how to use org.hl7.fhir.dstu3.model.Condition. 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
@Update
public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam Condition condition, @IdParam IdType theId, @ConditionalUrlParam String theConditional, RequestDetails theRequestDetails) {
	resourcePermissionProvider.checkPermission("update");

    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();

    method.setOperationOutcome(opOutcome);

    try {
        Condition newCondition = conditionDao.create(ctx, condition, theId, theConditional);
        method.setId(newCondition.getIdElement());
        method.setResource(newCondition);
    } catch (BaseServerResponseException srv) {
        // HAPI Exceptions pass through
        throw srv;
    } catch(Exception ex) {
        ProviderResponseLibrary.handleException(method,ex);
    }


    return method;
}
 
Example 2
@Create
public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam Condition condition) {

	resourcePermissionProvider.checkPermission("create");
    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();

    method.setOperationOutcome(opOutcome);

    try {
    Condition newCondition = conditionDao.create(ctx,condition, null,null);
    method.setId(newCondition.getIdElement());
    method.setResource(newCondition);
    } catch (BaseServerResponseException srv) {
        // HAPI Exceptions pass through
        throw srv;
    } catch(Exception ex) {
        ProviderResponseLibrary.handleException(method,ex);
    }

    return method;
}
 
Example 3
Source Project: synthea   Source File: ExportHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Helper to get a readable string representation of an Observation's value.
 * Units are not included.
 * 
 * @param observation The observation to get the value from
 * @return A human-readable string representation of observation.value
 */
public static String getObservationValue(Observation observation) {
  String value = null;
  
  if (observation.value instanceof Condition) {
    Code conditionCode = ((HealthRecord.Entry)observation.value).codes.get(0); 
    value = conditionCode.display;
  } else if (observation.value instanceof Code) {
    value = ((Code)observation.value).display;
  } else if (observation.value instanceof String) {
    value = (String)observation.value;
  } else if (observation.value instanceof Double) {
    // round to 1 decimal place for display
    value = String.format(Locale.US, "%.1f", observation.value);
  } else if (observation.value instanceof SampledData) {
    value = sampledDataToValueString((SampledData) observation.value);
  } else if (observation.value instanceof Attachment) {
    value = attachmentToValueString((Attachment) observation.value);
  } else if (observation.value != null) {
    value = observation.value.toString();
  }

  return value;
}
 
Example 4
Source Project: synthea   Source File: ExportHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Helper to get a readable string representation of an Observation's type.
 * 
 * @param observation The observation to get the type from
 * @return A human-readable string representation of the type of observation.value
 */
public static String getObservationType(Observation observation) {
  String type = null;
  
  if (observation.value instanceof Condition) {
    type = "text";
  } else if (observation.value instanceof Code) {
    type = "text";
  } else if (observation.value instanceof String) {
    type = "text";
  } else if (observation.value instanceof Double) {
    type = "numeric";
  } else if (observation.value != null) {
    type = "text";
  }
  
  return type;
}
 
Example 5
@Test
public void convertCondition20() throws IOException {
	// condition format of HAPI FHIR 2.0
	String oldContent = AllTests.getResourceAsString("/rsc/json/ConditionFormat20.json");
	assertFalse(FindingsFormatUtil.isCurrentFindingsFormat(oldContent));

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

	IBaseResource resource = AllTests.getJsonParser().parseResource(newContent.get());
	assertTrue(resource instanceof Condition);
	Condition condition = (Condition) resource;

	// category changed from diagnosis to problem-list-item
	List<CodeableConcept> category = condition.getCategory();
	assertFalse(category.isEmpty());
	CodeableConcept code = category.get(0);
	List<Coding> coding = code.getCoding();
	assertFalse(coding.isEmpty());
	assertTrue(coding.get(0).getCode().equals(ConditionCategory.PROBLEMLISTITEM.getCode()));
	// dateRecorded changed to assertedDate
	Date assertedDate = condition.getAssertedDate();
	assertNotNull(assertedDate);
}
 
Example 6
Source Project: bunsen   Source File: BundlesTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void getGetConditions() {

  Dataset<Row> conditions = bundles.extractEntry(spark,
      bundlesRdd,
      Condition.class);

  Assert.assertEquals(5, conditions.count());
}
 
Example 7
Source Project: bunsen   Source File: BundlesTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetResourcesByClass() {

  Dataset<Row> patients = bundles.extractEntry(spark, bundlesRdd, Patient.class);
  Dataset<Row> conditions = bundles.extractEntry(spark, bundlesRdd, Condition.class);

  checkPatients(patients);
  checkConditions(conditions);
}
 
Example 8
Source Project: bunsen   Source File: FunctionsTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets up Spark.
 */
@BeforeClass
public static void setUp() {
  spark = SparkSession.builder()
      .master("local[*]")
      .appName("testing")
      .getOrCreate();

  condition = new Condition();

  condition.setId("Condition/testid");

  conditions = conditionConverter.toDataFrame(spark, ImmutableList.of(condition));
}
 
Example 9
List<Composition> search(FhirContext ctx,

              @OptionalParam(name = Condition.SP_PATIENT) ReferenceParam patient
            , @OptionalParam(name = Composition.SP_IDENTIFIER) TokenParam identifier
            , @OptionalParam(name = Composition.SP_RES_ID) StringParam id
            , @OptionalParam(name = Composition.SP_TYPE) TokenParam type
            , @OptionalParam(name = Composition.SP_PERIOD)DateRangeParam dateRange

    );
 
Example 10
List<CompositionEntity> searchEntity(FhirContext ctx,
          @OptionalParam(name = Composition.SP_PATIENT) ReferenceParam patient
        , @OptionalParam(name = Condition.SP_IDENTIFIER) TokenParam identifier
        , @OptionalParam(name = Condition.SP_RES_ID) StringParam id
        , @OptionalParam(name = Composition.SP_TYPE) TokenParam type
        , @OptionalParam(name = Composition.SP_PERIOD)DateRangeParam dateRange
);
 
Example 11
List<DocumentReference> search(FhirContext ctx,

              @OptionalParam(name = Condition.SP_PATIENT) ReferenceParam patient
            , @OptionalParam(name = DocumentReference.SP_IDENTIFIER) TokenParam identifier
            , @OptionalParam(name = DocumentReference.SP_RES_ID) StringParam id
            , @OptionalParam(name = DocumentReference.SP_TYPE) TokenOrListParam type
            , @OptionalParam(name = DocumentReference.SP_PERIOD)DateRangeParam dateRange
            , @OptionalParam(name = DocumentReference.SP_SETTING) TokenParam setting

    );
 
Example 12
List<DocumentReferenceEntity> searchEntity(FhirContext ctx,
          @OptionalParam(name = DocumentReference.SP_PATIENT) ReferenceParam patient
        , @OptionalParam(name = Condition.SP_IDENTIFIER) TokenParam identifier
        , @OptionalParam(name = Condition.SP_RES_ID) StringParam id
        , @OptionalParam(name = DocumentReference.SP_TYPE) TokenOrListParam type
        , @OptionalParam(name = DocumentReference.SP_PERIOD)DateRangeParam dateRange
        , @OptionalParam(name = DocumentReference.SP_SETTING) TokenParam setting
);
 
Example 13
List<Condition> search(FhirContext ctx,

            @OptionalParam(name = Condition.SP_PATIENT) ReferenceParam patient
            , @OptionalParam(name = Condition.SP_CATEGORY) TokenParam category
            , @OptionalParam(name = Condition.SP_CLINICAL_STATUS) TokenParam clinicalstatus
            , @OptionalParam(name = Condition.SP_ASSERTED_DATE) DateRangeParam asserted
            , @OptionalParam(name = Condition.SP_IDENTIFIER) TokenParam identifier
            ,@OptionalParam(name= Condition.SP_RES_ID) StringParam id

    );
 
Example 14
List<ConditionEntity> searchEntity(FhirContext ctx,
        @OptionalParam(name = Condition.SP_PATIENT) ReferenceParam patient
        , @OptionalParam(name = Condition.SP_CATEGORY) TokenParam category
        , @OptionalParam(name = Condition.SP_CLINICAL_STATUS) TokenParam clinicalstatus
        , @OptionalParam(name = Condition.SP_ASSERTED_DATE) DateRangeParam asserted
        , @OptionalParam(name = Condition.SP_IDENTIFIER) TokenParam identifier
        ,@OptionalParam(name= Condition.SP_RES_ID) StringParam id
);
 
Example 15
@Search
public List<Condition> search(HttpServletRequest theRequest,
                              @OptionalParam(name = Condition.SP_PATIENT) ReferenceParam patient
        , @OptionalParam(name = Condition.SP_CATEGORY) TokenParam category
        , @OptionalParam(name = Condition.SP_CLINICAL_STATUS) TokenParam clinicalstatus
        , @OptionalParam(name = Condition.SP_ASSERTED_DATE) DateRangeParam asserted
        , @OptionalParam(name = Condition.SP_IDENTIFIER) TokenParam identifier
        , @OptionalParam(name = Condition.SP_RES_ID) StringParam resid
                              ) {
    return conditionDao.search(ctx,patient, category, clinicalstatus, asserted, identifier,resid);
}
 
Example 16
@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 17
Source Project: synthea   Source File: FhirStu3.java    License: Apache License 2.0 5 votes vote down vote up
static Type mapValueToFHIRType(Object value, String unit) {
  if (value == null) {
    return null;

  } else if (value instanceof Condition) {
    Code conditionCode = ((HealthRecord.Entry) value).codes.get(0);
    return mapCodeToCodeableConcept(conditionCode, SNOMED_URI);

  } else if (value instanceof Code) {
    return mapCodeToCodeableConcept((Code) value, SNOMED_URI);

  } else if (value instanceof String) {
    return new StringType((String) value);

  } else if (value instanceof Number) {
    double dblVal = ((Number) value).doubleValue();
    PlainBigDecimal bigVal = new PlainBigDecimal(dblVal);
    return new Quantity().setValue(bigVal)
        .setCode(unit).setSystem(UNITSOFMEASURE_URI)
        .setUnit(unit);
  } else if (value instanceof Components.SampledData) {
    return mapValueToSampledData((Components.SampledData) value, unit);
  } else {
    throw new IllegalArgumentException("unexpected observation value class: "
        + value.getClass().toString() + "; " + value);
  }
}
 
Example 18
Source Project: bunsen   Source File: TestData.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Returns a FHIR Condition for testing purposes.
 *
 * @return a FHIR Condition for testing.
 */
public static Condition newCondition() {

  Condition condition = new Condition();

  // Condition based on example from FHIR:
  // https://www.hl7.org/fhir/condition-example.json.html
  condition.setId("Condition/example");

  condition.setLanguage("en_US");

  // Narrative text
  Narrative narrative = new Narrative();
  narrative.setStatusAsString("generated");
  narrative.setDivAsString("This data was generated for test purposes.");
  XhtmlNode node = new XhtmlNode();
  node.setNodeType(NodeType.Text);
  node.setValue("Severe burn of left ear (Date: 24-May 2012)");
  condition.setText(narrative);

  condition.setSubject(new Reference("Patient/12345").setDisplay("Here is a display for you."));

  condition.setVerificationStatus(Condition.ConditionVerificationStatus.CONFIRMED);

  // Condition code
  CodeableConcept code = new CodeableConcept();
  code.addCoding()
      .setSystem("http://snomed.info/sct")
      .setCode("39065001")
      .setDisplay("Severe");
  condition.setSeverity(code);

  // Severity code
  CodeableConcept severity = new CodeableConcept();
  severity.addCoding()
      .setSystem("http://snomed.info/sct")
      .setCode("24484000")
      .setDisplay("Burn of ear")
      .setUserSelected(true);
  condition.setSeverity(severity);

  // Onset date time
  DateTimeType onset = new DateTimeType();
  onset.setValueAsString("2012-05-24");
  condition.setOnset(onset);

  return condition;
}
 
Example 19
Source Project: bunsen   Source File: TestData.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Returns a FHIR Condition for testing purposes.
 */
public static Condition newCondition() {

  Condition condition = new Condition();

  // Condition based on example from FHIR:
  // https://www.hl7.org/fhir/condition-example.json.html
  condition.setId("Condition/example");

  condition.setLanguage("en_US");

  // Narrative text
  Narrative narrative = new Narrative();
  narrative.setStatusAsString("generated");
  narrative.setDivAsString("This data was generated for test purposes.");
  XhtmlNode node = new XhtmlNode();
  node.setNodeType(NodeType.Text);
  node.setValue("Severe burn of left ear (Date: 24-May 2012)");
  condition.setText(narrative);

  condition.setSubject(new Reference("Patient/example").setDisplay("Here is a display for you."));

  condition.setVerificationStatus(Condition.ConditionVerificationStatus.CONFIRMED);

  // Condition code
  CodeableConcept code = new CodeableConcept();
  code.addCoding()
      .setSystem("http://snomed.info/sct")
      .setCode("39065001")
      .setDisplay("Severe");
  condition.setSeverity(code);

  // Severity code
  CodeableConcept severity = new CodeableConcept();
  severity.addCoding()
      .setSystem("http://snomed.info/sct")
      .setCode("24484000")
      .setDisplay("Burn of ear")
      .setUserSelected(true);
  condition.setSeverity(severity);

  // Onset date time
  DateTimeType onset = new DateTimeType();
  onset.setValueAsString("2012-05-24");
  condition.setOnset(onset);

  return condition;
}
 
Example 20
public Condition.ConditionClinicalStatus getClinicalStatus() {
    return clinicalStatus;
}
 
Example 21
public ConditionEntity setClinicalStatus(Condition.ConditionClinicalStatus clinicalStatus) {
    this.clinicalStatus = clinicalStatus;
    return this;
}
 
Example 22
public Condition.ConditionVerificationStatus getVerificationStatus() {
    return verificationStatus;
}
 
Example 23
public ConditionEntity setVerificationStatus(Condition.ConditionVerificationStatus verificationStatus) {
    this.verificationStatus = verificationStatus;
    return this;
}
 
Example 24
@Override
public Class<? extends IBaseResource> getResourceType() {
    return Condition.class;
}
 
Example 25
@Validate
public MethodOutcome testResource(@ResourceParam Condition resource,
                              @Validate.Mode ValidationModeEnum theMode,
                              @Validate.Profile String theProfile) {
    return resourceTestProvider.testResource(resource,theMode,theProfile);
}
 
Example 26
@Validate
public MethodOutcome testResource(@ResourceParam Condition resource,
                              @Validate.Mode ValidationModeEnum theMode,
                              @Validate.Profile String theProfile) {
    return resourceTestProvider.testResource(resource,theMode,theProfile);
}
 
Example 27
Source Project: synthea   Source File: FhirStu3.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Add a MedicationAdministration if needed for the given medication.
 * 
 * @param personEntry       The Entry for the Person
 * @param bundle            Bundle to add the MedicationAdministration to
 * @param encounterEntry    Current Encounter entry
 * @param medication        The Medication
 * @param medicationRequest The related medicationRequest
 * @return The added Entry
 */
private static BundleEntryComponent medicationAdministration(
    BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry,
    Medication medication, MedicationRequest medicationRequest) {

  MedicationAdministration medicationResource = new MedicationAdministration();

  medicationResource.setSubject(new Reference(personEntry.getFullUrl()));
  medicationResource.setContext(new Reference(encounterEntry.getFullUrl()));

  Code code = medication.codes.get(0);
  String system = code.system.equals("SNOMED-CT") ? SNOMED_URI : RXNORM_URI;

  medicationResource.setMedication(mapCodeToCodeableConcept(code, system));
  medicationResource.setEffective(new DateTimeType(new Date(medication.start)));

  medicationResource.setStatus(MedicationAdministrationStatus.fromCode("completed"));

  if (medication.prescriptionDetails != null) {
    JsonObject rxInfo = medication.prescriptionDetails;
    MedicationAdministrationDosageComponent dosage =
        new MedicationAdministrationDosageComponent();

    // as_needed is true if present
    if ((rxInfo.has("dosage")) && (!rxInfo.has("as_needed"))) {
      Quantity dose = new SimpleQuantity().setValue(
          rxInfo.get("dosage").getAsJsonObject().get("amount").getAsDouble());
      dosage.setDose((SimpleQuantity) dose);

      if (rxInfo.has("instructions")) {
        for (JsonElement instructionElement : rxInfo.get("instructions").getAsJsonArray()) {
          JsonObject instruction = instructionElement.getAsJsonObject();

          dosage.setText(instruction.get("display").getAsString());
        }
      }
    }
    medicationResource.setDosage(dosage);
  }

  if (!medication.reasons.isEmpty()) {
    // Only one element in list
    Code reason = medication.reasons.get(0);
    for (BundleEntryComponent entry : bundle.getEntry()) {
      if (entry.getResource().fhirType().equals("Condition")) {
        Condition condition = (Condition) entry.getResource();
        // Only one element in list
        Coding coding = condition.getCode().getCoding().get(0);
        if (reason.code.equals(coding.getCode())) {
          medicationResource.addReasonReference().setReference(entry.getFullUrl());
        }
      }
    }
  }

  BundleEntryComponent medicationAdminEntry = newEntry(bundle, medicationResource);
  return medicationAdminEntry;
}
 
Example 28
Source Project: synthea   Source File: FhirStu3.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Map the given CarePlan to a FHIR CarePlan resource, and add it to the given Bundle.
 *
 * @param personEntry The Entry for the Person
 * @param bundle Bundle to add the CarePlan to
 * @param encounterEntry Current Encounter entry
 * @param carePlan The CarePlan to map to FHIR and add to the bundle
 * @return The added Entry
 */
private static BundleEntryComponent careplan(BundleEntryComponent personEntry, Bundle bundle,
    BundleEntryComponent encounterEntry, CarePlan carePlan) {
  org.hl7.fhir.dstu3.model.CarePlan careplanResource = new org.hl7.fhir.dstu3.model.CarePlan();
  careplanResource.setIntent(CarePlanIntent.ORDER);
  careplanResource.setSubject(new Reference(personEntry.getFullUrl()));
  careplanResource.setContext(new Reference(encounterEntry.getFullUrl()));

  Code code = carePlan.codes.get(0);
  careplanResource.addCategory(mapCodeToCodeableConcept(code, SNOMED_URI));

  CarePlanActivityStatus activityStatus;
  GoalStatus goalStatus;

  Period period = new Period().setStart(new Date(carePlan.start));
  careplanResource.setPeriod(period);
  if (carePlan.stop != 0L) {
    period.setEnd(new Date(carePlan.stop));
    careplanResource.setStatus(CarePlanStatus.COMPLETED);
    activityStatus = CarePlanActivityStatus.COMPLETED;
    goalStatus = GoalStatus.ACHIEVED;
  } else {
    careplanResource.setStatus(CarePlanStatus.ACTIVE);
    activityStatus = CarePlanActivityStatus.INPROGRESS;
    goalStatus = GoalStatus.INPROGRESS;
  }

  if (!carePlan.activities.isEmpty()) {
    for (Code activity : carePlan.activities) {
      CarePlanActivityComponent activityComponent = new CarePlanActivityComponent();
      CarePlanActivityDetailComponent activityDetailComponent =
          new CarePlanActivityDetailComponent();

      activityDetailComponent.setStatus(activityStatus);

      activityDetailComponent.setCode(mapCodeToCodeableConcept(activity, SNOMED_URI));
      activityComponent.setDetail(activityDetailComponent);

      careplanResource.addActivity(activityComponent);
    }
  }

  if (!carePlan.reasons.isEmpty()) {
    // Only one element in list
    Code reason = carePlan.reasons.get(0);
    for (BundleEntryComponent entry : bundle.getEntry()) {
      if (entry.getResource().fhirType().equals("Condition")) {
        Condition condition = (Condition) entry.getResource();
        // Only one element in list
        Coding coding = condition.getCode().getCoding().get(0);
        if (reason.code.equals(coding.getCode())) {
          careplanResource.addAddresses().setReference(entry.getFullUrl());
        }
      }
    }
  }

  for (JsonObject goal : carePlan.goals) {
    BundleEntryComponent goalEntry = caregoal(bundle, goalStatus, goal);
    careplanResource.addGoal().setReference(goalEntry.getFullUrl());
  }

  return newEntry(bundle, careplanResource);
}
 
Example 29
Source Project: bunsen   Source File: FunctionsTest.java    License: Apache License 2.0 3 votes vote down vote up
@Test
public void resourceToJson() {

  Dataset<String> jsonDs = Functions.toJson(conditions, "Condition");

  String conditionJson = jsonDs.first();

  Condition parsedCondition = (Condition) CONTEXT.newJsonParser()
      .parseResource(conditionJson);

  Assert.assertEquals(condition.getId(), parsedCondition.getId());
}
 
Example 30
Source Project: bunsen   Source File: FunctionsTest.java    License: Apache License 2.0 3 votes vote down vote up
@Test
public void bundleToJson() {

  String jsonBundle = Functions.toJsonBundle(conditions, "Condition");

  Bundle bundle = (Bundle) CONTEXT.newJsonParser().parseResource(jsonBundle);

  Condition parsedCondition = (Condition) bundle.getEntryFirstRep().getResource();

  Assert.assertEquals(condition.getId(), parsedCondition.getId());
}