Skip to content

Commit

Permalink
Use fhirpathjs
Browse files Browse the repository at this point in the history
Ref: #8
  • Loading branch information
projkov committed Jul 17, 2024
1 parent f00c883 commit ddd113f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
18 changes: 5 additions & 13 deletions src/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import axios from "axios";
import { useEffect, useState } from "react";
import { EvaluateResponse } from "./interfaces";
import { toast } from 'react-toastify';
import { reqWrapper } from "./utils/requests";
import { config } from './config'

const fhirpath = require('fhirpath');
const fhirpath_r4_model = require('fhirpath/fhir-context/r4');

export function useFHIRPathUI() {
const fhirPathServiceURL = config.fhirpathApi || 'http://localhost:5000';
const evaluateURL = fhirPathServiceURL + '/evaluate';
const [url, setUrl] = useState<string>('');
const [resource, setResource] = useState<string>('');
const [expression, setExpression] = useState<string>('');
Expand All @@ -34,15 +33,8 @@ export function useFHIRPathUI() {

const handleExecute = async (executeResource: string, executeExpression: string) => {
setIsLoading(true);
const result = await reqWrapper(axios.post<EvaluateResponse>(evaluateURL, {
resource: JSON.parse(executeResource),
expression: executeExpression,
}))
if(result.status === 'success'){
setResult(JSON.stringify(result.data, null, 2));
} else {
showError(result.error);
}
const result = fhirpath.evaluate(JSON.parse(executeResource), executeExpression, null, fhirpath_r4_model);
setResult(JSON.stringify(result.data, null, 2));
setIsLoading(false);
};

Expand Down
3 changes: 0 additions & 3 deletions src/interfaces.ts

This file was deleted.

0 comments on commit ddd113f

Please sign in to comment.