Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pmanko committed Oct 16, 2023
1 parent 4a0720a commit 437d773
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 10 deletions.
1 change: 0 additions & 1 deletion .eslintcache

This file was deleted.

1 change: 0 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import logger from './lib/winston'
import { run } from './server/kafkaWorkers'
import MllpAdapter from './server/mllpAdapter'
import { ShrMediator } from './server/shrMediator'
import { LabWorkflowsBw } from './workflows/labWorkflowsBw'

if (require.main === module) {
if (config.get('app:port')) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/kafkaConsumerUtil.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Kafka, Consumer, EachBatchPayload, Transaction, Message, KafkaConfig, EachMessagePayload } from 'kafkajs';
import { Consumer, EachBatchPayload, Kafka, KafkaConfig, Message } from 'kafkajs';
import logger from './winston';

export type EachMessageCallback = (topic: string, partition: number, message: Message) => Promise<void>;
Expand Down
3 changes: 1 addition & 2 deletions src/lib/kafkaProducerUtil.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Kafka, KafkaConfig, Producer, ProducerConfig, ProducerRecord, Transaction } from 'kafkajs';
import config from './config'
import { Kafka, KafkaConfig, Producer, ProducerRecord, Transaction } from 'kafkajs';
import logger from './winston';

type DeliveryReportCallback = (report: any) => void;
Expand Down
163 changes: 163 additions & 0 deletions src/lib/validate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@

export enum FHIR_R4_RESOURCES {
Account = "Account",
ActivityDefinition = "ActivityDefinition",
AdverseEvent = "AdverseEvent",
AllergyIntolerance = "AllergyIntolerance",
Appointment = "Appointment",
AppointmentResponse = "AppointmentResponse",
AuditEvent = "AuditEvent",
Basic = "Basic",
Binary = "Binary",
BiologicallyDerivedProduct = "BiologicallyDerivedProduct",
BodyStructure = "BodyStructure",
Bundle = "Bundle",
CapabilityStatement = "CapabilityStatement",
CarePlan = "CarePlan",
CareTeam = "CareTeam",
CatalogEntry = "CatalogEntry",
ChargeItem = "ChargeItem",
ChargeItemDefinition = "ChargeItemDefinition",
Claim = "Claim",
ClaimResponse = "ClaimResponse",
ClinicalImpression = "ClinicalImpression",
CodeSystem = "CodeSystem",
Communication = "Communication",
CommunicationRequest = "CommunicationRequest",
CompartmentDefinition = "CompartmentDefinition",
Composition = "Composition",
ConceptMap = "ConceptMap",
Condition = "Condition",
Consent = "Consent",
Contract = "Contract",
Coverage = "Coverage",
CoverageEligibilityRequest = "CoverageEligibilityRequest",
CoverageEligibilityResponse = "CoverageEligibilityResponse",
DetectedIssue = "DetectedIssue",
Device = "Device",
DeviceDefinition = "DeviceDefinition",
DeviceMetric = "DeviceMetric",
DeviceRequest = "DeviceRequest",
DeviceUseStatement = "DeviceUseStatement",
DiagnosticReport = "DiagnosticReport",
DocumentManifest = "DocumentManifest",
DocumentReference = "DocumentReference",
DomainResource = "DomainResource",
EffectEvidenceSynthesis = "EffectEvidenceSynthesis",
Encounter = "Encounter",
Endpoint = "Endpoint",
EnrollmentRequest = "EnrollmentRequest",
EnrollmentResponse = "EnrollmentResponse",
EpisodeOfCare = "EpisodeOfCare",
EventDefinition = "EventDefinition",
Evidence = "Evidence",
EvidenceVariable = "EvidenceVariable",
ExampleScenario = "ExampleScenario",
ExplanationOfBenefit = "ExplanationOfBenefit",
FamilyMemberHistory = "FamilyMemberHistory",
Flag = "Flag",
Goal = "Goal",
GraphDefinition = "GraphDefinition",
Group = "Group",
GuidanceResponse = "GuidanceResponse",
HealthcareService = "HealthcareService",
ImagingStudy = "ImagingStudy",
Immunization = "Immunization",
ImmunizationEvaluation = "ImmunizationEvaluation",
ImmunizationRecommendation = "ImmunizationRecommendation",
ImplementationGuide = "ImplementationGuide",
InsurancePlan = "InsurancePlan",
Invoice = "Invoice",
Library = "Library",
Linkage = "Linkage",
List = "List",
Location = "Location",
Measure = "Measure",
MeasureReport = "MeasureReport",
Media = "Media",
Medication = "Medication",
MedicationAdministration = "MedicationAdministration",
MedicationDispense = "MedicationDispense",
MedicationKnowledge = "MedicationKnowledge",
MedicationRequest = "MedicationRequest",
MedicationStatement = "MedicationStatement",
MedicinalProduct = "MedicinalProduct",
MedicinalProductAuthorization = "MedicinalProductAuthorization",
MedicinalProductContraindication = "MedicinalProductContraindication",
MedicinalProductIndication = "MedicinalProductIndication",
MedicinalProductIngredient = "MedicinalProductIngredient",
MedicinalProductInteraction = "MedicinalProductInteraction",
MedicinalProductManufactured = "MedicinalProductManufactured",
MedicinalProductPackaged = "MedicinalProductPackaged",
MedicinalProductPharmaceutical = "MedicinalProductPharmaceutical",
MedicinalProductUndesirableEffect = "MedicinalProductUndesirableEffect",
MessageDefinition = "MessageDefinition",
MessageHeader = "MessageHeader",
MolecularSequence = "MolecularSequence",
NamingSystem = "NamingSystem",
NutritionOrder = "NutritionOrder",
Observation = "Observation",
ObservationDefinition = "ObservationDefinition",
OperationDefinition = "OperationDefinition",
OperationOutcome = "OperationOutcome",
Organization = "Organization",
OrganizationAffiliation = "OrganizationAffiliation",
Parameters = "Parameters",
Patient = "Patient",
PaymentNotice = "PaymentNotice",
PaymentReconciliation = "PaymentReconciliation",
Person = "Person",
PlanDefinition = "PlanDefinition",
Practitioner = "Practitioner",
PractitionerRole = "PractitionerRole",
Procedure = "Procedure",
Provenance = "Provenance",
Questionnaire = "Questionnaire",
QuestionnaireResponse = "QuestionnaireResponse",
RelatedPerson = "RelatedPerson",
RequestGroup = "RequestGroup",
ResearchDefinition = "ResearchDefinition",
ResearchElementDefinition = "ResearchElementDefinition",
ResearchStudy = "ResearchStudy",
ResearchSubject = "ResearchSubject",
Resource = "Resource",
RiskAssessment = "RiskAssessment",
RiskEvidenceSynthesis = "RiskEvidenceSynthesis",
Schedule = "Schedule",
SearchParameter = "SearchParameter",
ServiceRequest = "ServiceRequest",
Slot = "Slot",
Specimen = "Specimen",
SpecimenDefinition = "SpecimenDefinition",
StructureDefinition = "StructureDefinition",
StructureMap = "StructureMap",
Subscription = "Subscription",
Substance = "Substance",
SubstanceNucleicAcid = "SubstanceNucleicAcid",
SubstancePolymer = "SubstancePolymer",
SubstanceProtein = "SubstanceProtein",
SubstanceReferenceInformation = "SubstanceReferenceInformation",
SubstanceSourceMaterial = "SubstanceSourceMaterial",
SubstanceSpecification = "SubstanceSpecification",
SupplyDelivery = "SupplyDelivery",
SupplyRequest = "SupplyRequest",
Task = "Task",
TerminologyCapabilities = "TerminologyCapabilities",
TestReport = "TestReport",
TestScript = "TestScript",
ValueSet = "ValueSet",
VerificationResult = "VerificationResult",
VisionPrescription = "VisionPrescription"
}

export function getResourceTypeEnum(resourceType: string): FHIR_R4_RESOURCES {
if(isValidResourceType(resourceType)) {
return <FHIR_R4_RESOURCES>resourceType
} else {
throw new Error(`Invalid resource type ${resourceType}`)
}
}

export function isValidResourceType(resourceType: string): boolean {
return resourceType in FHIR_R4_RESOURCES
}
10 changes: 7 additions & 3 deletions src/routes/fhir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import config from '../lib/config'
import { invalidBundle, invalidBundleMessage } from '../lib/helpers'
import logger from '../lib/winston'
import { generateSimpleIpsBundle } from '../workflows/ipsWorkflows'
import { getResourceTypeEnum } from '../lib/validate'

export const router = express.Router()

Expand Down Expand Up @@ -85,7 +86,7 @@ router.post('/', async (req, res) => {
const uri = URI(config.get("fhirServer:baseURL"));


let ret = await got.post(uri.toString(), { json: resource })
const ret = await got.post(uri.toString(), { json: resource })

res.status(ret.statusCode).json(ret.body)

Expand Down Expand Up @@ -114,11 +115,14 @@ async function saveResource(req: any, res: any) {
resource.id = id
}

logger.info('Received a request to add resource type ' + resourceType)
logger.info('Received a request to add resource type ' + resourceType + ' with id ' + id)

let ret = await got.post(config.get('fhirServer:baseURL') + '/' + resourceType, { json: resource })
const ret = await got.post(config.get('fhirServer:baseURL') + '/' + getResourceTypeEnum(resourceType).toString, { json: resource })

res.status(ret.statusCode).json(ret.body)
}




export default router
2 changes: 1 addition & 1 deletion src/server/kafkaWorkers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { KafkaConfig, logLevel, Message } from 'kafkajs'
import { KafkaConfig, Message, logLevel } from 'kafkajs'
import logger from '../lib/winston'
import { LabWorkflowsBw, topicList } from '../workflows/labWorkflowsBw'
import { config } from '../lib/config'
Expand Down
1 change: 0 additions & 1 deletion src/server/shrMediator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import shrApp from '../lib/shr'
import logger from '../lib/winston'

import medUtils from 'openhim-mediator-utils'
import { error } from 'console'
import { LabWorkflowsBw } from '../workflows/labWorkflowsBw'


Expand Down

0 comments on commit 437d773

Please sign in to comment.