org.hl7.fhir.dstu3.model.MedicationRequest Java Examples

The following examples show how to use org.hl7.fhir.dstu3.model.MedicationRequest. 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: MedicationRequestProvider.java    From careconnect-reference-implementation with Apache License 2.0 6 votes vote down vote up
@Create
public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam MedicationRequest prescription) {

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

    method.setOperationOutcome(opOutcome);

    try {
    MedicationRequest newMedicationRequest = prescriptionDao.create(ctx,prescription, null,null);
    method.setId(newMedicationRequest.getIdElement());
    method.setResource(newMedicationRequest);
    } catch (Exception ex) {

        ProviderResponseLibrary.handleException(method,ex);
    }



    return method;
}
 
Example #2
Source File: MedicationRequestProvider.java    From careconnect-reference-implementation with Apache License 2.0 6 votes vote down vote up
@Update
public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam MedicationRequest prescription, @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 {
    MedicationRequest newMedicationRequest = prescriptionDao.create(ctx,prescription, theId, theConditional);
    method.setId(newMedicationRequest.getIdElement());
    method.setResource(newMedicationRequest);
    } catch (Exception ex) {

        ProviderResponseLibrary.handleException(method,ex);
    }



    return method;
}
 
Example #3
Source File: TestData.java    From bunsen with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new MedicationRequest for testing.
 *
 * @return a FHIR MedicationRequest for testing.
 */
public static MedicationRequest newMedicationRequest() {

  MedicationRequest medicationRequest = new MedicationRequest();

  medicationRequest.setId("test-medication-request");

  CodeableConcept itemCodeableConcept = new CodeableConcept();
  itemCodeableConcept.addCoding()
      .setSystem("http://www.nlm.nih.gov/research/umls/rxnorm")
      .setCode("103109")
      .setDisplay("Vitamin E 3 MG Oral Tablet [Ephynal]")
      .setUserSelected(true);

  medicationRequest.setMedication(itemCodeableConcept);

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

  medicationRequest.setDosageInstruction(ImmutableList.of(
      new Dosage().setTiming(new Timing().setRepeat(new TimingRepeatComponent().setCount(10)))));

  medicationRequest
      .setSubstitution(new MedicationRequestSubstitutionComponent().setAllowed(true));

  return medicationRequest;
}
 
Example #4
Source File: MedicationRequestRepository.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
List<MedicationRequestEntity> searchEntity(FhirContext ctx,
        @OptionalParam(name = MedicationRequest.SP_PATIENT) ReferenceParam patient
        , @OptionalParam(name = MedicationRequest.SP_CODE) TokenParam code
        , @OptionalParam(name = MedicationRequest.SP_AUTHOREDON) DateRangeParam dateWritten
        , @OptionalParam(name = MedicationRequest.SP_STATUS) TokenParam status
        , @OptionalParam(name = MedicationRequest.SP_IDENTIFIER) TokenParam identifier
        ,@OptionalParam(name= MedicationRequest.SP_RES_ID) StringParam id
        , @OptionalParam(name= MedicationRequest.SP_MEDICATION) ReferenceParam medication
);
 
Example #5
Source File: MedicationRequestRepository.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
List<MedicationRequest> search(FhirContext ctx,

                                   @OptionalParam(name = MedicationRequest.SP_PATIENT) ReferenceParam patient
            , @OptionalParam(name = MedicationRequest.SP_CODE) TokenParam code
            , @OptionalParam(name = MedicationRequest.SP_AUTHOREDON) DateRangeParam dateWritten
            , @OptionalParam(name = MedicationRequest.SP_STATUS) TokenParam status
            , @OptionalParam(name = MedicationRequest.SP_IDENTIFIER) TokenParam identifier
            , @OptionalParam(name= MedicationRequest.SP_RES_ID) StringParam id
            , @OptionalParam(name= MedicationRequest.SP_MEDICATION) ReferenceParam medication
    );
 
Example #6
Source File: MedicationRequestProvider.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
@Search
public List<MedicationRequest> search(HttpServletRequest theRequest,
                                      @OptionalParam(name = MedicationRequest.SP_PATIENT) ReferenceParam patient
        , @OptionalParam(name = MedicationRequest.SP_CODE) TokenParam code
        , @OptionalParam(name = MedicationRequest.SP_AUTHOREDON) DateRangeParam dateWritten
        , @OptionalParam(name = MedicationRequest.SP_STATUS) TokenParam status
        , @OptionalParam(name = MedicationRequest.SP_RES_ID) StringParam resid
        , @OptionalParam(name = MedicationRequest.SP_IDENTIFIER)  TokenParam identifierCode
        , @OptionalParam(name = MedicationRequest.SP_MEDICATION) ReferenceParam medication
                                      ) {
    return prescriptionDao.search(ctx,patient, code, dateWritten, status,identifierCode,resid,medication);
}
 
Example #7
Source File: MedicationRequestProvider.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
@Read()
public MedicationRequest get(@IdParam IdType prescriptionId) {
	resourcePermissionProvider.checkPermission("read");
    MedicationRequest prescription = prescriptionDao.read(ctx,prescriptionId);

    if ( prescription == null) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(
                new ResourceNotFoundException("No MedicationRequest/ " + prescriptionId.getIdPart()),
                 OperationOutcome.IssueType.NOTFOUND);
    }

    return prescription;
}
 
Example #8
Source File: MedicationRequestEntity.java    From careconnect-reference-implementation with Apache License 2.0 4 votes vote down vote up
public MedicationRequestEntity setIntent(MedicationRequest.MedicationRequestIntent intent) {
    this.intent = intent;
    return this;
}
 
Example #9
Source File: MedicationRequestEntity.java    From careconnect-reference-implementation with Apache License 2.0 4 votes vote down vote up
public MedicationRequest.MedicationRequestPriority getPriority() {
    return priority;
}
 
Example #10
Source File: MedicationRequestEntity.java    From careconnect-reference-implementation with Apache License 2.0 4 votes vote down vote up
public MedicationRequestEntity setPriority(MedicationRequest.MedicationRequestPriority priority) {
    this.priority = priority;
    return this;
}
 
Example #11
Source File: MedicationRequestEntity.java    From careconnect-reference-implementation with Apache License 2.0 4 votes vote down vote up
public MedicationRequest.MedicationRequestIntent getIntent() {
    return intent;
}
 
Example #12
Source File: MedicationRequestEntity.java    From careconnect-reference-implementation with Apache License 2.0 4 votes vote down vote up
public MedicationRequestEntity setStatus(MedicationRequest.MedicationRequestStatus status) {
    this.status = status;
    return this;
}
 
Example #13
Source File: MedicationRequestEntity.java    From careconnect-reference-implementation with Apache License 2.0 4 votes vote down vote up
public MedicationRequest.MedicationRequestStatus getStatus() {
    return status;
}
 
Example #14
Source File: MedicationRequestProvider.java    From careconnect-reference-implementation with Apache License 2.0 4 votes vote down vote up
@Validate
public MethodOutcome testResource(@ResourceParam MedicationRequest resource,
                              @Validate.Mode ValidationModeEnum theMode,
                              @Validate.Profile String theProfile) {
    return resourceTestProvider.testResource(resource,theMode,theProfile);
}
 
Example #15
Source File: MedicationRequestProvider.java    From careconnect-reference-implementation with Apache License 2.0 4 votes vote down vote up
@Override
public Class<? extends IBaseResource> getResourceType() {
    return MedicationRequest.class;
}
 
Example #16
Source File: FhirStu3.java    From synthea with 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 #17
Source File: TestData.java    From bunsen with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a FHIR medication request for testing purposes.
 */
public static MedicationRequest newMedRequest() {

  MedicationRequest medReq = new MedicationRequest();

  medReq.setId("test-med");

  // Medication code
  CodeableConcept med = new CodeableConcept();
  med.addCoding()
      .setSystem("http://www.nlm.nih.gov/research/umls/rxnorm")
      .setCode("582620")
      .setDisplay("Nizatidine 15 MG/ML Oral Solution [Axid]");

  med.setText("Nizatidine 15 MG/ML Oral Solution [Axid]");

  medReq.setMedication(med);

  Annotation annotation = new Annotation();

  annotation.setText("Test medication note.");

  annotation.setAuthor(
      new Reference("Provider/example")
          .setDisplay("Example provider."));

  medReq.addNote(annotation);

  return medReq;
}
 
Example #18
Source File: AvroConverterTest.java    From bunsen with Apache License 2.0 2 votes vote down vote up
/**
 * Initialize test data.
 */
@BeforeClass
public static void convertTestData() throws IOException {

  AvroConverter observationConverter = AvroConverter.forResource(FhirContexts.forStu3(),
      "Observation");

  avroObservation = (Record) observationConverter.resourceToAvro(testObservation);

  testObservationDecoded = (Observation) observationConverter.avroToResource(avroObservation);

  avroObservationNullStatus = (Record) observationConverter
      .resourceToAvro(testObservationNullStatus);

  testObservationDecodedNullStatus = (Observation) observationConverter
      .avroToResource(avroObservationNullStatus);

  AvroConverter patientConverter = AvroConverter.forResource(FhirContexts.forStu3(),
      TestData.US_CORE_PATIENT);

  avroPatient = (Record) patientConverter.resourceToAvro(testPatient);

  testPatientDecoded = (Patient) patientConverter.avroToResource(avroPatient);

  AvroConverter conditionConverter = AvroConverter.forResource(FhirContexts.forStu3(),
      TestData.US_CORE_CONDITION);

  avroCondition = (Record) conditionConverter.resourceToAvro(testCondition);

  testConditionDecoded = (Condition) conditionConverter.avroToResource(avroCondition);

  AvroConverter medicationConverter = AvroConverter.forResource(FhirContexts.forStu3(),
      TestData.US_CORE_MEDICATION);

  Record avroMedication = (Record) medicationConverter.resourceToAvro(testMedicationOne);

  testMedicationDecoded = (Medication) medicationConverter.avroToResource(avroMedication);

  AvroConverter medicationRequestConverter = AvroConverter.forResource(FhirContexts.forStu3(),
      TestData.US_CORE_MEDICATION_REQUEST,
      Arrays.asList(TestData.US_CORE_MEDICATION, TestData.PROVENANCE));

  avroMedicationRequest = (Record) medicationRequestConverter
      .resourceToAvro(testMedicationRequest);

  testMedicationRequestDecoded = (MedicationRequest) medicationRequestConverter
      .avroToResource(avroMedicationRequest);

  AvroConverter converterBunsenTestProfilePatient = AvroConverter
      .forResource(FhirContexts.forStu3(), TestData.BUNSEN_TEST_PATIENT);

  avroBunsenTestProfilePatient = (Record) converterBunsenTestProfilePatient
      .resourceToAvro(testBunsenTestProfilePatient);

  testBunsenTestProfilePatientDecoded = (Patient) converterBunsenTestProfilePatient
      .avroToResource(avroBunsenTestProfilePatient);
}
 
Example #19
Source File: SparkRowConverterTest.java    From bunsen with Apache License 2.0 2 votes vote down vote up
/**
 * Loads resource definitions used for testing.
 */
@BeforeClass
public static void loadDefinition() throws IOException {

  fhirContext = FhirContexts.forStu3();

  SparkRowConverter patientConverter = SparkRowConverter.forResource(fhirContext,
      TestData.US_CORE_PATIENT);

  Row testPatientRow = patientConverter.resourceToRow(testPatient);

  testPatientDataset = spark.createDataFrame(Collections.singletonList(testPatientRow),
      patientConverter.getSchema());

  testPatientDecoded = (Patient) patientConverter.rowToResource(testPatientDataset.head());

  SparkRowConverter observationConverter = SparkRowConverter.forResource(fhirContext,
      TestData.US_CORE_OBSERVATION);

  Row testObservationRow = observationConverter.resourceToRow(testObservation);

  testObservationDataset = spark.createDataFrame(Collections.singletonList(testObservationRow),
      observationConverter.getSchema());

  testObservationDecoded =
      (Observation) observationConverter.rowToResource(testObservationDataset.head());

  Row testObservationNullStatusRow = observationConverter
      .resourceToRow(testObservationNullStatus);

  testObservationNullStatusDataset = spark.createDataFrame(
      Collections.singletonList(testObservationNullStatusRow), observationConverter.getSchema());

  testObservationDecodedNullStatus = (Observation) observationConverter
      .rowToResource(testObservationNullStatusDataset.head());

  SparkRowConverter conditionConverter = SparkRowConverter.forResource(fhirContext,
      TestData.US_CORE_CONDITION);

  Row testConditionRow = conditionConverter.resourceToRow(testCondition);

  testConditionDataset = spark.createDataFrame(Collections.singletonList(testConditionRow),
      conditionConverter.getSchema());

  testConditionDecoded =
      (Condition) conditionConverter.rowToResource(testConditionDataset.head());

  SparkRowConverter medicationRequestConverter = SparkRowConverter.forResource(fhirContext,
      TestData.US_CORE_MEDICATION_REQUEST,
      Arrays.asList(TestData.US_CORE_MEDICATION, TestData.PROVENANCE));

  Row testMedicationRequestRow = medicationRequestConverter.resourceToRow(testMedicationRequest);

  testMedicationRequestDataset = spark.createDataFrame(
      Collections.singletonList(testMedicationRequestRow),
      medicationRequestConverter.getSchema());

  testMedicationRequestDecoded = (MedicationRequest) medicationRequestConverter
      .rowToResource(testMedicationRequestDataset.head());

  SparkRowConverter converterBunsenTestProfilePatient = SparkRowConverter
      .forResource(FhirContexts.forStu3(), TestData.BUNSEN_TEST_PATIENT);

  Row testBunsenTestProfilePatientRow = converterBunsenTestProfilePatient
      .resourceToRow(testBunsenTestProfilePatient);

  testBunsenTestProfilePatientDataset = spark
      .createDataFrame(Collections.singletonList(testBunsenTestProfilePatientRow),
          converterBunsenTestProfilePatient.getSchema());

  testBunsenTestProfilePatientDecoded = (Patient) converterBunsenTestProfilePatient
      .rowToResource(testBunsenTestProfilePatientRow);
}
 
Example #20
Source File: MedicationRequestRepository.java    From careconnect-reference-implementation with Apache License 2.0 votes vote down vote up
MedicationRequest create(FhirContext ctx,MedicationRequest prescription, @IdParam IdType theId, @ConditionalUrlParam String theConditional) throws OperationOutcomeException; 
Example #21
Source File: MedicationRequestRepository.java    From careconnect-reference-implementation with Apache License 2.0 votes vote down vote up
MedicationRequest read(FhirContext ctx, IdType theId);